Browse Source

Merge remote-tracking branch 'origin/AW-CCS'

FolusWen 3 years ago
parent
commit
4ccc6efe43

+ 310 - 98
EVSE/Projects/AW-CCS/Apps/LCM/Module_LcmControl.c

@@ -2,9 +2,9 @@
  * Module_LcmControl.c
  *
  * Created on : 2020-10-20
- * Update on : 2022-01-07
+ * Update on : 2022-01-17
  * Author : Folus Wen, Eason Yang
- * Version : V0.26
+ * Version : V0.27
  *
  */
 
@@ -44,6 +44,8 @@ void setQRCodeAlarm();
 void setEthernetIcon();
 uint8_t getCurrentPage();
 void setAlarmCodeAndIcon();
+void setPresentSessionFee();
+void setPresentParkingFee();
 void setBillingFromWebsite();
 int isEthConnected(char *eth);
 void setUserPrice(uint8_t type);
@@ -102,6 +104,8 @@ struct timespec					startTime[AC_QUANTITY][TMR_IDX_SHOW_AUTH_RESULT];
 #define TIME_AUTH_RESULT_TIME			5 // Unit: Second
 #define TIME_REFRESH_INFO				3 // Unit: Second
 
+#define is_error(ptr) 					((unsigned long)ptr > (unsigned long)-4000L)
+
 //=======================================
 // Declare Variable
 //=======================================
@@ -114,7 +118,7 @@ int Uart1Fd;
 //=======================================
 // Record version and date
 //=======================================
-char *FIRMWARE_UPDATE_IMAGE[3] = {"V0.26", "2022-01-07", "REV.02.00"};
+char *FIRMWARE_UPDATE_IMAGE[3] = {"V0.27", "2022-01-17", "REV.03.00"};
 
 //=======================================
 // Common routine
@@ -272,7 +276,8 @@ void getDateTimeString(char* result)
 	CurrentTime = time(NULL);
 	tm=localtime(&CurrentTime);
 
-	sprintf(result, "%04d/%02d/%02d %02d:%02d", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min);
+	//sprintf(result, "%04d/%02d/%02d %02d:%02d", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min);
+	sprintf(result, "%04d/%02d/%02d %02d:%02d %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,(tm->tm_hour%12),tm->tm_min,((tm->tm_hour/12)>0?"p.m":"a.m"));
 }
 
 //======================================================
