浏览代码

[Improve][Modularization][Module_OcppBackend]

2021.07.31 / Folus Wen

Actions:
1. When local pre-authorize fail from local db send out AuthrizeRequest to server.

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 3 年之前
父节点
当前提交
cbb661d180
共有 2 个文件被更改,包括 45 次插入22 次删除
  1. 17 14
      EVSE/Modularization/ocppfiles/MessageHandler.c
  2. 28 8
      EVSE/Projects/AW-CCS/Apps/Module_ConfigTools.c

+ 17 - 14
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -3617,7 +3617,7 @@ int sendAuthorizeRequest(int gun_index)
 	//Local Authorize
 	if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
 	{
-		DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
+		DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
 		strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
 		strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
 		strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
@@ -3646,23 +3646,25 @@ int sendAuthorizeRequest(int gun_index)
 		{
 			if(strcmp(idTagQuery.idTagstr,"") == 0)
 			{
-				DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
+				DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
 			}
-
-			if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
+			else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
 			{
-				DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
+				DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
 			}
 
-			DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
-			strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
-			strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
-			strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
-			DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
-			ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
-			ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
-			authorizeRetryTimes = 0;
-			return result;
+			if(!GetOcppConnStatus())
+			{
+				DEBUG_INFO("off-line Local Authorization Fail.\n");
+				strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
+				strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
+				strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
+				DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
+				ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
+				ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
+				authorizeRetryTimes = 0;
+				return result;
+			}
 		}
 		else
 		{
@@ -18098,6 +18100,7 @@ void InitialSystemValue(void)
 		cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
 		//clientTime.MeterValues[gun_index] = time((time_t*)NULL);
 		clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
+		memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
 	}
 
 	memset( (void *)unknownkey, 0, sizeof(unknownkey));

+ 28 - 8
EVSE/Projects/AW-CCS/Apps/Module_ConfigTools.c

@@ -56,6 +56,7 @@
 
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData			*ShmStatusCodeData;
+struct OCPP16Data 				*ShmOCPP16Data;
 
 int StoreLogMsg(const char *fmt, ...)
 {
@@ -185,34 +186,43 @@ int InitShareMemory()
 	//Initial ShmSysConfigAndInfo
 	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
 	{
-		#ifdef SystemLogMessage
 		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-		#endif
 		result = FAIL;
 	}
 	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
 	{
-		#ifdef SystemLogMessage
 		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
-		#endif
 		result = FAIL;
 	}
+	else
+	{}
 
 	//Initial ShmStatusCodeData
 	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
 	{
-		#ifdef SystemLogMessage
 		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-		#endif
 		result = FAIL;
 	}
 	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
 	{
-		#ifdef SystemLogMessage
 		DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-		#endif
 		result = FAIL;
 	}
+	else
+	{}
+
+   	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;
+	}
+	else
+	{}
 
 	return result;
 }
@@ -621,6 +631,7 @@ int main(void)
 			printf("\n ***** test menu ******************");
 			printf("\n  start: EVSE start charging request.");
 			printf("\n  stop: EVSE stop charging request.");
+			printf("\n  auth: Authorize request.");
 			printf("\n  cancel: return to main menu.");
 			printf("\n *************************************************");
 			printf("\n  Please input operation item: ");
@@ -656,6 +667,15 @@ int main(void)
 					printf("\n  Invalid input gun_index.");
 				}
 			}
+			else if(strcmp(cmd, "auth") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n  Please input idtag: ");
+				scanf("%s", &cmd[0]);
+
+				sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%s", cmd);
+				ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 1;
+			}
 			else if(strcmp(cmd, "cancel") == 0)
 			{}
 		}