SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Classes | Macros | Typedefs | Enumerations | Functions
fcdhid.h File Reference
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "fcdhidcmd.h"
#include "hidapi.h"
#include <inttypes.h>
+ Include dependency graph for fcdhid.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  FCD_CAPS_STRUCT
 FCD capabilities that depend on both hardware and firmware. More...
 

Macros

#define FALSE   0
 
#define TRUE   1
 

Typedefs

typedef int BOOL
 

Enumerations

enum  FCD_MODE_ENUM { FCD_MODE_NONE, FCD_MODE_DEAD, FCD_MODE_BL, FCD_MODE_APP }
 FCD mode enumeration. More...
 

Functions

hid_devicefcdOpen (uint16_t usVID, uint16_t usPID, int whichdongle)
 Open FCD device. More...
 
void fcdClose (hid_device *phd)
 Close FCD HID device. More...
 
FCD_MODE_ENUM fcdGetMode (hid_device *phd)
 Get FCD mode. More...
 
FCD_MODE_ENUM fcdGetFwVerStr (hid_device *phd, char *str)
 Get FCD firmware version as string. More...
 
FCD_MODE_ENUM fcdGetCaps (hid_device *phd, FCD_CAPS_STRUCT *fcd_caps)
 Get hardware and firmware dependent FCD capabilities. More...
 
FCD_MODE_ENUM fcdGetCapsStr (hid_device *phd, char *caps_str)
 Get hardware and firmware dependent FCD capabilities as string. More...
 
FCD_MODE_ENUM fcdAppReset (hid_device *phd)
 Reset FCD to bootloader mode. More...
 
FCD_MODE_ENUM fcdAppSetFreqkHz (hid_device *phd, int nFreq)
 Set FCD frequency with kHz resolution. More...
 
FCD_MODE_ENUM fcdAppSetFreq (hid_device *phd, int nFreq)
 Set FCD frequency with Hz resolution. More...
 
FCD_MODE_ENUM fcdBlReset (hid_device *phd)
 Reset FCD to application mode. More...
 
FCD_MODE_ENUM fcdBlErase (hid_device *phd)
 Erase firmware from FCD. More...
 
FCD_MODE_ENUM fcdBlWriteFirmware (hid_device *phd, char *pc, int64_t n64Size)
 Write new firmware into the FCD. More...
 
FCD_MODE_ENUM fcdBlVerifyFirmware (hid_device *phd, char *pc, int64_t n64Size)
 Verify firmware in FCd flash. More...
 
FCD_MODE_ENUM fcdAppSetParam (hid_device *phd, uint8_t u8Cmd, uint8_t *pu8Data, uint8_t u8len)
 Write FCD parameter (e.g. gain or filter) More...
 
FCD_MODE_ENUM fcdAppGetParam (hid_device *phd, uint8_t u8Cmd, uint8_t *pu8Data, uint8_t u8len)
 Read FCD parameter (e.g. gain or filter) More...
 

Macro Definition Documentation

◆ FALSE

#define FALSE   0

Definition at line 35 of file fcdhid.h.

◆ TRUE

#define TRUE   1

Definition at line 36 of file fcdhid.h.

Typedef Documentation

◆ BOOL

typedef int BOOL

Definition at line 37 of file fcdhid.h.

Enumeration Type Documentation

◆ FCD_MODE_ENUM

FCD mode enumeration.

Enumerator
FCD_MODE_NONE 

No FCD detected.

FCD_MODE_DEAD 
FCD_MODE_BL 

FCD present in bootloader mode.

FCD_MODE_APP 

FCD present in aplpication mode.

Definition at line 40 of file fcdhid.h.

40  {
43  FCD_MODE_BL,
45 } FCD_MODE_ENUM; // The current mode of the FCD: none inserted, in bootloader mode or in normal application mode
FCD_MODE_ENUM
FCD mode enumeration.
Definition: fcdhid.h:40

Function Documentation

◆ fcdAppGetParam()

FCD_MODE_ENUM fcdAppGetParam ( hid_device phd,
uint8_t  u8Cmd,
uint8_t pu8Data,
uint8_t  u8len 
)

Read FCD parameter (e.g. gain or filter)

Parameters
u8CmdThe command byte / parameter ID, see FCD_CMD_APP_GET_*
pu8DataTPointer to buffer where the parameter value(s) will be written
u8lenLength of pu8Data in bytes
Returns
One of FCD_MODE_NONE, FCD_MODE_APP or FCD_MODE_BL (see description)

This function can be used to read the value of a parameter in the FCD for which there is no high level API call. It gives access to the low level API of the FCD and the caller is expected to be aware of the various FCD commands, since they are required to be supplied as parameter to this function.

The return value can be used to determine the success or failure of the command execution:

  • FCD_MODE_APP : Reply from FCD was as expected (nominal case).
  • FCD_MODE_BL : Reply from FCD was not as expected.
  • FCD_MODE_NONE : No FCD was found

Definition at line 884 of file fcdhid.c.

References FCD_MODE_APP, FCD_MODE_BL, hid_read(), and hid_write().

