/**********************************************************************
Project:    Automatic cat feeder
Date:       march 19 2006
Author:     Jean-Fran�ois Martel
Target:     PIC 18F252
Compiler:   Microchip mcc18
Filename:	Protocol.h

File description:	Communication protocol implementation.


jean-francois.martel@polymtl.ca
**********************************************************************/


#ifndef BOOTLOADERINTERFACE_H
#define	BOOTLOADERINTERFACE_H

//Protocol buffer specific definitions

#define MASTER_ADDRESS 0x01
#define MY_DEVICE_ADDRESS 0x01

#define ADDRESS 0x01

//State Machine states
enum States
{
	Initialization,
	RxHeader,
    RxAdd,
	RxID,
	RxMyID,
	RxMyAddress,
	RxFlags,
	RxCMD,
	RxSize1,
	RxSize2,
    RxSize3,
    RxSize4,
	RxData,
	RxCRC		
};

//enum DEVICES_IDS
//{
//	ID_MASTER,		//Master Controller
//	ID_CONSOLE,		//LCD Console
//	ID_PC,			//PC
//	ID_AV_MUX,		//Audio Video Multiplexer
//	ID_IR_REMOTE,
//	ID_DEADBOLT
//};

//enum MESSAGE_IDS
//{
//	TX_NETWORK_ACK = 1,
//	RX_GET_STATUS,
//	TX_DEADBOLT_STATUS,
//
//	MAX_NETWORK_CMD
//};

//State machine states definition

void ProtocolInit(void);
void StateMachine(unsigned char STATE);
void ProtocolAnalyzeNewData(unsigned char RxByte);
void ResetStateMachine(void);
void ProtocolExecCmd(void);
void ProtocolAcknowledge(unsigned char Answer,unsigned char Cmd, unsigned char Data);
unsigned char* ProtocolGetFrame(unsigned char DestDevice,unsigned char DestAddress, unsigned char SenderDevice, unsigned char Cmd, unsigned char *Data,unsigned int Size,unsigned char Flags, int *FrameSize);
unsigned char ProtocolCalcCrc(unsigned char* Buffer,unsigned char size);
unsigned char ProtocolIsReceiving(void);
unsigned char *ProtocolMsgDataPtr();

#endif