
#include <delay.h>
#include <stdio.h>
#include <mega162.h>
#include <mega162_bits.h>

//USART BaudRate
#define BAUDRATE1200H 0x02
#define BAUDRATE1200L 0x40   
#define BAUDRATE2400H 0x01   
#define BAUDRATE2400L 0x1F   
#define BAUDRATE4800H 0x00   
#define BAUDRATE4800L 0x8F   
#define BAUDRATE9600H 0x00   
#define BAUDRATE9600L 0x47   
#define BAUDRATE19200H 0x00   
#define BAUDRATE19200L 0x23   
#define BAUDRATE38400H 0x00   
#define BAUDRATE38400L 0x11   
#define BAUDRATE57600H 0x00   
#define BAUDRATE57600L 0x0B   
#define BAUDRATE115200H 0x00  
#define BAUDRATE115200L 0x05  

//used for delay.h
#define Wait_5s 50  //5000ms
#define Wait_2s 20  //2000 ms
#define Wait_1s 10  //1000 ms
#define Wait_10ms 10  //10 ms  
#define Wait_5ms 5    //5 ms

//XBee commumication
#define ENTER_COMMAND_MODE "+++"
#define APPLY_COMMUNICATION_PARAMETERS "ATAC \r"
#define EXIT_COMMAND_MODE "ATCN \r"

void setPORTC_LED(char LED_number);
char XBeeEnterCommandMode (void);
void XBeeSetBaudRate (char * retezec, char baudRateXBee);
void XBeeSetParity (char * retezec, char parityXBee);
void XBeeSetUSARTParameters(char baudRateXBee, char parityXBee);
void SensorSetUSARTParameters(char baudRateSensor, char paritySensor);

char XBeeSendString (char * string);
char XBeeUdrRecieve (void);
char XBeeTransmitTestData (char * p_TestData, char count);


void XBeeUsartRecieve(char * p_programMemory, char * p_switchMemory, char * p_baudRateXBee, char * p_parityXBee, char * p_baudRateSensor, char * p_paritySensor, char * p_memory, char * p_stackForSensor, char * p_countStackForSensor);
void XBeeUsartRecieveConfirm(char * p_programMemory, char * p_switchMemory, char * p_memory,  char symbol); 
void XBeeUsartRecieveData(char * p_programMemory, char * p_switchMemory, char * p_baudRateXBee, char * p_parityXBee, char * p_baudRateSensor, char * p_paritySensor, char * p_stackForSensor, char * p_countStackForSensor, char symbol);

void SaveToStackForSensor(char symbol, char * p_stackForSensor, char * p_countStackForSensor);
char SensorUdrRecieve (void);
char SPIRecieve (void);
void SensorUsartRecieve(char * p_stackForPC, char * p_countStackForPC);
void SensorSPIRecieve(char * p_stackForPC, char * p_countStackForPC);