Selaa lähdekoodia

[Improve][Modularization][Module_Wifi]

2021.01.13 / Folus Wen

Actions:
1. Wifi interface gateway info parsing implement.

Files:
1. As follow commit history

Image version: V0.16
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 4 vuotta sitten
vanhempi
commit
ade9aebf71

+ 10 - 4
EVSE/Modularization/Module_Wifi.c

@@ -260,7 +260,7 @@ int isValidCheckSum(uint8_t *message);
 char *Support_InterfaceSTA[2]	= {"mlan0", "wlan0"};
 char *Support_InterfaceAP[1]	= {"uap0"};
 char *valid_Internet[2]			= {"8.8.8.8", "180.76.76.76"};
-char *Version_And_Date[2]		= {"V0.15","2020-11-26"};
+char *Version_And_Date[2]		= {"V0.16","2021-01-13"};
 int protocol_Version [] 		= {0,7,0};
 
 int StoreLogMsg(const char *fmt, ...)
@@ -567,11 +567,17 @@ int getInterfaceInfo()
 	{
 		while(fgets(buf, sizeof(buf), fp) != NULL)
 		{
-			if(strncmp(buf, "default", strlen("default")) == 0)
+#ifdef UBLOX
+			if((strstr(buf, "default") != NULL) && (strstr(buf, "mlan0") != NULL))
+#endif
+
+#ifdef MT7601U
+			if((strstr(buf, "default") != NULL) && (strstr(buf, "wlan0") != NULL))
+#endif
 				break;
 		}
 		
-		if(strncmp(buf, "default", strlen("default")) == 0)
+		if(strstr(buf, "default") != NULL)
 		{
 			sscanf(buf, "%*s%*s%s", tmp);
 			substr(Wifi.currentGateway, tmp, 0, strlen(tmp));
@@ -4711,7 +4717,7 @@ unsigned int isKernelSupportNAT()
 		if(fgets(buf, sizeof(buf), fp) != NULL)
 		{
 			sscanf(buf, "#%d", &version);
-			DEBUG_INFO("Kernel version: %d\n", result);
+			DEBUG_INFO("Kernel version: %d\n", version);
 
 			if(version >= 30)
 				result = YES;

+ 31 - 4
EVSE/Projects/AW-CCS/Apps/main.c

@@ -246,7 +246,7 @@ unsigned int isKernelSupportNAT()
 		if(fgets(buf, sizeof(buf), fp) != NULL)
 		{
 			sscanf(buf, "#%d", &version);
-			DEBUG_INFO("Kernel version: %d\n", version);
+			//DEBUG_INFO("Kernel version: %d\n", version);
 
 			if(version >= 30)
 				result = YES;
@@ -2505,10 +2505,9 @@ int isReachableInternet()
 	char buf[512];
 	char tmp[512];
 	
-
+	// Get ip address & net mask
 	strcpy(cmd, "ifconfig eth0");
 	fp = popen(cmd, "r");
-
 	if (fp != NULL)
 	{
 		while(fgets(buf, sizeof(buf), fp) != NULL)
@@ -2517,17 +2516,45 @@ int isReachableInternet()
 			{
 				sscanf(buf, "%*s%s", tmp);
 				substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
-
 				if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != 0)
 				{
 					strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
 				}
+
+				sscanf(buf, "%*s%*s%*s%s", tmp);
+				substr(tmp, tmp, strspn(tmp, "Mask:"), strlen(buf)-strspn(tmp, "Mask:"));
+				if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress) != 0)
+				{
+					strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress, tmp);
+				}
 			}
 		}
 	}
 	pclose(fp);
 	memset(buf, 0x00, sizeof(buf));
 
+	// Get gateway
+	fp = popen("ip route", "r");
+	if(fp == NULL)
+		result = FAIL;
+	else
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if((strstr(buf, "default") != NULL) && (strstr(buf, "eth0") != NULL))
+				break;
+		}
+
+		if(strstr(buf, "default") != NULL)
+		{
+			sscanf(buf, "%*s%*s%s", tmp);
+			substr((char*)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress, tmp, 0, strlen(tmp));
+		}
+	}
+	pclose(fp);
+	memset(buf, 0x00, sizeof(buf));
+
+
 	for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
 	{
 		sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);

+ 1 - 0
EVSE/Projects/AW-Regular/Apps/main.c

@@ -948,6 +948,7 @@ void InitEthernet()
 	system(tmpbuf);
 	system("/sbin/ifconfig eth0:1 192.168.201.201 netmask 255.255.255.248 up &");
 	system("ifconfig lo up &");
+	system("/sbin/ethtool -s eth0 speed 10 duplex full autoneg off");
 
 	if(isInterfaceUp("eth1")==PASS)
 	{