/***********************************************************************//**
 * @file		SerialCOM.h
 * @brief		Contains all functions for Serial communication
 * @version		1.0
 * @date		19. March 2014
 * @author		Michal Semrad
 **************************************************************************/
#ifndef SERIAL_H
#define SERIAL_H

#include "lpc17xx_uart.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_gpio.h"

#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "queue.h"
#include "timers.h"

#include "LED.h"
#include "kinematic.h"
#include "pwm.h"
#include "common.h"
#include "RobotControl.h"

#define LPC_UARTx LPC_UART3

#define SLIP_END        192    /* indicates end of packet */
#define SLIP_ESC        219    /* indicates byte stuffing */
#define SLIP_ESC_END    220    /* ESC ESC_END means END data byte */
#define SLIP_ESC_ESC    221    /* ESC ESC_ESC means ESC data byte */
#define MAX_PACKET_L	1800

#define ID_X        	1
#define ID_Y        	2
#define ID_Z        	3
#define ID_BETA        	4
#define ID_ALPHA       	5
#define ID_GRIP        	6

#define ID_Q0        	7
#define ID_Q1        	8
#define ID_Q2        	9
#define ID_Q3       	10

#define ID_STARTPOS		11
#define ID_INSTR       	12
#define ID_SPEED		13
#define ID_XYZABG		21
#define ID_ANGLES		22

#define ID_FREEHEAP		30
#define ID_TASKLIST		31
#define ID_QFREEHEAP	32
#define ID_QTASKLIST	33

#define ID_LOGGER		40

#define ID_RESET		45
#define ID_PAUSE		46
#define ID_CONTINUE		47

#define ID_CYCLIC		51
#define ID_ONCE			52
#define ID_SENDAGAIN	53

#define ID_PWMON		54
#define ID_PWMOFF		55

char packet_buffer[MAX_PACKET_L];

/*send again purposes*/
char id_previous;
char* data_previous;
int len_previous;

void SerialInit(void);
void SerialCOMTask(void * pvParameters);
void SlipSend(char id, char * data, int len);
void SerialProcessPacket(char packet[], int length);
void LogMessage(char* message,int len);
uint16_t crc_get(uint8_t * data, int len);

#endif /* SERIAL_H */
