Sfoglia il codice sorgente

[Improve][AW-Regular][main]

2021.02.18 / Folus Wen

Actions:
1. main.c integrate OCPP 1.6 & OCPP 2.0.1 control logic.
2. main.c stop charging session when OCPP recieve StartTransaction response status is not accepted.
3. Module_InternalComm.c relay status sync to ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].RelayK1K2Status.

Files:
1. As follow commit history

Image version: V0.66.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 4 anni fa
parent
commit
9415004f38

+ 32 - 13
EVSE/Projects/AW-CCS/Apps/main.c

@@ -1183,19 +1183,38 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
 	char* errMsg = NULL;
 	char sqlStr[1024];
 
-	sprintf(sqlStr, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
-					   "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%s');",
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
-					   ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
-					   ShmOCPP16Data->StopTransaction[gun_index].StopReason,
-					   ShmOCPP16Data->Cost.FinalCost[gun_index].description);
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		sprintf(sqlStr, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
+ 					    "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%s');",
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
+					    ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
+					    ShmOCPP16Data->StopTransaction[gun_index].StopReason,
+					    ShmOCPP16Data->Cost.FinalCost[gun_index].description);
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		sprintf(sqlStr, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
+ 					    "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%f');",
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
+					    ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
+					    ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason,
+					    ShmOCPP20Data->CostUpdated.totalCost);
+	}
 
 	if(sqlite3_open(DB_FILE, &db))
 	{

+ 107 - 0
EVSE/Projects/AW-Regular/Apps/Module_Debug.c

@@ -40,6 +40,8 @@
 
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData 			*ShmStatusCodeData;
+struct OCPP16Data				*ShmOCPP16Data;
+struct OCPP20Data				*ShmOCPP20Data;
 struct Charger					*ShmCharger;
 
 int StoreLogMsg(const char *fmt, ...)
@@ -113,6 +115,30 @@ int InitShareMemory()
 		result = FAIL;
 	}
 
