Yunhorn_OLD_R1_R2_R5/Src/user_data_send.c

75 lines
2.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "user_data_send.h"
#include <string.h>
#include <stdio.h>
#include "main.h"
char sendBuffer[64];
/*******************************************************************************
**函数名称UsartxSendDataByte(USART_TypeDef* USARTx,uint8_t Data)
**功能描述:串口发送一个字节
**入口参数USART_TypeDef* USARTx 串口句柄
uint8_t Data 要发送的数据
**输出:无
*******************************************************************************/
void UsartxSendDataByte(USART_TypeDef* USARTx,uint8_t Data)
{
LL_USART_TransmitData8(USARTx,Data);
while(LL_USART_IsActiveFlag_TXE(USARTx) == RESET){}
}
/*******************************************************************************
**函数名称UsartxSendDataStr(USART_TypeDef* USARTx,const uint8_t *Data,uint32_t len)
**功能描述:串口发送字符串
**入口参数USART_TypeDef* USARTx 串口句柄
uint8_t *Data 要发送的数据
uint32_t len 数据长度
**输出:无
*******************************************************************************/
void UsartxSendDataStr(USART_TypeDef* USARTx,uint8_t *Data,uint32_t len)
{
while(len--)
{
LL_USART_TransmitData8(USARTx,*(Data++));
while(LL_USART_IsActiveFlag_TXE(USARTx) == RESET){}
}
}
/*******************************************************************************
**函数名称SendData(uint8_t *sensorData)
**功能描述:发送传感器数据
**入口参数uint8_t *sensorData 要发送的数据
**输出:无
*******************************************************************************/
void SendData(uint16_t *sensorData)
{
uint8_t length = 0;
uint8_t buf[2];
buf[1]=sensorData[0]&0x00FF;
buf[0]=sensorData[0]>>8&0x00FF;
memset(sendBuffer, 0, sizeof(sendBuffer));
#ifdef TissuePaper
length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=%d,0,%d,<%02x\r\n", DATA_PORT,1, buf[1]);
//length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=%d,0,%d,>%02x\r\n", DATA_PORT, SENSOR_QUANTITY, sensorData[0]);
#endif
#ifdef JumboRoll
length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=%d,0,%d,<%02x\r\n", DATA_PORT, 1, buf[1]);
//length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=%d,0,%d,>%02x\r\n", DATA_PORT, SENSOR_QUANTITY, sensorData[0]);
#endif
#ifdef DoubleJumboRoll
uint8_t buf2[2];
buf2[1]=sensorData[2]&0x00FF;
buf2[0]=sensorData[2]>>8&0x00FF;
//length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=%d,0,%d,>%02x%02x\r\n", DATA_PORT, SENSOR_QUANTITY, sensorData[0],sensorData[1]);
length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=%d,0,%d,<%02x%02x\r\n", DATA_PORT,2, buf[1], buf2[1]);
#endif
#ifdef WasteBin
length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=%d,0,%d,<%02x%02x\r\n",DATA_PORT, 2, buf[0], buf[1]);
#endif
UsartxSendDataStr(Lora_Uart,(uint8_t *)sendBuffer,length);
}