885 {
886  //hid_device *phd=NULL;
887  unsigned char aucBufOut[65];
888  unsigned char aucBufIn[65];
889 
890  /*
891  phd = fcdOpen();
892  if (phd == NULL)
893  {
894  return FCD_MODE_NONE;
895  }*/
896 
897  aucBufOut[0]=0; // Report ID, ignored
898  aucBufOut[1]=u8Cmd;
899  hid_write(phd,aucBufOut,65);
900 
901  memset(aucBufIn,0xCC,65); // Clear out the response buffer
902  hid_read(phd,aucBufIn,65);
903  /* Copy return data to output buffer (even if cmd exec failed) */
904  memcpy(pu8Data,aucBufIn+2,u8len);
905 
906  /* Check status bytes in returned data */
907  if (aucBufIn[0]==u8Cmd && aucBufIn[1]==1) {
908  /*
909  fcdClose(phd);
910  phd = NULL;*/
911 
912  return FCD_MODE_APP;
913  }
914 
915  /* Response did not contain the expected bytes */
916  /*
917  fcdClose(phd);
918  phd = NULL;*/
919 
920  return FCD_MODE_BL;
921 }
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdAppReset()

FCD_MODE_ENUM fcdAppReset ( hid_device phd)

Reset FCD to bootloader mode.

Returns
FCD_MODE_NONE

This function is used to switch the FCD into bootloader mode in which various firmware operations can be performed.

FIXME: hid_read() will occasionally hang due to a pthread_cond_wait() never returning. It seems that the read_callback() in hid-libusb.c will never receive any data during the reconfiguration. Since the same logic works in the native windows application, it could be a libusb thing. Anyhow, since the value returned by this function is not used, we may as well just skip the hid_read() and return FME_NONE. Correct switch from APP to BL mode can be observed in /var/log/messages (linux) (when in bootloader mode the device version includes 'BL')

Definition at line 339 of file fcdhid.c.

References FCD_CMD_APP_RESET, FCD_MODE_NONE, and hid_write().

340 {
341  //hid_device *phd=NULL;
342  //unsigned char aucBufIn[65];
343  unsigned char aucBufOut[65];
344 
345  /*
346  phd = fcdOpen();
347 
348  if (phd == NULL)
349  {
350  return FCD_MODE_NONE;
351  }*/
352 
353  // Send an App reset command
354  aucBufOut[0] = 0; // Report ID, ignored
355  aucBufOut[1] = FCD_CMD_APP_RESET;
356  hid_write(phd, aucBufOut, 65);
357 
367  /*
368  memset(aucBufIn,0xCC,65); // Clear out the response buffer
369  hid_read(phd,aucBufIn,65);
370 
371  if (aucBufIn[0]==FCDCMDAPPRESET && aucBufIn[1]==1)
372  {
373  FCDClose(phd);
374  phd=NULL;
375  return FME_APP;
376  }
377  FCDClose(phd);
378  phd=NULL;
379  return FME_BL;
380  */
381 
382  /*
383  fcdClose(phd);
384  phd = NULL;*/
385 
386  return FCD_MODE_NONE;
387 
388 }
#define FCD_CMD_APP_RESET
Reset to bootloader.
Definition: fcdhidcmd.h:39
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdAppSetFreq()

FCD_MODE_ENUM fcdAppSetFreq ( hid_device phd,
int  nFreq 
)

Set FCD frequency with Hz resolution.

Parameters
nFreqThe new frequency in Hz.
Returns
The FCD mode.

This function sets the frequency of the FCD with 1 Hz resolution. The parameter nFreq must already contain any necessary frequency correction.

See also
fcdAppSetFreq

Definition at line 450 of file fcdhid.c.

References FCD_CMD_APP_SET_FREQ_HZ, FCD_MODE_APP, FCD_MODE_BL, hid_read(), and hid_write().

Referenced by FCDProInput::set_center_freq(), and FCDProPlusInput::set_center_freq().

451 {
452  //hid_device *phd=NULL;
453  unsigned char aucBufIn[65];
454  unsigned char aucBufOut[65];
455 
456  /*
457  phd = fcdOpen();
458 
459  if (phd == NULL)
460  {
461  return FCD_MODE_NONE;
462  }*/
463 
464  // Send an App reset command
465  aucBufOut[0] = 0; // Report ID, ignored
466  aucBufOut[1] = FCD_CMD_APP_SET_FREQ_HZ;
467  aucBufOut[2] = (unsigned char)nFreq;
468  aucBufOut[3] = (unsigned char)(nFreq>>8);
469  aucBufOut[4] = (unsigned char)(nFreq>>16);
470  aucBufOut[5] = (unsigned char)(nFreq>>24);
471  hid_write(phd, aucBufOut, 65);
472  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
473  hid_read(phd, aucBufIn, 65);
474 
475  if (aucBufIn[0]==FCD_CMD_APP_SET_FREQ_HZ && aucBufIn[1]==1)
476  {
477  /*
478  fcdClose(phd);
479  phd = NULL;*/
480 
481  return FCD_MODE_APP;
482  }
483 
484  /*
485  fcdClose(phd);
486  phd = NULL;*/
487 
488  return FCD_MODE_BL;
489 }
#define FCD_CMD_APP_SET_FREQ_HZ
Definition: fcdhidcmd.h:36
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fcdAppSetFreqkHz()

FCD_MODE_ENUM fcdAppSetFreqkHz ( hid_device phd,
int  nFreq 
)

