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

📄 input.c

📁 ADC图形图像例子
💻 C
字号:
/********************************************************************
 * File: INPUT.c
 * 
 * Copyright: Peak Microtech Corporation
 *
 *******************************************************************/

#define INPUT_GLOBALS
#include "net_cfg.h"


 // String compare
 // 1: Command_Buf include the string
 // 0: Command_Buf not include the string
uchar Str_Compare(unsigned char *string, uchar number)
{
	uchar i;
	uchar temp;

	for (i = 0; i < number; i++)
	{
		temp = Command_Buf[i];
		if (temp != (*string))
		{
			return (0);
		}
		string++;
	}
	return (1);
}


/* command list:
 *			1.:setgate xxx.xxx.xxx.xxx, Set gate IP address
 *			2.:setip xxx.xxx.xxx.xxx, Set my IP address
 *			3.:ping xxx.xxx.xxx.xxx, ping command
 *			4.:UDP xxx.xxx.xxx.xxx.1025.data, udp command
 *				1025 is port; data is send data				 */

// Deal with the input command
void process_command()
{
	uchar i;
	uint ip;
	uchar j;	

	if (Command_Len > 9)	// The size of one correct ping command > 9 byte	
		if ((Str_Compare("ping", 4) != 0) || (Str_Compare("PING", 4) != 0))
	// ping command parse
	{		
		ip = 0;
		for (i = 5, j = 0; i < Command_Len + 1; i++)
		// space
		{
			if (Command_Buf[i] != '.')
			{
				Command_Buf[i] = Command_Buf[i] &0x0f;
				ip = ip * 10;
				ip = ip + Command_Buf[i];
			}
			else
			{
				Ping_Ip_Address.bytes[j] = ip;
				j++;
				ip = 0;
			}
		}
		if (j == 3)
		{
			Ping_Ip_Address.bytes[j] = ip;
			// command correct
			UartPrintfCh1("\r\nPing IP=");
			Printf_IPStr(Ping_Ip_Address);
			UartPrintfCh1("\r\n");
			Ping_Count = 6;

			if ((Ping_Ip_Address.dwords &Mask_Ip_Address.dwords) ==
				(My_Ip_Address.dwords &Mask_Ip_Address.dwords))
			{
				// the same subway
				if ((Ping_Ip_Address.dwords == Gateway_Ip_Address.dwords) &(Gateway_IP_TTL
					> 5))
				{
					for (i = 0; i < 3; i++)
					{
						Ping_MAC.words[i] = Gateway_MAC.words[i];	
					}
					Ping_Request();
				}
				else
				{
					Arp_Request(Ping_Ip_Address.dwords);
				}
			}
			else
			// In other subway.
			{
				UartPrintfCh1("\r\nThe Host IS In other Subnet");
				Ping_IP_TTL = 10;
				for (j = 0; j < 6; j++)
				{
					Ping_MAC.bytes[j] = Gateway_MAC.bytes[j];
				}
				if (Gateway_IP_TTL == 0)
				{
					UartPrintfCh1("\r\nGateWay Not Found!\r\nC:>");
					Ping_Count = 0;
				}
			}
		}
		else
		{
			UartPrintfCh1("\r\nPing Command Error\r\nC:>");
		}
	}
	
	// Set my IP address
	if ((Str_Compare("setip", 5) != 0) || (Str_Compare("SETIP", 5) != 0))
	{		
		ip = 0;
		for (i = 6, j = 0; i < Command_Len + 1; i++)		
		{
			if (Command_Buf[i] != '.')
			{
				Command_Buf[i] = Command_Buf[i] &0x0f;
				ip = ip * 10;
				ip = ip + Command_Buf[i];
			}
			else
			{
				My_Ip_Address.bytes[j] = ip;
				j++;
				ip = 0;
			}
		} // command execute
		if (j == 3)
		{
			My_Ip_Address.bytes[j] = ip;
		}
		UartPrintfCh1("\r\nLOCAL IP WAS SET TO ");
		Printf_IPStr(My_Ip_Address);
		UartPrintfCh1("\r\n");
	}
	
	// Set gate IP address
	if ((Str_Compare("setgate", 7) != 0) || (Str_Compare("SETGATE", 7) != 0))
	{
		ip = 0;
		for (i = 8, j = 0; i < Command_Len + 1; i++)		
		{
			if (Command_Buf[i] != '.')
			{
				Command_Buf[i] = Command_Buf[i] &0x0f;
				ip = ip * 10;
				ip = ip + Command_Buf[i];
			}
			else
			{
				Gateway_Ip_Address.bytes[j] = ip;
				j++;
				ip = 0;
			}
		}

		if (j == 3)
		// Command execute
		{
			Gateway_Ip_Address.bytes[j] = ip;
		}
		UartPrintfCh1("GATEWAY WAS SET TO ");
		Printf_IPStr(Gateway_Ip_Address);
		UartPrintfCh1("\r\n");

	}
	
	// Deal with udp command
	if ((Str_Compare("udp", 3) != 0) || (Str_Compare("UDP", 3) != 0))
	{
		ip = 0;
		for (i = 4, j = 0; i < Command_Len + 1; i++)
		{
			// Get IP address
			if (Command_Buf[i] != '.')
			{
				Command_Buf[i] = Command_Buf[i] &0x0f;
				ip = ip * 10;
				ip = ip + Command_Buf[i];
			}
			else
			{
				if (j < 4)
					Ping_Ip_Address.bytes[j] = ip;
				if (j == 4)
				{
					RemotePort.word = ip;
					Printf_PortStr(RemotePort.word);
				}
				j++;
				if (j == 5)
				{
					Command_Buf[0] = i + 1;
					Command_Len = Command_Len - i;
					Command_Buf[1] = Command_Len >> 8;
					Command_Buf[2] = Command_Len &0xff;					
					break; 
				}
				ip = 0;
			}
		}
		
		if (j == 5)
		{
			// command correct
			UartPrintfCh1("\r\nUDP:DestIP=");
			Printf_IPStr(Ping_Ip_Address);
			UartPrintfCh1(" RemotePort=");
			Printf_PortStr(RemotePort.word);
			Udp_Count = 10; //10second
			if ((Ping_Ip_Address.dwords &Mask_Ip_Address.dwords) ==
				(My_Ip_Address.dwords &Mask_Ip_Address.dwords))
			{
				// The same subway
				Arp_Request(Ping_Ip_Address.dwords);
			}
			else
			{
				// In other subway
				Ping_IP_TTL = 10;
				for (j = 0; j < 6; j++)
				{
					Ping_MAC.bytes[j] = Gateway_MAC.bytes[j];
				}
				if (Gateway_IP_TTL == 0)
				{
					UartPrintfCh1("\r\nGateWay Not Found!\r\nC:>");
					Udp_Count = 0;
				}
			}
		}
		else
		{
			UartPrintfCh1("\r\nudp Command Error\r\nC:>");
		}
	}
	Command_Len = 0;
}

⌨️ 快捷键说明

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