reset_state.c 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #define SCPI_CORE_STATE__RESETSTATE_GUARD
  2. #include "app/scpi/CommandParserStates/reset_state.h"
  3. #include "app/scpi/CommandParserStates/search_for_command.h"
  4. #define SCPI_CORE_PRIVATE // access to 'scpi_core_private.h'
  5. #define SCPI_RESET_STATE_C // access to const values in 'scpi_core_private.h' structures
  6. #include "app/scpi/scpi_core_private.h"
  7. //----------------------------------------------------------------
  8. // Refer to:
  9. // [1] IEEE 488.2 Standard, revision IEEE Std 488.2-1987 (1992)
  10. // "IEEE Standard Codes, Formats, Protocols, and Common Commands for Use With IEEE Std 488.1-1987, IEEE
  11. // Standard Digital Interface for Programmable Instrumentation"
  12. // =================================================================================
  13. // @fsqvbl_SearchForCommandHeader
  14. // State's virtual table
  15. static void fsqe_ParserResetState( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  16. static void fsql_ParserResetState( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  17. static const struct fFSeqEntry_t * fsqf_ParserResetState( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx, const struct fFSeqEntry_t * * pnext );
  18. const fFSeqVTable_t fsqvbl_ParserResetState =
  19. {
  20. .f = fsqf_ParserResetState,
  21. .enter = fsqe_ParserResetState,
  22. .leave = fsql_ParserResetState
  23. };
  24. // =================================================================================
  25. // @fsqe_ParserResetState
  26. // State's enter routine
  27. static void fsqe_ParserResetState( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  28. {
  29. sScpiParserContext_t * global_ctx = ctx;
  30. (void)global_ctx;
  31. }
  32. // =================================================================================
  33. // @fsql_ParserResetState
  34. // State's leave routine
  35. static void fsql_ParserResetState( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  36. {
  37. sScpiParserContext_t * global_ctx = ctx;
  38. (void)global_ctx;
  39. }
  40. // =================================================================================
  41. // @fsqf_ParserResetState
  42. // State's body routine
  43. static const struct fFSeqEntry_t * fsqf_ParserResetState( const struct fFSeqEntry_t * this,
  44. tFSeqCtx_t ctx,
  45. const struct fFSeqEntry_t * * pDeferredNext )
  46. {
  47. // Function prepares the entire automat for work by initializing
  48. // ... global context.
  49. // --------------------------------------------------------------------------
  50. sScpiParserContext_t * global_ctx = ctx;
  51. // --------------------------------------------------------------------------
  52. // prepare global context:
  53. global_ctx->sWrite.pData = NULL;
  54. global_ctx->sWrite.nDataLength = 0;
  55. global_ctx->sMessage.pStr = NULL;
  56. global_ctx->sMessage.pEnd = NULL;
  57. global_ctx->sRead.pBuffer = NULL;
  58. global_ctx->sRead.pBufferIdx = NULL;
  59. global_ctx->sRead.nBufferSize = 0;
  60. global_ctx->sRead.nDataLength = 0;
  61. global_ctx->sRead.nTotalLength = 0;
  62. global_ctx->sRead.vLastBufferIdx = NULL;
  63. global_ctx->sEvent.eCode = eScpiEventEmpty; // no event occurred
  64. global_ctx->sParser.xCmdBranch = NULL; // =NULL: reset command branch to the root
  65. global_ctx->sParser.xHandler = NULL;
  66. global_ctx->sParser.xHandlerToken.shead = NULL;
  67. global_ctx->sParser.xHandlerToken.stail = NULL;
  68. global_ctx->sParser.bFirstCommandIndicator = true; // set first command indicator
  69. global_ctx->sEvent.eCode = eScpiEventEmpty; // reset event code
  70. global_ctx->sEvent.eStatus = eScpiStatus_success; // reset status code
  71. global_ctx->sExecution.runtimeError = 0;
  72. (void)global_ctx->sExecution.errorQueueOverflow; // do not reset here
  73. memset( global_ctx->sExecution.xScpiErrorMessage, 0, sizeof(global_ctx->sExecution.xScpiErrorMessage) );
  74. // "6.1.10.2.1 Message Available Message (MAV)", [1]
  75. // Actually, there no data in the output buffer now. Reset the MAV
  76. // Force reset MAV bit
  77. GPIBMachine.fGPIB_set_message_available_bit( &global_ctx->sGPIB.registers, false );
  78. // "5.8 Device Clear Requirements", [1]
  79. // DO NOT clear Error Queue and any bits other than clearing MAV bit in GPIB
  80. return fsq_GetStateById(this,eSearchForCommandHeader); // go to next state: eSearchForCommandHeader
  81. }