| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- #include <stdio.h>
- #define SCPI_ARGS_N 2
- #define SCPI_ARGS_MANDATORY_N 1
- #include "app/scpi/scpi_handler.h"
- // -----
- // @argTokens, @argTypes
- // Declare argument parser entities
- // Supported arguments: 1=CHARACTER, 2=CHARACTER
- DECLARE_SCPI_ARGS( eScpiArg_Character, eScpiArg_Character );
- // Argument 1 Character Values allowed list / ACM Port
- DECLARE_ARGUMENT_CHARACTER_ALLOWED_LIST_EXPORT( MemTable_AllowedValues_Port, "A", "B" );
- // Argument 2 Character Values allowed list / Memory Bank
- DECLARE_ARGUMENT_CHARACTER_ALLOWED_LIST_EXPORT( MemTable_AllowedValues_Bank, "FACTory", "USER1", "USER2", "USER3" );
- #include "app/scpi/commandHandlers/memory_table_adapter.h"
- #include "app/nfm/nfm_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_CommandHandlerMemoryTableAdapter
- // State's virtual table
- static void fsqe_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
- static void fsql_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
- static const struct fFSeqEntry_t * fsqf_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx, const struct fFSeqEntry_t * * pDeferredNext );
- const fFSeqVTable_t fsqvbl_CommandHandlerMEMoryTABLeADAPter =
- {
- .f = fsqf_CommandHandlerMemoryTableAdapter,
- .enter = fsqe_CommandHandlerMemoryTableAdapter,
- .leave = fsql_CommandHandlerMemoryTableAdapter
- };
- static void fsqe_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
- {
- sProcessProgramDataCommonContext_t * common_ctx = ctx;
-
- SCPI_PARSE_ARGUMENTS( common_ctx ); (void)common_ctx->argsParserStatus; // status is modified
- common_ctx->MemTableCommon.idx = 0;
- common_ctx->MemTableCommon.bank = 0;
- common_ctx->MemTableCommon.port = 0;
- }
- static void fsql_CommandHandlerMemoryTableAdapter( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
- {
- }
- static const struct fFSeqEntry_t * fsqf_CommandHandlerMemoryTableAdapter( 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;
- switch( common_ctx->event )
- {
- case eProgramData_Event_Write:
- {
- if( ! common_ctx->isQuery )
- {
- common_ctx->status = eProgramDataSyntaxError; // invalid command header type: COMMAND not supported
- }
- else if( eScpiStatus_success != common_ctx->argsParserStatus ) // check argument parser status
- {
- common_ctx->status = eProgramDataArgumentSyntax; // parameter syntax error, caller should generate error message
- }
- else
- {
- common_ctx->status = eProgramDataIllegalArgument; // forward set, illegal parameter value, caller should generate error message
- // process first argument (port)
- common_ctx->MemTableCommon.port = SCPI_PROCESS_ARGUMENT_CHARACTER( common_ctx, MemTable_AllowedValues_Port, 0 );
-
- // check result
- if( SCPI_ARGUMENT_CHARACTER_INVALID_ID == common_ctx->MemTableCommon.port )
- {
- (void)common_ctx->status; // eProgramDataIllegalArgument
- common_ctx->argErrIdx = 0; // specify erroneous argument index: port
- break;
- }
- // check count of arguments
- if( common_ctx->args > 1 )
- // process secord argument
- common_ctx->MemTableCommon.bank = SCPI_PROCESS_ARGUMENT_CHARACTER( common_ctx, MemTable_AllowedValues_Bank, 1 );
- else
- common_ctx->MemTableCommon.bank = 0; // factory, default
- // check result
- if( SCPI_ARGUMENT_CHARACTER_INVALID_ID == common_ctx->MemTableCommon.bank )
- {
- (void)common_ctx->status; // eProgramDataIllegalArgument
- common_ctx->argErrIdx = 1; // specify erroneous argument index: bank
- }
- common_ctx->status = eProgramDataNeedRead; // request processed, wait for reading...
-
- }
- }
- break;
- case eProgramData_Event_Read:
- {
- // @idx - current position of the source data to be outputed
- if( common_ctx->MemTableCommon.idx == 0 ) // first reading
- {
- eChrz_t chrz = (eChrz_t)((eChFactory) + common_ctx->MemTableCommon.bank);
- ePortId_t port = (ePortId_t)((ePortId_A) + common_ctx->MemTableCommon.port);
- size_t length = 0;
- if( NFMClass->methods.xCharacterization.getAdapterDesc( chrz, port,
- common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer),
- &length ) )
- {
- if( length == 0 )
- {
- common_ctx->tempBuffer[0] = '\'';
- common_ctx->tempBuffer[1] = ' ';
- common_ctx->tempBuffer[2] = '\'';
- length = 3;
- }
- // place null-terminator in the end of line
- common_ctx->tempBuffer[length] = '\0';
- }
- else
- {
- // Formal call: in case the parameter is optional, the token is unfilled.
- // So it is required to fill the token with correct values from allowed list.
- SCPI_ARGUMENT_CHARACTER_VALUE_TOKEN( MemTable_AllowedValues_Bank,
- common_ctx->MemTableCommon.bank,
- &common_ctx->argTokens[1] );
- fsq_RaiseErrorEx( SCPI_ERROR_CHRZ_DATA_NOTFOUND,
- SCPI_ERROR_CHRZ_DATA_NOTFOUND_MSG,
- common_ctx->argTokens[1].shead,
- common_ctx->argTokens[1].stail,
- global_ctx->sParser.xHandlerToken.shead,
- global_ctx->sParser.xHandlerToken.stail );
- common_ctx->status = eProgramData_SpecificError; // specific error already generated
- break;
- }
- }
- // 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:
- SCPI_RESPONSE_HELPER( common_ctx, common_ctx->MemTableCommon.idx );
- }
- break;
- }
- return nextstate;
- }
|