Эх сурвалжийг харах

2022-11-16/Jerry Wang
[OCPP 1.6]
Action:
1. Add checking gunType logic for new 'DL' series.
2. Modify access path of certificates.
3. Improve GetDiagnostics logic.
4. Add logic for DW series to reject the RemoteStart.req when one of the connectors is in charging.
5. Add logic to disconnect the websocket if the count of BootNotification no response is over 10 times.

File:
1. EVSE/Modularization/ocppfiles/Module_OcppBackend.c
--> Action 5
2. EVSE/Modularization/ocppfiles/Module_OcppBackend.h
--> Action 2
3. EVSE/Modularization/ocppfiles/MessageHandler.c
--> Action 1-4

Jerry Wang 2 жил өмнө
parent
commit
a3573ecf34

+ 67 - 19
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -4943,7 +4943,8 @@ int ProcessShareMemory()
 	 	if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
 	 	   ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
 		    (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
-			(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
+			(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
+			(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
 		   ) // 'D' means DC
 		{
 			// DO series
@@ -12221,7 +12222,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 						if(access(ROOTCA_V2G,F_OK) != -1)
 						{
 							DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
-							rename(ROOTCA_V2G, "/Storage/OCPP/rootCaV2g_fallback.pem");
+							rename(ROOTCA_V2G, "/Storage/rootCaV2g_fallback.pem");
 							rename(tempCert, ROOTCA_V2G);
 						}
 						else
@@ -12240,12 +12241,12 @@ int handleDataTransferRequest(char *uuid, char *payload)
 						if(access(ROOTCA_MO,F_OK) != -1)
 						{
 							DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
-							rename(ROOTCA_MO, "/Storage/OCPP/rootCaMo_fallback.pem");
+							rename(ROOTCA_MO, "/Storage/rootCaMo_fallback.pem");
 							rename(tempCert, ROOTCA_MO);
 						}
 						else
 						{
-							DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
+							DEBUG_INFO("No existed MORootCertificate. Creating...\n");
 							rename(tempCert, ROOTCA_MO);
 						}
 
@@ -12584,6 +12585,31 @@ void* GetDiagnosticsProcess(void* data)
 	}
 	json_object_put(GetDiagnostics);
 
+	// Notify CSU to get log of dispensers.
+	if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
+	   ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
+		(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
+		(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
+		(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
+	   )
+	{
+		sprintf((char *)ShmOCPP16Data->GetDiagnostics.StartTime,"%s",startTimestr);
+		sprintf((char *)ShmOCPP16Data->GetDiagnostics.StopTime,"%s",stopTimestr);
+
+		ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = TRUE;
+
+		struct timespec timerGetDiagnostics;
+		refreshStartTimer(&timerGetDiagnostics);
+		while(ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq != FALSE)
+		{
+			if(getDiffSecNow(timerGetDiagnostics)>=180)
+			{
+				ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = FALSE;
+				DEBUG_INFO("Waiting log of dispenser timeout.");
+			}
+		}
+	}
+
 	// Pack log to compress file
 	if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
 	   (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
@@ -12613,6 +12639,9 @@ void* GetDiagnosticsProcess(void* data)
 
 		sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
 		sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
+		sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
+		sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
+		sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
 		system(cmdBuf);
 
 		// Pack charging & event log
@@ -12994,6 +13023,24 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 			{
 				ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
 			}
+
+			if((ShmSysConfigAndInfo->SysConfig.ModelName[0] != 'D') && (ShmSysConfigAndInfo->SysConfig.ModelName[1] != 'W'))
+			{
+				for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
+				{
+					if(cpinitateMsg.bits[gun_index].isOnCharging ||
+					   (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL) ||
+					   (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing") != NULL))
+					{
+						if(connectorIdInt != (gun_index+1))
+						{
+							DEBUG_WARN("DWseries--> Other connector is in charging.\n");
+							result = FAIL;
+						}
+						break;
+					}
+				}
+			}
 		}
 		else
 		{
@@ -15881,11 +15928,11 @@ int handleDeleteCertificateRequest(char *uuid, char *payload)
 		}
 
 		// Check ManufacturerRootCertificate
-		if(access(ROOTCA_MFG,F_OK) != -1)
+		if(access(ROOTCA_MF,F_OK) != -1)
 		{
 			DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
 			isMatch = TRUE;
-			parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, compareData);
+			parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
 			for(int i = 0; compareData[i]; i++)
 			{
 				compareData[i] = tolower(compareData[i]);
@@ -15895,7 +15942,7 @@ int handleDeleteCertificateRequest(char *uuid, char *payload)
 
 			if(isMatch == TRUE)
 			{
-				parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, compareData);
+				parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
 				for(int i = 0; compareData[i]; i++)
 				{
 					compareData[i] = tolower(compareData[i]);
@@ -15906,7 +15953,7 @@ int handleDeleteCertificateRequest(char *uuid, char *payload)
 
 			if(isMatch == TRUE)
 			{
-				parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, compareData);
+				parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
 				for(int i = 0; compareData[i]; i++)
 				{
 					compareData[i] = tolower(compareData[i]);
@@ -15918,7 +15965,7 @@ int handleDeleteCertificateRequest(char *uuid, char *payload)
 			if(isMatch == TRUE)
 			{
 				DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
-				sprintf(temp, "rm -f %s", ROOTCA_MFG);
+				sprintf(temp, "rm -f %s", ROOTCA_MF);
 				system(temp);
 				sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
 				goto End;
@@ -15975,7 +16022,7 @@ End:
 	json_object_put(DeleteCertificate);
 	ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
 	sendDeleteCertificateConfirmation(uuid);
-
+	system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
 	return result;
 }
 
@@ -16144,19 +16191,19 @@ int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
 		// Check ManufacturerRootCertificate
 		else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
 		{
-			if(access(ROOTCA_MFG,F_OK) != -1)
+			if(access(ROOTCA_MF,F_OK) != -1)
 			{
 				char parseData[512] = {0};
-				if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_HashAlgorithm, parseData) == PASS)
+				if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
 					sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
 
-				if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, parseData) == PASS)
+				if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
 					sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
 
-				if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, parseData) == PASS)
+				if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
 					sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
 
-				if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
+				if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
 					sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
 			}
 			else
@@ -16638,16 +16685,16 @@ End:
 		}
 		else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
 		{
-			if(access(ROOTCA_MFG,F_OK) != -1)
+			if(access(ROOTCA_MF,F_OK) != -1)
 			{
 				DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
-				rename(ROOTCA_MFG, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
-				rename(tempCert, ROOTCA_MFG);
+				rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
+				rename(tempCert, ROOTCA_MF);
 			}
 			else
 			{
 				DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
-				rename(tempCert, ROOTCA_MFG);
+				rename(tempCert, ROOTCA_MF);
 			}
 		}
 
@@ -17401,6 +17448,7 @@ void handleStartTransactionResponse(char *payload, int gun_index)
 		sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);  // GunIndex, idtag, TransactionId
 		fputs(data, outfile);
 		fclose (outfile);
+		DEBUG_INFO("Update QueueTransactionId done...\n");
 	}
 
 	DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);

+ 20 - 5
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -40,6 +40,7 @@ uint8_t	isQueueSendable = 1;
 uint8_t counterQueueSent = 0;
 uint8_t	counterConnect = 0;
 uint8_t counterPingSend = 0;
+uint8_t counterBootNotificationSend = 0;
 
 sqlite3 *db;
 char *errMsg = NULL;
@@ -296,6 +297,7 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 			SetOcppConnStatus(TRUE);
 			refreshStartTimer(&startTime.pingOn);
 			counterPingSend = 0;
+			counterBootNotificationSend = 0;
 			queueOpInfo.TransactionMessageResend = 0;
 			break;
 		case LWS_CALLBACK_CLIENT_CONNECTION_ERROR://1
@@ -1365,7 +1367,7 @@ int main(void)
 	queueOpInfo.TransactionMessageResend = 0;
 
 	DEBUG_INFO("Module_OcppBackend task initialization...\n");
-	DEBUG_INFO("Git update date: 2022/11/11 \n");
+	DEBUG_INFO("Git update date: 2022/11/16 \n");
 	//lws_set_log_level(LLL_PARSER | LLL_HEADER | LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_INFO | LLL_DEBUG | LLL_EXT | LLL_CLIENT | LLL_LATENCY  , NULL);
 
 	if(ProcessShareMemory()== FAIL)
@@ -1502,7 +1504,7 @@ int main(void)
 	for(;;)
 	{
 		// Connect server
-		if(ConnectionEstablished==0) // Check InternetConn 0: disconnected, 1: connected
+		if(ConnectionEstablished==FALSE) // Check InternetConn 0: disconnected, 1: connected
 		{
 			isWebsocketSendable = 1;
 			isQueueSendable = 1;
@@ -1522,11 +1524,23 @@ int main(void)
 			// Sign in
 			if((GetServerSign() == FALSE) &&
 			   (isConnectorInitMode(0) != TRUE) &&
-			   ( (GetBootNotificationInterval()>0) ? (getDiffSecNow(startTime.bootNotification) >= GetBootNotificationInterval()) : (getDiffSecNow(startTime.bootNotification) >= defaultWaitingTime) )
+			   ((GetBootNotificationInterval()>0) ? (getDiffSecNow(startTime.bootNotification) >= GetBootNotificationInterval()) : (getDiffSecNow(startTime.bootNotification) >= defaultWaitingTime))
 			  )
 			{
-				sendBootNotificationRequest();
-				refreshStartTimer(&startTime.bootNotification);
+				if(counterBootNotificationSend>=10)
+				{
+					lws_context_destroy(context);
+					ConnectionEstablished = 0;
+					context = NULL;
+					counterBootNotificationSend = 0;
+					DEBUG_INFO("Disconnect because of 10 times no BootNotification response.\n");
+				}
+				else
+				{
+					sendBootNotificationRequest();
+					refreshStartTimer(&startTime.bootNotification);
+					counterBootNotificationSend++;
+				}
 			}
 
 			// Check System Value
@@ -1535,6 +1549,7 @@ int main(void)
 			// On line operation
 			if(GetServerSign() == TRUE)
 			{
+				counterBootNotificationSend = 0;
 				// Send message from queue
 				if((req_SendQueue == 1) && (isWebsocketSendable || ((queueOpInfo.TransactionMessageResend > 1) && (queueOpInfo.PreTransactionMessageResend != queueOpInfo.TransactionMessageResend))))
 				{

+ 11 - 11
EVSE/Modularization/ocppfiles/Module_OcppBackend.h

@@ -49,20 +49,20 @@
 #include    "SystemLogMessage.h"
 #include    "MessageHandler.h"
 
-#define		ROOTCA_CS				"/Storage/OCPP/rootCaCs.pem"						// for verify connect wss
-#define		ROOTCA_MFG				"/Storage/OCPP/rootCaMfg.pem"						// for verify signedUpdateFirmware
-#define		ROOTCA_V2G				"/Storage/OCPP/rootCaV2g.pem"						// for 15118
-#define		ROOTCA_MO				"/Storage/OCPP/rootCaMo.pem"						// for 15118
+#define		ROOTCA_CS				"/Storage/OCPP/rootCaCs.pem"					// for verify connect wss
+#define		ROOTCA_MF				"/Storage/OCPP/rootCaMf.pem"					// for verify signedUpdateFirmware
+#define		ROOTCA_V2G				"/Storage/rootCaV2g.pem"						// for 15118
+#define		ROOTCA_MO				"/Storage/rootCaMo.pem"						    // for 15118
 
-#define		CERTIFICATE_CP			"/Storage/OCPP/certCP.pem"							// for security profile 3
-#define		CERTIFICATE_V2G			"/Storage/OCPP/certV2G.pem"							// for 15118
-#define		CERTIFICATE_PnCAuth		"/Storage/OCPP/certPnCAuth.pem"						// for PnC authorization
+#define		CERTIFICATE_CP			"/Storage/OCPP/certCP.pem"						// for security profile 3
+#define		CERTIFICATE_V2G			"/Storage/certV2G.pem"							// for 15118
+#define		CERTIFICATE_PnCAuth		"/Storage/certPnCAuth.pem"						// for PnC authorization
 
-#define		PRIVATE_KEY_CP			"/Storage/OCPP/certCP.key"							// for security profile 3
-#define		PRIVATE_KEY_V2G			"/Storage/OCPP/certV2G.key"							// for 15118
+#define		PRIVATE_KEY_CP			"/Storage/OCPP/certCP.key"						// for security profile 3
+#define		PRIVATE_KEY_V2G			"/Storage/certV2G.key"							// for 15118
 
-#define		CSR_CP					"/Storage/OCPP/certCP.csr"							// for get CERTIFICATE_CP
-#define		CSR_V2G					"/Storage/OCPP/certV2G.csr"							// for get CERTIFICATE_V2G
+#define		CSR_CP					"/Storage/OCPP/certCP.csr"						// for get CERTIFICATE_CP
+#define		CSR_V2G					"/Storage/certV2G.csr"							// for get CERTIFICATE_V2G
 
 #define is_error(ptr) 				((unsigned long)ptr > (unsigned long)-4000L)
 #define PASS						1