Yunhorn_STS_E1/Src/user_data_send.c

91 lines
2.8 KiB
C
Raw 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 <string.h>
#include <stdio.h>
#include "main.h"
#include "lora.h"
#include "usart_user.h"
#include "user_data_send.h"
extern volatile uint8_t LORA_STATE;
extern volatile uint8_t TIMER_STATE;
/*******************************************************************************
**函数名称SendSensorData(uint8_t *sensorData)
**功能描述:发送传感器数据
**入口参数uint8_t *sensorData 要发送的数据
**输出:无
*******************************************************************************/
void SendSensorData(uint8_t status, uint8_t play_ctrl)
{
static uint8_t last_status = 0;
if(last_status != status)
{
if(LORA_STATE == LORA_JOINED)
{
char sendBuffer[64];
uint8_t length = 0;
memset(sendBuffer, 0, sizeof(sendBuffer));
//length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=102,0,2,<%02x%02x\r\n", status,play_ctrl);
length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=%d,0,2,<%02x%02x\r\n", sts_data_port, status, play_ctrl);
UsartxSendDataStr(LORA_USART, (uint8_t *)sendBuffer, length);
}
}
last_status = status;
}
/*******************************************************************************
**函数名称SendHBData(uint8_t *sensorData)
**功能描述:发送传感器数据
**入口参数uint8_t *sensorData 要发送的数据
**输出:无
*******************************************************************************/
void SendHbData(uint8_t status, uint8_t play_ctrl)
{
if(LORA_STATE == LORA_JOINED)
{
char sendBuffer[64];
uint8_t length = 0;
memset(sendBuffer, 0, sizeof(sendBuffer));
//length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=103,0,2,<%02x%02x\r\n", status,play_ctrl);
length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=%d,0,2,<%02x%02x\r\n", sts_hb_port, status, play_ctrl);
UsartxSendDataStr(LORA_USART, (uint8_t *)sendBuffer, length);
}
}
/*******************************************************************************
**函数名称SendReplyData(uint8_t *sensorData)
**功能描述:发送传感器数据
**入口参数uint8_t *sensorData 要发送的数据
**输出:无
*******************************************************************************/
void SendCmdReplyData(uint8_t *replybuf)
{
if(LORA_STATE == LORA_JOINED)
{
char sendBuffer[64];
uint8_t length = 0;
memset(sendBuffer, 0, sizeof(sendBuffer));
//length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=103,0,2,<%02x%02x\r\n", status,play_ctrl);
length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=%d,0,3,<%02x%02x%02x\r\n", sts_cmd_reply_port, (uint8_t)replybuf[0],(uint8_t)replybuf[1],(uint8_t)replybuf[2]);
UsartxSendDataStr(LORA_USART, (uint8_t *)sendBuffer, length);
}
}
void SendData_Lora(uint8_t send_status, uint8_t status, uint8_t play_ctrl)
{
if(send_status == SEND_DATA)
{
SendSensorData(status, play_ctrl);
}
else if(send_status == SEND_HEART_DATA)
{
SendHbData(status, play_ctrl);
}
}