2025-07-10 17:36:16 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
#include "protocol_struct.hpp"
|
|
|
|
|
|
#include "mqtt_config.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
namespace ProtocolCodec
|
|
|
|
|
|
{
|
|
|
|
|
|
// BCC 校验
|
|
|
|
|
|
uint8_t calculate_bcc(const std::vector<uint8_t> &data);
|
|
|
|
|
|
|
|
|
|
|
|
// 编码 FullPacket 为字节流(使用大端)
|
|
|
|
|
|
std::vector<uint8_t> encode_full_packet(const FullPacket &packet);
|
|
|
|
|
|
|
|
|
|
|
|
// 解码字节流为 FullPacket(成功返回 packet,否则 std::nullopt)
|
|
|
|
|
|
std::optional<FullPacket> decode_full_packet(const std::vector<uint8_t> &buffer);
|
|
|
|
|
|
|
|
|
|
|
|
// 构造心跳包
|
|
|
|
|
|
FullPacket create_heartbeat_packet(const std::string &vin);
|
|
|
|
|
|
|
|
|
|
|
|
std::optional<MqttParamSetting> parse_mqtt_param_setting(const std::vector<uint8_t> &data);
|
|
|
|
|
|
|
2025-07-11 17:37:54 +08:00
|
|
|
|
std::optional<VehicleMessage> parse_vehicle_message(const std::vector<uint8_t> &data);
|
|
|
|
|
|
|
2025-07-10 17:36:16 +08:00
|
|
|
|
std::vector<uint8_t> make_ack_response(const FullPacket &request, bool result);
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace ProtocolCodec
|