
#ifndef __UDP_KOMUNIKACE_H
#define __UDP_KOMUNIKACE_H

#include "stdint.h"
#include "udp.h"

// Definice offsetu hlavicky protokolu

#define OFFSET_UDP_Kom_Ident			OFFSET_UDP_Data+0		// 2 byte identifikace spravneho komunikacniho "paketu"
#define OFFSET_UDP_Kom_Typ				OFFSET_UDP_Data+2		// 1 byte urcujici typ zpravy (zadost o data nebo zaslani parametru)
#define OFFSET_UDP_Kom_Delka			OFFSET_UDP_Data+3		// 1 byte urcujici delku dat pri typu "zasilani parametru" = pocet parametru
#define OFFSET_UDP_Kom_Parametr			OFFSET_UDP_Data+4		// 1 byte kodu parametru
#define OFFSET_UDP_Kom_Hodnota			OFFSET_UDP_Data+5		// 2 byte hodnoty parametru

// Definice delek datoveho obsahu "paketu"
#define UDPKom_Parametr_delka			1		// 1 byte
#define UDPKom_Hodnota_delka			2		// 2 byte

// Definice typu "paketu"
#define UDPKom_Zadost					0x01	// Kod typu urcujici ze je "paket" zadosti o data
#define UDPKom_Nastaveni				0x02	// Kod typu urcujici ze "paket" obsahuje data s nastavenim
#define UDPKom_Odpoved					0x03	// Kod typu urcujici ze "paket" obsahuje odpoved na zadost s daty

// Definice nastavovanych parametru
#define UDPKom_Param_PWM1max			1
#define UDPKom_Param_PWM2max			2
#define UDPKom_Param_PWM3max			3
#define UDPKom_Param_PWM4max			4
#define UDPKom_Param_PWM5max			5
#define UDPKom_Param_PWM1set			6
#define UDPKom_Param_PWM2set			7
#define UDPKom_Param_PWM3set			8
#define UDPKom_Param_PWM4set			9
#define UDPKom_Param_PWM5set			10
#define UDPKom_Param_FANset				11
#define UDPKom_Param_FANtemp1			12
#define UDPKom_Param_FANtemp2			13
#define UDPKom_Param_FANtemp3			14
#define UDPKom_Param_FANtemp4			15
#define UDPKom_Param_FANval1			16
#define UDPKom_Param_FANval2			17
#define UDPKom_Param_FANval3			18
#define UDPKom_Param_FANval4			19
#define UDPKom_Param_Backlight			20
#define UDPKom_Param_FANforced			21
#define UDPKom_Param_Time				22
#define UDPKom_Param_TimeDAY			23
#define UDPKom_Param_TimeMONTH			24
#define UDPKom_Param_TimeYEAR			25
#define UDPKom_Param_TimeHOUR			26
#define UDPKom_Param_TimeMINUTE			27
#define UDPKom_Param_TimeSECOND			28
#define UDPKom_Param_LED6set			29
#define UDPKom_Param_LEDmode			30
#define UDPKom_Param_FlashSensorErase	31

// Definice offsetu parametru odesilanych do PC
#define UDPKom_Download_HeaderLen		4
#define UDPKom_Upload_HeaderLen			4

#define UDPKom_OFFSET_UploadIdent		OFFSET_UDP_Data+0		// 2 byte
#define UDPKom_OFFSET_UploadType		OFFSET_UDP_Data+2		// 1 byte
#define UDPKom_OFFSET_UploadDelka		OFFSET_UDP_Data+3		// 1 byte
#define UDPKom_OFFSET_UploadData		OFFSET_UDP_Data+4		// i*3 byte
#define UDPKom_OFFSET_UploadParametr	OFFSET_UDP_Data+4		// 1 byte
#define UDPKom_OFFSET_UploadHodnota		OFFSET_UDP_Data+5		// 2 byte

