下面试需要实现的一条协议。
用结构体实现上述信息的描述和初始化:
//----------------- struct of config file update --------------
struct esl_attr_data{
unsigned short id;
unsigned char type;
unsigned char gs;
};
struct port_data{
unsigned char esl_num;
struct esl_attr_data **esl_attr;
};
typedef struct cfg_f_data{
unsigned char port_num;
struct port_data **port;
}cfg_f_data_t;
#define __PORT_NUM__ 2
#define __PORT1_ESL_NUM__ 34
#define __PORT2_ESL_NUM__ 56
unsigned char esl_num_arry[__PORT_NUM__] = {65,31};
unsigned char *port1_attr[2] = {port1_esl_id,port1_esl_type};
unsigned char *port2_attr[2] = {port2_esl_id,port2_esl_type};
unsigned char port1_esl_id[__PORT1_ESL_NUM__] = {};
unsigned char port2_esl_id[__PORT2_ESL_NUM__] = {};
unsigned char port1_esl_type[__PORT1_ESL_NUM__] = {};
unsigned char port2_esl_type[__PORT1_ESL_NUM__] = {};
int i,j;
cfg_f_data_t *CfgFData;
struct port_data *PortData;
struct esl_attr_data *EslAttrData;
CfgFData = (cfg_f_data_t *)malloc(sizeof(cfg_f_data_t));
CfgFData->port_num = 2;
CfgFData->port = (struct port_data **)malloc(sizeof(struct port_data *) * CfgFData->port_num);
for(i = 0;i < CfgFData->port_num;i ++){
PortData = (struct port_data *)malloc(sizeof(struct port_data));
PortData->esl_num = PortData;
PortData->esl_attr = (struct esl_attr_data **)malloc(sizeof(struct esl_attr_data *) * PortData->esl_num);
for(j = 0;j < PortData->esl_num;j ++){
EslAttrData = (struct esl_attr_data *)malloc(sizeof(struct esl_attr_data));
EslAttrData->gs = 0x30;
EslAttrData->id = port1_attr[1][j];
EslAttrData->type = port1_attr[2][j];
PortData->esl_attr[j] = EslAttrData;
}
CfgFData->port = PortData;
}
//----------------------------------------------------- |