差气压计的蓝牙协议
This commit is contained in:
@ -56,8 +56,7 @@ extern void close_process(u16* pid,char* name);
|
||||
|
||||
typedef struct {
|
||||
// -- 六轴 --
|
||||
signed short acc_data[3];
|
||||
signed short gyr_data[3];
|
||||
signed short SC7U22_data[6];
|
||||
// -- 磁力计 --
|
||||
uint8_t mmc5603nj_buffer[9];
|
||||
// -- 速度 --
|
||||
@ -88,7 +87,11 @@ void SC7U22_static_calibration(void){
|
||||
static signed short combined_raw_data[6];
|
||||
static int calibration_done = 0;
|
||||
char status = 0;
|
||||
set_SC7U22_Error_Flag(0);
|
||||
static first_set_flag = 0;
|
||||
if(first_set_flag == 0){
|
||||
first_set_flag = 1;
|
||||
set_SC7U22_Error_Flag(0);
|
||||
}
|
||||
SL_SC7U22_RawData_Read(acc_data_buf,gyr_data_buf);
|
||||
memcpy(&combined_raw_data[0], acc_data_buf, 3 * sizeof(signed short));
|
||||
memcpy(&combined_raw_data[3], gyr_data_buf, 3 * sizeof(signed short));
|
||||
@ -97,20 +100,21 @@ void SC7U22_static_calibration(void){
|
||||
if(status == 1){ //校准完成
|
||||
extern u16 SC7U22_calibration_id;
|
||||
extern u8 SC7U22_init;
|
||||
first_set_flag = 0;
|
||||
SC7U22_init = 1;
|
||||
close_process(&SC7U22_calibration_id, "SC7U22_calibration");
|
||||
u8 send2_1[5] = {0xBB,0xBE,0x02,0x00,0x01};
|
||||
send_data_to_ble_client(&send2_1,strlen(send2_1));
|
||||
send_data_to_ble_client(&send2_1,5);
|
||||
}
|
||||
// if(count > 100){
|
||||
// count = 0;
|
||||
// char log_buffer[100];
|
||||
// // snprintf( log_buffer, sizeof(log_buffer),"status:%d\n",status);
|
||||
// // send_data_to_ble_client(&log_buffer,strlen(log_buffer));
|
||||
// xlog("status:%d\n", status);
|
||||
// xlog("RawData:AX=%d,AY=%d,AZ=%d,GX=%d,GY=%d,GZ=%d\r\n",combined_raw_data[0],combined_raw_data[1],combined_raw_data[2],combined_raw_data[3],combined_raw_data[4],combined_raw_data[5]);
|
||||
// }
|
||||
// count++;
|
||||
if(count > 100){
|
||||
count = 0;
|
||||
char log_buffer[100];
|
||||
// snprintf( log_buffer, sizeof(log_buffer),"status:%d\n",status);
|
||||
// send_data_to_ble_client(&log_buffer,strlen(log_buffer));
|
||||
xlog("status:%d\n", status);
|
||||
xlog("RawData:AX=%d,AY=%d,AZ=%d,GX=%d,GY=%d,GZ=%d\r\n",combined_raw_data[0],combined_raw_data[1],combined_raw_data[2],combined_raw_data[3],combined_raw_data[4],combined_raw_data[5]);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,8 +147,8 @@ void start_collect_fuc(void){
|
||||
uint16_t speed = sensor_processing_task(acc_data_buf,gyr_data_buf,angle, quaternion_output);
|
||||
|
||||
// -- 数据包装进结构体 --
|
||||
memcpy(BLE_send_data_tmp.acc_data, acc_data_buf, 3 * sizeof(signed short));
|
||||
memcpy(BLE_send_data_tmp.gyr_data, gyr_data_buf, 3 * sizeof(signed short));
|
||||
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.speed_cms = speed;
|
||||
|
||||
@ -157,17 +161,83 @@ void start_collect_fuc(void){
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ble数据发送
|
||||
* @brief ble数据发送函数
|
||||
*
|
||||
*/
|
||||
void BLE_send_fuc(void){
|
||||
BLE_send_data_t BLE_send_data_tmp;
|
||||
if(circle_buffer_is_empty(&BLE_send_buff) == 0){
|
||||
circle_buffer_read(&BLE_send_buff, &BLE_send_data_tmp);
|
||||
BLE_send_data_t data_to_send;
|
||||
|
||||
if (circle_buffer_is_empty(&BLE_send_buff) == 0) {
|
||||
circle_buffer_read(&BLE_send_buff, &data_to_send);
|
||||
} else {
|
||||
// 缓冲区为空,直接返回
|
||||
return;
|
||||
}
|
||||
|
||||
// --- 封装并发送六轴传感器数据 ---
|
||||
{
|
||||
// 协议定义: 包头(2) + 长度(1) + 类型(1) + 数据(12) = 16字节
|
||||
const uint8_t IMU_PACKET_LEN = 16;
|
||||
const uint8_t IMU_PAYLOAD_LEN = 13; // 类型(1) + 数据(12)
|
||||
const uint8_t IMU_TYPE = 0x01;
|
||||
|
||||
uint8_t imu_packet[IMU_PACKET_LEN];
|
||||
|
||||
// 填充包头
|
||||
imu_packet[0] = 0xBB;
|
||||
imu_packet[1] = 0xBE;
|
||||
imu_packet[2] = IMU_PAYLOAD_LEN;
|
||||
imu_packet[3] = IMU_TYPE;
|
||||
// 拷贝六轴数据
|
||||
memcpy(&imu_packet[4], data_to_send.SC7U22_data, sizeof(data_to_send.SC7U22_data));
|
||||
|
||||
send_data_to_ble_client(&imu_packet, IMU_PACKET_LEN);
|
||||
}
|
||||
|
||||
// --- 封装并发送磁力计数据 ---
|
||||
{
|
||||
// 协议定义: 包头(2) + 长度(1) + 类型(1) + 数据(9) = 13字节
|
||||
const uint8_t MAG_PACKET_LEN = 13;
|
||||
const uint8_t MAG_PAYLOAD_LEN = 10; // 类型(1) + 数据(9)
|
||||
const uint8_t MAG_TYPE = 0x02;
|
||||
|
||||
uint8_t mag_packet[MAG_PACKET_LEN];
|
||||
|
||||
// 填充包头
|
||||
mag_packet[0] = 0xBB;
|
||||
mag_packet[1] = 0xBE;
|
||||
mag_packet[2] = MAG_PAYLOAD_LEN;
|
||||
mag_packet[3] = MAG_TYPE;
|
||||
// 拷贝磁力计数据
|
||||
memcpy(&mag_packet[4], data_to_send.mmc5603nj_buffer, sizeof(data_to_send.mmc5603nj_buffer));
|
||||
|
||||
// 调用实际的蓝牙发送函数
|
||||
send_data_to_ble_client(&mag_packet, MAG_PACKET_LEN);
|
||||
}
|
||||
|
||||
// --- 封装并发送速度数据 ---
|
||||
{
|
||||
// 协议定义: 包头(2) + 长度(1) + 类型(1) + 数据(2) = 6字节
|
||||
const uint8_t SPEED_PACKET_LEN = 6;
|
||||
const uint8_t SPEED_PAYLOAD_LEN = 3; // 类型(1) + 数据(2)
|
||||
const uint8_t SPEED_TYPE = 0x04;
|
||||
|
||||
uint8_t speed_packet[SPEED_PACKET_LEN];
|
||||
|
||||
// 填充包头
|
||||
speed_packet[0] = 0xBB;
|
||||
speed_packet[1] = 0xBE;
|
||||
// 填充长度
|
||||
speed_packet[2] = SPEED_PAYLOAD_LEN;
|
||||
// 填充类型
|
||||
speed_packet[3] = SPEED_TYPE;
|
||||
|
||||
// 小端模式
|
||||
speed_packet[4] = (uint8_t)(data_to_send.speed_cms & 0xFF); // 低字节
|
||||
speed_packet[5] = (uint8_t)((data_to_send.speed_cms >> 8) & 0xFF); // 高字节
|
||||
|
||||
send_data_to_ble_client(&speed_packet, SPEED_PACKET_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user