/*
 * SCPI_defs.c
 *
 * Created: 8.3.2016 22:17:02
 *  Author: Chenda
 */ 
//#include <avr/io.h>
#include <stdint.h>
#include <stdbool.h>

#include "../../../Command_defs.h"
#include "SCPI_defs.h"

#include "../../lcd/lcd_h.h"

/************************************************************************/
/* Variables definition                                                 */
/************************************************************************/
const struct stScpi_command cstScpiCmds[] = {
	/* Core messages */
	{"*IDN?",CORE_IDN_QRY},
	{"*CLS",CORE_STAT_CLR},
	{"*RST",CORE_RESET},
	/* System messages */
	{"SYSTem:BEEPer[:IMMediate]",BEEP},
	{"SYSTem:ERRor?",ERROR_QRY},
	{"SYSTem:VERSion?",VER_QRY},
	{"SYSTem:LOCal",LOC_CTRL},
	{"SYSTem:REMote",REM_CTRL},
	{"SYSTem:RWLock",RW_LOCK},
	/* Display messages - dedicated for local control interface*/
	{"DISPlay[:WINDow][:STATe]",DISP_STAT},
	{"DISPlay[:WINDow][:STATe?]",DISP_STAT_QRY},
	{"DISPlay[:WINDow]:TEXT[:DATA]",DISP_TEXT},
	{"DISPlay[:WINDow]:TEXT[:DATA?]",DISP_TEXT_QRY},
	{"DISPlay[:WINDow]:TEXT:CLEar",DISP_CLR},
	/* Instrument messages - PS management messages */
	{"INSTrument[:NSELect]",INST_SEL},
	{"INSTrument[:NSELect?]",INST_SEL_QRY},
	{"INSTrument:RINStrument",INST_CONN},
	{"INSTrument:CINStrument?",INST_CONN_QRY},
	{"INSTrument:IPARameters?",INST_SEL_PAR_QRY},
	/* Source (PS) config messages */
	{"[SOURce:]CURRent[:LEVel][:IMMediate][:AMPLitude]",SRC_IMM_CURR},
	{"[SOURce:]CURRent[:LEVel][:IMMediate][:AMPLitude?]",SRC_IMM_CURR_QRY},
	{"[SOURce:]VOLTage[:LEVel][:IMMediate][:AMPLitude]",SRC_IMM_VOLT},
	{"[SOURce:]VOLTage[:LEVel][:IMMediate][:AMPLitude?]",SRC_IMM_VOLT_QRY},
	/* Source (PS) measure messages */
	{"MEASure[:SCALar]:CURRent[:DC?]",MEAS_CURR_QRY},
	{"MEASure[:SCALar][:VOLTage][:DC?]",MEAS_VOLT_QRY},
	/* Source (PS) output config messages */
	{"OUTPut[:STATe]",OUT_STAT},
	{"OUTPut[:STATe?]",OUT_STAT_QRY},
	{"OUTPut:ALL",OUT_STAT_ALL},
	END_OF_SCPI_CMD
};

const struct stParamUnit cstParamUnit[] = {
	{UNIT_SYM_MILI,UNIT_MULTI_MILI},
	{UNIT_SYM_KILO,UNIT_MULTI_KILO},
	UNIT_LIST_END
};

const struct stParamValue cstParamValue[] = {
	{VALUE_SYMB_VOLTS,VALUE_NR_OF_VOLTS},
	{VALUE_SYMB_AMPS,VALUE_NR_OF_AMPS},
	{VALUE_SYMB_WATTS,VALUE_NR_OF_WATTS},
	VALUE_LIST_END
};

const struct stTextValus cstTextValus[] = {
	{"MAX",TEXT_VAL_MAX_VAL},
	{"MIN",TEXT_VAL_MIN_VAL},
	{"TRUE",TEXT_VAL_TRUE},
	{"FALSE",TEXT_VAL_FALSE},
	{"ON",TEXT_VAL_ON},
	{"OFF",TEXT_VAL_OFF},
	TEXT_VAL_LIST_END
};

/************************************************************************/
/* Global functions                                                     */
/************************************************************************/	

const struct stScpi_command* GET_SCPI_PRGLAN_LIST(void)
{
	return cstScpiCmds;
}

const struct stParamUnit* GET_SCPI_UNIT_LIST(void)
{
	return cstParamUnit;
}

const struct stParamValue* GET_SCPI_VALUE_LIST(void)
{
	return cstParamValue;
}

const struct stTextValus* GET_SCPI_TEXT_VAL_LIST(void)
{
	return cstTextValus;
}

/*
* 1)	rozlozit prichozi zpravu na nody, parametry a odstranit pripadne suffixy nodu. Posledni node ponechat s pripadnym '?'
* 2)	hledat prvni node prichozi zpravy v definovanych commandech a vsude kde bude shoda, ulozit ptr na na definovanou zpravu do 'PossibleScpiCommands' - zmena
* 3)	pokud byla nalezen alespon jeden vyskyt, jit na smycku, pokud ne ukoncit pokus s error hlaskou nespravny command
* 4)	foreach(loop) pro 'PossibleScpiCommands[x]'
* 5)		rozlozit na node definovanou zpravu a pro kazdy node si drzet priznak jestli je povinny, nebo ne
* 6)		testovat kratky/dlouhy format zpravy - v obou pripadech musi striktne sedet, jen u dlouheho formatu muzou bejt vsechny pismena velky
* 7)		testovat jestli pozice prichozi zpravy nepreskocila nejaky povinny node definovane zpravy
* 8)		pokud je vse ok, z cstScpiCmds[x] ziskat program language command 
* 9)	foreach end
* 10)	pokud nebyla shoda, volitelne zkusit napojit serii nodu z predchoziho commandu a opakovat pokus parserovani
* 11)	pokud aji tento pokus selhal, vratit errorovou hlasku neznamy command


-- potrebne uloziste na provedeni akce:

*/