mirror of
http://180.163.74.83:13000/zhangzhenghao/AP05.git
synced 2025-12-15 16:14:29 +00:00
增加分组信息合包
This commit is contained in:
parent
876f563492
commit
efd64e3648
143
main.c
143
main.c
@ -121,9 +121,19 @@ static time_t first_3015_time = 0;
|
|||||||
static bool is_3015_collecting = false;
|
static bool is_3015_collecting = false;
|
||||||
static pthread_mutex_t lightsn_buffer_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t lightsn_buffer_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
// 3022合包缓存定义(放在文件顶部或main函数外部)
|
||||||
|
#define LABEL_BATCH_SIZE 20
|
||||||
|
static uint32_t tags_buf[LABEL_BATCH_SIZE] = {0};
|
||||||
|
static uint8_t lable1_buf[LABEL_BATCH_SIZE] = {0};
|
||||||
|
static uint16_t lable2_buf[LABEL_BATCH_SIZE] = {0};
|
||||||
|
static uint32_t lable3_buf[LABEL_BATCH_SIZE] = {0};
|
||||||
|
static int label_buf_count = 0;
|
||||||
|
static time_t label_buf_first_time = 0;
|
||||||
|
|
||||||
// 函数声明
|
// 函数声明
|
||||||
void *thread_timeout_check(void *arg);
|
void *thread_timeout_check(void *arg);
|
||||||
void *thread_3015_lighton_merge(void *arg);
|
void *thread_3015_lighton_merge(void *arg);
|
||||||
|
void *thread_label_batch_send(void *arg);
|
||||||
|
|
||||||
int getLedOtaVersion(char *filename);
|
int getLedOtaVersion(char *filename);
|
||||||
int getApOtaVersion(char *filename,char *modename);
|
int getApOtaVersion(char *filename,char *modename);
|
||||||
@ -1529,29 +1539,17 @@ void *thread_uart_recv_ack(void *arg){
|
|||||||
isLightOnByRule=false;
|
isLightOnByRule=false;
|
||||||
}
|
}
|
||||||
if(isLabelUp){
|
if(isLabelUp){
|
||||||
#if 1
|
#if 0
|
||||||
uint32_t tag=strtol(mqtt_parm.msg_sn,NULL,16);
|
time_t now = time(NULL);
|
||||||
uint16_t label2=strtol(mqtt_parm.msg_label2,NULL,16)&0xFFFF;
|
if(label_buf_count > 0 && (label_buf_count >= LABEL_BATCH_SIZE || (now - label_buf_first_time) >= 180)) {
|
||||||
uint32_t label3=strtol(mqtt_parm.msg_label3,NULL,16);
|
uart_data_send_head_lableup(&uartSend, 5, label_buf_count);
|
||||||
uart_data_send_lable(&uartSend,tag,atoi(mqtt_parm.msg_label1),label2,label3,
|
usleep(10000);
|
||||||
0,0,0,0,
|
uart_data_send_lable(&uartSend, tags_buf, lable1_buf, lable2_buf, lable3_buf, label_buf_count);
|
||||||
0,0,0,0,
|
label_buf_count = 0;
|
||||||
0,0,0,0,
|
label_buf_first_time = 0;
|
||||||
0,0,0,0,
|
isLabelUp = false;
|
||||||
1);
|
}
|
||||||
#else
|
|
||||||
uint32_t tag=strtol("00A04C0F",NULL,16);
|
|
||||||
uint16_t label2=strtol("FF01",NULL,16)&0xFFFF;
|
|
||||||
uint32_t label3=strtol("663855c0",NULL,16);
|
|
||||||
uart_data_send_lable(&uartSend,tag,atoi("03"),label2,label3,
|
|
||||||
0,0,0,0,
|
|
||||||
0,0,0,0,
|
|
||||||
0,0,0,0,
|
|
||||||
0,0,0,0,
|
|
||||||
1);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
isLabelUp=false;
|
|
||||||
}
|
}
|
||||||
}else if(parm_ack==0x4646){
|
}else if(parm_ack==0x4646){
|
||||||
last_2323_time = 0; // 重置时间
|
last_2323_time = 0; // 重置时间
|
||||||
@ -1984,51 +1982,34 @@ void *thread_mqtt_recv(void *arg){
|
|||||||
mqtt_service_reply(stationsn, mqtt_parm.msg_messageId, "ok", 1, productid);
|
mqtt_service_reply(stationsn, mqtt_parm.msg_messageId, "ok", 1, productid);
|
||||||
}else if(strcmp(mqtt_parm.msg_type,"3022")==0){
|
}else if(strcmp(mqtt_parm.msg_type,"3022")==0){
|
||||||
LOG_I("3022 updata lable\n");
|
LOG_I("3022 updata lable\n");
|
||||||
get_string_from_json_string_by_key_unescape(msg_data, "label1", mqtt_parm.msg_label1, sizeof(mqtt_parm.msg_label1));
|
char sn_str[32] = {0};
|
||||||
LOG_I("label1:%s\n",mqtt_parm.msg_label1);
|
char label1_str[8] = {0};
|
||||||
get_string_from_json_string_by_key_unescape(msg_data, "label2", mqtt_parm.msg_label2, sizeof(mqtt_parm.msg_label2));
|
char label2_str[8] = {0};
|
||||||
LOG_I("label2:%s\n",mqtt_parm.msg_label2);
|
char label3_str[16] = {0};
|
||||||
get_string_from_json_string_by_key_unescape(msg_data, "label3", mqtt_parm.msg_label3, sizeof(mqtt_parm.msg_label3));
|
get_string_from_json_string_by_key_unescape(msg_data, "sn", sn_str, sizeof(sn_str));
|
||||||
LOG_I("label3:%s\n",mqtt_parm.msg_label3);
|
get_string_from_json_string_by_key_unescape(msg_data, "label1", label1_str, sizeof(label1_str));
|
||||||
get_string_from_json_string_by_key_unescape(msg_data, "sn", mqtt_parm.msg_sn, sizeof(mqtt_parm.msg_sn));
|
get_string_from_json_string_by_key_unescape(msg_data, "label2", label2_str, sizeof(label2_str));
|
||||||
LOG_I("sn:%s\n",mqtt_parm.msg_sn);
|
get_string_from_json_string_by_key_unescape(msg_data, "label3", label3_str, sizeof(label3_str));
|
||||||
if(strcmp(mqtt_parm.msg_sn,"")!=0){
|
LOG_I("sn:%s\n", sn_str);
|
||||||
mqtt_service_reply(stationsn,mqtt_parm.msg_messageId,"ok",1,productid);
|
LOG_I("label1:%s\n", label1_str);
|
||||||
isSendComEnd=false;
|
LOG_I("label2:%s\n", label2_str);
|
||||||
isLightOn=false;
|
LOG_I("label3:%s\n", label3_str);
|
||||||
isLightOnByRule=false;
|
if(strcmp(sn_str,"")!=0){
|
||||||
isLabelUp=true;
|
if(label_buf_count == 0) {
|
||||||
//isSearchLabel=false;
|
label_buf_first_time = time(NULL);
|
||||||
// 分组信息缓存与批量处理
|
|
||||||
typedef struct {
|
|
||||||
char label1[64];
|
|
||||||
char label2[64];
|
|
||||||
char label3[64];
|
|
||||||
char sn[64];
|
|
||||||
} GroupInfo;
|
|
||||||
#define GROUP_MAX 20
|
|
||||||
static GroupInfo group_buffer[GROUP_MAX];
|
|
||||||
static int group_count = 0;
|
|
||||||
static time_t last_write_time = 0;
|
|
||||||
// 保存一次分组信息
|
|
||||||
strncpy(group_buffer[group_count].label1, mqtt_parm.msg_label1, sizeof(group_buffer[group_count].label1));
|
|
||||||
strncpy(group_buffer[group_count].label2, mqtt_parm.msg_label2, sizeof(group_buffer[group_count].label2));
|
|
||||||
strncpy(group_buffer[group_count].label3, mqtt_parm.msg_label3, sizeof(group_buffer[group_count].label3));
|
|
||||||
strncpy(group_buffer[group_count].sn, mqtt_parm.msg_sn, sizeof(group_buffer[group_count].sn));
|
|
||||||
group_count++;
|
|
||||||
if (group_count == 1) {
|
|
||||||
last_write_time = time(NULL);
|
|
||||||
}
|
|
||||||
time_t now = time(NULL);
|
|
||||||
if (group_count >= GROUP_MAX || (now - last_write_time) >= 180) {
|
|
||||||
for (int i = 0; i < group_count; i++) {
|
|
||||||
uart_data_send_head_lableup(&uartSend, 5, 1);
|
|
||||||
}
|
|
||||||
group_count = 0;
|
|
||||||
last_write_time = now;
|
|
||||||
}
|
}
|
||||||
|
tags_buf[label_buf_count] = strtoul(sn_str, NULL, 16);
|
||||||
|
lable1_buf[label_buf_count] = (uint8_t)atoi(label1_str);
|
||||||
|
lable2_buf[label_buf_count] = (uint16_t)strtoul(label2_str, NULL, 16);
|
||||||
|
lable3_buf[label_buf_count] = strtoul(label3_str, NULL, 16);
|
||||||
|
label_buf_count++;
|
||||||
|
mqtt_service_reply(stationsn, mqtt_parm.msg_messageId, "ok", 1, productid);
|
||||||
|
isSendComEnd = true;
|
||||||
|
isLightOn = false;
|
||||||
|
isLightOnByRule = false;
|
||||||
|
isLabelUp = true;
|
||||||
}else{
|
}else{
|
||||||
mqtt_service_reply(stationsn,mqtt_parm.msg_messageId,"sn is empty",0,productid);
|
mqtt_service_reply(stationsn, mqtt_parm.msg_messageId, "sn is empty", 0, productid);
|
||||||
}
|
}
|
||||||
}else if(strcmp(mqtt_parm.msg_type,"3023")==0){
|
}else if(strcmp(mqtt_parm.msg_type,"3023")==0){
|
||||||
LOG_I("3023 light on by rule\n");
|
LOG_I("3023 light on by rule\n");
|
||||||
@ -2449,7 +2430,7 @@ int main(int argc, char *argv[])
|
|||||||
pthread_detach(timeout_thread);
|
pthread_detach(timeout_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建3015合并点亮线程
|
// 新增:3015合并点亮线程
|
||||||
pthread_t pt_3015_merge;
|
pthread_t pt_3015_merge;
|
||||||
ret = pthread_create(&pt_3015_merge, NULL, thread_3015_lighton_merge, NULL);
|
ret = pthread_create(&pt_3015_merge, NULL, thread_3015_lighton_merge, NULL);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@ -2459,6 +2440,16 @@ int main(int argc, char *argv[])
|
|||||||
LOG_I("pthread_create 3015_merge success\n");
|
LOG_I("pthread_create 3015_merge success\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新增:3022合包批量下发线程
|
||||||
|
pthread_t pt_label_batch_send;
|
||||||
|
ret = pthread_create(&pt_label_batch_send, NULL, thread_label_batch_send, NULL);
|
||||||
|
if (ret != 0) {
|
||||||
|
LOG_I("pthread_create label_batch_send fail\n");
|
||||||
|
} else {
|
||||||
|
pthread_detach(pt_label_batch_send);
|
||||||
|
LOG_I("pthread_create label_batch_send success\n");
|
||||||
|
}
|
||||||
|
|
||||||
ret = pthread_create(&pt_ota,NULL,thread_ota,NULL);
|
ret = pthread_create(&pt_ota,NULL,thread_ota,NULL);
|
||||||
if(ret!=0){
|
if(ret!=0){
|
||||||
LOG_I("pthread_create ota fail\n");
|
LOG_I("pthread_create ota fail\n");
|
||||||
@ -2690,6 +2681,7 @@ void *thread_3015_lighton_merge(void *arg) {
|
|||||||
// 不要立即清空buffer,等待isLightOn处理完成
|
// 不要立即清空buffer,等待isLightOn处理完成
|
||||||
is_3015_collecting = false;
|
is_3015_collecting = false;
|
||||||
first_3015_time = 0;
|
first_3015_time = 0;
|
||||||
|
isLightOn = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&lightsn_buffer_mutex);
|
pthread_mutex_unlock(&lightsn_buffer_mutex);
|
||||||
@ -2698,3 +2690,22 @@ void *thread_3015_lighton_merge(void *arg) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3022合包批量下发线程
|
||||||
|
void *thread_label_batch_send(void *arg) {
|
||||||
|
while (1) {
|
||||||
|
if (isLightOnByRule == false && isLightOn == false) {
|
||||||
|
time_t now = time(NULL);
|
||||||
|
if (label_buf_count > 0 && (label_buf_count >= 10 || (now - label_buf_first_time) >= 180)) {
|
||||||
|
uart_data_send_head_lableup(&uartSend, 5, label_buf_count);
|
||||||
|
usleep(10000);
|
||||||
|
uart_data_send_lable(&uartSend, tags_buf, lable1_buf, lable2_buf, lable3_buf, label_buf_count);
|
||||||
|
label_buf_count = 0;
|
||||||
|
label_buf_first_time = 0;
|
||||||
|
isLabelUp = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
usleep(1000 * 1000); // 每秒检查一次
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -220,49 +220,33 @@ error:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart_data_send_head_lableup(uart_utils_t *uart,uint8_t wakeup_time,uint16_t tag_num){
|
int uart_data_send_head_lableup(uart_utils_t *uart, uint8_t wakeup_time, uint16_t tag_num) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
uint8_t data_len=0;
|
uint8_t data_len = 16 + (tag_num > 0 ? (tag_num - 1) * 11 : 0); // 兼容原协议
|
||||||
if(tag_num==1){
|
jt_head_package_t jt_head_package = {
|
||||||
data_len=16;
|
.pre = 0x2323,
|
||||||
}else if(tag_num==2){
|
.wakeupTime = wakeup_time,
|
||||||
data_len=27;
|
.func = 'B',
|
||||||
}else if(tag_num==3){
|
.len1 = 0x0000,
|
||||||
data_len=38;
|
.len2 = data_len,
|
||||||
}else if(tag_num==4){
|
.reserve = ntohs(0x0003),
|
||||||
data_len=49;
|
.lableNum = ntohs(tag_num),
|
||||||
}else if(tag_num==5){
|
|
||||||
data_len=60;
|
|
||||||
}
|
|
||||||
jt_head_package_t jt_head_package ={
|
|
||||||
.pre=0x2323,//# 0x23 $ 0x24
|
|
||||||
.wakeupTime=wakeup_time,//5s,<120s
|
|
||||||
.func='B',
|
|
||||||
.len1=0x0000,
|
|
||||||
.len2=data_len,
|
|
||||||
.reserve=ntohs(0x0003),
|
|
||||||
.lableNum=ntohs(tag_num),
|
|
||||||
};
|
};
|
||||||
|
LOG_I("%s:HEAD:%04x,%02x,%02x,%04x,%02x,%04x,%04x\r\n", __func__, jt_head_package.pre, jt_head_package.wakeupTime, jt_head_package.func,
|
||||||
LOG_I("%s:HEAD:%04x,%02x,%02x,%04x,%02x,%04x,%04x\r\n",__func__,jt_head_package.pre,jt_head_package.wakeupTime,jt_head_package.func,
|
jt_head_package.len1, jt_head_package.len2, jt_head_package.reserve, jt_head_package.lableNum);
|
||||||
jt_head_package.len1,jt_head_package.len2,jt_head_package.reserve,jt_head_package.lableNum);
|
if (uart == NULL) {
|
||||||
|
|
||||||
if (uart == NULL){
|
|
||||||
LOG_I("uart NULL pointer\n");
|
LOG_I("uart NULL pointer\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(sizeof(jt_head_package) == write(uart->uart_fd, &jt_head_package, sizeof(jt_head_package))){
|
if (sizeof(jt_head_package) == write(uart->uart_fd, &jt_head_package, sizeof(jt_head_package))) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
//LOG_I("%s success\n",__func__);
|
} else {
|
||||||
}else{
|
|
||||||
//LOG_I("%s fail\n", __func__);
|
|
||||||
ret = -2;
|
ret = -2;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
error:
|
error:
|
||||||
return ret;
|
return ret;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart_data_send_head_lightonrule(uart_utils_t *uart,uint8_t wakeup_time){
|
int uart_data_send_head_lightonrule(uart_utils_t *uart,uint8_t wakeup_time){
|
||||||
@ -430,267 +414,48 @@ error:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart_data_send_lable(uart_utils_t *uart,uint32_t tag_1,uint8_t tag_1_lable1,uint16_t tag_1_lable2,uint32_t tag_1_lable3,
|
int uart_data_send_lable(uart_utils_t *uart, uint32_t tags[], uint8_t lable1[], uint16_t lable2[], uint32_t lable3[], uint32_t tag_num) {
|
||||||
uint32_t tag_2,uint8_t tag_2_lable1,uint16_t tag_2_lable2,uint32_t tag_2_lable3,
|
|
||||||
uint32_t tag_3,uint8_t tag_3_lable1,uint16_t tag_3_lable2,uint32_t tag_3_lable3,
|
|
||||||
uint32_t tag_4,uint8_t tag_4_lable1,uint16_t tag_4_lable2,uint32_t tag_4_lable3,
|
|
||||||
uint32_t tag_5,uint8_t tag_5_lable1,uint16_t tag_5_lable2,uint32_t tag_5_lable3,
|
|
||||||
uint32_t tag_num){
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
if (uart == NULL){
|
if (uart == NULL) {
|
||||||
LOG_I("uart NULL pointer\n");
|
LOG_I("uart NULL pointer\n");
|
||||||
ret = -1;
|
return -1;
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
|
if (tag_num > MAX_LABEL_NUM) tag_num = MAX_LABEL_NUM;
|
||||||
uint8_t tag_1_1=(tag_1>>24)&0xFF;
|
uint8_t data_len = 16 + (tag_num > 0 ? (tag_num - 1) * 11 : 0); // 和头部一致
|
||||||
uint8_t tag_1_2=(tag_1>>16)&0xFF;
|
uint8_t *buf = (uint8_t *)malloc(data_len);
|
||||||
uint8_t tag_1_3=(tag_1>>8)&0xFF;
|
if (!buf) return -2;
|
||||||
uint8_t tag_1_4=(tag_1)&0xFF;
|
memset(buf, 0, data_len);
|
||||||
uint8_t tag_1_lable2_1=(tag_1_lable2>>8)&0xFF;
|
buf[0] = 0x00; // len1
|
||||||
uint8_t tag_1_lable2_2=(tag_1_lable2)&0xFF;
|
buf[1] = 0x00; // len2
|
||||||
uint8_t tag_1_lable3_1=(tag_1_lable3>>24)&0xFF;
|
buf[2] = data_len - 3; // 数据区长度(不含len1/len2/len3)
|
||||||
uint8_t tag_1_lable3_2=(tag_1_lable3>>16)&0xFF;
|
for (uint32_t i = 0; i < tag_num; ++i) {
|
||||||
uint8_t tag_1_lable3_3=(tag_1_lable3>>8)&0xFF;
|
int base = 3 + i * 11;
|
||||||
uint8_t tag_1_lable3_4=(tag_1_lable3)&0xFF;
|
buf[base + 0] = (tags[i] >> 24) & 0xFF;
|
||||||
|
buf[base + 1] = (tags[i] >> 16) & 0xFF;
|
||||||
uint8_t tag_2_1=(tag_2>>24)&0xFF;
|
buf[base + 2] = (tags[i] >> 8) & 0xFF;
|
||||||
uint8_t tag_2_2=(tag_2>>16)&0xFF;
|
buf[base + 3] = tags[i] & 0xFF;
|
||||||
uint8_t tag_2_3=(tag_2>>8)&0xFF;
|
buf[base + 4] = lable1[i];
|
||||||
uint8_t tag_2_4=(tag_2)&0xFF;
|
buf[base + 5] = (lable2[i] >> 8) & 0xFF;
|
||||||
uint8_t tag_2_lable2_1=(tag_2_lable2>>8)&0xFF;
|
buf[base + 6] = lable2[i] & 0xFF;
|
||||||
uint8_t tag_2_lable2_2=(tag_2_lable2)&0xFF;
|
buf[base + 7] = (lable3[i] >> 24) & 0xFF;
|
||||||
uint8_t tag_2_lable3_1=(tag_2_lable3>>24)&0xFF;
|
buf[base + 8] = (lable3[i] >> 16) & 0xFF;
|
||||||
uint8_t tag_2_lable3_2=(tag_2_lable3>>16)&0xFF;
|
buf[base + 9] = (lable3[i] >> 8) & 0xFF;
|
||||||
uint8_t tag_2_lable3_3=(tag_2_lable3>>8)&0xFF;
|
buf[base + 10] = lable3[i] & 0xFF;
|
||||||
uint8_t tag_2_lable3_4=(tag_2_lable3)&0xFF;
|
|
||||||
|
|
||||||
uint8_t tag_3_1=(tag_3>>24)&0xFF;
|
|
||||||
uint8_t tag_3_2=(tag_3>>16)&0xFF;
|
|
||||||
uint8_t tag_3_3=(tag_3>>8)&0xFF;
|
|
||||||
uint8_t tag_3_4=(tag_3)&0xFF;
|
|
||||||
uint8_t tag_3_lable2_1=(tag_3_lable2>>8)&0xFF;
|
|
||||||
uint8_t tag_3_lable2_2=(tag_3_lable2)&0xFF;
|
|
||||||
uint8_t tag_3_lable3_1=(tag_3_lable3>>24)&0xFF;
|
|
||||||
uint8_t tag_3_lable3_2=(tag_3_lable3>>16)&0xFF;
|
|
||||||
uint8_t tag_3_lable3_3=(tag_3_lable3>>8)&0xFF;
|
|
||||||
uint8_t tag_3_lable3_4=(tag_3_lable3)&0xFF;
|
|
||||||
|
|
||||||
uint8_t tag_4_1=(tag_4>>24)&0xFF;
|
|
||||||
uint8_t tag_4_2=(tag_4>>16)&0xFF;
|
|
||||||
uint8_t tag_4_3=(tag_4>>8)&0xFF;
|
|
||||||
uint8_t tag_4_4=(tag_4)&0xFF;
|
|
||||||
uint8_t tag_4_lable2_1=(tag_4_lable2>>8)&0xFF;
|
|
||||||
uint8_t tag_4_lable2_2=(tag_4_lable2)&0xFF;
|
|
||||||
uint8_t tag_4_lable3_1=(tag_4_lable3>>24)&0xFF;
|
|
||||||
uint8_t tag_4_lable3_2=(tag_4_lable3>>16)&0xFF;
|
|
||||||
uint8_t tag_4_lable3_3=(tag_4_lable3>>8)&0xFF;
|
|
||||||
uint8_t tag_4_lable3_4=(tag_4_lable3)&0xFF;
|
|
||||||
|
|
||||||
uint8_t tag_5_1=(tag_5>>24)&0xFF;
|
|
||||||
uint8_t tag_5_2=(tag_5>>16)&0xFF;
|
|
||||||
uint8_t tag_5_3=(tag_5>>8)&0xFF;
|
|
||||||
uint8_t tag_5_4=(tag_5)&0xFF;
|
|
||||||
uint8_t tag_5_lable2_1=(tag_5_lable2>>8)&0xFF;
|
|
||||||
uint8_t tag_5_lable2_2=(tag_5_lable2)&0xFF;
|
|
||||||
uint8_t tag_5_lable3_1=(tag_5_lable3>>24)&0xFF;
|
|
||||||
uint8_t tag_5_lable3_2=(tag_5_lable3>>16)&0xFF;
|
|
||||||
uint8_t tag_5_lable3_3=(tag_5_lable3>>8)&0xFF;
|
|
||||||
uint8_t tag_5_lable3_4=(tag_5_lable3)&0xFF;
|
|
||||||
if(tag_num==1){
|
|
||||||
uint8_t test1[14] = {0x00,0x00,13,tag_1_1,tag_1_2,tag_1_3,tag_1_4,
|
|
||||||
tag_1_lable1,tag_1_lable2_1,tag_1_lable2_2,tag_1_lable3_1,tag_1_lable3_2,tag_1_lable3_3,tag_1_lable3_4};
|
|
||||||
uint16_t crc_c=CRC16_XMODEM(test1,sizeof(test1));
|
|
||||||
for(int i=0;i<14;i++){
|
|
||||||
printf("%02x ",test1[i]);
|
|
||||||
}
|
|
||||||
LOG_I("\r\n");
|
|
||||||
LOG_I("%s XModem_CRC16 = %04x\r\n",__func__,crc_c);
|
|
||||||
jt_lable_led1_package_t jt_lable_led1_package ={
|
|
||||||
.len1=0x0000,
|
|
||||||
.len2=13,
|
|
||||||
.tag1=ntohl(tag_1),
|
|
||||||
.tag1_lable1=tag_1_lable1,
|
|
||||||
.tag1_lable2=ntohs(tag_1_lable2),
|
|
||||||
.tag1_lable3=ntohl(tag_1_lable3),
|
|
||||||
.crc=ntohs(crc_c),
|
|
||||||
};
|
|
||||||
if(sizeof(jt_lable_led1_package) == write(uart->uart_fd, &jt_lable_led1_package, sizeof(jt_lable_led1_package))){
|
|
||||||
ret = 0;
|
|
||||||
//LOG_I("%s success\n",__func__);
|
|
||||||
}else{
|
|
||||||
//LOG_I("%s fail\n", __func__);
|
|
||||||
ret = -2;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}else if(tag_num==2){
|
|
||||||
uint8_t test1[25] = {0x00,0x00,24,tag_1_1,tag_1_2,tag_1_3,tag_1_4,
|
|
||||||
tag_1_lable1,tag_1_lable2_1,tag_1_lable2_2,tag_1_lable3_1,tag_1_lable3_2,tag_1_lable3_3,tag_1_lable3_4,
|
|
||||||
tag_2_1,tag_2_2,tag_2_3,tag_2_4,
|
|
||||||
tag_2_lable1,tag_2_lable2_1,tag_2_lable2_2,tag_2_lable3_1,tag_2_lable3_2,tag_2_lable3_3,tag_2_lable3_4};
|
|
||||||
uint16_t crc_c=CRC16_XMODEM(test1,sizeof(test1));
|
|
||||||
for(int i=0;i<25;i++){
|
|
||||||
printf("%02x ",test1[i]);
|
|
||||||
}
|
|
||||||
LOG_I("\r\n");
|
|
||||||
LOG_I("%s XModem_CRC16 = %04x\r\n",__func__,crc_c);
|
|
||||||
jt_lable_led2_package_t jt_lable_led2_package ={
|
|
||||||
.len1=0x0000,
|
|
||||||
.len2=24,
|
|
||||||
.tag1=ntohl(tag_1),
|
|
||||||
.tag1_lable1=tag_1_lable1,
|
|
||||||
.tag1_lable2=ntohs(tag_1_lable2),
|
|
||||||
.tag1_lable3=ntohl(tag_1_lable3),
|
|
||||||
.tag2=ntohl(tag_2),
|
|
||||||
.tag2_lable1=tag_2_lable1,
|
|
||||||
.tag2_lable2=ntohs(tag_2_lable2),
|
|
||||||
.tag2_lable3=ntohl(tag_2_lable3),
|
|
||||||
.crc=ntohs(crc_c),
|
|
||||||
};
|
|
||||||
if(sizeof(jt_lable_led2_package) == write(uart->uart_fd, &jt_lable_led2_package, sizeof(jt_lable_led2_package))){
|
|
||||||
ret = 0;
|
|
||||||
//LOG_I("%s success\n",__func__);
|
|
||||||
}else{
|
|
||||||
//LOG_I("%s fail\n", __func__);
|
|
||||||
ret = -2;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}else if(tag_num==3){
|
|
||||||
uint8_t test1[36] = {0x00,0x00,35,tag_1_1,tag_1_2,tag_1_3,tag_1_4,
|
|
||||||
tag_1_lable1,tag_1_lable2_1,tag_1_lable2_2,tag_1_lable3_1,tag_1_lable3_2,tag_1_lable3_3,tag_1_lable3_4,
|
|
||||||
tag_2_1,tag_2_2,tag_2_3,tag_2_4,
|
|
||||||
tag_2_lable1,tag_2_lable2_1,tag_2_lable2_2,tag_2_lable3_1,tag_2_lable3_2,tag_2_lable3_3,tag_2_lable3_4,
|
|
||||||
tag_3_1,tag_3_2,tag_3_3,tag_3_4,
|
|
||||||
tag_3_lable1,tag_3_lable2_1,tag_3_lable2_2,tag_3_lable3_1,tag_3_lable3_2,tag_3_lable3_3,tag_3_lable3_4};
|
|
||||||
uint16_t crc_c=CRC16_XMODEM(test1,sizeof(test1));
|
|
||||||
for(int i=0;i<36;i++){
|
|
||||||
printf("%02x ",test1[i]);
|
|
||||||
}
|
|
||||||
LOG_I("\r\n");
|
|
||||||
LOG_I("%s XModem_CRC16 = %04x\r\n",__func__,crc_c);
|
|
||||||
jt_lable_led3_package_t jt_lable_led3_package ={
|
|
||||||
.len1=0x0000,
|
|
||||||
.len2=35,
|
|
||||||
.tag1=ntohl(tag_1),
|
|
||||||
.tag1_lable1=tag_1_lable1,
|
|
||||||
.tag1_lable2=ntohs(tag_1_lable2),
|
|
||||||
.tag1_lable3=ntohl(tag_1_lable3),
|
|
||||||
.tag2=ntohl(tag_2),
|
|
||||||
.tag2_lable1=tag_2_lable1,
|
|
||||||
.tag2_lable2=ntohs(tag_2_lable2),
|
|
||||||
.tag2_lable3=ntohl(tag_2_lable3),
|
|
||||||
.tag3=ntohl(tag_3),
|
|
||||||
.tag3_lable1=tag_3_lable1,
|
|
||||||
.tag3_lable2=ntohs(tag_3_lable2),
|
|
||||||
.tag3_lable3=ntohl(tag_3_lable3),
|
|
||||||
.crc=ntohs(crc_c),
|
|
||||||
};
|
|
||||||
if(sizeof(jt_lable_led3_package) == write(uart->uart_fd, &jt_lable_led3_package, sizeof(jt_lable_led3_package))){
|
|
||||||
ret = 0;
|
|
||||||
//LOG_I("%s success\n",__func__);
|
|
||||||
}else{
|
|
||||||
//LOG_I("%s fail\n", __func__);
|
|
||||||
ret = -2;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}else if(tag_num==4){
|
|
||||||
uint8_t test1[47] = {0x00,0x00,46,tag_1_1,tag_1_2,tag_1_3,tag_1_4,
|
|
||||||
tag_1_lable1,tag_1_lable2_1,tag_1_lable2_2,tag_1_lable3_1,tag_1_lable3_2,tag_1_lable3_3,tag_1_lable3_4,
|
|
||||||
tag_2_1,tag_2_2,tag_2_3,tag_2_4,
|
|
||||||
tag_2_lable1,tag_2_lable2_1,tag_2_lable2_2,tag_2_lable3_1,tag_2_lable3_2,tag_2_lable3_3,tag_2_lable3_4,
|
|
||||||
tag_3_1,tag_3_2,tag_3_3,tag_3_4,
|
|
||||||
tag_3_lable1,tag_3_lable2_1,tag_3_lable2_2,tag_3_lable3_1,tag_3_lable3_2,tag_3_lable3_3,tag_3_lable3_4,
|
|
||||||
tag_4_1,tag_4_2,tag_4_3,tag_4_4,
|
|
||||||
tag_4_lable1,tag_4_lable2_1,tag_4_lable2_2,tag_4_lable3_1,tag_4_lable3_2,tag_4_lable3_3,tag_4_lable3_4};
|
|
||||||
uint16_t crc_c=CRC16_XMODEM(test1,sizeof(test1));
|
|
||||||
for(int i=0;i<47;i++){
|
|
||||||
printf("%02x ",test1[i]);
|
|
||||||
}
|
|
||||||
LOG_I("\r\n");
|
|
||||||
LOG_I("%s XModem_CRC16 = %04x\r\n",__func__,crc_c);
|
|
||||||
jt_lable_led4_package_t jt_lable_led4_package ={
|
|
||||||
.len1=0x0000,
|
|
||||||
.len2=46,
|
|
||||||
.tag1=ntohl(tag_1),
|
|
||||||
.tag1_lable1=tag_1_lable1,
|
|
||||||
.tag1_lable2=ntohs(tag_1_lable2),
|
|
||||||
.tag1_lable3=ntohl(tag_1_lable3),
|
|
||||||
.tag2=ntohl(tag_2),
|
|
||||||
.tag2_lable1=tag_2_lable1,
|
|
||||||
.tag2_lable2=ntohs(tag_2_lable2),
|
|
||||||
.tag2_lable3=ntohl(tag_2_lable3),
|
|
||||||
.tag3=ntohl(tag_3),
|
|
||||||
.tag3_lable1=tag_3_lable1,
|
|
||||||
.tag3_lable2=ntohs(tag_3_lable2),
|
|
||||||
.tag3_lable3=ntohl(tag_3_lable3),
|
|
||||||
.tag4=ntohl(tag_4),
|
|
||||||
.tag4_lable1=tag_4_lable1,
|
|
||||||
.tag4_lable2=ntohs(tag_4_lable2),
|
|
||||||
.tag4_lable3=ntohl(tag_4_lable3),
|
|
||||||
.crc=ntohs(crc_c),
|
|
||||||
};
|
|
||||||
if(sizeof(jt_lable_led4_package) == write(uart->uart_fd, &jt_lable_led4_package, sizeof(jt_lable_led4_package))){
|
|
||||||
ret = 0;
|
|
||||||
//LOG_I("%s success\n",__func__);
|
|
||||||
}else{
|
|
||||||
//LOG_I("%s fail\n", __func__);
|
|
||||||
ret = -2;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}else if(tag_num==5){
|
|
||||||
uint8_t test1[58] = {0x00,0x00,57,tag_1_1,tag_1_2,tag_1_3,tag_1_4,
|
|
||||||
tag_1_lable1,tag_1_lable2_1,tag_1_lable2_2,tag_1_lable3_1,tag_1_lable3_2,tag_1_lable3_3,tag_1_lable3_4,
|
|
||||||
tag_2_1,tag_2_2,tag_2_3,tag_2_4,
|
|
||||||
tag_2_lable1,tag_2_lable2_1,tag_2_lable2_2,tag_2_lable3_1,tag_2_lable3_2,tag_2_lable3_3,tag_2_lable3_4,
|
|
||||||
tag_3_1,tag_3_2,tag_3_3,tag_3_4,
|
|
||||||
tag_3_lable1,tag_3_lable2_1,tag_3_lable2_2,tag_3_lable3_1,tag_3_lable3_2,tag_3_lable3_3,tag_3_lable3_4,
|
|
||||||
tag_4_1,tag_4_2,tag_4_3,tag_4_4,
|
|
||||||
tag_4_lable1,tag_4_lable2_1,tag_4_lable2_2,tag_4_lable3_1,tag_4_lable3_2,tag_4_lable3_3,tag_4_lable3_4,
|
|
||||||
tag_5_1,tag_5_2,tag_5_3,tag_5_4,
|
|
||||||
tag_5_lable1,tag_5_lable2_1,tag_5_lable2_2,tag_5_lable3_1,tag_5_lable3_2,tag_5_lable3_3,tag_5_lable3_4};
|
|
||||||
uint16_t crc_c=CRC16_XMODEM(test1,sizeof(test1));
|
|
||||||
for(int i=0;i<58;i++){
|
|
||||||
printf("%02x ",test1[i]);
|
|
||||||
}
|
|
||||||
LOG_I("\r\n");
|
|
||||||
LOG_I("%s XModem_CRC16 = %04x\r\n",__func__,crc_c);
|
|
||||||
jt_lable_led5_package_t jt_lable_led5_package ={
|
|
||||||
.len1=0x0000,
|
|
||||||
.len2=57,
|
|
||||||
.tag1=ntohl(tag_1),
|
|
||||||
.tag1_lable1=tag_1_lable1,
|
|
||||||
.tag1_lable2=ntohs(tag_1_lable2),
|
|
||||||
.tag1_lable3=ntohl(tag_1_lable3),
|
|
||||||
.tag2=ntohl(tag_2),
|
|
||||||
.tag2_lable1=tag_2_lable1,
|
|
||||||
.tag2_lable2=ntohs(tag_2_lable2),
|
|
||||||
.tag2_lable3=ntohl(tag_2_lable3),
|
|
||||||
.tag3=ntohl(tag_3),
|
|
||||||
.tag3_lable1=tag_3_lable1,
|
|
||||||
.tag3_lable2=ntohs(tag_3_lable2),
|
|
||||||
.tag3_lable3=ntohl(tag_3_lable3),
|
|
||||||
.tag4=ntohl(tag_4),
|
|
||||||
.tag4_lable1=tag_4_lable1,
|
|
||||||
.tag4_lable2=ntohs(tag_4_lable2),
|
|
||||||
.tag4_lable3=ntohl(tag_4_lable3),
|
|
||||||
.tag5=ntohl(tag_5),
|
|
||||||
.tag5_lable1=tag_5_lable1,
|
|
||||||
.tag5_lable2=ntohs(tag_5_lable2),
|
|
||||||
.tag5_lable3=ntohl(tag_5_lable3),
|
|
||||||
.crc=ntohs(crc_c),
|
|
||||||
};
|
|
||||||
if(sizeof(jt_lable_led5_package) == write(uart->uart_fd, &jt_lable_led5_package, sizeof(jt_lable_led5_package))){
|
|
||||||
ret = 0;
|
|
||||||
//LOG_I("%s success\n",__func__);
|
|
||||||
}else{
|
|
||||||
//LOG_I("%s fail\n", __func__);
|
|
||||||
ret = -2;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
error:
|
uint16_t crc_c = CRC16_XMODEM(buf, data_len - 2);
|
||||||
|
buf[data_len - 2] = (crc_c >> 8) & 0xFF;
|
||||||
|
buf[data_len - 1] = crc_c & 0xFF;
|
||||||
|
// 打印即将发送的数据内容
|
||||||
|
printf("[uart_data_send_lable] send: ");
|
||||||
|
for (int i = 0; i < data_len; ++i) {
|
||||||
|
printf("%02X ", buf[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
int write_ret = write(uart->uart_fd, buf, data_len);
|
||||||
|
LOG_I("[uart_data_send_lable] write_ret=%d, data_len=%d", write_ret, data_len);
|
||||||
|
if (write_ret == data_len) ret = 0; else ret = -3;
|
||||||
|
free(buf);
|
||||||
return ret;
|
return ret;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart_data_send_lighton(uart_utils_t *uart,uint8_t ledctl,uint16_t flash_i,uint16_t light_d,
|
int uart_data_send_lighton(uart_utils_t *uart,uint8_t ledctl,uint16_t flash_i,uint16_t light_d,
|
||||||
@ -733,15 +498,15 @@ int uart_data_send_lighton(uart_utils_t *uart,uint8_t ledctl,uint16_t flash_i,ui
|
|||||||
buf[7] = light_d_l;
|
buf[7] = light_d_l;
|
||||||
|
|
||||||
// 填充tag数据
|
// 填充tag数据
|
||||||
uint32_t tags[30] = {tag_1, tag_2, tag_3, tag_4, tag_5, tag_6, tag_7, tag_8, tag_9, tag_10,
|
uint32_t tags_array[30] = {tag_1, tag_2, tag_3, tag_4, tag_5, tag_6, tag_7, tag_8, tag_9, tag_10,
|
||||||
tag_11, tag_12, tag_13, tag_14, tag_15, tag_16, tag_17, tag_18, tag_19, tag_20,
|
tag_11, tag_12, tag_13, tag_14, tag_15, tag_16, tag_17, tag_18, tag_19, tag_20,
|
||||||
tag_21, tag_22, tag_23, tag_24, tag_25, tag_26, tag_27, tag_28, tag_29, tag_30};
|
tag_21, tag_22, tag_23, tag_24, tag_25, tag_26, tag_27, tag_28, tag_29, tag_30};
|
||||||
|
|
||||||
for (int i = 0; i < tag_num; ++i) {
|
for (int i = 0; i < tag_num; ++i) {
|
||||||
buf[8 + i * 4] = (tags[i] >> 24) & 0xFF;
|
buf[8 + i * 4] = (tags_array[i] >> 24) & 0xFF;
|
||||||
buf[9 + i * 4] = (tags[i] >> 16) & 0xFF;
|
buf[9 + i * 4] = (tags_array[i] >> 16) & 0xFF;
|
||||||
buf[10 + i * 4] = (tags[i] >> 8) & 0xFF;
|
buf[10 + i * 4] = (tags_array[i] >> 8) & 0xFF;
|
||||||
buf[11 + i * 4] = tags[i] & 0xFF;
|
buf[11 + i * 4] = tags_array[i] & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算CRC - 计算除了CRC本身之外的所有数据
|
// 计算CRC - 计算除了CRC本身之外的所有数据
|
||||||
@ -771,7 +536,7 @@ int uart_data_send_lighton(uart_utils_t *uart,uint8_t ledctl,uint16_t flash_i,ui
|
|||||||
|
|
||||||
DEBUG_TX("lightsnNum = %d\n", tag_num);
|
DEBUG_TX("lightsnNum = %d\n", tag_num);
|
||||||
for(int i=0;i<tag_num;i++) {
|
for(int i=0;i<tag_num;i++) {
|
||||||
DEBUG_TX("tag%d = %08X\n", i+1, tags[i]);
|
DEBUG_TX("tag%d = %08X\n", i+1, tags_array[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|||||||
@ -308,12 +308,7 @@ int uart_data_send_lighton(uart_utils_t *uart,uint8_t ledctl,uint16_t flash_i,ui
|
|||||||
uint32_t tag_21,uint32_t tag_22,uint32_t tag_23,uint32_t tag_24,uint32_t tag_25,
|
uint32_t tag_21,uint32_t tag_22,uint32_t tag_23,uint32_t tag_24,uint32_t tag_25,
|
||||||
uint32_t tag_26,uint32_t tag_27,uint32_t tag_28,uint32_t tag_29,uint32_t tag_30,
|
uint32_t tag_26,uint32_t tag_27,uint32_t tag_28,uint32_t tag_29,uint32_t tag_30,
|
||||||
uint32_t tag_num);
|
uint32_t tag_num);
|
||||||
int uart_data_send_lable(uart_utils_t *uart,uint32_t tag_1,uint8_t tag_1_lable1,uint16_t tag_1_lable2,uint32_t tag_1_lable3,
|
int uart_data_send_lable(uart_utils_t *uart, uint32_t tags[], uint8_t lable1[], uint16_t lable2[], uint32_t lable3[], uint32_t tag_num);
|
||||||
uint32_t tag_2,uint8_t tag_2_lable1,uint16_t tag_2_lable2,uint32_t tag_2_lable3,
|
|
||||||
uint32_t tag_3,uint8_t tag_3_lable1,uint16_t tag_3_lable2,uint32_t tag_3_lable3,
|
|
||||||
uint32_t tag_4,uint8_t tag_4_lable1,uint16_t tag_4_lable2,uint32_t tag_4_lable3,
|
|
||||||
uint32_t tag_5,uint8_t tag_5_lable1,uint16_t tag_5_lable2,uint32_t tag_5_lable3,
|
|
||||||
uint32_t tag_num);
|
|
||||||
int uart_data_send_light_rule(uart_utils_t *uart,uint8_t lable_1,uint16_t lable_2,uint32_t lable_3,
|
int uart_data_send_light_rule(uart_utils_t *uart,uint8_t lable_1,uint16_t lable_2,uint32_t lable_3,
|
||||||
uint8_t lable_1_rule, uint8_t lable_2_rule, uint8_t lable_3_rule,
|
uint8_t lable_1_rule, uint8_t lable_2_rule, uint8_t lable_3_rule,
|
||||||
uint8_t ledctrl, uint16_t flash_i, uint16_t light_d);
|
uint8_t ledctrl, uint16_t flash_i, uint16_t light_d);
|
||||||
@ -332,4 +327,20 @@ int uart_data_receive_version(uart_utils_t *uart);
|
|||||||
|
|
||||||
int uart_data_send_head_lightband(uart_utils_t *uart, uint8_t wakeup_time, uint16_t tag_num);
|
int uart_data_send_head_lightband(uart_utils_t *uart, uint8_t wakeup_time, uint16_t tag_num);
|
||||||
int uart_data_send_lightband(uart_utils_t *uart, uint8_t ledctl, uint16_t flash_i, uint16_t light_d, uint32_t tags[], uint8_t tag_leds[], uint16_t tag_num);
|
int uart_data_send_lightband(uart_utils_t *uart, uint8_t ledctl, uint16_t flash_i, uint16_t light_d, uint32_t tags[], uint8_t tag_leds[], uint16_t tag_num);
|
||||||
|
|
||||||
|
#define MAX_LABEL_NUM 30
|
||||||
|
typedef struct {
|
||||||
|
uint16_t len1;
|
||||||
|
uint8_t len2;
|
||||||
|
struct {
|
||||||
|
uint32_t tag;
|
||||||
|
uint8_t lable1;
|
||||||
|
uint16_t lable2;
|
||||||
|
uint32_t lable3;
|
||||||
|
} items[MAX_LABEL_NUM];
|
||||||
|
uint16_t crc;
|
||||||
|
} __attribute__((packed)) jt_lable_ledx_package_t;
|
||||||
|
|
||||||
|
int uart_data_send_head_lableup(uart_utils_t *uart, uint8_t wakeup_time, uint16_t tag_num);
|
||||||
|
int uart_data_send_lable(uart_utils_t *uart, uint32_t tags[], uint8_t lable1[], uint16_t lable2[], uint32_t lable3[], uint32_t tag_num);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user