#include "core/config.h" // CONFIG_REBOOT_FEATURE
#include "app/scpi/scpi_errs.h"

// Refer to: [1], p 520

int scpi_error_class( int errCode )
{
    if( errCode <= 0 )
      return (((int)((errCode) / 100))*100);

    return SCPI_ERROR_CLASS_EXECUTION; // treat all positive error codes as EXECUTION errors (device dependent)
}

const int SCPI_ERROR_SUCCESS = 0; // Success code
const char SCPI_ERROR_NO[] = "0, No Error";

const int SCPI_ERROR_COMMAND_ERROR = -100l;
const char SCPI_ERROR_COMMAND_ERROR_MSG[] = "Command Error";

const int SCPI_ERROR_INVALID_CHARACTER = -101l;
const char SCPI_ERROR_INVALID_CHARACTER_MSG[] = "Invalid character";

const int SCPI_ERROR_SYNTAX_ERROR = -102l;
const char SCPI_ERROR_SYNTAX_ERROR_MSG[] = "Syntax Error";
const char SCPI_ERROR_SYNTAX_ERROR_PARAM_MSG[] = "Parameter Syntax Error";

const int SCPI_ERROR_INVSEP_ERROR = -103l;
const char SCPI_ERROR_INVSEP_ERROR_MSG[] = "Invalid separator";

const int SCPI_ERROR_PARAMETER_NOTALLOWED = -108l;
const char SCPI_ERROR_PARAMETER_NOTALLOWED_MSG[] = "Parameter not allowed";

const int SCPI_ERROR_MISSING_PARAMETER = -109l;
const char SCPI_ERROR_MISSING_PARAMETER_MSG[] = "Missing parameter";

const int SCPI_ERROR_COMMAND_HEADER = -110l;
const char SCPI_ERROR_COMMAND_HEADER_MSG[] = "Command header error (parse error)";

const int SCPI_ERROR_COMMAND_HEADER_SEP = -111l;
const char SCPI_ERROR_COMMAND_HEADER_SEP_MSG[] = "Header separator error";

const int SCPI_ERROR_MNEMONIC_TOOLONG = -112l;
const char SCPI_ERROR_MNEMONIC_TOOLONG_MSG[] = "Program mnemonic too long";

const int SCPI_ERROR_UNDEFHEADER_ERROR = -113l;
const char SCPI_ERROR_UNDEFHEADER_ERROR_MSG[] = "Undefined header";

const int SCPI_ERROR_NUMERIC_DATAERROR = -120l;
const char SCPI_ERROR_NUMERIC_DATAERROR_MSG[] = "Numeric data error";

const int SCPI_ERROR_INVALID_NUMERIC_CHAR = -121l;
const char SCPI_ERROR_INVALID_NUMERIC_CHAR_MSG[] = "Invalid character in number";

const int SCPI_ERROR_INVALID_STRINGDATA = -151;
const char SCPI_ERROR_INVALID_STRINGDATA_MSG[] = "Invalid string data";

const int SCPI_ERROR_INVALID_BLOCKDATA = -161;
const char SCPI_ERROR_INVALID_BLOCKDATA_MSG[] = "Invalid block data";

const int SCPI_ERROR_EXECUTION_ERROR = -200l;
const char SCPI_ERROR_EXECUTION_ERROR_MSG[] = "Execution error";

const int SCPI_ERROR_TRIGGER_IGNORED = -211l;
const char SCPI_ERROR_TRIGGER_IGNORED_MSG[] = "Trigger ignored";

const int SCPI_ERROR_PARAMETER_ERROR = -220l;
const char SCPI_ERROR_PARAMETER_ERROR_MSG[] = "Parameter error";

const int SCPI_ERROR_DATA_RANGE = -222l;
const char SCPI_ERROR_DATA_RANGE_MSG[] = "Data out of range";
  
const int SCPI_ERROR_ILLEGAL_PARAM = -224l;
const char SCPI_ERROR_ILLEGAL_PARAM_MSG[] = "Illegal parameter value";

const int SCPI_ERROR_DEVICE_SPECIFIC = -300;
const char SCPI_ERROR_DEVICE_SPECIFIC_MSG[] = "Device-specific error";

const int SCPI_ERROR_QUEUE_OVERFLOW = -350l;
const char SCPI_ERROR_QUEUE_OVERFLOW_MSG[] = "Queue overflow";

const int SCPI_ERROR_OUTOF_MEMORY = -361l;
const char SCPI_ERROR_OUTOF_MEMORY_MSG[] = "Out of memory";

const int SCPI_ERROR_INBUF_OVERFLOW = -363l;
const char SCPI_ERROR_INBUF_OVERFLOW_MSG[] = "Input buffer overrun";

const int SCPI_ERROR_QUERY_ERROR = -400l;
const char SCPI_ERROR_QUERY_ERROR_MSG[] = "Query error";

const int SCPI_ERROR_POWERON = -500l;
const char SCPI_ERROR_POWERON_MSG[] = "Power on";

const int SCPI_ERROR_CHRZ_DATA_NOTFOUND = 1;   // Execution Error, see @scpi_error_class
const char SCPI_ERROR_CHRZ_DATA_NOTFOUND_MSG[] = "Characterization data not found";

const int SCPI_ERROR_THERM_DATA_NOTFOUND = 2;   // Execution Error, see @scpi_error_class
const char SCPI_ERROR_THERM_DATA_NOTFOUND_MSG[] = "Thermocompensation data not found or corrupted";

const int SCPI_ERROR_DATA_CORRUPTED = 3;   // Execution Error, see @scpi_error_class
const char SCPI_ERROR_DATA_CORRUPTED_MSG[] = "Data array corrupted or not found";

const int SCPI_ERROR_TOO_MANY_REQUESTS = 4;   // Execution Error, see @scpi_error_class
const char SCPI_ERROR_TOO_MANY_REQUESTS_MSG[] = "Too many requests in line";

const int SCPI_ERROR_INTERNAL_DEVICE = 5;   // Execution Error, see @scpi_error_class
const char SCPI_ERROR_INTERNAL_DEVICE_MSG[] = "Internal device error";
const char SCPI_ERROR_INTERNAL_INT_SWITCH_MSG[] = "# An unexpected error has occurred! The interface will not be switched!";
#if CONFIG_REBOOT_FEATURE
const char SCPI_MESSAGE_INTERNAL_INT_SWITCH_MSG[] = "! The interface will be switched automatically.";
#else
const char SCPI_MESSAGE_INTERNAL_INT_SWITCH_MSG[] = "! The interface will be switched the next time the USB cable is connected!";
#endif