修复iccid上报不正确的问题

This commit is contained in:
wjw 2025-07-16 15:24:50 +08:00
parent 9e558dc926
commit 1ff4910f55
3 changed files with 41 additions and 1 deletions

View File

@ -34,4 +34,12 @@ uint8_t *BcdToStr(uint8_t *str, const uint8_t *bcd, int bcd_len);
// strlen 为原始BCD数据字节数
uint8_t *rawBcdToStr(uint8_t *str, const uint8_t *bcd, int bcd_len);
/**
* @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);
#endif // JT808_UTIL_H_

View File

@ -667,7 +667,7 @@ void jt808_set_term_param_init(void){
memcpy(jt808_term_param_item.big_term_attr_resp.manufacturer_id, "LAT01", 5); // 制造商ID
memcpy(jt808_term_param_item.big_term_attr_resp.term_model, jt808_term_param_item.big_reg_info.term_model, 20); // 终端型号
memcpy(jt808_term_param_item.big_term_attr_resp.term_id, jt808_term_param_item.big_reg_info.term_id, 7); // 终端ID
memcpy(jt808_term_param_item.big_term_attr_resp.term_ICCID+4, jt808_term_param_item.phone_BCDnum, 6); // 终端手机号码
// memcpy(jt808_term_param_item.big_term_attr_resp.term_ICCID+4, jt808_term_param_item.phone_BCDnum, 6); // 终端手机号码
char str_hw_ver[] = "1.0.0"; // 硬件版本
char str_fw_ver[] = "1.0.1"; // 固件版本 原本为1.0.0
@ -771,6 +771,21 @@ void jt808_set_term_param_init(void){
JT808_DEBUG_DATA("%02X ",jt808_term_param_item.phone_BCDnum[i]);
}
JT808_DEBUG_DATA("\n");
size_t iccid_len = strlen(cm_iccid);
if(iccid_len > 0) {
// 确保不超过term_ICCID容量(10字节=20位BCD)
if(iccid_len > 20) iccid_len = 20;
// 将ASCII ICCID转换为BCD格式
uint8_t bcd_buffer[10] = {0};
ascii_to_bcd(cm_iccid, iccid_len, bcd_buffer);
// 复制到终端属性结构体
memcpy(jt808_term_param_item.big_term_attr_resp.term_ICCID,
bcd_buffer,
sizeof(jt808_term_param_item.big_term_attr_resp.term_ICCID));
}
}while(0);
do{// 注册信息初始化
char read_buf[35] = {0};

View File

@ -91,3 +91,20 @@ uint8_t *rawBcdToStr(uint8_t *str, const uint8_t *bcd, int bcd_len){
}
return str;
}
/**
* @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) {
size_t bcd_len = (len + 1) / 2; // 计算需要的BCD字节数
for(size_t i = 0; i < bcd_len; i++) {
uint8_t high = (i*2 < len) ? (ascii[i*2] - '0') : 0;
uint8_t low = (i*2+1 < len) ? (ascii[i*2+1] - '0') : 0;
bcd_out[i] = (high << 4) | low;
}
}