55 lines
1009 B
C++
55 lines
1009 B
C++
#ifndef NETWORKPROTOCOL_H
|
|
#define NETWORKPROTOCOL_H
|
|
|
|
#include "GlobalDefine.h"
|
|
#include "ProtocolDefs.h"
|
|
|
|
class CNetworkProtocol
|
|
{
|
|
public:
|
|
CNetworkProtocol();
|
|
~CNetworkProtocol();
|
|
|
|
private:
|
|
void ResetRxStateMachine();
|
|
unsigned char CalcCRC(char *Buffer, int Size);
|
|
int TxData(unsigned char MessageID,unsigned char Flags,unsigned char *Data,int Size, unsigned char Address,unsigned char ID);
|
|
void RxStateMachine(unsigned char Data);
|
|
|
|
//State Machine states
|
|
enum States
|
|
{
|
|
Initialization,
|
|
RxHeader,
|
|
RxID,
|
|
RxAdd,
|
|
RxMyID,
|
|
RxMyAddress,
|
|
RxFlags,
|
|
RxCMD,
|
|
RxSize1,
|
|
RxSize2,
|
|
RxData,
|
|
RxCRC
|
|
};
|
|
|
|
|
|
char *RxBuff;
|
|
char mRxData[MAX_MESSAGE_SIZE+10];
|
|
|
|
int RxState;
|
|
int RxSize;
|
|
char SenderID;
|
|
char SenderAddress;
|
|
int RxCmd;
|
|
int DataCnt;
|
|
int BufPtr;
|
|
unsigned char CRC;
|
|
unsigned char Flags;
|
|
|
|
unsigned char State;
|
|
|
|
};
|
|
|
|
#endif // NETWORKPROTOCOL_H
|