cls.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <stdio.h>
  2. #define SCPI_ARGS_N 0
  3. #include "app/scpi/scpi_handler.h"
  4. #include "app/scpi/commandHandlers/cls.h"
  5. #include "app/nfm/nfm_base.h"
  6. // Refer to:
  7. // [1] SCPI Specification, revision 1999.0
  8. // "Standard Commands for Programmable Instruments (SCPI), VERSION 1999.0, May 1999"
  9. // [2] Gpib Programming Tutorial, (http://g2pc1.bu.edu/~qzpeng/gpib/manual/GpibProgTut.pdf)
  10. // Electronics Group (http://www.few.vu.nl/~elec), 11 January 2000 Electronics Group
  11. // [3] IEEE 488.2 Standard, revision IEEE Std 488.2-1987 (1992)
  12. // "IEEE Standard Codes, Formats, Protocols, and Common Commands for Use With IEEE Std 488.1-1987, IEEE
  13. // =================================================================================
  14. // @fsqvbl_CommandHandlerCLS
  15. // State's virtual table
  16. static void fsqe_CommandHandlerCLS( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  17. static void fsql_CommandHandlerCLS( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  18. static const struct fFSeqEntry_t * fsqf_CommandHandlerCLS( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx, const struct fFSeqEntry_t * * pDeferredNext );
  19. const fFSeqVTable_t fsqvbl_CommandHandlerCLS =
  20. {
  21. .f = fsqf_CommandHandlerCLS,
  22. .enter = fsqe_CommandHandlerCLS,
  23. .leave = fsql_CommandHandlerCLS
  24. };
  25. static void fsqe_CommandHandlerCLS( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  26. {
  27. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  28. SCPI_PARSE_ARGUMENTS( common_ctx ); (void)common_ctx->argsParserStatus; // status is modified
  29. }
  30. static void fsql_CommandHandlerCLS( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  31. {
  32. }
  33. // "4.1.3.2 *CLS", [1]
  34. // "10.3 *CLS, Clear Status Command", [3]
  35. static const struct fFSeqEntry_t * fsqf_CommandHandlerCLS( const struct fFSeqEntry_t * this,
  36. tFSeqCtx_t ctx,
  37. const struct fFSeqEntry_t * * pDeferredNext )
  38. {
  39. const fFSeqEntry_t * nextstate = NULL;
  40. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  41. sScpiParserContext_t * global_ctx = common_ctx->global_ctx;
  42. switch( common_ctx->event )
  43. {
  44. case eProgramData_Event_Write:
  45. {
  46. if( common_ctx->isQuery )
  47. {
  48. common_ctx->status = eProgramDataSyntaxError; // invalid command header type: QUERY not supported
  49. }
  50. else if( eScpiStatus_success != common_ctx->argsParserStatus ) // check argument parser status
  51. {
  52. common_ctx->status = eProgramDataArgumentSyntax; // parameter syntax error, caller should generate error message
  53. }
  54. else
  55. {
  56. // clear ESB:
  57. // "11.5.1.2 Standard Event Status Register Operation", [3]
  58. // "<...> The Standard Event Status Register is destructively read (that is, read and cleared) <...>", [3]
  59. uint8_t esr;
  60. GPIBMachine.fGPIB_get_event_status_register( &global_ctx->sGPIB.registers, &esr );
  61. // clear STB:
  62. GPIBMachine.fGPIB_clr_status_byte( &global_ctx->sGPIB.registers );
  63. // Clear error queue
  64. errq_clear(&global_ctx->sExecution.xScpiErrorQueue);
  65. common_ctx->status = eProgramDataDone; // request processed
  66. // Since @done flag is set, this dispatcher shall not be called anymore.
  67. // Since this handler is implemented as a single-state automat, there no
  68. // ... other states to go to:
  69. (void)nextstate;
  70. }
  71. }
  72. break;
  73. }
  74. return nextstate;
  75. }