/*
 * API_common_defs.h
 *
 * Created: 4.3.2016 18:59:26
 *  Author: Chenda
 */ 


#ifndef API_COMMON_DEFS_H_
#define API_COMMON_DEFS_H_

/************************************************************************/
/* API message codes                                                    */
/************************************************************************/
#define API_RESP_ACK_MARK		0xFE
#define API_RESP_NACK_MARK		0xFF

/* Message types  */
#define API_CMD_MESS			0
#define API_ACK_MESS			1
#define API_NACK_MESS			2

/* API layer event type  */
#define API_NO_ACTION			0
#define API_PERIPH_NOT_AVAILBLE	1		// event according periphery status
#define API_ERROR				8		// event cleared to "API_NO_ACTION" by higher layer
/* --Receiver events */
#define API_RESP_WAITING		2		// event according periphery status
#define API_RECEIVING			3		// event according periphery status
#define API_FOREIGN_MESS		4		// event cleared to "API_NO_ACTION" by higher layer
#define API_PUBLIC_MESS			5		// event cleared to "API_NO_ACTION" by higher layer
#define API_GROUP_MESS			6		// event cleared to "API_NO_ACTION" by higher layer
#define API_PRIVATE_MESS		7		// event cleared to "API_NO_ACTION" by higher layer
/* --Transmitter events */
#define API_WAIT_FOR_REC		2		// event according periphery status
#define API_SENDING				3		// event according periphery status
#define API_SEND				4		// event seted by higher layer to initiate sending data
#define API_SEND_ACK_NACK			5		// event seted by higher layer to initiate sending ack/nack with data possibly

/************************************************************************/
/* UART1 API error codes                                                */
/************************************************************************/
#define API_E_NOT_RESP_MESS		64
#define API_E_NOT_CMD_MESS		65
#define API_E_UNKNOWN_CMD		66
#define API_E_CMD_PARAM			67

/************************************************************************/
/* API layer structure                                                  */
/************************************************************************/
struct stAPI_layer
{
	struct Receiver
	{
		uint8_t Event;
		uint8_t CmdAckNack_type;	// ACK & NACK = respond message, Cmd = Command message
		uint8_t SourceAdd;
		uint8_t TargetAdd;
		uint8_t Command;			// Respond - > contains responded command
		bool ExpectRespond;			// If is query, periphery wil expect respond, only if Command message
		// RAW data
		uint8_t DataLength;
		uint8_t *Data;				// READ ONLY!!! - points to source buffer start read position
		// Data as value
		//int16_t IntPartOfNumber;
		//int16_t TentPartOfNumber;	// tenth part multiplied by 1000
		//uint8_t ValueOfNumber;		// 0 = no value; 1 = Volts; 2 = Amps; 3 = Watts
		// Error data
		uint8_t ErrorNumber;
	}RX;
	
	struct Transmitter
	{
		uint8_t Event;
		uint8_t CmdAckNack_type;	// ACK & NACK = respond message, Cmd = Command message
		uint8_t SourceAdd;
		uint8_t TargetAdd;
		uint8_t Command;			// Respond - > contains responded command
		bool ExpectRespond;			// If message is query, periphery will expect respond
		// RAW data
		uint8_t DataLength;
		uint8_t *Data;				// READ ONLY!!! - points to target buffer start write position
		// Data as value
		//int16_t IntPartOfNumber;
		//int16_t TentPartOfNumber;	// tenth part multiplied by 1000
		//uint8_t ValueOfNumber;		// 0 = no value; 1 = Volts; 2 = Amps; 3 = Watts
		// Error data
		uint8_t ErrorNumber;
	}TX;
};

#endif /* API_COMMON_DEFS_H_ */