Set FCD frequency with kHz resolution.

Parameters
nFreqThe new frequency in kHz.
Returns
The FCD mode.

This function sets the frequency of the FCD with 1 kHz resolution. The parameter nFreq must already contain any necessary frequency correction.

See also
fcdAppSetFreq

Definition at line 400 of file fcdhid.c.

References FCD_CMD_APP_SET_FREQ_KHZ, FCD_MODE_APP, FCD_MODE_BL, hid_read(), and hid_write().

401 {
402  //hid_device *phd=NULL;
403  unsigned char aucBufIn[65];
404  unsigned char aucBufOut[65];
405 
406  /*
407  phd = fcdOpen();
408 
409  if (phd == NULL)
410  {
411  return FCD_MODE_NONE;
412  }*/
413 
414  // Send an App reset command
415  aucBufOut[0] = 0; // Report ID, ignored
416  aucBufOut[1] = FCD_CMD_APP_SET_FREQ_KHZ;
417  aucBufOut[2] = (unsigned char)nFreq;
418  aucBufOut[3] = (unsigned char)(nFreq>>8);
419  aucBufOut[4] = (unsigned char)(nFreq>>16);
420  hid_write(phd, aucBufOut, 65);
421  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
422  hid_read(phd, aucBufIn, 65);
423 
424  if (aucBufIn[0]==FCD_CMD_APP_SET_FREQ_KHZ && aucBufIn[1]==1)
425  {
426  /*
427  fcdClose(phd);
428  phd = NULL;*/
429 
430  return FCD_MODE_APP;
431  }
432 
433  /*
434  fcdClose(phd);
435  phd = NULL;*/
436 
437  return FCD_MODE_BL;
438 }
#define FCD_CMD_APP_SET_FREQ_KHZ
Definition: fcdhidcmd.h:35
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdAppSetParam()

FCD_MODE_ENUM fcdAppSetParam ( hid_device phd,
uint8_t  u8Cmd,
uint8_t pu8Data,
uint8_t  u8len 
)

Write FCD parameter (e.g. gain or filter)

Parameters
u8CmdThe command byte / parameter ID, see FCD_CMD_APP_SET_*
pu8DataThe parameter value to be written
u8lenLength of pu8Data in bytes
Returns
One of FCD_MODE_NONE, FCD_MODE_APP or FCD_MODE_BL (see description)

This function can be used to set the value of a parameter in the FCD for which there is no high level API call. It gives access to the low level API of the FCD and the caller is expected to be aware of the various FCD commands, since they are required to be supplied as parameter to this function.

The return value can be used to determine the success or failure of the command execution:

  • FCD_MODE_APP : Reply from FCD was as expected (nominal case).
  • FCD_MODE_BL : Reply from FCD was not as expected.
  • FCD_MODE_NONE : No FCD was found

Definition at line 826 of file fcdhid.c.

References FCD_MODE_APP, FCD_MODE_BL, hid_read(), and hid_write().

Referenced by FCDProInput::set_band(), FCDProPlusInput::set_bias_t(), FCDProInput::set_biasCurrent(), FCDProInput::set_gain1(), FCDProInput::set_gain2(), FCDProInput::set_gain3(), FCDProInput::set_gain4(), FCDProInput::set_gain5(), FCDProInput::set_gain6(), FCDProPlusInput::set_if_filter(), FCDProPlusInput::set_if_gain(), FCDProInput::set_ifFilter(), FCDProPlusInput::set_lna_gain(), FCDProInput::set_lnaEnhance(), FCDProInput::set_lnaGain(), FCDProPlusInput::set_mixer_gain(), FCDProInput::set_mixerFilter(), FCDProInput::set_mixerGain(), FCDProInput::set_mode(), FCDProInput::set_rcFilter(), FCDProPlusInput::set_rf_filter(), and FCDProInput::set_rfFilter().

827 {
828  //hid_device *phd=NULL;
829  unsigned char aucBufOut[65];
830  unsigned char aucBufIn[65];
831 
832  /*
833  phd = fcdOpen();
834 
835  if (phd == NULL)
836  {
837  return FCD_MODE_NONE;
838  }*/
839 
840  aucBufOut[0]=0; // Report ID, ignored
841  aucBufOut[1]=u8Cmd;
842  memcpy(aucBufOut+2, pu8Data,u8len);
843  hid_write(phd,aucBufOut,65);
844 
845  /* we must read after each write in order to empty FCD/HID buffer */
846  memset(aucBufIn,0xCC,65); // Clear out the response buffer
847  hid_read(phd,aucBufIn,65);
848 
849  /* Check the response, if OK return FCD_MODE_APP */
850  if (aucBufIn[0]==u8Cmd && aucBufIn[1]==1) {
851  /*
852  fcdClose(phd);
853  phd = NULL;*/
854 
855  return FCD_MODE_APP;
856  }
857 
858  /* Response did not contain the expected bytes */
859  /*
860  fcdClose(phd);
861  phd = NULL;*/
862 
863  return FCD_MODE_BL;
864 
865 }
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fcdBlErase()

FCD_MODE_ENUM fcdBlErase ( hid_device phd)

Erase firmware from FCD.

Returns
The FCD mode

This function deletes the firmware from the FCD. This is required before writing new firmware into the FCD.

See also
fcdBlWriteFirmware

