FIX | 优化代码

main
yuliang 2 weeks ago
parent 18c31b363c
commit 7277f562b3

@ -85,6 +85,7 @@
#define DEV_DATA_LEN 1000 #define DEV_DATA_LEN 1000
#define DEV_DATA_BITMAP_LEN 8 #define DEV_DATA_BITMAP_LEN 8
#define DEV_NAME_STR_LEN 32 #define DEV_NAME_STR_LEN 32
#define THREAD_NAME_LEN 32
/* Does the I/O error indicate that the operation should be retried later? */ /* Does the I/O error indicate that the operation should be retried later? */
#define ERRNO_IO_RETRY(EN) \ #define ERRNO_IO_RETRY(EN) \
@ -99,7 +100,7 @@ typedef struct
void *arg; void *arg;
int priority; int priority;
int log_module; int log_module;
char *thread_name; char thread_name[THREAD_NAME_LEN];
} thread_param_t; } thread_param_t;

@ -45,13 +45,9 @@
#include "pd_main.h" #include "pd_main.h"
#include "common.h" #include "common.h"
/* Define --------------------------------------------------------------------*/ /* Define --------------------------------------------------------------------*/
#define MAX_SLOTS 6
#define BUFFER_SIZE 2048 #define BUFFER_SIZE 2048
#define UDP_SLOTS 4 #define DAU_ETH_SLOTS_SUM 4
#define RS485_SLOTS 2 #define RS485_SLOTS 2
@ -202,7 +198,7 @@ typedef struct {
#define DAU_REG_PORT_ADDR_GET(port) ((port + 1) << 8) #define DAU_REG_PORT_ADDR_GET(port) ((port + 1) << 8)
/* Extern global variables ---------------------------------------------------*/ /* Extern global variables ---------------------------------------------------*/
extern dau_t daus[MAX_SLOTS]; extern dau_t daus[PD_SLOTS_MAX];
/* Extern functions ----------------------------------------------------------*/ /* Extern functions ----------------------------------------------------------*/
extern int32_t dau_handle_init(void); extern int32_t dau_handle_init(void);

@ -41,8 +41,9 @@
#include "cmd.h" #include "cmd.h"
/* Define --------------------------------------------------------------------*/ /* Define --------------------------------------------------------------------*/
#define PD_DAU_SUM 1 #define PD_SLOTS_MAX 8 // 主控之下最大槽位数
#define PD_DAU_PORT_SUM 8 #define PD_DAU_SUM 1 // 每个采集卡最大采集单元数, 固定为 1
#define PD_DAU_PORT_SUM 8 // 每个采集卡的采集单元最大端口数
#define PD_PORT_SUM 8 #define PD_PORT_SUM 8
#define PD_PORT_PROMPT_LEN 64 // DAU 端口节点前标长度. #define PD_PORT_PROMPT_LEN 64 // DAU 端口节点前标长度.
@ -378,7 +379,7 @@ typedef struct
extern pd_data_t pd_data; extern pd_data_t pd_data;
extern pd_config_t pd_config; extern pd_config_t pd_config;
extern pd_state_t pd_state; extern pd_state_t pd_state;
extern cmd_node_t pd_port_node; extern cmd_node_t pd_slot_node;
/* Extern functions ----------------------------------------------------------*/ /* Extern functions ----------------------------------------------------------*/
extern int32_t pd_main(void); extern int32_t pd_main(void);

@ -908,11 +908,11 @@ int32_t csg_handle_init_after(void)
param.log_module = LOG_CSG; param.log_module = LOG_CSG;
param.priority = 45; param.priority = 45;
param.thread_name = "CSG_RCVE"; snprintf(param.thread_name, THREAD_NAME_LEN, "CSG_RCVE");
create_thread(_csg_recv_handle, &param); create_thread(_csg_recv_handle, &param);
param.priority = 45; param.priority = 45;
param.thread_name = "CSG_HEARTBEAT"; snprintf(param.thread_name, THREAD_NAME_LEN, "CSG_HEARTBEAT");
create_thread(_csg_heartbeat_handle, &param); create_thread(_csg_heartbeat_handle, &param);
return E_NONE; return E_NONE;

@ -25,14 +25,15 @@
#include "pd_dau.h" #include "pd_dau.h"
#include "pd_hf.h" #include "pd_hf.h"
#include "pd_csg.h" #include "pd_csg.h"
/* Define --------------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
//dau_t dau; //dau_t dau;
pthread_mutex_t board_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t board_mutex = PTHREAD_MUTEX_INITIALIZER;
int udp_socket; int udp_socket;
dau_t daus[MAX_SLOTS]; dau_t daus[PD_SLOTS_MAX];
// 上传平台回调函数类型 // 上传平台回调函数类型
typedef void (*UploadCallback)(int slot, const void *data, size_t len); typedef void (*UploadCallback)(int slot, const void *data, size_t len);
@ -281,7 +282,7 @@ static int32_t _dau_find_proper_function(char *pkt)
{ {
int flag = 0; int flag = 0;
csg_pkt_head_t *head = (csg_pkt_head_t *)pkt; csg_pkt_head_t *head = (csg_pkt_head_t *)pkt;
for (int i = 0; i < MAX_SLOTS; i++) for (int i = 0; i < PD_SLOTS_MAX; i++)
{ {
if (daus[i].slot != head->slot) if (daus[i].slot != head->slot)
continue; continue;
@ -499,7 +500,7 @@ int _dau_remove(int slot)
#endif #endif
int _dau_insert(int slot, DauType type) int _dau_insert(int slot, DauType type)
{ {
if (slot < 0 || slot >= MAX_SLOTS) if (slot < 0 || slot >= PD_SLOTS_MAX)
{ {
return E_BAD_PARAM; return E_BAD_PARAM;
} }
@ -561,7 +562,7 @@ void _dau_response(int slot, char *buf, int len)
printf("_dau_response: slot=%d len=%d\n", slot, len); printf("_dau_response: slot=%d len=%d\n", slot, len);
if (slot >= 0 && slot < MAX_SLOTS) if (slot >= 0 && slot < PD_SLOTS_MAX)
{ {
if (daus[slot].type == DAU_TYPE_UDP) if (daus[slot].type == DAU_TYPE_UDP)
{ {
@ -670,7 +671,7 @@ void *_dau_udp_receive_handle(void *arg)
// 查找匹配的UDP板卡 // 查找匹配的UDP板卡
pthread_mutex_lock(&board_mutex); pthread_mutex_lock(&board_mutex);
for (int i = 0; i < UDP_SLOTS; i++) for (int i = 0; i < DAU_ETH_SLOTS_SUM; i++)
{ {
//printf("state=%d\n", daus[i].state); //printf("state=%d\n", daus[i].state);
if (daus[i].state == DAU_STATE_DISCONNECTED) if (daus[i].state == DAU_STATE_DISCONNECTED)
@ -705,48 +706,37 @@ void *_dau_udp_receive_handle(void *arg)
return NULL; return NULL;
} }
/* dau 预初始化 */
int32_t dau_handle_init(void) int32_t dau_handle_init(void)
{ {
int32_t rv = 0; memset(&daus, 0, sizeof(dau_t) * PD_SLOTS_MAX);
memset(&daus, 0, sizeof(dau_t)*MAX_SLOTS);
//cmd_install_element(CONFIG_NODE, &csg_server_set_cmd);
cmd_install_element(COMMON_NODE, &dau_add_cmd); cmd_install_element(COMMON_NODE, &dau_add_cmd);
cmd_install_element(COMMON_NODE, &no_dau_add_cmd); cmd_install_element(COMMON_NODE, &no_dau_add_cmd);
//cmd_install_element(COMMON_NODE, &csg_file_cmd);
/* 注册配置保存函数 */
//rv = cmd_config_node_config_register(CONFIG_PRI_CSG, _csg_config_save);
if (rv != E_NONE)
{
log_err(LOG_CSG, "Command save register ERROR %d!", rv);
return rv;
}
return E_NONE; return E_NONE;
} }
/* 后台通讯模块初始化. */ /* dau 初始化 */
int32_t dau_handle_init_after(void) int32_t dau_handle_init_after(void)
{ {
thread_param_t param = {0};
uint8_t i = 0;
if (0 == udp_socket) if (0 == udp_socket)
{ {
udp_socket = _dau_init_udp_server(); udp_socket = _dau_init_udp_server();
} }
printf("udp_socket=%d\n", udp_socket); printf("udp_socket=%d\n", udp_socket);
/* 初始化模块. */ /* 初始化模块. */
thread_param_t param = {0};
param.priority = 45; for (i = 0; i < DAU_ETH_SLOTS_SUM; i++)
param.thread_name = "DAU_MANAGER"; {
create_thread(_dau_manager_handle, &param); param.priority = 80;
snprintf(param.thread_name, THREAD_NAME_LEN, "DAU_RECV_%d", i);
param.priority = 45; create_thread(_dau_manager_handle, &param);
param.thread_name = "DAU_RECV"; }
create_thread(_dau_udp_receive_handle, &param);
return E_NONE; return E_NONE;
} }

@ -65,7 +65,7 @@
pd_data_t pd_data; pd_data_t pd_data;
pd_config_t pd_config; pd_config_t pd_config;
pd_state_t pd_state; pd_state_t pd_state;
cmd_node_t pd_port_node = cmd_node_t pd_slot_node =
{ {
PORT_NODE, PORT_NODE,
CONFIG_NODE, CONFIG_NODE,
@ -77,6 +77,24 @@ cmd_node_t pd_port_node =
extern int32_t _pd_port_str_to_unit_port(const char *port_str, uint8_t *unit, uint8_t *port); extern int32_t _pd_port_str_to_unit_port(const char *port_str, uint8_t *unit, uint8_t *port);
/* Internal functions --------------------------------------------------------*/ /* Internal functions --------------------------------------------------------*/
/* 进入 DAU 端口模式. */
CMD(pd_slot_terminal,
pd_slot_terminal_cmd,
"slot <1-8>",
"Slot\n"
"Port id: Ex: 1/1\n")
{
uint8_t slot = 0;
/* 取出端口号. */
slot = strtol(argv[0], NULL, 10);
pd_slot_node.param_num = slot;
snprintf(pd_slot_node.prompt, PD_PORT_PROMPT_LEN, "%%s(slot %d)# ", slot);
vty->node = PORT_NODE;
return CMD_SUCCESS;
}
/* 4G 模块是否使能. */ /* 4G 模块是否使能. */
CMD(pd_4G_enable, CMD(pd_4G_enable,
@ -232,6 +250,43 @@ int _pd_config_save(vty_t* vty)
return i; return i;
} }
/* config模式配置保存函数: vty -- 相应的终端 */
void _pd_slot_config_save_all(vty_t *vty, uint8_t unit)
{
array_t *configs = pd_slot_node.configs;
pd_port_cmd_save_config_f *func = NULL;
uint8_t i = 0;
vty_out(vty, "slot %d%s", unit + 1, VTY_NEWLINE);
for(i = 0; i < array_active(configs); i++)
{
func = array_lookup(configs, i);
if (!func)
{
continue;
}
func(vty, unit, 0);
}
vty_out(vty, "!%s", VTY_NEWLINE);
}
/* config模式配置保存函数: vty -- 相应的终端 */
int32_t _pd_slot_config_save(vty_t *vty)
{
uint8_t unit = 0;
/* 其他配置保存 */
for(unit = 0; unit < PD_SLOTS_MAX; unit++)
{
_pd_slot_config_save_all(vty, unit);
}
return E_NONE;
}
/* 将端口字符串, 转换成 unit port 格式. */ /* 将端口字符串, 转换成 unit port 格式. */
int32_t _pd_port_str_to_unit_port(const char *port_str, uint8_t *unit, uint8_t *port) int32_t _pd_port_str_to_unit_port(const char *port_str, uint8_t *unit, uint8_t *port)
{ {
@ -490,7 +545,7 @@ int32_t _pd_main_init(void)
} }
} }
pd_config.config.protocol_type = PD_PROTOCOL_LAND; pd_config.config.protocol_type = PD_PROTOCOL_LAND;
pd_config.config.power_frequency = 500; pd_config.config.power_frequency = 500;
pd_config.config.sync_mode = PD_SYNC_PT; pd_config.config.sync_mode = PD_SYNC_PT;
pd_config.config.is_4G_enable = FALSE; pd_config.config.is_4G_enable = FALSE;
@ -510,15 +565,16 @@ int32_t _pd_main_init(void)
} }
/* 注册端口节点. */ /* 注册端口节点. */
pd_port_node.prompt = XMALLOC(MTYPE_DAU, PD_PORT_PROMPT_LEN); cmd_install_node(&pd_slot_node, _pd_slot_config_save);
pd_port_node.configs = array_init(PD_PORT_CMD_PRI_COUNT, MTYPE_DAU); pd_slot_node.prompt = XMALLOC(MTYPE_DAU, PD_PORT_PROMPT_LEN);
pd_slot_node.configs = array_init(PD_PORT_CMD_PRI_COUNT, MTYPE_DAU);
cmd_install_element(CONFIG_NODE, &pd_4G_enable_cmd); cmd_install_element(CONFIG_NODE, &pd_4G_enable_cmd);
cmd_install_element(CONFIG_NODE, &pd_4G_APN_cmd); cmd_install_element(CONFIG_NODE, &pd_4G_APN_cmd);
cmd_install_element(CONFIG_NODE, &pd_protocol_type_cmd); cmd_install_element(CONFIG_NODE, &pd_protocol_type_cmd);
cmd_install_element(CONFIG_NODE, &pd_slot_terminal_cmd);
cmd_install_element(COMMON_NODE, &show_pd_cmd); cmd_install_element(COMMON_NODE, &show_pd_cmd);
return E_NONE; return E_NONE;
@ -535,7 +591,7 @@ int32_t _pd_main_init_after(void)
{ {
param.arg = NULL; param.arg = NULL;
param.priority = 20; param.priority = 20;
param.thread_name = "4G"; snprintf(param.thread_name, THREAD_NAME_LEN, "4G");
param.log_module = LOG_PD; param.log_module = LOG_PD;
create_thread(_pd_4G_handle, &param); create_thread(_pd_4G_handle, &param);
} }
@ -581,7 +637,7 @@ int32_t pd_main_after(void)
int32_t pd_port_cmd_config_register(int32_t pri, pd_port_cmd_save_config_f *func) int32_t pd_port_cmd_config_register(int32_t pri, pd_port_cmd_save_config_f *func)
{ {
cmd_node_t *node = &pd_port_node; cmd_node_t *node = &pd_slot_node;
/* 参数检查 */ /* 参数检查 */
if (pri >= PD_PORT_CMD_PRI_COUNT || !func) if (pri >= PD_PORT_CMD_PRI_COUNT || !func)

@ -138,7 +138,7 @@ const char history_file[] = "./command_line_history";
/* cli线程pid. */ /* cli线程pid. */
static pthread_t _cmd_pid; static pthread_t _cmd_pid;
extern cmd_node_t pd_port_node; extern cmd_node_t pd_slot_node;
extern int32_t vtysh_config_save_bak(int idx); extern int32_t vtysh_config_save_bak(int idx);
extern int32_t _config_write_host(vty_t *vty); extern int32_t _config_write_host(vty_t *vty);

Loading…
Cancel
Save