1.优化温度广播 2.添加OTA升级支持
This commit is contained in:
parent
ccd1b683bf
commit
4810e153e1
@ -21,6 +21,10 @@
|
||||
//#include "ble_trans_profile.h"
|
||||
static int led_state = 0;
|
||||
static u16 temer_temperature_detect = 0;
|
||||
|
||||
//struct app_dev_info_t dev_info;
|
||||
//struct app_dev_config_t dev_config;
|
||||
app_dev_config_t dev_config;
|
||||
void temperature_blink_led()
|
||||
{
|
||||
if (led_state)
|
||||
@ -324,7 +328,38 @@ static uint8_t reversal(uint8_t data)
|
||||
//printf("Temp %3.7f\r\n", dtmp);
|
||||
|
||||
printf("Temp: %d\r\n\r\n", temp_value);
|
||||
gpio_direction_output(IO_PORTB_05, 0);
|
||||
|
||||
|
||||
//FF
|
||||
|
||||
//先查明当前连接的conn_handle
|
||||
u16 connection_handle = ble_comm_dev_get_handle(0, GATT_ROLE_SERVER);
|
||||
if(connection_handle != 0)//
|
||||
{
|
||||
printf("ble connected !! connection_handle: %04x\n", connection_handle);
|
||||
return ;
|
||||
}else{
|
||||
//printf("connection_handle: %04x\n", connection_handle);
|
||||
}
|
||||
//BBOOEEb 2字节体温 2字节物温 2字节环温 1字节电量
|
||||
u16 body = (u16)temp_value;
|
||||
u16 obj = (u16)temp_value;
|
||||
u16 ntc = (u16)0;
|
||||
u8 battery = 99;
|
||||
u8 ff_temp_data[7] = {0};
|
||||
//body
|
||||
ff_temp_data[0] = (body >> 8) & 0xFF;
|
||||
ff_temp_data[1] = (body) & 0xFF;
|
||||
//obj
|
||||
ff_temp_data[2] = (obj >> 8) & 0xFF;
|
||||
ff_temp_data[3] = (obj) & 0xFF;
|
||||
//env
|
||||
ff_temp_data[4] = (ntc >> 8) & 0xFF;
|
||||
ff_temp_data[5] = (ntc) & 0xFF;
|
||||
//batt
|
||||
ff_temp_data[6] = battery & 0xFF;
|
||||
trans_client_adv_data_set_ff(ff_temp_data,sizeof(ff_temp_data));
|
||||
gpio_direction_output(IO_PORTB_05, 0);
|
||||
}
|
||||
void temperature_detect(void)
|
||||
{
|
||||
@ -334,12 +369,12 @@ void temperature_detect(void)
|
||||
#endif
|
||||
|
||||
u16 charge_led_hander = 0;
|
||||
void temperature_charge_led(u8 on){
|
||||
void temperature_charge_lowpower(u8 on){
|
||||
if(charge_led_hander){
|
||||
sys_timer_del(charge_led_hander);
|
||||
}
|
||||
if(on){
|
||||
charge_led_hander = sys_timer_add(NULL, temperature_blink_led, 500);
|
||||
charge_led_hander = sys_timer_add(NULL, temperature_blink_led, 1000);
|
||||
}else{
|
||||
sys_timer_del(charge_led_hander);
|
||||
}
|
||||
@ -383,6 +418,8 @@ void temperature_charge_state(int state){
|
||||
//接入充电
|
||||
case BLE_TEMPERATURE_CHARGE_STATE_CHARGING :
|
||||
printf("BLE_TEMPERATURE_CHARGE_STATE_CHARGING\n");
|
||||
//关闭低电提示LED
|
||||
temperature_charge_lowpower(0);
|
||||
sys_timer_del(temer_temperature_detect);
|
||||
//体温计指标灯闪烁3次后转灭
|
||||
for(int i = 0; i< 3 ; i++){
|
||||
@ -399,18 +436,20 @@ void temperature_charge_state(int state){
|
||||
//充电完成
|
||||
case BLE_TEMPERATURE_CHARGE_STATE_FULL :
|
||||
//printf("BLE_TEMPERATURE_CHARGE_STATE_FULL\n");
|
||||
//spple_power_event_to_user(POWER_EVENT_POWER_SOFTOFF);
|
||||
//printf("!!!!!!!!!!!!!! POWER OFF!!!!!!!!!!!!!!!!\n");
|
||||
temperature_set_soft_poweroff();
|
||||
break;
|
||||
//拔出充电
|
||||
case BLE_TEMPERATURE_CHARGE_STATE_IDLE :
|
||||
printf("BLE_TEMPERATURE_CHARGE_STATE_IDLE\n");
|
||||
temer_temperature_detect = sys_timer_add(NULL, temperature_detect, 300);
|
||||
temperature_charge_led(0);
|
||||
temer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval);
|
||||
//temperature_charge_led(0);
|
||||
temperature_work_led(1);
|
||||
sys_s_hi_timerout_add(NULL,temperature_poweron_led_timeout,2000);
|
||||
break;
|
||||
//低电
|
||||
case BLE_TEMPERATURE_CHARGE_STATE_LOWPOWER:
|
||||
temperature_charge_lowpower(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -433,20 +472,48 @@ void temperature_ble_init(){
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* 初始化测温相关的参数
|
||||
*/
|
||||
void temperature_config_init(){
|
||||
//int syscfg_read(u16 item_id, void *buf, u16 len);
|
||||
//int syscfg_write(u16 item_id, void *buf, u16 len);
|
||||
|
||||
int ret = syscfg_read(BLE_TEMPERATURE_VM_DEVICE_CONFIG, &dev_config, sizeof(app_dev_config_t));
|
||||
if (ret != sizeof(app_dev_config_t)) {
|
||||
printf("temperature_config_init err:%d", ret);
|
||||
|
||||
dev_config.detect_interval = 500;
|
||||
dev_config.temperature_offset = 0;
|
||||
syscfg_write(BLE_TEMPERATURE_VM_DEVICE_CONFIG, &dev_config, sizeof(app_dev_config_t));
|
||||
}
|
||||
//test
|
||||
dev_config.detect_interval = 0;
|
||||
dev_config.temperature_offset = 0;
|
||||
ret = syscfg_read(BLE_TEMPERATURE_VM_DEVICE_CONFIG, &dev_config, sizeof(app_dev_config_t));
|
||||
if (ret != sizeof(app_dev_config_t)) {
|
||||
printf("temperature_config_init err:%d", ret);
|
||||
}else{
|
||||
printf("detect_interval :%d", dev_config.detect_interval);
|
||||
printf("temperature_offset :%d", dev_config.temperature_offset);
|
||||
}
|
||||
dev_config.detect_interval = 2000;
|
||||
|
||||
}
|
||||
|
||||
void temperature_init(void)
|
||||
{
|
||||
printf(">>>>>>>>>>>>>>>>> temperature_init ...\n");
|
||||
delay_us(60);
|
||||
printf(">>>>>>>>>>>>>>>>> temperature_init2 ...\n");
|
||||
printf(">>>>>>>>>>>>>>>>> temperature_OTA ...\n");
|
||||
|
||||
extern u16 get_vbat_trim();
|
||||
extern u16 get_vbg_trim();
|
||||
printf("vbat_trim:%d...vbg_trim:%d", get_vbat_trim(), get_vbg_trim());
|
||||
// 添加以上代码,看打印值,如果为15跟63,那就要用烧录器先烧录一遍。
|
||||
|
||||
temperature_config_init();
|
||||
|
||||
//从收纳仓取出时自动开机(指示灯亮2S后灭)
|
||||
temperature_work_led(1);
|
||||
sys_s_hi_timerout_add(NULL,temperature_poweron_led_timeout,2000);
|
||||
@ -454,7 +521,7 @@ void temperature_init(void)
|
||||
//sys_s_hi_timer_add(NULL, temperature_blink_led, 200);
|
||||
//sys_s_hi_timer_add(NULL, temperature_detect, 2000);
|
||||
//sys_timer_add 方式添加定时任务 任务里边可以使用udelay delay_ms 等延时 sys_s_hi_timer_add 则延时无效
|
||||
temer_temperature_detect = sys_timer_add(NULL, temperature_detect, 300);
|
||||
temer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval);
|
||||
|
||||
|
||||
// NTC VDD
|
||||
|
@ -9,7 +9,7 @@
|
||||
/* Following Macros Affect Periods Of Both Code Compiling And Post-build */
|
||||
|
||||
#define CONFIG_DOUBLE_BANK_ENABLE 0 //单双备份选择(若打开了改宏,FLASH结构变为双备份结构,适用于接入第三方协议的OTA, PS: JL-OTA同样支持双备份升级, 需要根据实际FLASH大小同时配置CONFIG_FLASH_SIZE)
|
||||
#define CONFIG_APP_OTA_ENABLE 0 //是否支持RCSP升级(JL-OTA)
|
||||
#define CONFIG_APP_OTA_ENABLE 1 //是否支持RCSP升级(JL-OTA)
|
||||
|
||||
#define CONFIG_UPDATE_JUMP_TO_MASK 0 //配置升级到loader的方式0为直接reset,1为跳转(适用于芯片电源由IO口KEEP住的方案,需要注意检查跳转前是否将使用DMA的硬件模块全部关闭)
|
||||
|
||||
|
@ -706,6 +706,11 @@ static int trans_make_set_adv_data(void)
|
||||
adv_name_ok = 0;
|
||||
}
|
||||
|
||||
log_info("trans_adv_data @@ (%d):", offset);
|
||||
//FF
|
||||
//BBOOEEb 2字节体温 2字节物温 2字节环温 1字节电量
|
||||
u8 ff_temp_data[7] = {0};
|
||||
offset += make_eir_packet_data(&buf[offset], offset, HCI_EIR_DATATYPE_MANUFACTURER_SPECIFIC_DATA, (void *)ff_temp_data, sizeof(ff_temp_data));
|
||||
if (offset > ADV_RSP_PACKET_MAX) {
|
||||
puts("***trans_adv_data overflow!!!!!!\n");
|
||||
return -1;
|
||||
@ -717,6 +722,55 @@ static int trans_make_set_adv_data(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int trans_client_adv_data_set_ff(u8*data, int len)
|
||||
{
|
||||
//putchar('L');
|
||||
//put_u8hex(adv_cnt);
|
||||
//ble_module_enable(0);
|
||||
ble_op_adv_enable(0);
|
||||
u8 offset = 0;
|
||||
u8 *buf = trans_adv_data;
|
||||
|
||||
#if DOUBLE_BT_SAME_MAC
|
||||
offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_FLAGS, FLAGS_GENERAL_DISCOVERABLE_MODE | FLAGS_LE_AND_EDR_SAME_CONTROLLER, 1);
|
||||
#else
|
||||
offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_FLAGS, FLAGS_GENERAL_DISCOVERABLE_MODE | FLAGS_EDR_NOT_SUPPORTED, 1);
|
||||
#endif
|
||||
|
||||
offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_COMPLETE_16BIT_SERVICE_UUIDS, 0xAF30, 2);
|
||||
|
||||
char *gap_name = ble_comm_get_gap_name();
|
||||
u8 name_len = strlen(gap_name);
|
||||
u8 vaild_len = ADV_RSP_PACKET_MAX - (offset + 2);
|
||||
if (name_len < vaild_len) {
|
||||
offset += make_eir_packet_data(&buf[offset], offset, HCI_EIR_DATATYPE_COMPLETE_LOCAL_NAME, (void *)gap_name, name_len);
|
||||
adv_name_ok = 1;
|
||||
} else {
|
||||
adv_name_ok = 0;
|
||||
}
|
||||
//FF
|
||||
u8 ff_temp_data[5] = {0};
|
||||
offset += make_eir_packet_data(&buf[offset], offset, HCI_EIR_DATATYPE_MANUFACTURER_SPECIFIC_DATA, (void *)data, len);
|
||||
if (offset > ADV_RSP_PACKET_MAX) {
|
||||
puts("***trans_adv_data overflow!!!!!!\n");
|
||||
return -1;
|
||||
}
|
||||
log_info("trans_adv_data(%d):", offset);
|
||||
log_info_hexdump(buf, offset);
|
||||
trans_server_adv_config.adv_data_len = offset;
|
||||
trans_server_adv_config.adv_data = trans_adv_data;
|
||||
//adv_cnt++; // trans_make_set_adv_data()内引用此变量填充广播包
|
||||
//trans_make_set_adv_data();
|
||||
//FF offset 为18
|
||||
//memcpy(trans_server_adv_config.adv_data[18],data,len);
|
||||
//trans_server_adv_config.adv_data[18] =
|
||||
/* trans_make_set_rsp_data(); //看情况是否需要修改rsp包,一起调用即可*/
|
||||
//ble_module_enable(1);
|
||||
ble_op_set_adv_data(trans_server_adv_config.adv_data_len,trans_server_adv_config.adv_data);
|
||||
ble_op_adv_enable(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 组织rsp包数据,放入buff
|
||||
@ -734,8 +788,8 @@ static int trans_make_set_rsp_data(void)
|
||||
u8 *buf = trans_scan_rsp_data;
|
||||
|
||||
#if RCSP_BTMATE_EN
|
||||
u8 tag_len = sizeof(user_tag_string);
|
||||
offset += make_eir_packet_data(&buf[offset], offset, HCI_EIR_DATATYPE_MANUFACTURER_SPECIFIC_DATA, (void *)user_tag_string, tag_len);
|
||||
//u8 tag_len = sizeof(user_tag_string);
|
||||
//offset += make_eir_packet_data(&buf[offset], offset, HCI_EIR_DATATYPE_MANUFACTURER_SPECIFIC_DATA, (void *)user_tag_string, tag_len);
|
||||
#endif
|
||||
|
||||
if (!adv_name_ok) {
|
||||
|
@ -16,4 +16,5 @@ int trans_client_search_remote_stop(u16 conn_handle);
|
||||
|
||||
void trans_ios_services_init(void);
|
||||
void trans_ios_services_exit(void);
|
||||
int trans_client_adv_data_set_ff(u8*data, int len);
|
||||
#endif
|
||||
|
@ -18,8 +18,12 @@
|
||||
#define BLE_TEMPERATURE_CHARGE_STATE_CHARGING 1
|
||||
#define BLE_TEMPERATURE_CHARGE_STATE_FULL 2
|
||||
#define BLE_TEMPERATURE_CHARGE_STATE_IDLE 3
|
||||
#define BLE_TEMPERATURE_CHARGE_STATE_LOWPOWER 4
|
||||
|
||||
struct app_dev_info_t
|
||||
//VM用户自定义配置项[1 ~ 49]
|
||||
#define BLE_TEMPERATURE_VM_DEVICE_CONFIG 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u16 temperature_sensor;
|
||||
u32 temperature_ntc;
|
||||
@ -27,14 +31,18 @@ struct app_dev_info_t
|
||||
u16 batt_vat;
|
||||
u8 is_bat_charge;
|
||||
u8 is_bat_full;
|
||||
};
|
||||
}app_dev_info_t;
|
||||
|
||||
struct app_dev_config_t
|
||||
typedef struct
|
||||
{
|
||||
u8 detect_interval;
|
||||
};
|
||||
/* 测温检测间隔 ms 1000ms*/
|
||||
int16_t detect_interval;
|
||||
/* 温度校准 0.1C *1000 = 100 或者 -100*/
|
||||
int16_t temperature_offset;
|
||||
}app_dev_config_t;
|
||||
|
||||
extern struct app_dev_info_t dev_info;
|
||||
//extern struct app_dev_info_t dev_info;
|
||||
//extern struct app_dev_config_t dev_config;
|
||||
|
||||
void temperature_ble_init();
|
||||
void temperature_init(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user