Definition at line 559 of file fcdhid.c.

References FCD_CMD_BL_ERASE, FCD_MODE_APP, FCD_MODE_BL, hid_read(), and hid_write().

560 {
561  //hid_device *phd=NULL;
562  unsigned char aucBufIn[65];
563  unsigned char aucBufOut[65];
564 
565  /*
566  phd = fcdOpen();
567 
568  if (phd == NULL)
569  {
570  return FCD_MODE_NONE;
571  }*/
572 
573  // Send an App reset command
574  aucBufOut[0] = 0; // Report ID, ignored
575  aucBufOut[1] = FCD_CMD_BL_ERASE;
576  hid_write(phd, aucBufOut, 65);
577  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
578  hid_read(phd, aucBufIn, 65);
579 
580  if (aucBufIn[0]==FCD_CMD_BL_ERASE && aucBufIn[1]==1)
581  {
582  /*
583  fcdClose(phd);
584  phd = NULL;*/
585 
586  return FCD_MODE_BL;
587  }
588 
589  /*
590  fcdClose(phd);
591  phd = NULL;*/
592 
593  return FCD_MODE_APP;
594 }
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
#define FCD_CMD_BL_ERASE
Definition: fcdhidcmd.h:28
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdBlReset()

FCD_MODE_ENUM fcdBlReset ( hid_device phd)

Reset FCD to application mode.

Returns
FCD_MODE_NONE

This function is used to switch the FCD from bootloader mode into application mode.

FIXME: hid_read() will hang due to a pthread_cond_wait() never returning. It seems that the read_callback() in hid-libusb.c will never receive any data during the reconfiguration. Since the same logic works in the native windows application, it could be a libusb thing. Anyhow, since the value returned by this function is not used, we may as well jsut skip the hid_read() and return FME_NONE. Correct switch from BL to APP mode can be observed in /var/log/messages (linux) (when in bootloader mode the device version includes 'BL')

Definition at line 499 of file fcdhid.c.

References FCD_CMD_BL_RESET, FCD_MODE_NONE, and hid_write().

500 {
501  //hid_device *phd=NULL;
502  // unsigned char aucBufIn[65];
503  unsigned char aucBufOut[65];
504 
505  /*
506  phd = fcdOpen();
507 
508  if (phd == NULL)
509  {
510  return FCD_MODE_NONE;
511  }*/
512 
513  // Send an BL reset command
514  aucBufOut[0] = 0; // Report ID, ignored
515  aucBufOut[1] = FCD_CMD_BL_RESET;
516  hid_write(phd, aucBufOut, 65);
517 
527  /*
528  memset(aucBufIn,0xCC,65); // Clear out the response buffer
529  hid_read(phd,aucBufIn,65);
530 
531  if (aucBufIn[0]==FCDCMDBLRESET && aucBufIn[1]==1)
532  {
533  FCDClose(phd);
534  phd=NULL;
535  return FME_BL;
536  }
537  FCDClose(phd);
538  phd=NULL;
539  return FME_APP;
540  */
541 
542  /*
543  fcdClose(phd);
544  phd = NULL;*/
545 
546  return FCD_MODE_NONE;
547 
548 }
#define FCD_CMD_BL_RESET
Definition: fcdhidcmd.h:27
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdBlVerifyFirmware()

FCD_MODE_ENUM fcdBlVerifyFirmware ( hid_device phd,
char *  pc,
int64_t  n64Size 
)

Verify firmware in FCd flash.

Parameters
pcPointer to firmware data to verify against.
n64SizeSize of the data in pc.
Returns
The FCD_MODE_BL if verification was succesful.

This function verifies the firmware currently in the FCd flash against the firmware image pointed to by pc. The function return FCD_MODE_BL if the verification is OK and FCD_MODE_APP otherwise.

Definition at line 708 of file fcdhid.c.

References FCD_CMD_BL_GET_BYTE_ADDR_RANGE, FCD_CMD_BL_READ_FLASH_BLOCK, FCD_CMD_BL_SET_BYTE_ADDR, FCD_MODE_APP, FCD_MODE_BL, hid_read(), and hid_write().

