From: penglei <1624952103@qq.com> Date: Sat, 30 Mar 2024 15:07:15 +0000 (+0800) Subject: 蓝牙产测 X-Git-Tag: release_V1.2.70_20241020_135402~1246 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=4600cc07a3c56c92224b4880c1c4b43f3b487b21;p=mirrors%2FFD230.git 蓝牙产测 --- diff --git a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c index 6bafd5345..3c6c55aed 100644 --- a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c +++ b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c @@ -6,6 +6,19 @@ #include "factorytestService.h" #include "wearable_log.h" #include "custom_utils.h" +#include "app_common_api.h" +#include "lcd_private.h" +#include "app_at_process.h" +#include "cywee_hal.h" +#include "hx3695.h" +#include "ppg_service.h" +#include "button_porting.h" +#include "cat1_ctl.h" +#include "cat1_server.h" +#include "hx3695_hrs_agc.h" +#include "hx3695_spo2_agc.h" +#include "hx3695_factory_test.h" +#include "power_display_service.h" #pragma pack(1) typedef struct factorytest_cmd_header_t @@ -18,6 +31,21 @@ typedef struct factorytest_cmd_header_t }factorytest_cmd_header_t; #pragma pack() +static osTimerId_t g_ble_vibrator_timer; + +static osTimerId_t g_ble_acc_timer; + +static osTimerId_t g_ble_hrs_timer; +static osTimerId_t g_ble_spo2_timer; +static osTimerId_t g_ble_graycard_timer; +static osTimerId_t g_ble_leaklight_timer; + +static uint8_t graycard_flag = 0; +static uint8_t leaklight_flag = 0; + +static uint16_t cycle_time_ms = 200; +static uint16_t duty = 20; + uint16_t modbus_crc16(uint8_t *data, uint16_t length) { uint8_t crc_hi = 0xFF; uint8_t crc_lo = 0xFF; @@ -43,12 +71,12 @@ errcode_t factorytest_protocol_replymsg(uint8_t mode, uint8_t submode,uint8_t te uint8_t * replybuf=NULL; errcode_t ret; - uint16_t total_len = input_len +1+2+1+1+1+2;//头+长度+mode+submod+testitem+crc + uint8_t total_len = input_len +1+2+1+1+1+2;//头+长度+mode+submod+testitem+crc replybuf = malloc(total_len); if(replybuf == NULL) return ERRCODE_MALLOC; factorytest_cmd_header_t *pcmdheader = (factorytest_cmd_header_t*)replybuf; pcmdheader->header = BLE_TEST_PROTOCOL_HEADER; - pcmdheader->len = total_len - 2 -1 - 2; //去掉头,长度,crc + pcmdheader->len = (total_len - 2 -1 - 2); //去掉头,长度,crc pcmdheader->mode = mode; pcmdheader->submod = submode; pcmdheader->testitem = testitem; @@ -57,13 +85,171 @@ errcode_t factorytest_protocol_replymsg(uint8_t mode, uint8_t submode,uint8_t te //计算除了crc外的所有数据 uint16_t crc16 = modbus_crc16(replybuf,total_len - 2); - *(replybuf+(total_len-1)) = ((uint8_t *) &crc16 )[1]; - *(replybuf+(total_len-2)) = ((uint8_t *) &crc16 )[0]; + uint8_t* plen =(uint8_t*)(&pcmdheader->len); + uint8_t t = plen[0]; + plen[0] = plen[1]; + plen[1] = t; + + replybuf[(total_len-1)] = ((uint8_t *) &crc16 )[0]; + replybuf[(total_len-2)] = ((uint8_t *) &crc16 )[1]; ret = ble_factorytest_server_send_input_report(replybuf,total_len); free(replybuf); return ret; } + +void ble_vibrator_check_timer_callback(void) +{ + vibrator_cyclicity(duty,cycle_time_ms,1000); +} + +void ble_acc_check_timer_callback(void) +{ + uint16_t databuf[6]; + get_gsensor_single(databuf); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_ACC, + 0x05, + databuf, + strlen(databuf)); +} + + +void ble_hrs_check_timer_callback(void) +{ + uint32_t databuf[4] = {0}; + int32_t ppg_buf; + + if(ble_hrs_flag == 1) + { + ble_hrs_flag = 0; + osTimerDelete(g_ble_hrs_timer); + ppg_send_cmd_to_driver("hrs",0); + return; + } + + if(ble_hrs_data > 10000) + { + ppg_buf = ble_hrs_data; + + databuf[0] = (uint32_t)((ppg_buf & 0xFF000000) >> 24); + databuf[1] = (uint32_t)((ppg_buf & 0x00FF0000) >> 16); + databuf[2] = (uint32_t)((ppg_buf & 0x0000FF00) >> 8); + databuf[3] = (uint32_t)((ppg_buf & 0x000000FF) >> 0); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, + 0x03, + databuf, + strlen(databuf)); + } + +} + +void ble_spo2_check_timer_callback(void) +{ + uint32_t databuf[4] = {0}; + int32_t red_buf; + + if(ble_spo2_flag == 1) + { + ble_spo2_flag = 0; + osTimerDelete(g_ble_spo2_timer); + ppg_send_cmd_to_driver("spo2",0); + return; + } + + if(ble_hrs_data > 10000) + { + red_buf = ble_spo2_data; + + databuf[0] = (uint32_t)((red_buf & 0xFF000000) >> 24); + databuf[1] = (uint32_t)((red_buf & 0x00FF0000) >> 16); + databuf[2] = (uint32_t)((red_buf & 0x0000FF00) >> 8); + databuf[3] = (uint32_t)((red_buf & 0x000000FF) >> 0); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, + 0x04, + databuf, + strlen(databuf)); + } + +} + +void ble_graycard_check_timer_callback(void) +{ + if(graycard_flag == 10) + { + graycard_flag = 0; + osTimerDelete(g_ble_graycard_timer); + return; + } + ppg_send_cmd_to_driver("graycard",1); + FT_RESULTS_t ft_result = hx3695_factroy_test(GRAY_CARD_TEST); + ppg_send_cmd_to_driver("graycard",0); + uint32_t databuf[12] = {0}; + + databuf[0] = (uint32_t)((ft_result.gr_data_final & 0xFF000000) >> 24); + databuf[1] = (uint32_t)((ft_result.gr_data_final & 0x00FF0000) >> 16); + databuf[2] = (uint32_t)((ft_result.gr_data_final & 0x0000FF00) >> 8); + databuf[3] = (uint32_t)((ft_result.gr_data_final & 0x000000FF) >> 0); + + databuf[4] = (uint32_t)((ft_result.red_data_final & 0xFF000000) >> 24); + databuf[5] = (uint32_t)((ft_result.red_data_final & 0x00FF0000) >> 16); + databuf[6] = (uint32_t)((ft_result.red_data_final & 0x0000FF00) >> 8); + databuf[7] = (uint32_t)((ft_result.red_data_final & 0x000000FF) >> 0); + + databuf[8] = (uint32_t)((ft_result.ir_data_final & 0xFF000000) >> 24); + databuf[9] = (uint32_t)((ft_result.ir_data_final & 0x00FF0000) >> 16); + databuf[10] = (uint32_t)((ft_result.ir_data_final & 0x0000FF00) >> 8); + databuf[11] = (uint32_t)((ft_result.ir_data_final & 0x000000FF) >> 0); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, + 0x05, + databuf, + strlen(databuf)); + graycard_flag++; +} + +void ble_leaklight_check_timer_callback(void) +{ + if(leaklight_flag == 10) + { + leaklight_flag = 0; + osTimerDelete(g_ble_leaklight_timer); + return; + } + ppg_send_cmd_to_driver("leaklight",1); + FT_RESULTS_t ft_result = hx3695_factroy_test(LEAK_LIGHT_TEST); + ppg_send_cmd_to_driver("leaklight",0); + uint32_t databuf[12] = {0}; + + databuf[0] = (uint32_t)((ft_result.gr_data_final & 0xFF000000) >> 24); + databuf[1] = (uint32_t)((ft_result.gr_data_final & 0x00FF0000) >> 16); + databuf[2] = (uint32_t)((ft_result.gr_data_final & 0x0000FF00) >> 8); + databuf[3] = (uint32_t)((ft_result.gr_data_final & 0x000000FF) >> 0); + + databuf[4] = (uint32_t)((ft_result.red_data_final & 0xFF000000) >> 24); + databuf[5] = (uint32_t)((ft_result.red_data_final & 0x00FF0000) >> 16); + databuf[6] = (uint32_t)((ft_result.red_data_final & 0x0000FF00) >> 8); + databuf[7] = (uint32_t)((ft_result.red_data_final & 0x000000FF) >> 0); + + databuf[8] = (uint32_t)((ft_result.ir_data_final & 0xFF000000) >> 24); + databuf[9] = (uint32_t)((ft_result.ir_data_final & 0x00FF0000) >> 16); + databuf[10] = (uint32_t)((ft_result.ir_data_final & 0x0000FF00) >> 8); + databuf[11] = (uint32_t)((ft_result.ir_data_final & 0x000000FF) >> 0); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, + 0x06, + databuf, + strlen(databuf)); + leaklight_flag++; +} + /** * BLE_TEST_CMD_MODE_COMMON * factorytest_protocol_common_decode @@ -77,7 +263,7 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t case BLE_TEST_CMD_COMMON_SUB_MODE_SYSTEM_VERSION: if (testitem == 0x02) { - + //获取软件版本 uint8_t buildversion[64]={0}; uint16_t versionlen = 0; ret = uapi_get_buildversion(buildversion,&versionlen); @@ -89,14 +275,768 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t } break; + case BLE_TEST_CMD_COMMON_SUB_MODE_POWER_ON_OFF_DEVICE: + + if(testitem == 0x01) + { + //系统自检(未完成) + } + + if(testitem == 0x02) + { + //关机 + uint8_t send_data = 0x00; + uint16_t len = sizeof(send_data); + uapi_poweroff_device(); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON, + BLE_TEST_CMD_COMMON_SUB_MODE_POWER_ON_OFF_DEVICE, + 0x02, + &send_data, + len); + } else if(testitem == 0x03) + { + //重启 + uint8_t send_data = 0x00; + uint16_t len = sizeof(send_data); + uapi_reboot_device(); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON, + BLE_TEST_CMD_COMMON_SUB_MODE_POWER_ON_OFF_DEVICE, + 0x03, + &send_data, + len); + } else if(testitem == 0x05) + { + //恢复出厂设置(未完成) + uint8_t send_data = 0x00; + uint16_t len = sizeof(send_data); + //bluetooth_factory_reset(); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON, + BLE_TEST_CMD_COMMON_SUB_MODE_POWER_ON_OFF_DEVICE, + 0x05, + &send_data, + len); + } + break; + + case BLE_TEST_CMD_COMMON_SUB_MODE_POWERCONSUMPTION: + break; + + case BLE_TEST_CMD_COMMON_SUB_MODE_OTA: + break; + + default: + printf(""); + break; + + } +} + +/** + * BLE_TEST_CMD_MODE_SOFT_TEST + * factorytest_protocol_soft_test_decode +*/ + +void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint8_t* data,uint16_t len) +{ + errcode_t ret; + switch(submode) + { + printf("submode 0x%02X testitem 0x%02X\r\n",submode,testitem); + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_BLE: + if (testitem == 0x02) + { + //获取蓝牙地址 + uint8_t btaddr[64]={0}; + uint32_t btaddrlen = 0; + uapi_get_btaddr(btaddr,&btaddrlen); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_BLE, + 0x02, + btaddr, + btaddrlen); + } + //获取蓝牙信号强度(未完成) + if (testitem == 0x03) + { + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_BLE, + 0x03, + &send_data, + datalen); + } + //发射功率(未完成) + if (testitem == 0x05) + { + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_BLE, + 0x05, + &send_data, + len); + } + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR: + + if(testitem == 0x01) + { + PRINT("222\r\n"); + //打开马达 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + g_ble_vibrator_timer = osTimerNew((osTimerFunc_t)ble_vibrator_check_timer_callback, osTimerPeriodic, NULL, NULL); + + osTimerStart(g_ble_vibrator_timer,1000); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR, + 0x01, + &send_data, + datalen); + + } else if(testitem == 0x02) + { + //关闭马达 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + cycle_time_ms = 200; + duty = 20; + + osTimerDelete(g_ble_vibrator_timer); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR, + 0x02, + &send_data, + datalen); + } else if(testitem == 0x03) + { + //打开周期性马达 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + cycle_time_ms = data[0]; + duty = data[1]; + + g_ble_vibrator_timer = osTimerNew((osTimerFunc_t)ble_leaklight_check_timer_callback, osTimerPeriodic, NULL, NULL); + + osTimerStart(g_ble_vibrator_timer,1000); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR, + 0x03, + &send_data, + datalen); + + } else if(testitem == 0x04) + { + //关闭周期性马达 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + osTimerDelete(g_ble_vibrator_timer); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR, + 0x04, + &send_data, + datalen); + } + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_KEY: + //按键测试(未完成) + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_RTC: + + if(testitem == 0x01) + { + //写入RTC + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + set_system_time((char *)data); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_RTC, + 0x01, + &send_data, + datalen); + } else if(testitem == 0x02) + { + //获取RTC + uint32_t send_data[64] = {0}; + get_system_time(&send_data[1]); + uint16_t datalen = strlen(send_data); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR, + 0x02, + &send_data, + datalen); + } + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CUSTOM_CMD: + if(testitem == 0x01) + { + //写SN + uint8_t send_data = 0x00; + + zh_set_sn(data,len); + + uint16_t datalen = strlen(send_data); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CUSTOM_CMD, + 0x01, + &send_data, + datalen); + } else if(testitem == 0x02) + { + //读SN + uint8_t send_data[64] = {0}; + uint32_t datalen; + zh_get_sn(&send_data[1],&datalen); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CUSTOM_CMD, + 0x02, + send_data, + datalen+1); + } else if(testitem == 0x11) + { + uint8_t i; + //获取soc_id + uint8_t soc_id[21]; // 20 is soc id length + soc_id[0] = 0; + uapi_soc_read_id(&soc_id[1], 21); + + uint16_t datalen = strlen((char *)soc_id); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CUSTOM_CMD, + 0x11, + soc_id, + datalen); + } + + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LCD: + if(testitem == 0x01) + { + //获取LCD_ID + uint32_t id; + uint8_t lcd_id[3] = {0}; + lcd_getid(&id); + + lcd_id[0] = 0; + lcd_id[1] = id >> 8; + lcd_id[2] = id; + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LCD, + 0x01, + lcd_id, + strlen((char *)lcd_id)); + } else if(testitem == 0x02) + { + PRINT("333\r\n"); + //LCD 上电 + + mcu_pm_lcd_on(0,0); + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + mcu_pm_lcd_on(0,0); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LCD, + 0x02, + &send_data, + datalen); + } else if(testitem == 0x03) + { + //LCD下电 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + mcu_pm_lcd_off(0,0); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LCD, + 0x03, + &send_data, + datalen); + + } else if(testitem == 0x04) + { + //LCD显示颜色 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + uint32_t color_buf[5] = {0xffff0000,0xff00ff00,0xff0000ff,0xffffffff,0xff000000}; + switch (data[0]) + { + case 1: + lcd_fill(color_buf[0], 4); + break; + case 2: + lcd_fill(color_buf[1], 4); + break; + case 3: + lcd_fill(color_buf[2], 4); + break; + case 4: + lcd_fill(color_buf[3], 4); + break; + case 5: + lcd_fill(color_buf[4], 4); + break; + + default: + break; + } + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LCD, + 0x04, + &send_data, + datalen); + } else if(testitem == 0x05) + { + uint8_t send_data = 0; + uint16_t datalen = sizeof(send_data); + uint32_t timeout = *data; + //修改自动灭屏时间 + power_display_set_screen_auto_off_timeout(timeout); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LCD, + 0x05, + &send_data, + datalen); + } + + + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_TP: + if(testitem == 0x01) + { + //获取ID + uint16_t id[16] = {0}; + touch_getid(&id[1]); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_TP, + 0x01, + id, + strlen(id)); + } else if(testitem == 0x03) + { + //触摸测试 + uint8_t send_data = 0x01; + uint16_t datalen = sizeof(send_data); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_TP, + 0x03, + &send_data, + datalen); + + send_data = 0x00; + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_TP, + 0x03, + &send_data, + datalen); + + + } else if(testitem == 0x05) + { + //获取原始数据 + int16_t x,y; + get_tp_info(&x,&y); + uint16_t databuf[3] = {0}; + + databuf[1] = x & 0XFF; + databuf[2] = y & 0XFF; + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_TP, + 0x05, + databuf, + strlen(databuf)); + } + + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_ACC: + if(testitem == 0x01) + { + //acc ID(未完成) + uint8_t acc_id[2] = {0}; + acc_id[1] = 0x44; + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_ACC, + 0x01, + &acc_id, + strlen((char *)acc_id)); + + } else if(testitem == 0x04) + { + //单次获得acc + uint16_t databuf[6]; + get_gsensor_single(databuf); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_ACC, + 0x04, + databuf, + strlen(databuf)); + + } else if(testitem == 0x05) + { + //连续获得acc + g_ble_acc_timer = osTimerNew((osTimerFunc_t)ble_acc_check_timer_callback, osTimerPeriodic, NULL, NULL); + osTimerStart(g_ble_acc_timer,1000); + + } else if(testitem == 0x06) + { + //关闭连续acc + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + osTimerStop(g_ble_acc_timer); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_ACC, + 0x06, + &send_data, + datalen); + } + + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS: + if(testitem == 0x01) + { + //获取chip_id + uint8_t chip_id; + chip_id = hx3695_get_chip_id(); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, + 0x01, + &chip_id, + sizeof(chip_id)); + + } else if(testitem == 0x02) + { + //关闭所有LED + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + send_ppg_cmd_msg("ledoff"); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, + 0x02, + &send_data, + datalen); + } else if(testitem == 0x03) + { + //打开心率检测 + g_ble_hrs_timer = osTimerNew((osTimerFunc_t)ble_hrs_check_timer_callback, osTimerPeriodic, NULL, NULL); + osTimerStart(g_ble_hrs_timer,400); + ppg_send_cmd_to_driver("hrs",1); + + } else if(testitem == 0x04) + { + //打开血氧检测 + g_ble_spo2_timer = osTimerNew((osTimerFunc_t)ble_spo2_check_timer_callback, osTimerPeriodic, NULL, NULL); + osTimerStart(g_ble_spo2_timer,400); + ppg_send_cmd_to_driver("spo2",1); + + } else if(testitem == 0x05) + { + //灰卡测试 + g_ble_graycard_timer = osTimerNew((osTimerFunc_t)ble_graycard_check_timer_callback, osTimerPeriodic, NULL, NULL); + osTimerStart(g_ble_graycard_timer,400); + + } else if(testitem == 0x06) + { + //漏光测试 + g_ble_leaklight_timer = osTimerNew((osTimerFunc_t)ble_leaklight_check_timer_callback, osTimerPeriodic, NULL, NULL); + osTimerStart(g_ble_leaklight_timer,400); + + } + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_COMPASS: + if(testitem == 0x01) + { + //获取mmc5603 ID + unsigned char chip_id; + mmc5603_getid(&chip_id); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_COMPASS, + 0x01, + &chip_id, + sizeof(chip_id)); + + } else if(testitem == 0x02) + { + //地磁sensor测试 + float fAzimuth,fPitch,fRoll; + mmc5603_getdata(&fAzimuth,&fPitch,&fRoll); + + uint16_t databuf[6] = {0}; + + databuf[0] = (uint16_t)(((uint16_t)fAzimuth & 0xFF00) >> 8); + databuf[1] = (uint16_t)((uint16_t)fAzimuth & 0x00FF); + + databuf[2] = (uint16_t)(((uint16_t)fPitch & 0xFF00) >> 8); + databuf[3] = (uint16_t)((uint16_t)fPitch & 0x00FF); + + databuf[4] = (uint16_t)(((uint16_t)fRoll & 0xFF00) >> 8); + databuf[5] = (uint16_t)((uint16_t)fRoll & 0x00FF); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_COMPASS, + 0x02, + databuf, + strlen(databuf)); + } + + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM: + if(testitem == 0x02) + { + //获取充电状态 + bool state; + state = uapi_get_charger_plug_status(); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM, + 0x02, + &state, + sizeof(state)); + + } else if(testitem == 0x03) + { + //获取电量 + uint8_t power; + battery_getvolpower(&power); + + uint8_t send_data[2] = {0}; + send_data[1] = power & 0XFF; + uint16_t datalen = strlen((char *)send_data); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM, + 0x03, + &send_data, + datalen); + } else if(testitem == 0x04) + { + //获取电压 + float voltage; + battery_getvoltage(&voltage); + + uint8_t send_data[2] = {0}; + send_data[1] = (uint8_t)voltage & 0XFF; + uint16_t datalen = strlen((char *)send_data); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM, + 0x04, + &send_data, + datalen); + } else if(testitem == 0x05) + { + //关机 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + uapi_poweroff_device(); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM, + 0x05, + &send_data, + datalen); + } + + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_EXTFLASH: + if(testitem == 0x01) + { + //获得flash_id + uint32_t id; + flash_getid(&id); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_EXTFLASH, + 0x01, + &id, + sizeof(id)); + + } else if(testitem == 0x02) + { + //flash自检 + uint8_t send_data = 0x01; + uint16_t datalen = sizeof(send_data); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_EXTFLASH, + 0x02, + &send_data, + datalen); + + send_data = 0x02; + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_EXTFLASH, + 0x02, + &send_data, + datalen); + } else if(testitem == 0x03) + { + //flash擦除 + uint8_t send_data = 0x01; + uint16_t datalen = sizeof(send_data); + flash_erase(); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM, + 0x05, + &send_data, + datalen); + } + + break; + + //扩展RAM(未完成) + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_EXTRAM: + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1: + if(testitem == 0x01) + { + //打开cat1 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + uapi_cat1_power_on(1); + uapi_cat1_reset(0); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, + 0x01, + &send_data, + datalen); + + } else if(testitem == 0x02) + { + //关闭cat1 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + uapi_cat1_power_on(0); + uapi_cat1_reset(1); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, + 0x02, + &send_data, + datalen); + + + } else if(testitem == 0x03) + { + //查看sim卡插入状态(未完成) + // uint8_t send_data = 0x00; + // uint16_t len = sizeof(send_data); + + // factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + // BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, + // 0x03, + // &send_data, + // len); + } else if(testitem == 0x04) + { + //查看信号强度(未完成) + // uint8_t send_data = 0x00; + // uint16_t len = sizeof(send_data); + + // factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + // BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, + // 0x04, + // &send_data, + // len); + } else if(testitem == 0x05) + { + //查看网络类型(未完成) + // uint8_t send_data = 0x00; + // uint16_t len = sizeof(send_data); + + // factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + // BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, + // 0x05, + // &send_data, + // len); + } else if(testitem == 0x06) + { + //拨打电话 + + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + cat1_call_dial((char *)data); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, + 0x06, + &send_data, + datalen); + + } else if(testitem == 0x07) + { + //接听电话 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + + cat1_call_answer(); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, + 0x07, + &send_data, + datalen); + } + + else if(testitem == 0x08) + { + //挂断电话 + uint8_t send_data = 0x00; + uint16_t datalen = sizeof(send_data); + cat1_call_hungup(); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, + 0x08, + &send_data, + datalen); + } + + break; + default: printf(""); break; } } + + errcode_t factorytest_protocol_decode(uint8_t *buf, uint16_t event_size) { + //if(buf != NULL && event_size>=(1+2+1+1+1+2/*header+len+mod+submod+item+crc*/)) if(buf != NULL && event_size>=(1+2+1+1+1+2/*header+len+mod+submod+item+crc*/)) { factorytest_cmd_header_t header ={0}; @@ -137,6 +1077,10 @@ errcode_t factorytest_protocol_decode(uint8_t *buf, uint16_t event_size) // 主模式ID 生产软件 0x02 case BLE_TEST_CMD_MODE_SOFT_TEST: + PRINT("111\r\n"); + factorytest_protocol_soft_test_decode(header.submod,header.testitem, + buf+1+2+1+1+1, + header.len); break; // 主模式ID 硬测接口 0x03 diff --git a/code/sdk/application/wearable/service/power_manager/include/power_display_service.h b/code/sdk/application/wearable/service/power_manager/include/power_display_service.h index 9c54682c2..332d870a3 100755 --- a/code/sdk/application/wearable/service/power_manager/include/power_display_service.h +++ b/code/sdk/application/wearable/service/power_manager/include/power_display_service.h @@ -418,6 +418,9 @@ errcode_t power_display_task_init(void); */ screen_context_t *power_display_get_screen_context(void); +extern errcode_t power_display_set_screen_auto_off_timeout(uint32_t timeout); + + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/application/wearable/service/power_manager/src/power_display_service.c b/code/sdk/application/wearable/service/power_manager/src/power_display_service.c index 5db3374bd..df572795f 100755 --- a/code/sdk/application/wearable/service/power_manager/src/power_display_service.c +++ b/code/sdk/application/wearable/service/power_manager/src/power_display_service.c @@ -99,7 +99,7 @@ static screen_state_t power_display_get_screen_state(void) return g_screen_context.current_state; } -static errcode_t power_display_set_screen_auto_off_timeout(uint32_t timeout) +errcode_t power_display_set_screen_auto_off_timeout(uint32_t timeout) { if (g_screen_context.time_out_enable == false) { return ERRCODE_FAIL; diff --git a/code/sdk/application/wstp/at_service/app/app_at_process.c b/code/sdk/application/wstp/at_service/app/app_at_process.c index 47d45da16..a68127b08 100755 --- a/code/sdk/application/wstp/at_service/app/app_at_process.c +++ b/code/sdk/application/wstp/at_service/app/app_at_process.c @@ -2359,7 +2359,8 @@ static uint32_t mcu_get_time(uint8_t *para, uint32_t para_len) { unused(para); unused(para_len); - return get_system_time(); + uint32_t timebuf; + return get_system_time(&timebuf); } #ifdef SUPPORT_POWER_MANAGER diff --git a/code/sdk/application/wstp/at_service/app/app_at_process.h b/code/sdk/application/wstp/at_service/app/app_at_process.h index 3dccec79f..d954b1e4c 100755 --- a/code/sdk/application/wstp/at_service/app/app_at_process.h +++ b/code/sdk/application/wstp/at_service/app/app_at_process.h @@ -69,6 +69,7 @@ extern uint32_t mcu_pm_lcd_off(uint8_t *para, uint32_t para_len); extern errcode_t upg_flash_write(const uint32_t flash_offset, uint32_t size, const uint8_t *ram_data, bool do_erase); extern uint32_t mcu_pm_lcd_on(uint8_t *para, uint32_t para_len); extern uint32_t mcu_pm_lcd_off(uint8_t *para, uint32_t para_len); +extern uint32_t lcd_fill(uint8_t *data, uint32_t data_len); #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/application/wstp/at_service/app/app_common_api.c b/code/sdk/application/wstp/at_service/app/app_common_api.c index c45989b30..3fc8baaf9 100755 --- a/code/sdk/application/wstp/at_service/app/app_common_api.c +++ b/code/sdk/application/wstp/at_service/app/app_common_api.c @@ -181,7 +181,7 @@ uint32_t set_system_time(char* time) return ERRCODE_SUCC; } -uint32_t get_system_time(void) +uint32_t get_system_time(uint32_t *timedata) { char timebuf[TIME_MAX] = { 0 }; struct tm tm; @@ -197,9 +197,13 @@ uint32_t get_system_time(void) wstp_print("%s", timebuf); } + memcmp(timedata,&timebuf,strlen(&timebuf)); + uint32_t millisec = tv.tv_usec / USEC_TO_MILLI; wstp_print(":%03d\n", millisec); + timedata = strcat(timedata,&millisec); + return ERRCODE_SUCC; } diff --git a/code/sdk/application/wstp/at_service/app/app_common_api.h b/code/sdk/application/wstp/at_service/app/app_common_api.h index 5edaf084a..bd42cf016 100755 --- a/code/sdk/application/wstp/at_service/app/app_common_api.h +++ b/code/sdk/application/wstp/at_service/app/app_common_api.h @@ -1,3 +1,13 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-03-13 15:08:38 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-03-30 21:22:18 + * @FilePath: /FD230/code/sdk/application/wstp/at_service/app/app_common_api.h + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ /** * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n * @@ -30,7 +40,7 @@ int add_function(char *name, char *description, int (*func)(int argc, char *argv #endif uint32_t get_sec_time(char* time); uint32_t set_system_time(char* time); -uint32_t get_system_time(void); +uint32_t get_system_time(uint32_t *timebuf); uint32_t nandflash_aging_test(char* para); uint32_t flash_aging_test(char* para); uint32_t freertos_heap_print(void); diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index 4b63a572a..d46b8312e 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -429,7 +429,7 @@ typedef struct extern void get_gsonsen_xyz(gsenson_t *t); -extern void gsensor_get_n_data(uint8_t cnt); +void gsensor_get_n_data(uint8_t cnt,gsenson_t t[]); #pragma pack() diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index d3b01a5ea..15f2fc604 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -44,35 +44,39 @@ static int16 right_falg=-1; void get_gsonsen_xyz(gsenson_t *t) { - if(osal_mutex_trylock(&mutex_gsenson_queue)==0) - { - CWM_OS_dbgPrintf("get_gsonsen_xyz_fail\n"); - return; - } + // if(osal_mutex_trylock(&mutex_gsenson_queue)==0) + // { + // CWM_OS_dbgPrintf("get_gsonsen_xyz_fail\n"); + // return; + // } t->x = gxyz_t_queue[left_falg].x; t->y = gxyz_t_queue[left_falg].y; t->z = gxyz_t_queue[left_falg].z; - osal_mutex_unlock(&mutex_gsenson_queue); + //osal_mutex_unlock(&mutex_gsenson_queue); } -void gsensor_get_n_data(uint8_t cnt) +void gsensor_get_n_data(uint8_t cnt,gsenson_t t[]) { for(int i=0;i 10000) + { + ble_hrs_data = PPG_buf[ii]; + } + } #ifndef GSEN_40MS_TIMMER //readFifoByHrsModule(); @@ -2712,6 +2732,26 @@ void hx3695_hrs_ppg_Int_handle(void) // result.ir_data_final = hrs_s_dat.ir_data[0]; // hx3695_factory_test_process(NULL, APP_FACTORY_TEST_HR_START, &result); + //gsensor_get_n_data(8,gsensordata); + + // for(ii=0; ii<*count; ii++) + // { + // if(ii == 8) + // { + // gsen_fifo_x_send[ii] = gsen_fifo_x_send[ii - 1]; + // gsen_fifo_y_send[ii] = gsen_fifo_y_send[ii - 1]; + // gsen_fifo_z_send[ii] = gsen_fifo_z_send[ii - 1]; + // } + // else + // { + // gsen_fifo_x_send[ii] = gsensordata[ii].x; + // gsen_fifo_y_send[ii] = gsensordata[ii].y; + // gsen_fifo_z_send[ii] = gsensordata[ii].z; + // } + + // PRINT("hxdata:%d/%d %d %d %d %d %d %d\r\n" ,1+ii,*count,PPG_buf[ii],ir_buf[0],gsen_fifo_x[ii],gsen_fifo_y[ii],gsen_fifo_z[ii],ppg_s_data.green_cur); + // } + hrs_wear_status = hx3695_hrs_get_wear_status(); PRINT("hrs_wear_status: %d !!\r\n", hrs_wear_status); @@ -2755,6 +2795,12 @@ void hx3695_hrs_ppg_Int_handle(void) PRINT("hx3695 data_cnt: %d, hr_living: %d, hr_living_qu: %d, hr_living_std: %d, hr_result:%d \r\n", alg_results.data_cnt, hrsresult.hr_living, hrsresult.hr_living_qu, hrsresult.hr_living_std, hrsresult.lastesthrs); + + if(hrsresult.lastesthrs > 0) + { + ble_hrs_flag = 1; + } + if(hrs_wear_status == MSG_HRS_WEAR && hrsresult.hr_living == MSG_LIVING_TRUE) { // app_hr_reset_stop_timer(); @@ -3069,6 +3115,14 @@ void hx3695_spo2_ppg_Int_handle(void) return; } + for(ii = 0; ii < hrs_s_dat.count; ii++) + { + if(red_buf[ii] > 10000) + { + ble_spo2_data = red_buf[ii]; + } + } + #ifndef GSEN_40MS_TIMMER // readFifoByHrsModule(); @@ -3154,6 +3208,9 @@ void hx3695_spo2_ppg_Int_handle(void) DEBUG_PRINTF("block_cnt: %d, data_cnt:%d, hr_result:%d,ir_quality:%d,motion:%d,poor_signal:%d,reliable_score_result:%d,screen_up:%d,spo2_result:%d\r\n",spo2_alg_results.block_cnt,spo2_alg_results.data_cnt,spo2_alg_results.hr_result,spo2_alg_results.ir_quality,spo2_alg_results.motion,spo2_alg_results.poor_signal,spo2_alg_results.reliable_score_result,spo2_alg_results.screen_up,spo2_alg_results.spo2_result); hrsresult.lastestspo2 = spo2_alg_results.spo2_result; + + if(hrsresult.lastestspo2 > 0) + ble_spo2_flag = 1; // if(hrsresult.lastestspo2) { // store_latest_spo2(hrsresult.lastestspo2); diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.h b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.h index b35d7a256..7a7ad4d9d 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.h +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.h @@ -295,7 +295,15 @@ void agc_timeout_handler(void * p_context); void heart_rate_meas_timeout_handler(void * p_context); void Efuse_Mode_Check(void); +uint8_t hx3695_get_chip_id(void); + + #include "hx3695_hal.h" +extern int32_t ble_hrs_data; +extern uint8_t ble_hrs_flag; + +extern int32_t ble_spo2_data; +extern uint8_t ble_spo2_flag; #endif diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c index 4d4d72383..749efac90 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c @@ -1,3 +1,13 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-03-13 15:08:38 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-03-29 10:51:50 + * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ #include #include @@ -44,7 +54,9 @@ void ppg_send_cmd_to_driver(char* mode, uint8_t enable) md = FT_LEAK_LIGHT_MODE; } else if (strcmp(mode, "graycard") == 0) { md = FT_GRAY_CARD_MODE; - } + } else if (strcmp(mode, "ledoff") == 0) { + md = FT_LED_OFF_MODE; + } if (enable == 1) { @@ -56,7 +68,7 @@ void ppg_send_cmd_to_driver(char* mode, uint8_t enable) } else { // ppg_service_running_stat = false; - if(md == HRS_MODE|| md == FT_LEAK_LIGHT_MODE || md == FT_GRAY_CARD_MODE) + if(md == HRS_MODE|| md == FT_LEAK_LIGHT_MODE || md == FT_GRAY_CARD_MODE || md == FT_GRAY_CARD_MODE) { #ifdef HRS_ALG_LIB hx3695_hrs_disable(); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index f1c3f8dd8..461cf9af4 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -658,16 +658,33 @@ errcode_t uapi_get_buildversion(uint8_t *para, uint32_t para_len) return ERRCODE_SUCC; } -// #include "vibrator.h" +#include "vibrator.h" + + +void vibrator_switch(uint8_t cmd) +{ + //g_VibratorFunc_Swtich(cmd); +} + +void vibrator_cyclicity(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_time_ms) +{ + g_VibratorFunc(duty,cycle_time_ms,duration_time_ms); +} + +void VibratorFunc_PowerOn(void) +{ + //g_VibratorFunc_PowerOn(); +} + +void VibratorFunc_PowerOff(void) +{ + //g_VibratorFunc_PowerOff(); +} -// void Vibrator_swtich(uint8_t cmd) -// { -// g_Vibrator_swtich(cmd); -// } #include "lcd_common.h" -void lcd_getid(void) +void lcd_getid(uint32_t *id) { lcd_drv_common *lcd_drv_comm_api = NULL; lcd_drv_cfg *lcd_cfg = NULL; @@ -682,16 +699,62 @@ void lcd_getid(void) if (lcd_cfg == NULL) { PRINT("lcd_cfg is null.\r\n"); }else + { PRINT("LCD ID : 0x%x\r\n",(uint32_t)lcd_cfg->lcd_id); + *id = (uint32_t)lcd_cfg->lcd_id; + } } } - +#include "ft6x46_ctrl.h" #include "ft6x46_touch1.h" #define FTS_REG_CHIP_ID 0xA3 #define FTS_REG_CHIP_ID2 0x9F +/*Max point numbers of touch trace*/ +#define MAX_POINTS_TOUCH_TRACE 1 +/*Length of touch information*/ +#define MAX_LEN_TOUCH_INFO (MAX_POINTS_TOUCH_TRACE * 6 + 2) +#define FTS_MAX_POINTS_SUPPORT 10 + +struct fts_ts_event { + int x; /*x coordinate */ + int y; /*y coordinate */ + int p; /* pressure */ + int type; /* touch event flag: 0 -- down; 1-- up; 2 -- contact */ + int id; /*touch ID */ + int area; /*touch area*/ +}; + + +void get_tp_info(int16_t *x,int16_t *y) +{ + uint8_t i = 0; + uint8_t base = 0; + uint8_t regaddr = 0x01; + uint8_t buf[MAX_LEN_TOUCH_INFO];/*A maximum of two points are supported*/ + + struct fts_ts_event events[FTS_MAX_POINTS_SUPPORT]; /* multi-touch */ + /*read touch information from reg0x01*/ + tp_ft6x46_i2c_data_read(regaddr, buf, MAX_LEN_TOUCH_INFO); + + memset(events, 0xFF, sizeof(struct fts_ts_event) * FTS_MAX_POINTS_SUPPORT); + + for (i = 0; i < MAX_POINTS_TOUCH_TRACE; i++) + { + base = 2 + i * 6; + + events[i].x = ((buf[base] & 0x0F) << 8) + buf[base + 1]; + events[i].y = ((buf[base + 2] & 0x0F) << 8) + buf[base + 3]; + + *x = events[i].x; + *y = events[i].y; -void touch_getid(void) + PRINT("X : %d, y : %d \r\n",*x,*y); + } +} + + +void touch_getid(uint16_t *id) { ext_errno ret; uint8_t chip_id[2] = { 0 }; @@ -704,9 +767,11 @@ void touch_getid(void) if (ret != EXT_ERR_SUCCESS) { PRINT("get ic information error2"); } else + { PRINT("TOUCH CHIP ID = 0x%02x%02x", chip_id[0], chip_id[1]); + sprintf(id,"0x%02x%02x", chip_id[0], chip_id[1]); + } } - } #include "touch_screen_drv.h" @@ -719,10 +784,17 @@ void touch_getstate(void) } #include "MMC5603.h" +#include "mag_service.h" +void mmc5603_getid(unsigned char *id) +{ + MMC5603_GETID(id); +} -void mmc5603_getid(void) +void mmc5603_getdata(float *fAzimuth,float *fPitch,float *fRoll) { - MMC5603_GETID(); + *fAzimuth = mag_service_get_fAzimuth(); + *fPitch = mag_service_get_fPitch(); + *fRoll = mag_service_get_fRoll(); } @@ -736,41 +808,58 @@ void charge_getstate(void) } #include "battery_service.h" -#define batteryservice_VOLTAGE_MAX (4.2f) -#define batteryservice_VOLTAGE_MIN (3.2f) -void battery_getpower(void) +void battery_getvolpower(uint8_t *power) { - float vol = 0; - uint8_t per; - battery_info_t *current_battery_info = get_current_battery_info(); - vol = current_battery_info->battery_voltage; - per = (vol - batteryservice_VOLTAGE_MIN)*100/(batteryservice_VOLTAGE_MAX - batteryservice_VOLTAGE_MIN) ; - if(per <= 0) - per = 0; - else if(per >= 100) - per = 100; - PRINT("power : %d \r\n",per); + float voltage; + *power = battery_get_voltage(&voltage); } -void battery_getvoltage(void) +void battery_getvoltage(float *voltage) { - battery_info_t *current_battery_info = get_current_battery_info(); - batteryservice_get_voltage_by_channel(¤t_battery_info->battery_voltage,ADC_CHANNEL_BAT_VOLTAGE); - PRINT("voltage : %f \r\n",current_battery_info->battery_voltage); + battery_get_voltage(voltage); } #include "flash.h" +void flash_getid(uint32_t *id) +{ + flash_info_t norflash_id; + uapi_flash_get_info(0, &norflash_id); + *id = norflash_id.flash_id; +} + void flash_erase(void) { - if (uapi_flash_chip_erase(CHIP_FLASH_ID) != ERRCODE_SUCC) - PRINT("flash erase err !!! \r\n"); - else - PRINT("flash erase succ !!! \r\n"); + uapi_flash_chip_erase(0); + uapi_flash_chip_erase(1); } +#include "cywee_hal.h" + +void get_gsensor_single(uint16_t *databuf) +{ + gsenson_t *t; + get_gsonsen_xyz(t); + + databuf[0] = (uint16_t)((t->x & 0xFF00) >> 8); + databuf[1] = (uint16_t)(t->x & 0x00FF); + + databuf[2] = (uint16_t)((t->y & 0xFF00) >> 8); + databuf[3] = (uint16_t)(t->y & 0x00FF); + + databuf[4] = (uint16_t)((t->z & 0xFF00) >> 8); + databuf[5] = (uint16_t)(t->z & 0x00FF); +} + +void gsensor_get_single_data(gsenson_t *t) +{ + get_gsonsen_xyz(t); +} + +//#include "lis2doc_reg.h" + #include "stdio.h" /**** 静态全局变量 ****/ diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 2a3592d12..7fe824b7b 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -62,28 +62,32 @@ errcode_t uapi_get_buildversion(uint8_t *para, uint32_t para_len); */ //开关马达 -void Vibrator_swtich(uint8_t cmd); +void vibrator_switch(uint8_t cmd); +void vibrator_cyclicity(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_time_ms); //获取lcd id -void lcd_getid(void); +void lcd_getid(uint32_t *id); //获取TP ID -void touch_getid(void); +void touch_getid(uint16_t *id); +void get_tp_info(int16_t *x,int16_t *y); //获取触摸屏状态 void touch_getstate(void); //获取MMC5063 ID -void mmc5603_getid(void); +void mmc5603_getid(unsigned char *id); +void mmc5603_getdata(float *fAzimuth,float *fPitch,float *fRoll); //获取充电状态 void charge_getstate(void); //获取电压 -void battery_getvoltage(void); -void battery_getvolpower(void); +void battery_getvoltage(float *voltage); +void battery_getvolpower(uint8_t *power); //flash整片擦除 +void flash_getid(uint32_t *id); void flash_erase(void); //进入recovery @@ -91,7 +95,7 @@ int enter_recovery(void); //设置bmp图片 int set_bmp(void); - +void get_gsensor_single(uint16_t *databuf); #ifdef __cplusplus } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index 3e78e3661..8cd451609 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -175,7 +175,7 @@ static uint32_t custom_lcd_getid(uint8_t *para, uint32_t paraLen, char *strCommo UNUSED(strCommonCmd); - lcd_getid(); + //lcd_getid(); return ERRCODE_SUCC; } @@ -185,7 +185,7 @@ static uint32_t custom_touch_getid(uint8_t *para, uint32_t paraLen, char *strCom UNUSED(strCommonCmd); - touch_getid(); + //touch_getid(); return ERRCODE_SUCC; } @@ -205,7 +205,7 @@ static uint32_t custom_mmc5603_getid(uint8_t *para, uint32_t paraLen, char *strC UNUSED(strCommonCmd); - mmc5603_getid(); + //mmc5603_getid(); return ERRCODE_SUCC; } @@ -225,7 +225,7 @@ static uint32_t custom_battery_getpower(uint8_t *para, uint32_t paraLen, char *s UNUSED(strCommonCmd); - battery_getpower(); + //battery_getpower(); return ERRCODE_SUCC; } @@ -235,7 +235,7 @@ static uint32_t custom_battery_getvoltage(uint8_t *para, uint32_t paraLen, char UNUSED(strCommonCmd); - battery_getvoltage(); + //battery_getvoltage(); return ERRCODE_SUCC; } @@ -261,9 +261,48 @@ static uint32_t custom_enter_recovery(uint8_t *para, uint32_t paraLen, char *str return ERRCODE_SUCC; } +static uint32_t custom_vibrator_on(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + + UNUSED(strCommonCmd); + + VibratorFunc_PowerOn(); + + return ERRCODE_SUCC; +} + +static uint32_t custom_vibrator_off(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + + UNUSED(strCommonCmd); + + VibratorFunc_PowerOff(); + + return ERRCODE_SUCC; +} + +#include "cywee_hal.h" +#include "hx3695_hrs_agc.h" +static uint32_t custom_gsensor_getdata(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + // gsenson_t *t; + // uint16_t databuf[6]; + UNUSED(strCommonCmd); + + return ERRCODE_SUCC; +} + +static uint32_t custom_get_tpinfo(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + int16_t x,y; + + UNUSED(strCommonCmd); + + get_tp_info(&x,&y); -// { (char *)"AT^VIBRATOR", custom_vibrator_swtich, (char *)" " }, + return ERRCODE_SUCC; +} static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^CUSTOM_SN", custom_utils_setsn, (char *)"123456789ABCDEF2345678" }, @@ -271,6 +310,11 @@ static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^DOWNLOADOTA", custom_start_ota_download, (char *)" " }, { (char *)"AT^STARTOTA", custom_start_ota, (char *)" " }, + { (char *)"AT^VIBRATORON", custom_vibrator_on, (char *)" " }, + + { (char *)"AT^VIBRATOROFF", custom_vibrator_off, (char *)" " }, + + { (char *)"AT^VIBRATORSWITCH", custom_vibrator_switch, (char *)" " }, { (char *)"AT^LCDID", custom_lcd_getid, (char *)" " }, @@ -289,6 +333,10 @@ static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^FLASHERASE", custom_flash_erase, (char *)" " }, { (char *)"AT^RECOVERY", custom_enter_recovery, (char *)" " }, + + { (char *)"AT^GSENSOR", custom_gsensor_getdata, (char *)" " }, + + { (char *)"AT^GETTP", custom_get_tpinfo, (char *)" " }, }; at_cmd_table_t *get_custom_utils_cmd_table(uint32_t *cmd_count) diff --git a/code/sdk/drivers/peripheral/vibrator/vibrator.c b/code/sdk/drivers/peripheral/vibrator/vibrator.c index 7e50e1863..c13f35f57 100644 --- a/code/sdk/drivers/peripheral/vibrator/vibrator.c +++ b/code/sdk/drivers/peripheral/vibrator/vibrator.c @@ -126,7 +126,7 @@ static pin_t pin = VIBRATOR_GPIOPPIN; static pin_mode_t mode = VIBRATORPIN_MODE; static uint8_t vibrating = 0; - +static uint8_t switch_flag = 1; void g_VibratorFunc(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_time_ms) { @@ -171,4 +171,5 @@ void g_VibratorFunc(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_tim } } + #endif