@@ -468,6 +473,8 @@ void page_charging(uint8_t gun_index, uint8_t system_mode)
 				if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 				{
 					setRunningCost(gun_index, TOTAL_COST);
+					setRunningCost(gun_index, SESSION_FEE);
+					setRunningCost(gun_index, OCCUPANCY_FEE);
 				}
 				else
 				{
@@ -478,16 +485,29 @@ void page_charging(uint8_t gun_index, uint8_t system_mode)
 			{
 				if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
 				{
-					setDisplayValue(ICON_CHARGING_COST, APPEAR);
+					setDisplayValue(ICON_CHARGING_TOTAL_COST, APPEAR);
+					setDisplayValue(ICON_CHARGING_SESSION_FEE, APPEAR);
+					setDisplayValue(ICON_CHARGING_PARKING_FEE, APPEAR);
+
 					setPresentFinalCost(getPresentFinalCost(gun_index));
+					//setPresentSessionFee();
+					setPresentParkingFee();
 				}
 				else
 				{
-					// User spend cost
-					setDisplayValue(ICON_CHARGING_COST, DISAPPEAR);
-					setDisplayValue(TEXT_CHARGING_COST, DISAPPEAR);
+					// Total cost disappear
+					setDisplayValue(ICON_CHARGING_TOTAL_COST, DISAPPEAR);
+					setDisplayValue(TEXT_CHARGING_TOTAL_COST, DISAPPEAR);
+
+					// Session fee disappear
+					setDisplayValue(ICON_CHARGING_SESSION_FEE, DISAPPEAR);
+					setDisplayValue(TEXT_CHARGING_SESSION_FEE, DISAPPEAR);
 
-					// User account balance
+					// Parking fee disappear
+					setDisplayValue(ICON_CHARGING_PARKING_FEE, DISAPPEAR);
+					setDisplayValue(TEXT_CHARGING_PARKING_FEE, DISAPPEAR);
+
+					// User account balance disappear
 					setDisplayValue(ICON_COMPLETE_WALLET, DISAPPEAR);
 					setDisplayValue(TEXT_REMAINING_ACCOUNT_BALANCE, DISAPPEAR);
 				}
@@ -532,6 +552,8 @@ void page_complete(uint8_t gun_index, uint8_t system_mode)
 		if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 		{
 			setFinalCost(gun_index, TOTAL_COST);
+			setFinalCost(gun_index, SESSION_FEE);
+			setFinalCost(gun_index, OCCUPANCY_FEE);
 			setFinalCost(gun_index, ACCOUNT_BALANCE);
 			//setCurrencyAndUnitFromBackend(FINAL_COST, ACCOUNT_BALANCE, gun_index);
 		}
@@ -544,19 +566,32 @@ void page_complete(uint8_t gun_index, uint8_t system_mode)
 	{
 		if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
 		{
-			setDisplayValue(ICON_CHARGING_COST, APPEAR);
+			setDisplayValue(ICON_CHARGING_TOTAL_COST, APPEAR);
+			setDisplayValue(ICON_CHARGING_SESSION_FEE, APPEAR);
+			setDisplayValue(ICON_CHARGING_PARKING_FEE, APPEAR);
+
 			setPresentFinalCost(getPresentFinalCost(gun_index));
+			//setPresentSessionFee();
+			setPresentParkingFee();
 
 			setDisplayValue(ICON_COMPLETE_WALLET, DISAPPEAR);
 			setDisplayValue(TEXT_REMAINING_ACCOUNT_BALANCE, DISAPPEAR);
 		}
 		else
 		{
-			// User spend cost
-			setDisplayValue(ICON_CHARGING_COST, DISAPPEAR);
-			setDisplayValue(TEXT_CHARGING_COST, DISAPPEAR);
+			// Total cost disappear
+			setDisplayValue(ICON_CHARGING_TOTAL_COST, DISAPPEAR);
+			setDisplayValue(TEXT_CHARGING_TOTAL_COST, DISAPPEAR);
 
-			// User account balance
+			// Session fee disappear
+			setDisplayValue(ICON_CHARGING_SESSION_FEE, DISAPPEAR);
+			setDisplayValue(TEXT_CHARGING_SESSION_FEE, DISAPPEAR);
+
+			// Parking fee disappear
+			setDisplayValue(ICON_CHARGING_PARKING_FEE, DISAPPEAR);
+			setDisplayValue(TEXT_CHARGING_PARKING_FEE, DISAPPEAR);
+
+			// User account balance disappear
 			setDisplayValue(ICON_COMPLETE_WALLET, DISAPPEAR);
 			setDisplayValue(TEXT_REMAINING_ACCOUNT_BALANCE, DISAPPEAR);
 		}
@@ -582,6 +617,8 @@ void page_terminating(uint8_t gun_index, uint8_t system_mode)
 			if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 			{
 				setRunningCost(gun_index, TOTAL_COST);
+				setRunningCost(gun_index, SESSION_FEE);
+				setRunningCost(gun_index, OCCUPANCY_FEE);
 			}
 			else
 			{
@@ -592,16 +629,29 @@ void page_terminating(uint8_t gun_index, uint8_t system_mode)
 		{
 			if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
 			{
-				setDisplayValue(ICON_CHARGING_COST, APPEAR);
+				setDisplayValue(ICON_CHARGING_TOTAL_COST, APPEAR);
+				setDisplayValue(ICON_CHARGING_SESSION_FEE, APPEAR);
+				setDisplayValue(ICON_CHARGING_PARKING_FEE, APPEAR);
+
 				setPresentFinalCost(getPresentFinalCost(gun_index));
+				//setPresentSessionFee();
+				setPresentParkingFee();
 			}
 			else
 			{
-				// User spend cost
-				setDisplayValue(ICON_CHARGING_COST, DISAPPEAR);
-				setDisplayValue(TEXT_CHARGING_COST, DISAPPEAR);
+				// Total cost disappear
+				setDisplayValue(ICON_CHARGING_TOTAL_COST, DISAPPEAR);
+				setDisplayValue(TEXT_CHARGING_TOTAL_COST, DISAPPEAR);
+
+				// Session fee disappear
+				setDisplayValue(ICON_CHARGING_SESSION_FEE, DISAPPEAR);
+				setDisplayValue(TEXT_CHARGING_SESSION_FEE, DISAPPEAR);
+
+				// Parking fee disappear
+				setDisplayValue(ICON_CHARGING_PARKING_FEE, DISAPPEAR);
+				setDisplayValue(TEXT_CHARGING_PARKING_FEE, DISAPPEAR);
 
-				// User account balance
+				// User account balance disappear
 				setDisplayValue(ICON_COMPLETE_WALLET, DISAPPEAR);
 				setDisplayValue(TEXT_REMAINING_ACCOUNT_BALANCE, DISAPPEAR);
 			}
@@ -1092,15 +1142,52 @@ void setPriceFromWebsite(float monry_rate)
 //=======================================
 void setPresentFinalCost(float cost)
 {
-	uint8_t data[16];
-	uint8_t finalCost[16];
+	uint8_t data[32];
+	uint8_t finalCost[32];
 
 	memset(data, 0x00, ARRAY_SIZE(data));
 	memset(finalCost, 0x00, ARRAY_SIZE(finalCost));
 
 	sprintf((char *)finalCost, "%.2f", cost);
 	string2ByteArray(finalCost, data);
-	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_COST, data, ARRAY_SIZE(data));
+
+	// Total Cost
+	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_TOTAL_COST, data, ARRAY_SIZE(data));
+
+	// Session Fee
+	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_SESSION_FEE, data, ARRAY_SIZE(data));
+}
+
+//=======================================
+// Setting [ Session Fee ] ( WEB PAGE )
+//=======================================
+void setPresentSessionFee()
+{
+	uint8_t data[32];
+	uint8_t sessionFee[32];
+
+	memset(data, 0x00, ARRAY_SIZE(data));
+	memset(sessionFee, 0x00, ARRAY_SIZE(sessionFee));
+
+	strcpy((char*)sessionFee, "-----");
+	string2ByteArray(sessionFee, data);
+	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_SESSION_FEE, data, ARRAY_SIZE(data));
+}
+
+//=======================================
+// Setting [ Parking Fee ] ( WEB PAGE )
+//=======================================
+void setPresentParkingFee()
+{
+	uint8_t data[32];
+	uint8_t parkingFee[32];
+
+	memset(data, 0x00, ARRAY_SIZE(data));
+	memset(parkingFee, 0x00, ARRAY_SIZE(parkingFee));
+
+	strcpy((char*)parkingFee, "-----");
+	string2ByteArray(parkingFee, data);
+	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_PARKING_FEE, data, ARRAY_SIZE(data));
 }
 
 //=======================================
@@ -1310,62 +1397,127 @@ void setDefaultPrice(uint8_t type)
 //=======================================
 void setFinalCost(uint8_t gun_index, uint8_t type)
 {
-	uint8_t length;
 	uint8_t output_data[32];
-	char input_data[32];
-	char tmp[256];
-	char *splitString[10];
-	const char *Symbol = ";";
 	unsigned char cost_empty[32];
 	unsigned char balance_empty[32];
+	unsigned char session_empty[32];
+	unsigned char occupancy_empty[32];
+	json_object *jsonDescription;
 
-	memset(tmp, 0, ARRAY_SIZE(tmp));
 	memset(output_data, 0x00, ARRAY_SIZE(output_data));
-	memset(input_data, 0x00, ARRAY_SIZE(input_data));
-	memset(cost_empty, 0x00, ARRAY_SIZE(cost_empty));
 	memset(balance_empty, 0x00, ARRAY_SIZE(balance_empty));
+	memset(cost_empty, 0x00, ARRAY_SIZE(cost_empty));
+	memset(session_empty, 0x00, ARRAY_SIZE(session_empty));
+	memset(occupancy_empty, 0x00, ARRAY_SIZE(occupancy_empty));
 
 	switch(type)
 	{
 		case CONNECTION_FEE:
 			break;
 		case SESSION_FEE:
+
+			if(ShmOCPP16Data->StopTransaction[gun_index].TransactionId != ShmOCPP16Data->Cost.FinalCost[gun_index].txId)
+			{
+				setDisplayValue(ICON_CHARGING_SESSION_FEE, APPEAR);
+
+				strcpy((char*)session_empty, "-----");
+				string2ByteArray(session_empty, output_data);
+				lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_SESSION_FEE, output_data, ARRAY_SIZE(output_data));
+			}
+			else
+			{
+				double chargingCost = 0;
+				jsonDescription = json_tokener_parse((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
+
+				if(!is_error(jsonDescription))
+				{
+					if(json_object_object_get(jsonDescription,"chargingFee") != NULL)
+					{
+						chargingCost += json_object_get_double(json_object_object_get(jsonDescription,"chargingFee"));
+					}
+
+					if(chargingCost> 0)
+						sprintf((char*)output_data, "%.2f", chargingCost);
+					else
+						sprintf((char*)output_data, "-----");
+
+					// APPEAR COST ICON
+					setDisplayValue(ICON_CHARGING_SESSION_FEE, APPEAR);
+					lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_SESSION_FEE, output_data, ARRAY_SIZE(output_data));
+				}
+				json_object_put(jsonDescription);
+			}
 			break;
 		case OCCUPANCY_FEE:
+
+			if(ShmOCPP16Data->StopTransaction[gun_index].TransactionId != ShmOCPP16Data->Cost.FinalCost[gun_index].txId)
+			{
+				setDisplayValue(ICON_CHARGING_PARKING_FEE, APPEAR);
+
+				strcpy((char*)occupancy_empty, "-----");
+				string2ByteArray(occupancy_empty, output_data);
+				lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_PARKING_FEE, output_data, ARRAY_SIZE(output_data));
+			}
+			else
+			{
+				double parkingCost = 0;
+				jsonDescription = json_tokener_parse((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
+
+				if(!is_error(jsonDescription))
+				{
+					if(json_object_object_get(jsonDescription,"parkingFee") != NULL)
+					{
+						parkingCost += json_object_get_double(json_object_object_get(jsonDescription,"parkingFee"));
+					}
+
+					if(parkingCost > 0)
+						sprintf((char*)output_data, "%.2f", parkingCost);
+					else
+						sprintf((char*)output_data, "-----");
+
+					setDisplayValue(ICON_CHARGING_PARKING_FEE, APPEAR);
+					lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_PARKING_FEE, output_data, ARRAY_SIZE(output_data));
+				}
+				json_object_put(jsonDescription);
+			}
 			break;
 		case TOTAL_COST:
 			if(ShmOCPP16Data->StopTransaction[gun_index].TransactionId != ShmOCPP16Data->Cost.FinalCost[gun_index].txId)
 			{
-				setDisplayValue(ICON_CHARGING_COST, APPEAR);
+				setDisplayValue(ICON_CHARGING_TOTAL_COST, APPEAR);
 
 				strcpy((char*)cost_empty, "-----");
 				string2ByteArray(cost_empty, output_data);
-				lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_COST, output_data, ARRAY_SIZE(output_data));
+				lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_TOTAL_COST, output_data, ARRAY_SIZE(output_data));
 			}
 			else
 			{
-				if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Total Cost:") > 0))
-				{
-					// APPEAR COST ICON
-					setDisplayValue(ICON_CHARGING_COST, APPEAR);
+				double chargingCost = 0;
+				double parkingCost = 0;
+				jsonDescription = json_tokener_parse((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
 
-					// APPEAR COST TEXT
-					strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
-					split((char**)splitString, tmp, Symbol);
-					memcpy(input_data, splitString[3], strlen(splitString[3]));
-					length = strlen(input_data);
-					trim_string(input_data,length);
-					memcpy(output_data ,input_data, strlen(input_data));
-					lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_COST, output_data, ARRAY_SIZE(output_data));
-				}
-				else
+				if(!is_error(jsonDescription))
 				{
-					setDisplayValue(ICON_CHARGING_COST, APPEAR);
+					if(json_object_object_get(jsonDescription,"chargingFee") != NULL)
+					{
+						chargingCost += json_object_get_double(json_object_object_get(jsonDescription,"chargingFee"));
+					}
+
+					if(json_object_object_get(jsonDescription,"parkingFee") != NULL)
+					{
+						parkingCost += json_object_get_double(json_object_object_get(jsonDescription,"parkingFee"));
+					}
+
+					if((chargingCost + parkingCost) > 0)
+						sprintf((char*)output_data, "%.2f", (chargingCost + parkingCost));
+					else
+						sprintf((char*)output_data, "-----");
 
-					strcpy((char*)cost_empty, "-----");
-					string2ByteArray(cost_empty, output_data);
-					lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_COST, output_data, ARRAY_SIZE(output_data));
+					// APPEAR COST ICON
+					setDisplayValue(ICON_CHARGING_TOTAL_COST, APPEAR);
+					lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_TOTAL_COST, output_data, ARRAY_SIZE(output_data));
 				}