709 {
710  //hid_device *phd=NULL;
711  unsigned char aucBufIn[65];
712  unsigned char aucBufOut[65];
713  uint32_t u32AddrStart;
714  uint32_t u32AddrEnd;
715  uint32_t u32Addr;
716 
717  /*
718  phd = fcdOpen();
719 
720  if (phd==NULL)
721  {
722  return FCD_MODE_NONE;
723  }*/
724 
725  // Get the valid flash address range
726  aucBufOut[0] = 0; // Report ID, ignored
727  aucBufOut[1] = FCD_CMD_BL_GET_BYTE_ADDR_RANGE;
728  hid_write(phd, aucBufOut, 65);
729  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
730  hid_read(phd, aucBufIn, 65);
731 
732  if (aucBufIn[0]!=FCD_CMD_BL_GET_BYTE_ADDR_RANGE || aucBufIn[1]!=1)
733  {
734  /*
735  fcdClose(phd);
736  phd = NULL;*/
737 
738  return FCD_MODE_APP;
739  }
740 
741  u32AddrStart=
742  aucBufIn[2]+
743  (((uint32_t)aucBufIn[3])<<8)+
744  (((uint32_t)aucBufIn[4])<<16)+
745  (((uint32_t)aucBufIn[5])<<24);
746 
747  u32AddrEnd=
748  aucBufIn[6]+
749  (((uint32_t)aucBufIn[7])<<8)+
750  (((uint32_t)aucBufIn[8])<<16)+
751  (((uint32_t)aucBufIn[9])<<24);
752 
753  // Set start address for flash
754  aucBufOut[0] = 0; // Report ID, ignored
755  aucBufOut[1] = FCD_CMD_BL_SET_BYTE_ADDR;
756  aucBufOut[2] = ((unsigned char)u32AddrStart);
757  aucBufOut[3] = ((unsigned char)(u32AddrStart>>8));
758  aucBufOut[4] = ((unsigned char)(u32AddrStart>>16));
759  aucBufOut[5] = ((unsigned char)(u32AddrStart>>24));
760  hid_write(phd, aucBufOut, 65);
761  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
762  hid_read(phd, aucBufIn, 65);
763 
764  if (aucBufIn[0]!=FCD_CMD_BL_SET_BYTE_ADDR || aucBufIn[1]!=1)
765  {
766  /*
767  fcdClose(phd);
768  phd = NULL;*/
769 
770  return FCD_MODE_APP;
771  }
772 
773  // Read blocks
774  aucBufOut[0] = 0; // Report ID, ignored
775  aucBufOut[1] = FCD_CMD_BL_READ_FLASH_BLOCK;
776  for (u32Addr=u32AddrStart; u32Addr+47<u32AddrEnd && u32Addr+47<n64Size; u32Addr+=48)
777  {
778  hid_write(phd, aucBufOut, 65);
779  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
780  hid_read(phd, aucBufIn, 65);
781 
782  if (aucBufIn[0]!=FCD_CMD_BL_READ_FLASH_BLOCK || aucBufIn[1]!=1)
783  {
784  /*
785  fcdClose(phd);
786  phd = NULL;*/
787 
788  return FCD_MODE_APP;
789  }
790 
791  if (memcmp(&aucBufIn[2],&pc[u32Addr],48)!=0)
792  {
793  /*
794  fcdClose(phd);
795  phd = NULL;*/
796 
797  return FCD_MODE_APP;
798  }
799  }
800 
801  /*
802  fcdClose(phd);
803  phd = NULL;*/
804 
805  return FCD_MODE_BL;
806 }
#define FCD_CMD_BL_GET_BYTE_ADDR_RANGE
Definition: fcdhidcmd.h:30
#define FCD_CMD_BL_SET_BYTE_ADDR
Definition: fcdhidcmd.h:29
unsigned int uint32_t
Definition: rtptypes_win.h:46
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
#define FCD_CMD_BL_READ_FLASH_BLOCK
Definition: fcdhidcmd.h:32
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdBlWriteFirmware()

FCD_MODE_ENUM fcdBlWriteFirmware ( hid_device phd,
char *  pc,
int64_t  n64Size 
)

Write new firmware into the FCD.

Parameters
pcPointer to the new firmware data
n64sizeThe number of bytes in the data
Returns
The FCD mode

This function is used to upload new firmware into the FCD flash.

See also
fcdBlErase

Definition at line 606 of file fcdhid.c.

References FCD_CMD_BL_GET_BYTE_ADDR_RANGE, FCD_CMD_BL_SET_BYTE_ADDR, FCD_CMD_BL_WRITE_FLASH_BLOCK, FCD_MODE_APP, FCD_MODE_BL, hid_read(), and hid_write().

