syst_version.c 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <stdio.h>
  2. #define SCPI_ARGS_N 0
  3. #include "app/scpi/scpi_handler.h"
  4. #include "app/scpi/commandHandlers/syst_version.h"
  5. #include "app/nfm/nfm_base.h"
  6. //----------------------------------------------------------------
  7. // Refer to:
  8. // [1] SCPI Specification, revision 1999.0
  9. // "Standard Commands for Programmable Instruments (SCPI), VERSION 1999.0, May 1999"
  10. //----------------------------------------------------------------
  11. // Refer "21.21 :VERSion?", [1]
  12. // =================================================================================
  13. // @fsqvbl_CommandHandlerSystemVersion
  14. // State's virtual table
  15. static void fsqe_CommandHandlerSystemVersion( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  16. static void fsql_CommandHandlerSystemVersion( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  17. static const struct fFSeqEntry_t * fsqf_CommandHandlerSystemVersion( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx, const struct fFSeqEntry_t * * pDeferredNext );
  18. const fFSeqVTable_t fsqvbl_CommandHandlerSystemVersion =
  19. {
  20. .f = fsqf_CommandHandlerSystemVersion,
  21. .enter = fsqe_CommandHandlerSystemVersion,
  22. .leave = fsql_CommandHandlerSystemVersion
  23. };
  24. static void fsqe_CommandHandlerSystemVersion( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  25. {
  26. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  27. common_ctx->SYSTemVERSion.idx = 0; // reset position
  28. }
  29. static void fsql_CommandHandlerSystemVersion( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  30. {
  31. }
  32. static const struct fFSeqEntry_t * fsqf_CommandHandlerSystemVersion( const struct fFSeqEntry_t * this,
  33. tFSeqCtx_t ctx,
  34. const struct fFSeqEntry_t * * pDeferredNext )
  35. {
  36. const fFSeqEntry_t * nextstate = NULL;
  37. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  38. switch( common_ctx->event )
  39. {
  40. case eProgramData_Event_Write:
  41. {
  42. if( ! common_ctx->isQuery )
  43. {
  44. common_ctx->status = eProgramDataSyntaxError; // invalid command header type: COMMAND not supported
  45. }
  46. else
  47. {
  48. common_ctx->status = eProgramDataNeedRead; // request processed, wait for reading...
  49. (void)nextstate; // stay in this state
  50. }
  51. }
  52. break;
  53. case eProgramData_Event_Read:
  54. {
  55. // @idx - current position of the source data to be outputed
  56. if( common_ctx->SYSTemVERSion.idx == 0 ) // first reading
  57. {
  58. memset( common_ctx->tempBuffer, 0, sizeof(common_ctx->tempBuffer) );
  59. _snprintf( common_ctx->tempBuffer,
  60. sizeof( common_ctx->tempBuffer ),
  61. "%4d.%1d", SCPI_VERSION_YEAR, SCPI_VERSION_REVISION );
  62. }
  63. // Since @done flag is set, this dispatcher shall not be called anymore.
  64. // Since this handler is implemented as a single-state automat, there no
  65. // ... other states to go to:
  66. (void)nextstate;
  67. // modify current postion index:
  68. SCPI_RESPONSE_HELPER( common_ctx, common_ctx->SYSTemVERSion.idx);
  69. }
  70. break;
  71. }
  72. return nextstate;
  73. }