memory_table_group.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #include <stdio.h>
  2. #define SCPI_ARGS_N 1
  3. #define SCPI_ARGS_MANDATORY_N 0
  4. #include "app/scpi/scpi_handler.h"
  5. const uint8_t fsqvbl_CommandHandlerMemoryTableAnalyzer = 1; // MEMory:TABLe:ANALyzer
  6. const uint8_t fsqvbl_CommandHandlerMemoryTableDate = 2; // MEMory:TABLe:DATE
  7. const uint8_t fsqvbl_CommandHandlerMemoryTableOperator = 3; // MEMory:TABLe:OPERator
  8. const uint8_t fsqvbl_CommandHandlerMemoryTablePlace = 4; // MEMory:TABLe:PLACe
  9. const uint8_t fsqvbl_CommandHandlerMemoryTablePoints = 5; // MEMory:TABLe:POINts
  10. const uint8_t fsqvbl_CommandHandlerMemoryTableTemperature = 6; // MEMory:TABLe:TEMPerature
  11. const uint8_t fsqvbl_CommandHandlerMemoryTableTime = 7; // MEMory:TABLe:TIME
  12. const uint8_t fsqvbl_CommandHandlerMemoryTableFrequencyStart = 8; // MEMory:TABLe:FREQuency:STARt
  13. const uint8_t fsqvbl_CommandHandlerMemoryTableFrequencyStop = 9; // MEMory:TABLe:FREQuency:STOP
  14. const uint8_t fsqvbl_CommandHandlerMemoryTableFrequencyType = 10; // MEMory:TABLe:FREQuency:TYPE
  15. // -----
  16. // @argTokens, @argTypes
  17. // Declare argument parser entities
  18. // Supported arguments: 1=CHARACTER
  19. DECLARE_SCPI_ARGS( eScpiArg_Character );
  20. // Argument 1 Character Values allowed list / Memory Bank
  21. DECLARE_ARGUMENT_CHARACTER_ALLOWED_LIST_IMPORT( MemTable_AllowedValues_Bank )
  22. #include "app/scpi/commandHandlers/memory_table_group.h"
  23. #include "app/nfm/nfm_base.h"
  24. // Refer to:
  25. // [1] SCPI Specification, revision 1999.0
  26. // "Standard Commands for Programmable Instruments (SCPI), VERSION 1999.0, May 1999"
  27. // [2] Gpib Programming Tutorial, (http://g2pc1.bu.edu/~qzpeng/gpib/manual/GpibProgTut.pdf)
  28. // Electronics Group (http://www.few.vu.nl/~elec), 11 January 2000 Electronics Group
  29. // [3] IEEE 488.2 Standard, revision IEEE Std 488.2-1987 (1992)
  30. // "IEEE Standard Codes, Formats, Protocols, and Common Commands for Use With IEEE Std 488.1-1987, IEEE
  31. // =================================================================================
  32. // @fsqvbl_CommandHandlerMemoryTableAnalyzer
  33. // State's virtual table
  34. static void fsqe_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  35. static void fsql_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  36. static const struct fFSeqEntry_t * fsqf_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx, const struct fFSeqEntry_t * * pDeferredNext );
  37. const fFSeqVTable_t fsqvbl_CommandHandlerMEMoryTABLe_group =
  38. {
  39. .f = fsqf_CommandHandlerMemoryTable_Group,
  40. .enter = fsqe_CommandHandlerMemoryTable_Group,
  41. .leave = fsql_CommandHandlerMemoryTable_Group
  42. };
  43. static void fsqe_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  44. {
  45. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  46. SCPI_PARSE_ARGUMENTS( common_ctx ); (void)common_ctx->argsParserStatus; // status is modified
  47. common_ctx->MemTableCommon.idx = 0;
  48. common_ctx->MemTableCommon.bank = 0;
  49. common_ctx->MemTableCommon.port = 0;
  50. }
  51. static void fsql_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  52. {
  53. }
  54. static const struct fFSeqEntry_t * fsqf_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this,
  55. tFSeqCtx_t ctx,
  56. const struct fFSeqEntry_t * * pDeferredNext )
  57. {
  58. const fFSeqEntry_t * nextstate = NULL;
  59. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  60. sScpiParserContext_t * global_ctx = common_ctx->global_ctx;
  61. switch( common_ctx->event )
  62. {
  63. case eProgramData_Event_Write:
  64. {
  65. if( ! common_ctx->isQuery )
  66. {
  67. common_ctx->status = eProgramDataSyntaxError; // invalid command header type: COMMAND not supported
  68. }
  69. else if( eScpiStatus_success != common_ctx->argsParserStatus ) // check argument parser status
  70. {
  71. common_ctx->status = eProgramDataArgumentSyntax; // parameter syntax error, caller should generate error message
  72. }
  73. else
  74. {
  75. common_ctx->status = eProgramDataIllegalArgument; // forward set, illegal parameter value, caller should generate error message
  76. // check count of arguments
  77. if( common_ctx->args > 0 )
  78. {
  79. // process first argument (bank)
  80. common_ctx->MemTableCommon.bank = SCPI_PROCESS_ARGUMENT_CHARACTER( common_ctx, MemTable_AllowedValues_Bank, 0 );
  81. }
  82. else
  83. {
  84. // first argument (bank)
  85. common_ctx->MemTableCommon.bank = 0; // FACTORY (default)
  86. }
  87. // check result
  88. if( SCPI_ARGUMENT_CHARACTER_INVALID_ID != common_ctx->MemTableCommon.bank )
  89. {
  90. common_ctx->status = eProgramDataNeedRead; // request processed, wait for reading...
  91. }
  92. }
  93. }
  94. break;
  95. case eProgramData_Event_Read:
  96. {
  97. // @idx - current position of the source data to be outputed
  98. if( common_ctx->MemTableCommon.idx == 0 ) // first reading
  99. {
  100. eChrz_t bank = (eChrz_t)((eChFactory) + common_ctx->MemTableCommon.bank);
  101. size_t length = 0;
  102. bool number = false;
  103. bool rc = false;
  104. if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableAnalyzer )
  105. {
  106. rc = NFMClass->methods.xCharacterization.getAnalyzer( bank,
  107. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  108. &length );
  109. }
  110. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableDate )
  111. {
  112. rc = NFMClass->methods.xCharacterization.getDate( bank,
  113. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  114. &length );
  115. }
  116. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableOperator )
  117. {
  118. rc = NFMClass->methods.xCharacterization.getOperator( bank,
  119. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  120. &length );
  121. }
  122. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTablePlace )
  123. {
  124. rc = NFMClass->methods.xCharacterization.getPlace( bank,
  125. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  126. &length );
  127. }
  128. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTablePoints )
  129. {
  130. int16_t points = 0; number = true;
  131. rc = NFMClass->methods.xCharacterization.getPointsCountSafe( bank, &points );
  132. if( rc ) length = _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%d", points );
  133. }
  134. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableTemperature )
  135. {
  136. double temp = 0.0; number = true;
  137. rc = NFMClass->methods.xCharacterization.getChrzTemp( bank, &temp );
  138. if( rc ) length = _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%.4f", temp );
  139. }
  140. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableTime )
  141. {
  142. rc = NFMClass->methods.xCharacterization.getTime( bank,
  143. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  144. &length );
  145. }
  146. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableFrequencyStart )
  147. {
  148. double freq = 0.0; number = true;
  149. rc = NFMClass->methods.xCharacterization.getStartFreq( bank, &freq );
  150. if( rc ) length = _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%1.8E", freq );
  151. }
  152. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableFrequencyStop )
  153. {
  154. double freq = 0.0; number = true;
  155. rc = NFMClass->methods.xCharacterization.getStopFreq( bank, &freq );
  156. if( rc ) length = _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%1.8E", freq );
  157. }
  158. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableFrequencyType )
  159. {
  160. eChrzScaleType_t type = eChScale_undefined;
  161. rc = NFMClass->methods.xCharacterization.getScaleType( bank, &type );
  162. if( rc )
  163. {
  164. switch( type )
  165. {
  166. case eChScaleLinear:
  167. length = _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%s", "LIN" );
  168. break;
  169. case eChScaleSegment:
  170. length = _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%s", "SEGM" );
  171. break;
  172. default: rc = false;
  173. }
  174. }
  175. }
  176. if( rc )
  177. {
  178. if( length == 0 )
  179. {
  180. if( number )
  181. {
  182. common_ctx->tempBuffer[0] = '0';
  183. length = 1;
  184. }
  185. else
  186. {
  187. common_ctx->tempBuffer[0] = '\'';
  188. common_ctx->tempBuffer[1] = ' ';
  189. common_ctx->tempBuffer[2] = '\'';
  190. length = 3;
  191. }
  192. }
  193. // place null-terminator in the end of line
  194. common_ctx->tempBuffer[length] = '\0';
  195. }
  196. else
  197. {
  198. // Formal call: in case the parameter is optional, the token is unfilled.
  199. // So it is required to fill the token with correct values from allowed list.
  200. SCPI_ARGUMENT_CHARACTER_VALUE_TOKEN( MemTable_AllowedValues_Bank,
  201. common_ctx->MemTableCommon.bank,
  202. &common_ctx->argTokens[0] );
  203. fsq_RaiseErrorEx( SCPI_ERROR_CHRZ_DATA_NOTFOUND,
  204. SCPI_ERROR_CHRZ_DATA_NOTFOUND_MSG,
  205. common_ctx->argTokens[0].shead,
  206. common_ctx->argTokens[0].stail,
  207. global_ctx->sParser.xHandlerToken.shead,
  208. global_ctx->sParser.xHandlerToken.stail );
  209. common_ctx->status = eProgramData_SpecificError; // specific error already generated
  210. break;
  211. }
  212. }
  213. // Since @done flag is set, this dispatcher shall not be called anymore.
  214. // Since this handler is implemented as a single-state automat, there no
  215. // ... other states to go to:
  216. (void)nextstate;
  217. // modify current postion index:
  218. SCPI_RESPONSE_HELPER( common_ctx, common_ctx->MemTableCommon.idx );
  219. }
  220. break;
  221. }
  222. return nextstate;
  223. }