607 {
608  //hid_device *phd=NULL;
609  unsigned char aucBufIn[65];
610  unsigned char aucBufOut[65];
611  uint32_t u32AddrStart;
612  uint32_t u32AddrEnd;
613  uint32_t u32Addr;
614 
615  /*
616  phd = fcdOpen();
617 
618  if (phd==NULL)
619  {
620  return FCD_MODE_NONE;
621  }*/
622 
623  // Get the valid flash address range
624  aucBufOut[0] = 0; // Report ID, ignored
625  aucBufOut[1] = FCD_CMD_BL_GET_BYTE_ADDR_RANGE;
626  hid_write(phd, aucBufOut, 65);
627  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
628  hid_read(phd, aucBufIn, 65);
629 
630  if (aucBufIn[0]!=FCD_CMD_BL_GET_BYTE_ADDR_RANGE || aucBufIn[1]!=1)
631  {
632  /*
633  fcdClose(phd);
634  phd = NULL;*/
635 
636  return FCD_MODE_APP;
637  }
638 
639  u32AddrStart=
640  aucBufIn[2]+
641  (((uint32_t)aucBufIn[3])<<8)+
642  (((uint32_t)aucBufIn[4])<<16)+
643  (((uint32_t)aucBufIn[5])<<24);
644  u32AddrEnd=
645  aucBufIn[6]+
646  (((uint32_t)aucBufIn[7])<<8)+
647  (((uint32_t)aucBufIn[8])<<16)+
648  (((uint32_t)aucBufIn[9])<<24);
649 
650  // Set start address for flash
651  aucBufOut[0] = 0; // Report ID, ignored
652  aucBufOut[1] = FCD_CMD_BL_SET_BYTE_ADDR;
653  aucBufOut[2] = ((unsigned char)u32AddrStart);
654  aucBufOut[3] = ((unsigned char)(u32AddrStart>>8));
655  aucBufOut[4] = ((unsigned char)(u32AddrStart>>16));
656  aucBufOut[5] = ((unsigned char)(u32AddrStart>>24));
657  hid_write(phd, aucBufOut, 65);
658  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
659  hid_read(phd, aucBufIn, 65);
660 
661  if (aucBufIn[0]!=FCD_CMD_BL_SET_BYTE_ADDR || aucBufIn[1]!=1)
662  {
663  /*
664  fcdClose(phd);
665  phd = NULL;*/
666 
667  return FCD_MODE_APP;
668  }
669 
670  // Write blocks
671  aucBufOut[0] = 0; // Report ID, ignored
672  aucBufOut[1] = FCD_CMD_BL_WRITE_FLASH_BLOCK;
673  for (u32Addr=u32AddrStart; u32Addr+47<u32AddrEnd && u32Addr+47<n64Size; u32Addr+=48)
674  {
675  memcpy(&aucBufOut[3], &pc[u32Addr], 48);
676 
677  hid_write(phd, aucBufOut, 65);
678  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
679  hid_read(phd, aucBufIn, 65);
680 
681  if (aucBufIn[0]!=FCD_CMD_BL_WRITE_FLASH_BLOCK || aucBufIn[1]!=1)
682  {
683  /*
684  fcdClose(phd);
685  phd = NULL;*/
686 
687  return FCD_MODE_APP;
688  }
689  }
690 
691  /*
692  fcdClose(phd);
693  phd = NULL;*/
694 
695  return FCD_MODE_BL;
696 }
#define FCD_CMD_BL_GET_BYTE_ADDR_RANGE
Definition: fcdhidcmd.h:30
#define FCD_CMD_BL_SET_BYTE_ADDR
Definition: fcdhidcmd.h:29
#define FCD_CMD_BL_WRITE_FLASH_BLOCK
Definition: fcdhidcmd.h:31
unsigned int uint32_t
Definition: rtptypes_win.h:46
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdClose()

void fcdClose ( hid_device phd)

Close FCD HID device.

Definition at line 78 of file fcdhid.c.

References hid_close().

Referenced by FCDProPlusInput::closeDevice(), and FCDProInput::closeDevice().

79 {
80  hid_close(phd);
81 }
void HID_API_EXPORT hid_close(hid_device *dev)
Close a HID device.
Definition: hid-libusb.c:1157
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fcdGetCaps()

FCD_MODE_ENUM fcdGetCaps ( hid_device phd,
FCD_CAPS_STRUCT fcd_caps 
)

Get hardware and firmware dependent FCD capabilities.

Parameters
fcd_capsPointer to an FCD_CAPS_STRUCT
Returns
The current FCD mode.

This function queries the FCD and extracts the hardware and firmware dependent capabilities. Currently these capabilities are:

  • Bias T (available since S/N TBD)
  • Cellular block (the certified version of the FCD) When the FCD is in application mode, the string returned by the query command is (starting at index 2): FCDAPP 18.08 Brd 1.0 No blk 1.0 means no bias tee, 1.1 means there is a bias tee 'No blk' means it is not cellular blocked.

Ref: http://uk.groups.yahoo.com/group/FCDevelopment/message/303

Definition at line 205 of file fcdhid.c.

References FCD_CMD_BL_QUERY, FCD_MODE_APP, FCD_MODE_BL, FCD_MODE_NONE, FCD_CAPS_STRUCT::hasBiasT, FCD_CAPS_STRUCT::hasCellBlock, hid_read(), and hid_write().

206 {
207  //hid_device *phd=NULL;
208  unsigned char aucBufIn[65];
209  unsigned char aucBufOut[65];
210  FCD_MODE_ENUM fcd_mode = FCD_MODE_NONE;
211 
212  /* clear output buffer */
213  fcd_caps->hasBiasT = 0;
214  fcd_caps->hasCellBlock = 0;
215 
216  /*
217  phd = fcdOpen();
218 
219  if (phd == NULL)
220  {
221  return FCD_MODE_NONE;
222  }*/
223 
224  /* Send a BL Query Command */
225  aucBufOut[0] = 0; // Report ID, ignored
226  aucBufOut[1] = FCD_CMD_BL_QUERY;
227  hid_write(phd, aucBufOut, 65);
228  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
229  hid_read(phd, aucBufIn, 65);
230 
231  /*
232  fcdClose(phd);
233  phd = NULL;*/
234 
235  /* first check status bytes then check which mode */
236  if (aucBufIn[0]==FCD_CMD_BL_QUERY && aucBufIn[1]==1) {
237 
238  /* In bootloader mode we have the string "FCDBL" starting at acBufIn[2] **/
239  if (strncmp((char *)(aucBufIn+2), "FCDBL", 5) == 0) {
240  fcd_mode = FCD_MODE_BL;
241  }
242  /* In application mode we have "FCDAPP 18.08 Brd 1.0 No blk" (see API doc) */
243  else if (strncmp((char *)(aucBufIn+2), "FCDAPP", 6) == 0) {
244 
245  /* Bias T */
246  fcd_caps->hasBiasT = (aucBufIn[21] == '1') ? 1 : 0;
247 
248  /* cellular block */
249  if (strncmp((char *)(aucBufIn+23), "No blk", 6) == 0) {
250  fcd_caps->hasCellBlock = 0;
251  } else {
252  fcd_caps->hasCellBlock = 1;
253  }
254 
255  fcd_mode = FCD_MODE_APP;
256  }
257  /* either no FCD or firmware less than 18f */
258  else {
259  fcd_mode = FCD_MODE_NONE;
260  }
261  }
262 
263  return fcd_mode;
264 }
unsigned char hasBiasT
Definition: fcdhid.h:49
#define FCD_CMD_BL_QUERY
Definition: fcdhidcmd.h:26
FCD_MODE_ENUM
FCD mode enumeration.
Definition: fcdhid.h:40
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
unsigned char hasCellBlock
Definition: fcdhid.h:50
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdGetCapsStr()

