暂存:数据发送协议完善中
This commit is contained in:
@ -85,13 +85,21 @@ unsigned char xtell_bl_state=0; //存放经典蓝牙的连接状态,0断开
|
||||
u8 bt_newname =0;
|
||||
unsigned char xt_ble_new_name[9] = "CM-22222";
|
||||
static u16 play_poweron_ok_timer_id = 0;
|
||||
|
||||
// -- 初始化标志位 --
|
||||
u8 SC7U22_init = 0; //六轴是否初始化
|
||||
u8 MMC5603nj_init = 0; //地磁是否初始化
|
||||
|
||||
// -- 线程id --
|
||||
u16 SC7U22_calibration_id;
|
||||
u16 start_collect_fuc_id;
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
extern int bt_hci_event_handler(struct bt_event *bt);
|
||||
|
||||
extern void SC7U22_static_calibration(void);
|
||||
extern void create_process(u16* pid, const char* name, void *priv, void (*func)(void *priv), u32 msec);
|
||||
extern void close_process(u16* pid,char* name);
|
||||
extern void start_collect_fuc(void);
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* 模式状态机, 通过start_app()控制状态切换
|
||||
@ -203,52 +211,56 @@ void le_user_app_event_handler(struct sys_event* event){
|
||||
if (event->u.app.buffer[0] == 0xBE && event->u.app.buffer[1] == 0xBB) {
|
||||
if(event->u.app.buffer[2] == 0x01){ //后面的数据长度 1
|
||||
switch (event->u.app.buffer[3]){
|
||||
case 0x01:
|
||||
char* send_start = "will start after 5 seconds\n";
|
||||
send_data_to_ble_client(send_start,strlen(send_start));
|
||||
|
||||
if (mmc5603nj_init() != 0) {
|
||||
xlog("MMC5603NJ initialization failed!\n");
|
||||
char* send_error = "calibration error\n";
|
||||
send_data_to_ble_client(send_error,strlen(send_error));
|
||||
}
|
||||
xlog("MMC5603NJ PID: 0x%02X\n", mmc5603nj_get_pid());
|
||||
char* send_tmp = "8th calibration completed\n";
|
||||
send_data_to_ble_client(send_tmp,strlen(send_tmp));
|
||||
break;
|
||||
case 0x02:
|
||||
extern void create_process(u16* pid,char* name, void *priv, void (*func)(void *priv), u32 msec);
|
||||
extern void sensor_measure(void);
|
||||
static int test_id;
|
||||
SL_SC7U22_Config();
|
||||
static skiing_tracker_t skiing_data;
|
||||
skiing_tracker_init(&skiing_data);
|
||||
create_process(&test_id, "test",NULL, sensor_measure, 10);
|
||||
send_tmp = "The test has begun.\n";
|
||||
send_data_to_ble_client(send_tmp,strlen(send_tmp));
|
||||
break;
|
||||
case 0x03:
|
||||
extern void start_detection(void);
|
||||
start_detection();
|
||||
send_tmp = "start_detection\n";
|
||||
send_data_to_ble_client(send_tmp,strlen(send_tmp));
|
||||
break;
|
||||
case 0x04:
|
||||
extern void stop_detection(void);
|
||||
stop_detection();
|
||||
send_tmp = "stop_detection\n";
|
||||
send_data_to_ble_client(send_tmp,strlen(send_tmp));
|
||||
break;
|
||||
case 0x05:
|
||||
extern void clear_speed(void);
|
||||
clear_speed();
|
||||
send_tmp = "Reset speed and distances to zero\n";
|
||||
send_data_to_ble_client(send_tmp,strlen(send_tmp));
|
||||
|
||||
case 0x01:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}else if(event->u.app.buffer[2] == 0x02){ //后面数据长度为2
|
||||
switch (event->u.app.buffer[3]){ //数据包类型
|
||||
case 0x00: //数据包类型为:指定传感器初始化
|
||||
u8 send2_0[5] = {0xBB,0xBE,0x02,0x00,0x00};
|
||||
if(event->u.app.buffer[4] == 0x01){ //六轴
|
||||
if (SL_SC7U22_Config() == 0) {
|
||||
send2_0[4] = 0x00; //初始化失败
|
||||
SC7U22_init = 0;
|
||||
send_data_to_ble_client(&send2_0,strlen(send2_0));
|
||||
break;
|
||||
}
|
||||
create_process(&SC7U22_calibration_id,"SC7U22_calibration",NULL,SC7U22_static_calibration,10);
|
||||
}else if(event->u.app.buffer[4] == 0x02){ //地磁
|
||||
if(mmc5603nj_init() == 0){
|
||||
MMC5603nj_init = 0;
|
||||
break;
|
||||
}
|
||||
MMC5603nj_init = 1;
|
||||
send2_0[4] = 0x03; //地磁初始化失败
|
||||
send_data_to_ble_client(&send2_0,strlen(send2_0));
|
||||
}
|
||||
break;
|
||||
case 0x01: //数据包类型为:获取指定传感器初始化状态
|
||||
u8 send2_1[5] = {0xBB,0xBE,0x02,0x01,0x00};
|
||||
if(event->u.app.buffer[4] == 0x01){ //六轴
|
||||
send2_1[4] = SC7U22_init;
|
||||
}else if(event->u.app.buffer[4] == 0x02){ //地磁
|
||||
send2_1[4] = MMC5603nj_init + 2;
|
||||
}
|
||||
send_data_to_ble_client(&send2_1,strlen(send2_1));
|
||||
break;
|
||||
case 0x02: //开始/停止滑雪计算
|
||||
if(event->u.app.buffer[4] == 0x01){ //开始滑雪计算
|
||||
if(SC7U22_init == 0 || MMC5603nj_init == 0){ //传感器未进行初始化
|
||||
u8 send2_2[5] = {0xBB,0xBE,0x02,0x01,0x00};
|
||||
send_data_to_ble_client(&send2_2,strlen(send2_2));
|
||||
send2_2[4] = 0x02;
|
||||
send_data_to_ble_client(&send2_2,strlen(send2_2));
|
||||
return;
|
||||
}
|
||||
create_process(&start_collect_fuc_id,"start_collect",NULL,start_collect_fuc,10);
|
||||
}else if(event->u.app.buffer[4] == 0x02){ //停止滑雪计算
|
||||
close_process(&start_collect_fuc_id,"start_collect");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user