diff --git a/main.c b/main.c index 2d3bc47..298733b 100644 --- a/main.c +++ b/main.c @@ -123,7 +123,7 @@ int fd; int UPCASE=0; int count_value=0; int getPayloadTime=100*1000;//usecond -char softwareVersion[16]="2.1.22"; +char softwareVersion[16]="2.1.23"; //char stationsn[16]="d126ei4lj4cc00";//TJ250995217957 //char productid[8]="10045"; //char appSecret[64]="s3izIliw0CF48Pcsi16rjOmoFRf5WEt8"; @@ -832,40 +832,23 @@ void removeLog(){ } } -void enableWatchDog() { - // 使用 /dev/watchdog 设备,第一次喂狗自动开启看门狗 - // 超时时间固定为5s,不喂狗时默认关闭 - LOG_I("watchdog will be enabled on first feed\n"); +void enableWatchDog(){ + system("echo 1 > /sys/class/gpio/export");//watchdog enable pin SGM820 + system("echo 112 > /sys/class/gpio/export");//feed watchdog pin red + system("echo out > /sys/class/gpio/gpio1/direction"); + system("echo out > /sys/class/gpio/gpio112/direction"); + system("echo 1 > /sys/class/gpio/gpio1/value"); + LOG_I("enable watchdog\n"); + system("echo 1 > /sys/class/gpio/gpio112/value"); } -void feedWatchDog() { - // 使用 /dev/watchdog 设备喂狗 - // 超时时间固定为5s,喂狗命令: echo "" > /dev/watchdog - int fd; - int gpio_fd = open("/sys/class/gpio/gpio112/value", O_WRONLY); - int led_state = 0; - - while(1) { - fd = open("/dev/watchdog", O_WRONLY); - if (fd < 0) { - LOG_I("can not open /dev/watchdog: %s\n", strerror(errno)); - sleep(1); - continue; - } - write(fd, "", 1); - close(fd); - - // 喂狗时翻转 gpio112 灯状态 - if (gpio_fd >= 0) { - led_state = !led_state; - write(gpio_fd, led_state ? "1" : "0", 1); - } - - sleep(1); // 每2秒喂一次狗,超时时间为5s - } - - if (gpio_fd >= 0) { - close(gpio_fd); +void feedWatchDog(){ + while(1){ + //LOG_I("feed watchdog\n"); + system("echo 0 > /sys/class/gpio/gpio112/value"); + usleep(100*1000); + system("echo 1 > /sys/class/gpio/gpio112/value"); + sleep(1); } } @@ -2980,109 +2963,8 @@ int main(int argc, char *argv[]) char networktype[32]={0}; LOG_I("version:%s\n",softwareVersion); - //system("insmod /system/lib/modules/wk2xxx_spi.ko"); + system("insmod /system/lib/modules/wk2xxx_spi.ko"); system("timedatectl set-timezone Asia/Shanghai"); - - - // 导出 GPIO 63 - { - int fd = open("/sys/class/gpio/export", O_WRONLY); - if (fd >= 0) { - write(fd, "63", 2); - close(fd); - } - } - // 设置 GPIO 63 方向为 in - { - int fd = open("/sys/class/gpio/gpio63/direction", O_WRONLY); - if (fd >= 0) { - write(fd, "in", 2); - close(fd); - } - } - // 导出 GPIO 113 - { - int fd = open("/sys/class/gpio/export", O_WRONLY); - if (fd >= 0) { - write(fd, "112", 3); - write(fd, "113", 3); - write(fd, "114", 3); - write(fd, "115", 3); - write(fd, "117", 3); - close(fd); - } - } - { - int fd = open("/sys/class/gpio/gpio112/direction", O_WRONLY); - if (fd >= 0) { - write(fd, "out", 3); - close(fd); - } - } - // 设置 GPIO 113 方向为 out - { - int fd = open("/sys/class/gpio/gpio113/direction", O_WRONLY); - if (fd >= 0) { - write(fd, "out", 3); - close(fd); - } - } - #if 0 - // 导出 GPIO 118 - { - int fd = open("/sys/class/gpio/export", O_WRONLY); - if (fd >= 0) { - write(fd, "118", 3); - close(fd); - } - } - // 设置 GPIO 118 方向为 out - { - int fd = open("/sys/class/gpio/gpio118/direction", O_WRONLY); - if (fd >= 0) { - write(fd, "out", 3); - close(fd); - } - } - #endif - // 导出 GPIO 115 - { - int fd = open("/sys/class/gpio/export", O_WRONLY); - if (fd >= 0) { - write(fd, "115", 3); - close(fd); - } - } - // 设置 GPIO 115 方向为 out - { - int fd = open("/sys/class/gpio/gpio115/direction", O_WRONLY); - if (fd >= 0) { - write(fd, "out", 3); - close(fd); - } - } - // 导出 GPIO 117 - { - int fd = open("/sys/class/gpio/export", O_WRONLY); - if (fd >= 0) { - write(fd, "117", 3); - close(fd); - } - } - // 设置 GPIO 117 方向为 out - { - int fd = open("/sys/class/gpio/gpio117/direction", O_WRONLY); - if (fd >= 0) { - write(fd, "out", 3); - close(fd); - } - } - - setGpio113High(); - setGpio114High(); - setGpio115High(); - setGpio117High(); - uart_open(&uartSend,"/dev/ttyS0");//U12 ttyS0,U14 ttyS4,U21 ttysWK0 U13 ttysWK1 U15 ttysWK2 U22 ttysWK3 U20 ttyS1 uart_init(&uartSend,115200,8,1,'N',0); uart_open(&uartRecvData,"/dev/ttyS4"); @@ -3091,13 +2973,12 @@ int main(int argc, char *argv[]) uart_open(&uartRecvBack,"/dev/ttysWK0"); uart_init(&uartRecvBack,115200,8,1,'N',0); //doCommand_help(0, NULL); - //system("echo 113 > /sys/class/gpio/export");//pin 113 yellow - //system("echo out > /sys/class/gpio/gpio113/direction"); - //system("echo 63 > /sys/class/gpio/export");//pin 63 key - //system("echo in > /sys/class/gpio/gpio63/direction"); + system("echo 113 > /sys/class/gpio/export");//pin 113 yellow + system("echo out > /sys/class/gpio/gpio113/direction"); + system("echo 63 > /sys/class/gpio/export");//pin 63 key + system("echo in > /sys/class/gpio/gpio63/direction"); #if 1 enableWatchDog(); - ret = pthread_create(&pt_watchdog,NULL,thread_feed_watchdog,NULL); if(ret!=0){ LOG_I("pthread_create watchdog fail\n"); @@ -3196,23 +3077,22 @@ int main(int argc, char *argv[]) pthread_detach(pt_station_heartbeat); } - // 心跳检测线程移到MQTT连接成功后启动,避免MQTT未连接时上报失败 - // ret = pthread_create(&pt_heartbeat_check,NULL,thread_heartbeat_check,NULL); - // if(ret!=0){ - // LOG_I("pthread_create heartbeat_check fail\n"); - // }else{ - // LOG_I("pthread_create heartbeat_check success\n"); - // pthread_detach(pt_heartbeat_check); - // } + ret = pthread_create(&pt_heartbeat_check,NULL,thread_heartbeat_check,NULL); + if(ret!=0){ + LOG_I("pthread_create heartbeat_check fail\n"); + }else{ + LOG_I("pthread_create heartbeat_check success\n"); + pthread_detach(pt_heartbeat_check); + } -#if 1 - //ret = pthread_create(&pt_simulate_light,NULL,thread_simulate_light,NULL); - //if(ret!=0){ - // LOG_I("pthread_create simulate_light fail\n"); - //}else{ - // LOG_I("pthread_create simulate_light success\n"); - // pthread_detach(pt_simulate_light); - //} +#if 0 + ret = pthread_create(&pt_simulate_light,NULL,thread_simulate_light,NULL); + if(ret!=0){ + LOG_I("pthread_create simulate_light fail\n"); + }else{ + LOG_I("pthread_create simulate_light success\n"); + pthread_detach(pt_simulate_light); + } ret = pthread_create(&pt_all_light,NULL,thread_all_light,NULL); if(ret!=0){ @@ -3221,14 +3101,6 @@ int main(int argc, char *argv[]) LOG_I("pthread_create all_light success\n"); pthread_detach(pt_all_light); } - - //ret = pthread_create(&pt_simulate_mqtt_topic,NULL,thread_simulate_mqtt_topic,NULL); - //if(ret!=0){ - // LOG_I("pthread_create simulate_mqtt_topic fail\n"); - //}else{ - // LOG_I("pthread_create simulate_mqtt_topic success\n"); - // pthread_detach(pt_simulate_mqtt_topic); - //} #endif #if 0 readresult=file_to_buffer("mqttRawPassword",&len); @@ -3377,4 +3249,4 @@ int main(int argc, char *argv[]) } } return 0; -} +} \ No newline at end of file diff --git a/mqtt_utils/mqtt_utils.c b/mqtt_utils/mqtt_utils.c index 6f0baee..6745e10 100644 --- a/mqtt_utils/mqtt_utils.c +++ b/mqtt_utils/mqtt_utils.c @@ -141,7 +141,7 @@ void *thread_yellow_led_flash(void *arg) { int delay_us = 100000 + (rand() % 400000); // 100000-500000 微秒 // 点亮黄灯 - system("echo 1 > /sys/class/gpio/gpio114/value"); + system("echo 1 > /sys/class/gpio/gpio113/value"); // 随机延时保持亮 usleep(delay_us); @@ -150,14 +150,14 @@ void *thread_yellow_led_flash(void *arg) { if (!yellow_led_flash_running) break; // 熄灭黄灯 - system("echo 0 > /sys/class/gpio/gpio114/value"); + system("echo 0 > /sys/class/gpio/gpio113/value"); // 随机延时保持灭 usleep(delay_us); } // 确保退出时灯是灭的 - system("echo 0 > /sys/class/gpio/gpio114/value"); + system("echo 0 > /sys/class/gpio/gpio113/value"); LOG_I("Yellow LED flash thread exited\n"); return NULL; } @@ -172,7 +172,7 @@ void mqtt_net_failure(int *failure_times){ } pthread_mutex_unlock(&yellow_led_mutex); - system("echo 0 > /sys/class/gpio/gpio114/value"); + system("echo 0 > /sys/class/gpio/gpio113/value"); if(failure_times != NULL){ (*failure_times)++; LOG_I("mqtt net failure_times = %d\n", *failure_times); @@ -389,7 +389,7 @@ void mqtt_utils_connected(void *context, char *cause){ if (ret != 0) { LOG_I("Failed to create yellow LED flash thread, using constant on\n"); yellow_led_flash_running = false; - system("echo 1 > /sys/class/gpio/gpio114/value");//yellow ok + system("echo 1 > /sys/class/gpio/gpio113/value");//yellow ok } else { pthread_detach(pt_yellow_led_flash); LOG_I("Yellow LED flash thread started\n");