25 lines
768 B
C
25 lines
768 B
C
|
|
#pragma once
|
|||
|
|
|
|||
|
|
#include "protocol_struct.h"
|
|||
|
|
#include <vector>
|
|||
|
|
#include <string>
|
|||
|
|
#include <cstdint>
|
|||
|
|
|
|||
|
|
namespace ProtocolCodec
|
|||
|
|
{
|
|||
|
|
// 获取当前北京时间,返回 6 字节 vector {year, month, day, hour, minute, second}
|
|||
|
|
std::vector<uint8_t> get_current_time_bytes();
|
|||
|
|
|
|||
|
|
// 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);
|
|||
|
|
|
|||
|
|
std::vector<uint8_t> make_ack_response(const FullPacket &request, bool result);
|
|||
|
|
|
|||
|
|
} // namespace ProtocolCodec
|