From 9455f1ee506dcbcc9c95d1103276d2876655c733 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, 22 May 2025 17:46:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/main.c | 241 +++++++++++++++++++++++++------------- applications/user_sys.h | 2 + bsp/inc/bsp_led.h | 10 +- bsp/src/at_device_ml307.c | 68 +++++------ bsp/src/bsp_button.c | 2 +- bsp/src/bsp_flash.c | 2 +- bsp/src/bsp_ml307.c | 63 ++++++---- bsp/src/bsp_mq.c | 5 +- 8 files changed, 252 insertions(+), 141 deletions(-) diff --git a/applications/main.c b/applications/main.c index 6a299d9..1278c2c 100644 --- a/applications/main.c +++ b/applications/main.c @@ -43,9 +43,13 @@ TsSysControl SysControl; struct rt_timer work_cnt_timer; struct rt_timer preheat_timer; // 传统模式需要进行预热, +uint8_t preheat_flag = 0; // 预热时间是否结束标志 + +uint8_t Calibration_flag = 0;//查看是否在标定检测状态 void Send_Laser_Alarm_Event(AlarmEvent event_type); TeCalibrationStatus g_Calibration_status = kNotCalibrated; + static void Set_Event(AlarmEvent event_type) { if (event_type < kMaxEventcnt) @@ -143,63 +147,113 @@ void Work_Cnt_Timer_Callback(void *parameter) void Preheat_Timer_Callback(void *parameter) { - BEEP_PREAT_OK; LED_STOP(r); LED_STOP(g); LED_STOP(y); LOG_D("预热完成"); - Send_Laser_Alarm_Event(kNormalDetectionEvents); + preheat_flag = 1; + if (g_Calibration_status == kSysGasCalibStatus) + { + Send_Laser_Alarm_Event(kNormalDetectionEvents); + } + else + { + Send_Laser_Alarm_Event(kCalibrationEvent); + } } int APP_Calibration_Handle(void) { - // 定义超时时间,单位为毫秒 -#define TIMEOUT_MS (3 * 60 * 1000) + uint8_t i = 0; + uint16_t gas_buf[10] = {0}; + uint32_t gas_calibration_voltage = 0; - LED_STOP(g); - LED_STOP(y); - LED_ON(r); - LED_START(r); - - uint32_t ticks = 0, gas_calibration_voltage; - LOG_D("标定开始"); + // if (Get_Gas_VoltageAdcInt1000x() > 400 && Get_Gas_VoltageAdcInt1000x() < 900) + // { + // LED_OFF(r); + // LED_OFF(g); + // LED_ON(y); + // LOG_D("传感器故障"); + // return 0; + // } + if (Get_Gas_VoltageAdcInt1000x() > (MQ_VOLTAGE_ALARM_DEFAULT - 1500) && Get_Gas_VoltageAdcInt1000x() < (MQ_VOLTAGE_ALARM_DEFAULT + 1000)) + { + LOG_D("标定开始"); + LED_OFF(g); + LED_OFF(y); + LED_OFF(r); + LED_CTRL(y, "200,200", -1); + LED_START(y); + } + else + { + g_Calibration_status = kNotCalibrated; + LOG_D("没有气体,请重新上电标定"); + Send_Laser_Alarm_Event(kNotCalibratedEvent); + return 0; + } + Calibration_flag = 1; while (1) { - gas_calibration_voltage = Get_Gas_VoltageAdcInt1000x(); - LOG_D("ticks[%d] gas_calibration_voltage = %d", ticks++, gas_calibration_voltage); - - if (ticks > (TIMEOUT_MS / 1000)) + for (i = 0; i < 10; i++) { - ticks = 0; // 加这个的原因是,如果刚开始没标定,但是时间到了,此时刚通气开始标定,可能直接就读到值了,所以加这个判断 - if (gas_calibration_voltage > (MQ_VOLTAGE_ALARM_DEFAULT - 1500) && gas_calibration_voltage < (MQ_VOLTAGE_ALARM_DEFAULT + 1000)) + gas_buf[i] = Get_Gas_VoltageAdcInt1000x(); + if (gas_buf[i] == 0) { - uint8_t calibration_buf[2] = {0}; - calibration_buf[0] = gas_calibration_voltage & 0xFF; // 低字节 - calibration_buf[1] = (gas_calibration_voltage >> 8) & 0xFF; // 高字节 - LOG_D("calibration_buf[0] = %X calibration_buf[1] = %X", calibration_buf[0], calibration_buf[1]); - Flash_Sys_Cfg(kAlarmLValueId, calibration_buf, 2); - LOG_D("标定完成"); - // 标定完成打开绿灯常亮,蜂鸣器叫一下 - BEEP_CALIBRATION_OK; - LED_STOP(g); - LED_ON(g); - Flash_Set_Calibration_State(kSysGasCalibStatus); - g_Calibration_status = kSysGasCalibStatus; - break; + return 0; } + gas_calibration_voltage |= gas_buf[i]; + rt_thread_mdelay(1000); } - if (g_Calibration_status == kSysGasCalibStatus) + if (i == 10) { - return RT_EOK; + gas_calibration_voltage = (uint16_t)gas_calibration_voltage / 10; + uint8_t calibration_buf[2] = {0}; + calibration_buf[0] = gas_calibration_voltage & 0xFF; // 低字节 + calibration_buf[1] = (gas_calibration_voltage >> 8) & 0xFF; // 高字节 + LOG_D("calibration_buf[0] = %X calibration_buf[1] = %X", calibration_buf[0], calibration_buf[1]); + Flash_Sys_Cfg(kAlarmLValueId, calibration_buf, 2); + LOG_D("标定完成"); + Calibration_flag = 0; + Flash_Set_Calibration_State(kSysGasCalibStatus); + g_Calibration_status = kSysGasCalibStatus; + Send_Laser_Alarm_Event(kNormalDetectionEvents); + + return 0; + } + else + { + LOG_E("标定错误"); + return -1; } - rt_thread_mdelay(1000); } } -// 已经标定了 -void APP_Handle(void) +int main(void) { + // 定义超时时间,单位为毫秒 +#define TIMEOUT_MS (3 * 60 * 1000) #define WORK_TIMER_CNT (1000 * 60 * 60) + + if (Get_VIN_VoltageInt1000x() > 10000) + { + SYS_EventInit(); + BSP_SYS_Init(); + work_duration = Flash_Get_WorkDuration(); + LOG_D("工作时长:%d", work_duration); + // 读取历史记录总数 + g_Calibration_status = Flash_Get_Calibration_State(); + rt_thread_mdelay(10); + } + else + { + LOG_D("欠压复位\r\n"); + RCC_ClearFlag(); + NVIC_SystemReset(); // 直接重启系统 + } + BSP_VIN_Detection_Init(); + + rt_err_t result = RT_EINVAL; rt_uint32_t received_event; @@ -237,6 +291,7 @@ void APP_Handle(void) Send_Laser_Alarm_Event(kPreheatingEvent); // 这一句的作用是设备不是掉电重启的情况,直接进入预热模式 } RCC_ClearFlag(); + while (1) { result = rt_event_recv(&alarm_event, @@ -250,7 +305,9 @@ void APP_Handle(void) Get_Sys_Event_Flag(kSelfCheckEvent) | // 自检 Get_Sys_Event_Flag(kFaultEvent) | // 故障模式 Get_Sys_Event_Flag(kFaultRcyEvent) | // 故障恢复 - Get_Sys_Event_Flag(KMuteEvent), // 消音 + Get_Sys_Event_Flag(KMuteEvent) | // 消音 + Get_Sys_Event_Flag(kCalibrationEvent) | // 标定 + Get_Sys_Event_Flag(kNotCalibratedEvent), // 标定 RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &received_event); if (result == RT_EOK) @@ -272,8 +329,38 @@ void APP_Handle(void) SysControl.last_status = SysControl.status; SysControl.status = kPreheatingEvent; - LED_G_PREAT; - rt_timer_start(&preheat_timer); + + if (SysControl.last_status != kSelfCheckEvent) + { + LED_G_PREAT; + rt_timer_start(&preheat_timer); + } + else + { + LED_STOP(r); + LED_STOP(g); + LED_STOP(y); + LED_CTRL(g, "100,100", -1); + LED_START(g); + } + } + else if (received_event & Get_Sys_Event_Flag(kCalibrationEvent)) // 标定状态 + { + LOG_D("标定检测"); + SysControl.last_status = SysControl.status; + SysControl.status = kCalibrationEvent; + APP_Calibration_Handle(); + } + else if (received_event & Get_Sys_Event_Flag(kNotCalibratedEvent)) // 未标定状态 + { + LOG_D("未标定模式"); + + SysControl.last_status = SysControl.status; + SysControl.status = kNotCalibratedEvent; + LED_STOP(r); + LED_STOP(g); + LED_STOP(y); + LED_ON(r); } else if (received_event & Get_Sys_Event_Flag(kNormalDetectionEvents)) // 正常检测 { @@ -472,7 +559,36 @@ void APP_Handle(void) LED_STOP(r); LED_STOP(g); LED_STOP(y); - Send_Laser_Alarm_Event(kNormalDetectionEvents); + + if (g_Calibration_status == kSysGasCalibStatus) + { + if (SysControl.last_status == kPreheatingEvent) + { + if (preheat_flag) + { + Send_Laser_Alarm_Event(kNormalDetectionEvents); + } + else + { + Send_Laser_Alarm_Event(kPreheatingEvent); + } + } + else + { + Send_Laser_Alarm_Event(kNormalDetectionEvents); + } + } + else + { + if (preheat_flag) + { + Send_Laser_Alarm_Event(kNotCalibratedEvent); + } + else + { + Send_Laser_Alarm_Event(kPreheatingEvent); + } + } } else if (received_event & Get_Sys_Event_Flag(kSensorFailureEvent)) // 失效 { @@ -485,8 +601,8 @@ void APP_Handle(void) { Flash_Write_Record(kRecordSensoEndOfLife); } - Ml307_Send_Event(kMl307DeviceFailureEvent);//发送一个失效事件 - Send_Laser_Alarm_Event(kNormalDetectionEvents);///再返回正常模式继续检测 + Ml307_Send_Event(kMl307DeviceFailureEvent); // 发送一个失效事件 + Send_Laser_Alarm_Event(kNormalDetectionEvents); /// 再返回正常模式继续检测 // LED_Y_END_OF_LIFE; } } @@ -494,46 +610,6 @@ void APP_Handle(void) } } -int main(void) -{ - if (Get_VIN_VoltageInt1000x() > 10000) - { - SYS_EventInit(); - BSP_SYS_Init(); - work_duration = Flash_Get_WorkDuration(); - LOG_D("工作时长:%d", work_duration); - // 读取历史记录总数 - g_Calibration_status = Flash_Get_Calibration_State(); - rt_thread_mdelay(10); - } - else - { - LOG_D("欠压复位\r\n"); - RCC_ClearFlag(); - NVIC_SystemReset(); // 直接重启系统 - } - BSP_VIN_Detection_Init(); - while (1) - { - switch (g_Calibration_status) - { - case kNotCalibrated: // 没标定 - { - APP_Calibration_Handle(); - break; - } - case kSysGasCalibStatus: - { - APP_Handle(); - break; - } - default: - break; - } - rt_thread_mdelay(10); - } -} - #ifdef TEST_ENABLE static void SYS_Set_RtcProductTime(int argc, char **argv) { @@ -560,6 +636,7 @@ static void SYS_Set_RtcProductTime(int argc, char **argv) LOG_E("SYS_Set_RtcProductTime --use _cmd_ [2000 + y] [m] [d] [h] [m] [s]"); } } + MSH_CMD_EXPORT(SYS_Set_RtcProductTime, "SYS_Set_RtcProductTime"); // 测试系统标定值修改 @@ -575,12 +652,14 @@ static void TEST_SYS_Calibartion(int argc, char **argv) Flash_Set_Calibration_State(kSysGasCalibStatus); LOG_D("标定值修改为 = %d", Flash_Get_SysCfg(kAlarmLValueId)); g_Calibration_status = kSysGasCalibStatus; + Send_Laser_Alarm_Event(kNormalDetectionEvents); /// 再返回正常模式继续检测 } else { LOG_E("TEST_SYS_Calibartion 0~4095"); } } + MSH_CMD_EXPORT(TEST_SYS_Calibartion, "修改系统标定值"); static void SYS_SW_Version(void) diff --git a/applications/user_sys.h b/applications/user_sys.h index faa0947..80e49f9 100644 --- a/applications/user_sys.h +++ b/applications/user_sys.h @@ -64,6 +64,8 @@ typedef enum kSelfCheckEvent, KMuteEvent, kAlarmExceptionEvent, // 浓度异常报警 + kCalibrationEvent, //标定阶段 + kNotCalibratedEvent, //未标定状态 kMaxEventcnt, } AlarmEvent; diff --git a/bsp/inc/bsp_led.h b/bsp/inc/bsp_led.h index d9fd5f7..9ef0a9f 100644 --- a/bsp/inc/bsp_led.h +++ b/bsp/inc/bsp_led.h @@ -38,15 +38,19 @@ extern agile_led_t *led_y; LED_STOP(r);\ LED_STOP(g);\ LED_STOP(y);\ - LED_CTRL(g, "500,2500", -1);\ + LED_CTRL(g, "500,2500", 1);\ LED_START(g);\ rt_thread_mdelay(1000);\ - LED_CTRL(y, "500,2500", -1);\ + LED_CTRL(y, "500,2500", 1);\ LED_START(y);\ rt_thread_mdelay(1000);\ - LED_CTRL(r, "500,2500", -1);\ + LED_CTRL(r, "500,2500", 1);\ LED_START(r);\ rt_thread_mdelay(1000);\ + BEEP_CTRL("500,500", 1); \ + BEEP_START; \ + LED_CTRL(g, "100,100", -1);\ + LED_START(g);\ } while (0U) #define LED_G_NORMAL \ diff --git a/bsp/src/at_device_ml307.c b/bsp/src/at_device_ml307.c index cb2abbb..0052824 100644 --- a/bsp/src/at_device_ml307.c +++ b/bsp/src/at_device_ml307.c @@ -954,6 +954,7 @@ static void ml307_init_thread_entry(void *parameter) result = -RT_ERROR; goto __exit; } + if(*(uint32_t *)FLASH_IOT_IMEI_ADDR == 0xE339E339) { #define ML307_NETDEV_HWADDR_LEN 8 #define ML307_IMEI_LEN 15 @@ -1019,7 +1020,8 @@ static void ml307_init_thread_entry(void *parameter) rt_thread_mdelay(1000); } /* set network interface device hardware iccid */ - { + if(*(uint32_t *)FLASH_IOT_ICCID_ADDR == 0xE339E339) + { #define ML307_ICCID_LEN 20 @@ -1045,7 +1047,7 @@ static void ml307_init_thread_entry(void *parameter) } /* set network interface device hardware imsi */ - { + if(*(uint32_t *)FLASH_IOT_IMSI_ADDR == 0xE339E339){ #define ML307_IMSI_LEN 15 @@ -1094,43 +1096,43 @@ static void ml307_init_thread_entry(void *parameter) result = -RT_ERROR; goto __exit; } - // if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL=1,1") != RT_EOK) - if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL=0") != RT_EOK) + if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL=1,1") != RT_EOK) + // if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL=0") != RT_EOK) { result = -RT_ERROR; goto __exit; } -// #if defined(AT_DEBUG) -// /* check the GPRS network IP address */ -// for (i = 0; i < IPADDR_RETRY; i++) -// { -// if (at_obj_exec_cmd(client, resp, "AT+MIPCALL?") == RT_EOK) -// { -// #define IP_ADDR_SIZE_MAX 16 -// char ipaddr_str[8 * IP_ADDR_SIZE_MAX] = {0}; -// char ipaddr_v4[IP_ADDR_SIZE_MAX] = {0}; -// char ipaddr_v6[4 * IP_ADDR_SIZE_MAX] = {0}; +#if defined(AT_DEBUG) + /* check the GPRS network IP address */ + for (i = 0; i < IPADDR_RETRY; i++) + { + if (at_obj_exec_cmd(client, resp, "AT+MIPCALL?") == RT_EOK) + { +#define IP_ADDR_SIZE_MAX 16 + char ipaddr_str[8 * IP_ADDR_SIZE_MAX] = {0}; + char ipaddr_v4[IP_ADDR_SIZE_MAX] = {0}; + char ipaddr_v6[4 * IP_ADDR_SIZE_MAX] = {0}; -// /* parse response data "+CGPADDR: 1," */ -// if (at_resp_parse_line_args_by_kw(resp, "+MIPCALL:", "+MIPCALL: %*d,%*d,%s", ipaddr_str) > 0) -// { -// const char *ipaddr_v4_str = strstr(ipaddr_str, "\""); -// sscanf(ipaddr_v4_str, "\"%[^\"]", ipaddr_v4); -// const char *ipaddr_v6_str = strstr(ipaddr_str, "\",\""); -// sscanf(ipaddr_v6_str, "\",\"%[^\"]", ipaddr_v6); + /* parse response data "+CGPADDR: 1," */ + if (at_resp_parse_line_args_by_kw(resp, "+MIPCALL:", "+MIPCALL: %*d,%*d,%s", ipaddr_str) > 0) + { + const char *ipaddr_v4_str = strstr(ipaddr_str, "\""); + sscanf(ipaddr_v4_str, "\"%[^\"]", ipaddr_v4); + const char *ipaddr_v6_str = strstr(ipaddr_str, "\",\""); + sscanf(ipaddr_v6_str, "\",\"%[^\"]", ipaddr_v6); -// LOG_D("%s device IP address: %s - %s", device->name, ipaddr_v4, ipaddr_v6); -// break; -// } -// } -// rt_thread_mdelay(1000); -// } -// if (i == IPADDR_RETRY) -// { -// LOG_E("%s device GPRS is get IP address failed", device->name); -// result = -RT_ERROR; -// goto __exit; -// } + LOG_D("%s device IP address: %s - %s", device->name, ipaddr_v4, ipaddr_v6); + break; + } + } + rt_thread_mdelay(1000); + } + if (i == IPADDR_RETRY) + { + LOG_E("%s device GPRS is get IP address failed", device->name); + result = -RT_ERROR; + goto __exit; + } #endif Time_Calibration(device); /* initialize successfully */ diff --git a/bsp/src/bsp_button.c b/bsp/src/bsp_button.c index f2f5770..ec49066 100644 --- a/bsp/src/bsp_button.c +++ b/bsp/src/bsp_button.c @@ -55,7 +55,7 @@ static void _CommonBtnEvtCb (void *arg) if (flex_button_event_read (&user_button[USER_BUTTON_1]) == FLEX_BTN_PRESS_DOUBLE_CLICK) { - if (SysControl.status > kPreheatingEvent) + if(SysControl.status != kCalibrationEvent) { Send_Laser_Alarm_Event (kSelfCheckEvent); } diff --git a/bsp/src/bsp_flash.c b/bsp/src/bsp_flash.c index a8e6f2c..1241e9f 100644 --- a/bsp/src/bsp_flash.c +++ b/bsp/src/bsp_flash.c @@ -895,7 +895,7 @@ int BSP_Flash_Init (void) Flash_SetProductTimeLimit (2025, 2, 10, 13, 50, 20, kFactoryTimeId); Set_ExpirationTime (MAX_EXPIRATION_DAYS); - Flash_Set_Calibration_State(kSysGasCalibStatus); // 标定状态 + Flash_Set_Calibration_State(kNotCalibrated); // 标定状态 Flash_Set_Valve_Num(0); sci.hw_ver = SYS_HW_VERSION; sci.sw_ver = SYS_SW_VERSION; diff --git a/bsp/src/bsp_ml307.c b/bsp/src/bsp_ml307.c index f4ceca0..8db1320 100644 --- a/bsp/src/bsp_ml307.c +++ b/bsp/src/bsp_ml307.c @@ -814,6 +814,7 @@ int Ml307_Send_Device_Failure(struct at_device *device, void *param) } return RT_EOK; } + /*这个【4、优先级最低当同时触发后,相同服务直接合并】暂时还没想好怎么做, 思路感觉就是得重新开一个线程,然后再开一个任务队列,将所有的事件,发送到任务队列 在线程中,对任务队列进行查看并处理,看目前都有哪些事件,是处于那个优先级得,如果是最低优先级,就只发送一帧数据就行了, @@ -943,13 +944,8 @@ int Ml307_Process_Events(Ml307Event ml307_recv_event, struct at_device *device, if (ret != RT_EOK) { ml307_connect_sever_flag = 0; - ml307_conncet_tcp_flag = 0; - if (!ml307_disconnect_retry_flag) - { - LOG_D("断网,启动重连\n"); - rt_sem_release(ml307_disconnect_sem); - } - LOG_D("断网,等待连接中......\n"); + rt_sem_release(ml307_disconnect_sem); + LOG_D("与服务区断开连接,等待连接中......\n"); } } @@ -1967,19 +1963,43 @@ static void Ml307_Life_Thread_Entry(void *parameter) result = -RT_ERROR; goto __exit; } - // if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL=1,1") != RT_EOK) - // { - // result = -RT_ERROR; - // goto __exit; - // } - // int link_stat = 0; - // 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+MIPCALL=1,1") != RT_EOK) + { + result = -RT_ERROR; + goto __exit; + } +#if defined(AT_DEBUG) + /* check the GPRS network IP address */ + for (i = 0; i < 10; i++) + { + if (at_obj_exec_cmd(device->client, resp, "AT+MIPCALL?") == RT_EOK) + { +#define IP_ADDR_SIZE_MAX 16 + char ipaddr_str[8 * IP_ADDR_SIZE_MAX] = {0}; + char ipaddr_v4[IP_ADDR_SIZE_MAX] = {0}; + char ipaddr_v6[4 * IP_ADDR_SIZE_MAX] = {0}; + + /* parse response data "+CGPADDR: 1," */ + if (at_resp_parse_line_args_by_kw(resp, "+MIPCALL:", "+MIPCALL: %*d,%*d,%s", ipaddr_str) > 0) + { + const char *ipaddr_v4_str = rt_strstr(ipaddr_str, "\""); + sscanf(ipaddr_v4_str, "\"%[^\"]", ipaddr_v4); + const char *ipaddr_v6_str = rt_strstr(ipaddr_str, "\",\""); + sscanf(ipaddr_v6_str, "\",\"%[^\"]", ipaddr_v6); + + LOG_D("%s device IP address: %s - %s", device->name, ipaddr_v4, ipaddr_v6); + break; + } + } + rt_thread_mdelay(2000); + } + if (i == 10) + { + LOG_E("%s device GPRS is get IP address failed", device->name); + result = -RT_ERROR; + goto __exit; + } +#endif if (device->class->device_ops->control(device, AT_DEVICE_CTRL_NET_CONN, RT_NULL) == RT_EOK) { LOG_D("重连网络成功\n"); @@ -2012,6 +2032,7 @@ static void Ml307_Life_Thread_Entry(void *parameter) else { ml307_disconnect_retry_flag = 0; + Ml307_Send_Event(kMl307HeartbeatEvent); } } else @@ -2146,6 +2167,7 @@ int BSP_Ml307_Thread_Init(void) return ret; } + // INIT_APP_EXPORT(BSP_Ml307_Thread_Init); int ml307_device_register(void) @@ -2158,6 +2180,7 @@ int ml307_device_register(void) AT_DEVICE_CLASS_ML307, (void *)ml307); } + // INIT_DEVICE_EXPORT(ml307_device_register); #endif // IOT_MODULE_SWITCH diff --git a/bsp/src/bsp_mq.c b/bsp/src/bsp_mq.c index 536484c..5c14903 100644 --- a/bsp/src/bsp_mq.c +++ b/bsp/src/bsp_mq.c @@ -47,7 +47,7 @@ uint16_t Get_Gas_VoltageInt1000x(void) uint16_t Get_Gas_VoltageAdcInt1000x(void) { rt_uint16_t voltage_adc = (Get_ADC_Average(kGasAdc) * 3.3 / 4096) * 1000; - // LOG_D("Get_Gas_VoltageAdcInt1000x = %04d", voltage_adc); + LOG_D("Get_Gas_VoltageAdcInt1000x = %04d", voltage_adc); return voltage_adc; } @@ -79,7 +79,7 @@ static void Sensor_HandleAlarm(uint8_t count, uint8_t threshold) alarm_flag = 1; Sensor_device.detection_flag = kSensorAlarm; Send_Laser_Alarm_Event(kAlarmEvent); - + } else if (alarm_flag == 1 && count == 0) { @@ -180,6 +180,7 @@ static void Sensor_detection_thread_entry(void *param) if(calibration_flag == 1) break; rt_thread_mdelay(1000); + Get_Gas_VoltageAdcInt1000x(); } rt_uint16_t alarm_value = Flash_Get_SysCfg(kAlarmLValueId); // 获取系统报警阈值; From e8968153d28cd2cf87677050a10503199350c864 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: Fri, 23 May 2025 13:55:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=88=9D?= =?UTF-8?q?=E6=AC=A1=E5=86=99=E5=85=A5falsh=20=E6=A8=A1=E7=BB=84=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/src/at_device_ml307.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bsp/src/at_device_ml307.c b/bsp/src/at_device_ml307.c index 0052824..42480d5 100644 --- a/bsp/src/at_device_ml307.c +++ b/bsp/src/at_device_ml307.c @@ -186,7 +186,7 @@ static void urc_tcp_connect_state(struct at_client *client, const char *data, rt if (sscanf(data, "+MIPOPEN:%d,%d", &id, &err_code) == 2) { - socket_id = id; + socket_id = id; { switch (err_code) { @@ -954,7 +954,8 @@ static void ml307_init_thread_entry(void *parameter) result = -RT_ERROR; goto __exit; } - if(*(uint32_t *)FLASH_IOT_IMEI_ADDR == 0xE339E339) + 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)) { #define ML307_NETDEV_HWADDR_LEN 8 #define ML307_IMEI_LEN 15 @@ -1020,8 +1021,9 @@ static void ml307_init_thread_entry(void *parameter) rt_thread_mdelay(1000); } /* set network interface device hardware iccid */ - if(*(uint32_t *)FLASH_IOT_ICCID_ADDR == 0xE339E339) - { + LOG_D("*(rt_uint16_t *)FLASH_IOT_ICCID_ADDR = %#X", *(rt_uint16_t *)FLASH_IOT_ICCID_ADDR); + if ((*(rt_uint16_t *)FLASH_IOT_ICCID_ADDR == 0xE339) || (*(uint16_t *)FLASH_IOT_ICCID_ADDR == 0x39E3)) + { #define ML307_ICCID_LEN 20 @@ -1045,9 +1047,10 @@ static void ml307_init_thread_entry(void *parameter) rt_memcpy(ml307.iccid, iccid, ML307_ICCID_LEN); Flash_Sys_Cfg(kIotIccidId, ml307.iccid, ML307_ICCID_LEN); } - + LOG_D("*(rt_uint16_t *)FLASH_IOT_IMSI_ADDR = %#X", *(rt_uint16_t *)FLASH_IOT_IMSI_ADDR); /* set network interface device hardware imsi */ - if(*(uint32_t *)FLASH_IOT_IMSI_ADDR == 0xE339E339){ + if ((*(rt_uint16_t *)FLASH_IOT_IMSI_ADDR == 0xE339) || (*(uint16_t *)FLASH_IOT_IMSI_ADDR == 0x39E3)) + { #define ML307_IMSI_LEN 15 From c8f605082a228889f0a2386765722ae062967b65 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: Fri, 23 May 2025 14:20:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9A=82=E5=AD=98=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/inc/bsp_mq.h | 8 ++++---- bsp/src/at_device_ml307.c | 22 +++++++++++++++++++--- bsp/src/bsp_flash.c | 37 +++++++++++++++++++++++-------------- 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/bsp/inc/bsp_mq.h b/bsp/inc/bsp_mq.h index ffb2782..3e2e1c8 100644 --- a/bsp/inc/bsp_mq.h +++ b/bsp/inc/bsp_mq.h @@ -1,12 +1,12 @@ -/*** +/*** * @Author: mbw * @Date: 2024-11-30 16:46:31 * @LastEditors: mbw && 1600520629@qq.com * @LastEditTime: 2025-02-21 15:32:14 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\inc\bsp_mq.h - * @Description: + * @Description: * @ - * @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + * @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. */ /* * @Author : stark1898y 1658608470@qq.com @@ -26,7 +26,7 @@ // MQ采样间隔 #define MQ_SAMPLING_INTERVAL_MS (100U) -#define SENSOR_SAMPLING_TIMS (10U) +#define SENSOR_SAMPLING_TIMS (4U) // MQ采样时间窗口 #define MQ_SAMPLING_S (uint8_t)(3U) diff --git a/bsp/src/at_device_ml307.c b/bsp/src/at_device_ml307.c index 42480d5..fde444e 100644 --- a/bsp/src/at_device_ml307.c +++ b/bsp/src/at_device_ml307.c @@ -954,7 +954,7 @@ static void ml307_init_thread_entry(void *parameter) result = -RT_ERROR; goto __exit; } - LOG_D("*(rt_uint16_t *)FLASH_IOT_IMEI_ADDR = %#X", *(rt_uint16_t *)FLASH_IOT_IMEI_ADDR); + // 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)) { #define ML307_NETDEV_HWADDR_LEN 8 @@ -978,6 +978,12 @@ static void ml307_init_thread_entry(void *parameter) rt_memcpy(ml307.imei, imei, ML307_IMEI_LEN); Flash_Sys_Cfg(kIotImeiId, ml307.imei, ML307_IMEI_LEN); } + else + { + rt_memset((char *)ml307.imei, 0, ML307_IMEI_LEN); + Get_IotImei((char *)&ml307.imei[0], ML307_IMEI_LEN); + } + /* check SIM card */ for (i = 0; i < CPIN_RETRY; i++) { @@ -1021,7 +1027,7 @@ static void ml307_init_thread_entry(void *parameter) rt_thread_mdelay(1000); } /* set network interface device hardware iccid */ - LOG_D("*(rt_uint16_t *)FLASH_IOT_ICCID_ADDR = %#X", *(rt_uint16_t *)FLASH_IOT_ICCID_ADDR); + // LOG_D("*(rt_uint16_t *)FLASH_IOT_ICCID_ADDR = %#X", *(rt_uint16_t *)FLASH_IOT_ICCID_ADDR); if ((*(rt_uint16_t *)FLASH_IOT_ICCID_ADDR == 0xE339) || (*(uint16_t *)FLASH_IOT_ICCID_ADDR == 0x39E3)) { @@ -1047,7 +1053,12 @@ static void ml307_init_thread_entry(void *parameter) rt_memcpy(ml307.iccid, iccid, ML307_ICCID_LEN); Flash_Sys_Cfg(kIotIccidId, ml307.iccid, ML307_ICCID_LEN); } - LOG_D("*(rt_uint16_t *)FLASH_IOT_IMSI_ADDR = %#X", *(rt_uint16_t *)FLASH_IOT_IMSI_ADDR); + else + { + rt_memset((char *)ml307.iccid, 0, ML307_ICCID_LEN); + Get_IotIccid((char *)&ml307.iccid[0], ML307_ICCID_LEN); + } + // 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)) { @@ -1074,6 +1085,11 @@ static void ml307_init_thread_entry(void *parameter) rt_memcpy(ml307.imsi, imsi, ML307_IMSI_LEN); Flash_Sys_Cfg(kIotImsiId, ml307.imsi, ML307_IMSI_LEN); } + else + { + rt_memset((char *)ml307.imsi, 0, ML307_IMSI_LEN); + Get_IotImsi((char *)&ml307.imsi[0], ML307_IMSI_LEN); + } /* check the GPRS network is registered */ for (i = 0; i < CEREG_RETRY; i++) diff --git a/bsp/src/bsp_flash.c b/bsp/src/bsp_flash.c index 1241e9f..62530a2 100644 --- a/bsp/src/bsp_flash.c +++ b/bsp/src/bsp_flash.c @@ -150,13 +150,16 @@ static rt_size_t Flash_Read(rt_uint32_t addr, rt_uint8_t *buf, rt_size_t len) return read_len; } -int Get_IotImei(char *buf, rt_size_t len) +int Get_IotImei (char *buf, rt_size_t len) { + if ((*(rt_uint8_t *)FLASH_IOT_IMEI_ADDR != 0xE3) && (*(rt_uint8_t *)FLASH_IOT_IMEI_ADDR != 0x39)) { - rt_memcpy(buf, (char *)FLASH_IOT_IMEI_ADDR, len); - - LOG_D("IMEI: %s", buf); + char imei_buf[FLASH_IOT_IMEI_LEN + 1]={0}; + Flash_Read(FLASH_IOT_IMEI_ADDR, (rt_uint8_t *)&imei_buf[0], len); + imei_buf[len] = '\0'; + LOG_D ("read imei: %s", imei_buf); + rt_memcpy(buf, imei_buf, len); return 0; } else @@ -166,18 +169,21 @@ int Get_IotImei(char *buf, rt_size_t len) { buf[i] = '0'; } - LOG_D("IMSI: %s", buf); + LOG_D ("IOT IMSI: %s", buf); return -1; } } -int Get_IotImsi(char *buf, rt_size_t len) +int Get_IotImsi (char *buf, rt_size_t len) { if ((*(rt_uint8_t *)FLASH_IOT_IMSI_ADDR != 0xE3) && (*(rt_uint8_t *)FLASH_IOT_IMSI_ADDR != 0x39)) { - rt_memcpy(buf, (char *)FLASH_IOT_IMSI_ADDR, len); + char imsi_buf[FLASH_IOT_IMSI_LEN]={0}; + Flash_Read(FLASH_IOT_IMSI_ADDR, (rt_uint8_t *)imsi_buf, len); + imsi_buf[len] = '\0'; + LOG_D ("read imsi: %s", imsi_buf); + rt_memcpy(buf, imsi_buf, len); - LOG_D("IMSI: %s", buf); return 0; } else @@ -187,18 +193,20 @@ int Get_IotImsi(char *buf, rt_size_t len) { buf[i] = '0'; } - LOG_D("IMSI: %s", buf); + LOG_D ("IOT IMSI: %s", buf); return -1; } } -int Get_IotIccid(char *buf, rt_size_t len) +int Get_IotIccid (char *buf, rt_size_t len) { if ((*(rt_uint8_t *)FLASH_IOT_ICCID_ADDR != 0xE3) && (*(rt_uint8_t *)FLASH_IOT_ICCID_ADDR != 0x39)) { - rt_memcpy(buf, (char *)FLASH_IOT_ICCID_ADDR, len); - - LOG_D("ICCID: %s", buf); + char iccid_buf[FLASH_IOT_ICCID_LEN]={0}; + Flash_Read(FLASH_IOT_ICCID_ADDR, (rt_uint8_t *)iccid_buf, len); + iccid_buf[len] = '\0'; + LOG_D ("read iccid: %s", iccid_buf); + rt_memcpy(buf, iccid_buf, len); return 0; } else @@ -208,11 +216,12 @@ int Get_IotIccid(char *buf, rt_size_t len) { buf[i] = '0'; } - LOG_D("ICCID: %s", buf); + LOG_D ("IOT ICCID: %s", buf); return -1; } } + /** * @description: * @param {uint32_t} addr