gpib_parser.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #ifndef _GPIB_PARSER_
  2. #define _GPIB_PARSER_
  3. //---------------------------------------------------------------------------
  4. #include <string.h> // uses strcmp(), strstr()
  5. //#include <acmmem.h> // uses strcmp(), strstr()
  6. #include "gpib_parser_casts.h"
  7. #include "gpib_parser_validators.h"
  8. #include "gpib_parser_numutils.h"
  9. #include "gpib_parser_strutils.h"
  10. // ERROR_USBTMC_*
  11. // Standard USBTMC error codes
  12. #define ERROR_USBTMC_DATANOTFOUND 1
  13. #define ERROR_USBTMC_NOTHERMCOMPDATA 2
  14. #define ERROR_USBTMC_ARRAY_CORRUPTED 3
  15. #define ERROR_USBTMC_TOOMANY_REQUESTS 4
  16. #define ERROR_USBTMC_INTERNAL 5
  17. //#define ERROR_USBTMC_BUFFER_OVERFLOW_OUT 6
  18. //#define ERROR_USBTMC_BUFFER_OVERFLOW_IN 7
  19. // #define ERROR_USBTMC_HEADER_CORRUPTED 8
  20. #define ERROR_USBTMC_COMMANDONLY -110
  21. #define ERROR_USBTMC_REQUESTONLY -110
  22. #define ERROR_USBTMC_INVALID_HEADER -110
  23. #define ERROR_USBTMC_EXECUTION -102
  24. #define ERROR_USBTMC_PARAMETER -220
  25. #define ERROR_USBTMC_TRIGGERIGNORED -211
  26. // The state machine: the ESR register bits
  27. #define GPIB_ERROR_ID_COR (0x80000000) // Command or Request, (GPIB_ERROR_ID_COR|0x00000001) === Request
  28. #define GPIB_ERROR_ID_EXE (0x40000000) // Execution Error
  29. // Internal error codes:
  30. #define ERROR_GPIB_INTERNAL 1
  31. #define ERROR_GPIB_WRONG_PARAMETERS_COUNT 2
  32. #define ERROR_GPIB_INVALID_PARAMETER 3
  33. #define ERROR_GPIB_REQUEST_ONLY_SUPPORT 4
  34. #define ERROR_GPIB_INVALID_PARAMETER_TYPE 5
  35. // #define ERROR_GPIB_PARAMETER_NOT_SUPPORTED 6 // not used
  36. #define ERROR_GPIB_DATA_NOT_FOUND 7
  37. #define ERROR_GPIB_COMMAND_ONLY_SUPPORT 8
  38. #define ERROR_GPIB_BUFFER_OVERFLOW 9
  39. #define ERROR_GPIB_ARRAY_CORRUPTED 10
  40. #define ERROR_GPIB_TOO_MANY_REQUESTS 11
  41. #define ERROR_GPIB_THERMDATA_NOT_FOUND 12
  42. #define ERROR_GPIB_UNCOMPLETE_COMMAND 13
  43. #define ERROR_GPIB_TRIGGER_IGNORED 14
  44. #define ERROR_GPIB_INVALID_ENUM_PARAMETERS 15
  45. //#define ERROR_GPIB_HEADER_CORRUPTED 16
  46. typedef unsigned int ( * TCmdParser_f)( USB_DEVICE_INFO *, QUEUE *, BOOL );
  47. typedef enum
  48. {
  49. eParTypeNone,
  50. eParTypeNR1, // SCPI Parameter type NR1, integer (positive, zero, negative), "-17", "2", "7", "0", "46"
  51. eParTypeNR2, // SCPI Parameter type NR2, float (positive, zero, negative), "-17.0", "2.7", "0.46"
  52. eParTypeNR3, // SCPI Parameter type NR3, scientific float (positive, zero, negative), "-1.70E+1", "+2.70E+0", "4.60E-1"
  53. eParTypeChar, // SCPI Parameter type CHAR, ASCII character
  54. eParTypeString, // SCPI Parameter type STRING, a wrapped with single or double quote sequence of CHAR's, must begin with a queue and must end with the same quote
  55. eParTypeDatablock // SCPI Parameter type BLOCK, a large quantity of related data
  56. }
  57. eParameterType_t;
  58. // MEMORY_SIZE_PARAMQUEUE:
  59. // The size in bytes of the queue for passing parameters
  60. #define MEMORY_SIZE_PARAMQUEUE RAM_SCPIPARAM_SIZE
  61. #define GPIB_DUMMY_FUNCTION ( GPIB_Default_Handler )
  62. #define GPIB_DEF_FUNCTION ( GPIB_Default_Handler )
  63. // ============================================================================================================
  64. struct __sScpiCommand;
  65. struct __sScpiCommand
  66. {
  67. const char * header; // a command mnemonic (name)
  68. const char * shortheader; // a short command mnemonic
  69. BOOL enablerequest; // the sign if the orignal name is equals to the user-typed name (excluding the last '?'-character)
  70. TCmdParser_f function; // command parser function
  71. unsigned short int childcount; // amount of child commands
  72. unsigned short int childcountmax; // maximum available count of child commands
  73. struct __sScpiCommand * pcommands; // a list of child commands
  74. BOOL bTagArgUsed; // Use a special tag parameter to specialize the handler call
  75. unsigned int xTagArg; // an extra tag parameter for the handler
  76. };
  77. typedef struct __sScpiCommand sScpiCommand_t;
  78. // ============================================================================================================
  79. unsigned int GPIB_Default_Handler( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL req );
  80. unsigned int GPIB_SystemVersion( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL req );
  81. unsigned int GPIB_Identification ( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL req );
  82. unsigned int GPIB_Reset( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  83. unsigned int GPIB_Clear( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  84. unsigned int GPIB_EventStatusEnable( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  85. unsigned int GPIB_EventStatusRegister( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  86. unsigned int GPIB_OperationComplete( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  87. unsigned int GPIB_Trigger( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  88. unsigned int GPIB_Wait( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  89. unsigned int GPIB_InterfaceSwitch( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  90. unsigned int GPIB_SystemError( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  91. unsigned int GPIB_SystemErrorAll( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  92. unsigned int GPIB_StatusOperationEvent( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  93. unsigned int GPIB_StatusOperationCondition( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  94. unsigned int GPIB_StatusOperationEnable( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  95. unsigned int GPIB_StatusQuestionableEvent( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  96. unsigned int GPIB_StatusQuestionableCondition( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  97. unsigned int GPIB_StatusQuestionableEnable( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  98. unsigned int GPIB_StatusPreset( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  99. unsigned int GPIB_GetTemperature( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  100. unsigned int GPIB_SwitchCount( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  101. unsigned int GPIB_SwitchState( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  102. unsigned int GPIB_SwitchList( USB_DEVICE_INFO * udi, QUEUE * pQParametes, BOOL request );
  103. unsigned int GPIB_MemTablePoints( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  104. unsigned int GPIB_MemTableTime( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  105. unsigned int GPIB_MemTableDate( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  106. unsigned int GPIB_MemTableTemp( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  107. unsigned int GPIB_MemTableFields( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  108. unsigned int GPIB_MemTableConn( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  109. unsigned int GPIB_MemTableAdap( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  110. unsigned int GPIB_MemTableAnalyzer( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  111. unsigned int GPIB_MemTablePlace( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  112. unsigned int GPIB_MemTableOperator( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  113. unsigned int GPIB_MemTableData( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  114. unsigned int GPIB_MemTableTherFunction( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  115. unsigned int GPIB_StatusEnableRegister( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  116. unsigned int GPIB_StatusRegister( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  117. eChrz_t GPIB_GetChrzTableId( const char * pParamText, size_t nTextLen );
  118. ePortId_t GPIB_GetPortId( const char * pParamText, size_t nTextLen );
  119. ePortComb_t GPIB_GetPortComb( const char * pParamText, size_t nTextLen );
  120. ePortStateId_t GPIB_GetPortStateId( const char * pParamText, size_t nTextLen );
  121. size_t GPIB_MemoryTablePoints( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  122. size_t GPIB_MemoryTableDate( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  123. size_t GPIB_MemoryTableTime( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  124. size_t GPIB_MemoryTableTemp( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  125. size_t GPIB_MemoryTableFreqType( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  126. size_t GPIB_MemoryTableFreqData( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  127. size_t GPIB_MemoryTableFreqSegmData( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  128. size_t GPIB_MemoryTableFreqStart( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  129. size_t GPIB_MemoryTableFreqStop( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  130. size_t GPIB_MemoryTableConnector( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  131. size_t GPIB_MemoryTableAdapter( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  132. size_t GPIB_MemoryTableAnalyzer( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  133. size_t GPIB_MemoryTablePlace( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  134. size_t GPIB_MemoryTableOperator( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  135. size_t GPIB_MemoryTableData( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  136. size_t GPIB_MemTableTherCorrFreqStart( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  137. size_t GPIB_MemTableTherCorrFreqStop( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  138. size_t GPIB_MemTableTherCorrPoints( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  139. size_t GPIB_MemTableTherCorrPhase( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  140. size_t GPIB_MemTableTherCorrMagniture( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request );
  141. // ============================================================================================================
  142. void GPIB_DevDepInit( USB_DEVICE_INFO * udi );
  143. // GPIB_EnumParameters:
  144. // Processes the @pParamString with @length length and parses the command parameters.
  145. // The following SCPI types are supported:
  146. // - NR1, NR2, NR3
  147. // - Mnemonic (character)
  148. // - Strings
  149. // - binary DataBlock
  150. // All the parameters are packed into the @pQueue
  151. // In case an error occurred, the function interrupts processing and return an error code.
  152. // Note: in case of error the @pQueue is already modified.
  153. // @pParamString - the source string
  154. // @length - the length of @pParamString
  155. // @pQueue - the queue to pack parameters in
  156. // @pEnd - optional pointer to store the end of parsed string after parsing. Can be NULL.
  157. // If @pEnd isn't NULL, it will contain the pointer to the character after the lastest parsed character in @pParamString.
  158. // Return: error code (negative) or number of parsed parameters (positive)
  159. int GPIB_EnumParameters( const char * parstring, size_t strl, QUEUE * pQueue, const char ** pEnd );
  160. int GPIB_CommandExecute( USB_DEVICE_INFO * udi, const char * str );
  161. sScpiCommand_t * GPIB_InitializeAllCommands( void );
  162. unsigned int GPIB_RaiseStandartError( USB_DEVICE_INFO * udi,
  163. unsigned int errCode,
  164. const char * data,
  165. GPIB_ErrorClass_t errClass
  166. );
  167. //char * GPIB_GetStringEnd( char * gpibstr, unsigned int datalen );
  168. //ESTATE GPIB_GetKeystateID( char * sQueueParameter, unsigned int dwQueueParameterSize, BOOL ExpandFormat );
  169. //EPORT GPIB_GetPortID( char * sQueueParameter, unsigned int dwQueueParameterSize );
  170. //char * GPIB_StrChr( char * str, char chr, char * end );
  171. unsigned int GPIBInit( USB_DEVICE_INFO * udi );
  172. #endif