#ifndef SCPI_CORE_STATE__PROCESSDATA
#define SCPI_CORE_STATE__PROCESSDATA

    #include "app/scpi/scpi_core.h"    
    #include "app/scpi/scpi_numeric_types.h"
    #include "app/nfm/nfm_base.h" // xACMGetFreqPoints_t
    extern const fFSeqVTable_t fsqvbl_ProcessProgramData;

    #ifndef SCPI_CORE_STATE__PROCESSDATA_GUARD
    extern void ctx_ProcessProgramData;
    #endif

    #define SCPI_STATE_PROCESSDATA\
            DECLARE_SCPI_STATE_ENTRY( fsqvbl_ProcessProgramData, \
                                      &ctx_ProcessProgramData )

    // =================================================================================
    // @eProcessProgramDataStatus_t
    typedef enum
    {
        eProgramDataRuntimeError,  // Request failed (run-time, execution error)
        eProgramDataSyntaxError,   // Request failed (syntax error)
        eProgramDataArgumentSyntax,// Request failed (argument syntax error), sParser.xCtxObj contains error details
        eProgramDataArgumentValue, // Request failed (argument data error, invalid range or value) 
        eProgramDataArgumentType,  // Request failed (argument data error, invalid data type conversion) 
        eProgramDataArgumentRange, // Request failed (argument value range error, invalid range or value) 
        eProgramDataIllegalArgument,//Request failed (illegal argument value) 
        eProgramData_SpecificError,// Request failed (no error message is required to generate because it is already done by handler)
        eProgramDataNeedData,      // Request is being processed, need more data to be written using 'eScpiEventWrite' to continue
        eProgramDataNeedRead,      // Request processed, but the response must be read using 'eScpiEventRead'
        eProgramDataDone,          // Request completely processed, no more call is needed
    }
    eProcessProgramDataStatus_t;
    // =================================================================================
    // @eProcessProgramHandlerEvent_t
    typedef enum
    {
        eProgramData_Event_Write,         // First call of command/query
        eProgramData_Event_Read,          // Second call of query
        eProgramData_Event_Done,          // Formal code: no I/O operations shall be performed
    }
    eProcessProgramHandlerEvent_t;
    // =================================================================================
    // @sProcessProgramDataSubGlobalContext_t
    // Common global context for each SCPI command
    typedef struct
    {
       void * global_ctx;
       const void * handler_ctx;

       bool needParseEndOfCommand; // End-of-command parser indicator
       bool isQuery;  // mirror of @sScpiParserContext_t::sMessage.bQuery
       sProcessNumericEntry_t numericProcessContext; // @processNumericArgument context

       int8_t status; // program data handler status, @eProcessProgramDataStatus_t
       int8_t event;  // program data handler event code, @eProcessProgramHandlerEvent_t
       int8_t argsParserStatus; // argument parser status, @eScpiStatus_t
       uint8_t argEntityTypes[ SCPI_MAX_ARGS ]; // Processed argument entity types, @eScpiEntityType_t
       uint8_t args; // Parsed arguments count, see @parseArguments_helper
       uint8_t argErrIdx; // erroneous argument index, the value >=SCPI_MAX_ARGS means this value is not specified (default)

       sStrToken_t argTokens[ SCPI_MAX_ARGS ];  // Argument tokens for @parseArguments, see @parseArguments_helper
       char tempBuffer[ SCPI_MAX_CMD_TEMP_BUFFER ]; // common general purpose command buffer
       //sStrToken_t argArray[ SCPI_MAX_ARRAY_ARG_BUFFER ]; // Array of Argument tokens for @parseArrayArguments
       uint8_t argArray[SCPI_MAX_ARRAY_ARG_BUFFER];
       union
       {
           struct { size_t idx; } IDN;
           struct { size_t idx; size_t N; size_t MAX_N; } TEST;
           struct { int dummy; } MEM_TABLE_DATA;
           struct { size_t idx; bool error; } SYSTemERRor;
           struct { size_t idx; } SYSTemVERSion;
           struct { size_t idx; } ESRSTB;
           struct { size_t idx; } ESESRE;
           struct { size_t idx; } OPC;
           struct { size_t idx; int32_t port; int32_t bank; } MemTableCommon;
           struct { size_t idx; } MemTableThermoCorrCommon;
           struct { size_t idx; int32_t state; } MeasAndSwitch;
           struct { size_t idx; int32_t state; } SwitchState;
           struct { size_t idx; size_t nchs; int32_t bank; xNFMGetFreqPoints_t getctx; double dFreqPoints[6]; bool init; bool isdone; } MemTableFreqData;
           struct { size_t idx; size_t nchs; int32_t bank; size_t iSeg; size_t nSeg; bool init; bool isdone; sEcalSegment_t Segment; } MemTableFreqSegmData;
           struct { size_t idx; } IntSwitch;
           struct { size_t idx; size_t nchs; int32_t bank; int32_t comb; int32_t state; xNFMGetPointsSimplified_t getctx; sNFMChrzPoint_t dDataPoints[3]; bool init; bool isdone; } MemTableData;
           struct { size_t idx; size_t nchs; int32_t comb; int32_t state; xNFMGetPointsSimplified_t getctx; sNFMChrzPoint_t dDataPoints[6]; bool init; bool isdone; } MemTableThermoCorrectionData;
           struct { size_t idx; size_t nchs; int32_t bank; xSWGetTablePoints_t getctx; sSWTablePoint_t dTablePoints[10]; bool init; bool isdone; } MemTablePlanData;
       };
    }
    sProcessProgramDataCommonContext_t;

    // =================================================================================
#endif