From 40c054d4911e9d7fb53ddbab9597c01620eb75f1 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, 9 May 2025 16:48:19 +0800 Subject: [PATCH] =?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/user_sys.h | 3 +++ bsp/inc/bsp_flash.h | 2 +- bsp/inc/bsp_ml307.h | 4 +++- bsp/src/.vscode/settings.json | 20 ++++++++++++++++++++ bsp/src/at_device_ml307.c | 9 +++++---- bsp/src/bsp_bt.c | 8 ++++++++ bsp/src/bsp_flash.c | 3 ++- bsp/src/bsp_ml307.c | 18 ++---------------- 8 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 bsp/src/.vscode/settings.json diff --git a/applications/user_sys.h b/applications/user_sys.h index 6af50a2..babd9aa 100644 --- a/applications/user_sys.h +++ b/applications/user_sys.h @@ -28,9 +28,12 @@ #define SYS_RELAY_SWITCH (0X04U) #define SYS_ALARM_VALVE_MAX (0X30U) + +// 正式平台链接 #define SYS_IOT_URL ("8.130.122.162") #define SYS_IOT_PORT ("7153") +//测试平台链接 // #define SYS_IOT_URL ("8.130.105.38") // #define SYS_IOT_PORT ("7133") diff --git a/bsp/inc/bsp_flash.h b/bsp/inc/bsp_flash.h index 7ef5fdc..d1828e5 100644 --- a/bsp/inc/bsp_flash.h +++ b/bsp/inc/bsp_flash.h @@ -267,7 +267,7 @@ typedef struct __attribute__((packed)) rt_uint8_t iot_imei[15]; // IMEI rt_uint8_t iot_imsi[15]; // IMSI rt_uint8_t iot_iccid[20]; // ICCID -} sys_config_info; +}sys_config_info; typedef struct { diff --git a/bsp/inc/bsp_ml307.h b/bsp/inc/bsp_ml307.h index 8b20d6b..aa6ec71 100644 --- a/bsp/inc/bsp_ml307.h +++ b/bsp/inc/bsp_ml307.h @@ -34,7 +34,7 @@ #define CMD_TYPE_INSTRUCTION_REPLY 0x14 // 命令类型 - 指令下发回复 (设备->平台) #define CMD_TYPE_TIME_CALIBRATION 0x15 // 命令类型 - 时间校准 (设备->平台) -#define PROTOCOL_VERSION 0x41 /*协议版本*/ +#define PROTOCOL_VERSION 0x11 /*协议版本*/ /*数据序列号*/ #define DATA_SERIAL_NUM 0x0001 // 1 @@ -80,6 +80,8 @@ #define INSTRUCTION_DOWN_VALVE_ADD 0x61 // 新增阀门设备 #define INSTRUCTION_DOWN_VALVE_REPLACE 0x62 // 更换阀门设备 #define INSTRUCTION_DOWN_VALVE_REMOVE 0x63 // 移除阀门设备 + + /************************************************************************************************************/ #define RESPONSE_CODE_SUCCESS 0x00 // 响应码 - 操作成功 #define RESPONSE_CODE_CRC_FAIL 0x01 // 响应码 - CRC 校验失败 diff --git a/bsp/src/.vscode/settings.json b/bsp/src/.vscode/settings.json new file mode 100644 index 0000000..0ce7a27 --- /dev/null +++ b/bsp/src/.vscode/settings.json @@ -0,0 +1,20 @@ +{ + "MicroPython.executeButton": [ + { + "text": "▶", + "tooltip": "运行", + "alignment": "left", + "command": "extension.executeFile", + "priority": 3.5 + } + ], + "MicroPython.syncButton": [ + { + "text": "$(sync)", + "tooltip": "同步", + "alignment": "left", + "command": "extension.execute", + "priority": 4 + } + ] +} \ No newline at end of file diff --git a/bsp/src/at_device_ml307.c b/bsp/src/at_device_ml307.c index 476ad51..2ff83e8 100644 --- a/bsp/src/at_device_ml307.c +++ b/bsp/src/at_device_ml307.c @@ -18,7 +18,7 @@ * 2019-12-13 qiyongzhong first version */ -#include +// #include #include #include "bsp_flash.h" #include @@ -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) { - if (id == socket_id) + socket_id = id; { switch (err_code) { @@ -217,6 +217,7 @@ static void urc_tcp_disconnect(struct at_client *client, const char *data, rt_si if (sscanf(data, "+MIPURC: \"disconn\",%d,%d", &id, &state) == 2) { + socket_id = id; if (id == socket_id) { ml307_conncet_tcp_flag = 0; @@ -890,11 +891,11 @@ static void ml307_init_thread_entry(void *parameter) while (1) { /* power on the ml307 device */ - rt_thread_mdelay(1000); + // rt_thread_mdelay(1000); ml307_power_on(device); LOG_D("power on %s device.", device->name); - rt_thread_mdelay(2000); + // rt_thread_mdelay(2000); /* wait ml307 startup finish, send AT every 500ms, if receive OK, SYNC success*/ if (at_client_obj_wait_connect(client, ML307_WAIT_CONNECT_TIME)) { diff --git a/bsp/src/bsp_bt.c b/bsp/src/bsp_bt.c index 1d05fba..44781e3 100644 --- a/bsp/src/bsp_bt.c +++ b/bsp/src/bsp_bt.c @@ -380,11 +380,19 @@ int BSP_Bt_Process(uint8_t *data, uint16_t len) if(valve[data_buf[3] - 1].valve_connct_status == 1) { LOG_D("阀门连接"); + while (!power_on_send_flag)//等待4G模块联网完成 + { + rt_thread_mdelay(100); + } Ml307_Send_Event(kMl307ValveConnectEvent); } else { LOG_D("阀门断开"); + while (!power_on_send_flag) + { + rt_thread_mdelay(100); + } Ml307_Send_Event(KMl307ValveDisconnectEvent); } break; diff --git a/bsp/src/bsp_flash.c b/bsp/src/bsp_flash.c index c53159e..a8e6f2c 100644 --- a/bsp/src/bsp_flash.c +++ b/bsp/src/bsp_flash.c @@ -1,4 +1,4 @@ -#include "bsp_flash.h" + #include "lwutil.h" #include "bsp_rtc.h" #include "bsp_hr.h" @@ -6,6 +6,7 @@ #include #include #include "rtdef.h" +#include "bsp_flash.h" #define LOG_TAG "bsp_flash" #define LOG_LVL LOG_LVL_DBG diff --git a/bsp/src/bsp_ml307.c b/bsp/src/bsp_ml307.c index ad3455f..4e95fae 100644 --- a/bsp/src/bsp_ml307.c +++ b/bsp/src/bsp_ml307.c @@ -991,22 +991,8 @@ 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_SELF_CHECK) || - (ops->recv->recv_data.event_type == EVENT_TYPE_SILENCE) || - (ops->recv->recv_data.event_type == EVENT_TYPE_EXCEPTION) || - (ops->recv->recv_data.event_type == EVENT_TYPE_VALVE_STATUS) || - (ops->recv->recv_data.event_type == EVENT_TYPE_FAN_STATUS) || - (ops->recv->recv_data.event_type == EVENT_TYPE_TEMP_ANOMALY) || - (ops->recv->recv_data.event_type == EVENT_TYPE_POWER_ON) || - (ops->recv->recv_data.event_type == EVENT_TYPE_POWER_OFF) || - (ops->recv->recv_data.event_type == EVENT_TYPE_ALARM) || - (ops->recv->recv_data.event_type == EVENT_TYPE_ALARM_RECOVER) || - (ops->recv->recv_data.event_type == EVENT_TYPE_FAULT) || - (ops->recv->recv_data.event_type == EVENT_TYPE_FAULT_RECOVER) || - (ops->recv->recv_data.event_type == EVENT_TYPE_DEVICE_FAILURE) || - (ops->recv->recv_data.event_type == EVENT_TYPE_VALVE_CONNECT) || - (ops->recv->recv_data.event_type == EVENT_TYPE_VALVE_DISCONNECT)) + if ((ops->recv->recv_data.event_type >= EVENT_TYPE_HEARTBEAT) && + (ops->recv->recv_data.event_type <= INSTRUCTION_DOWN_VALVE_REMOVE)) { LOG_D("服务器响应成功,响应码:[%02X]\n", ops->recv->recv_data.event_type); rt_sem_release(ml307_recv_msg_sem);