+				json_object_put(jsonDescription);
 			}
 			break;
 		case ACCOUNT_BALANCE:
@@ -1380,29 +1532,27 @@ void setFinalCost(uint8_t gun_index, uint8_t type)
 			}
 			else
 			{
-				if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Account Balance:") > 0))
-				{
-					// APPEAR BALANCE ICON
-					setDisplayValue(ICON_COMPLETE_WALLET, APPEAR);
+				double accountBalance = 0;
+				jsonDescription = json_tokener_parse((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
 
-					// APPEAR BALANCE TEXT
-					strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
-					split((char**)splitString, tmp, Symbol);
-					memcpy(input_data, splitString[4], strlen(splitString[4]));
-					length = strlen(input_data);
-					trim_string(input_data,length);
-					memcpy(output_data ,input_data, strlen(input_data));
-					lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_REMAINING_ACCOUNT_BALANCE, output_data, ARRAY_SIZE(output_data));
-				}
-				else
+				if(!is_error(jsonDescription))
 				{
-					setDisplayValue(ICON_COMPLETE_WALLET, APPEAR);
+					if(json_object_object_get(jsonDescription,"accountBalance") != NULL)
+					{
+						accountBalance += json_object_get_double(json_object_object_get(jsonDescription,"accountBalance"));
+					}
+
+					if(accountBalance > 0)
+						sprintf((char*)output_data, "%.2f", accountBalance);
+					else
+						sprintf((char*)output_data, "-----");
 
-					strcpy((char*)balance_empty, "-----");
-					string2ByteArray(balance_empty, output_data);
 
+					// APPEAR COST ICON
+					setDisplayValue(ICON_COMPLETE_WALLET, APPEAR);
 					lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_REMAINING_ACCOUNT_BALANCE, output_data, ARRAY_SIZE(output_data));
 				}
+				json_object_put(jsonDescription);
 			}
 			break;
 		default:
@@ -1415,65 +1565,125 @@ void setFinalCost(uint8_t gun_index, uint8_t type)
 //=======================================
 void setRunningCost(uint8_t gun_index, uint8_t type)
 {
-	uint8_t length;
 	uint8_t output_data[32];
-	char input_data[32];
-	char tmp[256];
-	char *splitString[10];
-	const char *Symbol = ";";
 	unsigned char cost_empty[32];
+	unsigned char session_empty[32];
+	unsigned char occupancy_empty[32];
+	json_object *jsonDescription;
 
-	memset(tmp, 0, ARRAY_SIZE(tmp));
 	memset(output_data, 0x00, ARRAY_SIZE(output_data));
-	memset(input_data, 0x00, ARRAY_SIZE(input_data));
 	memset(cost_empty, 0x00, ARRAY_SIZE(cost_empty));
+	memset(session_empty, 0x00, ARRAY_SIZE(session_empty));
+	memset(occupancy_empty, 0x00, ARRAY_SIZE(occupancy_empty));
 
 	switch(type)
 	{
 		case CONNECTION_FEE:
 			break;
 		case SESSION_FEE:
+			if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId != ShmOCPP16Data->Cost.RunningCost[gun_index].txId)
+			{
+				setDisplayValue(ICON_CHARGING_SESSION_FEE, APPEAR);
+
+				strcpy((char*)session_empty, "-----");
+				string2ByteArray(session_empty, output_data);
+				lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_SESSION_FEE, output_data, ARRAY_SIZE(output_data));
+			}
+			else
+			{
+				double chargingCost = 0;
+				jsonDescription = json_tokener_parse((char*)ShmOCPP16Data->Cost.RunningCost[gun_index].description);
+
+				if(!is_error(jsonDescription))
+				{
+					if(json_object_object_get(jsonDescription,"chargingFee") != NULL)
+					{
+						chargingCost += json_object_get_double(json_object_object_get(jsonDescription,"chargingFee"));
+					}
+
+					if(chargingCost> 0)
+						sprintf((char*)output_data, "%.2f", chargingCost);
+					else
+						sprintf((char*)output_data, "-----");
+
+					// APPEAR COST ICON
+					setDisplayValue(ICON_CHARGING_SESSION_FEE, APPEAR);
+					lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_SESSION_FEE, output_data, ARRAY_SIZE(output_data));
+				}
+				json_object_put(jsonDescription);
+			}
+
 			break;
 		case OCCUPANCY_FEE:
+			if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId != ShmOCPP16Data->Cost.RunningCost[gun_index].txId)
+			{
+				setDisplayValue(ICON_CHARGING_PARKING_FEE, APPEAR);
+
+				strcpy((char*)occupancy_empty, "-----");
+				string2ByteArray(occupancy_empty, output_data);
+				lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_PARKING_FEE, output_data, ARRAY_SIZE(output_data));
+			}
+			else
+			{
+				double parkingCost = 0;
+				jsonDescription = json_tokener_parse((char*)ShmOCPP16Data->Cost.RunningCost[gun_index].description);
+
+				if(!is_error(jsonDescription))
+				{
+					if(json_object_object_get(jsonDescription,"parkingFee") != NULL)
+					{
+						parkingCost += json_object_get_double(json_object_object_get(jsonDescription,"parkingFee"));
+					}
+
+					if(parkingCost > 0)
+						sprintf((char*)output_data, "%.2f", parkingCost);
+					else
+						sprintf((char*)output_data, "-----");
+
+					setDisplayValue(ICON_CHARGING_PARKING_FEE, APPEAR);
+					lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_PARKING_FEE, output_data, ARRAY_SIZE(output_data));
+				}
+				json_object_put(jsonDescription);
+			}
+
 			break;
 		case TOTAL_COST:
 			if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId != ShmOCPP16Data->Cost.RunningCost[gun_index].txId)
 			{
-				setDisplayValue(ICON_CHARGING_COST, APPEAR);
+				setDisplayValue(ICON_CHARGING_TOTAL_COST, APPEAR);
 
 				strcpy((char*)cost_empty, "-----");
 				string2ByteArray(cost_empty, output_data);
-				lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_COST, output_data, ARRAY_SIZE(output_data));
+				lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_TOTAL_COST, output_data, ARRAY_SIZE(output_data));
 			}
 			else
 			{
-				if(strlen((char*)ShmOCPP16Data->Cost.RunningCost[gun_index].description) > 0)
+				double chargingCost = 0;
+				double parkingCost = 0;
+				jsonDescription = json_tokener_parse((char*)ShmOCPP16Data->Cost.RunningCost[gun_index].description);
+
+				if(!is_error(jsonDescription))
 				{
-					if((strstr((char*)ShmOCPP16Data->Cost.RunningCost[gun_index].description, "Total Cost:") > 0))
+					if(json_object_object_get(jsonDescription,"chargingFee") != NULL)
 					{
-						// APPEAR COST ICON
-						setDisplayValue(ICON_CHARGING_COST, APPEAR);
+						chargingCost += json_object_get_double(json_object_object_get(jsonDescription,"chargingFee"));
+					}
 
-						// APPEAR COST TEXT
-						strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.RunningCost[gun_index].description);
-						split((char**)splitString, tmp, Symbol);
-						memcpy(input_data, splitString[3], strlen(splitString[3]));
-						length = strlen(input_data);
-						trim_string(input_data,length);
-						memcpy(output_data ,input_data, strlen(input_data));
-						lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_COST, output_data, ARRAY_SIZE(output_data));
+					if(json_object_object_get(jsonDescription,"parkingFee") != NULL)
+					{
+						parkingCost += json_object_get_double(json_object_object_get(jsonDescription,"parkingFee"));
 					}
+
+					if((chargingCost + parkingCost) > 0)
+						sprintf((char*)output_data, "%.2f", (chargingCost + parkingCost));
 					else
