| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- #error Deprecated. 'ese_sre' is used instead
- #include <stdio.h>
- const int fsqvbl_CommandHandlerSRE_context = 3;
- #define SCPI_ARGS_N_C 1
- #define SCPI_ARGS_N_Q 0
- #include "app/scpi/scpi_handler.h"
- // -----
- // @argTypesCommand
- // Declare argument parser entities for command form
- // Supported arguments: 1=NUMERIC
- DECLARE_SCPI_ARGS_C( eScpiArg_Numeric );
- // -----
- // @argTypesQuery
- // Declare argument parser entities for query form
- // Supported arguments: 0
- DECLARE_SCPI_ARGS_Q();
- DECLARE_ARGUMENT_NUMERIC_VALUES_I8(AllowedValues_Argument1, 0, 255);
- #include "app/scpi/commandHandlers/sre.h"
- #include "app/acm/acm_base.h"
- // Refer to:
- // [1] SCPI Specification, revision 1999.0
- // "Standard Commands for Programmable Instruments (SCPI), VERSION 1999.0, May 1999"
- // [2] Gpib Programming Tutorial, (http://g2pc1.bu.edu/~qzpeng/gpib/manual/GpibProgTut.pdf)
- // Electronics Group (http://www.few.vu.nl/~elec), 11 January 2000 Electronics Group
- // [3] IEEE 488.2 Standard, revision IEEE Std 488.2-1987 (1992)
- // "IEEE Standard Codes, Formats, Protocols, and Common Commands for Use With IEEE Std 488.1-1987, IEEE
- // =================================================================================
- // @fsqvbl_CommandHandlerSRE
- // State's virtual table
- static void fsqe_CommandHandlerSRE( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
- static void fsql_CommandHandlerSRE( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
- static const struct fFSeqEntry_t * fsqf_CommandHandlerSRE( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx, const struct fFSeqEntry_t * * pDeferredNext );
- const fFSeqVTable_t fsqvbl_CommandHandlerSRE =
- {
- .f = fsqf_CommandHandlerSRE,
- .enter = fsqe_CommandHandlerSRE,
- .leave = fsql_CommandHandlerSRE
- };
- static void fsqe_CommandHandlerSRE( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
- {
- sProcessProgramDataCommonContext_t * common_ctx = ctx;
- sScpiParserContext_t * global_ctx = common_ctx->global_ctx;
-
- common_ctx->SRE.idx = 0; // rsret position
- SCPI_PARSE_ARGUMENTS( common_ctx ); (void)common_ctx->argsParserStatus; // status is modified
- (void)global_ctx;
- }
- static void fsql_CommandHandlerSRE( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
- {
- sProcessProgramDataCommonContext_t * common_ctx = ctx;
- sScpiParserContext_t * global_ctx = common_ctx->global_ctx;
-
- (void)common_ctx;
- (void)global_ctx;
- }
- static const struct fFSeqEntry_t * fsqf_CommandHandlerSRE( const struct fFSeqEntry_t * this,
- tFSeqCtx_t ctx,
- const struct fFSeqEntry_t * * pDeferredNext )
- {
- const fFSeqEntry_t * nextstate = NULL;
-
- sProcessProgramDataCommonContext_t * common_ctx = ctx;
- sScpiParserContext_t * global_ctx = common_ctx->global_ctx;
-
- (void)common_ctx;
- (void)global_ctx;
- switch( common_ctx->event )
- {
- case eProgramData_Event_Write:
- {
- if( eScpiStatus_success != common_ctx->argsParserStatus ) // check argument parser status
- {
- common_ctx->status = eProgramDataArgumentSyntax; // parameter syntax error, caller should generate error message
- }
- else
- if( ! common_ctx->isQuery )
- {
- common_ctx->status = eProgramDataSyntaxError; // forward set
- const sNumericEntry_t * ne = SCPI_PROCESS_ARGUMENT_NUMERIC(common_ctx, &AllowedValues_Argument1, 0);
- if( NULL != ne )
- switch( ne->error )
- {
- case ScpiNumericSuccess:
- {
- GPIBMachine.fGPIB_set_service_request_enable_register( &global_ctx->sGPIB.registers,
- (uint8_t)ne->Value.i );
- common_ctx->status = eProgramDataDone;
- }
- break;
- // -------- processed by SCPI_PROCESS_ARGUMENT_NUMERIC ----
- // "11.5.1.1.5", [3]
- // "10.10.6 Error Handling", [3]
- // "<...> An out-of-range integer shall cause an Execution Error, see 11.5.1.1.5. <...>"
- case ScpiNumericError_DEVICE_RANGE: // the value is out of range supported by device
- case ScpiNumericError_USER_RANGE: // the value is out of user specified range: // the value is out of range supported by device
- case ScpiNumericError_USER_TYPE: // the value does not match to the user expectation
- case ScpiNumericInvalidArg: // forbidden case: design bug
- case ScpiNumericError: // generic numeric conversion error
- break;
- // --------------------------------------------------------
- }
- }
- else
- {
- common_ctx->status = eProgramDataNeedRead; // request processed, wait for reading...
- (void)nextstate; // stay in this state
- }
- }
- break;
-
- case eProgramData_Event_Read:
- {
- // Take the input buffer by @pBuffer and @nBufferLength
- // @dst = @pBuffer, output response buffer
- // @bsize = @nBufferLength, output buffer size
- uint8_t * dst = (uint8_t*)global_ctx->sRead.pBufferIdx;
- size_t bsize = global_ctx->sRead.nBufferSize;
- // @idx - current position of the source data to be outputed
- size_t idx = common_ctx->SRE.idx;
-
- if( 0 == idx )
- {
- memset( common_ctx->tempBuffer, 0, sizeof(common_ctx->tempBuffer) );
- uint8_t SRE = 0;
-
- // Read ESB:
- // "11.5.1.2 Standard Event Status Register Operation", [3]
- // "<...> The Standard Event Status Register is destructively read (that is, read and cleared) <...>", [3]
- // retrieve ESB and clear it
- GPIBMachine.fGPIB_get_service_request_enable_register( &global_ctx->sGPIB.registers, &SRE );
-
- int iSRE = (int)SRE;
- // first call: prepare buffer
- _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%d", iSRE );
- }
- // @SRE_str - response string
- const char * SRE_str = common_ctx->tempBuffer;
-
- // Copy response string char by char to the output buffer
- // ... until the null-character is reached or the output
- // ... buffer free space is ran out:
- while( ('\0' != SRE_str[idx]) && ( 0<bsize ) )
- {
- *dst++ = SRE_str[idx++]; bsize--;
- }
- // Set the @nDataLength to indicate the copied part size:
- // @bsize after copying reprsrent the free space left in bytes;
- // @nBufferLength after copying reprsrent the free space in bytes before copying;
- // Thus (@nBufferSize-@bsize) is the number of bytes has been copyied:
- global_ctx->sRead.nDataLength += global_ctx->sRead.nBufferSize - bsize;
- // Check for end-condition:
- if( '\0' == SRE_str[idx] )
- {
- common_ctx->status = eProgramDataDone;
- }
- // Since @done flag is set, this dispatcher shall not be called anymore.
- // Since this handler is implemented as a single-state automat, there no
- // ... other states to go to:
- (void)nextstate;
- // modify current postion index:
- common_ctx->SRE.idx = idx;
- }
- break;
- }
- return nextstate;
- }
|