⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 analyseframe.c

📁 基于嵌入式web服务器的web应用层代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*********************************************************************
    Filename:       analyseframe.c
    Revised:        $Date: 2007-12-11 10:38:52 -0800 $
    Revision:       $Revision: 10194 $
    
    Description:    
            
    Notes:  

*********************************************************************/

/*********************************************************************
 * INCLUDES
 */
#include <string.h> 

#include "analyseframe.h" 
#include "uart.h" 
#include "web.h"

/*********************************************************************
 * LOCAL VARIABLES
 */ 
cmd_frame_t cmd_frame = {0xF5, 0xFA, 0xFB, 0xFF};
info_frame_t info_frame;
char query_string_data[MAX_QUERY_STRING_LENGTH];
unsigned char frame_ready = FRAME_FINISHED;

unsigned char wait_for_dealed_buf[2][RX_BUF_SIZE];
unsigned char save_cmd_enable = 0;				//接收完成标志

 
/*********************************************************************
 * CONSTANTS
 */
const char *device_head_table[MAX_DEVICE_HEAD_LENGTH] = 
{
	"device", "cmd", "location", "operation", "address",
};


/*********************************************************************/
const char *dxc_timeslot_table[7] = 
{
	"src_board", "src_port", "src_timeslot", "dst_board", "dst_port", "dst_timeslot", "dxc_flag",
};

const char *V35_work_mode_table[8] = 
{
	"board_num", "port_num", "work_mode", "work_rxp", "work_txp", "work_clk", "main_clk", "mode_type",
};

const char *V35_frame_type_table[3] = 
{
	"board_num", "port_num", "frame_type",
};

const char *V35_timeslot_table[3] = 
{
	"board_num", "port_num", "down_timeslot",
};

const char *CLK_prio_table[10] =
{
	"prio1", "prio2", "prio3", "prio4", "prio5", "prio6", "prio7", "prio8", "prio9", "prio10",
};

const char *FE_up_band_table[2] = 
{
	"board_num", "up_band",
};

const char *FE_port_band_table[3] = 
{
	"board_num", "port_num", "port_band",
};

const char *FE_vlan_mode_table[2] = 
{
	"board_num", "vlan_mode",
};

const char *FE_vlan_group_table[6] = 
{
	"board_num", "vlan_group", "vlan_port1", "vlan_port2", "vlan_port3", "vlan_port4", 
};

const char *FE_vlan_tag_table[3] = 
{
	"board_num", "vlan_group", "vlan_tag",
};

const char *phone_number_table[1] = 
{
	"telephone_number",
};

const char *port_loop_table[3] = 
{
	"board_num", "port_num", "loop_flag", 
};

const char *OPT_switch_table[1] = 
{
	"switch_flag", 
};

const char *OPT_enable_table[2] = 
{
	"opt1_enable", "opt2_enable", 
};

const char *system_time_table[6] = 
{
	"time_year", "time_month", "time_day", "time_hour", "time_minute", "time_second",
};

const char *alarm_mask_table[13] = 
{
	"board_num", "port_num", "mask_flag", "alm_id01",  "alm_id02", "alm_id03", "alm_id04", "alm_id05", "alm_id06", "alm_id07", "alm_id08", "alm_id09", "alm_id10",
};

const char *alarm_level_table[11] = 
{
	"alm_level", "alm_id01", "alm_id02", "alm_id03", "alm_id04", "alm_id05", "alm_id06", "alm_id07", "alm_id08", "alm_id09", "alm_id10", 
};



/*********************************************************************/

