memory_table_freq_group.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. // -----
  13. // @argTokens, @argTypes
  14. // Declare argument parser entities
  15. // Supported arguments: 1=CHARACTER
  16. DECLARE_SCPI_ARGS( eScpiArg_Character );
  17. // Argument 1 Character Values allowed list / Memory Bank
  18. DECLARE_ARGUMENT_CHARACTER_ALLOWED_LIST_IMPORT( MemTable_AllowedValues_Bank )
  19. #include "app/scpi/commandHandlers/memory_table_group.h"
  20. #include "app/acm/acm_base.h"
  21. // Refer to:
  22. // [1] SCPI Specification, revision 1999.0
  23. // "Standard Commands for Programmable Instruments (SCPI), VERSION 1999.0, May 1999"
  24. // [2] Gpib Programming Tutorial, (http://g2pc1.bu.edu/~qzpeng/gpib/manual/GpibProgTut.pdf)
  25. // Electronics Group (http://www.few.vu.nl/~elec), 11 January 2000 Electronics Group
  26. // [3] IEEE 488.2 Standard, revision IEEE Std 488.2-1987 (1992)
  27. // "IEEE Standard Codes, Formats, Protocols, and Common Commands for Use With IEEE Std 488.1-1987, IEEE
  28. // =================================================================================
  29. // @fsqvbl_CommandHandlerMemoryTableAnalyzer
  30. // State's virtual table
  31. static void fsqe_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  32. static void fsql_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  33. static const struct fFSeqEntry_t * fsqf_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx, const struct fFSeqEntry_t * * pDeferredNext );
  34. const fFSeqVTable_t fsqvbl_CommandHandlerMEMoryTABLe_group =
  35. {
  36. .f = fsqf_CommandHandlerMemoryTable_Group,
  37. .enter = fsqe_CommandHandlerMemoryTable_Group,
  38. .leave = fsql_CommandHandlerMemoryTable_Group
  39. };
  40. static void fsqe_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  41. {
  42. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  43. SCPI_PARSE_ARGUMENTS( common_ctx ); (void)common_ctx->argsParserStatus; // status is modified
  44. common_ctx->MemTableCommon.idx = 0;
  45. }
  46. static void fsql_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  47. {
  48. }
  49. static const struct fFSeqEntry_t * fsqf_CommandHandlerMemoryTable_Group( const struct fFSeqEntry_t * this,
  50. tFSeqCtx_t ctx,
  51. const struct fFSeqEntry_t * * pDeferredNext )
  52. {
  53. const fFSeqEntry_t * nextstate = NULL;
  54. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  55. sScpiParserContext_t * global_ctx = common_ctx->global_ctx;
  56. switch( common_ctx->event )
  57. {
  58. case eProgramData_Event_Write:
  59. {
  60. if( ! common_ctx->isQuery )
  61. {
  62. common_ctx->status = eProgramDataSyntaxError; // invalid command header type: COMMAND not supported
  63. }
  64. else if( eScpiStatus_success != common_ctx->argsParserStatus ) // check argument parser status
  65. {
  66. common_ctx->status = eProgramDataArgumentSyntax; // parameter syntax error, caller should generate error message
  67. }
  68. else
  69. {
  70. common_ctx->status = eProgramDataIllegalArgument; // forward set, illegal parameter value, caller should generate error message
  71. // check count of arguments
  72. if( common_ctx->args > 0 )
  73. {
  74. // process first argument (bank)
  75. common_ctx->MemTableCommon.bank = SCPI_PROCESS_ARGUMENT_CHARACTER( common_ctx, MemTable_AllowedValues_Bank, 0 );
  76. }
  77. else
  78. {
  79. // first argument (bank)
  80. common_ctx->MemTableCommon.bank = 0; // FACTORY (default)
  81. }
  82. // check result
  83. if( SCPI_ARGUMENT_CHARACTER_INVALID_ID != common_ctx->MemTableCommon.bank )
  84. {
  85. common_ctx->status = eProgramDataNeedRead; // request processed, wait for reading...
  86. }
  87. }
  88. }
  89. break;
  90. case eProgramData_Event_Read:
  91. {
  92. // @idx - current position of the source data to be outputed
  93. if( common_ctx->MemTableCommon.idx == 0 ) // first reading
  94. {
  95. eChrz_t bank = (eChrz_t)((eChFactory) + common_ctx->MemTableCommon.bank);
  96. size_t length = 0;
  97. bool rc = false;
  98. if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableAnalyzer )
  99. {
  100. rc = ACMClass->methods.xCharacterization.getAnalyzer( bank,
  101. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  102. &length );
  103. }
  104. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableDate )
  105. {
  106. rc = ACMClass->methods.xCharacterization.getDate( bank,
  107. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  108. &length );
  109. }
  110. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableOperator )
  111. {
  112. rc = ACMClass->methods.xCharacterization.getOperator( bank,
  113. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  114. &length );
  115. }
  116. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTablePlace )
  117. {
  118. rc = ACMClass->methods.xCharacterization.getPlace( bank,
  119. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  120. &length );
  121. }
  122. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTablePoints )
  123. {
  124. size_t points = 0;
  125. rc = ACMClass->methods.xCharacterization.getPointsCountSafe( bank, &points );
  126. if( rc ) length = snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%d", points );
  127. }
  128. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableTemperature )
  129. {
  130. double temp = 0.0;
  131. rc = ACMClass->methods.xCharacterization.getChrzTemp( bank, &temp );
  132. if( rc ) length = snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%.4f", temp );
  133. }
  134. else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMemoryTableTime )
  135. {
  136. rc = ACMClass->methods.xCharacterization.getTime( bank,
  137. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  138. &length );
  139. }
  140. if( rc )
  141. {
  142. if( length == 0 )
  143. {
  144. common_ctx->tempBuffer[0] = '\'';
  145. common_ctx->tempBuffer[1] = ' ';
  146. common_ctx->tempBuffer[2] = '\'';
  147. length = 3;
  148. }
  149. // place null-terminator in the end of line
  150. common_ctx->tempBuffer[length] = '\0';
  151. }
  152. else
  153. {
  154. fsq_RaiseErrorEx( SCPI_ERROR_CHRZ_DATA_NOTFOUND,
  155. SCPI_ERROR_CHRZ_DATA_NOTFOUND_MSG,
  156. common_ctx->argTokens[1].shead,
  157. common_ctx->argTokens[1].stail,
  158. global_ctx->sParser.xHandlerToken.shead,
  159. global_ctx->sParser.xHandlerToken.stail );
  160. common_ctx->status = eProgramData_SpecificError; // specific error already generated
  161. break;
  162. }
  163. }
  164. // Since @done flag is set, this dispatcher shall not be called anymore.
  165. // Since this handler is implemented as a single-state automat, there no
  166. // ... other states to go to:
  167. (void)nextstate;
  168. // modify current postion index:
  169. SCPI_RESPONSE_HELPER( common_ctx, common_ctx->MemTableCommon.idx );
  170. }
  171. break;
  172. }
  173. return nextstate;
  174. }