ese_sre.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // =============================================================================
  2. // Command description ESE
  3. // =============================================================================
  4. // Semantic for command: %command <%value>
  5. // Syntax for command : *ESE <numeric>
  6. // Semantic for query: %query
  7. // Syntax for query : *ESE?
  8. // Sets or reads the Standard Event Status Enable Register (command/request).
  9. // Arguments:
  10. // @value - <numeric> from 0 to 255:
  11. // Returns:
  12. // <numeric>.
  13. // -----
  14. // =============================================================================
  15. // Command description SRE
  16. // =============================================================================
  17. // Semantic for command: %command <%value>
  18. // Syntax for command : *ESR <numeric>
  19. // Semantic for query: %query
  20. // Syntax for query : *ESR?
  21. // Sets or reads the Service Request Enable Register (command/request).
  22. // Arguments:
  23. // @value - <numeric> from 0 to 255:
  24. // Returns:
  25. // <numeric>.
  26. // -----
  27. #include <stdio.h>
  28. #include <stdint.h>
  29. const uint8_t fsqvbl_CommandHandlerESE_context = 1;
  30. const uint8_t fsqvbl_CommandHandlerSRE_context = 2;
  31. #define SCPI_ARGS_N_C 1
  32. #define SCPI_ARGS_N_Q 0
  33. #include "app/scpi/scpi_handler.h"
  34. // -----
  35. // @argTypesCommand
  36. // Declare argument parser entities for command form
  37. // Supported arguments: 1=NUMERIC
  38. DECLARE_SCPI_ARGS_C( eScpiArg_Numeric );
  39. // -----
  40. // @argTypesQuery
  41. // Declare argument parser entities for query form
  42. // Supported arguments: 0
  43. DECLARE_SCPI_ARGS_Q();
  44. DECLARE_ARGUMENT_NUMERIC_VALUES_I8(AllowedValues_Argument1, 0, 255);
  45. #include "app/scpi/commandHandlers/ese_sre.h"
  46. #include "app/nfm/nfm_base.h"
  47. // Refer to:
  48. // [1] SCPI Specification, revision 1999.0
  49. // "Standard Commands for Programmable Instruments (SCPI), VERSION 1999.0, May 1999"
  50. // [2] Gpib Programming Tutorial, (http://g2pc1.bu.edu/~qzpeng/gpib/manual/GpibProgTut.pdf)
  51. // Electronics Group (http://www.few.vu.nl/~elec), 11 January 2000 Electronics Group
  52. // [3] IEEE 488.2 Standard, revision IEEE Std 488.2-1987 (1992)
  53. // "IEEE Standard Codes, Formats, Protocols, and Common Commands for Use With IEEE Std 488.1-1987, IEEE
  54. // =================================================================================
  55. // @fsqvbl_CommandHandlerESESRE
  56. // State's virtual table
  57. static void fsqe_CommandHandlerESESRE( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  58. static void fsql_CommandHandlerESESRE( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  59. static const struct fFSeqEntry_t * fsqf_CommandHandlerESESRE( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx, const struct fFSeqEntry_t * * pDeferredNext );
  60. const fFSeqVTable_t fsqvbl_CommandHandlerESESRE =
  61. {
  62. .f = fsqf_CommandHandlerESESRE,
  63. .enter = fsqe_CommandHandlerESESRE,
  64. .leave = fsql_CommandHandlerESESRE
  65. };
  66. static void fsqe_CommandHandlerESESRE( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  67. {
  68. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  69. common_ctx->ESESRE.idx = 0; // reset position
  70. SCPI_PARSE_ARGUMENTS( common_ctx ); (void)common_ctx->argsParserStatus; // status is modified
  71. }
  72. static void fsql_CommandHandlerESESRE( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  73. {
  74. }
  75. static const struct fFSeqEntry_t * fsqf_CommandHandlerESESRE( const struct fFSeqEntry_t * this,
  76. tFSeqCtx_t ctx,
  77. const struct fFSeqEntry_t * * pDeferredNext )
  78. {
  79. const fFSeqEntry_t * nextstate = NULL;
  80. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  81. sScpiParserContext_t * global_ctx = common_ctx->global_ctx;
  82. switch( common_ctx->event )
  83. {
  84. case eProgramData_Event_Write:
  85. {
  86. if( eScpiStatus_success != common_ctx->argsParserStatus ) // check argument parser status
  87. {
  88. common_ctx->status = eProgramDataArgumentSyntax; // parameter syntax error, caller should generate error message
  89. }
  90. else
  91. if( ! common_ctx->isQuery )
  92. {
  93. common_ctx->status = eProgramDataSyntaxError; // forward set
  94. const sNumericEntry_t * ne = SCPI_PROCESS_ARGUMENT_NUMERIC(common_ctx, &AllowedValues_Argument1, 0);
  95. if( NULL != ne )
  96. switch( ne->error )
  97. {
  98. case ScpiNumericSuccess:
  99. {
  100. if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerESE_context )
  101. GPIBMachine.fGPIB_set_event_status_enable_register( &global_ctx->sGPIB.registers,
  102. (uint8_t)ne->Value.i );
  103. if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerSRE_context )
  104. GPIBMachine.fGPIB_set_service_request_enable_register( &global_ctx->sGPIB.registers,
  105. (uint8_t)ne->Value.i );
  106. common_ctx->status = eProgramDataDone;
  107. }
  108. break;
  109. // -------- processed by SCPI_PROCESS_ARGUMENT_NUMERIC ----
  110. // "11.5.1.1.5", [3]
  111. // "10.10.6 Error Handling", [3]
  112. // "<...> An out-of-range integer shall cause an Execution Error, see 11.5.1.1.5. <...>"
  113. case ScpiNumericError_DEVICE_RANGE: // the value is out of range supported by device
  114. case ScpiNumericError_USER_RANGE: // the value is out of user specified range: // the value is out of range supported by device
  115. case ScpiNumericError_USER_TYPE: // the value does not match to the user expectation
  116. case ScpiNumericInvalidArg: // forbidden case: design bug
  117. case ScpiNumericError: // generic numeric conversion error
  118. break;
  119. // --------------------------------------------------------
  120. }
  121. }
  122. else
  123. {
  124. common_ctx->status = eProgramDataNeedRead; // request processed, wait for reading...
  125. (void)nextstate; // stay in this state
  126. }
  127. }
  128. break;
  129. case eProgramData_Event_Read:
  130. {
  131. // @idx - current position of the source data to be outputed
  132. if( 0 == common_ctx->ESESRE.idx )
  133. {
  134. memset( common_ctx->tempBuffer, 0, sizeof(common_ctx->tempBuffer) );
  135. uint8_t ESESRE = 0;
  136. // Read ESE:
  137. if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerESE_context )
  138. GPIBMachine.fGPIB_get_event_status_enable_register( &global_ctx->sGPIB.registers, &ESESRE );
  139. // Read ESB:
  140. if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerSRE_context )
  141. GPIBMachine.fGPIB_get_service_request_enable_register( &global_ctx->sGPIB.registers, &ESESRE );
  142. int iESESRE = (int)ESESRE;
  143. // first call: prepare buffer
  144. _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%d", iESESRE );
  145. }
  146. // Since @done flag is set, this dispatcher shall not be called anymore.
  147. // Since this handler is implemented as a single-state automat, there no
  148. // ... other states to go to:
  149. (void)nextstate;
  150. // modify current postion index:
  151. SCPI_RESPONSE_HELPER( common_ctx, common_ctx->ESESRE.idx );
  152. }
  153. break;
  154. }
  155. return nextstate;
  156. }