From ed01a458161d623282d84feabe2ce613390fe116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=A9=AC=5F666?= <13089258+pony-six-hundred-and-sixty-six@user.noreply.gitee.com> Date: Thu, 5 Dec 2024 16:57:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E7=81=AF=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/main.c | 34 +-- bsp/inc/bsp_emv.h | 63 ++++++ bsp/inc/bsp_led.h | 25 +-- bsp/inc/bsp_mq.h | 2 +- bsp/src/at_device_ml307.c | 33 +-- bsp/src/bsp_bt.c | 2 +- bsp/src/bsp_emv.c | 171 +++++++++++++++ bsp/src/bsp_flash.c | 16 +- bsp/src/bsp_led.c | 3 +- bsp/src/bsp_ml307.c | 217 +++++++++++--------- bsp/src/bsp_mq.c | 4 +- rt-thread/components/net/at/src/at_client.c | 2 +- 12 files changed, 413 insertions(+), 159 deletions(-) create mode 100644 bsp/inc/bsp_emv.h create mode 100644 bsp/src/bsp_emv.c diff --git a/applications/main.c b/applications/main.c index e5de7e0..5cb3a86 100644 --- a/applications/main.c +++ b/applications/main.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-10-23 17:14:16 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2024-12-04 11:37:55 + * @LastEditTime: 2024-12-05 16:42:07 * @FilePath: \ble_bjq_ch303rct6_ml307\applications\main.c * @Descrt_thread_ * @@ -153,7 +153,7 @@ int main(void) { // 定义超时时间,单位为毫秒 // #define TIMEOUT_MS 3 * 60 * 1000 -#define TIMEOUT_MS 15* 1000 +#define TIMEOUT_MS 8* 1000 #define WORK_TIMER_CNT (1000 * 60 * 60 * 24) rt_err_t result = RT_EINVAL; rt_uint32_t received_event; @@ -271,22 +271,8 @@ int main(void) SysControl.last_status = SysControl.status; SysControl.status = kPreheatingEvent; - - LED_STOP(r); - LED_STOP(g); - LED_STOP(y); - LED_CTRL(g, "500,2500", -1); - LED_START(g); - rt_thread_mdelay(1000); - LED_CTRL(y, "500,2500", -1); - LED_START(y); - rt_thread_mdelay(1000); - LED_CTRL(r, "500,2500", -1); - LED_START(r); - rt_thread_mdelay(1000); - + LED_G_PREAT; rt_timer_start(&preheat_timer); - } else if (received_event & Get_Sys_Event_Flag(kNormalDetectionEvents)) // 正常检测 { @@ -294,19 +280,7 @@ int main(void) SysControl.last_status = SysControl.status; SysControl.status = kNormalDetectionEvents; -#if (IOT_MODULE_SWITCH == 1) - if (ml307_conncet_tcp_flag) - { - LED_G_INTERNET; - } - else - { -#endif - LED_G_NORMAL; -#if (IOT_MODULE_SWITCH == 1) - } -#endif - rt_thread_mdelay(10); + LED_G_NORMAL; LOG_D("LED_G_NORMAL"); } else if (received_event & Get_Sys_Event_Flag(kAlarmExceptionEvent)) // 浓度异常 diff --git a/bsp/inc/bsp_emv.h b/bsp/inc/bsp_emv.h new file mode 100644 index 0000000..a7df1ed --- /dev/null +++ b/bsp/inc/bsp_emv.h @@ -0,0 +1,63 @@ +/* + * @Author : stark1898y 1658608470@qq.com + * @Date : 2024-08-29 13:44:16 + * @LastEditors : stark1898y 1658608470@qq.com + * @LastEditTime : 2024-08-29 14:06:06 + * @FilePath : \JT-DT-YD4N02A_RTT-Nano\bsp\inc\bsp_emv.h + * @Description : + * + * Copyright (c) 2024 by yzy, All Rights Reserved. + */ +#ifndef __BSP_EMV__ +#define __BSP_EMV__ + +#include "board.h" +#include "drv_gpio.h" + +/*机械手引脚定义*/ +#define MACHINE_HAND_SLEEP_PIN GET_PIN(A, 5) // 高电平进入正常工作状态 +#define MACHINE_HAND_COIL_A_PIN GET_PIN(A, 6) +#define MACHINE_HAND_COIL_B_PIN GET_PIN(A, 7) + +/*控制逻辑 + A:1 B 0 SLEEP 1 正向 + A:0 B 1 SLEEP 1 反向 + A:1 B 1 SLEEP 1 停止 +*/ + +/*正向*/ +#define EMV_FORWARD_ON(x) do\ +{\ + rt_pin_write(MACHINE_HAND_SLEEP_PIN, PIN_HIGH);\ + rt_pin_write(MACHINE_HAND_COIL_A_PIN, PIN_HIGH);\ + rt_pin_write(MACHINE_HAND_COIL_B_PIN, PIN_LOW);\ + rt_thread_mdelay(x);\ + rt_pin_write(MACHINE_HAND_SLEEP_PIN, PIN_LOW);\ + rt_pin_write(MACHINE_HAND_COIL_A_PIN, PIN_LOW);\ +}\ +while (0); + +/*反向*/ +#define EMV_BACKWARD_ON(x) do\ +{\ + rt_pin_write(MACHINE_HAND_SLEEP_PIN, PIN_HIGH);\ + rt_pin_write(MACHINE_HAND_COIL_A_PIN, PIN_LOW);\ + rt_pin_write(MACHINE_HAND_COIL_B_PIN, PIN_HIGH);\ + rt_thread_mdelay(x);\ + rt_pin_write(MACHINE_HAND_SLEEP_PIN, PIN_LOW);\ + rt_pin_write(MACHINE_HAND_COIL_B_PIN, PIN_LOW);\ +}\ +while (0); + + +// #define EMV_PIN GET_PIN(B, 0) + +// // 保持不动 +// #define EMV_ON rt_pin_write(EMV_PIN, PIN_LOW) +// // 高电平 关闭电磁阀 +// #define EMV_OFF rt_pin_write(EMV_PIN, PIN_HIGH) + +// extern volatile rt_uint16_t emv_state_flag; +// int BSP_Set_Emv_Status(rt_bool_t status); + +#endif // !__BSP_EMV__ diff --git a/bsp/inc/bsp_led.h b/bsp/inc/bsp_led.h index df2af96..e407327 100644 --- a/bsp/inc/bsp_led.h +++ b/bsp/inc/bsp_led.h @@ -35,17 +35,18 @@ extern agile_led_t *led_y; #define LED_G_PREAT \ do \ { \ - LED_STOP(r); \ - LED_STOP(g); \ - LED_STOP(y); \ - LED_CTRL(r, "500,1000", 4);\ - LED_START(r);\ - rt_thread_mdelay(500);\ - LED_CTRL(g, "500,1000", 4);\ + LED_STOP(r);\ + LED_STOP(g);\ + LED_STOP(y);\ + LED_CTRL(g, "500,2500", -1);\ LED_START(g);\ - rt_thread_mdelay(500);\ - LED_CTRL(y, "500,1000", 4);\ + rt_thread_mdelay(1000);\ + LED_CTRL(y, "500,2500", -1);\ LED_START(y);\ + rt_thread_mdelay(1000);\ + LED_CTRL(r, "500,2500", -1);\ + LED_START(r);\ + rt_thread_mdelay(1000);\ } while (0U) #define LED_G_NORMAL \ @@ -73,7 +74,7 @@ extern agile_led_t *led_y; LED_STOP(r); \ LED_STOP(g); \ LED_STOP(y); \ - LED_CTRL(g, "100,2000", -1);\ + LED_CTRL(g, "200,200", -1);\ LED_START(g);\ } while (0U) @@ -93,7 +94,8 @@ extern agile_led_t *led_y; LED_STOP(r); \ LED_STOP(g); \ LED_STOP(y); \ - LED_ON(r); \ + LED_CTRL(r, "500,500", -1); \ + LED_START(r); \ } while (0U) #define LED_Y_END_OF_LIFE \ @@ -104,7 +106,6 @@ extern agile_led_t *led_y; LED_STOP(y); \ LED_CTRL(y, "500,500", -1); \ LED_START(r); \ - LED_START(g); \ } while (0U) #endif //!__BSP_LED_H__ diff --git a/bsp/inc/bsp_mq.h b/bsp/inc/bsp_mq.h index 1b3ce33..3b6b82b 100644 --- a/bsp/inc/bsp_mq.h +++ b/bsp/inc/bsp_mq.h @@ -43,7 +43,7 @@ #define MQ_VOLTAGE_RATIO (1.74F) // adc voltage 1000x -#define MQ_VOLTAGE_HIGH_LIMIT (4900U) +#define MQ_VOLTAGE_HIGH_LIMIT (4095U) #define MQ_VOLTAGE_LOW_LIMIT (100U) #define MQ_VOLTAGE_ALARM_DEFAULT (uint16_t)(2500U) diff --git a/bsp/src/at_device_ml307.c b/bsp/src/at_device_ml307.c index 00c09a0..ce4a9a9 100644 --- a/bsp/src/at_device_ml307.c +++ b/bsp/src/at_device_ml307.c @@ -2,7 +2,7 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-09-04 13:33:49 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2024-12-05 09:06:18 + * @LastEditTime: 2024-12-05 16:31:00 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\at_device_ml307.c * @Description : * @@ -43,7 +43,7 @@ #ifdef AT_DEVICE_USING_ML307 #define ML307_WAIT_CONNECT_TIME 5000 -#define ML307_THREAD_STACK_SIZE 4096 +#define ML307_THREAD_STACK_SIZE (4096) #define ML307_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 2) @@ -224,7 +224,7 @@ static int ml307_wakeup(struct at_device *device) return (RT_EOK); } #endif -char data_buf[AT_CLIENT_RECV_BUFF_LEN] = {0}; + static void urc_tcp_recv(struct at_client *client, const char *data, rt_size_t size) { int id; @@ -232,12 +232,13 @@ static void urc_tcp_recv(struct at_client *client, const char *data, rt_size_t s rt_uint16_t crc16 = 0; rt_uint16_t rec_crc16 = 0; char crc16_buf[6] = {0}; - + char data_buf[AT_CLIENT_RECV_BUFF_LEN] = {0}; + rt_uint8_t recv_byte_buf[AT_CLIENT_RECV_BUFF_LEN] = {0}; rt_memset(data_buf, 0, sizeof(data_buf)); LOG_D("ml307 recv data: %s", data); /*+MIPURC: "rtcp",,,*/ - if (sscanf(data, "+MIPURC: \"rtcp\",%d,%d,%s", &id, &len, data_buf) == 3) + if (sscanf(data, "+MIPURC: \"rtcp\",%d,%d,%s\r\n", &id, &len, data_buf) == 3) { if (id == socket_id) { @@ -291,10 +292,6 @@ static void urc_tcp_connect_state(struct at_client *client, const char *data, rt { LOG_D("ml307 connect to tcp server success"); ml307_conncet_tcp_flag = 1; - if (SysControl.status == kNormalDetectionEvents) - { - LED_G_INTERNET; - } } } } @@ -517,6 +514,10 @@ int at_send_data(struct at_device *device, const char *data, rt_size_t send_len) if (ml307_conncet_tcp_flag) { + if (SysControl.status == kNormalDetectionEvents) + { + LED_G_INTERNET; + } rt_uint8_t retry = 0; rt_uint8_t max_retry_count = (rt_uint8_t)Flash_Get_SysCfg(kIotRetryId); LOG_D("max_retry_count:%d", max_retry_count); @@ -530,7 +531,6 @@ int at_send_data(struct at_device *device, const char *data, rt_size_t send_len) } while (retry < max_retry_count) { - rt_thread_mdelay(1000); if (at_obj_exec_cmd(device->client, resp, TCP_SEND_DATA, socket_id, send_len, data) == RT_EOK) { size_t len = 0; @@ -540,6 +540,10 @@ int at_send_data(struct at_device *device, const char *data, rt_size_t send_len) { LOG_D("send data success, len:%d", len); at_delete_resp(resp); + if (SysControl.status == kNormalDetectionEvents) + { + LED_G_NORMAL; + } return RT_EOK; } @@ -550,6 +554,7 @@ int at_send_data(struct at_device *device, const char *data, rt_size_t send_len) retry++; } } + rt_thread_mdelay(2000); retry++; } at_delete_resp(resp); @@ -558,6 +563,10 @@ int at_send_data(struct at_device *device, const char *data, rt_size_t send_len) else { LOG_D("not connected tcp sever!"); + if (SysControl.status == kNormalDetectionEvents) + { + LED_G_NORMAL; + } return -RT_ERROR; } } @@ -771,7 +780,7 @@ static void ml307_check_link_status_entry(void *parameter) static int ml307_netdev_check_link_status(struct netdev *netdev) { #define ML307_LINK_THREAD_TICK 20 -#define ML307_LINK_THREAD_STACK_SIZE (1024 + 512) +#define ML307_LINK_THREAD_STACK_SIZE (1024) #define ML307_LINK_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX - 2) rt_thread_t tid; @@ -1363,7 +1372,7 @@ static void ml307_init_thread_entry(void *parameter) /* set network interface device status and address information */ ml307_netdev_set_info(device->netdev); /* check and create link staus sync thread */ - ml307_netdev_check_link_status(device->netdev); + // ml307_netdev_check_link_status(device->netdev); LOG_I("%s device network initialize success.", device->name); rt_completion_done(&ml307_init_complate); // 通知初始化完成 } diff --git a/bsp/src/bsp_bt.c b/bsp/src/bsp_bt.c index d6c1211..b6de82c 100644 --- a/bsp/src/bsp_bt.c +++ b/bsp/src/bsp_bt.c @@ -14,7 +14,7 @@ int BSP_BT_Init(void) { for (size_t i = 0; i < MAX_VALVE_NUM; i++) { - valve_t[i].valve_id = i; + valve_t[i].valve_id = (i + 1);//1-8 if (Flash_Get_Mac_Addr(valve_t[i].valve_mac, i) == RT_EOK) { rt_memcpy(valve_t[i].valve_mac, mac_buf, 6); diff --git a/bsp/src/bsp_emv.c b/bsp/src/bsp_emv.c new file mode 100644 index 0000000..4b51978 --- /dev/null +++ b/bsp/src/bsp_emv.c @@ -0,0 +1,171 @@ +/* + * @Author: mbw + * @Date: 2024-10-09 08:42:14 + * @LastEditors: mbw && 1600520629@qq.com + * @LastEditTime: 2024-12-05 15:44:33 + * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_emv.c + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ +#include "bsp_emv.h" +#include "rtthread.h" +#include "pin.h" +#include "bsp_flash.h" +#include + + +#define LOG_TAG "bsp.emv" +#define LOG_LVL LOG_LVL_DBG +#include + +#define EMV_LINKED 0x02 +#define EMV_FUNCTION_ON 0x04 +#define EMV_STATUS_OPEN 0x07 +#define EMV_STATUS_CLOSE 0x06 +#define EMV_NOT_CONNECTED 0x04 +#define EMV_FUNCTION_OFF 0x00 + +// volatile rt_uint16_t emv_state_flag = 0; // 0:关闭,1:打开 +// struct rt_timer emv_timer; + +// // 获取电磁阀连接状态 +// static int Get_Emv_Link_Status(void) +// { +// // TODO: 需要有检测功能,默认连接,其实只要有这个功能开关就行,连接状态只对上报服务器相关,本地动作不受影响 +// return EMV_LINKED; +// // return EMV_NOT_CONNECTED; +// } + +// // 获取电磁阀状态 +// int Get_Emv_Status(void) +// { +// rt_uint8_t emv_state = (rt_uint8_t)Flash_Get_SysCfg(kEmagneticSwitchId) & 0x07; // 获取开关阀功能开关状态 +// if (emv_state & EMV_FUNCTION_ON) // 阀门功能开启了 +// { +// LOG_D("具备阀门功能"); +// if (Get_Emv_Link_Status() & EMV_LINKED) +// { +// LOG_D("阀门已经连接"); +// if (rt_pin_read(EMV_PIN)) // 高电平 +// { +// return EMV_STATUS_OPEN; +// } +// else // 低电平 +// { +// return EMV_STATUS_CLOSE; +// } +// } +// else +// { +// LOG_D("阀门未连接"); +// return EMV_NOT_CONNECTED; // 0x04为未连接 +// } +// } +// return EMV_FUNCTION_OFF; // 0阀门功能未开启 +// } + +// /* +// * @brief 设置电磁阀状态 +// * 0x07 为打开,0x06为关闭 +// */ +// int BSP_Set_Emv_Status(rt_bool_t status) +// { +// rt_uint8_t ret = Get_Emv_Status(); +// if (ret == EMV_FUNCTION_OFF || ret == EMV_NOT_CONNECTED) // 功能未开启或未连接 +// { +// return (ret | 0xB0); +// } +// else +// { +// if (status == 0)//关阀指令 +// { +// if (ret == EMV_STATUS_CLOSE) // 阀门已经关闭 +// { +// return EMV_STATUS_CLOSE; +// } +// else +// { +// emv_state_flag = 0; +// return EMV_STATUS_CLOSE; +// } +// } +// else //开阀指令 +// { +// if (ret == EMV_STATUS_OPEN) // 阀门已经打开 +// { +// return EMV_STATUS_OPEN; +// } +// else +// { +// emv_state_flag = 1; +// return EMV_STATUS_OPEN; +// } +// } +// } +// } + +// // 定时器回调函数 +// void BSP_EMV_Timer_Callback(void *parameter) +// { +// static rt_uint8_t last_pos = 0; +// rt_uint8_t pos = 0; + +// pos = emv_state_flag; + +// // 执行电磁阀动作逻辑 +// if (last_pos != pos) +// { +// if (pos == 1) +// { +// LOG_D("EMV_ON"); +// rt_pin_write(EMV_PIN, 1); //关闭电磁阀 +// } +// else if (pos == 0) +// { +// LOG_D("EMV_OFF"); +// rt_pin_write(EMV_PIN, 0);// 断开连接 +// } +// last_pos = pos; +// } +// } + +// 初始化电磁阀 +int BSP_EMV_Init(void) +{ + rt_pin_mode(MACHINE_HAND_SLEEP_PIN, PIN_MODE_OUTPUT); + rt_pin_mode(MACHINE_HAND_COIL_A_PIN, PIN_MODE_OUTPUT); + rt_pin_mode(MACHINE_HAND_COIL_B_PIN, PIN_MODE_OUTPUT); + rt_pin_write(MACHINE_HAND_COIL_B_PIN, PIN_LOW); + rt_pin_write(MACHINE_HAND_SLEEP_PIN, PIN_LOW); + rt_pin_write(MACHINE_HAND_COIL_A_PIN, PIN_LOW); + // rt_pin_mode(EMV_PIN, PIN_MODE_OUTPUT); + // EMV_ON; + + LOG_D("BSP_EMV_Init"); + // rt_timer_init(&emv_timer, "emv_timer", BSP_EMV_Timer_Callback, RT_NULL, 10, RT_TIMER_FLAG_PERIODIC); + // rt_timer_start(&emv_timer); // 启动定时器 + return RT_EOK; +} +INIT_DEVICE_EXPORT(BSP_EMV_Init); + +static void TEST_Jxs(int argc, char **argv) +{ + if (argc == 3) + { + rt_uint8_t direction = atoi(argv[1]); + rt_uint16_t time = atoi(argv[2]); + LOG_D("direction:%d,time:%d",direction,time); + if (direction) + { + EMV_FORWARD_ON(time); + } + else if (direction == 2) + { + EMV_BACKWARD_ON(time); + } + + } +} +MSH_CMD_EXPORT(TEST_Jxs,"TEST_Jxs 方向 时间ms"); + diff --git a/bsp/src/bsp_flash.c b/bsp/src/bsp_flash.c index 08e3a1d..67a908f 100644 --- a/bsp/src/bsp_flash.c +++ b/bsp/src/bsp_flash.c @@ -364,16 +364,26 @@ int Flash_Set_Mac_Addr(rt_uint8_t *mac_addr, rt_uint8_t number) int Flash_Get_Mac_Addr(rt_uint8_t *mac_addr, rt_uint8_t number) { rt_uint8_t data[FLASH_VALVE_MAC_ADDR_LEN]; + char mac[16] = {20}; rt_memcpy(data, (rt_uint8_t *)(FLASH_VALVE_1_MAC_ADDR_ADDR + number * FLASH_VALVE_MAC_ADDR_LEN), FLASH_VALVE_MAC_ADDR_LEN); if (data == RT_NULL) { LOG_E("Flash_Get_Mac_Addr failed"); return -RT_ERROR; } - LOG_D("data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x", 0, data[0], 1, data[1], 2, data[2], 3, data[3], 4, data[4], 5, data[5]); - rt_snprintf(mac_addr, 6, "%02x:%02x:%02x:%02x:%02x:%02x", + //进行两次判断的原因主要为,防止MAC地址确实有个e3或者e99,但是MAC地址确是正确的情况,防止出现错误,两次判断可以从一定程度上降低这种风险 + if (((data[0] == 0xe3) || (data[0] == 0x39))&&((data[1] == 0xe3) || (data[1] == 0x39))) + { + rt_memset(data, 0, sizeof(data)); + return RT_EEMPTY; + } + + rt_snprintf(mac, 20, "%02x:%02x:%02x:%02x:%02x:%02x", data[5], data[4], data[3], data[2], data[1], data[0]); - return 0; + LOG_I("mac_addr:%s", mac); + rt_memcpy(mac_addr, data, FLASH_VALVE_MAC_ADDR_LEN); + + return RT_EOK; } /*设置无线调压器数量*/ diff --git a/bsp/src/bsp_led.c b/bsp/src/bsp_led.c index e4a91cf..f6da075 100644 --- a/bsp/src/bsp_led.c +++ b/bsp/src/bsp_led.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-11-30 15:46:21 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2024-12-03 17:40:33 + * @LastEditTime: 2024-12-05 16:49:31 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_led.c * @Description: * @@ -42,7 +42,6 @@ static void TEST_LED(int argc, char **argv) if (argc == 4) { char led_name = argv[1][0]; - // strcmp(led_name, "r") int loop_cnt = atoi(argv[3]); switch (led_name) { diff --git a/bsp/src/bsp_ml307.c b/bsp/src/bsp_ml307.c index b22a5f7..bbe5bb1 100644 --- a/bsp/src/bsp_ml307.c +++ b/bsp/src/bsp_ml307.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-11-30 15:46:21 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2024-12-05 09:01:42 + * @LastEditTime: 2024-12-05 16:27:12 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_ml307.c * @Description: * @@ -22,8 +22,8 @@ #include #if IOT_MODULE_SWITCH == 1 -#define ML307_THREAD_STACK_SIZE (4096+2048) -#define ML307_RECV_THREAD_STACK_SIZE (4096+2048) +#define ML307_THREAD_STACK_SIZE (4096 + 2048) +#define ML307_RECV_THREAD_STACK_SIZE (4096 + 2048) #define ML307_LIFE_THREAD_STACK_SIZE (1024) #define ML307_THREAD_PRIORITY 25 #define ML307_THREAD_TICKS 50 @@ -176,7 +176,7 @@ static void Ml307_Ht_Timer_Cb(void *parameter) // 定时器回调函数,当1分钟内没有数据交互时,关闭tcp连接 static void Ml307_Life_Timer_Cb(void *parameter) { - rt_sem_release(ml307_life_sem); + // rt_sem_release(ml307_life_sem); } // 定时器回调函数,当1分钟内没有数据交互时,关闭tcp连接 @@ -223,8 +223,8 @@ void Reset_Ml307_Life_Timer(void) int _Pack_Send(struct Ml307_Ops *ops, char *buf) { char ml307_send_buf[1024] = {0}; // 发送缓冲区,用于存储最终发送的数据 - // char byteArr1[512]; // 转换成字节值 - unsigned short crc16 = 0; // 存储CRC16校验和 + // char byteArr1[512]; // 转换成字节值 + unsigned short crc16 = 0; // 存储CRC16校验和 struct at_device *device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, ML307_SAMPLE_DEIVCE_NAME); ASSERT(device); @@ -248,7 +248,7 @@ int _Pack_Send(struct Ml307_Ops *ops, char *buf) // LOG_D("ml307_send_buf: %s", ml307_send_buf); rt_uint16_t data_len = rt_strlen(ml307_send_buf); // 通过AT指令发送数据给ML307模块 - if (at_send_data(device, ml307_send_buf, data_len/2) != RT_EOK) + if (at_send_data(device, ml307_send_buf, data_len / 2) != RT_EOK) { return -RT_ERROR; } @@ -272,7 +272,7 @@ static int _Send_Handle(struct Ml307_Ops *ops, rt_size_t data_num, rt_size_t cmd { // 临时缓冲区,用于格式化数据 char data_buf[1024] = {0}; - rt_size_t data_len = rt_strlen(data); + rt_size_t data_len = rt_strlen(data); // 格式化数据,构建发送给ML307模块的数据包 rt_int32_t len = rt_snprintf(data_buf, sizeof(data_buf), @@ -323,14 +323,15 @@ int BSP_Ml307_Init(struct Ml307_Ops *ops, rt_uint8_t version) int _Update_Valve_Data(struct Ml307_Ops *ops) { - valve_data_t valve_data_t[MAX_VALVE_NUM] = {0}; - rt_uint8_t id = 0; + valve_data_t valve_data_t[MAX_VALVE_NUM] = {0}; + rt_uint8_t id = 0; rt_uint8_t mac_addr[FLASH_VALVE_MAC_ADDR_LEN] = {0}; - ops->body->valve_num = Flash_Get_Valve_Num(); - if (ops->body->valve_num == 0)//确保至少有一个阀门数据体 + ops->body->valve_num = Flash_Get_Valve_Num(); + if (ops->body->valve_num == 0) // 确保至少有一个阀门数据体 { LOG_D("No valve data"); - rt_memcpy(&ops->body->valve_data, &valve_data_t[0], sizeof(struct valve_data)); + rt_memset(&ops->body->valve_data, 0, sizeof(struct valve_data));//直接全部发送0 + // rt_memcpy(&ops->body->valve_data, &valve_data_t[0], sizeof(struct valve_data)); } else { @@ -340,16 +341,18 @@ int _Update_Valve_Data(struct Ml307_Ops *ops) Flash_Get_Mac_Addr(mac_addr, i); for (; j < FLASH_VALVE_MAC_ADDR_LEN; j++) { - if ((mac_addr[j] == 0xe3)||(mac_addr[j] == 0xe9)) + if ((mac_addr[j] == 0xe3) || (mac_addr[j] == 0x39)) { break; } } - if(i == FLASH_VALVE_MAC_ADDR_LEN) + if (i == FLASH_VALVE_MAC_ADDR_LEN) { + rt_memcmp(valve_t[i].valve_mac, mac_addr, FLASH_VALVE_MAC_ADDR_LEN); rt_memcpy(&ops->body->valve_data[id], &valve_t[i], sizeof(valve_data_t)); + ops->body->valve_data[id].valve_id = (i + 1); id++; - } + } } } return RT_EOK; @@ -357,8 +360,7 @@ int _Update_Valve_Data(struct Ml307_Ops *ops) // 更新函数 int BSP_Ml307_Update(struct Ml307_Ops *ops, rt_uint8_t device_type, rt_uint8_t event_type) { - - + ops->body->device_type = device_type; ops->body->event_type = event_type; ops->body->hw = (rt_uint8_t)Flash_Get_SysCfg(kHwVerId); @@ -368,7 +370,7 @@ int BSP_Ml307_Update(struct Ml307_Ops *ops, rt_uint8_t device_type, rt_uint8_t e ops->body->product_work_temperature = 0x32; ops->body->work_duration = work_duration; ops->body->device_status = device_state_flag; - ops->body->valve_num = Flash_Get_Valve_Num(); + ops->body->valve_num = Flash_Get_Valve_Num(); _Update_Valve_Data(ops); return RT_EOK; @@ -376,8 +378,8 @@ int BSP_Ml307_Update(struct Ml307_Ops *ops, rt_uint8_t device_type, rt_uint8_t e int Ml307_Send_Data(struct Ml307_Ops *ops, rt_uint8_t data_num, rt_uint8_t cmd, rt_uint8_t device_type, rt_uint8_t event_type) { - rt_size_t lenght = 0; - int ret = 0; + rt_size_t lenght = 0; + int ret = 0; char data_buf[1024] = {0}; char temp[3]; // 临时缓冲区,用于存储每个字节的十六进制表示 @@ -402,11 +404,11 @@ int Ml307_Send_Data(struct Ml307_Ops *ops, rt_uint8_t data_num, rt_uint8_t cmd, { if (ops->body->valve_num == 0) { - lenght = (sizeof(struct DataBody) - (MAX_VALVE_NUM - 1) * sizeof(struct valve_data));//至少要发送一个阀门数据体 + lenght = (sizeof(struct DataBody) - (MAX_VALVE_NUM - 1) * sizeof(struct valve_data)); // 至少要发送一个阀门数据体 } else { - lenght = (sizeof(struct DataBody) - (MAX_VALVE_NUM - ops->body->valve_num) * sizeof(struct valve_data));//至少要发送一个阀门数据体 + lenght = (sizeof(struct DataBody) - (MAX_VALVE_NUM - ops->body->valve_num) * sizeof(struct valve_data)); // 至少要发送一个阀门数据体 } for (int i = 0; i < lenght; i++) { @@ -853,8 +855,8 @@ int Ml307_Process_Events(Ml307Event ml307_recv_event, struct at_device *device, break; } } - - if (event)// 处理该事件 + + if (event) // 处理该事件 { // 打印事件的名称 LOG_D("%s上报\n", event->event_name); @@ -872,7 +874,7 @@ int Ml307_Process_Events(Ml307Event ml307_recv_event, struct at_device *device, { if (device->class->device_ops->control(device, AT_DEVICE_CTRL_NET_CONN, RT_NULL) == RT_EOK) // 打开连接 { - Reset_Ml307_Life_Timer(); + // Reset_Ml307_Life_Timer(); // 重启后重新尝试发送 result = event->send_func(device, ml307_ops); if (result != RT_EOK) @@ -935,7 +937,7 @@ int Compare_HeaderToTail(struct Ml307_Ops *ops) void Handle_Server_Reply(struct Ml307_Ops *ops) { - if ((ops->recv->recv_data.event_type == INSTRUCTION_HEART_BEAT)||(ops->recv->recv_data.event_type == EVENT_TYPE_POWER_ON)) + if ((ops->recv->recv_data.event_type == INSTRUCTION_HEART_BEAT) || (ops->recv->recv_data.event_type == EVENT_TYPE_POWER_ON)) { LOG_D("服务器响应成功,响应码:[%02X]\n", ops->recv->recv_data.event_type); } @@ -977,32 +979,38 @@ void Handle_Mute(struct Ml307_Ops *ops) rt_err_t Handle_Close_Valve(struct Ml307_Ops *ops) { LOG_D("服务器下发关闭阀门指令\n"); - int i = 0; - char mac_addr[6] = {0}; - char imei[16] = {0}; + int i = 0; + rt_uint8_t data[FLASH_VALVE_MAC_ADDR_LEN + 1] = {0}; + rt_uint8_t mac_addr[6] = {0}; + char imei[16] = {0}; Get_Iot_Imei(imei, FLASH_NB_IMEI_LEN); char temp[32] = "0"; - String2Hex(temp, imei); // 将字符串转为十六进制字符串 - if (ops->recv->recv_data.res_data[0] != 0)//不为零则说明关闭无线阀门 + String2Hex(temp, imei); // 将字符串转为十六进制字符串 + rt_memcpy(data, (ops->recv->recv_data.res_data + 8), FLASH_VALVE_MAC_ADDR_LEN + 1); + LOG_D("data[0] = %x data[1] = %x data[2] = %x data[3] = %x data[4] = %x, data[5] = %x data[6] = %x", data[0], data[1], data[2], data[3], data[4], data[5], data[6]); + if ((data[0] > 0) && (data[0] < MAX_VALVE_NUM)) // 不为零则说明关闭无线阀门 { - Flash_Get_Mac_Addr(mac_addr, ops->recv->recv_data.res_data[0]); + LOG_D("无线阀门编号:%d\n", data[0]); + Flash_Get_Mac_Addr(mac_addr, data[0] - 1); + LOG_D("mac_addr[0] = %x mac_addr[1] = %x mac_addr[2] = %x mac_addr[3] = %x mac_addr[4] = %x, mac_addr[5] = %x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); /*对两个数组进行比较,如果值不同则退出*/ for (; i < FLASH_VALVE_MAC_ADDR_LEN; i++) { - if (mac_addr[i] != ops->recv->recv_data.res_data[i + 1]) + if (mac_addr[i] != data[i+1]) { - LOG_E("mac_addr[%x] != ops->recv->recv_data.res_data[%x]\n", mac_addr[i], ops->recv->recv_data.res_data[i + 1]); + LOG_E("mac_addr[%d][%x]!= data[%d][%x]\n", i, mac_addr[i], i+1, data[i+1]); + ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_CLOSE_VALVE, temp, RESPONSE_CODE_ACTION_FAILURE); + return RT_ERROR; } } - if(i == FLASH_VALVE_MAC_ADDR_LEN) + if (i == FLASH_VALVE_MAC_ADDR_LEN) { LOG_D("mac地址匹配成功,执行关阀动作\n"); - //TODO:此处需要增加关阀无线阀门的逻辑 - - ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_CLOSE_VALVE, temp, RESPONSE_CODE_SUCCESS); - return RT_EOK; + // TODO:此处需要增加关阀无线阀门的逻辑 + ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_CLOSE_VALVE, temp, RESPONSE_CODE_SUCCESS); + return RT_EOK; } else { @@ -1013,15 +1021,13 @@ rt_err_t Handle_Close_Valve(struct Ml307_Ops *ops) else { LOG_D("关闭有线阀门\n"); - //TODO:此处需要增加关阀有线阀门的逻辑 - // emv_state_flag = 0; // 电磁阀动作 - // rt_thread_mdelay(20); - // emv_state_flag = 0; - ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_CLOSE_VALVE, temp, RESPONSE_CODE_SUCCESS); + // TODO:此处需要增加关阀有线阀门的逻辑 + // emv_state_flag = 0; // 电磁阀动作 + // rt_thread_mdelay(20); + // emv_state_flag = 0; + ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_CLOSE_VALVE, temp, RESPONSE_CODE_SUCCESS); return RT_EOK; } - - } void Handle_Open_Valve(struct Ml307_Ops *ops) @@ -1209,10 +1215,10 @@ void Handle_Sever_Addr_Set(struct Ml307_Ops *ops) /*新增阀门设备*/ rt_err_t Handle_Valve_Add(struct Ml307_Ops *ops) { - rt_uint8_t data[7] = {0}; - char imei[16] = {0}; - char temp[32] = "0"; - rt_uint8_t cnt = Flash_Get_Valve_Num(); + rt_uint8_t data[7] = {0}; + char imei[16] = {0}; + char temp[32] = "0"; + rt_uint8_t cnt = Flash_Get_Valve_Num(); rt_uint8_t mac_addr[FLASH_VALVE_MAC_ADDR_LEN + 1] = {0}; Get_Iot_Imei(imei, FLASH_NB_IMEI_LEN); String2Hex(temp, imei); // 将字符串转为十六进制字符串 @@ -1226,12 +1232,13 @@ rt_err_t Handle_Valve_Add(struct Ml307_Ops *ops) rt_memcpy(data, (ops->recv->recv_data.res_data + 8), FLASH_VALVE_MAC_ADDR_LEN + 1); - LOG_D("data[0] = %x data[1] = %x data[2] = %x data[3] = %x data[4] = %x, data[5] = %x", data[0], data[1], data[2], data[3], data[4], data[5], data[6]); - if (Flash_Get_Mac_Addr(mac_addr, data[0]) != RESET) + LOG_D("data[0] = %x data[1] = %x data[2] = %x data[3] = %x data[4] = %x, data[5] = %x data[6] = %x", data[0], data[1], data[2], data[3], data[4], data[5], data[6]); + //无阀门数据时添加,有阀门数据时不添加 + if ((Flash_Get_Mac_Addr(mac_addr, data[0]) == RT_EEMPTY)||((Flash_Get_Mac_Addr(mac_addr, data[0]) == RT_EOK))) { - if ((mac_addr[0] != 0xe3) && (mac_addr[0] != 0xe9)) + if (mac_addr[0] == 0)//无MAC地址数据,写入MAC地址数据 { - if (Flash_Set_Mac_Addr(&data[1], data[0]) == RESET) + if (Flash_Set_Mac_Addr(&data[1], (data[0] - 1)) == RESET) { LOG_E("新增阀门设备失败\n"); ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_ADD, temp, RESPONSE_CODE_ACTION_FAILURE); @@ -1242,28 +1249,55 @@ rt_err_t Handle_Valve_Add(struct Ml307_Ops *ops) ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_ADD, temp, RESPONSE_CODE_SUCCESS); return RT_EOK; } - else + else//不为空,不添加 { LOG_E("该阀门设备已存在,请选择更换阀门编号后重试\n"); ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_ADD, temp, RESPONSE_CODE_OTHER_ERROR); return RT_EOK; } } - } /*更换阀门设备*/ rt_err_t Handle_Valve_Replace(struct Ml307_Ops *ops) { - rt_uint8_t data[6] = {0}; - char imei[16] = {0}; - char temp[32] = "0"; + size_t i = 0; + rt_uint8_t data[13] = {0}; + rt_uint8_t mac_addr[FLASH_VALVE_MAC_ADDR_LEN] = {0}; + char imei[16] = {0}; + char temp[32] = "0"; Get_Iot_Imei(imei, FLASH_NB_IMEI_LEN); String2Hex(temp, imei); // 将字符串转为十六进制字符串 - rt_memcpy(data, (ops->recv->recv_data.res_data + 8), FLASH_VALVE_MAC_ADDR_LEN + 1); - LOG_D("data[0] = %x data[1] = %x data[2] = %x data[3] = %x data[4] = %x, data[5] = %x", data[0], data[1], data[2], data[3], data[4], data[5], data[6]); - + rt_memcpy(data, (ops->recv->recv_data.res_data + 3), (2 * FLASH_VALVE_MAC_ADDR_LEN + 1)); + /*设备编号(1byte)+ 新MAC地址(6)+ 旧阀门MAC地址(6) + 补零字节= 15byte*/ + if (Flash_Get_Mac_Addr(mac_addr, data[0]) == RT_EOK) + { + for (; i < FLASH_VALVE_MAC_ADDR_LEN; i++) + { + if (mac_addr[i] != data[i + 7]) + { + LOG_E("旧阀门MAC地址错误\n"); + ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_REPLACE, temp, RESPONSE_CODE_OTHER_ERROR); + + return RT_ERROR; + } + } + LOG_D("data[0] = %x data[1] = %x data[2] = %x data[3] = %x data[4] = %x, data[5] = %x data[6] = %x data[7] = %x data[8] = %x data[9] = %x data[10] = %x data[11] = %x data[12] = %x", + data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12]); + if (i == FLASH_VALVE_MAC_ADDR_LEN) + { + if (Flash_Set_Mac_Addr(&data[2], data[0]) == RESET) + { + LOG_E("更换阀门设备失败\n"); + ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_REPLACE, temp, RESPONSE_CODE_ACTION_FAILURE); + return RT_ERROR; + } + LOG_D("更换阀门设备成功\n"); + ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_REPLACE, temp, RESPONSE_CODE_SUCCESS); + return RT_EOK; + } + } if (Flash_Set_Mac_Addr(&data[1], data[0]) == RESET) { LOG_E("更换阀门设备失败\n"); @@ -1291,15 +1325,17 @@ rt_err_t Handle_Remove_Valve(struct Ml307_Ops *ops) { LOG_E("阀门设备数量为0, 无法移除\n"); ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_REMOVE, temp, RESPONSE_CODE_ACTION_FAILURE); + return RT_ERROR; } rt_memcpy(data, (ops->recv->recv_data.res_data + 8), FLASH_VALVE_MAC_ADDR_LEN + 1); LOG_D("data[0] = %x data[1] = %x data[2] = %x data[3] = %x data[4] = %x, data[5] = %x", data[0], data[1], data[2], data[3], data[4], data[5], data[6]); rt_memset(&data[1], 0, sizeof(data) - 1); - if (Flash_Set_Mac_Addr(&data[1], data[0]) != RT_EOK) + if (Flash_Set_Mac_Addr(&data[1], data[0] - 1) == RESET) { LOG_E("移除阀门设备失败\n"); ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_REMOVE, temp, RESPONSE_CODE_ACTION_FAILURE); + return RT_ERROR; } else @@ -1307,6 +1343,7 @@ rt_err_t Handle_Remove_Valve(struct Ml307_Ops *ops) LOG_D("移除阀门设备成功\n"); Flash_Set_Valve_Num(cnt - 1); ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_ML307, INSTRUCTION_DOWN_VALVE_REMOVE, temp, RESPONSE_CODE_SUCCESS); + return RT_EOK; } } @@ -1411,7 +1448,7 @@ void Handle_Cmd_Type(struct Ml307_Ops *ops) void Analyze_Recv_Frame(struct at_device *device, struct Ml307_Ops *ops) { rt_err_t ret = RT_EOK; - Reset_Ml307_Life_Timer(); // 只要数据,则重置定时器,不管数据是否正确 + // Reset_Ml307_Life_Timer(); // 只要数据,则重置定时器,不管数据是否正确 ret = Compare_HeaderToTail(ops); if (ret == RT_EOK) @@ -1431,7 +1468,6 @@ void Analyze_Recv_Frame(struct at_device *device, struct Ml307_Ops *ops) */ static void Ml307_Send_Thread_Entry(void *param) { - rt_uint16_t cnt = 0; rt_err_t result = RT_EOK; rt_uint32_t ml307_recv_event; LOG_D("ml307 thread entry\n"); @@ -1448,15 +1484,6 @@ static void Ml307_Send_Thread_Entry(void *param) else { LOG_D("ml307 init success\n"); - while (cnt < 5000) // 等待激光器进入正常工作状态 - { - if (SysControl.status == kNormalDetectionEvents) - { - break; - } - cnt++; - rt_thread_mdelay(10); - } rt_completion_wait(&ml307_init_complate, RT_WAITING_FOREVER); // wait for ml307 init finish Ml307_Send_Event(kMl307PowerOnEvent); } @@ -1490,7 +1517,7 @@ static void Ml307_Send_Thread_Entry(void *param) if (device->class->device_ops->control(device, AT_DEVICE_CTRL_NET_CONN, RT_NULL) == RT_EOK) // 打开连接 { LOG_I("ml307 connect tcp success\n"); - rt_timer_start(ml307_life_timer); + // rt_timer_start(ml307_life_timer); } else { @@ -1499,7 +1526,7 @@ static void Ml307_Send_Thread_Entry(void *param) } if (ml307_conncet_tcp_flag) { - Reset_Ml307_Life_Timer(); + // Reset_Ml307_Life_Timer(); if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307PowerOnEvent)) { result = Ml307_Process_Events(kMl307PowerOnEvent, device, ops); // 当上电心跳包发送不成功时,其他事件不启动 @@ -1513,7 +1540,7 @@ static void Ml307_Send_Thread_Entry(void *param) { rt_timer_start(ml307_timer); // 当上电心跳包发送成功时, 开始心跳包周期发送 power_on_send_flag = 1; - // Ml307_Send_Event(kMl307TimeCalibrationEvent); // 上电网络连接成功时,更新下时间 + Ml307_Send_Event(kMl307TimeCalibrationEvent); // 上电网络连接成功时,更新下时间 rt_timer_start(ml307_upload_timer); } } @@ -1621,8 +1648,8 @@ static void Ml307_Send_Thread_Entry(void *param) { LOG_E("ml307 send data failed result = [%d]\n", result); } - ml307_event_initialized = RT_FALSE; // 当接收到掉电事件时,发送完成后删除事件,不再接收其他事件 - rt_event_detach(&at_device_event); + ml307_event_initialized = RT_FALSE; // 当接收到掉电事件时,不再接收其他事件 + // rt_event_detach(&at_device_event); } else if (ml307_recv_event & Ml307_Get_Event_Flag(kMl307DeviceFailureEvent)) { @@ -1654,7 +1681,7 @@ static void Ml307_Recv_Thread_Entry(void *parameter) ret = rt_sem_take(ml307_recv_sem, RT_WAITING_FOREVER); // 这个主要用来处理的数据 if (ret == RT_EOK) { - rt_timer_start(ml307_life_timer); + // rt_timer_start(ml307_life_timer); /*对数据帧进行分析,判断所处的是对服务器响应还是指令下发*/ Analyze_Recv_Frame(device, ops); } @@ -1676,10 +1703,10 @@ static void Ml307_Life_Thread_Entry(void *parameter) ret = rt_sem_take(ml307_life_sem, RT_WAITING_FOREVER); if (ret == RT_EOK) { - if (ml307_conncet_tcp_flag) + if (ml307_conncet_tcp_flag != RT_TRUE) { - device->class->device_ops->control(device, AT_DEVICE_CTRL_NET_DISCONN, RT_NULL); - LOG_D("close ml307 tcp connect\n "); + device->class->device_ops->control(device, AT_DEVICE_CTRL_NET_CONN, RT_NULL); + LOG_D("retry ml307 tcp connect\n "); } } } @@ -1727,16 +1754,16 @@ int BSP_Ml307_Thread_Init(void) rt_kprintf("创建定时器失败\n"); return -1; } - ml307_life_timer = rt_timer_create("ml307_life", - Ml307_Life_Timer_Cb, - RT_NULL, - 30 * RT_TICK_PER_SECOND, - RT_TIMER_FLAG_ONE_SHOT); - if (ml307_life_timer == RT_NULL) - { - rt_kprintf("创建定时器失败\n"); - return -1; - } + // ml307_life_timer = rt_timer_create("ml307_life", + // Ml307_Life_Timer_Cb, + // RT_NULL, + // 30 * RT_TICK_PER_SECOND, + // RT_TIMER_FLAG_ONE_SHOT); + // if (ml307_life_timer == RT_NULL) + // { + // rt_kprintf("创建定时器失败\n"); + // return -1; + // } ml307_power_error_timer = rt_timer_create("ml307_error_timer", Ml307_Error_Timer_Cb, RT_NULL, @@ -1786,7 +1813,7 @@ int BSP_Ml307_Thread_Init(void) sizeof(ml307_life_thread_stack), ML307_LIFE_THREAD_PRIORITY, ML307_LIFE_THREAD_TICKS); - rt_thread_startup(&ml307_life_thread); + // rt_thread_startup(&ml307_life_thread); return ret; } diff --git a/bsp/src/bsp_mq.c b/bsp/src/bsp_mq.c index df86c8a..78625d2 100644 --- a/bsp/src/bsp_mq.c +++ b/bsp/src/bsp_mq.c @@ -2,7 +2,7 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-06-18 15:48:01 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2024-12-04 10:29:14 + * @LastEditTime: 2024-12-05 16:44:14 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_mq.c * @Description : * @@ -104,7 +104,7 @@ static uint8_t Sensor_CheckData(void) rt_uint16_t voltage = Get_Gas_VoltageInt1000x(); alarm_status_buffer[index] = (voltage < Sensor_device.alarm_value) ? kSensorNormal : kSensorAlarm; - fault_buf[index] = ((voltage < MQ_VOLTAGE_LOW_LIMIT) || (voltage > MQ_VOLTAGE_LOW_LIMIT)) ? kSensorNormal : kSensorFault; + fault_buf[index] = ((voltage < MQ_VOLTAGE_LOW_LIMIT) || (voltage > MQ_VOLTAGE_HIGH_LIMIT)) ? kSensorFault : kSensorNormal; index++; if (index >= SENSOR_SAMPLING_TIMS) { diff --git a/rt-thread/components/net/at/src/at_client.c b/rt-thread/components/net/at/src/at_client.c index 6cbe2ad..856dfa9 100644 --- a/rt-thread/components/net/at/src/at_client.c +++ b/rt-thread/components/net/at/src/at_client.c @@ -868,7 +868,7 @@ static int at_client_para_init(at_client_t client) client->parser = rt_thread_create(name, (void (*)(void *parameter))client_parser, client, - 2048, + 4096, RT_THREAD_PRIORITY_MAX / 3 - 1, 5); if (client->parser == RT_NULL)