// Definice odesilanych parametru
#define UDPKom_Upload_PWM1				1
#define UDPKom_Upload_PWM2				2
#define UDPKom_Upload_PWM3				3
#define UDPKom_Upload_PWM4				4
#define UDPKom_Upload_PWM5				5
#define UDPKom_Upload_CurrRAW1			6
#define UDPKom_Upload_CurrRAW2			7
#define UDPKom_Upload_CurrRAW3			8
#define UDPKom_Upload_CurrRAW4			9
#define UDPKom_Upload_CurrRAW5			10
#define UDPKom_Upload_Curr1				11
#define UDPKom_Upload_Curr2				12
#define UDPKom_Upload_Curr3				13
#define UDPKom_Upload_Curr4				14
#define UDPKom_Upload_Curr5				15
#define UDPKom_Upload_Temp1				16
#define UDPKom_Upload_Temp2				17
#define UDPKom_Upload_Temp3				18
#define UDPKom_Upload_HumRAW			19
#define UDPKom_Upload_Hum				20
#define UDPKom_Upload_FAN				21
#define UDPKom_Upload_Temp4				22
#define UDPKom_Upload_TCPState			23														
#define UDPKom_Upload_TCPTimeout1		24
#define UDPKom_Upload_TCPTimeout2		25
#define UDPKom_Upload_TCPTimeout3		26
#define UDPKom_Upload_TCPTimeout4		27
#define UDPKom_Upload_PlanovacCelkem	28
#define UDPKom_Upload_PlanovacAktiv		29
#define UDPKom_Upload_PlanovacData1		30		// Zacatek Den+Mesic
#define UDPKom_Upload_PlanovacData2		31		// Zacatek Rok+Hodina
#define UDPKom_Upload_PlanovacData3		32		// Zacatek Minuta+Vterina
#define UDPKom_Upload_PlanovacData4		33		// Aktualne Den+Mesic
#define UDPKom_Upload_PlanovacData5		34		// Aktualne Rok+Hodina
#define UDPKom_Upload_PlanovacData6		35		// Aktualne Minuta+Vterina
#define UDPKom_Upload_PlanovacData7		36		// Kanal 1+2
#define UDPKom_Upload_PlanovacData8		37		// Kanal 3+4
#define UDPKom_Upload_PlanovacData9		38		// Kanal 5+6
#define UDPKom_Upload_PlanovacData10	39		// Stav + 0x00
#define UPPKom_Upload_LED6				40

// Definice offsetu dat ve vysilanem UDP datagramu
#define UDPKom_OFFSET_UploadPWM1		OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 0
#define UDPKom_OFFSET_UploadPWM2		OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 3
#define UDPKom_OFFSET_UploadPWM3		OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 6
#define UDPKom_OFFSET_UploadPWM4		OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 9
#define UDPKom_OFFSET_UploadPWM5		OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 12
#define UDPKom_OFFSET_CurrRAW1			OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 15
#define UDPKom_OFFSET_CurrRAW2			OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 18
#define UDPKom_OFFSET_CurrRAW3			OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 21
#define UDPKom_OFFSET_CurrRAW4			OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 24
#define UDPKom_OFFSET_CurrRAW5			OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 27
#define UDPKom_OFFSET_Curr1				OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 30
#define UDPKom_OFFSET_Curr2				OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 33
#define UDPKom_OFFSET_Curr3				OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 36
#define UDPKom_OFFSET_Curr4				OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 39
#define UDPKom_OFFSET_Curr5				OFFSET_UDP_Data+UDPKom_Upload_HeaderLen + 42

// Definice synchronizacniho slova
#define UDPKom_SyncWord					0xABCD

// Prototypy funkci
uint8_t UDPKom_ProcessData(uint8_t *RX_buffer);
uint8_t UDPKom_SendDataFromRX(uint8_t *RX_buffer, uint8_t *TX_buffer);
uint8_t UDPKom_CheckIdent(uint8_t *RX_buffer);

#endif
/* Konec souboru */
