您的位置:首页 > 其它

通信协议设计

2015-09-18 13:57 246 查看
下面是一个分层体系结构的协议。

__packed struct xxFrameStruct
{
u16  sync;             //同步字,高字节0xaa 低字节0x55
u8   verandihl;        //版本与头长度,各占4位,高4位为版本号,低4位*2=包头长度
u8   frameindex;       //包序号,同一个包的多个帧中,序号是不变的
u16  totallength;      //数据总长度,不包含结构头的长度
u8   ServiceType;      //服务类型
u8   reserve ;         //保留
_packed_ union
{
struct RequestStruct  Request;
struct ErrorStruct    Error;
u8 bytes[258];
};
}xxFrame,*pxxFrame;
__packed struct RequestStruct
{
u8  proandchl;     //协议和通道,高4位协议,低4位通道号
u8  CommandHead;  //命令字
_packed_ union
{
struct ParameterStruct CommParameterStruct;
struct RequestStruct CommBytes;
struct ResponseStruct ResponseBytes;
u8  bytes[258];
};
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: