Browse Source

[Improve][Added][AW-CCS][main.c]
2022-04-27 / EASON YANG
Action
1.Added: InitEthernet() function. Bridge eth/wifi , lo up.
2.Improve: checkChargingProfileLimit() function. Lcoal power sharing in check limit.
3.Improve: checkTask() function. OCPP and local power sharing coexist.

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

FIRMWARE VERSION: B0.62.XX.XXXX.PX

8009 2 years ago
parent
commit
681f2d3bf6
1 changed files with 41 additions and 20 deletions
  1. 41 20
      EVSE/Projects/AW-CCS/Apps/main.c

+ 41 - 20
EVSE/Projects/AW-CCS/Apps/main.c

@@ -2422,6 +2422,11 @@ void InitEthernet()
 	char tmpbuf[256];
 	unsigned int natInterface = 0;
 
+	// Detele bridge interface
+	system("/sbin/ifconfig uap0 down");
+	system("/sbin/ifconfig br0 down");
+	system("/usr/sbin/brctl delbr br0");
+
 	//Init Eth0 for internet
 	memset(tmpbuf,0,256);
 	sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up &",
@@ -2661,6 +2666,25 @@ void InitEthernet()
 				refreshStartTimer(&startTime[0][TMR_IDX_RESET_WIFI]);
 			}
 
+			// Bridge ethernet to uap0 to get dynamic ip address
+			if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing &&
+			  (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == 2) &&
+			  (isUap0up() == PASS) &&
+			  (access("/sys/class/net/br0/address", F_OK) == -1))
+			{
+				sleep(10);
+				system("/usr/sbin/brctl addbr br0");
+				system("/usr/sbin/brctl addif br0 eth0");
+				system("/usr/sbin/brctl addif br0 uap0");
+				system("/sbin/ifconfig br0 192.168.10.200 up");
+				system("/bin/sed -i '/interface/d' /etc/udhcpd.conf");
+				system("/bin/echo 'interface	br0' >> /etc/udhcpd.conf");
+				system("kill udhcpd");
+				system("/usr/sbin/udhcpd /etc/udhcpd.conf");
+
+				DEBUG_INFO("Bridge uap0 & eth0 for local power sharing by ethernet.\n");
+			}
+
 			sleep(5);
 		}
 	}
@@ -4031,7 +4055,7 @@ void checkTask()
 		system("/root/Module_EventLogging &");
 	}
 
-	if((strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) && !ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing)
+	if((strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0))
 	{
 		if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 		{
@@ -4069,7 +4093,7 @@ void checkTask()
 		}
 	}
 
-	if((strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) && !ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing)
+	if((strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0))
 	{
 		if(system("pidof -s OcppBackendPH > /dev/null") != 0)
 		{
@@ -4458,6 +4482,20 @@ void checkChargingProfileLimit(uint8_t gun_index, uint8_t system_mode)
 		}
 	}
 
+	// Charging session target current check if OCPP disconnect and power sharing server connected
+	if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > 0)
+	{
+		if(ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer)
+		   ShmCharger->gun_info[gun_index].targetCurrent = ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent[gun_index]>ShmCharger->gun_info[gun_index].primaryMcuState.rating_current?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent[gun_index];
+		else
+		{
+			if(ShmCharger->gun_info[gun_index].targetCurrent != 0)
+				DEBUG_WARN("Disconnect from power sharing server, target current set to 0.\n");
+
+			ShmCharger->gun_info[gun_index].targetCurrent = 0;
+		}
+	}
+
 	switch(system_mode)
 	{
 		case SYS_MODE_IDLE:
@@ -5508,14 +5546,11 @@ int main(void)
 						ShmCharger->gun_info[gun_index].isSleepOn = NO;
 
 						// If Web Server OPCC URL is empty kill Module_OcppBackend
-						if((strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") == 0) || ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing)
+						if((strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") == 0))
 						{
 							if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") == 0)
 								DEBUG_INFO("URL is empty kill Module_OcppBackend...\n");
 
-							if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing)
-								DEBUG_INFO("Local power sharing enable kill Module_OcppBackend...\n");
-
 							system ("pkill OcppBackend");
 						}
 
@@ -6288,20 +6323,6 @@ int main(void)
 						// Checking profile id > 0 and current time is between charging profile validFrom & validTo
 						checkChargingProfileLimit(gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus);
 
-						// Charging session target current check if OCPP disconnect and power sharing server connected
-						if(!ocpp_get_connection_status() && ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing)
-						{
-							if(ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer)
-								ShmCharger->gun_info[gun_index].targetCurrent = ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent;
-							else
-							{
-								if(ShmCharger->gun_info[gun_index].targetCurrent != 0)
-									DEBUG_WARN("Disconnect from power sharing server, target current set to 0.\n");
-
-								ShmCharger->gun_info[gun_index].targetCurrent = 0;
-							}
-						}
-
 						// Charging session local limit condition check
 						if(ocpp_get_connection_status())
 						{