mirror of
https://github.com/goldenfishs/MRobot.git
synced 2025-09-14 12:54:33 +08:00
大更新
This commit is contained in:
parent
d626e4e656
commit
f1c6b085a4
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@ -11,6 +11,12 @@
|
||||
"device.h": "c",
|
||||
"gpio.h": "c",
|
||||
"uart.h": "c",
|
||||
"motor_rm.h": "c"
|
||||
"motor_rm.h": "c",
|
||||
"mm.h": "c",
|
||||
"capacity.h": "c",
|
||||
"error_detect.h": "c",
|
||||
"bmi088.h": "c",
|
||||
"time.h": "c",
|
||||
"motor.h": "c"
|
||||
}
|
||||
}
|
BIN
assets/.DS_Store
vendored
BIN
assets/.DS_Store
vendored
Binary file not shown.
@ -1,12 +0,0 @@
|
||||
/*
|
||||
弹道补偿算法。
|
||||
*/
|
||||
|
||||
#include "ballistics.h"
|
||||
|
||||
void Ballistics_Init(Ballistics_t *b) { (void)b; }
|
||||
void Ballistics_Apply(Ballistics_t *b, float bullet_speed) {
|
||||
(void)b;
|
||||
(void)bullet_speed;
|
||||
}
|
||||
void Ballistics_Reset(Ballistics_t *b) { (void)b; }
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
弹道补偿算法。
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ahrs.h"
|
||||
|
||||
typedef struct {
|
||||
AHRS_Eulr_t *eulr;
|
||||
} Ballistics_t;
|
||||
|
||||
void Ballistics_Init(Ballistics_t *b);
|
||||
void Ballistics_Apply(Ballistics_t *b, float bullet_speed);
|
||||
void Ballistics_Reset(Ballistics_t *b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
剩余电量算法。
|
||||
|
||||
通过电压值计算剩余电量。
|
||||
*/
|
||||
|
||||
|
@ -11,7 +11,7 @@ extern "C" {
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ahrs.h"
|
||||
#include "component/ahrs.h"
|
||||
|
||||
#define CMD_REFEREE_MAX_NUM (3) /* 发送命令限定的最大数量 */
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
ahrs,component/user_math.h
|
||||
capacity,component/user_math.h
|
||||
cmd,component/ahrs
|
||||
error_detect,bsp/mm
|
||||
pid,component/filter
|
||||
ahrs,component/filter
|
||||
filter,component/ahrs
|
||||
filter,component/ahrs
|
||||
mixer,component/user_math.h
|
||||
ui,component/user_math.h
|
|
@ -1,2 +1,14 @@
|
||||
pid,好用的
|
||||
ahrs,开源的
|
||||
ahrs,开源的AHRS算法,MadgwickAHRS
|
||||
capacity,电池容量计算
|
||||
cmd,通用控制命令
|
||||
crc8,CRC8校验rm
|
||||
crc16,CRC16校验rm
|
||||
error_detect,错误检测
|
||||
filter,各类滤波器
|
||||
FreeRTOS_CLI,FreeRTOS命令行接口
|
||||
limiter,限幅器
|
||||
mixer,混控器
|
||||
ui,用户交互
|
||||
user_math,用户自定义数学函数
|
||||
pid,PID控制器
|
|
@ -1,4 +1,4 @@
|
||||
bsp,can,dwt,gpio,i2c,mm,spi,uart,pwm,time
|
||||
component,ahrs,ballistics,capacity,cmd,crc8,crc16,error_detect,filter,FreeRTOS_CLI,limiter,mixer,pid,ui,user_math
|
||||
component,ahrs,capacity,cmd,crc8,crc16,error_detect,filter,FreeRTOS_CLI,limiter,mixer,pid,ui,user_math
|
||||
device,dr16,bmi088,ist8310,motor,motor_rm,motor_vesc,motor_lk,motor_lz,motor_odrive,dm_imu,servo,buzzer,led,ws2812
|
||||
module,
|
|
BIN
assets/User_code/device/.DS_Store
vendored
BIN
assets/User_code/device/.DS_Store
vendored
Binary file not shown.
@ -1,6 +1,5 @@
|
||||
/*
|
||||
BMI088 陀螺仪+加速度计传感器。
|
||||
|
||||
BMI088 陀螺仪+加速度计传感器。
|
||||
*/
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
|
@ -79,7 +79,10 @@ devices:
|
||||
name: "VESC 电调"
|
||||
description: "VESC 电调驱动"
|
||||
dependencies:
|
||||
bsp: ["can", "time"]
|
||||
bsp: ["can", "time", "mm"]
|
||||
component: ["user_math"]
|
||||
thread_signals:
|
||||
- name: "SIGNAL_VESC_DATA_REDY"
|
||||
files:
|
||||
header: "motor_vesc.h"
|
||||
source: "motor_vesc.c"
|
||||
@ -88,7 +91,10 @@ devices:
|
||||
name: "ODrive 电机"
|
||||
description: "ODrive 电机驱动"
|
||||
dependencies:
|
||||
bsp: ["can", "time"]
|
||||
bsp: ["can", "time", "mm"]
|
||||
component: ["user_math"]
|
||||
thread_signals:
|
||||
- name: "SIGNAL_ODRIVE_DATA_REDY"
|
||||
files:
|
||||
header: "motor_odrive.h"
|
||||
source: "motor_odrive.c"
|
||||
@ -97,7 +103,10 @@ devices:
|
||||
name: "RM 电机"
|
||||
description: "RM 电机驱动"
|
||||
dependencies:
|
||||
bsp: ["can", "time"]
|
||||
bsp: ["can", "time", "mm"]
|
||||
component: ["user_math"]
|
||||
thread_signals:
|
||||
- name: "SIGNAL_RM_MOTOR_DATA_REDY"
|
||||
files:
|
||||
header: "motor_rm.h"
|
||||
source: "motor_rm.c"
|
||||
@ -105,6 +114,11 @@ devices:
|
||||
motor:
|
||||
name: "通用电机"
|
||||
description: "通用电机驱动"
|
||||
dependencies:
|
||||
bsp: []
|
||||
component: []
|
||||
bsp_requirements: []
|
||||
thread_signals: []
|
||||
files:
|
||||
header: "motor.h"
|
||||
source: "motor.c"
|
||||
@ -115,11 +129,91 @@ devices:
|
||||
dependencies:
|
||||
bsp: ["pwm", "time"]
|
||||
component: []
|
||||
bsp_requirements:
|
||||
- type: "pwm"
|
||||
var_name: "BSP_PWM_WS2812"
|
||||
description: "用于WS2812数据传输的PWM通道"
|
||||
thread_signals: []
|
||||
files:
|
||||
header: "ws2812.h"
|
||||
source: "ws2812.c"
|
||||
source: "ws2812.c"
|
||||
|
||||
buzzer:
|
||||
name: "蜂鸣器"
|
||||
description: "蜂鸣器驱动"
|
||||
dependencies:
|
||||
bsp: ["pwm"]
|
||||
component: []
|
||||
bsp_requirements:
|
||||
- type: "pwm"
|
||||
var_name: "BSP_PWM_BUZZER"
|
||||
description: "用于蜂鸣器的PWM通道"
|
||||
thread_signals: []
|
||||
files:
|
||||
header: "buzzer.h"
|
||||
source: "buzzer.c"
|
||||
|
||||
dm_imu:
|
||||
name: "DM IMU"
|
||||
description: "DM IMU 传感器"
|
||||
dependencies:
|
||||
bsp: ["can", "time"]
|
||||
component: ["user_math"]
|
||||
thread_signals:
|
||||
- name: "SIGNAL_DM_IMU_DATA_REDY"
|
||||
files:
|
||||
header: "dm_imu.h"
|
||||
source: "dm_imu.c"
|
||||
|
||||
led:
|
||||
name: "LED 灯"
|
||||
description: "LED 灯驱动"
|
||||
dependencies:
|
||||
bsp: ["gpio", "pwm"]
|
||||
component: []
|
||||
thread_signals: []
|
||||
files:
|
||||
header: "led.h"
|
||||
source: "led.c"
|
||||
|
||||
motor_lk:
|
||||
name: "LK 电机"
|
||||
description: "LK 电机驱动"
|
||||
dependencies:
|
||||
bsp: ["can", "time", "mm"]
|
||||
component: ["user_math"]
|
||||
thread_signals:
|
||||
- name: "SIGNAL_LK_MOTOR_DATA_REDY"
|
||||
files:
|
||||
header: "motor_lk.h"
|
||||
source: "motor_lk.c"
|
||||
|
||||
motor_lz:
|
||||
name: "LZ 电机"
|
||||
description: "LZ 电机驱动"
|
||||
dependencies:
|
||||
bsp: ["can", "time", "mm"]
|
||||
component: ["user_math"]
|
||||
thread_signals:
|
||||
- name: "SIGNAL_LZ_MOTOR_DATA_REDY"
|
||||
files:
|
||||
header: "motor_lz.h"
|
||||
source: "motor_lz.c"
|
||||
|
||||
servo:
|
||||
name: "舵机"
|
||||
description: "舵机驱动"
|
||||
dependencies:
|
||||
bsp: ["pwm"]
|
||||
component: []
|
||||
thread_signals: []
|
||||
files:
|
||||
header: "servo.h"
|
||||
source: "servo.c"
|
||||
|
||||
vofa:
|
||||
name: "VOFA"
|
||||
description: "VOFA 数据传输协议"
|
||||
dependencies:
|
||||
bsp: ["uart"]
|
||||
component: []
|
||||
thread_signals: []
|
||||
files:
|
||||
header: "vofa.h"
|
||||
source: "vofa.c"
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
DM_IMU数据获取
|
||||
DM_IMU数据获取(CAN)
|
||||
*/
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
DR16接收机
|
||||
DR16接收机
|
||||
*/
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
IST8310 地磁传感器。
|
||||
|
||||
IST8310 地磁传感器。
|
||||
*/
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
DR16接收机
|
||||
电机通用函数
|
||||
*/
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
@ -18,29 +18,17 @@
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
float MOTOR_GetRotorAbsAngle(const MOTOR_t *motor) {
|
||||
if (motor == NULL) return DEVICE_ERR_NULL;
|
||||
if (motor->reverse) {
|
||||
return -motor->feedback.rotor_abs_angle;
|
||||
}else{
|
||||
return motor->feedback.rotor_abs_angle;
|
||||
}
|
||||
motor->feedback.rotor_abs_angle;
|
||||
}
|
||||
|
||||
float MOTOR_GetRotorSpeed(const MOTOR_t *motor) {
|
||||
if (motor == NULL) return DEVICE_ERR_NULL;
|
||||
if (motor->reverse) {
|
||||
return -motor->feedback.rotor_speed;
|
||||
}else{
|
||||
return motor->feedback.rotor_speed;
|
||||
}
|
||||
return motor->feedback.rotor_speed;
|
||||
}
|
||||
|
||||
float MOTOR_GetTorqueCurrent(const MOTOR_t *motor) {
|
||||
if (motor == NULL) return DEVICE_ERR_NULL;
|
||||
if (motor->reverse) {
|
||||
return -motor->feedback.torque_current;
|
||||
}else{
|
||||
return motor->feedback.torque_current;
|
||||
}
|
||||
return motor->feedback.torque_current;
|
||||
}
|
||||
|
||||
float MOTOR_GetTemp(const MOTOR_t *motor) {
|
||||
|
@ -1,10 +1,5 @@
|
||||
/*
|
||||
灵足电机驱动
|
||||
|
||||
灵足电机通信协议:
|
||||
- CAN 2.0通信接口,波特率1Mbps
|
||||
- 采用扩展帧格式(29位ID)
|
||||
- ID格式:Bit28~24(通信类型) + Bit23~8(数据区2) + Bit7~0(目标地址)
|
||||
*/
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include "motor_lz.h"
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
CAN总线上的设备
|
||||
将所有CAN总线上挂载的设备抽象成一个设备进行配置和控制
|
||||
Odrive电机驱动
|
||||
*/
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include "motor_odrive.h"
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
CAN总线上的设备
|
||||
将所有CAN总线上挂载的设备抽象成一个设备进行配置和控制
|
||||
RM电机驱动
|
||||
*/
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include "motor_rm.h"
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
CAN总线上的设备
|
||||
将所有CAN总线上挂载的设备抽象成一个设备进行配置和控制
|
||||
VESC电机驱动
|
||||
*/
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include "motor_vesc.h"
|
||||
|
@ -20,125 +20,125 @@ extern "C"
|
||||
// VESC数量根据实际情况调整
|
||||
#define VESC_MAX_MOTORS 4
|
||||
|
||||
/* Exported constants ------------------------------------------------------- */
|
||||
/* Exported constants ------------------------------------------------------- */
|
||||
|
||||
/* Exported macro ----------------------------------------------------------- */
|
||||
/* Exported types ----------------------------------------------------------- */
|
||||
/* Exported macro ----------------------------------------------------------- */
|
||||
/* Exported types ----------------------------------------------------------- */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
VESC_1 = 1,
|
||||
VESC_2 = 2,
|
||||
VESC_3 = 3,
|
||||
VESC_4 = 4,
|
||||
CAN_VESC5065_M1_MSG1 = 0x901, // vesc的数据回传使用了扩展id,[0:7]为驱动器id,[8:15]为帧类型
|
||||
CAN_VESC5065_M2_MSG1 = 0x902,
|
||||
CAN_VESC5065_M3_MSG1 = 0x903,
|
||||
CAN_VESC5065_M4_MSG1 = 0x904,
|
||||
}VESC_ID;
|
||||
typedef enum
|
||||
{
|
||||
VESC_1 = 1,
|
||||
VESC_2 = 2,
|
||||
VESC_3 = 3,
|
||||
VESC_4 = 4,
|
||||
CAN_VESC5065_M1_MSG1 = 0x901, // vesc的数据回传使用了扩展id,[0:7]为驱动器id,[8:15]为帧类型
|
||||
CAN_VESC5065_M2_MSG1 = 0x902,
|
||||
CAN_VESC5065_M3_MSG1 = 0x903,
|
||||
CAN_VESC5065_M4_MSG1 = 0x904,
|
||||
}VESC_ID;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CAN_PACKET_SET_DUTY = 0,
|
||||
CAN_PACKET_SET_CURRENT = 1,
|
||||
CAN_PACKET_SET_CURRENT_BRAKE = 2,
|
||||
CAN_PACKET_SET_RPM = 3,
|
||||
CAN_PACKET_SET_POS = 4,
|
||||
CAN_PACKET_FILL_RX_BUFFER = 5,
|
||||
CAN_PACKET_FILL_RX_BUFFER_LONG = 6,
|
||||
CAN_PACKET_PROCESS_RX_BUFFER = 7,
|
||||
CAN_PACKET_PROCESS_SHORT_BUFFER = 8,
|
||||
CAN_PACKET_STATUS = 9,
|
||||
CAN_PACKET_SET_CURRENT_REL = 10,
|
||||
CAN_PACKET_SET_CURRENT_BRAKE_REL = 11,
|
||||
CAN_PACKET_SET_CURRENT_HANDBRAKE = 12,
|
||||
CAN_PACKET_SET_CURRENT_HANDBRAKE_REL = 13
|
||||
} CAN_PACKET_ID;
|
||||
typedef enum
|
||||
{
|
||||
CAN_PACKET_SET_DUTY = 0,
|
||||
CAN_PACKET_SET_CURRENT = 1,
|
||||
CAN_PACKET_SET_CURRENT_BRAKE = 2,
|
||||
CAN_PACKET_SET_RPM = 3,
|
||||
CAN_PACKET_SET_POS = 4,
|
||||
CAN_PACKET_FILL_RX_BUFFER = 5,
|
||||
CAN_PACKET_FILL_RX_BUFFER_LONG = 6,
|
||||
CAN_PACKET_PROCESS_RX_BUFFER = 7,
|
||||
CAN_PACKET_PROCESS_SHORT_BUFFER = 8,
|
||||
CAN_PACKET_STATUS = 9,
|
||||
CAN_PACKET_SET_CURRENT_REL = 10,
|
||||
CAN_PACKET_SET_CURRENT_BRAKE_REL = 11,
|
||||
CAN_PACKET_SET_CURRENT_HANDBRAKE = 12,
|
||||
CAN_PACKET_SET_CURRENT_HANDBRAKE_REL = 13
|
||||
} CAN_PACKET_ID;
|
||||
|
||||
// Control Modes
|
||||
typedef enum
|
||||
{
|
||||
DUTY_CONTROL = 0x0,
|
||||
RPM_CONTROL = 0x1,
|
||||
CURRENT_CONTROL = 0x2,
|
||||
POSITION_CONTROL = 0x3
|
||||
} Control_Mode;
|
||||
// Control Modes
|
||||
typedef enum
|
||||
{
|
||||
DUTY_CONTROL = 0x0,
|
||||
RPM_CONTROL = 0x1,
|
||||
CURRENT_CONTROL = 0x2,
|
||||
POSITION_CONTROL = 0x3
|
||||
} Control_Mode;
|
||||
|
||||
/*每个电机需要的参数*/
|
||||
typedef struct
|
||||
{
|
||||
BSP_CAN_t can;
|
||||
uint16_t id;
|
||||
uint16_t mode;
|
||||
bool reverse;
|
||||
} VESC_Param_t;
|
||||
/*每个电机需要的参数*/
|
||||
typedef struct
|
||||
{
|
||||
BSP_CAN_t can;
|
||||
uint16_t id;
|
||||
uint16_t mode;
|
||||
bool reverse;
|
||||
} VESC_Param_t;
|
||||
|
||||
/*电机实例*/
|
||||
typedef struct ODrive_t
|
||||
{
|
||||
VESC_Param_t param;
|
||||
MOTOR_t motor;
|
||||
} VESC_t;
|
||||
/*电机实例*/
|
||||
typedef struct ODrive_t
|
||||
{
|
||||
VESC_Param_t param;
|
||||
MOTOR_t motor;
|
||||
} VESC_t;
|
||||
|
||||
/*CAN管理器,管理一个CAN总线上所有的电机*/
|
||||
typedef struct
|
||||
{
|
||||
BSP_CAN_t can;
|
||||
VESC_t *motors[VESC_MAX_MOTORS];
|
||||
uint8_t motor_count;
|
||||
} VESC_CANManager_t;
|
||||
/*CAN管理器,管理一个CAN总线上所有的电机*/
|
||||
typedef struct
|
||||
{
|
||||
BSP_CAN_t can;
|
||||
VESC_t *motors[VESC_MAX_MOTORS];
|
||||
uint8_t motor_count;
|
||||
} VESC_CANManager_t;
|
||||
|
||||
/* Exported functions prototypes -------------------------------------------- */
|
||||
/* Exported functions prototypes -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief 注册一个vesc电机
|
||||
* @param param 电机参数
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_Register(VESC_Param_t *param);
|
||||
/**
|
||||
* @brief 注册一个vesc电机
|
||||
* @param param 电机参数
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_Register(VESC_Param_t *param);
|
||||
|
||||
/**
|
||||
* @brief 更新指定电机数据
|
||||
* @param param 电机参数
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_Update(VESC_Param_t *param);
|
||||
/**
|
||||
* @brief 更新指定电机数据
|
||||
* @param param 电机参数
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_Update(VESC_Param_t *param);
|
||||
|
||||
/**
|
||||
* @brief 更新所有电机数据
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_UpdateAll(void);
|
||||
|
||||
/**
|
||||
* @brief 设置一个电机的输出
|
||||
* @param param 电机参数
|
||||
* @param value 输出值
|
||||
* @return
|
||||
*/
|
||||
/**
|
||||
* @brief 更新所有电机数据
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_UpdateAll(void);
|
||||
|
||||
int8_t VESC_SetOutput(VESC_Param_t *param, float value);
|
||||
/**
|
||||
* @brief 设置一个电机的输出
|
||||
* @param param 电机参数
|
||||
* @param value 输出值
|
||||
* @return
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief 获取指定电机的实例指针
|
||||
* @param param 电机参数
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_SetOutput(VESC_Param_t *param, float value);
|
||||
|
||||
VESC_t* VESC_GetMotor(VESC_Param_t *param);
|
||||
/**
|
||||
* @brief 获取指定电机的实例指针
|
||||
* @param param 电机参数
|
||||
* @return
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief 使电机松弛(设置输出为0)
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_Relax(VESC_Param_t *param);
|
||||
/**
|
||||
* @brief 使电机离线(设置在线状态为false)
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_Offine(VESC_Param_t *param);
|
||||
VESC_t* VESC_GetMotor(VESC_Param_t *param);
|
||||
|
||||
/**
|
||||
* @brief 使电机松弛(设置输出为0)
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_Relax(VESC_Param_t *param);
|
||||
/**
|
||||
* @brief 使电机离线(设置在线状态为false)
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
int8_t VESC_Offine(VESC_Param_t *param);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,14 +1,10 @@
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "vofa.h"
|
||||
#include "device/vofa.h"
|
||||
#include "bsp/uart.h"
|
||||
/* Private define ----------------------------------------------------------- */
|
||||
|
||||
//#define PROTOCOL_RAWDATA
|
||||
#define PROTOCOL_FIREWATER
|
||||
//#define PROTOCOL_JUSTFLOAT
|
||||
|
||||
#define MAX_CHANNEL 64u // 根据实际最大通道数调整
|
||||
|
||||
#define JUSTFLOAT_TAIL 0x7F800000
|
||||
@ -16,6 +12,7 @@
|
||||
/* Private typedef ---------------------------------------------------------- */
|
||||
/* Private variables -------------------------------------------------------- */
|
||||
static uint8_t vofa_tx_buf[sizeof(float) * MAX_CHANNEL + sizeof(uint32_t)];
|
||||
static VOFA_Protocol_t current_protocol = VOFA_PROTOCOL_FIREWATER; // ĬÈÏÐÒé
|
||||
|
||||
/* Private function -------------------------------------------------------- */
|
||||
|
||||
@ -59,19 +56,34 @@ void VOFA_JustFloat_Send(float *channels, uint8_t channel_count, bool dma)
|
||||
}
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
init8_t VOFA_Send(float* channels, uint8_t channel_count, bool dma) {
|
||||
#ifdef PROTOCOL_RAWDATA
|
||||
sprintf(vofa_tx_buf, "Channel1:%.2f,Channel2:%.2f\n", channels[0],channels[1]);
|
||||
VOFA_RawData_Send(vofa_tx_buf, dma);
|
||||
#elif defined(PROTOCOL_FIREWATER)
|
||||
VOFA_FireWater_Send(channels, channel_count, dma);
|
||||
#elif defined(PROTOCOL_JUSTFLOAT)
|
||||
VOFA_JustFloat_Send(channels, channel_count, dma);
|
||||
#else
|
||||
// ĬÈÏʹÓÃRawDataÐÒé
|
||||
char data[256];
|
||||
sprintf(data, "Channel1: %.2f, Channel2: %.2f\n", channels[0], channels[1]);
|
||||
VOFA_RawData_Send(data, dma);
|
||||
#endif
|
||||
int8_t VOFA_init(VOFA_Protocol_t protocol) {
|
||||
current_protocol = protocol;
|
||||
return DEVICE_OK;
|
||||
}
|
||||
|
||||
int8_t VOFA_Send(float* channels, uint8_t channel_count, bool dma) {
|
||||
switch (current_protocol) {
|
||||
case VOFA_PROTOCOL_RAWDATA:
|
||||
{
|
||||
char data[256];
|
||||
if (channel_count >= 1) {
|
||||
sprintf(data, "Channel1: %.2f", channels[0]);
|
||||
if (channel_count >= 2) {
|
||||
sprintf(data + strlen(data), ", Channel2: %.2f", channels[1]);
|
||||
}
|
||||
strcat(data, "\n");
|
||||
VOFA_RawData_Send(data, dma);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case VOFA_PROTOCOL_FIREWATER:
|
||||
VOFA_FireWater_Send(channels, channel_count, dma);
|
||||
break;
|
||||
case VOFA_PROTOCOL_JUSTFLOAT:
|
||||
VOFA_JustFloat_Send(channels, channel_count, dma);
|
||||
break;
|
||||
default:
|
||||
return DEVICE_ERR;
|
||||
}
|
||||
return DEVICE_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user