-					{
-						setDisplayValue(ICON_CHARGING_COST, APPEAR);
+						sprintf((char*)output_data, "-----");
 
-						strcpy((char*)cost_empty, "-----");
-						string2ByteArray(cost_empty, output_data);
-						lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_COST, output_data, ARRAY_SIZE(output_data));
-					}
+					// APPEAR COST ICON
+					setDisplayValue(ICON_CHARGING_TOTAL_COST, APPEAR);
+					lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_TOTAL_COST, output_data, ARRAY_SIZE(output_data));
 				}
-				else
-				{}
+				json_object_put(jsonDescription);
 			}
 
 			break;
@@ -2163,9 +2373,11 @@ void setTextToEmpty(uint8_t gun_index)
 	strcpy((char*)text_empty, "    ");
 	string2ByteArray(text_empty, data);
 
-	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_COST, data, ARRAY_SIZE(data));
-	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_REMAINING_ACCOUNT_BALANCE, data, ARRAY_SIZE(data));
+	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_TOTAL_COST, data, ARRAY_SIZE(data));
+	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_SESSION_FEE, data, ARRAY_SIZE(data));
+	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CHARGING_PARKING_FEE, data, ARRAY_SIZE(data));
 	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_USER_ACCOUNT_BALANCE, data, ARRAY_SIZE(data));
+	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_REMAINING_ACCOUNT_BALANCE, data, ARRAY_SIZE(data));
 }
 
 //=======================================

+ 3 - 2
EVSE/Projects/AW-CCS/Apps/LCM/lcmComm_dgus.c

@@ -2,9 +2,9 @@
  * lcmComm_dgus.c
  *
  * Created on : 2020-10-20
- * Update on : 2021-12-14
+ * Update on : 2022-01-17
  * Author : Folus Wen, Eason Yang
- * Version : V0.24
+ * Version : V0.27
  *
  */
 
