?? analyseframe.c
字號:
for (i=0; i<4; i++)
p_iframe->vlan_port[i] = wait_for_dealed_buf[channel][idx++];
display_web_read_result();
break;
case CMD_ACK_SET_VLAN_TAG:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
display_web_set_result();
break;
case CMD_ACK_READ_VLAN_TAG:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
for (i=0; i<2; i++)
p_iframe->vlan_tag[i] = wait_for_dealed_buf[channel][idx++];
display_web_read_result();
break;
case CMD_ACK_READ_WORK_BOARD:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
for (i=0; i<4; i++)
p_iframe->board_type[i] = wait_for_dealed_buf[channel][idx++];
display_web_read_result();
break;
case CMD_ACK_SET_PHONE_NUMBER:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
display_web_set_result();
break;
case CMD_ACK_READ_PHONE_NUMBER:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
p_iframe->telephone_number = wait_for_dealed_buf[channel][idx++];
display_web_read_result();
break;
case CMD_ACK_SET_LOOP:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
display_web_set_result();
break;
case CMD_ACK_READ_LOOP:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
p_iframe->loop_flag = wait_for_dealed_buf[channel][idx++];
display_web_read_result();
break;
case CMD_ACK_SET_OPT_SWITCH:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
display_web_set_result();
break;
case CMD_ACK_READ_OPT_SWITCH:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
p_iframe->switch_flag = wait_for_dealed_buf[channel][idx++];
display_web_read_result();
break;
case CMD_ACK_SET_OPT_ENABLE:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
display_web_set_result();
break;
case CMD_ACK_READ_OPT_ENABLE:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
for (i=0; i<2; i++)
p_iframe->opt_enable[i] = wait_for_dealed_buf[channel][idx++];
display_web_read_result();
break;
case CMD_ACK_SET_SYSTEM_TIME:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
display_web_set_result();
break;
case CMD_ACK_READ_MCU_VERSION:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
for (i=0; i<4; i++)
p_iframe->version[i] = wait_for_dealed_buf[channel][idx++];
display_web_read_result();
break;
case CMD_ACK_READ_DEVICE_TYPE:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
for (i=0; i<4; i++)
p_iframe->device_type[i] = wait_for_dealed_buf[channel][idx++];
display_web_read_result();
break;
case CMD_ACK_READ_ALARM:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
for (i=0; i<(p_cframe->info_length-1)/3; i++)
{
p_iframe->alarm_board[i] = wait_for_dealed_buf[channel][idx++];
p_iframe->alarm_port[i] = wait_for_dealed_buf[channel][idx++];
p_iframe->alarm_id[i] = wait_for_dealed_buf[channel][idx++];
}
display_web_read_result();
break;
case CMD_ACK_SET_ALARM_MASK:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
display_web_set_result();
break;
case CMD_ACK_READ_ALARM_MASK:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
for (i=0; i<(p_cframe->info_length-1)/3; i++)
{
p_iframe->alarm_board[i] = wait_for_dealed_buf[channel][idx++];
p_iframe->alarm_port[i] = wait_for_dealed_buf[channel][idx++];
p_iframe->alarm_id[i] = wait_for_dealed_buf[channel][idx++];
}
display_web_read_result();
break;
case CMD_ACK_SET_ALARM_LEVEL:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
display_web_set_result();
break;
case CMD_ACK_READ_EVENT:
p_iframe->success_flag = wait_for_dealed_buf[channel][idx++];
for (i=0; i<(p_cframe->info_length-1)/3; i++)
{
p_iframe->alarm_board[i] = wait_for_dealed_buf[channel][idx++];
p_iframe->alarm_port[i] = wait_for_dealed_buf[channel][idx++];
p_iframe->event_id[i] = wait_for_dealed_buf[channel][idx++];
}
display_web_read_result();
break;
default:
break;
}
}
unsigned char check_frame_info(char *string_info)
{
unsigned char value = 0;
unsigned int i;
for (i=0; i<7; i++)
{
if (strcmp(string_info, string_to_hex_zero[i]) == 0)
{
value = 0;
break;
}
else if (strcmp(string_info, string_to_hex_one[i]) == 0)
{
value = 1;
break;
}
}
return (value);
}
unsigned char check_frame_info2(char *string_info)
{
unsigned char value = 0;
unsigned int i;
for (i=0; i<23; i++)
{
//printf("<p>prio is: %s</p>", clk_types[i].name);
//printf("<p>value is: %d</p>", clk_types[i].value);
if (strcmp(string_info, clk_types[i].name) == 0)
{
value = clk_types[i].value;
break;
}
}
return (value);
}
//將指定緩沖區數據轉換為ASCII 碼數據流,在minicom 中調試時用
unsigned int frame_to_ascii(unsigned char *hex_buf, unsigned char *ascii_buf, unsigned int length)
{
unsigned char temph, templ;
unsigned int i;
for (i=0; i<length; i++)
{
temph = HexToAscii(hex_buf[i]>>4);
templ = HexToAscii(hex_buf[i]&0x0F);
ascii_buf[i*3] = temph;
ascii_buf[i*3+1] = templ;
ascii_buf[i*3+2] = ' ';
}
return (length*3);
}
void make_normal_frame(void)
{
unsigned char tmp_buf[50];
unsigned char ascii_buf[100];
unsigned char check_sum = 0;
cmd_frame_t *p_cframe = &cmd_frame;
unsigned int k = 0;
unsigned int i;
unsigned int length;
for (i=0; i<4; i++)
tmp_buf[k++] = p_cframe->head[i]; //加載幀頭"0xF5FAFBFF"
for (i=0; i<3; i++) //目標地址
tmp_buf[k++] = p_cframe->dst_addr[i]; //加載目的地址為接收數據時的源地址
for (i=0; i<3; i++) //源地址
tmp_buf[k++] = p_cframe->src_addr[i]; //加載源地址為接收數據時的目的地址
tmp_buf[k++] = p_cframe->net_id; //加載網絡序號
check_sum ^= p_cframe->net_id;
tmp_buf[k++] = p_cframe->cmd_index; //加載命令序號
check_sum ^= p_cframe->cmd_index;
tmp_buf[k++] = p_cframe->cmd_code_send; //加載命令代碼
check_sum ^= p_cframe->cmd_code_send;
tmp_buf[k++] = (unsigned char)(p_cframe->info_length >> 8); //加載信息域長度
check_sum ^= (unsigned char)(p_cframe->info_length >> 8);
tmp_buf[k++] = (unsigned char)(p_cframe->info_length & 0xff);
check_sum ^= (unsigned char)(p_cframe->info_length & 0xff);
for (i=0; i<p_cframe->info_length; i++) //加載信息域
{
tmp_buf[k++] = p_cframe->frame_info[i];
check_sum ^= p_cframe->frame_info[i];
}
tmp_buf[k++] = check_sum;
#ifdef DEBUG_MODE
//將指定緩沖區數據轉換為ASCII 碼數據流,在minicom 中調試時用
length = frame_to_ascii(tmp_buf, ascii_buf, k); //k == p_cframe->info_length+16
port_write("com(rev): ", 10);
port_write(ascii_buf, length);
port_write("\r\n", 2);
#else
port_write(tmp_buf, k);
#endif
}
void receive_normal_frame(void)
{
unsigned int frame_head = 0;
unsigned char cmd_head_flg = 0;
unsigned int idx = 0;
unsigned char check_sum;
cmd_frame_t *p_cframe = &cmd_frame;
if (rx_buf_pointer >= RX_BUF_SIZE) //接收緩沖區溢出
{
rx_buf_overflow = 1; //置接收緩沖區溢出標志
rx_buf_pointer = 0; //清接收數組指針
frame_head = 0;
cmd_head_flg = 0;
save_cmd_enable = 0;
goto parse_frame;
}
frame_head |= (unsigned int)rx_buf[idx++] << 24;
frame_head |= (unsigned int)rx_buf[idx++] << 16;
frame_head |= (unsigned int)rx_buf[idx++] << 8;
frame_head |= (unsigned int)rx_buf[idx++] << 0;
if (frame_head == 0xF5FAFBFF)
{
cmd_head_flg = 1;
}
if (cmd_head_flg)
{
//p_cframe->info_length = (((unsigned short int)rx_buf[9+4]) << 8) | rx_buf[10+4]; //接收幀長
//if (rx_buf[0+4] == My_Grp_Addr)
{
memcpy(wait_for_dealed_buf[0], &rx_buf[idx], rx_buf_pointer-4);
save_cmd_enable = 1; //一幀命令接收完畢,可以進行解析
}
//else
{
//save_cmd_enable = 0;
}
frame_head = 0;
cmd_head_flg = 0;
rx_buf_pointer = 0; //清接收數組指針
goto parse_frame;
}
else
{
rx_buf_overflow = 0; //置接收緩沖區溢出標志
rx_buf_pointer = 0; //清接收數組指針
frame_head = 0;
cmd_head_flg = 0;
save_cmd_enable = 0;
//printf("frame error!\n");
printf("<p>命令幀有誤!\n");
}
return;
parse_frame:
save_cmd();
return;
}
void save_cmd(void)
{
unsigned char use_channel = 0;
if (rx_buf_overflow) //接收緩沖區溢出
{
rx_buf_overflow = 0;
//reply_normal_frame(CMD_UNKNOW, NULL, NULL);
}
else if (save_cmd_enable) //接收緩沖區沒有溢出,且一幀命令接收完畢,進行解析
{
use_channel = 0;
save_cmd_enable = 0;
analysis_tty_cmd(use_channel);
}
}
void frame_process(void)
{
unsigned char times = 0;
unsigned int i, j;
cmd_frame_t *p_cframe = &cmd_frame;
unsigned char temp[3];
if (frame_ready == FRAME_READY)
times = 1;
else if (frame_ready == FRAME_DOUBLE)
times = 2;
else if (frame_ready == FRAME_ERROR)
{
printf("<p>發送命令有誤!\n");
return;
}
else
{
return;
}
for (i=0; i<times; i++)
{
if ((i == 1) && (p_cframe->cmd_code_send == CMD_SET_DXC_TIMESLOT))
{
for (j=0; j<3; j++)
{
temp[j] = p_cframe->frame_info[j];
p_cframe->frame_info[j] = p_cframe->frame_info[j+3];
p_cframe->frame_info[j+3] = temp[j];
}
}
make_normal_frame();
if (port_read())
receive_normal_frame();
else
{
printf("<p>沒有響應!\n");
printf("<p><a href=../index.html>返回 </a><p>");
}
}
frame_ready = FRAME_FINISHED;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -