Преглед изворни кода

2020-08-27 / Eason Yang
Action
1. Rename version.
2. Synchronize from AW-Regular.Fixed issue. V0.52.XX.XXXX.XX->V0.56.XX.XXXX.XX

File
1.main.c
Action 1.
Action 2.

Version :V0.43.XX.XXXX.XX

8009 пре 4 година
родитељ
комит
ea78c0c329

+ 148 - 45
EVSE/Projects/Noodoe/Apps/main.c

@@ -46,6 +46,7 @@ void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
 void split(char **arr, char *str, const char *del);
 
 int isReachableInternet();
+int isRouteFail();
 int InitRfidPort(void);
 int GetCardSerialNumber();
 void setLedMotion(unsigned char gun_index,unsigned char led_mode);
@@ -969,6 +970,19 @@ void InitEthernet()
 	{
 		for(;;)
 		{
+			if(isRouteFail())
+			{
+				DEBUG_ERROR("eth0 not in route, restart eth0.\n");
+				system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
+				
+				if((ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient==0))
+				{
+					system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
+					sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
+					system(tmpbuf);
+				}
+			}
+			
 			if(isReachableInternet() == PASS)
 			{
 				ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=OFF;
@@ -976,15 +990,20 @@ void InitEthernet()
 			}
 			else
 			{
-				if(++cnt_pingDNS_Fail > 3)
+				if(cnt_pingDNS_Fail >= 3)
 				{
-					ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=ON;
+					ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=ON;					
+				}
+				else
+				{
+					cnt_pingDNS_Fail++;
 				}
 			}
 			
 			if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet &&
 			   ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi &&
-			   ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi)
+			   ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi &&
+			   (ShmOCPP16Data->OcppConnStatus != PASS))
 			{
 				ShmSysConfigAndInfo->SysInfo.InternetConn = OFF;
 			}
@@ -992,6 +1011,50 @@ void InitEthernet()
 			{
 				ShmSysConfigAndInfo->SysInfo.InternetConn = ON;
 			}
+			
+			//============================================================
+			// Priority for internet  0 : First / 1 : Second / 2: Third 
+			//============================================================
+			if(!ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet)
+			{
+				system("/sbin/ifmetric eth0 0");
+				
+				if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+				{
+					system("/sbin/ifmetric mlan0 1");
+				}
+				
+				if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+				{
+					system("/sbin/ifmetric ppp0 2");
+				}
+			}
+			else if(!ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi)
+			{
+				if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+				{
+					system("/sbin/ifmetric eth0 1");
+					system("/sbin/ifmetric mlan0 0");
+				}
+				
+				if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+				{
+					system("/sbin/ifmetric ppp0 2");
+				}
+			}
+			else if(!ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi)
+			{
+				if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+				{
+					system("/sbin/ifmetric mlan0 2");
+				}
+				
+				if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+				{
+					system("/sbin/ifmetric eth0 1");
+					system("/sbin/ifmetric ppp0 0");
+				}
+			}
 
 			sleep(5);
 		}
@@ -1019,6 +1082,11 @@ int SpawnTask()
 	{
 		system("/root/Module_Wifi &");
 	}
+	else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
+	{
+		system("/root/Module_4g &");
+		system("/root/Module_Wifi &");
+	}
 
 	system("/root/Module_EventLogging &");
 	if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0)
@@ -1187,7 +1255,7 @@ void get_firmware_version(unsigned char gun_index)
 	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.42.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.43.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -1246,6 +1314,11 @@ void get_firmware_version(unsigned char gun_index)
 			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
 			ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[9] = '2';
 			break;
+		case 'D':
+			// WIFI + 4G
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '5';
+			ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[9] = '5';
+			break;
 		default:
 			// LAN
 			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
@@ -1640,63 +1713,79 @@ int isReachableInternet()
 	char buf[512];
 	char tmp[512];
 	
-	if(ShmOCPP16Data->OcppConnStatus == PASS)
-	{
-		result = PASS;
-	}
-	else
-	{
-		strcpy(cmd, "ifconfig eth0");
-		fp = popen(cmd, "r");
+	strcpy(cmd, "ifconfig eth0");
+	fp = popen(cmd, "r");
 
-		if (fp != NULL)
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
 		{
-			while(fgets(buf, sizeof(buf), fp) != NULL)
+			if (strstr(buf, "inet addr:") > 0)
 			{
-				if (strstr(buf, "inet addr:") > 0)
-				{
-					sscanf(buf, "%*s%s", tmp);
-					substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
+				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);
-					}
+				if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != 0)
+				{
+					strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
 				}
 			}
 		}
