代码如下:
#include "zf_common_headfile.h"
#include "vofa.h"
uint8 f_temp[4];
uint8 vofa_tail[4] = {0x00, 0x00, 0x80, 0x7F};
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 vofa内置转换函数 float -> byte[4]
// 参数说明 float数据实参 ;用于接收转换后的数组 ,请提前初始化
// 返回参数 none
// 使用示例 float_to_byte(float_number , byte[4]);
// 备注信息 none
//-------------------------------------------------------------------------------------------------------------------
void inline float_to_byte(float f, uint8 byte[])
{
FloatLongType fl;
fl.fdata = f;
byte[0] = (uint8)fl.ldata;
byte[1] = (uint8)(fl.ldata >> 8);
byte[2] = (uint8)(fl.ldata >> 16);
byte[3] = (uint8)(fl.ldata >> 24);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 发送justfloat格式的数据帧流
// 参数说明 信道数 int channel_num ; 发送一组float数据
// 返回参数 none
// 使用示例 vofa_sending_data(int channel_num , f);
// 备注信息 none
//-------------------------------------------------------------------------------------------------------------------
void vofa_sending_data(int channelNum, float *vofaTemp)
{
uint8 f_temp[4];
uint8 vofa_tail[4];
vofa_tail[0] = 0X00;
vofa_tail[1] = 0X00;
vofa_tail[2] = 0X80;
vofa_tail[3] = 0X7f;
for (int channelCount = 0; channelCount < channelNum; channelCount++)
{
float_to_byte(vofaTemp[channelCount], f_temp);
/*------------attention------------*/
// 下方的发送函数可根据具体设备自行更换!
uart_write_buffer(UART_0, &f_temp[0], 4);
// seekfree_wireless_send_buffer(&f_temp, 4);
}
uart_write_buffer(UART_0, &vofa_tail[0], 4);
// uart_write_buffer(UART_0, &vofa_tail, 4);
// seekfree_wireless_send_buffer(&vofa_tail, 4);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 发送justfloat格式的数据
// 参数说明 一个float数据
// 返回参数 none
// 使用示例 vofa_sending_one_data(f);
// 备注信息 none
//-------------------------------------------------------------------------------------------------------------------
void inline vofa_sending_one_data(float vofaTemp)
{
float_to_byte(vofaTemp, f_temp);
/*------------attention------------*/
// 下方的发送函数可根据具体设备自行更换!
uart_write_buffer(UART_0, &f_temp[0], 4);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 发送justfloat格式的帧尾
// 参数说明 一个float数据
// 返回参数 none
// 使用示例 vofa_sending_one_data();
// 备注信息 none
//-------------------------------------------------------------------------------------------------------------------
void inline vofa_sending_tail(void)
{
uart_write_buffer(UART_0, &vofa_tail[0], 4);
}
#include "zf_common_headfile.h"
#ifndef _vofa_h
#define _vofa_h
typedef union
{
float fdata;
unsigned long ldata;
} FloatLongType;
void float_to_byte(float f, uint8 byte[]);
void vofa_sending_data(int channel_num, float f[]);
void vofa_sending_one_data(float vofaTemp);
void vofa_sending_tail(void);
#endif