#ifndef SCPI_ERRS_H
#define SCPI_ERRS_H
//
// 22/01/2021
// Alexander Sychov
// SCPI Error codes and classes
//
// References:
// [1] SCPI Standard "1999 SCPI Syntax & Style, Standard Commands for Programmable Instruments" VERSION 1999.0 May, 1999
// [2] 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
//      Standard Digital Interface for Programmable Instrumentation"
//
#define SCPI_ERROR_STATE                     SCPI_ERROR_SUCCESS              // Enter error state without generating message

extern const int SCPI_ERROR_SUCCESS; // Success code
extern const char SCPI_ERROR_NO[];

// @SCPI_ERROR_COMMAND_ERROR - SCPI Common (Class) Error
// "21.8.9 Command Error", [1]
// "11.5.1.1.4 Bit 5 - Command ERROR (CME)", [2]
extern const int SCPI_ERROR_COMMAND_ERROR;
extern const char SCPI_ERROR_COMMAND_ERROR_MSG[];
#define SCPI_ERROR_CLASS_COMMAND  (-100l)

extern const int SCPI_ERROR_INVALID_CHARACTER;
extern const char SCPI_ERROR_INVALID_CHARACTER_MSG[];

extern const int SCPI_ERROR_SYNTAX_ERROR;
extern const char SCPI_ERROR_SYNTAX_ERROR_MSG[];
extern const char SCPI_ERROR_SYNTAX_ERROR_PARAM_MSG[];

extern const int SCPI_ERROR_INVSEP_ERROR;
extern const char SCPI_ERROR_INVSEP_ERROR_MSG[];

extern const int SCPI_ERROR_PARAMETER_NOTALLOWED;   
extern const char SCPI_ERROR_PARAMETER_NOTALLOWED_MSG[];

extern const int SCPI_ERROR_MISSING_PARAMETER;   
extern const char SCPI_ERROR_MISSING_PARAMETER_MSG[];

extern const int SCPI_ERROR_COMMAND_HEADER;
extern const char SCPI_ERROR_COMMAND_HEADER_MSG[];

extern const int SCPI_ERROR_COMMAND_HEADER_SEP;
extern const char SCPI_ERROR_COMMAND_HEADER_SEP_MSG[];

extern const int SCPI_ERROR_MNEMONIC_TOOLONG;
extern const char SCPI_ERROR_MNEMONIC_TOOLONG_MSG[];

extern const int SCPI_ERROR_UNDEFHEADER_ERROR;
extern const char SCPI_ERROR_UNDEFHEADER_ERROR_MSG[];

extern const int SCPI_ERROR_NUMERIC_DATAERROR;
extern const char SCPI_ERROR_NUMERIC_DATAERROR_MSG[];

extern const int SCPI_ERROR_INVALID_NUMERIC_CHAR;
extern const char SCPI_ERROR_INVALID_NUMERIC_CHAR_MSG[];

extern const int SCPI_ERROR_INVALID_STRINGDATA;
extern const char SCPI_ERROR_INVALID_STRINGDATA_MSG[];

extern const int SCPI_ERROR_INVALID_BLOCKDATA;
extern const char SCPI_ERROR_INVALID_BLOCKDATA_MSG[];

// @SCPI_ERROR_EXECUTION_ERROR - SCPI Common (Class) Error
// "21.8.10 Execution Error", [1]
// "11.5.1.1.5 Bit 4 - Execution ERROR (E)", [2]
extern const int SCPI_ERROR_EXECUTION_ERROR;
extern const char SCPI_ERROR_EXECUTION_ERROR_MSG[];
#define SCPI_ERROR_CLASS_EXECUTION  (-200l)

extern const int SCPI_ERROR_DATA_RANGE;
extern const char SCPI_ERROR_DATA_RANGE_MSG[];

extern const int SCPI_ERROR_ILLEGAL_PARAM;
extern const char SCPI_ERROR_ILLEGAL_PARAM_MSG[];

extern const int SCPI_ERROR_PARAMETER_ERROR;
extern const char SCPI_ERROR_PARAMETER_ERROR_MSG[];

extern const int SCPI_ERROR_TRIGGER_IGNORED;
extern const char SCPI_ERROR_TRIGGER_IGNORED_MSG[];

// @SCPI_ERROR_DEVICE_SPECIFIC - SCPI Common (Class) Error
// "21.8.11 Device-Specific Error", [1]
// "11.5.1.1.6 Bit 3 - Device-Specific ERROR (DDE)", [2]
extern const int SCPI_ERROR_DEVICE_SPECIFIC;
extern const char SCPI_ERROR_DEVICE_SPECIFIC_MSG[];
#define SCPI_ERROR_CLASS_DEVICE  (-300l)

extern const int SCPI_ERROR_QUEUE_OVERFLOW;
extern const char SCPI_ERROR_QUEUE_OVERFLOW_MSG[];

extern const int SCPI_ERROR_OUTOF_MEMORY;
extern const char SCPI_ERROR_OUTOF_MEMORY_MSG[];

extern const int SCPI_ERROR_INBUF_OVERFLOW;
extern const char SCPI_ERROR_INBUF_OVERFLOW_MSG[];

extern const int SCPI_ERROR_CHRZ_DATA_NOTFOUND;
extern const char SCPI_ERROR_CHRZ_DATA_NOTFOUND_MSG[];

extern const int SCPI_ERROR_THERM_DATA_NOTFOUND;
extern const char SCPI_ERROR_THERM_DATA_NOTFOUND_MSG[];

extern const int SCPI_ERROR_DATA_CORRUPTED;
extern const char SCPI_ERROR_DATA_CORRUPTED_MSG[];

extern const int SCPI_ERROR_TOO_MANY_REQUESTS;
extern const char SCPI_ERROR_TOO_MANY_REQUESTS_MSG[];

extern const int SCPI_ERROR_INTERNAL_DEVICE;
extern const char SCPI_ERROR_INTERNAL_DEVICE_MSG[];
extern const char SCPI_ERROR_INTERNAL_INT_SWITCH_MSG[];
extern const char SCPI_MESSAGE_INTERNAL_INT_SWITCH_MSG[];


// @SCPI_ERROR_QUERY_ERROR - SCPI Common (Class) Error
// "21.8.12 Query Error", [1]
// "11.5.1.1.7 Bit 2 - Query ERROR (QYE)", [2]
extern const int SCPI_ERROR_QUERY_ERROR;
extern const char SCPI_ERROR_QUERY_ERROR_MSG[];
#define SCPI_ERROR_CLASS_QUERY  (-400l)

extern const int SCPI_ERROR_POWERON;
extern const char SCPI_ERROR_POWERON_MSG[];

// No error class recognized
#define SCPI_ERROR_CLASS_UNDEFINED (0)

// @SCPI_ERROR_CLASS
// Macro returns the SCPI error class by error code:
// - SCPI_ERROR_CLASS_UNDEFINED
// - SCPI_ERROR_CLASS_COMMAND
// - SCPI_ERROR_CLASS_EXECUTION
// - SCPI_ERROR_CLASS_DEVICE
// - SCPI_ERROR_CLASS_QUERY

#define SCPI_ERROR_CLASS(errCode)  scpi_error_class(errCode)
int scpi_error_class( int errCode );
#endif