/*
 * SCPI_defs.h
 *
 * Created: 8.3.2016 21:56:08
 *  Author: Chenda
 */ 


#ifndef SCPI_DEFS_H_
#define SCPI_DEFS_H_

#define NO_PAR		0
#define TEXT_PAR	1
#define NUMBER_PAR	2

/************************************************************************/
/* SCPI mnemonic parser                                                 */
/************************************************************************/
struct stScpi_command {
	const char * SCPI_mess;
	uint8_t ProgLangCmd;
};

#define END_OF_SCPI_CMD			{0,0}
#define MAX_MESS_LENTH			((MAX_MNEMONIC_LENGTH+2+1)*MAX_NODE_LEVELS)
	
#define MAX_MNEMONIC_LENGTH		12
#define MAX_NODE_LEVELS			6

struct stMessNode {
	char *pChar;
	uint8_t strLen;
};

struct stScpi_messageIN {
	char *OriginalMess;
	uint8_t OriginalMessLen;
	struct stMessNode Node[MAX_NODE_LEVELS];
	bool Query;
	char *Param;
	uint8_t Param_len;
};

struct stScpi_messageTEMP { 
	int8_t TempMessIndex;
	char *ScpiTempMess;
	uint8_t ScpiTempMessLen;
	struct stMessNode Node[MAX_NODE_LEVELS];
	bool MandatoryNode[MAX_NODE_LEVELS];
	bool Query;
};

/************************************************************************/
/* SCPI parameter parser                                                */
/************************************************************************/
struct stParamUnit {
	const char unitSymbol;
	int8_t multiplier;	// number multiplier 0 = 1x; 1 = 1000x; -1 = 1/1000 etc
};

// unit multiplier
#define UNIT_MULTI_MILI		-1
#define UNIT_MULTI_KILO		1
#define UNIT_MULTI_NO_UNIT	0
// unit symbols
#define UNIT_SYM_MILI		'm'
#define UNIT_SYM_KILO		'k'

#define UNIT_LIST_END		{0,0}

struct stParamValue {
	const char valueSymbol;
	uint8_t NoOfVal;	
};

#define VALUE_NR_OF_VOLTS	1
#define VALUE_NR_OF_AMPS	2
#define VALUE_NR_OF_WATTS	3
#define VALUE_NR_OF_NOVLA	0

#define VALUE_SYMB_VOLTS	'V'
#define VALUE_SYMB_AMPS		'A'
#define VALUE_SYMB_WATTS	'W'

#define VALUE_LIST_END		{0,0}
	
struct stTextValus {
	const char *Text;
	int16_t RepreVal;	
};

#define TEXT_VAL_MAX_VAL	32767
#define TEXT_VAL_MIN_VAL	0
#define TEXT_VAL_TRUE		1
#define TEXT_VAL_FALSE		0
#define TEXT_VAL_ON			1
#define TEXT_VAL_OFF		0

#define TEXT_VAL_LIST_END	{"",0}
	
/************************************************************************/
/* Output SCPI module structure                                         */
/************************************************************************/
#define SCPI_PARSING_NORESULT	0
#define	SCPI_PARSING_PASS		1
#define SCPI_PARSING_CMD_FAIL	2
#define SCPI_PARSING_PAR_FAIL	3

struct stScpi_ParsingStatus {
	uint8_t ParsingResult;
	bool Query;
	uint8_t ParsedCmd;
	char *UnparsedParam;
	uint8_t UnparsedParLen;
	// parsed parameter
	//bool ParsedParam;				// false = unsuccesful ; true = succesful
	int16_t IntPartOfNumber;
	int16_t TenthPartOfNumber;		// tenth part multiplied by 1000
	uint8_t ValueOfNumber;			// 0 = no value; 1 = Volts; 2 = Amps; 3 = Watts
};

/************************************************************************/
/* Public functions                                                     */
/************************************************************************/
const struct stScpi_command* GET_SCPI_PRGLAN_LIST(void);
const struct stParamUnit* GET_SCPI_UNIT_LIST(void);
const struct stParamValue* GET_SCPI_VALUE_LIST(void);
const struct stTextValus* GET_SCPI_TEXT_VAL_LIST(void);

#endif /* SCPI_DEFS_H_ */