一句句解释分析细致讲解一下这段代码void netconf_entry(void) { int state = 0; int event = 0; UINT8 * pPacket = NULL; UINT32 dataLen = 0; char *pData = NULL; UINT8 ret = 0; struct np_module netopeer_module; struct np_module server_module; memset(&netopeer_module,0,sizeof(struct np_module)); memset(&server_module,0,sizeof(struct np_module)); state = Ros_GetCurState(); event = Ros_GetMsgId(); switch( state ) { case NETCONF_PROCESS_INIT: switch( event ) { case MSG_MasterPowerOn: case MSG_SlavePowerOn: //printf("netconf_entry MSG_SlavePowerOn\n"); Ros_SetNextState(NETCONF_PROCESS_RUNNING); break; case MSG_INIT_PROTOCOL_OK: Ros_SetNextState(NETCONF_PROCESS_RUNNING); break; default: break; } break; case NETCONF_PROCESS_RUNNING: switch( event ) { case MSG_DriverOK: netconf_init(); break; case MSG_NETCONF_TO_DCN: nc_verb_verbose("netconf_entry recv netconf to dcn msg\n"); break; case MSG_ALARM_TO_NETCONF: NcProcessAlarmMsg(); break; case MSG_LIBNETCONF_TO_NETOPEER: ncRcvLibnetconfMsgProc(); break; case MSG_NETCONF_LLDP_TIMER: Ros_SetTimer(netconfLLDPTimerID, NETCONF_MSG_TIME_LLDP, 0); ncLldpchange(); break; case MSG_NETCONF_15MIN_PERF_TIMER: Ros_SetTimer(netconf15MINPerfTimerID, NETCONF_MSG_15MIN_TIME_PERF, 0); packageOptInfo15Min(); packageIfStatisInfo15Min(); break; case MSG_NETCONF_24H_PERF_TIMER: Ros_SetTimer(netconf24hPerfTimerID, NETCONF_MSG_24H_TIME_PERF, 0); packageOptInfo24H(); packageIfStatisInfo24H(); break; case MSG_NETCONF_MEM_CHECK_TIMER: printS("MSG_NETCONF_MEM_CHECK_TIMER TIMEROUT\n"); memory_line_check(0); break; case MSG_NETCONF_TIMER: oam_perf_netconf_show_value_entry(); break; default: break; } break; default: break; } return EXIT_SUCCESS; }
时间: 2024-02-14 11:28:20 浏览: 114
下面是对这段代码的逐句解释和分析:
```c++
void netconf_entry(void)
{
int state = 0;
int event = 0;
UINT8 * pPacket = NULL;
UINT32 dataLen = 0;
char *pData = NULL;
UINT8 ret = 0;
struct np_module netopeer_module;
struct np_module server_module;
memset(&netopeer_module,0,sizeof(struct np_module));
memset(&server_module,0,sizeof(struct np_module));
```
这段代码定义了一个名为netconf_entry的函数,没有参数,返回类型为void。
接下来,定义了一系列变量,包括state和event(int类型)、pPacket(UINT8指针类型)、dataLen(UINT32类型)、pData(char指针类型)和ret(UINT8类型)。
然后,定义了两个结构体变量netopeer_module和server_module,并使用memset函数将其内容初始化为0。
```c++
state = Ros_GetCurState();
event = Ros_GetMsgId();
switch( state )
{
case NETCONF_PROCESS_INIT:
switch( event )
{
case MSG_MasterPowerOn:
case MSG_SlavePowerOn:
//printf("netconf_entry MSG_SlavePowerOn\n");
Ros_SetNextState(NETCONF_PROCESS_RUNNING);
break;
case MSG_INIT_PROTOCOL_OK:
Ros_SetNextState(NETCONF_PROCESS_RUNNING);
break;
default:
break;
}
break;
case NETCONF_PROCESS_RUNNING:
switch( event )
{
case MSG_DriverOK:
netconf_init();
break;
case MSG_NETCONF_TO_DCN:
nc_verb_verbose("netconf_entry recv netconf to dcn msg\n");
break;
case MSG_ALARM_TO_NETCONF:
NcProcessAlarmMsg();
break;
case MSG_LIBNETCONF_TO_NETOPEER:
ncRcvLibnetconfMsgProc();
break;
case MSG_NETCONF_LLDP_TIMER:
Ros_SetTimer(netconfLLDPTimerID, NETCONF_MSG_TIME_LLDP, 0);
ncLldpchange();
break;
case MSG_NETCONF_15MIN_PERF_TIMER:
Ros_SetTimer(netconf15MINPerfTimerID, NETCONF_MSG_15MIN_TIME_PERF, 0);
packageOptInfo15Min();
packageIfStatisInfo15Min();
break;
case MSG_NETCONF_24H_PERF_TIMER:
Ros_SetTimer(netconf24hPerfTimerID, NETCONF_MSG_24H_TIME_PERF, 0);
packageOptInfo24H();
packageIfStatisInfo24H();
break;
case MSG_NETCONF_MEM_CHECK_TIMER:
printS("MSG_NETCONF_MEM_CHECK_TIMER TIMEROUT\n");
memory_line_check(0);
break;
case MSG_NETCONF_TIMER:
oam_perf_netconf_show_value_entry();
break;
default:
break;
}
break;
default:
break;
}
return EXIT_SUCCESS;
}
```
接下来,代码根据当前状态(state)和事件(event)进行switch语句的判断。
如果state为NETCONF_PROCESS_INIT,根据event的不同进行不同的操作。如果event是MSG_MasterPowerOn或MSG_SlavePowerOn,则将下一个状态设置为NETCONF_PROCESS_RUNNING。如果event是MSG_INIT_PROTOCOL_OK,则同样将下一个状态设置为NETCONF_PROCESS_RUNNING。
如果state为NETCONF_PROCESS_RUNNING,根据event的不同进行不同的操作。如果event是MSG_DriverOK,则调用netconf_init函数。如果event是MSG_NETCONF_TO_DCN,则打印一条调试信息。如果event是MSG_ALARM_TO_NETCONF,则调用NcProcessAlarmMsg函数。如果event是MSG_LIBNETCONF_TO_NETOPEER,则调用ncRcvLibnetconfMsgProc函数。如果event是MSG_NETCONF_LLDP_TIMER,则设置一个定时器,并调用ncLldpchange函数。如果event是MSG_NETCONF_15MIN_PERF_TIMER,则设置一个定时器,并依次调用packageOptInfo15Min和packageIfStatisInfo15Min函数。如果event是MSG_NETCONF_24H_PERF_TIMER,则设置一个定时器,并依次调用packageOptInfo24H和packageIfStatisInfo24H函数。如果event是MSG_NETCONF_MEM_CHECK_TIMER,则打印一条信息,并调用memory_line_check函数。如果event是MSG_NETCONF_TIMER,则调用oam_perf_netconf_show_value_entry函数。
最后,函数返回EXIT_SUCCESS(整数值,表示成功)。
阅读全文