通信协议设计

下面是一个分层体系结构的协议。

__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];
    };      
};
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值