77 lines
1.9 KiB
C
77 lines
1.9 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_uart6,
|
|
};
|
|
|
|
static void app_com_uart_class_rate_set(app_com_class_t * p_com,u16 baud_rate);
|
|
static void app_com_class_update(void );
|
|
static void app_com_init(void);
|
|
|
|
app_com_t app_com=
|
|
{
|
|
.init = app_com_init,
|
|
.class_update = app_com_class_update,
|
|
};
|
|
|
|
static void app_com_init(void)
|
|
{
|
|
u8 i;
|
|
for(i=0;i<APP_COM_NUM;i++)
|
|
{
|
|
app_com.com[i].com_uart = com_to_uart[i];
|
|
}
|
|
app_com_class_update();
|
|
}
|
|
|
|
|
|
|
|
/*串口配置*/
|
|
static void app_com_class_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++;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|