-		pclose(fp);
-		memset(buf, 0x00, sizeof(buf));
+	}
+	pclose(fp);
+	memset(buf, 0x00, sizeof(buf));
 
-		for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
+	for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
+	{
+		sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
+		fp = popen(cmd, "r");
+		if(fp != NULL)
 		{
-			sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
-			fp = popen(cmd, "r");
-			if(fp != NULL)
+			while(fgets(buf, sizeof(buf), fp) != NULL)
 			{
-				while(fgets(buf, sizeof(buf), fp) != NULL)
+				if(strstr(buf, "transmitted") > 0)
 				{
-					if(strstr(buf, "transmitted") > 0)
-					{
-						//sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
+					//sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
 
-						if(strstr(buf,"100%") != NULL)
-						{
+					if(strstr(buf,"100%") != NULL)
+					{
 
-						}
-						else
-						{
-							result = PASS;
-						}
-						//DEBUG_INFO("%s",buf);
-						//DEBUG_INFO("%s\n",tmp);
 					}
+					else
+					{
+						result = PASS;
+					}
+					//DEBUG_INFO("%s",buf);
+					//DEBUG_INFO("%s\n",tmp);
 				}
 			}
-			pclose(fp);
 		}
+		pclose(fp);
 	}
+	
+	return result;
+}
 
+//===============================================
+// Check route for eth0
+//===============================================
+int isRouteFail()
+{
+	int result = YES;
+	FILE *fp;	
+	char buf[512];	
+	
+	fp = popen("route -n", "r");
+	if(fp != NULL)		
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{			
+			if(strstr(buf, "eth0") != NULL)
+				result = NO;
+		}		
+	}
+	pclose(fp);
+	
 	return result;
 }
 
@@ -1779,7 +1868,6 @@ int getScheduleStart(int gun_index)
 		tbScheduleStart.millitm = 0;
 
 		result = DiffTimebWithNow(tbScheduleStart)/1000;
-		
 		//DEBUG_INFO("Schedule start compare Now(seconds): %d\r\n", result);
 	}
 	else
@@ -1808,7 +1896,6 @@ int getStartSinceToday()
 	tbStartToday.time = mktime(tmStartToday);
 
 	result = DiffTimebWithNow(tbStartToday)/1000;
-	
 	//DEBUG_INFO("Start today compare Now(seconds): %d\r\n", result);
 
 	return result;
@@ -1833,7 +1920,6 @@ int getStartSinceWeek()
 	tbStartWeek.time = mktime(tmStartWeek);
 
 	result = DiffTimebWithNow(tbStartWeek)/1000;
-	
 	//DEBUG_INFO("Start week compare Now(seconds): %d\r\n", result);
 
 	return result;
@@ -1911,6 +1997,20 @@ void checkTask()
 			system("/root/Module_Wifi &");
 		}
 	}
+	else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
+	{
+		if(system("pidof -s Module_4g > /dev/null") != 0)
+		{
+			DEBUG_INFO("Module_4g not running, restart it.\r\n");
+			system("/root/Module_4g &");
+		}
+		
+		if(system("pidof -s Module_Wifi > /dev/null") != 0)
+		{
+			DEBUG_INFO("Module_Wifi not running, restart it.\r\n");
+			system("/root/Module_Wifi &");
+		}
+	}
 
 	if(system("pidof -s Module_EventLogging > /dev/null") != 0)
 	{
@@ -2983,6 +3083,8 @@ int main(void)
 
 						getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
 						startTime[gun_index][TMR_IDX_AUTH].time -= TIMEOUT_SPEC_AUTH;
+						
+						sleep(3);
 					}
 
 					// End authorize pass
@@ -3189,6 +3291,7 @@ int main(void)
 					if(isModeChange(gun_index))
 					{
 						setLedMotion(gun_index, LED_ACTION_STOP);
+						sleep(3);
 					}
 
 					if(ShmOCPP16Data->MsMsg.bits.ResetReq)

BIN
EVSE/Projects/Noodoe/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/Noodoe/Images/ramdisk.gz