diff --git a/applications/main.c b/applications/main.c index 39f34e2..5da0c08 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: 2025-06-23 14:00:30 + * @LastEditTime: 2025-06-23 14:17:21 * @FilePath: \ble_bjq_ch303rct6_ml307\applications\main.c * @Descrt_thread_ * @@ -474,6 +474,12 @@ int main(void) Send_Laser_Alarm_Event(kFaultEvent); } } + else + { + LOG_D("正常监测模式"); + alarm_flag = 0; + fault_flag = 0; + } } else if (received_event & Get_Sys_Event_Flag(kAlarmExceptionEvent)) // 浓度异常 { @@ -525,17 +531,17 @@ int main(void) SysControl.last_status = SysControl.status; SysControl.status = kAlarmRcyEvent; - alarm_flag = 0; - Flash_Write_Record(kRecordAlarmRcy); BEEP_STOP; + + Send_Laser_Alarm_Event(kNormalDetectionEvents); #if (IOT_MODULE_SWITCH == 1) Ml307_Send_Event(kMl307AlarmRcyEvent); #endif - Send_Laser_Alarm_Event(kNormalDetectionEvents); + } else if (received_event & Get_Sys_Event_Flag(kFaultEvent)) // 故障 { diff --git a/applications/user_sys.h b/applications/user_sys.h index 218b242..1b549da 100644 --- a/applications/user_sys.h +++ b/applications/user_sys.h @@ -19,7 +19,7 @@ #define SYS_HW_VERSION (0X13U) -#define SYS_SW_VERSION (0X18U) +#define SYS_SW_VERSION (0X20U) #define SYS_IOT_UPLOAD_CYCLE_MIN (0X003CU) // 高位在后,低位在前 #define SYS_IOT_RETRY (0X03U) #define SYS_TEMP_ALARM_THRESHOLD (0X32U) diff --git a/bsp/src/at_device_ml307.c b/bsp/src/at_device_ml307.c index 64740d1..e27c7fb 100644 --- a/bsp/src/at_device_ml307.c +++ b/bsp/src/at_device_ml307.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-11-30 15:46:21 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2025-06-21 10:37:54 + * @LastEditTime: 2025-06-23 14:42:15 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\at_device_ml307.c * @Description: * @@ -406,26 +406,26 @@ static int ml307_check_link_status(struct at_device *device) // ml307 = (struct at_device_ml307 *)device->user_data; - resp = at_create_resp(96, 0, rt_tick_from_millisecond(300)); + resp = at_create_resp(128, 0, rt_tick_from_millisecond(300)); if (resp == RT_NULL) { LOG_E("no memory for resp create."); return -RT_ERROR; } - if(at_obj_exec_cmd(device->client, resp, "AT+MIPCALL?") < 0) - { - result = -RT_ERROR; - goto __exit; - } + // if(at_obj_exec_cmd(device->client, resp, "AT+MIPCALL?") < 0) + // { + // result = -RT_ERROR; + // goto __exit; + // } - if (at_resp_parse_line_args_by_kw(resp, "+MIPCALL:", "+MIPCALL: %d,%*d,%*s", &link_stat) > 0) - { - if (link_stat == 1) - { - result = RT_EOK; - } - } + // if (at_resp_parse_line_args_by_kw(resp, "+MIPCALL:", "+MIPCALL: %d,%*d,%*s", &link_stat) > 0) + // { + // if (link_stat == 1) + // { + // result = RT_EOK; + // } + // } if(at_obj_exec_cmd(device->client, resp, "AT+CGACT?") < 0) { @@ -437,7 +437,6 @@ static int ml307_check_link_status(struct at_device *device) { result = link_stat; } - __exit: if(resp) @@ -483,7 +482,6 @@ static int ml307_netdev_set_info (struct netdev *netdev) result = -RT_ENOMEM; goto __exit; } - device->class->device_ops->control (device, AT_DEVICE_CTRL_NET_CONN, RT_NULL); // 打开连接 /* set network interface device IP address */ { #define IP_ADDR_SIZE_MAX 16 @@ -511,6 +509,12 @@ static int ml307_netdev_set_info (struct netdev *netdev) inet_aton (ipaddr, &addr); netdev_low_level_set_ipaddr (netdev, &addr); } + if ( device->class->device_ops->control (device, AT_DEVICE_CTRL_NET_CONN, RT_NULL) != RT_EOK) + { + result = -RT_ERROR; + goto __exit; + } + __exit: if (resp) { @@ -530,7 +534,7 @@ static void ml307_check_link_status_entry(void *parameter) #define ML307_LINK_STATUS_OK 1 #define ML307_LINK_RESP_SIZE 128 #define ML307_LINK_RESP_TIMO (3 * RT_TICK_PER_SECOND) -#define ML307_LINK_DELAY_TIME (3000 * RT_TICK_PER_SECOND) +#define ML307_LINK_DELAY_TIME (60 * RT_TICK_PER_SECOND) at_response_t resp = RT_NULL; int link_status; @@ -582,14 +586,20 @@ int ml307_netdev_check_link_status (struct netdev *netdev) } // RT_ASSERT(netdev); - rt_snprintf (tname, RT_NAME_MAX, "%s", netdev->name); - + rt_snprintf (tname, RT_NAME_MAX, "%s_link", netdev->name); + LOG_I("netdev name: %s", tname); /* create ml307 link status polling thread */ tid = rt_thread_create (tname, ml307_check_link_status_entry, (void *)netdev, ML307_LINK_THREAD_STACK_SIZE, ML307_LINK_THREAD_PRIORITY, ML307_LINK_THREAD_TICK); if (tid != RT_NULL) { rt_thread_startup (tid); + LOG_D("create link status polling thread success."); + } + else + { + rt_thread_delete(tid); + LOG_E("create link status polling thread failed."); } return RT_EOK; @@ -989,7 +999,7 @@ static void ml307_init_thread_entry (void *parameter) goto __exit; } // LOG_D("*(rt_uint16_t *)FLASH_IOT_IMEI_ADDR = %#X", *(rt_uint16_t *)FLASH_IOT_IMEI_ADDR); - if ((*(rt_uint16_t *)FLASH_IOT_IMEI_ADDR == 0xE339) || (*(uint16_t *)FLASH_IOT_IMEI_ADDR == 0x39E3)) + if ((*(rt_uint16_t *)FLASH_IOT_IMEI_ADDR == 0xE339) || (*(rt_uint16_t *)FLASH_IOT_IMEI_ADDR == 0x39E3)) { #define ML307_NETDEV_HWADDR_LEN 8 #define ML307_IMEI_LEN 15 @@ -1098,7 +1108,7 @@ static void ml307_init_thread_entry (void *parameter) } // LOG_D("*(rt_uint16_t *)FLASH_IOT_IMSI_ADDR = %#X", *(rt_uint16_t *)FLASH_IOT_IMSI_ADDR); /* set network interface device hardware imsi */ - if ((*(rt_uint16_t *)FLASH_IOT_IMSI_ADDR == 0xE339) || (*(uint16_t *)FLASH_IOT_IMSI_ADDR == 0x39E3)) + if ((*(rt_uint16_t *)FLASH_IOT_IMSI_ADDR == 0xE339) || (*(rt_uint16_t *)FLASH_IOT_IMSI_ADDR == 0x39E3)) { #define ML307_IMSI_LEN 15 diff --git a/bsp/src/bsp_led.c b/bsp/src/bsp_led.c index e4a0724..f6e497a 100644 --- a/bsp/src/bsp_led.c +++ b/bsp/src/bsp_led.c @@ -19,7 +19,7 @@ #include ALIGN(4) -static char user_led_thread_stack[512]; +static char user_led_thread_stack[1024]; static struct rt_thread user_led_thread; // 用到了atoi diff --git a/bsp/src/bsp_ml307.c b/bsp/src/bsp_ml307.c index a4f5a21..7bf2a06 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: 2025-06-21 10:41:27 + * @LastEditTime: 2025-06-23 14:37:55 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_ml307.c * @Description: * @@ -26,7 +26,7 @@ #if IOT_MODULE_SWITCH == 1 #define ML307_THREAD_STACK_SIZE (4096 + 2048) #define ML307_RECV_THREAD_STACK_SIZE (4096 + 2048) -#define ML307_LIFE_THREAD_STACK_SIZE (4096 + 1024) +#define ML307_LIFE_THREAD_STACK_SIZE (4096) #define ML307_THREAD_PRIORITY 25 #define ML307_THREAD_TICKS 50 #define ML307_RECV_THREAD_PRIORITY 24 diff --git a/bsp/src/bsp_mq.c b/bsp/src/bsp_mq.c index a435532..b1ce5a5 100644 --- a/bsp/src/bsp_mq.c +++ b/bsp/src/bsp_mq.c @@ -92,10 +92,13 @@ static void Sensor_HandleAlarm(uint8_t count, uint8_t threshold) Sensor_device.detection_flag = kSensorNormal; Send_Laser_Alarm_Event(kAlarmRcyEvent); } - else if ((Get_Gas_VoltageAdcInt1000x() < 1000) && (count == 0)) + else { - alarm_flag = 0; - Sensor_device.detection_flag = kSensorNormal; + if ((Get_Gas_VoltageAdcInt1000x() < 1000) && (count == 0)) + { + alarm_flag = 0; + Sensor_device.detection_flag = kSensorNormal; + } } } @@ -127,7 +130,7 @@ static uint8_t Sensor_CheckData(void) if(alarm_flag)//检测到报警后的报警恢复,降低其阈值 { - alarm_status_buffer[index] = (((voltage > (Sensor_device.alarm_value - 500)) && (voltage < MQ_VOLTAGE_HIGH_LIMIT)) ? kSensorAlarm : kSensorNormal); + alarm_status_buffer[index] = (((voltage > (Sensor_device.alarm_value - 200)) && (voltage < MQ_VOLTAGE_HIGH_LIMIT)) ? kSensorAlarm : kSensorNormal); } else { @@ -211,7 +214,10 @@ static void Sensor_detection_thread_entry(void *param) { if (SysControl.status > kPreheatingEvent) { - Sensor_CheckData(); + if(calibration_flag == kSysGasCalibStatus) + { + Sensor_CheckData(); + } } rt_thread_mdelay(500); } diff --git a/rt-thread/rtconfig.h b/rt-thread/rtconfig.h index 0fd4645..4e5988b 100644 --- a/rt-thread/rtconfig.h +++ b/rt-thread/rtconfig.h @@ -77,7 +77,7 @@ #define RT_USING_COMPONENTS_INIT #define RT_USING_USER_MAIN -#define RT_MAIN_THREAD_STACK_SIZE 2048 +#define RT_MAIN_THREAD_STACK_SIZE 1536 #define RT_MAIN_THREAD_PRIORITY 5 #ifdef ENABLE_LOG_ALL @@ -88,7 +88,7 @@ #define FINSH_THREAD_NAME "tshell" #define FINSH_THREAD_PRIORITY 11 -#define FINSH_THREAD_STACK_SIZE 3072 +#define FINSH_THREAD_STACK_SIZE 2048 #define FINSH_USING_HISTORY #define FINSH_HISTORY_LINES 5 #define FINSH_USING_SYMTAB