编辑
2024-05-22
测试数据
0

目录

类型转换
byte转float
数据处理
FIFO

类型转换

byte转float

C#
byte[] byteArray = { 0xcd, 0xcc, 0x68, 0x43 }; //232.8 float floatnum=BitConverter.ToSingle(byteArray, 0);//232.8
C
//ESP8266 u8 byteArray[] = { 0xcd, 0xcc, 0x68, 0x43 }; //232.8 float floatnum=0; os_memcpy(&floatnum,byteArray,4); os_printf("floatnum%lf\r\n",floatnum);

数据处理

FIFO

C
#include "fifo.h" #include "math.h" #include <stdlib.h> void FIFO_SAVE(fifo_TypeDef* fifo_name,u8 data) { fifo_name->timer=0; fifo_name->data[fifo_name->write_cnt]=data; fifo_name->write_cnt++; if(fifo_name->write_cnt>(FIFO_SIZE-2)) { fifo_name->write_cnt=0; } } u8 FIFO_READ(fifo_TypeDef* fifo_name) { u8 data; data = fifo_name->data[fifo_name->read_cnt]; fifo_name->read_cnt++; if(fifo_name->read_cnt>(FIFO_SIZE-2)) { fifo_name->read_cnt=0; } return data; } void FIFO_TIMER(fifo_TypeDef* fifo_name) { if(fifo_name->timer<1000) { fifo_name->timer++; } } void FIFO_INIT(fifo_TypeDef* fifo_name) { memset(fifo_name->data,0,sizeof(fifo_name->data)); fifo_name->write_cnt=0; fifo_name->read_cnt=0; } u8 FIFO_IS_NULL(fifo_TypeDef* fifo_name) { if(fifo_name->read_cnt==fifo_name->write_cnt) { return 0; } else { return 1; } }

本文作者:Kellermen

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!