diff --git a/.mrs/ble_bjq_ch303rct6_ml307.mrs-workspace b/.mrs/ble_bjq_ch303rct6_ml307.mrs-workspace new file mode 100644 index 0000000..1c39ace --- /dev/null +++ b/.mrs/ble_bjq_ch303rct6_ml307.mrs-workspace @@ -0,0 +1,26 @@ +{ + "folders": [ + { + "path": "." + }, + { + "name": "ble_bjq_ch303rct6_ml307", + "path": "../" + } + ], + "settings": { + "mrs.workspace.type": "project", + "files.associations": { + "*.c": "c", + "*.h": "cpp", + "*.hxx": "cpp", + "*.hpp": "cpp", + "*.c++": "cpp", + "*.cpp": "cpp", + "*.cxx": "cpp", + "*.cc": "cpp", + "*.hh": "cpp", + "*.h++": "cpp" + } + } +} \ No newline at end of file diff --git a/.mrs/launch.json b/.mrs/launch.json new file mode 100644 index 0000000..e17263f --- /dev/null +++ b/.mrs/launch.json @@ -0,0 +1,65 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "mrs-debugger", + "request": "launch", + "name": "ble_bjq_ch303rct6_ml307", + "cwd": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307", + "openOCDCfg": { + "useLocalOpenOCD": true, + "executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe", + "configOptions": [ + "-f \"c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/wch-riscv.cfg\" -c \"chip_id CH32V30x\"" + ], + "gdbport": 3333, + "telnetport": 4444, + "tclport": 6666, + "host": "localhost", + "port": 3333, + "skipDownloadBeforeDebug": false, + "enablePageEraser": false, + "enableNoZeroWaitingAreaFlash": false + }, + "gdbCfg": { + "executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/Toolchain/RISC-V Embedded GCC12/bin/riscv-wch-elf-gdb.exe", + "commands": [ + "set mem inaccessible-by-default off", + "set architecture riscv:rv32", + "set remotetimeout unlimited", + "set disassembler-options xw" + ], + "options": [] + }, + "startup": { + "initCommands": { + "initReset": true, + "initResetType": "init", + "armSemihosting": false, + "additionalCommands": [] + }, + "loadedFiles": { + "executableFile": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307\\obj\\ble_bjq_ch303rct6_ml307.elf", + "symbolFile": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307\\obj\\ble_bjq_ch303rct6_ml307.elf", + "executableFileOffset": 0, + "symbolFileOffset": 0 + }, + "runCommands": { + "runReset": true, + "runResetType": "halt", + "additionalCommands": [], + "setBreakAt": "handle_reset", + "continue": true, + "setProgramCounterAt": 0 + }, + "debugInRAM": false + }, + "svdpath": "c:\\MounRiver\\MounRiver_Studio2\\resources\\app\\resources\\win32\\components\\WCH\\SDK\\default/RISC-V/CH32V307/NoneOS/CH32V307xx.svd", + "output": { + "showDebugGDBTrace": true, + "saveDebugOutputToFile": false, + "showDebugOutputTimestamps": true + } + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 56f348f..4a46191 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,6 +18,8 @@ } ], "files.associations": { + "*.ndjson": "jsonl", + "*.dbclient-js": "javascript", "rtthread.h": "c", "user_sys.h": "c", "bsp_led.h": "c", @@ -57,6 +59,7 @@ "string.h": "c", "completion.h": "c", "bsp_bt.h": "c", - "bsp_ml307.h": "c" + "bsp_ml307.h": "c", + "bsp_vin_detection.h": "c" } } diff --git a/applications/main.c b/applications/main.c index ec06d4a..cf0567d 100644 --- a/applications/main.c +++ b/applications/main.c @@ -92,8 +92,15 @@ void Send_Laser_Alarm_Event(AlarmEvent event_type) if (is_event_initialized == RT_TRUE) { - rt_event_send(&alarm_event, Get_Sys_Event_Flag(event_type)); - LOG_D("Send_Laser_Alarm_Event = %d", SysControl.status); + if (SysControl.status == kPowerDownEvent) + { + LOG_D("掉电模式下不处理其他事件"); + } + else + { + LOG_I("Send_Laser_Alarm_Event = %d", event_type); + rt_event_send(&alarm_event, Get_Sys_Event_Flag(event_type)); + } } else { @@ -102,6 +109,7 @@ void Send_Laser_Alarm_Event(AlarmEvent event_type) } } + int _Self_Check_Mode(void) { LED_STOP(r); @@ -150,7 +158,6 @@ int main(void) { // 定义超时时间,单位为毫秒 #define TIMEOUT_MS 3 * 60 * 1000 -// #define TIMEOUT_MS 8 * 1000 #define WORK_TIMER_CNT (1000 * 60 * 60) rt_err_t result = RT_EINVAL; rt_uint32_t received_event; @@ -345,7 +352,6 @@ int main(void) Flash_Write_Record(kRecordAlarm); // 写入flash报警信息 if (Flash_Get_Valve_Num()) { - // Bt_Valve_Handler(kValveCmdCtr, 0, RT_NULL); rt_uint8_t mac_addr[6]; Flash_Get_Mac_Addr(mac_addr, 1); Bt_Valve_Handler(kValveCmdCtr, 1, mac_addr); diff --git a/applications/user_sys.c b/applications/user_sys.c index 3ab8263..21aff66 100644 --- a/applications/user_sys.c +++ b/applications/user_sys.c @@ -30,9 +30,7 @@ #include "bsp_rng.h" - - -volatile rt_uint16_t work_duration = 1; // 工作时长 +volatile rt_uint16_t work_duration = 0; // 工作时长,单位:小时 volatile rt_uint8_t device_life_check = 0; volatile rt_uint8_t device_state_flag = 0; // 设备失效标志 diff --git a/bsp/inc/bsp_flash.h b/bsp/inc/bsp_flash.h index a43f2fa..d16eaaa 100644 --- a/bsp/inc/bsp_flash.h +++ b/bsp/inc/bsp_flash.h @@ -116,9 +116,9 @@ #define FLASH_IOT_ICCID_ADDR (FLASH_IOT_IMSI_ADDR + FLASH_IOT_IMSI_LEN) #define FLASH_IOT_ICCID_LEN (20) -/*工作时长记录*/ +/*工作时长记录 5* 365 * 24 = 43800 < 65535*/ #define FLASH_WORK_TIME_ADDR (FLASH_IOT_ICCID_ADDR + FLASH_IOT_ICCID_LEN) -#define FLASH_WORK_TIME_LEN (2)//单位:天 +#define FLASH_WORK_TIME_LEN (2)//单位:hours /*正式平台服务器地址*/ #define FLASH_SERVER_ADDR_ADDR (FLASH_WORK_TIME_ADDR + FLASH_WORK_TIME_LEN) diff --git a/bsp/inc/bsp_rtc.h b/bsp/inc/bsp_rtc.h index 949f996..79ce637 100644 --- a/bsp/inc/bsp_rtc.h +++ b/bsp/inc/bsp_rtc.h @@ -20,7 +20,7 @@ typedef struct __attribute__((packed)) { uint16_t year; // 年份设置,取值范围为 uint8_t month; // 日期设置,取值范围为1~31 - uint8_t day; // 月份设置,取值范围为1~12 + uint16_t day; // 月份设置,取值范围为1~12 uint8_t hour; /* 小时设置 */ uint8_t minute; /* 分钟设置 */ diff --git a/bsp/src/at_device_ml307.c b/bsp/src/at_device_ml307.c index 788fa86..8275061 100644 --- a/bsp/src/at_device_ml307.c +++ b/bsp/src/at_device_ml307.c @@ -1,12 +1,12 @@ /* - * @Author : stark1898y 1658608470@qq.com - * @Date : 2024-09-04 13:33:49 + * @Author: mbw + * @Date: 2024-11-30 15:46:21 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2025-01-05 13:03:00 + * @LastEditTime: 2025-01-09 14:18:04 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\at_device_ml307.c - * @Description : - * - * Copyright (c) 2024 by yzy, All Rights Reserved. + * @Description: + * + * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. */ /* * Copyright (c) 2006-2023, RT-Thread Development Team @@ -1094,7 +1094,28 @@ static void ml307_init_thread_entry(void *parameter) goto __exit; } #endif - + if (at_obj_exec_cmd(device->client, resp, "AT+CCLK?") == RT_EOK) + { + TsRtcDateTime rtc_dt; + int year, mounth, days, hous, min, sec; + /*+CCLK:24/11/12,06:08:19+32*/ + if (at_resp_parse_line_args_by_kw(resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d+32\"", &year, &mounth, &days, &hous, &min, &sec) > 0) + { + rtc_dt.year = (2000 + year); + rtc_dt.month = mounth; + rtc_dt.day = days; + rtc_dt.hour = hous; // 此时为零区时间,需要转化为东八区 + rtc_dt.minute = min; + rtc_dt.second = sec; + Time_Zone_Conversion(&rtc_dt); // 时区设置 + rtc_dt.week = RTC_GetWeek(rtc_dt.year, rtc_dt.month, rtc_dt.day); + RTC_SetTime(rtc_dt.year, rtc_dt.month, rtc_dt.day, + rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间 + LOG_I("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n", + rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second); + result = RT_EOK; + } + } /* initialize successfully */ result = RT_EOK; break; diff --git a/bsp/src/bsp_button.c b/bsp/src/bsp_button.c index f81a73c..1cb331c 100644 --- a/bsp/src/bsp_button.c +++ b/bsp/src/bsp_button.c @@ -50,7 +50,7 @@ static uint8_t _CommonBtnRead(void *arg) static void _CommonBtnEvtCb(void *arg) { - static rt_uint8_t button_cnt = 0; + // static rt_uint8_t button_cnt = 0; if (flex_button_event_read(&user_button[USER_BUTTON_1]) == FLEX_BTN_PRESS_CLICK) { diff --git a/bsp/src/bsp_flash.c b/bsp/src/bsp_flash.c index db01b88..7420aad 100644 --- a/bsp/src/bsp_flash.c +++ b/bsp/src/bsp_flash.c @@ -275,8 +275,7 @@ int Flash_Set_WorkDuration(rt_uint16_t value) rt_uint8_t in_page_offset = (FLASH_WORK_TIME_ADDR - FLASH_CONFIG_INFO_START_ADDR); Flash_ErasePage_ReadConfigInfo(page_buf); - - *(rt_uint16_t *)(page_buf + in_page_offset) = value; + rt_memcpy(page_buf + in_page_offset, &value, FLASH_WORK_TIME_LEN); return Flash_Write_ConfigInfo(page_buf); } @@ -284,12 +283,6 @@ int Flash_Get_Sever_Addr_Info(flash_sever_info *sever_info) { rt_uint8_t data[FLASH_SERVER_LEN]; rt_memcpy(data, (rt_uint8_t *)FLASH_SERVER_ADDR_ADDR, FLASH_SERVER_LEN); - if (data == RT_NULL) - { - LOG_E("Flash_Get_Sever_Addr_Info failed"); - - return -RT_ERROR; - } LOG_D("FLASH_SERVER_ADDR_ADDR = %X", FLASH_SERVER_ADDR_ADDR); 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(sever_info->server_url, sizeof(sever_info->server_url), "%d.%d.%d.%d", @@ -655,8 +648,9 @@ void Flash_ErasePage_ConfigInfo(void) void Flash_ErasePage_ReadConfigInfo(rt_uint8_t *page_buf) { Flash_Read(FLASH_CONFIG_INFO_START_ADDR, page_buf, FLASH_PAGE_SIZE); - + rt_thread_mdelay(10); Flash_ErasePage_ConfigInfo(); + rt_thread_mdelay(10); } int Flash_Write_ConfigInfo(rt_uint8_t *page_buf) @@ -908,7 +902,7 @@ int BSP_Flash_Init(void) sci.emagnetic_switch = sys_emagnetic_switch; sci.relay_switch = sys_relay_switch; - Flash_Set_WorkDuration(work_duration); + Flash_Set_WorkDuration(0);//第一次下载工作时长为0 LOG_D("work_duration:%d", Flash_Get_WorkDuration()); Convert_To_Hex(&sever_info, sever_data); @@ -921,7 +915,7 @@ int BSP_Flash_Init(void) { LOG_D("Flash_Set_Sever_Addr_Info error!"); } - Flash_Set_Calibration_State(kSysGasCalibStatus); // 未标定状态 + Flash_Set_Calibration_State(kSysGasCalibStatus); // 标定状态 Flash_Set_Valve_Num(0); Flash_Write(FLASH_HW_VER_ADDR, (rt_uint8_t *)&sci, (sizeof(sys_config_info) - 50)); diff --git a/bsp/src/bsp_ml307.c b/bsp/src/bsp_ml307.c index 36de704..0a7d7a0 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-01-05 13:29:29 + * @LastEditTime: 2025-01-08 16:36:27 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_ml307.c * @Description: * @@ -1685,6 +1685,7 @@ static void Ml307_Life_Thread_Entry(void *parameter) device->class->device_ops->control(device, AT_DEVICE_CTRL_RESET, RT_NULL); // 先关闭,再处理 if(ml307_disconnect_pdp_flag) { + ml307_disconnect_pdp_flag = 0; at_response_t resp = at_create_resp(32, 0, 5000); if (resp == RT_NULL) {