100 lines
2.5 KiB
C
100 lines
2.5 KiB
C
/*
|
|
* @Author: wujunchao wujunchao@wuxismart.com
|
|
* @Date: 2024-12-24 08:18:25
|
|
* @LastEditors: wujunchao wujunchao@wuxismart.com
|
|
* @LastEditTime: 2025-03-17 09:31:06
|
|
* @FilePath: \signal_generator\App\MODBUS\modbus.c
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
*/
|
|
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
#include "stdio.h"
|
|
#include "modbus.h"
|
|
#include "usart.h"
|
|
#include "apps_gather.h"
|
|
|
|
//static void scom_485_send(UART_HandleTypeDef *huart, char *str)
|
|
//{
|
|
// RS485_RW(RS485_WR);
|
|
// vTaskDelay(10);
|
|
// printf("\r\n");
|
|
// usart_printf(huart, "rs485 receive:[%s]\r\n", str);
|
|
// printf("printf test_data:[%s]\r\n", str);
|
|
// RS485_RW(RS485_RD);
|
|
//}
|
|
|
|
void parse_scom_485(st_scom *scom)
|
|
{
|
|
if ((scom == &scom2_rs485) && (scom->rx_flag == TRUE))
|
|
{
|
|
scom->rx_flag = FALSE;
|
|
if ((scom->rx_buff[0] == 0xff) && (scom->rx_buff[1] == 0xff) && (scom->rx_buff[scom->rx_len - 1] == 0xaa))
|
|
{
|
|
// scom_485_send(&huart2, scom->rx_buff);
|
|
//RS485_RW(RS485_WR);
|
|
vTaskDelay(10);
|
|
HAL_UART_Transmit(&huart2, scom->rx_buff, scom->rx_len, 0xFFFF);
|
|
//RS485_RW(RS485_RD);
|
|
}
|
|
scom->rx_len = 0;
|
|
}
|
|
}
|
|
|
|
void transparent_485(st_scom *scom)
|
|
{
|
|
if(scom != &scom2_rs485) return;
|
|
|
|
//PC -> SIG
|
|
if(scom->rx_flag == TRUE)
|
|
{
|
|
scom->rx_flag = FALSE;
|
|
|
|
switch (sig_trans)
|
|
{
|
|
case TRANS_HART:
|
|
{
|
|
if ((scom->rx_buff[0] == 0xff) && (scom->rx_buff[1] == 0xff) && (scom->rx_buff[scom->rx_len - 1] == 0xaa))
|
|
{
|
|
//SIG -> DEVICE
|
|
memcpy(scom1_hart.tx_buff, scom->rx_buff, sizeof(scom->rx_buff));
|
|
scom1_hart.tx_flag = TRUE;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case TRANS_BLUETOOTH:
|
|
{
|
|
memcpy(scom6_ble.tx_buff, scom->rx_buff, sizeof(scom->rx_buff));
|
|
scom6_ble.tx_flag = TRUE;
|
|
}
|
|
break;
|
|
|
|
case TRANS_MODBUS:
|
|
{}
|
|
break;
|
|
|
|
case TRANS_NONE:
|
|
{}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
scom->rx_len = 0;
|
|
}
|
|
|
|
//SIG -> PC
|
|
if(scom->tx_flag == TRUE)
|
|
{
|
|
scom->tx_flag = FALSE;
|
|
|
|
vTaskDelay(10);
|
|
HAL_UART_Transmit(&huart2, scom->tx_buff, scom->tx_len, 0xFFFF);
|
|
}
|
|
|
|
}
|
|
|
|
|