memory_table_adapter.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include <stdio.h>
  2. #define SCPI_ARGS_N 2
  3. #define SCPI_ARGS_MANDATORY_N 1
  4. #include "app/scpi/scpi_handler.h"
  5. // -----
  6. // @argTokens, @argTypes
  7. // Declare argument parser entities
  8. // Supported arguments: 1=CHARACTER, 2=CHARACTER
  9. DECLARE_SCPI_ARGS( eScpiArg_Character, eScpiArg_Character );
  10. // Argument 1 Character Values allowed list / ACM Port
  11. DECLARE_ARGUMENT_CHARACTER_ALLOWED_LIST_EXPORT( MemTable_AllowedValues_Port, "A", "B" );
  12. // Argument 2 Character Values allowed list / Memory Bank
  13. DECLARE_ARGUMENT_CHARACTER_ALLOWED_LIST_EXPORT( MemTable_AllowedValues_Bank, "FACTory", "USER1", "USER2", "USER3" );
  14. #include "app/scpi/commandHandlers/memory_table_adapter.h"
  15. #include "app/nfm/nfm_base.h"
  16. // Refer to:
  17. // [1] SCPI Specification, revision 1999.0
  18. // "Standard Commands for Programmable Instruments (SCPI), VERSION 1999.0, May 1999"
  19. // [2] Gpib Programming Tutorial, (http://g2pc1.bu.edu/~qzpeng/gpib/manual/GpibProgTut.pdf)
  20. // Electronics Group (http://www.few.vu.nl/~elec), 11 January 2000 Electronics Group
  21. // [3] IEEE 488.2 Standard, revision IEEE Std 488.2-1987 (1992)
  22. // "IEEE Standard Codes, Formats, Protocols, and Common Commands for Use With IEEE Std 488.1-1987, IEEE
  23. // =================================================================================
  24. // @fsqvbl_CommandHandlerMemoryTableAdapter
  25. // State's virtual table
  26. static void fsqe_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  27. static void fsql_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  28. static const struct fFSeqEntry_t * fsqf_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx, const struct fFSeqEntry_t * * pDeferredNext );
  29. const fFSeqVTable_t fsqvbl_CommandHandlerMEMoryTABLeADAPter =
  30. {
  31. .f = fsqf_CommandHandlerMemoryTableAdapter,
  32. .enter = fsqe_CommandHandlerMemoryTableAdapter,
  33. .leave = fsql_CommandHandlerMemoryTableAdapter
  34. };
  35. static void fsqe_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  36. {
  37. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  38. SCPI_PARSE_ARGUMENTS( common_ctx ); (void)common_ctx->argsParserStatus; // status is modified
  39. common_ctx->MemTableCommon.idx = 0;
  40. common_ctx->MemTableCommon.bank = 0;
  41. common_ctx->MemTableCommon.port = 0;
  42. }
  43. static void fsql_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  44. {
  45. }
  46. static const struct fFSeqEntry_t * fsqf_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this,
  47. tFSeqCtx_t ctx,
  48. const struct fFSeqEntry_t * * pDeferredNext )
  49. {
  50. const fFSeqEntry_t * nextstate = NULL;
  51. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  52. sScpiParserContext_t * global_ctx = common_ctx->global_ctx;
  53. switch( common_ctx->event )
  54. {
  55. case eProgramData_Event_Write:
  56. {
  57. if( ! common_ctx->isQuery )
  58. {
  59. common_ctx->status = eProgramDataSyntaxError; // invalid command header type: COMMAND not supported
  60. }
  61. else if( eScpiStatus_success != common_ctx->argsParserStatus ) // check argument parser status
  62. {
  63. common_ctx->status = eProgramDataArgumentSyntax; // parameter syntax error, caller should generate error message
  64. }
  65. else
  66. {
  67. common_ctx->status = eProgramDataIllegalArgument; // forward set, illegal parameter value, caller should generate error message
  68. // process first argument (port)
  69. common_ctx->MemTableCommon.port = SCPI_PROCESS_ARGUMENT_CHARACTER( common_ctx, MemTable_AllowedValues_Port, 0 );
  70. // check result
  71. if( SCPI_ARGUMENT_CHARACTER_INVALID_ID == common_ctx->MemTableCommon.port )
  72. {
  73. (void)common_ctx->status; // eProgramDataIllegalArgument
  74. common_ctx->argErrIdx = 0; // specify erroneous argument index: port
  75. break;
  76. }
  77. // check count of arguments
  78. if( common_ctx->args > 1 )
  79. // process secord argument
  80. common_ctx->MemTableCommon.bank = SCPI_PROCESS_ARGUMENT_CHARACTER( common_ctx, MemTable_AllowedValues_Bank, 1 );
  81. else
  82. common_ctx->MemTableCommon.bank = 0; // factory, default
  83. // check result
  84. if( SCPI_ARGUMENT_CHARACTER_INVALID_ID == common_ctx->MemTableCommon.bank )
  85. {
  86. (void)common_ctx->status; // eProgramDataIllegalArgument
  87. common_ctx->argErrIdx = 1; // specify erroneous argument index: bank
  88. }
  89. common_ctx->status = eProgramDataNeedRead; // request processed, wait for reading...
  90. }
  91. }
  92. break;
  93. case eProgramData_Event_Read:
  94. {
  95. // @idx - current position of the source data to be outputed
  96. if( common_ctx->MemTableCommon.idx == 0 ) // first reading
  97. {
  98. eChrz_t chrz = (eChrz_t)((eChFactory) + common_ctx->MemTableCommon.bank);
  99. ePortId_t port = (ePortId_t)((ePortId_A) + common_ctx->MemTableCommon.port);
  100. size_t length = 0;
  101. if( NFMClass->methods.xCharacterization.getAdapterDesc( chrz, port,
  102. common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
  103. &length ) )
  104. {
  105. if( length == 0 )
  106. {
  107. common_ctx->tempBuffer[0] = '\'';
  108. common_ctx->tempBuffer[1] = ' ';
  109. common_ctx->tempBuffer[2] = '\'';
  110. length = 3;
  111. }
  112. // place null-terminator in the end of line
  113. common_ctx->tempBuffer[length] = '\0';
  114. }
  115. else
  116. {
  117. // Formal call: in case the parameter is optional, the token is unfilled.
  118. // So it is required to fill the token with correct values from allowed list.
  119. SCPI_ARGUMENT_CHARACTER_VALUE_TOKEN( MemTable_AllowedValues_Bank,
  120. common_ctx->MemTableCommon.bank,
  121. &common_ctx->argTokens[1] );
  122. fsq_RaiseErrorEx( SCPI_ERROR_CHRZ_DATA_NOTFOUND,
  123. SCPI_ERROR_CHRZ_DATA_NOTFOUND_MSG,
  124. common_ctx->argTokens[1].shead,
  125. common_ctx->argTokens[1].stail,
  126. global_ctx->sParser.xHandlerToken.shead,
  127. global_ctx->sParser.xHandlerToken.stail );
  128. common_ctx->status = eProgramData_SpecificError; // specific error already generated
  129. break;
  130. }
  131. }
  132. // Since @done flag is set, this dispatcher shall not be called anymore.
  133. // Since this handler is implemented as a single-state automat, there no
  134. // ... other states to go to:
  135. (void)nextstate;
  136. // modify current postion index:
  137. SCPI_RESPONSE_HELPER( common_ctx, common_ctx->MemTableCommon.idx );
  138. }
  139. break;
  140. }
  141. return nextstate;
  142. }