#include "robot_tx.h"

void tx_robot_data(uint8_t heartbeat,uint8_t breath ,uint8_t pressure_H,uint8_t pressure_L,uint8_t spo2, float temperature)
{
	uint8_t temperature_H=0, temperature_L=0 ;
	int i=0 ;
	
			temperature_H=((int)(temperature*10))/256; //高八位
			temperature_L=((int)(temperature*10))%256;; //低八位
			
			char process_date[7]={0};
			process_date[0]=heartbeat;				//心跳
			process_date[1]=breath;						//呼吸
			process_date[2]=temperature_H;		//温度高8位
			process_date[3]=temperature_L;		//温度低8位
			process_date[4]=pressure_H;				//血压峰值
			process_date[5]=pressure_L;				//血压最低值
			process_date[6]=spo2;							//血氧值
			
			
			
			uint8_t package_data=0 ;//定义包长度数据
			uint8_t check_crc_length=0;//定义统计校验和 校验数据的长度
			char robot_tx_buf[100];	//发送的数据缓存
			
			uint8_t all_length=0 ;//定义一个发送数据包的长度
			uint8_t request_length=2 ;//定义整个数据报头所占的字节长度
			uint8_t package_length=1 ;//定义包长度所占的字节长度
			uint8_t id1_length=1 ;//定义ID1长度
			uint8_t id1_data_length=7 ;//定义ID1数据长度
			uint8_t check_length=1 ;//定义校验和数据长度
						
			robot_tx_buf[0]=0x66 ;	//数据报头
			robot_tx_buf[1]=0xcc ;	//数据报头
			robot_tx_buf[request_length+package_length-1]=id1_length+id1_data_length ;//计算包的长度=包ID长度+数据长度	
			robot_tx_buf[request_length+package_length+id1_length-1]=0x01;	//包ID
			
			for(i=0;i<id1_data_length;i++)
			{
			robot_tx_buf[request_length+package_length+id1_length+i]=process_date[i];	//数据接收
			}
			
			all_length=request_length+package_length+id1_length+id1_data_length+check_length;
			//总长度=数据报头所占的字节长度 + 包长度所占的字节长度 + 定义ID1长度 + ID1数据长度 + 定义校验和数据长度
			
			robot_tx_buf[all_length-1]=0;	//将校验位清零
			check_crc_length=package_length+id1_length+id1_data_length;	//统计选要校验的数据的长度
			for(i=0;i<check_crc_length;i++)
			{
			robot_tx_buf[all_length-1]=robot_tx_buf[all_length-1]+robot_tx_buf[request_length+i];
			//robot_tx_buf[all_length-1]就是最后一个校验位
			}
			HAL_UART_Transmit(&huart4,(uint8_t *)robot_tx_buf, all_length, 1000);//
}



#ifndef __ROBOT_TX_H
#define __ROBOT_TX_H

#include "stm32f1xx_hal.h"
#include "uart.h"



void tx_robot_data(uint8_t heartbeat,uint8_t breath ,uint8_t pressure_H,uint8_t pressure_L,uint8_t spo2, float temperature);

#endif


Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