@@ -74,6 +74,7 @@ int transceiverDgus(int32_t fd, uint8_t *tx, uint16_t tx_len, uint8_t *rx, uint1
 		}
 		else if(tx[3] == CMD_REG_READ_DATA)
 		{
+			usleep(100);
 			len = read(fd, rx, rx_len);
 			if(len > 0)
 			{

+ 18 - 14
EVSE/Projects/AW-CCS/Apps/LCM/lcmComm_dgus.h

@@ -2,9 +2,9 @@
  * lcmComm_dwin.h
  *
  * Created on : 2020-10-20
- * Update on : 2021-12-14
+ * Update on : 2022-01-17
  * Author : Folus Wen, Eason Yang
- * Version : V0.24
+ * Version : V0.27
  *
  */
 
@@ -146,27 +146,27 @@
 #define ICON_PREPARING_PLUG_ARROW			0x100B
 #define ICON_PREPARING_TIMER				0x100C
 #define ICON_PREPARING_ENERGY				0x100D
-#define ICON_PREPARING_COST					0x100E
+#define ICON_PREPARING_TOTAL_COST			0x100E
 #define ICON_PREPARING_POWER				0x100F
 #define ICON_PREPARING_ANIMATION			0x1010
-#define Reserve_3							0x1011
-#define Reserve_4							0x1012
+#define ICON_PREPARING_SESSION_FEE			0x1011 // NEW
+#define ICON_PREPARING_PARKING_FEE			0x1012 // NEW
 #define ICON_PRECHARGING_TIMER				0x1013
 #define ICON_PRECHARGING_ENERGY				0x1014
-#define ICON_PRECHARGING_COST				0x1015
+#define ICON_PRECHARGING_TOTAL_COST			0x1015
 #define ICON_PRECHARGING_POWER				0x1016
 #define ICON_PRECHARGING_ANIMATION			0x1017
 #define ICON_PRECHARGING_FUNNEL				0x1018
-#define Reserve_5							0x1019
-#define Reserve_6							0x101A
+#define ICON_PRECHARGING_SESSION_FEE		0x1019 // NEW
+#define ICON_PRECHARGING_PARKING_FEE		0x101A // NEW
 #define ICON_CHARGING_TIMER					0x101B
 #define ICON_CHARGING_ENERGY				0x101C
-#define ICON_CHARGING_COST					0x101D
+#define ICON_CHARGING_TOTAL_COST			0x101D
 #define ICON_CHARGING_POWER					0x101E
 #define ICON_CHARGING_ANIMATION				0x101F
 #define ICON_CHARGING_LIGHTNING				0x1020
-#define Reserve_7							0x1021
-#define Reserve_8							0x1022
+#define ICON_CHARGING_SESSION_FEE			0x1021	// NEW
+#define ICON_CHARGING_PARKING_FEE			0x1022	// NEW
 #define ICON_COMPLETE_TIMER					0x1023
 #define ICON_COMPLETE_ENERGY				0x1024
 #define ICON_COMPLETE_WALLET				0x1025
@@ -221,16 +221,20 @@
 #define Reserve5							0x20F8	// size 16
 #define TEXT_CHARGING_TIMER					0x2108	// size 16
 #define TEXT_CHARGING_ENERGY				0x2118	// size 16
-#define TEXT_CHARGING_COST					0x2128	// size 16
+#define TEXT_CHARGING_TOTAL_COST			0x2128	// size 16
 #define TEXT_CHARGING_POWER					0x2138	// size 16
-#define Reserve6							0x2148	// size 16
-#define Reserve7							0x2158	// size 16
+#define TEXT_CHARGING_SESSION_FEE			0x2148	// size 16	// NEW
+#define TEXT_CHARGING_PARKING_FEE			0x2158	// size 16	// NEW
 #define TEXT_REMAINING_ACCOUNT_BALANCE		0x2168	// size 16
 #define TEXT_USER_ACCOUNT_BALANCE			0x2178	// size 16
 #define TEXT_USER_CURRENCY					0x2188	// size 16
 #define Reserve8							0x2198	// size 16
 #define Reserve9							0x21A8	// siez 16
 #define TEXT_POWER_CONSUMPTION				0x21B8	// size 32
+#define TEXT_PREPARING_SESSION_FEE			0x21D8	// size 16 // NEW
+#define TEXT_PREPARING_PARKING_FEE			0x21E8	// size 16 // NEW
+#define TEXT_PRECHARGING_SESSION_FEE		0x21F8	// size 16 // NEW
+#define TEXT_PRECHARGING_PARKING_FEE		0x2208	// size 16 // NEW
 
 #define TEXT_RTC							0X2500	// size 32
 

+ 65 - 2
EVSE/Projects/AW-CCS/Apps/Module_InternalComm.c

@@ -763,7 +763,7 @@ unsigned char Query_AC_MCU_Status(unsigned char fd, unsigned char targetAddr, Ac
 		{
 			Ret_Buf->cp_state = rx[6];
 			Ret_Buf->current_limit = rx[7] | (rx[8]<<0x08);
-			Ret_Buf->cp_voltage_positive = (rx[9] | (rx[10]<<0x08))/100.0;		
+			Ret_Buf->cp_voltage_positive = (rx[9] | (rx[10]<<0x08))/100.0;
 			Ret_Buf->cp_voltage_negtive = (rx[11] | (rx[12]<<0x08))/100.0;
 			Ret_Buf->locker_state = rx[13];
 			Ret_Buf->relay_state = rx[14];
@@ -1537,7 +1537,7 @@ unsigned char Config_AC_MaxCurrent_And_CpPwmDuty(unsigned char fd, unsigned char
 	tx[4] = 0x01;
 	tx[5] = 0x00;
 	tx[6] = Set_Buf->max_current;
-		DEBUG_WARN("Config_AC_MaxCurrent_And_CpPwmDuty...%d\n", Set_Buf->max_current);
+	DEBUG_WARN("Config_AC_MaxCurrent_And_CpPwmDuty...%d\n", Set_Buf->max_current);
 
 	for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
 			chksum ^= tx[6+idx];
@@ -2208,6 +2208,39 @@ int main(void)
 					else
 						failCount[gun_index] = FAIL_SPEC_COMM;
 				}
+				
+				//===============================
+				// Case 11 : Query present output current
+				//===============================
+				if(Query_Present_OutputCurrent(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].outputCurrent) == PASS)
+				{
+#ifndef SIMULATION
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2 = (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3 = (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
+					
+					
+					ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[0] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
+					ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[1] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
+					ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[2] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];							
+#else	//SIMULATION
+				ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
+				if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+				{
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2 = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3 = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
+				}
+#endif	//SIMULATION
+					failCount[gun_index] = 0;
+				}
+				else
+				{
+					DEBUG_WARN("MCU-%d get output current fail...%d\n", gun_index, failCount[gun_index]);
+					if(failCount[gun_index]<USHRT_MAX)
+						failCount[gun_index]++;
+					else
+						failCount[gun_index] = FAIL_SPEC_COMM;
+				}
 
 				//==========================================================
 				// High priority polling log print out
@@ -2369,6 +2402,7 @@ int main(void)
 					//===============================
 					// Query primary MCU BLE config
 					//===============================
+					/*
 					if((previousCharger.gun_info[gun_index].bleConfigData.isLogin != ShmCharger->gun_info[gun_index].bleConfigData.isLogin) ||
 					   (previousCharger.gun_info[gun_index].bleConfigData.isRequestStart != ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart) ||
 					   (previousCharger.gun_info[gun_index].bleConfigData.isRequestStop != ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop))
@@ -2387,10 +2421,12 @@ int main(void)
 						previousCharger.gun_info[gun_index].bleConfigData.isRequestStart = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart;
 						previousCharger.gun_info[gun_index].bleConfigData.isRequestStop = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop;
 					}
+					*/
 
 					//===============================
 					// Query primary MCU ble login id
 					//===============================
+					/*
 					if((strcmp((char *)&previousCharger.gun_info[gun_index].bleLoginCentralId.id,(char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id) != 0))
 					{
 						if(strcmp((char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id,"") != 0)
@@ -2403,6 +2439,29 @@ int main(void)
 
 						memcpy(&previousCharger.gun_info[gun_index].bleLoginCentralId.id, ShmCharger->gun_info[gun_index].bleLoginCentralId.id, ARRAY_SIZE(ShmCharger->gun_info[gun_index].bleLoginCentralId.id));
 					}
+					*/
+					
+					//===============================
+					// Query primary Out put current config
+					//===============================
+					if((previousCharger.gun_info[gun_index].outputCurrent.L1N_L12[0] != ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]) ||
+					   (previousCharger.gun_info[gun_index].outputCurrent.L2N_L23[0] != ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0]) ||
+					   (previousCharger.gun_info[gun_index].outputCurrent.L3N_L31[0] != ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0]))
+					{
+						DEBUG_INFO("===========================================\n");
+						DEBUG_INFO("==== Normal priority polling : Case 3 =====\n");
+						DEBUG_INFO("===========================================\n");
+						DEBUG_INFO("MCU-%d get output current L1: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
+						if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+						{
+							DEBUG_INFO("MCU-%d get output current L2: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0]);
+							DEBUG_INFO("MCU-%d get output current L3: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0]);
+						}
+
+						previousCharger.gun_info[gun_index].outputCurrent.L1N_L12[0] = ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
+						previousCharger.gun_info[gun_index].outputCurrent.L2N_L23[0] = ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
+						previousCharger.gun_info[gun_index].outputCurrent.L3N_L31[0] = ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
+					}
 				}
 			}
 			else
@@ -2444,6 +2503,7 @@ int main(void)
 						}
 						break;
 					case 3:
+						/*
 						//===============================
 						// Query present output current
 						//===============================
@@ -2476,6 +2536,7 @@ int main(void)
 							else
 								failCount[gun_index] = FAIL_SPEC_COMM;
 						}
+						*/
 						break;
 					case 5:
 						//===============================
@@ -2808,6 +2869,7 @@ int main(void)
 					switch(logIndex)
 					{
 						case 1:
+							/*
 							if((previousCharger.gun_info[gun_index].outputCurrent.L1N_L12[0] != ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]) ||
 							   (previousCharger.gun_info[gun_index].outputCurrent.L2N_L23[0] != ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0]) ||
 							   (previousCharger.gun_info[gun_index].outputCurrent.L3N_L31[0] != ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0]))
@@ -2826,6 +2888,7 @@ int main(void)
 								previousCharger.gun_info[gun_index].outputCurrent.L2N_L23[0] = ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
 								previousCharger.gun_info[gun_index].outputCurrent.L3N_L31[0] = ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
 							}
+							*/
 
 							break;
 						case 2:

+ 21 - 17
EVSE/Projects/AW-CCS/Apps/main.c

@@ -2297,9 +2297,11 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 		if(ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == '7')
 			ShmCharger->isCcsEnable = ON;
 	}
-        #ifdef ENABLE_CCS
+
+	#ifdef ENABLE_CCS
 	ShmCharger->isCcsEnable = ON;
 	#endif
+
 	RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo);
 
 	return PASS;