+	// Initial ShmOCPP16Data
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
+	{
+		DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
+		result = FAIL;
+	}
+	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
+		result = FAIL;
+	}
+
+	// Initial ShmOCPP20Data
+	if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
+	{
+		DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
+		result = FAIL;
+	}
+	else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
+		result = FAIL;
+	}
+
 	//Initial ShmCharger
 	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
 	{
@@ -165,6 +191,7 @@ int main(void)
 		memset(cmd, 0x00, ARRAY_SIZE(cmd));
 		printf("\n ============== Debug main menu ==================");
 		printf("\n  info: List charger status info.");
+		printf("\n  test: Charger test command.");
 		printf("\n  exit: Exit Module_Debug_Test.");
 		printf("\n =================================================");
 		printf("\n  Please input debug command: ");
@@ -195,14 +222,26 @@ int main(void)
 
 					gun_index = gun_index<AC_QUANTITY?gun_index:0;
 
+					printf("\n  CSU u-boot version: %s", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
+					printf("\n  CSU kernel version: %s", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev);
+					printf("\n  CSU rootfs version: %s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+					printf("\n --------------------------------------------------");
 					printf("\n  Charger connector plug times: %d", ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
+					printf("\n --------------------------------------------------");
 					printf("\n  CP positive voltage: %.2f", ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltagePositive);
 					printf("\n  CP negative voltage: %.2f", ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative);
+					printf("\n --------------------------------------------------");
 					printf("\n  CSU to MCU legacyRequest: %d", ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
 					printf("\n  CSU to MCU relay on request: %d", ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn);
+					printf("\n --------------------------------------------------");
 					printf("\n  Charger charging mode BS/HLC: %d", ShmCharger->gun_info[gun_index].chargingMode);
+					printf("\n --------------------------------------------------");
 					printf("\n  Charger input voltage L1: %.2f", ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
+					printf("\n --------------------------------------------------");
 					printf("\n  CSU output current L1: %.2f", ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
+					printf("\n --------------------------------------------------");
+					printf("\n  CSU power total consumption: %.2f", (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0));
+					printf("\n --------------------------------------------------");
 					printf("\n  CSU temperature: %d", ShmCharger->gun_info[gun_index].temperature.point[0]);
 
 					wait();
@@ -213,7 +252,9 @@ int main(void)
 					scanf("%d", &gun_index);
 					printf("\n  MCU info.\n\n");
 
+					gun_index = gun_index<AC_QUANTITY?gun_index:0;
 
+					printf("\n  Firmware version: %s", ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 					wait();
 				}
@@ -224,6 +265,72 @@ int main(void)
 				}
 			}while(!isExit);
 		}
+		else if(strcmp(cmd, "test") == 0)
+		{
+			int gun_index;
+
+			memset(cmd, 0x00, ARRAY_SIZE(cmd));
+			printf("\n ***************** Info menu *********************");
+			printf("\n  start: start charging session");
+			printf("\n  stop: stop charging session");
+			printf("\n  operative: enable charger gun");
+			printf("\n  inoperative: disable charger gun");
+			printf("\n  exit: exit to previous menu.");
+			printf("\n *************************************************");
+			printf("\n  Please input command: ");
+			scanf("%s", &cmd[0]);
+
+			if(strcmp(cmd, "start") == 0)
+			{
+				printf("\n  Please input gun index: ");
+				scanf("%d", &gun_index);
+
+				ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].schedule.isTriggerStart = ON;
+			}
+			else if(strcmp(cmd, "stop") == 0)
+			{
+				printf("\n  Please input gun index: ");
+				scanf("%d", &gun_index);
+
+				ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].schedule.isTriggerStop = ON;
+			}
+			else if(strcmp(cmd, "operative") == 0)
+			{
+				printf("\n  Please input gun index: ");
+				scanf("%d", &gun_index);
+
+				if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+				{
+					sprintf((char*)ShmOCPP16Data->ChangeAvailability[gun_index].Type, "Operative");
+					ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = ON;
+				}
+				else
+				{
+					sprintf((char*)(char*)ShmOCPP20Data->ChangeAvailability[gun_index].operationalStatus, "Operative");
+					ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = ON;
+				}
+			}
+			else if(strcmp(cmd, "inoperative") == 0)
+			{
+				printf("\n  Please input gun index: ");
+				scanf("%d", &gun_index);
+
+				if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+				{
+					sprintf((char*)ShmOCPP16Data->ChangeAvailability[gun_index].Type, "Inoperative");
+					ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = ON;
+				}
+				else
+				{
+					sprintf((char*)(char*)ShmOCPP20Data->ChangeAvailability[gun_index].operationalStatus, "Inoperative");
+					ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = ON;
+				}
+			}
+			else if(strcmp(cmd, "exit") == 0)
+			{
+				printf("\n  Exit to previous.\n\n");
+			}
+		}
 		else if(strcmp(cmd, "exit") == 0)
 		{
 			printf("\n  exit program.\n\n");

+ 1 - 1
EVSE/Projects/AW-Regular/Apps/Module_FactoryConfig.c

@@ -323,7 +323,7 @@ int main(int argc, char *argv[])
 	SysConfig.OfflinePolicy = 2;			// 0: local list, 1: Phihong RFID tag, 2: free charging, 3: no charging
 	SysConfig.OfflineMaxChargeEnergy = 0;	// 0: Same as MaxChargeEnergy	Other: 1~65535KWH
 	SysConfig.OfflineMaxChargeDuration = 0; // 0: Same as MaxChargeDuration Other: 1~65535 minutes
-
+	//SysConfig.isReqFirstUpgrade = 1;		// 0: Skip first upgrade, 	1: Process first upgrade
 
 	// Customization configuration item
 	if(strstr((char*)&SysConfig.ModelName[12], "P0") != NULL)

+ 8 - 6
EVSE/Projects/AW-Regular/Apps/Module_InternalComm.c

@@ -15,12 +15,12 @@
 
 #include 	<unistd.h>
 #include 	<stdarg.h>
-#include  	<stdio.h>      /*標準輸入輸出定義*/
-#include  	<stdlib.h>     /*標準函數庫定義*/
-#include  	<unistd.h>     /*Unix 標準函數定義*/
-#include  	<fcntl.h>      /*檔控制定義*/
-#include  	<termios.h>    /*PPSIX 終端控制定義*/
-#include 	<errno.h>      /*錯誤號定義*/
+#include  	<stdio.h>
+#include  	<stdlib.h>
+#include  	<unistd.h>
+#include  	<fcntl.h>
+#include  	<termios.h>
+#include 	<errno.h>
 #include 	<errno.h>
 #include 	<string.h>
 #include	<time.h>
@@ -1824,6 +1824,8 @@ int main(void)
 					ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltagePositive = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive;
 					ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive;
 
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].RelayK1K2Status = ShmCharger->gun_info[gun_index].primaryMcuState.relay_state;
+
 					failCount[gun_index] = 0;
 				}
 				else

File diff suppressed because it is too large
+ 871 - 57
EVSE/Projects/AW-Regular/Apps/main.c


Some files were not shown because too many files changed in this diff