FCD_MODE_ENUM fcdGetCapsStr ( hid_device phd,
char *  caps_str 
)

Get hardware and firmware dependent FCD capabilities as string.

Parameters
caps_strPointer to a pre-allocated string buffer where the info will be copied.
Returns
The current FCD mode.

This function queries the FCD and copies the returned string into the caps_str parameter. THe return buffer must be at least 28 characters. When the FCD is in application mode, the string returned by the query command is (starting at index 2): FCDAPP 18.08 Brd 1.0 No blk 1.0 means no bias tee, 1.1 means there is a bias tee 'No blk' means it is not cellular blocked.

Ref: http://uk.groups.yahoo.com/group/FCDevelopment/message/303

Definition at line 281 of file fcdhid.c.

References FCD_CMD_BL_QUERY, FCD_MODE_APP, FCD_MODE_BL, FCD_MODE_NONE, hid_read(), and hid_write().

282 {
283  //hid_device *phd=NULL;
284  unsigned char aucBufIn[65];
285  unsigned char aucBufOut[65];
286  FCD_MODE_ENUM fcd_mode = FCD_MODE_NONE;
287 
288  /*
289  phd = fcdOpen();
290 
291  if (phd == NULL)
292  {
293  return FCD_MODE_NONE;
294  }*/
295 
296  /* Send a BL Query Command */
297  aucBufOut[0] = 0; // Report ID, ignored
298  aucBufOut[1] = FCD_CMD_BL_QUERY;
299  hid_write(phd, aucBufOut, 65);
300  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
301  hid_read(phd, aucBufIn, 65);
302 
303  /*
304  fcdClose(phd);
305  phd = NULL;*/
306 
307  /* first check status bytes then check which mode */
308  if (aucBufIn[0]==FCD_CMD_BL_QUERY && aucBufIn[1]==1) {
309 
310  /* In bootloader mode we have the string "FCDBL" starting at acBufIn[2] **/
311  if (strncmp((char *)(aucBufIn+2), "FCDBL", 5) == 0) {
312  fcd_mode = FCD_MODE_BL;
313  }
314  /* In application mode we have "FCDAPP 18.08 Brd 1.0 No blk" (see API doc) */
315  else if (strncmp((char *)(aucBufIn+2), "FCDAPP", 6) == 0) {
316 
317  strncpy(caps_str, (char *)(aucBufIn+2), 27);
318  caps_str[27] = 0;
319 
320  fcd_mode = FCD_MODE_APP;
321  }
322  /* either no FCD or firmware less than 18f */
323  else {
324  fcd_mode = FCD_MODE_NONE;
325  }
326  }
327 
328  return fcd_mode;
329 }
#define FCD_CMD_BL_QUERY
Definition: fcdhidcmd.h:26
FCD_MODE_ENUM
FCD mode enumeration.
Definition: fcdhid.h:40
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdGetFwVerStr()

FCD_MODE_ENUM fcdGetFwVerStr ( hid_device phd,
char *  str 
)

Get FCD firmware version as string.

Parameters
strThe returned vesion number as a 0 terminated string (must be pre-allocated)
Returns
The current FCD mode.
See also
FCD_MODE_ENUM

Definition at line 140 of file fcdhid.c.

References FCD_CMD_BL_QUERY, FCD_MODE_APP, FCD_MODE_BL, FCD_MODE_NONE, hid_read(), and hid_write().

141 {
142  //hid_device *phd=NULL;
143  unsigned char aucBufIn[65];
144  unsigned char aucBufOut[65];
145  FCD_MODE_ENUM fcd_mode = FCD_MODE_NONE;
146 
147  /*
148  phd = fcdOpen();
149 
150  if (phd == NULL)
151  {
152  return FCD_MODE_NONE;
153  }*/
154 
155  /* Send a BL Query Command */
156  aucBufOut[0] = 0; // Report ID, ignored
157  aucBufOut[1] = FCD_CMD_BL_QUERY;
158  hid_write(phd, aucBufOut, 65);
159  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
160  hid_read(phd, aucBufIn, 65);
161 
162  /*
163  fcdClose(phd);
164  phd = NULL;*/
165 
166  /* first check status bytes then check which mode */
167  if (aucBufIn[0]==FCD_CMD_BL_QUERY && aucBufIn[1]==1) {
168 
169  /* In bootloader mode we have the string "FCDBL" starting at acBufIn[2] **/
170  if (strncmp((char *)(aucBufIn+2), "FCDBL", 5) == 0) {
171  fcd_mode = FCD_MODE_BL;
172  }
173  /* In application mode we have "FCDAPP_18.06" where the number is the FW version */
174  else if (strncmp((char *)(aucBufIn+2), "FCDAPP", 6) == 0) {
175  strncpy(str, (char *)(aucBufIn+9), 5);
176  str[5] = 0;
177  fcd_mode = FCD_MODE_APP;
178  }
179  /* either no FCD or firmware less than 18f */
180  else {
181  fcd_mode = FCD_MODE_NONE;
182  }
183  }
184 
185  return fcd_mode;
186 }
#define FCD_CMD_BL_QUERY
Definition: fcdhidcmd.h:26
FCD_MODE_ENUM
FCD mode enumeration.
Definition: fcdhid.h:40
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdGetMode()

