@ -29,6 +29,7 @@
# include "asm/rtc.h"
# include "system/timer.h"
# include "adv_time_stamp_setting.h"
# include "btstack/le/le_user.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
//宏定义
# define ENABLE_XLOG 1
@ -433,20 +434,128 @@ void xtell_task_create(void){
//test
//
void bmp280_test ( void ) {
/**
* @brief 开始采集传感器数据和计算速度
*
*/
void sensor_task ( void ) {
while ( 1 ) {
// xlog("=======sensor_read_data START\n");
static signed short combined_raw_data [ 6 ] ;
static int initialized = 0 ;
static int calibration_done = 0 ;
char status = 0 ;
BLE_send_data_t BLE_send_data_tmp ;
uint8_t mmc5603nj_buffer [ 9 ] ;
signed short acc_data_buf [ 3 ] ;
signed short gyr_data_buf [ 3 ] ;
float angle [ 3 ] ;
float quaternion_output [ 3 ] ;
float temperature = 0 ;
float pressure = 0 ;
// -- 读数据 --
SL_SC7U22_RawData_Read ( acc_data_buf , gyr_data_buf ) ;
mmc5603nj_read_origin_data ( mmc5603nj_buffer ) ;
// bmp280_read_originanl_data(&BLE_send_data_tmp.adc_P, &BLE_send_data_tmp.adc_T);
bmp280_read_data ( & temperature , & pressure ) ;
memcpy ( & combined_raw_data [ 0 ] , acc_data_buf , 3 * sizeof ( signed short ) ) ;
memcpy ( & combined_raw_data [ 3 ] , gyr_data_buf , 3 * sizeof ( signed short ) ) ;
// -- 四元数 --
status = Q_SL_SC7U22_Angle_Output ( 0 , combined_raw_data , angle , NULL , 0 , quaternion_output ) ;
// -- 速度计算 --
memcpy ( acc_data_buf , & combined_raw_data [ 0 ] , 3 * sizeof ( signed short ) ) ;
memcpy ( gyr_data_buf , & combined_raw_data [ 3 ] , 3 * sizeof ( signed short ) ) ;
uint16_t speed = sensor_processing_task ( acc_data_buf , gyr_data_buf , angle , quaternion_output ) ;
// -- 数据包装进结构体 --
memcpy ( & BLE_send_data_tmp . SC7U22_data [ 0 ] , acc_data_buf , 3 * sizeof ( signed short ) ) ;
memcpy ( & BLE_send_data_tmp . SC7U22_data [ 3 ] , gyr_data_buf , 3 * sizeof ( signed short ) ) ;
memcpy ( BLE_send_data_tmp . mmc5603nj_buffer , mmc5603nj_buffer , 9 ) ;
BLE_send_data_tmp . temperature = ( int16_t ) ( temperature * 1000.0f ) ;
BLE_send_data_tmp . pressure = ( int32_t ) ( pressure * 1000.0f ) ;
BLE_send_data_tmp . speed_cms = speed ;
extern u8 foot_init ;
BLE_send_data_tmp . foot_state = foot_init ;
BLE_send_data_tmp . timestamp_ms = get_ms_timer ( ) ;
// -- 放进缓冲区 --
if ( circle_buffer_is_full ( & BLE_send_buff ) = = 0 ) {
circle_buffer_write ( & BLE_send_buff , & BLE_send_data_tmp ) ;
}
// xlog("=======sensor_read_data END\n");
os_time_dly ( 1 ) ;
}
}
# define BUFF_LEN 500
static signed char acc_data_buf [ BUFF_LEN ] = { 0 } ;
// 1. 定义一个全局的信号量
static OS_SEM ble_send_sem ;
void on_ble_can_send ( void ) {
os_sem_post ( & ble_send_sem ) ;
}
int j = 0 ;
void data_send_task ( void ) {
while ( 1 ) {
// 等待“发送许可”信号量,如果没许可,任务会在此阻塞
// os_sem_pend(&ble_send_sem, 1);
// static signed char acc_data_buf[60] = {
// 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22
// };
acc_data_buf [ 1 ] = ( uint8_t ) ( j & 0xFF ) ;
acc_data_buf [ 2 ] = ( uint8_t ) ( j > > 8 & 0xFF ) ;
acc_data_buf [ 3 ] = ( uint8_t ) ( j > > 16 & 0xFF ) ;
acc_data_buf [ 4 ] = ( uint8_t ) ( j > > 24 & 0xFF ) ;
acc_data_buf [ 0 ] = 0xAA ;
send_data_to_ble_client ( & acc_data_buf , 500 ) ;
// acc_data_buf[0] = 0xBB;
// send_data_to_ble_client(&acc_data_buf, 500);
// acc_data_buf[0] = 0xCC;
// send_data_to_ble_client(&acc_data_buf, 500);
// acc_data_buf[0] = 0xDD;
// send_data_to_ble_client(&acc_data_buf, 500);
void gsensor_test ( void ) {
# if 1
signed short acc_data_buf [ 3 ] ;
signed short gyr_data_buf [ 3 ] ;
SL_SC7U22_RawData_Read ( acc_data_buf , gyr_data_buf ) ;
# endif
// static signed char acc_data_buf[20] = {
// 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
// };
// send_data_to_ble_client(&acc_data_buf, 20);
// send_data_to_ble_client(&acc_data_buf, 20);
// send_data_to_ble_client(&acc_data_buf, 20);
// xlog("===========time:%d\n",get_ms_timer());
j + + ;
os_time_dly ( 4 ) ; //10ms单位
}
}
static u16 gtest_id = 0 ;
void test_func ( void ) {
create_process ( & gtest_id , " gtest_id " , NULL , gsensor_test , 1000 ) ;
// a. 初始化信号量, 初始值为0
// os_sem_create(&ble_send_sem, 0);
// b. 注册回调函数,让协议栈知道在准备好时该调用谁
// struct ble_server_operation_t *ble_ops;
// ble_get_server_operation_table(&ble_ops);
// ble_ops->regist_wakeup_send(NULL, on_ble_can_send);
for ( int i = 0 ; i < BUFF_LEN ; i + + ) {
acc_data_buf [ i ] = i ;
}
os_task_create ( data_send_task , NULL , 5 , 1024 , 32 , " data_send_task " ) ;
// data_send_task();
}