memory_table_connector.c 6.4 KB

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