From e461c0dca01b5ae5ce6f70d12001547e9e72e64e Mon Sep 17 00:00:00 2001 From: tpu Date: Sun, 20 Jul 2025 18:00:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=9E=E7=8E=B0OTA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.txt | 2 +- src/config/user_config.h | 4 +- src/custom_profile/user_custs1_def.h | 2 +- src/epd/epd.h | 1 + src/user_custs1_impl.c | 9 +- src/user_peripheral.c | 17 +++- src/user_peripheral.h | 1 + weble/weble.html | 131 +++++++++++++++++++++++++++ 8 files changed, 159 insertions(+), 8 deletions(-) diff --git a/Readme.txt b/Readme.txt index a61cadb..20bb9b3 100644 --- a/Readme.txt +++ b/Readme.txt @@ -7,7 +7,7 @@ 显示农历与节气和节假日 显示电池电量 蓝牙对时 - 蓝牙OTA(尚未实现) + 蓝牙OTA 编译与烧写 diff --git a/src/config/user_config.h b/src/config/user_config.h index 3c5e950..69d6e13 100644 --- a/src/config/user_config.h +++ b/src/config/user_config.h @@ -55,7 +55,7 @@ **************************************************************************************** */ -#define EPD_VERSION 0xA50f0004 +#define EPD_VERSION 0xA50f0005 /* @@ -231,7 +231,7 @@ static const struct gapm_configuration user_gapm_conf = { /// Maximal MTU. Shall be set to 23 if Legacy Pairing is used, 65 if Secure Connection is used, /// more if required by the application - .max_mtu = 23, + .max_mtu = 192, /// Device Address Type .addr_type = APP_CFG_ADDR_TYPE(USER_CFG_ADDRESS_MODE), diff --git a/src/custom_profile/user_custs1_def.h b/src/custom_profile/user_custs1_def.h index 4d17547..46d79d6 100644 --- a/src/custom_profile/user_custs1_def.h +++ b/src/custom_profile/user_custs1_def.h @@ -59,7 +59,7 @@ // Service 1 of the custom server 1 #define DEF_SVC1_CTRL_POINT_CHAR_LEN 1 #define DEF_SVC1_ADC_VAL_1_CHAR_LEN 2 -#define DEF_SVC1_LONG_VALUE_CHAR_LEN 48 +#define DEF_SVC1_LONG_VALUE_CHAR_LEN 160 /// Custom1 Service Data Base Characteristic enum diff --git a/src/epd/epd.h b/src/epd/epd.h index b068c9e..159d0f9 100644 --- a/src/epd/epd.h +++ b/src/epd/epd.h @@ -26,6 +26,7 @@ int sf_sector_erase(int cmd, int addr, int wait); int sf_page_write(int addr, u8 *buf, int size); int sf_read(int addr, int len, u8 *buf); int selflash(int otp_boot); +int ota_handle(u8 *buf); // epd_hw void epd_hw_init(u32 config0, u32 config1, int w, int h, int mode); diff --git a/src/user_custs1_impl.c b/src/user_custs1_impl.c index c6137c1..938506d 100644 --- a/src/user_custs1_impl.c +++ b/src/user_custs1_impl.c @@ -514,6 +514,10 @@ void clock_draw(int flags) { char tbuf[64]; + if(ota_state){ + return; + } + epd_hw_open(); epd_update_mode(flags&3); @@ -571,14 +575,17 @@ void user_svc1_ctrl_wr_ind_handler(ke_msg_id_t const msgid, struct custs1_val_wr void user_svc1_long_val_wr_ind_handler(ke_msg_id_t const msgid, struct custs1_val_write_ind const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { - printk("Long value: %d\n", param->length); + //printk("Long value: %d\n", param->length); if(param->value[0]==0x91){ clock_set((uint8_t*)param->value); clock_draw(DRAW_BT|UPDATE_FAST); clock_print(); + }else if(param->value[0]>=0xa0){ + ota_handle((u8*)param->value); } } + void user_svc1_long_val_att_info_req_handler(ke_msg_id_t const msgid, struct custs1_att_info_req const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { struct custs1_att_info_rsp *rsp = KE_MSG_ALLOC(CUSTS1_ATT_INFO_RSP, src_id, dest_id, custs1_att_info_rsp); diff --git a/src/user_peripheral.c b/src/user_peripheral.c index 9c7bc11..d7957f7 100644 --- a/src/user_peripheral.c +++ b/src/user_peripheral.c @@ -77,6 +77,8 @@ static char adv_name[20]; char *bt_id = adv_name+12; int clock_interval; +const volatile u32 epd_version[3] = {0xF9A51379, ~0xF9A51379, EPD_VERSION}; + /* * FUNCTION DEFINITIONS @@ -173,7 +175,7 @@ void user_app_init(void) { read_otp_value(); - printk("\n\nuser_app_init! %s\n", __TIME__); + printk("\n\nuser_app_init! %s %08x\n", __TIME__, epd_version[2]); app_param_update_request_timer_used = EASY_TIMER_INVALID_TIMER; app_clock_timer_used = EASY_TIMER_INVALID_TIMER; @@ -240,6 +242,8 @@ void user_app_on_db_init_complete( void ) void user_app_adv_start(void) { + u8 vbuf[4]; + if(adv_state) return; adv_state = 1; @@ -247,6 +251,13 @@ void user_app_adv_start(void) struct gapm_start_advertise_cmd* cmd = app_easy_gap_undirected_advertise_get_active(); app_add_ad_struct(cmd, adv_name, adv_name[0]+1, 1); + vbuf[0] = 0x03; + vbuf[1] = GAP_AD_TYPE_MANU_SPECIFIC_DATA; + vbuf[2] = EPD_VERSION&0xff; + vbuf[3] = (EPD_VERSION>>8)&0xff; + app_add_ad_struct(cmd, vbuf, vbuf[0]+1, 1); + + //default_advertise_operation(); //app_easy_gap_undirected_advertise_start(); app_easy_gap_undirected_advertise_with_timeout_start(user_default_hnd_conf.advertise_period, NULL); @@ -327,7 +338,7 @@ void user_catch_rest_hndl(ke_msg_id_t const msgid, case CUSTS1_VAL_WRITE_IND: { /* 写特征值通知. 值已经写入Database中了. */ - printk("CUSTS1_VAL_WRITE_IND!\n"); + //printk("CUSTS1_VAL_WRITE_IND!\n"); struct custs1_val_write_ind const *msg_param = (struct custs1_val_write_ind const *)(param); switch (msg_param->handle) @@ -358,7 +369,7 @@ void user_catch_rest_hndl(ke_msg_id_t const msgid, case CUSTS1_ATT_INFO_REQ: { /* 读ATT_INFO请求. 需要返回数据. */ - printk("CUSTS1_ATT_INFO_REQ!\n"); + //printk("CUSTS1_ATT_INFO_REQ!\n"); struct custs1_att_info_req const *msg_param = (struct custs1_att_info_req const *)param; switch (msg_param->att_idx) diff --git a/src/user_peripheral.h b/src/user_peripheral.h index dec69d7..9e2e95c 100644 --- a/src/user_peripheral.h +++ b/src/user_peripheral.h @@ -86,6 +86,7 @@ */ extern char *bt_id; +extern int ota_state; /* diff --git a/weble/weble.html b/weble/weble.html index 063414b..377ae75 100644 --- a/weble/weble.html +++ b/weble/weble.html @@ -13,8 +13,10 @@
+
+