vofa通讯协议源码-justfloat

代码如下:

#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

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值