{"id":107,"date":"2010-10-29T10:37:06","date_gmt":"2010-10-29T10:37:06","guid":{"rendered":"http:\/\/www.funcubedongle.com\/?p=107"},"modified":"2010-11-05T11:54:05","modified_gmt":"2010-11-05T11:54:05","slug":"dongle-programming-interface","status":"publish","type":"post","link":"https:\/\/www.funcubedongle.com\/?p=107","title":{"rendered":"Dongle programming interface"},"content":{"rendered":"<p>I&#8217;ve been receiving a number of questions about the programming interface for the FCD.<\/p>\n<p>Although the quadrature I\/Q stream is over a standard USB stereo soundcard interface, in order to change the centre frequency there is\u00a0an additional\u00a0programming interface that uses the USB HID standard interface. Here&#8217;s an example <!--more-->to set the centre frequency of the dongle give the frequency in kHz:<\/p>\n<pre>static unsigned char HIDSetFreq(HANDLE hWrite,HANDLE hRead,int nFreq)\r\n{\r\n\u00a0DWORD dwBytesWritten=0;\r\n\u00a0DWORD dwBytesRead=0;\r\n\u00a0unsigned char au8BufOut[65]; \/\/ endpoint size + 1\r\n\u00a0unsigned char au8BufIn[65]; \/\/ endpoint size + 1\r\n\r\n au8BufOut[0]=0; \/\/ First byte is report ID. Ignored by HID Class\r\n   \/\/ firmware as only config'd for one report\r\n\u00a0au8BufOut[1]=100; \/\/ Command to Set Frequency on dongle\r\n\u00a0au8BufOut[2]=(unsigned char)nFreq;\r\n\u00a0au8BufOut[3]=(unsigned char)(nFreq&gt;&gt;8);\r\n\u00a0au8BufOut[4]=(unsigned char)(nFreq&gt;&gt;16);\r\n\u00a0WriteFile(hWrite,au8BufOut,65,&amp;dwBytesWritten,0);\r\n\u00a0ReadFile(hRead,au8BufIn,65,&amp;dwBytesRead,0);\r\n\u00a0return au8BufIn[2]; \/\/ au8BufIn[2]==1 if success.\r\n}<\/pre>\n<p>The HID command output to the dongle is 64 bytes,\u00a0as is the HID\u00a0response input\u00a0back into the host. You also need to prepend the buffers with one byte each for the HID report ID that&#8217;s not actually used, so 65 bytes total each.<\/p>\n<p>In the output command buffer, after the unused HID report byte, the FCD command byte follows. The &#8220;SetFreq&#8221; command is 100. Following this is the 24 bit little endian integer frequency specified in kHz.<\/p>\n<p>In response, the 65 bytes buffer includes a copy of the command (100 in this case) at index 1 and a boolean success\/fail 1\/0 response at index 2.<\/p>\n<p>So far so good. But you need to open up\u00a0input and output\u00a0HID\u00a0handles first to use this function! This is rather more fiddly, certainly\u00a0in the Windows world. I have some example code here that demonstrates this: <a href=\"http:\/\/www.g6lvb.com\/Fungle\/FCHid002.zip\">http:\/\/www.g6lvb.com\/Fungle\/FCHid002.zip<\/a><\/p>\n<p>Howard<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been receiving a number of questions about the programming interface for the FCD. Although the quadrature I\/Q stream is over a standard USB stereo soundcard interface, in order to change the centre frequency there is\u00a0an additional\u00a0programming interface that uses &hellip; <a href=\"https:\/\/www.funcubedongle.com\/?p=107\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.funcubedongle.com\/index.php?rest_route=\/wp\/v2\/posts\/107"}],"collection":[{"href":"https:\/\/www.funcubedongle.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.funcubedongle.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.funcubedongle.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.funcubedongle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=107"}],"version-history":[{"count":3,"href":"https:\/\/www.funcubedongle.com\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/www.funcubedongle.com\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions\/119"}],"wp:attachment":[{"href":"https:\/\/www.funcubedongle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.funcubedongle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.funcubedongle.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}