62 lines
1.6 KiB
C
62 lines
1.6 KiB
C
#pragma once
|
||
#pragma pack(1)
|
||
|
||
#include "kdefine.h"
|
||
|
||
__NAMESPACE_BEGIN__(HJ)
|
||
|
||
#define FRAME_HEADER_LENGTH (5)
|
||
#define FRAME_TAILE_LENGTH (4)
|
||
|
||
typedef enum tagErrorCode : unsigned char
|
||
{
|
||
ERR_OK = 0X00,
|
||
ERR_INVALID_LEN = 0X01,
|
||
ERR_INVALID_UTF8 = 0X02,
|
||
ERR_INVALID_BUF_LEN = 0X03,
|
||
ERR_INVALID_JSON_FMT = 0X04,
|
||
ERR_INVALID_FSUCODE = 0X05,
|
||
ERR_INVALID_CFG_CONTENT = 0X06, // 文件内容错误
|
||
ERR_RETRANS_CONTENT = 0X07, // 重传文件内容
|
||
ERR_PERMISSION_DENIED = 0X08, //写文件权限不够
|
||
ERR_UNKOWN = 0XFF
|
||
} ErrorCode;
|
||
|
||
typedef enum tagFrameType : unsigned char
|
||
{
|
||
Frame_Response = 0x00, //返回帧
|
||
Frame_Request = 0x01, //请求帧
|
||
Frame_Echo_Request = 0x02, //测试请求帧
|
||
Frame_DeviceData_Request = 0x03, //来自采集程序的数据请求包,将数据保存到数据库中
|
||
Frame_Configure_DB_Request = 0x04, //上传配置文件
|
||
} FrameType;
|
||
|
||
typedef struct tagFrameTail
|
||
{
|
||
unsigned char frame_delimiter[4] = { 0xEE,0xFF,0xEE,0xFF };
|
||
} FrameTail;
|
||
|
||
#define FRAME_HEADER_LENGTH (5) // frame_type(1) + frame_len(4)
|
||
|
||
typedef struct tagFrame
|
||
{
|
||
FrameType frame_type; //帧类型
|
||
unsigned int frame_len; //帧数据长度
|
||
unsigned char frame_content[1]; //帧的内容,实际应为json字符串,由json内容自解释
|
||
tagFrame()
|
||
{
|
||
frame_type = Frame_Response;
|
||
frame_len = 1;
|
||
frame_content[0] = ERR_OK;
|
||
}
|
||
void setErrorFrame(ErrorCode err = ERR_OK)
|
||
{
|
||
frame_len = 1;
|
||
frame_content[0] = err;
|
||
}
|
||
} MessageFrame;
|
||
|
||
__NAMESPACE_END__(HJ)
|
||
|
||
#pragma pack()
|