102 lines
2.3 KiB
C
102 lines
2.3 KiB
C
/**********************************************************************
|
||
Project: Automatic cat feeder
|
||
Date: march 19 2006
|
||
Author: Jean-Fran<61>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
|
||
#include "ProtocolDefs.h"
|
||
|
||
#define MASTER_ADDRESS 0x01
|
||
#define MY_DEVICE_ADDRESS 0x01
|
||
|
||
#define ADDRESS 0x01
|
||
|
||
enum eProtocolUser
|
||
{
|
||
NETWORK_PROTOCOL_USER_LORA,
|
||
NETWORK_PROTOCOL_USER_LTE
|
||
};
|
||
|
||
//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
|
||
|
||
typedef struct stProtocolData
|
||
{
|
||
unsigned char mRxData[MAX_MESSAGE_SIZE+10];
|
||
unsigned char mTxData[MAX_MESSAGE_SIZE+10];
|
||
unsigned int DataSize;
|
||
unsigned int DataCtr;
|
||
unsigned int BufPtr;
|
||
unsigned char RxPtr;
|
||
unsigned char Command;
|
||
unsigned char State;
|
||
unsigned char CRC;
|
||
unsigned char SenderID;
|
||
unsigned char SenderAddress;
|
||
unsigned char Flags;
|
||
unsigned char IsUpdating;
|
||
unsigned char *BmpDataPtr;
|
||
}ProtocolData_t;
|
||
|
||
void ProtocolInit(int User);
|
||
void StateMachine(unsigned char STATE, ProtocolData_t *ProtocolData);
|
||
void ProtocolAnalyzeNewData(unsigned char RxByte, int User);
|
||
void ResetStateMachine(ProtocolData_t *ProtocolData);
|
||
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(ProtocolData_t *ProtocolData);
|
||
|
||
#endif |