/*==================================================================================================

FILE INFORMATION HEADER

USED IN PROJECT:			S1003065-01 PPS-TX/S1003067-01 PPS-RX software application
ITEM TYPE:					Source Code
ITEM NAME:					xlru_message_def.h
ITEM DESCRIPTION:			This file contains the definitions of messages
TARGET:						ATSAM4LC8B / ATSAM4LS8B
DOC REFERENCES:				SWDS1003065-01/SWDS1003065-01
PROGRAMMER NAME(S):			A.Chessa, L.Vallongo
COPYRIGHT:					LEONARDO-FINMECCANICA S.p.A
REVISION HISTORY:
- 01.00: first release

====================================================================================================
© Copyright LEONARDO S.p.A.. All rights reserved
Any right of industrial and intellectual property on this document,
and of technical Know-how herein contained, belongs to
LEONARDO S.p.A. and/or third parties.
According to the law, it is forbidden to disclose, reproduce or however
use this document and any data herein contained for any use without
previous written authorization by LEONARDO S.p.A.
==================================================================================================*/


#ifndef XLRU_MESSAGE_DEF_H_
#define XLRU_MESSAGE_DEF_H_

#define DEBUG		//use to debug with no LCU connected

#define BUFFER_DIM 					1024
#define BUFFER_DIM_MIN_RESPONSE		4

//HEADER
#define	SOM				'@'
#define DSTID_BROADCAST	'0'
#define DSTID_PSM		'1'
#define DSTID_PPS		'2'
#define DSTID_LCU		'3'

#define DSTID_PSM_INT	1
#define DSTID_PPS_INT	2
#define DSTID_LCU_INT	3

#define XGET			'_'

#define STATUS_SPARE	'_'

#define SOM_REPLY			'!'
#define SRCID_LCU			'3'
#define ACK_NO_ERROR		'+'
#define ACK_GENERIC_ERROR	'-'
#define ACK_CHECKSUM_ERROR	'*'
#define ACK_PAYLOAD_ERROR	'?'
#define CR_EOM				'\r'			//(uint8_t)(13)		//CR

const char FCS[16] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'};
const char MSGID[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
						'Q','R','S','T','U','V','W','X','Y','Z'};
const char MSG_NICE[] = "NICE00";

#define EIF_HEADER_LEN		4
#define EIF_FOOTER_LEN		3

// BYTES INDEX OF MESSAGE
//	HEADER BYTES INDEX Common to both RX & TX message
#define	SOM_INDEX			0
#define DSTID_INDEX			1
#define FCS_INDEX			2
#define ACK_INDEX			3

#define DEF_NO_ERROR		0
#define DEF_MISSING_LINK	1
#define DEF_RX_CHECKSUM		2
#define DEF_TOO_SHORT		3
#define DEF_ERROR_DECODING	4

//error definitions into decode rx messages
#define DECODE_NO_ERROR		0
#define DECODE_TOO_SHORT	1
#define DECODE_NOT_VALID    2

//define string message
#define STR_TOO_SHOORT			"msg short"
#define STR_NOT_SOM_REPLY 		"don't start!"
#define STR_DEVICE_NOT_CORRECT	"not for LCU/PPS/PSM"
#define STR_INDEX_MSG_WRONG		"not actual."
#define STR_GENERIC_ERROR		"generic error"
#define STR_CHECKSUM_REC_ERROR	"checksum error"
#define STR_PAYLOAD_ERROR		"payload error"
#define STR_CHECKSUM_OK			"checksum ok"
#define STR_CHECKSUM_ERROR		"checksum error"
#define STR_ERROR_DECODING		"error into decode"

#if 0
struct unit_comm_status_t
{
	bool commDeviceOk;	//the communication device is working
	bool linkUp;		//communication with unit is OK. Unit status is valid
};

struct unit_basic_status_t	//Common to all units
{
	bool unitOk;		//unit is OK

	bool overtempWarning;	//Override-able over-temperature warning
	bool overtempHazard;	//No Override-able over-temperature hazard
};

struct unit_status_t
{
	unit_comm_status_t commStatus;
	unit_basic_status_t basicStatus;
};
#endif

struct xlru_unit_status_t
{
	bool unitOk;		//unit is OK

	bool overtempWarning;	//Override-able over-temperature warning
	bool overtempHazard;	//No Override-able over-temperature hazard

};

struct xlru_counter_t
{
	long int last_decode_error;		//count error into last decode response message
	long int rx_mess;				//count response messages
	long int rx_mess_error;			//count response messages with error
	long int no_response;			//count messages without response
	long int checksum_error;		//count checksum error
	char last_error[1024];				//report last error
	char last_rx[1024];					//last received message
	char last_tx[1024];					//last sent message
};


#endif /* XLRU_MESSAGE_DEF_H_ */