const cmd_type_t cmd_types[MAX_CMD_NUMBER] = 
{
	{"dxc_timeslot", CMD_SET_DXC_TIMESLOT, CMD_READ_DXC_TIMESLOT},
	{"V35_work_mode", CMD_SET_V35_WORKMODE, CMD_READ_V35_WORKMODE},
//	{"V35_frame_type", CMD_SET_V35_FRAMETYPE, CMD_READ_V35_FRAMETYPE},
	{"V35_timeslot", CMD_SET_V35_TIMESLOT, CMD_READ_V35_TIMESLOT},
	{"V35_attribute", CMD_READ_V35_ATTRIBUTE, CMD_READ_V35_ATTRIBUTE},
	{"CLK_prio", CMD_SET_CLOCK_PRIO, CMD_READ_CLOCK_PRIO},
	{"read_work_clock", CMD_READ_WORK_CLOCK, CMD_READ_WORK_CLOCK},
	{"read_clock_info", CMD_READ_CLOCK_INFO, CMD_READ_CLOCK_INFO},
	{"FE_up_band", CMD_SET_FE_UP_BAND, CMD_READ_FE_UP_BAND},
	{"FE_port_band", CMD_SET_FE_PORT_BAND, CMD_READ_FE_PORT_BAND},
	{"FE_vlan_mode", CMD_SET_VLAN_MODE, CMD_READ_VLAN_MODE},
	{"FE_vlan_group", CMD_SET_VLAN_GROUP, CMD_READ_VLAN_GROUP},
	{"FE_vlan_tag", CMD_SET_VLAN_TAG, CMD_READ_VLAN_TAG},
	{"read_work_board", CMD_READ_WORK_BOARD, CMD_READ_WORK_BOARD},	
	{"phone_number", CMD_SET_PHONE_NUMBER, CMD_READ_PHONE_NUMBER},
	
	{"port_loop", CMD_SET_LOOP, CMD_READ_LOOP},
	{"OPT_switch", CMD_SET_OPT_SWITCH, CMD_READ_OPT_SWITCH},
	{"OPT_enable", CMD_SET_OPT_ENABLE, CMD_READ_OPT_ENABLE},
	
	{"system_time", CMD_SET_SYSTEM_TIME, CMD_SET_SYSTEM_TIME},	
	{"read_mcu_version", CMD_READ_MCU_VERSION, CMD_READ_MCU_VERSION},
	{"read_device_type", CMD_READ_DEVICE_TYPE, CMD_READ_DEVICE_TYPE},	
	
	{"read_alarm", CMD_READ_ALARM, CMD_READ_ALARM},
	{"alarm_mask", CMD_SET_ALARM_MASK, CMD_READ_ALARM_MASK},
	{"alarm_level", CMD_SET_ALARM_LEVEL, CMD_SET_ALARM_LEVEL},
	{"read_event", CMD_READ_EVENT, CMD_READ_EVENT},	
	
};

const clk_type_t clk_types[23] = 
{
	{"NONE", 0}, 
	{"OPT1", 1}, 
	{"OPT2", 2}, 
	{"PORT_OPT1", 3}, 
	{"PORT_OPT1", 4}, 
	{"BOARD1_PORT1", 5}, 
	{"BOARD1_PORT2", 6}, 
	{"BOARD1_PORT3", 7}, 
	{"BOARD1_PORT4", 8}, 
	{"BOARD2_PORT1", 9}, 
	{"BOARD2_PORT2", 10}, 
	{"BOARD2_PORT3", 11}, 
	{"BOARD2_PORT4", 12}, 
	{"BOARD3_PORT1", 13}, 
	{"BOARD3_PORT2", 14}, 
	{"BOARD3_PORT3", 15}, 
	{"BOARD3_PORT4", 16}, 
	{"BOARD4_PORT1", 17}, 
	{"BOARD4_PORT2", 18}, 
	{"BOARD4_PORT3", 19}, 
	{"BOARD4_PORT4", 20}, 
	{"FREE", 21}, 
	{"EXT_CLOCK", 22}, 
};

/*********************************************************************/

const char *string_to_hex_zero[7] = 
{
	"0", "DTE", "INT", "UNFRAME", "PORT", "MASTER", "DISABLE",
};

const char *string_to_hex_one[7] = 
{
	"1", "DCE", "EXT", "FRAME", "TAG", "SLAVE", "ENABLE",
};








  
 
/*********************************************************************
 * FUNCTIONS
 */ 

//将ASCII 码转换为HEX(16进制)码
unsigned char AsciiToHex(unsigned char ascii)
{
	volatile unsigned char hex_num;

	if ((ascii >= '0') && (ascii <= '9'))
		hex_num = ascii - '0';
	else if ((ascii >= 'a') && (ascii <= 'f'))
		hex_num = ascii - 'a' + 0x0A;
	else if ((ascii >= 'A') && (ascii <= 'F'))
		hex_num = ascii - 'A' + 0x0A;	
	else
		hex_num = ascii;
 	
	return(hex_num);
}


//将HEX(16进制)码转换为ASCII 码
unsigned char HexToAscii(unsigned char hex)
{
	volatile unsigned char ascii_num;

	//if ((hex >= 0x00) && (hex <= 0x09))
	if (hex <= 0x09)
		ascii_num = hex + '0';
	else if ((hex >= 0x0A) && (hex <= 0x0F))	
		ascii_num = hex - 0x0A + 'A';
	else
		ascii_num = 0x5A;				//ASCII "Z"

	return(ascii_num);
}
 
