12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #pragma once
- #include <Cmnpp/IProtocol.h>
- #include <memepp/variable_buffer.hpp>
- #include <memepp/buffer_view.hpp>
- struct ret_value
- {
- double double_value;
- char str_value[255];
- int str_len;
- int type =0;
- };
- class DataHelper
- {
- public:
- // 检查给定数据缓冲区的校验和是否正确
- // 参数:
- // buf: 数据缓冲区数组
- // start: 校验和开始位置的索引
- // len: 校验和计算的字节数
- // checksum: 校验和计算的字节数
- // 返回值: 校验和是否正确的布尔值
- static void check_sum(uint8_t buf[], int start, int len, uint8_t checksum[]);
- // 获取buf数组的长度,因为buf数组是静态存储的,因此使用静态关键字static进行修饰
- // 参数:
- // - buf: 字节数组
- // 返回值:
- // - int: buf数组的长度
- static int get_len(uint8_t buf[]);
-
- // 生成协议的数组长度:
- // len: 生成的字节数组的长度
- // afterLen: 生成的字节数组的数组名
- static void generate_len(int len, uint8_t after_len[]);
- // 该函数用于从给定的字节数组buf中获取无符号整数,并返回该整数值
- // 参数:
- // - buf: 存储无符号整数的字节数组
- // - len: 字节数组的长度
- static int get_unsigned_int(uint8_t buf[], int len);
- // 该函数用于从给定的字节数组中获取一个有符号整数
- // 参数:
- // - buf:存放字节的数组
- // - len:字节数组的长度
- // 返回值:获取到的有符号整数
- static int get_signed_int(uint8_t buf[], int len);
- // 该函数用于从给定的字节数组中获取无符号的双精度浮点数
- // 参数:
- // - buf: 存储字节的数组
- // - len: 字节数组的长度
- // - factor: 用于缩放浮点数的因子
- // 返回值:获取到的无符号双精度浮点数
- static double get_unsigned_double(uint8_t buf[], int len, int factor);
-
- // 从buf数组中获取有len个元素的双精度有符号整数,每个元素的权因子为factor
- // 返回结果为获取到的双精度有符号整数
- static double get_signed_double(uint8_t buf[], int len, int factor);
-
- // 将一个字节的 ASCII 字符拷贝到缓冲区中
- // 参数:
- // - dest: 指向目标缓冲区的指针
- // - b: 要拷贝的字节
- // - index: 缓冲区中当前已拷贝的字节数,更新为拷贝后的值
- // 返回值:无
- static void buffer_copy_uint8_ascii(uint8_t* dest, uint8_t b, uint8_t &index);
-
- // 将一个字节的 ASCII 字符拷贝到缓冲区中
- // 参数:
- // - dest: 指向目标缓冲区的指针
- // - b: 要拷贝的字节
- // - index: 缓冲区中当前已拷贝的字节数,更新为拷贝后的值
- // 返回值:无
- static void buffer_copy_uint16_ascii(uint8_t* dest, uint16_t b, uint8_t &index);
-
- // 将一个字节的 ASCII 字符拷贝到缓冲区中
- static int buffer_from_ascii_uint8(uint8_t* dest, uint8_t* src, int len);
- // 从缓冲区中读取一个字节的 ASCII 字符
- static uint8_t read_uint8_ascii(uint8_t* src, uint8_t &index);
- // 从缓冲区中读取两个字节的 ASCII 字符
- static uint16_t read_uint16_ascii(uint8_t* src, uint8_t &index);
-
- };
|