FCD_MODE_ENUM fcdGetMode ( hid_device phd)

Get FCD mode.

Returns
The current FCD mode.
See also
FCD_MODE_ENUM

Definition at line 88 of file fcdhid.c.

References FCD_CMD_BL_QUERY, FCD_MODE_APP, FCD_MODE_BL, FCD_MODE_NONE, hid_read(), and hid_write().

89 {
90  //hid_device *phd=NULL;
91  unsigned char aucBufIn[65];
92  unsigned char aucBufOut[65];
93  FCD_MODE_ENUM fcd_mode = FCD_MODE_NONE;
94 
95  /*
96  phd = fcdOpen();
97 
98  if (phd == NULL)
99  {
100  return FCD_MODE_DEAD;
101  }*/
102 
103  /* Send a BL Query Command */
104  aucBufOut[0] = 0; // Report ID, ignored
105  aucBufOut[1] = FCD_CMD_BL_QUERY;
106  hid_write(phd, aucBufOut, 65);
107  memset(aucBufIn, 0xCC, 65); // Clear out the response buffer
108  hid_read(phd, aucBufIn, 65);
109 
110  /*
111  fcdClose(phd);
112  phd = NULL;*/
113 
114  /* first check status bytes then check which mode */
115  if (aucBufIn[0]==FCD_CMD_BL_QUERY && aucBufIn[1]==1) {
116 
117  /* In bootloader mode we have the string "FCDBL" starting at acBufIn[2] **/
118  if (strncmp((char *)(aucBufIn+2), "FCDBL", 5) == 0) {
119  fcd_mode = FCD_MODE_BL;
120  }
121  /* In application mode we have "FCDAPP_18.06" where the number is the FW version */
122  else if (strncmp((char *)(aucBufIn+2), "FCDAPP", 6) == 0) {
123  fcd_mode = FCD_MODE_APP;
124  }
125  /* either no FCD or firmware less than 18f */
126  else {
127  fcd_mode = FCD_MODE_NONE;
128  }
129  }
130 
131  return fcd_mode;
132 }
#define FCD_CMD_BL_QUERY
Definition: fcdhidcmd.h:26
FCD_MODE_ENUM
FCD mode enumeration.
Definition: fcdhid.h:40
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid-libusb.c:1083
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid-libusb.c:925
+ Here is the call graph for this function:

◆ fcdOpen()

hid_device* fcdOpen ( uint16_t  usVID,
uint16_t  usPID,
int  whichdongle 
)

Open FCD device.

Returns
Pointer to the FCD HID device or NULL if none found

This function looks for FCD devices connected to the computer and opens the first one found.

Definition at line 31 of file fcdhid.c.

References hid_enumerate(), hid_free_enumeration(), hid_open_path(), hid_device_info::next, and hid_device_info::path.

Referenced by FCDProPlusInput::openDevice(), and FCDProInput::openDevice().

32 {
33  struct hid_device_info *phdi=NULL;
34  hid_device *phd=NULL;
35  char *pszPath=NULL;
36 
37  phdi = hid_enumerate(usVID, usPID);
38 
39  int which = whichdongle;
40 
41  while (phdi && which)
42  {
43  phdi=phdi->next;
44  which--;
45  }
46 
47  if (phdi==NULL)
48  {
49  return NULL; // No FCD device found
50  }
51 
52  pszPath=strdup(phdi->path);
53 
54  if (pszPath==NULL)
55  {
56  return NULL;
57  }
58 
60  phdi=NULL;
61 
62  if ((phd=hid_open_path(pszPath)) == NULL)
63  {
64  free(pszPath);
65  pszPath=NULL;
66 
67  return NULL;
68  }
69 
70  free(pszPath);
71  pszPath=NULL;
72 
73  return phd;
74 }
char * path
Definition: hidapi.h:51
struct hid_device_info * next
Definition: hidapi.h:78
hid_device *HID_API_EXPORT hid_open_path(const char *path)
Open a HID device by its path name.
Definition: hid-libusb.c:792
struct hid_device_info HID_API_EXPORT * hid_enumerate(unsigned short vendor_id, unsigned short product_id)
Enumerate the HID Devices.
Definition: hid-libusb.c:444
void HID_API_EXPORT hid_free_enumeration(struct hid_device_info *devs)
Free an enumeration Linked List.
Definition: hid-libusb.c:605
+ Here is the call graph for this function:
+ Here is the caller graph for this function: