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] =?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