2024-11-08 18:02:29 +08:00
|
|
|
|
|
|
|
|
|
|
#ifndef JT808_UTIL_H_
|
|
|
|
|
|
#define JT808_UTIL_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
// #include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
// 双字节大小端交换
|
|
|
|
|
|
uint16_t Swap16(uint16_t val16);
|
|
|
|
|
|
// 四字节大小端交换
|
|
|
|
|
|
uint32_t Swap32(uint32_t val32);
|
|
|
|
|
|
// 异或校验
|
|
|
|
|
|
uint8_t BCC_Check(const uint8_t *src, uint32_t len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 十进制转BCD码
|
|
|
|
|
|
uint8_t DecToBcd(uint8_t Dec);
|
|
|
|
|
|
|
|
|
|
|
|
// BCD码转十进制
|
|
|
|
|
|
uint8_t BcdToDec(uint8_t Bcd);
|
|
|
|
|
|
|
|
|
|
|
|
// 原始字符串转BCD码 //奇数位时,首位BCD码前面补0
|
|
|
|
|
|
uint8_t *rawStrToBcd(uint8_t *bcd, const uint8_t *str, uint16_t str_len);
|
|
|
|
|
|
|
|
|
|
|
|
// BCD转字符串,自动去掉bcd码前导零
|
|
|
|
|
|
// bcdlen 为bcd码字节数
|
|
|
|
|
|
uint8_t *BcdToStr(uint8_t *str, const uint8_t *bcd, int bcd_len);
|
|
|
|
|
|
|
|
|
|
|
|
// 原始BCD数据转字符串
|
|
|
|
|
|
// strlen 为原始BCD数据字节数
|
|
|
|
|
|
uint8_t *rawBcdToStr(uint8_t *str, const uint8_t *bcd, int bcd_len);
|
|
|
|
|
|
|
2025-07-16 15:24:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 将ASCII字符串转换为BCD编码
|
|
|
|
|
|
* @param ascii 输入字符串
|
|
|
|
|
|
* @param len 字符串长度
|
|
|
|
|
|
* @param bcd_out 输出BCD数组
|
|
|
|
|
|
*/
|
|
|
|
|
|
void ascii_to_bcd(const char* ascii, size_t len, uint8_t* bcd_out);
|
|
|
|
|
|
|
2024-11-08 18:02:29 +08:00
|
|
|
|
#endif // JT808_UTIL_H_
|