kunlang_mqtt_client/include/protocol_struct.hpp
2025-07-10 17:36:16 +08:00

72 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <string>
#include <vector>
#include <cstdint>
#include <optional>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
// ==========================
// 🕒 32960 时间结构(用于数据单元)
// ==========================
struct TimeStamp
{
uint8_t year; // 年0~99
uint8_t month; // 月1~12
uint8_t day; // 日1~31
uint8_t hour; // 小时0~23
uint8_t minute; // 分钟0~59
uint8_t second; // 秒0~59
};
// ==========================
// 📦 通用数据包结构(协议层)
// ==========================
struct FullPacket
{
uint8_t start_flag1 = 0x23; // 起始符 '#'
uint8_t start_flag2 = 0x23; // 起始符 '#'
uint8_t command_id; // 命令标识(如 0x81、0xD3 等)
uint8_t response_flag; // 应答标志0xFE 表示命令包)
std::string vin; // 17 字节 VIN 编码ASCII
uint8_t encryption_method; // 加密方式0x01 无加密)
uint16_t data_length; // 数据单元长度
std::vector<uint8_t> data_unit; // 数据单元(二进制)
uint8_t checksum; // BCC 校验值
};
// ==========================
// ⚙️ MQTT 参数项结构0x81 子项)
// ==========================
struct MqttParameterItem
{
uint8_t param_id; // 参数 ID如 0x86~0x8B
std::vector<uint8_t> value; // 参数值(动态长度)
};
// ==========================
// 📡 设置 MQTT 参数(命令 0x81
// ==========================
struct MqttParamSetting
{
TimeStamp timestamp; // 设置时间6 字节)
uint16_t sequence; // 流水号2 字节)
uint8_t param_count; // 参数个数0~2520xFE 异常0xFF 无效)
std::vector<MqttParameterItem> items; // 参数项列表
};
// ==========================
// 🚗 车辆上报/通知/广播结构(命令 0xD3 / 0xD4 / 0xD5
// ==========================
struct VehicleMessage
{
TimeStamp timestamp; // 时间6 字节)
uint16_t sequence; // 流水号2 字节)
uint16_t message_length; // 消息内容长度2 字节)
std::string json_payload; // JSON 字符串消息内容
};