Compare commits
No commits in common. "e9b7bc62a8906ceb928c6a2d27a43a53bc15a9fb" and "8146508cb4e09950140a5dec9c9a0ccc0529fa9f" have entirely different histories.
e9b7bc62a8
...
8146508cb4
36
main.c
36
main.c
@ -157,7 +157,7 @@ int fd;
|
|||||||
int UPCASE=0;
|
int UPCASE=0;
|
||||||
int count_value=0;
|
int count_value=0;
|
||||||
int getPayloadTime=100*1000;//usecond
|
int getPayloadTime=100*1000;//usecond
|
||||||
char softwareVersion[16]="2.1.30";
|
char softwareVersion[16]="2.1.28";
|
||||||
//char stationsn[16]="d126ei4lj4cc00";//TJ250995217957
|
//char stationsn[16]="d126ei4lj4cc00";//TJ250995217957
|
||||||
//char productid[8]="10045";
|
//char productid[8]="10045";
|
||||||
//char appSecret[64]="s3izIliw0CF48Pcsi16rjOmoFRf5WEt8";
|
//char appSecret[64]="s3izIliw0CF48Pcsi16rjOmoFRf5WEt8";
|
||||||
@ -165,7 +165,6 @@ char stationsn[32]="90A9F73002CD";
|
|||||||
char productid[16]="WcLightStrip";
|
char productid[16]="WcLightStrip";
|
||||||
char appKey[32]="fdhQmhqhvbL1cf1K9mUqt";
|
char appKey[32]="fdhQmhqhvbL1cf1K9mUqt";
|
||||||
char appSecret[64]="RxU8NZjfZaxsKg2B3Dr6sx";
|
char appSecret[64]="RxU8NZjfZaxsKg2B3Dr6sx";
|
||||||
char subid[64]="EKmmjqyLRgghANEiQAA5LZ"; // 默认值,可从文件覆盖
|
|
||||||
char hostDomain[64]="auk-iot.test1.zservey.com";
|
char hostDomain[64]="auk-iot.test1.zservey.com";
|
||||||
int mqtt_port=1883;
|
int mqtt_port=1883;
|
||||||
//char hostDomain[64]="127.0.0.1";
|
//char hostDomain[64]="127.0.0.1";
|
||||||
@ -276,7 +275,7 @@ void report_lightbar_login(uint16_t tagCodeHead, uint32_t tagCode) {
|
|||||||
subDeviceKey, subDeviceKey, "WcSubLightStrip", MQTT_ALGORITHM, timestamp_str);
|
subDeviceKey, subDeviceKey, "WcSubLightStrip", MQTT_ALGORITHM, timestamp_str);
|
||||||
|
|
||||||
// 使用HMAC-SHA1计算password
|
// 使用HMAC-SHA1计算password
|
||||||
hmacsha1_hex(subid, stringToSign, password, sizeof(password));
|
hmacsha1_hex("EKmmjqyLRgghANEiQAA5LZ", stringToSign, password, sizeof(password));
|
||||||
|
|
||||||
// 构建topic
|
// 构建topic
|
||||||
snprintf(topic, sizeof(topic), "/auk/iot/things/v1/sub/device/up/login/WcSubLightStrip/%s/%ld",
|
snprintf(topic, sizeof(topic), "/auk/iot/things/v1/sub/device/up/login/WcSubLightStrip/%s/%ld",
|
||||||
@ -287,8 +286,8 @@ void report_lightbar_login(uint16_t tagCodeHead, uint32_t tagCode) {
|
|||||||
"{\"password\":\"%s\",\"timestamp\":%ld,\"signingAlgorithm\":\"%s\"}",
|
"{\"password\":\"%s\",\"timestamp\":%ld,\"signingAlgorithm\":\"%s\"}",
|
||||||
password, timestamp, MQTT_ALGORITHM);
|
password, timestamp, MQTT_ALGORITHM);
|
||||||
|
|
||||||
LOG_I("Lightbar login report - topic: %s\n", topic);
|
//LOG_I("Lightbar login report - topic: %s\n", topic);
|
||||||
LOG_I("Lightbar login report - payload: %s\n", payload);
|
//LOG_I("Lightbar login report - payload: %s\n", payload);
|
||||||
|
|
||||||
// 发送MQTT消息
|
// 发送MQTT消息
|
||||||
mqtt_utils_publish(&mqtt_config, topic, 0, payload, strlen(payload));
|
mqtt_utils_publish(&mqtt_config, topic, 0, payload, strlen(payload));
|
||||||
@ -637,7 +636,7 @@ void report_lightbar_logout(uint16_t tagCodeHead, uint32_t tagCode) {
|
|||||||
subDeviceKey, subDeviceKey, "WcSubLightStrip", MQTT_ALGORITHM, timestamp_str);
|
subDeviceKey, subDeviceKey, "WcSubLightStrip", MQTT_ALGORITHM, timestamp_str);
|
||||||
|
|
||||||
// 使用HMAC-SHA1计算password
|
// 使用HMAC-SHA1计算password
|
||||||
hmacsha1_hex(subid, stringToSign, password, sizeof(password));
|
hmacsha1_hex("EKmmjqyLRgghANEiQAA5LZ", stringToSign, password, sizeof(password));
|
||||||
|
|
||||||
// 构建topic (logout)
|
// 构建topic (logout)
|
||||||
snprintf(topic, sizeof(topic), "/auk/iot/things/v1/sub/device/up/logout/WcSubLightStrip/%s/%ld",
|
snprintf(topic, sizeof(topic), "/auk/iot/things/v1/sub/device/up/logout/WcSubLightStrip/%s/%ld",
|
||||||
@ -2381,6 +2380,10 @@ void *thread_uart_recv_data(void *arg){
|
|||||||
while(1){
|
while(1){
|
||||||
int ret = uart_data_receive_data_back(&uartRecvData,&parmAck,&tagCodeHead,&tagCode,&tagSignal,&totalLen,&tagFeature,
|
int ret = uart_data_receive_data_back(&uartRecvData,&parmAck,&tagCodeHead,&tagCode,&tagSignal,&totalLen,&tagFeature,
|
||||||
&count,&batteryV,&version,&ledCtrl,&signCode,&reserve,&lableParm);
|
&count,&batteryV,&version,&ledCtrl,&signCode,&reserve,&lableParm);
|
||||||
|
if(ret < 0) {
|
||||||
|
usleep(100000); // 失败时延迟100ms
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// 只在有效数据时才打印(tag不为0)
|
// 只在有效数据时才打印(tag不为0)
|
||||||
if(tagCode != 0) {
|
if(tagCode != 0) {
|
||||||
@ -2415,11 +2418,15 @@ void *thread_uart_recv_back(void *arg){
|
|||||||
//LOG_I("Before uart_data_receive_data_back call\n");
|
//LOG_I("Before uart_data_receive_data_back call\n");
|
||||||
int ret = uart_data_receive_data_back(&uartRecvBack,&parmAck,&tagCodeHead,&tagCode,&tagSignal,&totalLen,&tagFeature,
|
int ret = uart_data_receive_data_back(&uartRecvBack,&parmAck,&tagCodeHead,&tagCode,&tagSignal,&totalLen,&tagFeature,
|
||||||
&count,&batteryV,&version,&ledCtrl,&signCode,&reserve,&lableParm);
|
&count,&batteryV,&version,&ledCtrl,&signCode,&reserve,&lableParm);
|
||||||
|
if(ret < 0) {
|
||||||
|
//LOG_I("uart_data_receive_data_back failed with ret=%d, sleeping 100ms\n", ret);
|
||||||
|
usleep(100000); // 失败时延迟100ms
|
||||||
|
continue;
|
||||||
|
}
|
||||||
//LOG_I("After uart_data_receive_data_back call, ret: %d\n", parmAck);
|
//LOG_I("After uart_data_receive_data_back call, ret: %d\n", parmAck);
|
||||||
|
|
||||||
// 只在有效数据且不是心跳时才打印
|
// 只在有效数据且不是心跳时才打印
|
||||||
if(tagCode != 0) {
|
if(tagCode != 0 && tagFeature != 0xFF) {
|
||||||
LOG_I("recv_back:%04x,%04x,tag:%08x,%02x,%02x,%02x,%02x,battery:%02x,%04x,%02x,%04x,reserve:%04x,%08x\n",
|
LOG_I("recv_back:%04x,%04x,tag:%08x,%02x,%02x,%02x,%02x,battery:%02x,%04x,%02x,%04x,reserve:%04x,%08x\n",
|
||||||
parmAck,tagCodeHead,tagCode,tagSignal,totalLen,tagFeature,count,batteryV,version,ledCtrl,signCode,reserve,lableParm);
|
parmAck,tagCodeHead,tagCode,tagSignal,totalLen,tagFeature,count,batteryV,version,ledCtrl,signCode,reserve,lableParm);
|
||||||
}
|
}
|
||||||
@ -3522,19 +3529,6 @@ int main(int argc, char *argv[])
|
|||||||
LOG_I("use default productid:%s\n",productid);
|
LOG_I("use default productid:%s\n",productid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取subid配置
|
|
||||||
readresult=file_to_buffer("/root/subid",&len);
|
|
||||||
if(readresult!=NULL){
|
|
||||||
trim_whitespace(readresult); // 先清理空白字符
|
|
||||||
memset(subid, 0, sizeof(subid));
|
|
||||||
strncpy(subid, readresult, sizeof(subid)-1);
|
|
||||||
free(readresult);
|
|
||||||
readresult = NULL;
|
|
||||||
LOG_I("saved subid:%s\n", subid);
|
|
||||||
} else {
|
|
||||||
LOG_I("subid file not found, using default:%s\n", subid);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取appSecret配置
|
// 读取appSecret配置
|
||||||
readresult=file_to_buffer("appSecret",&len);
|
readresult=file_to_buffer("appSecret",&len);
|
||||||
if(readresult!=NULL){
|
if(readresult!=NULL){
|
||||||
|
|||||||
@ -3421,13 +3421,23 @@ int uart_data_receive_version(uart_utils_t *uart){
|
|||||||
int uart_data_receive_data_back(uart_utils_t *uart,uint16_t *parmAck,uint16_t *tagCodeHead,uint32_t *tagCode,uint8_t *tagSignal,
|
int uart_data_receive_data_back(uart_utils_t *uart,uint16_t *parmAck,uint16_t *tagCodeHead,uint32_t *tagCode,uint8_t *tagSignal,
|
||||||
uint8_t *totalLen,uint8_t *tagFeature,uint8_t *count,uint8_t *batteryV,uint16_t *version,uint8_t *ledCtrl,
|
uint8_t *totalLen,uint8_t *tagFeature,uint8_t *count,uint8_t *batteryV,uint16_t *version,uint8_t *ledCtrl,
|
||||||
uint16_t *signCode,uint16_t *reserve,uint32_t *lableParm){
|
uint16_t *signCode,uint16_t *reserve,uint32_t *lableParm){
|
||||||
|
//LOG_I("ENTER: uart_data_receive_data_back\n");
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
jt_data_back_package_t jt_data_back_package;
|
jt_data_back_package_t jt_data_back_package;
|
||||||
uint8_t *buf = (uint8_t *)&jt_data_back_package;
|
uint8_t *buf = (uint8_t *)&jt_data_back_package;
|
||||||
int pkg_size = sizeof(jt_data_back_package_t);
|
int pkg_size = sizeof(jt_data_back_package_t);
|
||||||
|
|
||||||
|
//LOG_I("DEBUG: uart_data_receive_data_back starting, uart_fd=%d, buffer size: %d bytes\n", uart->uart_fd, pkg_size);
|
||||||
|
|
||||||
ret = uart_read_until_time(uart->uart_fd,(char *)buf, pkg_size, 1000, 50);
|
ret = uart_read_until_time(uart->uart_fd,(char *)buf, pkg_size, 1000, 50);
|
||||||
|
//LOG_I("DEBUG: uart_read_until_time returned %d (expected %d)\n", ret, pkg_size);
|
||||||
if(ret != pkg_size){
|
if(ret != pkg_size){
|
||||||
|
if(ret == 0) {
|
||||||
|
// 超时,不打印错误日志
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//LOG_I("uart_data_receive_data_back failed - ret=%d, expected=%d\n", ret, pkg_size);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "read_utils.h"
|
#include "read_utils.h"
|
||||||
#define PRINT_TIME_TAG
|
#define PRINT_TIME_TAG
|
||||||
#define DBG_TAG "read_utils"
|
#define DBG_TAG "read_utils"
|
||||||
@ -20,15 +21,20 @@ int read_data_until_time(int fd, char *buffer, int len, int timeout_first, int t
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset(buffer, 0, len);
|
memset(buffer, 0, len);
|
||||||
tv.tv_sec = 0;
|
|
||||||
tv.tv_usec = timeout_first*1000;
|
|
||||||
for(i=0; i<len; i++){
|
for(i=0; i<len; i++){
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(fd, &fds);
|
FD_SET(fd, &fds);
|
||||||
//ret = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
|
// 每次都要重新设置超时时间,因为 select 会修改 tv
|
||||||
ret = select(FD_SETSIZE, &fds, NULL, NULL, 0);
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = (i == 0) ? timeout_first*1000 : timeout_interval*1000;
|
||||||
|
// 确保超时时间正确设置
|
||||||
|
if(tv.tv_usec >= 1000000) {
|
||||||
|
tv.tv_sec = tv.tv_usec / 1000000;
|
||||||
|
tv.tv_usec = tv.tv_usec % 1000000;
|
||||||
|
}
|
||||||
|
ret = select(fd + 1, &fds, NULL, NULL, &tv);
|
||||||
if(ret < 0){
|
if(ret < 0){
|
||||||
LOG_I("%s:seclect error\n",__func__);
|
LOG_I("%s:select error, errno=%d (%s), fd=%d\n",__func__, errno, strerror(errno), fd);
|
||||||
i = -1;
|
i = -1;
|
||||||
break;
|
break;
|
||||||
}else if(ret > 0){
|
}else if(ret > 0){
|
||||||
@ -45,8 +51,6 @@ int read_data_until_time(int fd, char *buffer, int len, int timeout_first, int t
|
|||||||
buffer[i] = c;
|
buffer[i] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tv.tv_sec = 0;
|
|
||||||
tv.tv_usec = timeout_interval*1000;
|
|
||||||
}else{
|
}else{
|
||||||
//LOG_I("read time out\n");
|
//LOG_I("read time out\n");
|
||||||
break;
|
break;
|
||||||
@ -68,14 +72,19 @@ int read_data_until_char(int fd, char *buffer, int len, char until, int timeout_
|
|||||||
|
|
||||||
memset(buffer, 0, len);
|
memset(buffer, 0, len);
|
||||||
for(i=0; i<len; i++){
|
for(i=0; i<len; i++){
|
||||||
tv.tv_sec = 0;
|
|
||||||
tv.tv_usec = timeout_first*1000;
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(fd, &fds);
|
FD_SET(fd, &fds);
|
||||||
//ret = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
|
// 每次都要重新设置超时时间,因为 select 会修改 tv
|
||||||
ret = select(FD_SETSIZE, &fds, NULL, NULL, 0);
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = (i == 0) ? timeout_first*1000 : timeout_interval*1000;
|
||||||
|
// 确保超时时间正确设置
|
||||||
|
if(tv.tv_usec >= 1000000) {
|
||||||
|
tv.tv_sec = tv.tv_usec / 1000000;
|
||||||
|
tv.tv_usec = tv.tv_usec % 1000000;
|
||||||
|
}
|
||||||
|
ret = select(fd + 1, &fds, NULL, NULL, &tv);
|
||||||
if(ret < 0){
|
if(ret < 0){
|
||||||
LOG_I("%s:seclect error\n",__func__);
|
LOG_I("%s:select error, errno=%d (%s), fd=%d\n",__func__, errno, strerror(errno), fd);
|
||||||
i = -1;
|
i = -1;
|
||||||
break;
|
break;
|
||||||
}else if(ret > 0){
|
}else if(ret > 0){
|
||||||
@ -93,15 +102,13 @@ int read_data_until_char(int fd, char *buffer, int len, char until, int timeout_
|
|||||||
LOG_D("i= %d\n", i);
|
LOG_D("i= %d\n", i);
|
||||||
LOG_D("\t,[%#x], <%c>\n", c, c);
|
LOG_D("\t,[%#x], <%c>\n", c, c);
|
||||||
#endif
|
#endif
|
||||||
tv.tv_sec = 0;
|
}
|
||||||
tv.tv_usec = timeout_interval*1000;
|
}
|
||||||
|
}else{
|
||||||
if(c == until){
|
if(c == until){
|
||||||
i++;
|
i++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
//LOG_I("read time out\n");
|
//LOG_I("read time out\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,14 +128,19 @@ int read_data_until_str(int fd, char *buffer, int len, char *until, int until_le
|
|||||||
|
|
||||||
memset(buffer, 0, len);
|
memset(buffer, 0, len);
|
||||||
for(i=0; i<len; i++){
|
for(i=0; i<len; i++){
|
||||||
tv.tv_sec = 0;
|
|
||||||
tv.tv_usec = timeout_first*1000;
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(fd, &fds);
|
FD_SET(fd, &fds);
|
||||||
//ret = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
|
// 每次都要重新设置超时时间,因为 select 会修改 tv
|
||||||
ret = select(FD_SETSIZE, &fds, NULL, NULL, 0);
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = (i == 0) ? timeout_first*1000 : timeout_interval*1000;
|
||||||
|
// 确保超时时间正确设置
|
||||||
|
if(tv.tv_usec >= 1000000) {
|
||||||
|
tv.tv_sec = tv.tv_usec / 1000000;
|
||||||
|
tv.tv_usec = tv.tv_usec % 1000000;
|
||||||
|
}
|
||||||
|
ret = select(fd + 1, &fds, NULL, NULL, &tv);
|
||||||
if(ret < 0){
|
if(ret < 0){
|
||||||
LOG_I("%s:seclect error\n",__func__);
|
LOG_I("%s:select error, errno=%d (%s), fd=%d\n",__func__, errno, strerror(errno), fd);
|
||||||
i = -1;
|
i = -1;
|
||||||
break;
|
break;
|
||||||
}else if(ret > 0){
|
}else if(ret > 0){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user