sggt/App/HART/hart.c

51 lines
1.1 KiB
C

// #include <stdio.h>
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "hart.h"
#include "gpio.h"
void hart_send(UART_HandleTypeDef *huart, uint8_t *data)
{
usart_printf(huart, (char *)data);
}
void parse_scom_hart(st_scom *scom)
{
if (scom == &scom1_hart)
{
scom->rx_flag = FALSE;
if ((scom->rx_buff[0] == 0xff) && (scom->rx_buff[1] == 0xff) && (scom->rx_buff[scom->rx_len - 1] == 0xAA))
{
;
}
scom->tx_flag = TRUE;
scom->rx_len = 0;
}
}
void hart_communicate(st_scom *scom)
{
uint8_t hart_data_test[18] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xaa};
HART_RTS(RTS_OFF);
if (scom->rx_flag == TRUE)
{
scom->rx_flag = FALSE;
parse_scom_hart(scom);
}
// scom->tx_flag = TRUE;
if (scom->tx_flag == TRUE)
{
scom->tx_flag = FALSE;
HART_RTS(RTS_ON);
vTaskDelay(5);
memcpy(scom->tx_buff, hart_data_test, sizeof(hart_data_test));
hart_send(&huart1, scom->tx_buff);
HART_RTS(RTS_OFF);
}
}