wf282A读数有问题
This commit is contained in:
@ -178,15 +178,15 @@ void sensor_collect_task(void){
|
||||
send_data.sensor_package[i].pressure = (int32_t)(pressure * 1000.0f);
|
||||
}
|
||||
|
||||
// xlog("temperature: %.2f,pressure: %.2f\n",temperature,pressure);
|
||||
xlog("temperature: %.2f,pressure: %.2f\n",temperature,pressure);
|
||||
// xlog("fifo_num:%d\n",fifo_num);
|
||||
|
||||
send_data.checkout_1 = 0xBE;
|
||||
send_data.checkout_2 = 0xBB;
|
||||
send_data.foot = foot_init;
|
||||
send_data.package_index = package_index;
|
||||
circle_buffer_write(&g_ble_send_cb, &send_data);
|
||||
os_sem_post(&receiver_ready_sem); //通知另一个发送任务
|
||||
// circle_buffer_write(&g_ble_send_cb, &send_data);
|
||||
// os_sem_post(&receiver_ready_sem); //通知另一个发送任务
|
||||
|
||||
memset(&send_data, 0, sizeof(ble_send_data_t));
|
||||
memset(&accx_buf, 0, sizeof(accx_buf));
|
||||
@ -446,59 +446,14 @@ static OS_SEM ble_send_sem;
|
||||
|
||||
|
||||
int j = 0;
|
||||
void data_send_task(void){
|
||||
signed short accx_buf[100];
|
||||
signed short accy_buf[100];
|
||||
signed short accz_buf[100];
|
||||
signed short gyrx_buf[100];
|
||||
signed short gyry_buf[100];
|
||||
signed short gyrz_buf[100];
|
||||
SL_SC7U22_FIFO_Read(accx_buf,accy_buf,accz_buf,gyrx_buf,gyry_buf,gyrz_buf); //一次性读取内置fifo的数据
|
||||
|
||||
#if 1
|
||||
// 定义新的Packet ID和数据长度
|
||||
#define PACKET_ID_RAW_IMU 0x04
|
||||
#define PACKET_LENGTH_RAW_IMU 12 // 6个传感器值,每个2字节
|
||||
|
||||
// 声明一个发送缓冲区,用于包含帧头、ID、长度、数据和校验和
|
||||
// 帧头 (2) + ID (1) + 长度 (1) + 数据 (12) + 校验和 (1) = 17 字节
|
||||
uint8_t tx_buffer[2 + 1 + 1 + PACKET_LENGTH_RAW_IMU + 1];
|
||||
uint8_t checksum = 0;
|
||||
int i; // 用于循环计算校验和
|
||||
|
||||
// 填充帧头
|
||||
tx_buffer[0] = 0xAA;
|
||||
tx_buffer[1] = 0xFF;
|
||||
|
||||
// 填充Packet ID和长度
|
||||
tx_buffer[2] = PACKET_ID_RAW_IMU;
|
||||
tx_buffer[3] = PACKET_LENGTH_RAW_IMU;
|
||||
|
||||
// 填充原始传感器数据 (与你原先的processing_data内容相同)
|
||||
tx_buffer[4] = (uint8_t)(accx_buf[0] & 0xFF); // accX LSB
|
||||
tx_buffer[5] = (uint8_t)(accx_buf[0] >> 8 & 0xFF); // accX MSB
|
||||
tx_buffer[6] = (uint8_t)(accy_buf[0] & 0xFF); // accY LSB
|
||||
tx_buffer[7] = (uint8_t)(accy_buf[0] >> 8 & 0xFF); // accY MSB
|
||||
tx_buffer[8] = (uint8_t)(accz_buf[0] & 0xFF); // accZ LSB
|
||||
tx_buffer[9] = (uint8_t)(accz_buf[0] >> 8 & 0xFF); // accZ MSB
|
||||
tx_buffer[10] = (uint8_t)(gyrx_buf[0] & 0xFF); // gyrX LSB
|
||||
tx_buffer[11] = (uint8_t)(gyrx_buf[0] >> 8 & 0xFF); // gyrX MSB
|
||||
tx_buffer[12] = (uint8_t)(gyry_buf[0] & 0xFF); // gyrY LSB
|
||||
tx_buffer[13] = (uint8_t)(gyry_buf[0] >> 8 & 0xFF); // gyrY MSB
|
||||
tx_buffer[14] = (uint8_t)(gyrz_buf[0] & 0xFF); // gyrZ LSB
|
||||
tx_buffer[15] = (uint8_t)(gyrz_buf[0] >> 8 & 0xFF); // gyrZ MSB
|
||||
|
||||
// 计算校验和 (从 Packet ID 到所有数据字节的和)
|
||||
checksum = tx_buffer[2] + tx_buffer[3]; // ID + Length
|
||||
for (i = 0; i < PACKET_LENGTH_RAW_IMU; i++) {
|
||||
checksum += tx_buffer[4 + i]; // 加上所有数据字节
|
||||
void sensor_test_task(void){
|
||||
float temperature = 0;
|
||||
float pressure = 0;
|
||||
while(1){
|
||||
WF_GET_Temperature_Pressure(&temperature, &pressure);
|
||||
xlog("temperature: %.3f,pressure: %.3f\n",temperature,pressure);
|
||||
os_time_dly(100);
|
||||
}
|
||||
tx_buffer[4 + PACKET_LENGTH_RAW_IMU] = checksum; // 校验和是最后一个字节
|
||||
|
||||
// 发送整个缓冲区
|
||||
extern void uartSendData(void *buf, u16 len) ; // 确保u16是uint16_t或unsigned short
|
||||
uartSendData(tx_buffer, sizeof(tx_buffer)); // 发送总共17字节
|
||||
#endif
|
||||
|
||||
}
|
||||
static u16 gtest_id = 0;
|
||||
@ -521,9 +476,9 @@ void test_func(void){
|
||||
#else
|
||||
WF_Init();
|
||||
#endif
|
||||
os_task_create(BLE_send_fuc,NULL,5,1024,32,"BLE_send_fuc");
|
||||
os_task_create(sensor_collect_task,NULL,5,1024,32,"sensor_collect_task");
|
||||
// create_process(&test_id, "sensor_test",NULL,data_send_task ,3);
|
||||
// os_task_create(BLE_send_fuc,NULL,5,1024,32,"BLE_send_fuc");
|
||||
// os_task_create(sensor_collect_task,NULL,5,1024,32,"sensor_collect_task");
|
||||
os_task_create(sensor_test_task,NULL,5,1024,32,"sensor_test");
|
||||
// data_send_task();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user