//查找指定字符串2 在字符串1 中的位置 
int strspos(char *string1, char *string2, unsigned int count)
{
	int length = 0, offset = 0;
	int position = 0;
	int str_pos = 0xffff;
	char *start = string1;
	char *compare = string2;

	while (*compare)
	{	
		//position = strpos(start + offset, *compare);		
		position = strcspn(start + offset, compare);			//strcspn 与strpos 函数功能基本一致		
		if ((position == 0xffff) || ((position + offset) >= count))
		{
	 		return (0xffff);
		}

		if (length == 0)
		{
			str_pos = position + offset;
			offset = str_pos + 1;
			length++;
			compare++;
		}
		else
		{
			if (position == 0)
			{				
				length++;
				offset++;
				compare++;				
			}
			else
			{
			 	length = 0;
				offset++;
				compare = string2;
			}
		}
	}
	if ((str_pos+1) >= strlen(string1))
		str_pos = 0xffff;
	return (str_pos);
} 


//处理网页表单传入的数据 
void operate_query_string(char *string)
{
	char *query_string = string;
	cmd_frame_t *p_cframe = &cmd_frame;
	info_frame_t *p_iframe = &info_frame;
	const cmd_type_t *cmd_type = cmd_types; 
	unsigned char tmp_buf[MAX_DEVICE_HEAD_LENGTH][20];
	unsigned int i;
	unsigned short int address;

#ifdef DEBUG_MODE
	printf("<p>data is: %s</p>", string);
	printf("<p>length is: %d</p>", strlen(string));
#endif
	
	for (i=0; i<MAX_DEVICE_HEAD_LENGTH; i++)
	{
		query_string = string + strspos(string, (char *)device_head_table[i], MAX_QUERY_STRING_LENGTH);
		sscanf(query_string, "%*[^=]=%[^&]", tmp_buf[i]);
#ifdef DEBUG_MODE
		printf("<p>%s is: %s</p>", device_head_table[i], tmp_buf[i]);
#endif
	}
	
	if (strcmp(tmp_buf[0], "E1_BOARD") == 0)									//device_id
		p_iframe->device_id = E1_BOARD;
	else if (strcmp(tmp_buf[0], "V35_BOARD") == 0)
		p_iframe->device_id = V35_BOARD;	
	else if (strcmp(tmp_buf[0], "FE_BOARD") == 0)	
		p_iframe->device_id = FE_BOARD;
	else if (strcmp(tmp_buf[0], "MAIN_BOARD") == 0)	
		p_iframe->device_id = MAIN_BOARD;
/*	
	printf("<p>device_name is: %s</p>", tmp_buf[0]);
	printf("<p>cmd_name is: %s</p>", tmp_buf[1]);
	printf("<p>location is: %s</p>", tmp_buf[2]);
	printf("<p>operation is: %s</p>", tmp_buf[3]);
*/	
	sscanf(tmp_buf[4], "%hd", &address);
	p_cframe->dst_addr[1] = (unsigned char)(address >> 8);
	p_cframe->dst_addr[2] = (unsigned char)(address);
	
	//printf("<p>dst_addr1 is: %x</p>", p_cframe->dst_addr[1]);
	//printf("<p>dst_addr2 is: %x</p>", p_cframe->dst_addr[2]);
	for (i=0; i<MAX_CMD_NUMBER; i++)																//cmd_code_send
	{
		if (strcmp(tmp_buf[1], cmd_type[i].cmd_name) == 0)
		{
			if (strcmp(tmp_buf[3], "set") == 0)
				p_cframe->cmd_code_send = cmd_type[i].cmd_set;
			else if (strcmp(tmp_buf[3], "query") == 0)
				p_cframe->cmd_code_send = cmd_type[i].cmd_read;
			break;
		}
	}	

#ifdef DEBUG_MODE	
	printf("<p>cmd_code_send is: %x</p>", p_cframe->cmd_code_send);
#endif
	analysis_web_cmd(string);			

} 
 
 
//解帧并下发
void analysis_web_cmd(char *string)
{
	cmd_frame_t *p_cframe = &cmd_frame;
	info_frame_t *p_iframe = &info_frame;	
	char *query_string = string;
	unsigned char info_buf[14][15];
	//unsigned char frame[20];
	unsigned char temp_buf[3];
	unsigned int i, k = 0;
	unsigned int idx = 0;
	unsigned int offset;
	unsigned char tmp_val = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -