浏览代码

[Improve][Modularization][Module_OcppBackend20]

2021.02.08 / Folus Wen

Actions:
1. define.h NotifyEVChargingNeedsReq, unsigned char NotifyEVChargingNeedsConf, ClearedChargingLimitReq, ClearedChargingLimitConf move to CSUMsg struct.
2. GetReport, Get15118EVCertificate, ClearedChargingLimit, NotifyEVChargingNeeds, CertificateSigned logic implement.
3. Authorize function logic imrpove.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 4 年之前
父节点
当前提交
c8b88d57f9
共有 4 个文件被更改,包括 165 次插入54 次删除
  1. 123 12
      EVSE/Modularization/ocpp20/MessageHandler.c
  2. 17 18
      EVSE/Projects/AW-CCS/Apps/main.c
  3. 8 9
      EVSE/Projects/AW-CCS/Apps/main.h
  4. 17 15
      EVSE/Projects/define.h

+ 123 - 12
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -78,12 +78,14 @@ static char *ChangeAvailabilityStatusEnumTypeStr[] = {
 	MACROSTR(Scheduled)
 };
 
+#if 0
 static char *ChargingLimitSourceEnumTypeStr[] = {
 	MACROSTR(EMS),
 	MACROSTR(Other),
 	MACROSTR(SO),
 	MACROSTR(CSO)
 };
+#endif
 
 static char *ChargingProfileKindEnumTypeStr[] = {
 	MACROSTR(Absolute),
@@ -144,6 +146,7 @@ static char *ComponentCriterionEnumTypeStr[] = {
 	MACROSTR(Problem)
 };
 
+#if 0
 static char *ConnectorEnumTypeStr[] = {
 	MACROSTR(cCCS1),
 	MACROSTR(cCCS2),
@@ -168,6 +171,7 @@ static char *ConnectorEnumTypeStr[] = {
 	MACROSTR(Undetermined),
 	MACROSTR(Unknown)
 };
+#endif
 
 static char *ConnectorStatusEnumTypeStr[] = {
 	MACROSTR(Available),
@@ -177,11 +181,13 @@ static char *ConnectorStatusEnumTypeStr[] = {
 	MACROSTR(Faulted)
 };
 
+#if 0
 static char *CostKindEnumTypeStr[] = {
 	MACROSTR(CarbonDioxideEmission),
 	MACROSTR(RelativePricePercentage),
 	MACROSTR(RenewableGenerationPercentage)
 };
+#endif
 
 static char *CustomerInformationStatusEnumTypeStr[] = {
 	MACROSTR(Accepted),
@@ -222,12 +228,14 @@ static char *DisplayMessageStatusEnumTypeStr[] = {
 	MACROSTR(UnknownTransaction)
 };
 
+#if 0
 static char *EnergyTransferModeEnumTypeStr[] = {
 	MACROSTR(DC),
 	MACROSTR(AC_single_phase),
 	MACROSTR(AC_two_phase),
 	MACROSTR(AC_three_phase)
 };
+#endif
 
 static char *EventNotificationEnumTypeStr[] = {
 	MACROSTR(HardWiredNotification),
@@ -4936,6 +4944,52 @@ void CheckSystemValue(void)
 		sendAuthorizeRequest(0);
 	}
 
+	if(isWebsocketSendable &&
+	   (server_sign == TRUE) &&
+	   (ShmOCPP20Data->GetReport.requestId > 0))
+	{
+		for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
+		{
+			if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
+			{
+				/*
+				 * TODO:
+				 * 	1. Report component that are active
+				 */
+			}
+			else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
+			{
+				/*
+				 * TODO:
+				 * 	1. Report component that are available
+				 */
+			}
+			else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
+			{
+				/*
+				 * TODO:
+				 * 	1. Report component that are enable
+				 */
+			}
+			else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
+			{
+				/*
+				 * TODO:
+				 * 	1. Report component that are problem
+				 */
+			}
+			else
+			{
+				/*
+				 * TODO:
+				 * 	1. Process unknown criteria condition
+				 */
+			}
+		}
+
+		ShmOCPP20Data->GetReport.requestId = 0;
+	}
+
 	if(isWebsocketSendable &&
 	   (server_sign == TRUE) &&
 	   (ShmOCPP20Data->GetBaseReport.requestId > 0))
@@ -5033,6 +5087,30 @@ void CheckSystemValue(void)
 		ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
 	}
 
+	if(isWebsocketSendable &&
+	   (server_sign == TRUE) &&
+	   ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
+	{
+		if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
+		{
+
+		}
+		else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
+		{
+
+		}
+		else
+		{
+
+		}
+
+		sendGet15118EVCertificateRequest();
+		ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
+	}
+
+
+
+
 	//===============================
 	// Each connector operation check
 	//===============================
@@ -5636,6 +5714,14 @@ void CheckSystemValue(void)
 			sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
 		}
 
+		//==========================================
+		// csu cleared charging limit request
+		//==========================================
+		if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
+		{
+			sendClearedChargingLimitRequest(gun_index);
+		}
+
 		//==========================================
 		// csu trigger CancelReservationConf
 		//==========================================
@@ -5644,6 +5730,14 @@ void CheckSystemValue(void)
 			sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
 		}
 
+		//==========================================
+		// csu notify EV charging need request
+		//==========================================
+		if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
+		{
+			sendNotifyEVChargingNeedsRequest(gun_index);
+		}
+
 		//==========================================
 		// csu trigger ChangeAvailabilityConf
 		//==========================================
@@ -5658,7 +5752,6 @@ void CheckSystemValue(void)
 		if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
 		{
 			sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
-			ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
 		}
 
 		//==========================================
@@ -5667,7 +5760,7 @@ void CheckSystemValue(void)
 		if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
 		{
 			sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
-			ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
+
 		}
 	}
 }
@@ -5758,13 +5851,13 @@ int sendAuthorizeRequest(int gun_index)
 		}
 	}
 
-	//initialize  struct Authorize
-	memset(&(ShmOCPP20Data->Authorize), 0 , sizeof(struct StructAuthorize));
-
 	//get data from shared memory
 	strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
-	strcpy((char *)ShmOCPP20Data->Authorize.idToken.type, IdTokenEnumTypeStr[IdTokenEnumType_ISO14443]);
 
+	/*
+	if(strlen((char*)ShmOCPP20Data->Authorize.idToken.type) == 0)
+		strcpy((char *)ShmOCPP20Data->Authorize.idToken.type, IdTokenEnumTypeStr[IdTokenEnumType_ISO14443]);
+*/
 	json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
 	json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
 	json_object_object_add(Authorize, "idToken", idToken);
@@ -5863,6 +5956,8 @@ int sendClearedChargingLimitRequest(int gun_index)
 		result = PASS;
 	}
 
+	ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
+
 	return result;
 }
 
@@ -9391,6 +9486,8 @@ int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
 	LWS_Send(message);
 	result = TRUE;
 
+	ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
+
 	return result;
 }
 
@@ -9685,6 +9782,8 @@ int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
 	LWS_Send(message);
 	result = TRUE;
 
+	ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
+
 	return result;
 }
 
@@ -9896,6 +9995,19 @@ int handleCertificateSignedRequest(char *uuid, char *payload)
 		if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
 		{
 			sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
+
+			if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
+			{
+
+			}
+			else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
+			{
+
+			}
+			else
+			{
+
+			}
 		}
 
 		strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
@@ -13836,13 +13948,12 @@ int handleSetDisplayMessageRequest(char *uuid, char *payload)
 	}
 	json_object_put(SetDisplayMessage);
 
-	/*
-	 * TODO:
-	 * 	1. Configure display message and response
-	 */
 	strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
 	sendSetMonitoringBaseConfirmation(uuid);
 
+	// Anouce CSU there is display request come from server
+	ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
+
 	return result;
 }
 
@@ -14989,8 +15100,8 @@ void handleClearedChargingLimitResponse(char *payload, int gun_index)
 	}
 	json_object_put(ClearedChargingLimit);
 
-	ShmOCPP20Data->MsMsg.bits.ClearedChargingLimitReq = OFF;
-	ShmOCPP20Data->MsMsg.bits.ClearedChargingLimitConf = ON;
+	ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
+	ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
 }
 
 void handleDataTransferResponse(char *payload, int gun_index)

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

@@ -431,8 +431,10 @@ uint8_t ocpp_get_remotestop(uint8_t gun_index)
 	return result;
 }
 
-void ocpp_set_auth_req(uint8_t status)
+void ocpp_set_auth_req(uint8_t status, ...)
 {
+	va_list args;
+
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->SpMsg.bits.AuthorizeReq != status)
@@ -448,7 +450,12 @@ void ocpp_set_auth_req(uint8_t status)
 		if(ShmOCPP20Data->SpMsg.bits.AuthorizeReq != status)
 		{
 			if(status == ON)
+			{
 				memset(&ShmOCPP20Data->Authorize.Response_idTokenInfo, 0x00, sizeof(struct IdTokenInfoType));
+				va_start(args, status);
+				sprintf((char*)ShmOCPP20Data->Authorize.idToken.type, "%s", va_arg(args, char*));
+				va_end(args);
+			}
 
 			ShmOCPP20Data->SpMsg.bits.AuthorizeReq = status;
 		}
@@ -1585,7 +1592,7 @@ void InitEthernet()
 	system(tmpbuf);
 	system("ifconfig lo up &");
 	system("/sbin/ifconfig eth0:1 192.168.201.201 netmask 255.255.255.248 up &");
-	system("/sbin/ethtool -s eth0 speed 10 duplex full autoneg off");
+	//system("/sbin/ethtool -s eth0 speed 10 duplex full autoneg off");
 
     //Run DHCP client if enabled
 	system("killall udhcpc");
@@ -1762,17 +1769,8 @@ void InitEthernet()
 
 int SpawnTask()
 {
-	system ("pkill Module_4g");
-	system ("pkill Module_Wifi");
-	system ("pkill Module_EventLogging");
+	system ("pkill Module_");
 	system ("pkill OcppBackend");
-	system ("pkill Module_AlarmDetect");
-	system ("pkill Module_InternalComm");
-	system ("pkill Module_Speaker");
-	system ("pkill Module_ProduceUtils");
-	system ("pkill Module_LcmControl");
-	system ("pkill Module_PowerSharing");
-	system ("pkill Module_InitUpgrade");
 
 	if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
 	{
@@ -1784,6 +1782,7 @@ int SpawnTask()
 	}
 
 	system("/root/Module_EventLogging &");
+
 	if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0)
 	{
 		ocpp_process_start();
@@ -3868,7 +3867,7 @@ int main(void)
 									if(ocpp_get_connection_status())
 									{
 										// On line
-										ocpp_set_auth_req(ON);
+										ocpp_set_auth_req(ON, "ISO14443");
 										setLedMotion(gun_index,LED_ACTION_AUTHED);
 									}
 									else
@@ -3877,7 +3876,7 @@ int main(void)
 										switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
 										{
 											case OFF_POLICY_LOCALLIST:
-												ocpp_set_auth_req(ON);
+												ocpp_set_auth_req(ON, "ISO14443");
 												break;
 											case OFF_POLICY_PH_RFID:
 												break;
@@ -4411,7 +4410,7 @@ int main(void)
 												if(ocpp_get_connection_status())
 												{
 													// On line
-													ocpp_set_auth_req(ON);
+													ocpp_set_auth_req(ON, "ISO14443");
 												}
 												else
 												{
@@ -4419,7 +4418,7 @@ int main(void)
 													switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
 													{
 														case OFF_POLICY_LOCALLIST:
-															ocpp_set_auth_req(ON);
+															ocpp_set_auth_req(ON, "ISO14443");
 															break;
 														case OFF_POLICY_PH_RFID:
 															break;
@@ -4847,7 +4846,7 @@ int main(void)
 												if(ocpp_get_connection_status())
 												{
 													// On line
-													ocpp_set_auth_req(ON);
+													ocpp_set_auth_req(ON, "ISO14443");
 												}
 												else
 												{
@@ -4855,7 +4854,7 @@ int main(void)
 													switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
 													{
 														case OFF_POLICY_LOCALLIST:
-															ocpp_set_auth_req(ON);
+															ocpp_set_auth_req(ON, "ISO14443");
 															break;
 														case OFF_POLICY_PH_RFID:
 															break;

+ 8 - 9
EVSE/Projects/AW-CCS/Apps/main.h

@@ -67,14 +67,6 @@
 #define CCS_CP_STATE_G					8	//G (>12V)
 #define CCS_CP_STATE_H					9	//H  (<12V)
 
-//===================================
-// Define start mode constant
-//===================================
-#define START_METHOD_FREE	 		0
-#define START_METHOD_RFID	 		1
-#define START_METHOD_BACKEND 		2
-#define START_METHOD_BLE	 		3
-
 //===================================
 // Define Speaker type constant
 //===================================
@@ -120,7 +112,6 @@
 #define ALARM_L3_OVER_CURRENT					0x02000000
 #define ALARM_L2_CIRCUIT_SHORT                  0x04000000 
 #define ALARM_L3_CIRCUIT_SHORT                  0x08000000
-
 #define ALARM_METER_TIMEOUT						0x10000000
 
 
@@ -156,6 +147,14 @@
 #define CCS_PWM_DUTY_5					5
 #define CCS_PWM_DUTY_100				100
 
+enum START_METHOD
+{
+	START_METHOD_FREE=0,
+	START_METHOD_RFID,
+	START_METHOD_BACKEND,
+	START_METHOD_BLE
+};
+
 enum HANDSHAKE_STATE
 {
 	HANDSHAKE_IDLE=0,

+ 17 - 15
EVSE/Projects/define.h

@@ -5492,23 +5492,22 @@ struct OCPP20Data
 			unsigned char NotifyDisplayMessagesReq :1;
 			unsigned char NotifyDisplayMessagesConf :1;
 
-			unsigned char NotifyEVChargingNeedsReq :1;
-			unsigned char NotifyEVChargingNeedsConf :1;
 			unsigned char NotifyEVChargingScheduleReq :1;
 			unsigned char NotifyEVChargingScheduleConf :1;
 			unsigned char NotifyEventReq :1;
 			unsigned char NotifyEventConf :1;
 			unsigned char NotifyMonitoringReportReq :1;
 			unsigned char NotifyMonitoringReportConf :1;
-
 			unsigned char NotifyReportReq :1;
 			unsigned char NotifyReportConf :1;
+
 			unsigned char ReportChargingProfilesReq :1;
 			unsigned char ReportChargingProfilesConf :1;
 			unsigned char SecurityEventNotificationReq :1;
 			unsigned char SecurityEventNotificationConf :1;
 			unsigned char SignCertificateReq :1;
 			unsigned char SignCertificateConf :1;
+			unsigned char :2;
 
 		} bits;
 	} SpMsg;
@@ -5559,71 +5558,70 @@ struct OCPP20Data
 			unsigned char ClearCacheConf :1;	//bit 3,
 			unsigned char ClearDisplayMessageReq :1;
 			unsigned char ClearDisplayMessageConf :1;
-			unsigned char ClearedChargingLimitReq :1;
-			unsigned char ClearedChargingLimitConf :1;
-
 			unsigned char ClearVariableMonitoringReq :1;
 			unsigned char ClearVariableMonitoringConf :1;
+
 			unsigned char CostUpdatedReq :1;
 			unsigned char CostUpdatedConf :1;
 			unsigned char CustomerInformationReq :1;
 			unsigned char CustomerInformationConf :1;
 			unsigned char DeleteCertificateReq :1;
 			unsigned char DeleteCertificateConf :1;
-
 			unsigned char GetBaseReportReq :1;
 			unsigned char GetBaseReportConf :1;
+
 			unsigned char GetChargingProfilesReq :1;
 			unsigned char GetChargingProfilesConf :1;
 			unsigned char GetCompositeScheduleReq :1;	//bit 4,
 			unsigned char GetCompositeScheduleConf :1;	//bit 5,
 			unsigned char GetDisplayMessagesReq :1;
 			unsigned char GetDisplayMessagesConf :1;
-
 			unsigned char GetInstalledCertificateIdsReq :1;
 			unsigned char GetInstalledCertificateIdsConf :1;
+
 			unsigned char GetLocalListVersionReq :1; //bit 2,
 			unsigned char GetLocalListVersionConf :1;	//bit 3,
 			unsigned char GetLogReq :1;
 			unsigned char GetLogConf :1;
 			unsigned char GetMonitoringReportReq :1;
 			unsigned char GetMonitoringReportConf :1;
-
 			unsigned char GetReportReq :1;
 			unsigned char GetReportConf :1;
+
 			unsigned char GetTransactionStatusReq :1;
 			unsigned char GetTransactionStatusConf :1;
 			unsigned char GetVariablesReq :1;
 			unsigned char GetVariablesConf :1;
 			unsigned char InstallCertificateReq :1;
 			unsigned char InstallCertificateConf :1;
-
 			unsigned char PublishFirmwareReq :1;
 			unsigned char PublishFirmwareConf :1;
+
 			unsigned char ResetReq :1; //bit 4,
 			unsigned char ResetConf :1;	//bit 5,
 			unsigned char SendLocalListReq :1;	//bit 6,
 			unsigned char SendLocalListConf :1;	//bit 7,
 			unsigned char SetChargingProfileReq :1;	//bit 6,
 			unsigned char SetChargingProfileConf :1;	//bit 7,
-
 			unsigned char SetDisplayMessageReq :1;
 			unsigned char SetDisplayMessageConf :1;
+
 			unsigned char SetMonitoringBaseReq :1;
 			unsigned char SetMonitoringBaseConf :1;
 			unsigned char SetMonitoringLevelReq :1;
 			unsigned char SetMonitoringLevelConf :1;
 			unsigned char SetNetworkProfileReq :1;
 			unsigned char SetNetworkProfileConf :1;
-
 			unsigned char SetVariableMonitoringReq :1;
 			unsigned char SetVariableMonitoringConf :1;
+
 			unsigned char SetVariablesReq :1;
 			unsigned char SetVariablesConf :1;
 			unsigned char UnpublishFirmwareReq :1;
 			unsigned char UnpublishFirmwareConf :1;
-			unsigned char UpdateFirmwareReq :1;	//bit 6,
-			unsigned char UpdateFirmwareConf :1;	//bit 7,
+			unsigned char UpdateFirmwareReq :1;
+			unsigned char UpdateFirmwareConf :1;
+			unsigned char :2;
 		} bits;
 	} MsMsg;
 
@@ -5636,7 +5634,11 @@ struct OCPP20Data
 			//CSUMsgValue[0]
 			unsigned char ChargingProfileReq:1;	//bit 0,
 			unsigned char ChargingProfileConf:1;	//bit 0,
-			unsigned char :6;	//bit 1,2,3,4,5,6,7 , reserved
+			unsigned char ClearedChargingLimitReq :1;
+			unsigned char ClearedChargingLimitConf :1;
+			unsigned char NotifyEVChargingNeedsReq :1;
+			unsigned char NotifyEVChargingNeedsConf :1;
+			unsigned char :2;	//bit 1,2,3,4,5,6,7 , reserved
 		} bits[CONNECTOR_QUANTITY];
 	}CSUMsg;