@@ -2897,7 +2899,8 @@ float presentChargedEnergyTotal(unsigned char gun_index)
 
 	for(int idx=0;idx<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].presentChargedEnergyPeriod);idx++)
 	{
-		result += ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].presentChargedEnergyPeriod[idx];
+		//result += ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].presentChargedEnergyPeriod[idx];
+		result += (((int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].presentChargedEnergyPeriod[idx]*1000))/(float)1000);
 	}
 
 	return result;
@@ -2964,7 +2967,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, "B0.60.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "B0.61.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -4036,20 +4039,20 @@ void checkTask()
 	}
 
 	if(ShmCharger->isCcsEnable == ON)
-        {
-                if((system("pidof -s CsuComm > /dev/null") != 0))
-                {
-                        DEBUG_INFO("CsuComm not running, restart it.\n");
-                        system ("/root/CsuComm &");
-                }
- 
-                if((system("pidof -s SeccComm > /dev/null") != 0))
-                {
-                        sleep(3);
-                        DEBUG_INFO("SeccComm not running, restart it.\n");
-                        system ("/root/SeccComm &");
-                }
-        }
+	{
+		if((system("pidof -s CsuComm > /dev/null") != 0))
+		{
+				DEBUG_INFO("CsuComm not running, restart it.\n");
+				system ("/root/CsuComm &");
+		}
+
+		if((system("pidof -s SeccComm > /dev/null") != 0))
+		{
+				sleep(3);
+				DEBUG_INFO("SeccComm not running, restart it.\n");
+				system ("/root/SeccComm &");
+		}
+	}
 }
 
 void checkConnectionTimeout()
@@ -4392,6 +4395,7 @@ void checkChargingProfileLimit(uint8_t gun_index, uint8_t system_mode)
 				ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((1 <= ShmCharger->gun_info[gun_index].targetCurrent) && (ShmCharger->gun_info[gun_index].targetCurrent <= 5)? 6:((ShmCharger->gun_info[gun_index].targetCurrent == 0)? 100:ShmCharger->gun_info[gun_index].targetCurrent));
 			}
 			ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
+
 			break;
 		case SYS_MODE_CHARGING:
 		case SYS_MODE_TERMINATING: