gateway_mcu/CH32V303-FreeRTOS/App/application/Host/Src/hostSensorDataParse.c

362 lines
9.8 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 "hostSensorDataParse.h"
#include "hostQueueUart.h"
#include "mcu_common.h"
/**
* @brief 接收J0口传来的数据
* @param
* @retval
*/
void J0_SensorDataAnalysis(void)
{
static uint32_t tick;
if (J0_485RxBufferIndex == 0) {
tick = xTaskGetTickCount();
}
/* 单次进入最多6ms3个时钟周期串口中有数据 */
uint32_t nowTick = xTaskGetTickCount();
while ((getTickDiff(nowTick) < 3)
&& (uart_dev_char_present(g_J0_handle) == 1)
&& (maxdataLen > J0_485RxBufferIndex)) {
J0_485RxBuffer[J0_485RxBufferIndex++] = uart_dev_in_char(g_J0_handle);
}
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
if ((J0_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
uint32_t tempLen = 6 + J0_485RxBufferIndex + hostQueueUartSendInfoSize;
if (xPortGetFreeHeapSize() < tempLen + 1024) {
J0_485RxBufferIndex = 0;
return;
}
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
sendBuff->length = 6 + J0_485RxBufferIndex;
sendBuff->data = Buff + sizeof(hostQueueUartSendInfo);
uint8_t *send = sendBuff->data;
/* 起始标志 */
*send = 'S';
*(send + 1) = 'L';
/* 端口号 */
send += 2;
*send = J0;
/* 数据包长度 */
send += 1;
*send = (uint8_t)(J0_485RxBufferIndex >> 8);
*(send + 1) = (uint8_t)(J0_485RxBufferIndex);
/* 数据包 */
send += 2;
memcpy((char *)send, (char *)J0_485RxBuffer, J0_485RxBufferIndex);
/* 结束标志 */
send += J0_485RxBufferIndex;
*send = 0x17;
/* 队列中有空间,则将发送数据 */
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
xQueueSend(su806_uart_Queue, &Buff, 10);
}
/* 队列无空间,将数据丢弃 */
else {
vPortFree(Buff);
}
/* 发送完成或遇到问题将buff中的数据清零 */
J0_485RxBufferIndex = 0;
}
}
/**
* @brief 接收J2口传来的数据
* @param
* @retval
*/
void J2_SensorDataAnalysis(void)
{
static uint32_t tick;
if (J2_485RxBufferIndex == 0) {
tick = xTaskGetTickCount();
}
/* 单次进入最多6ms3个时钟周期串口中有数据 */
uint32_t nowTick = xTaskGetTickCount();
while ((getTickDiff(nowTick) < 3)
&& (uart_dev_char_present(g_J2_handle) == 1)
&& (maxdataLen > J2_485RxBufferIndex)) {
J2_485RxBuffer[J2_485RxBufferIndex++] = uart_dev_in_char(g_J2_handle);
}
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
if ((J2_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
uint32_t tempLen = 6 + J2_485RxBufferIndex + hostQueueUartSendInfoSize;
if (xPortGetFreeHeapSize() < tempLen + 1024) {
J2_485RxBufferIndex = 0;
return;
}
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
sendBuff->length = 6 + J2_485RxBufferIndex;
sendBuff->data = Buff + sizeof(hostQueueUartSendInfo);
uint8_t *send = sendBuff->data;
/* 起始标志 */
*send = 'S';
*(send + 1) = 'L';
/* 端口号 */
send += 2;
*send = J2;
/* 数据包长度 */
send += 1;
*send = (uint8_t)(J2_485RxBufferIndex >> 8);
*(send + 1) = (uint8_t)(J2_485RxBufferIndex);
/* 数据包 */
send += 2;
memcpy((char *)send, (char *)J2_485RxBuffer, J2_485RxBufferIndex);
/* 结束标志 */
send += J2_485RxBufferIndex;
*send = 0x17;
/* 队列中有空间,则将发送数据 */
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
xQueueSend(su806_uart_Queue, &Buff, 10);
}
/* 队列无空间,将数据丢弃 */
else {
vPortFree(Buff);
}
/* 发送完成或遇到问题将buff中的数据清零 */
J2_485RxBufferIndex = 0;
}
}
/**
* @brief 接收J4口传来的数据
* @param
* @retval
*/
void J4_SensorDataAnalysis(void)
{
static uint32_t tick;
if (J4_485RxBufferIndex == 0) {
tick = xTaskGetTickCount();
}
/* 单次进入最多6ms3个时钟周期串口中有数据 */
uint32_t nowTick = xTaskGetTickCount();
while ((getTickDiff(nowTick) < 3)
&& (uart_dev_char_present(g_J4_handle) == 1)
&& (maxdataLen > J4_485RxBufferIndex)) {
J4_485RxBuffer[J4_485RxBufferIndex++] = uart_dev_in_char(g_J4_handle);
}
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
if ((J4_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
uint32_t tempLen = 6 + J4_485RxBufferIndex + hostQueueUartSendInfoSize;
if (xPortGetFreeHeapSize() < tempLen + 1024) {
J4_485RxBufferIndex = 0;
return;
}
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
sendBuff->length = 6 + J4_485RxBufferIndex;
sendBuff->data = Buff + sizeof(hostQueueUartSendInfo);
uint8_t *send = sendBuff->data;
/* 起始标志 */
*send = 'S';
*(send + 1) = 'L';
/* 端口号 */
send += 2;
*send = J4;
/* 数据包长度 */
send += 1;
*send = (uint8_t)(J4_485RxBufferIndex >> 8);
*(send + 1) = (uint8_t)(J4_485RxBufferIndex);
/* 数据包 */
send += 2;
memcpy((char *)send, (char *)J4_485RxBuffer, J4_485RxBufferIndex);
/* 结束标志 */
send += J4_485RxBufferIndex;
*send = 0x17;
/* 队列中有空间,则将发送数据 */
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
xQueueSend(su806_uart_Queue, &Buff, 10);
}
/* 队列无空间,将数据丢弃 */
else {
vPortFree(Buff);
}
/* 发送完成或遇到问题将buff中的数据清零 */
J4_485RxBufferIndex = 0;
}
}
/**
* @brief 接收J6口传来的数据
* @param
* @retval
*/
void J6_SensorDataAnalysis(void)
{
static uint32_t tick;
if (J6_485RxBufferIndex == 0) {
tick = xTaskGetTickCount();
}
/* 单次进入最多6ms3个时钟周期串口中有数据 */
uint32_t nowTick = xTaskGetTickCount();
while ((getTickDiff(nowTick) < 3)
&& (uart_dev_char_present(g_J6_handle) == 1)
&& (maxdataLen > J6_485RxBufferIndex)) {
J6_485RxBuffer[J6_485RxBufferIndex++] = uart_dev_in_char(g_J6_handle);
}
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
if ((J6_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
uint32_t tempLen = 6 + J6_485RxBufferIndex + hostQueueUartSendInfoSize;
if (xPortGetFreeHeapSize() < tempLen + 1024) {
J6_485RxBufferIndex = 0;
return;
}
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
sendBuff->length = 6 + J6_485RxBufferIndex;
sendBuff->data = Buff + sizeof(hostQueueUartSendInfo);
uint8_t *send = sendBuff->data;
/* 起始标志 */
*send = 'S';
*(send + 1) = 'L';
/* 端口号 */
send += 2;
*send = J6;
/* 数据包长度 */
send += 1;
*send = (uint8_t)(J6_485RxBufferIndex >> 8);
*(send + 1) = (uint8_t)(J6_485RxBufferIndex);
/* 数据包 */
send += 2;
memcpy((char *)send, (char *)J6_485RxBuffer, J6_485RxBufferIndex);
/* 结束标志 */
send += J6_485RxBufferIndex;
*send = 0x17;
/* 队列中有空间,则将发送数据 */
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
xQueueSend(su806_uart_Queue, &Buff, 10);
}
/* 队列无空间,将数据丢弃 */
else {
vPortFree(Buff);
}
/* 发送完成或遇到问题将buff中的数据清零 */
J6_485RxBufferIndex = 0;
}
}
/**
* @brief 接收Lora口传来的数据
* @param
* @retval
*/
void Lora_SensorDataAnalysis(void)
{
static uint32_t tick;
if (loraRxBufferIndex == 0) {
tick = xTaskGetTickCount();
}
/* 单次进入最多6ms3个时钟周期串口中有数据 */
uint32_t nowTick = xTaskGetTickCount();
while ((getTickDiff(nowTick) < 3)
&& (uart_dev_char_present(g_Lora_handle) == 1)
&& (maxdataLen > loraRxBufferIndex)) {
loraRxBuffer[loraRxBufferIndex++] = uart_dev_in_char(g_Lora_handle);
}
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
if ((loraRxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
uint32_t tempLen = 6 + loraRxBufferIndex + hostQueueUartSendInfoSize;
if (xPortGetFreeHeapSize() < tempLen + 1024) {
loraRxBufferIndex = 0;
return;
}
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
sendBuff->length = 6 + loraRxBufferIndex;
sendBuff->data = Buff + sizeof(hostQueueUartSendInfo);
uint8_t *send = sendBuff->data;
/* 起始标志 */
*send = 'S';
*(send + 1) = 'L';
/* 端口号 */
send += 2;
*send = Lora;
/* 数据包长度 */
send += 1;
*send = (uint8_t)(loraRxBufferIndex >> 8);
*(send + 1) = (uint8_t)(loraRxBufferIndex);
/* 数据包 */
send += 2;
memcpy((char *)send, (char *)loraRxBuffer, loraRxBufferIndex);
/* 结束标志 */
send += loraRxBufferIndex;
*send = 0x17;
/* 队列中有空间,则将发送数据 */
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
xQueueSend(su806_uart_Queue, &Buff, 10);
}
/* 队列无空间,将数据丢弃 */
else {
vPortFree(Buff);
}
/* 发送完成或遇到问题将buff中的数据清零 */
loraRxBufferIndex = 0;
}
}