通信协议设计

来源:互联网 发布:库里季后赛数据 编辑:程序博客网 时间:2024/06/03 10:17

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

__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 0