78 lines
2.1 KiB
C
78 lines
2.1 KiB
C
#include "app_com.h"
|
|
#include "app_leakage.h"
|
|
#include "proto_modbus_master_leakage.h"
|
|
|
|
/*com口对应的串口*/
|
|
bsp_uart_t *com_to_uart[APP_COM_NUM] =
|
|
{
|
|
&com_uart4,
|
|
&com_uart2,
|
|
&com_uart3,
|
|
&com_uart1,
|
|
};
|
|
|
|
static void app_com_uart_baud_rate_set(app_com_class_t * p_com,u16 baud_rate);
|
|
static void app_com_class_update(void );
|
|
static void app_com_init(app_com_class_t * p_com);
|
|
|
|
app_com_t app_com=
|
|
{
|
|
|
|
};
|
|
|
|
static void app_com_init(app_com_class_t * p_com)
|
|
{
|
|
if(p_com == &app_com.com[APP_COM1])
|
|
p_com->com_uart = com_to_uart[APP_COM1];
|
|
else if(p_com == &app_com.com[APP_COM2])
|
|
p_com->com_uart = com_to_uart[APP_COM2];
|
|
else if(p_com == &app_com.com[APP_COM3])
|
|
p_com->com_uart = com_to_uart[APP_COM3];
|
|
else if(p_com == &app_com.com[APP_COM4])
|
|
p_com->com_uart = com_to_uart[APP_COM4];
|
|
}
|
|
|
|
|
|
|
|
/*串口配置*/
|
|
static void app_com_uart_baud_rate_set(app_com_class_t * p_com,u16 baud_rate)
|
|
{
|
|
p_com->com_uart->set.baud_rate(p_com->com_uart,baud_rate);
|
|
}
|
|
|
|
|
|
/*将同一com口的设备进行划分*/
|
|
static void app_com_class_update(void )
|
|
{
|
|
u16 i,j;
|
|
u8 com_index,id;
|
|
|
|
/********************************************总数清零******************************************************/
|
|
for(i=0;i<APP_COM_NUM;i++)
|
|
{
|
|
modbus_leakage[i].sensor_num = 0;
|
|
}
|
|
|
|
/*遍历子系统*/
|
|
for(i=0;i<APP_LEAKAGE_SUB_DEVICE_NUM;i++)
|
|
{
|
|
/*设备使能*/
|
|
if(ENABLE == leakage.sub_device_data[i].flash_data.state)
|
|
{
|
|
/********************************************COM口划分******************************************************/
|
|
com_index = leakage.sub_device_data[i].flash_data.com;
|
|
id = leakage.sub_device_data[i].flash_data.modbus_id;
|
|
/*绑定modbus id*/
|
|
modbus_leakage[com_index].sensor[modbus_leakage[com_index].sensor_num].comm.id = id;
|
|
/*绑定子设备索引索引*/
|
|
modbus_leakage[com_index].sensor[modbus_leakage[com_index].sensor_num].comm.leakage_data_index = i;
|
|
/*comm口设备总数++*/
|
|
modbus_leakage[com_index].sensor_num++;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|