Browse Source

[Improve][Modularization][Module_OcppBackend]

2020.11.09 / Folus Wen

Actions:
1. Authorization from cache function implement.

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 years ago
parent
commit
130deb9152

+ 116 - 339
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -6,19 +6,6 @@
 
 //TxDefaultProfile
 #define TxDefaultProfile_0_JSON			"/Storage/OCPP/TxDefaultProfile_0.json"
-#define TxDefaultProfile_1_JSON			"/Storage/OCPP/TxDefaultProfile_1.json"
-#define TxDefaultProfile_2_JSON			"/Storage/OCPP/TxDefaultProfile_2.json"
-
-//TxProfile
-#define TxProfile_1_JSON				"/Storage/OCPP/TxProfile_1.json"
-#define TxProfile_2_JSON				"/Storage/OCPP/TxProfile_2.json"
-
-#define ChargingProfile_0_JSON			"/Storage/OCPP/chargingprofile_0.json"
-#define ChargingProfile_1_JSON			"/Storage/OCPP/chargingprofile_1.json"
-#define ChargingProfile_2_JSON			"/Storage/OCPP/chargingprofile_2.json"
-#define AuthorizationCache_JSON			"/Storage/OCPP/AuthorizationCache.json"
-#define LocalAuthorizationList_JSON		"/Storage/OCPP/LocalAuthorizationList.json"
-
 
 struct SysConfigAndInfo				*ShmSysConfigAndInfo;
 struct StatusCodeData 				*ShmStatusCodeData;
@@ -109,7 +96,6 @@ static struct OCPPAuthLocalElemet
 static int HeartBeatWithNOResponse = 0;
 
 extern void  ChageWebSocketPingInterval(int WebSocketPingInterval);
-extern struct Charger_Info Charger;
 extern sqlite3 *db;
 
 int TransactionMessageAttemptsGet(void);
@@ -2951,7 +2937,6 @@ void CheckSystemValue(void)
 //==========================================
 int sendAuthorizeRequest(int gun_index)
 {
-
 	mtrace();
 	int result = FAIL;
 	char message[100]={0};
@@ -2962,7 +2947,7 @@ int sendAuthorizeRequest(int gun_index)
 	memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
 
 	//Local Authorize
-	if	((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
+	if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
 	{
 		DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
 		strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
@@ -2978,20 +2963,30 @@ int sendAuthorizeRequest(int gun_index)
 	else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
 			((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
 	{
-		OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
+		// Query from cache
+		DEBUG_INFO("Authorize from cache.\n");
+		OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
+
+		// Query from list
+		if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
+		{
+			DEBUG_INFO("Authorize from list.\n");
+			OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
+		}
+
 		if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
 		{
 			if(strcmp(idTagQuery.idTagstr,"") == 0)
 			{
-				DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
+				DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
 			}
 
 			if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
 			{
-				DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
+				DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
 			}
 
-			DEBUG_INFO("offline Local Authorization Fail !!!!\n");
+			DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
 			strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
 			strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
 			strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
@@ -3003,7 +2998,7 @@ int sendAuthorizeRequest(int gun_index)
 		}
 		else
 		{
-			DEBUG_INFO("offline Local Authorization get result !!!!\n");
+			DEBUG_INFO("off-line Local Authorization get result !!!!\n");
 			strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
 			strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
 
@@ -3021,7 +3016,7 @@ int sendAuthorizeRequest(int gun_index)
 		}
 	}
 
-	//initailize  struct Authorize
+	//initialize  struct Authorize
 	memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
 
 	//get data from shared memory
@@ -3049,48 +3044,7 @@ int sendBootNotificationRequest(void)
 	char message[500]={0}, payload[700]={0};
     char guid[37]={0};
     char tempdata[65]={0};
-/*
-    int IsGunCharging = FALSE;
-
-    //check Transaction active
-    for (int index = 0; index < CHAdeMO_QUANTITY; index++)
-    {
-    	if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
-    	{
-    		IsGunCharging = TRUE;
-    	}
-    }
-
-    for (int index = 0; index < CCS_QUANTITY; index++)
-    {
-    	if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
-    	{
-    		IsGunCharging = TRUE;
-    	}
-    }
-
-    for (int index = 0; index < GB_QUANTITY; index++)
-    {
-    	if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
-    	{
-    		IsGunCharging = TRUE;
-    	}
-    }
 
-    for (int index = 0; index < AC_QUANTITY; index++)
-    {
-    	if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
-        {
-    		IsGunCharging = TRUE;
-        }
-    }
-
-    if(IsGunCharging == TRUE)
-    {
-    	server_sign = TRUE;
-    	return result;
-    }
-*/
 	// Fill BootNotification fields
 	strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
 	strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
@@ -6843,7 +6797,6 @@ int handleClearCacheRequest(char *uuid, char *payload)
 	mtrace();
 	int result = FAIL;
 	char comfirmstr[20];
-	int fd;
     char rmFileCmd[100]={0};
     struct stat stats;
     DEBUG_INFO("handleClearCacheRequest...\n");
@@ -6859,45 +6812,18 @@ int handleClearCacheRequest(char *uuid, char *payload)
     	system(rmFileCmd);
     }
 
-    memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
-    if((access(AuthorizationCache_JSON,F_OK))!=-1)
+    if(OCPP_cleanLocalCache())
     {
-    	DEBUG_INFO("AuthorizationCache file exist.\n");
+    	sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
     }
     else
     {
-    	DEBUG_INFO("AuthorizationCache file not exist\n");
-    	FILE *log = fopen(AuthorizationCache_JSON, "w+");
-
-    	if(log == NULL)
-    	{
-    		DEBUG_INFO("AuthorizationCache file is NULL\n");
-    		sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
-    		goto end;
-    	}
-    	else
-    	{
-    		fclose(log);
-    	}
+    	sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
     }
 
-    if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
-    {
-    	DEBUG_INFO("open AuthorizationCache file failed\n");
-        sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
-    }
-    else
-    {
-    	DEBUG_INFO("open AuthorizationCache file successful\n");
-        ftruncate(fd,0);
-        lseek(fd,0,SEEK_SET);
-        close(fd);
-        sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
-    }
-
-end:
     sendClearCacheConfirmation(uuid, comfirmstr);
-	return result;
+
+    return result;
 }
 
 int handleClearChargingProfileRequest(char *uuid, char *payload)
@@ -9505,8 +9431,8 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 
 			//DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
 
-			OCPP_getIdTag(idTagstr);
-			//OCPP_getIdTag("test"); For Test
+			OCPP_getIdTagFromLocalList(idTagstr);
+			//OCPP_getIdTagFromLocalList("test"); For Test
 			//DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
 			//DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
 
@@ -9515,7 +9441,7 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 				//Local list full update
 				DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
 				// update list
-				OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
+				OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
 				//DEBUG_INFO("Local list full update. 1\n");
 				//OCPP_get_TableAuthlocalAllData();
 				//DEBUG_INFO("Local list full update. 2\n");
@@ -9523,7 +9449,7 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 			else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
 			{
 				DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
-				OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
+				OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
 			}
 
 			strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
@@ -10902,19 +10828,8 @@ void handleAuthorizeResponse(char *payload, int gun_index)
 	char expiryDatestr[30]={0};
 	char parentIdTagstr[20]={0};
 	char statusstr[20]={0};
-	char expiryDatestrtemp[30]={0};
-	char parentIdTagstrtemp[20]={0};
-	char IdTagstrtemp[20]={0};
-	char statusstrtemp[20]={0};
 	int expiryDateISNULL=FALSE;
 	int parentIdTagISNULL=FALSE;
-	char sstr[160]={0};
-	char* filename = AuthorizationCache_JSON;
-	char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
-	char *loc;
-	int  resultRename=0;
-	int responseIdTagInfoAsZero= 0;
-	char rmFileCmd[50]={0};
 
 	DEBUG_INFO("handleAuthorizeResponse...\n");
 	json_object *Authorize;
@@ -10949,209 +10864,9 @@ void handleAuthorizeResponse(char *payload, int gun_index)
 	//Update idTag information to authorization cache if supproted
 	if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) &&  (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
 	{
-		if((access(filename,F_OK))!=-1)
-		{
-			printf("AuthorizationCache exist.\n");
-		}
-		else
-		{
-			printf("AuthorizationCache not exist\n");
-			FILE *log = fopen(filename, "w+");
-
-			if(log == NULL)
-			{
-				printf("log is NULL\n");
-			   goto out;
-			}
-			else
-			{
-			   fclose(log);
-			}
-		}
-
-		FILE *infile;
-		FILE *outfile;
-		// open file for writing
-		infile = fopen (filename, "r");
-		outfile = fopen (tempfile, "w");
-
-
-		int c;
-		c = fgetc(infile);
-		//DEBUG_INFO("c:%d\n",c);
-		rewind(infile);
-
-		if(c == EOF)
-		{
-			DEBUG_INFO("Orignal File is  NULL\n");
-			if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
-			{
-				strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
-			}
-			else
-			{
-				strcpy(expiryDatestrtemp, "");
-			}
-
-			if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
-			{
-				strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
-			}
-			else
-			{
-				strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
-			}
-
-			strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
-
-			fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
-			fclose(infile);
-			fclose(outfile);
-
-			sprintf(rmFileCmd,"rm -f %s",filename);
-			system(rmFileCmd);
-
-			resultRename = rename(tempfile, filename);
-
-			if(resultRename == 0)
-			{
-				printf("File renamed successfully");
-			}
-			else
-			{
-				printf("Error: unable to rename the file");
-			}
-
-		}
-		else
-		{
-			char buf[160]={0};
-
-			while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
-			{
-			   buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
-
-			   memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
-			   memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
-			   memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
-			   memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
-			   memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
-			   memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
-			   memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
-
-			   //------------------IdTag-----------------------
-			   loc = strstr(buf, "idTag");
-			   memset(sstr ,0, ARRAY_SIZE(sstr) );
-			   c = 0;
-			   while (loc[3+strlen("idTag")+c] != '\"')
-			   {
-			 		sstr[c] = loc[3+strlen("idTag")+c];
-			 		c++;
-			   }
-			   sstr[c] = '\0';
-			   strcpy(IdTagstrtemp,sstr);
-
-			   //*********************expiryDate***************/
-			   loc = strstr(buf, "expiryDate");
-			   memset(sstr ,0, ARRAY_SIZE(sstr) );
-			   c = 0;
-			   while (loc[3+strlen("expiryDate")+c] != '\"')
-			   {
-				   sstr[c] = loc[3+strlen("expiryDate")+c];
-				   c++;
-			   }
-			   sstr[c] = '\0';
-			   strcpy(expiryDatestr,sstr);
-
-			   //*********************parentIdTag***************/
-			   loc = strstr(buf, "parentIdTag");
-			   memset(sstr ,0, ARRAY_SIZE(sstr) );
-			   c = 0;
-			   while (loc[3+strlen("parentIdTag")+c] != '\"')
-			   {
-				   sstr[c] = loc[3+strlen("parentIdTag")+c];
-				   c++;
-			   }
-			   sstr[c] = '\0';
-			   strcpy(parentIdTagstr,sstr);
-
-			   //*********************status***************/
-			   loc = strstr(buf, "status");
-			   memset(sstr ,0, ARRAY_SIZE(sstr) );
-			   c = 0;
-			   while (loc[3+strlen("status")+c] != '\"')
-			   {
-				   sstr[c] = loc[3+strlen("status")+c];
-				   c++;
-			   }
-			   sstr[c] = '\0';
-			   strcpy(statusstr,sstr);
-
-			   if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
-			   {
-				   DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
-				   responseIdTagInfoAsZero = 1;
-			   }
-			   else
-			   {
-				   DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
-			   }
-
-			   if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
-			   {
-					//modify item
-
-					if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
-					{
-						strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
-					}
-					else
-					{
-						strcpy(expiryDatestrtemp, "");
-					}
-
-					if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
-					{
-						strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
-					}
-					else
-					{
-						strcpy(parentIdTagstrtemp, parentIdTagstr);
-					}
-					strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
-
-			   }
-			   else
-			   {
-				   //wrie original item
-				   strcpy(expiryDatestrtemp, expiryDatestr);
-				   strcpy(parentIdTagstrtemp, parentIdTagstr);
-				   strcpy(statusstrtemp, statusstr);
-			   }
-
-			   fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
-			}
-
-			fclose(infile);
-			fclose(outfile);
-
-			sprintf(rmFileCmd,"rm -f %s",filename);
-			system(rmFileCmd);
-
-			resultRename = rename(tempfile, filename);
-
-			if(resultRename == 0)
-			{
-				DEBUG_INFO("File renamed successfully");
-			}
-			else
-			{
-				DEBUG_INFO("Error: unable to rename the file");
-			}
-		}
+		OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
 	}
 
-out:
 	ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
 	ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
 	authorizeRetryTimes = 0;
@@ -15020,25 +14735,26 @@ static int versioncallback(void *data, int argc, char **argv, char **azColName){
    return 0;
 }
 
-static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
-   //int i;
+static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
+
    //printf("%s:\n", (const char*)data);
 
    //idTag
-   sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
-   sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
+   sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
+   sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
 
    //parentIdTag
-   sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
+   sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
 
    //expir_date
-   sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
+   sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
 
    //status
-   sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
+   sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
 
    //version
-   idTagQuery.listVersionInt = atoi(argv[5]);
+   if(columenCount > 5)
+	   idTagQuery.listVersionInt = atoi(columnValue[5]);
 
    //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
 
@@ -15066,28 +14782,69 @@ int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **c
     return 0;
 }
 
-void OCPP_getListVerion()
+int OCPP_cleanLocalCache()
+{
+	char * sqlcleanLocalList = "delete from ocpp_auth_cache";
+	char *errMsg = 0;
+	int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
+
+	if (SQLITE_OK != rc)
+	{
+		DEBUG_INFO("SQL error: %s\n",errMsg);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
+{
+	 int isSuccess = TRUE;
+	 int ret = 0;
+	 //const char* data = "Callback function called";
+	 char sql[300];
+	 char zErrMsg[200];
+
+	 memset(sql, 0, 300);
+	 memset(zErrMsg, 0, 200);
+
+	 sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
+
+	 //* Execute SQL statement */
+	 ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
+	 if( ret != SQLITE_OK )
+	 {
+		 DEBUG_INFO("SQL error: %s\n", zErrMsg);
+		 isSuccess = FALSE;
+	 }
+
+	 return isSuccess;
+}
+
+void OCPP_getIdTagFromLocalCache(char idTag[])
 {
     int rc = 0;
-   // const char* data = "Callback function called";
+
     char sql[100];
     char zErrMsg[100];
 
     memset(sql, 0, 100);
     memset(zErrMsg, 0, 100);
+    memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
+    memset(&idTagQuery, 0, sizeof(idTagQuery));
 
-    strcpy(sql, "select * from ocpp_auth_local order by idx");
+    sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
 
     /* Execute SQL statement */
-    rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
+    rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
 
     if( rc != SQLITE_OK )
     {
-    	DEBUG_INFO("SQL error: %s", zErrMsg);
+    	DEBUG_INFO("SQL error: %s\n", zErrMsg);
     }
 }
 
-void OCPP_getIdTag(char idTag[])
+void OCPP_getListVerion()
 {
     int rc = 0;
    // const char* data = "Callback function called";
@@ -15096,22 +14853,16 @@ void OCPP_getIdTag(char idTag[])
 
     memset(sql, 0, 100);
     memset(zErrMsg, 0, 100);
-    memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
-    memset(&idTagQuery, 0, sizeof(idTagQuery));
 
-    //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
-    sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
+    strcpy(sql, "select * from ocpp_auth_local order by idx");
 
     /* Execute SQL statement */
-
-    rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
+    rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
 
     if( rc != SQLITE_OK )
     {
-    	DEBUG_INFO("SQL error: %s", zErrMsg);
+    	DEBUG_INFO("SQL error: %s\n", zErrMsg);
     }
-
-   //return ver;
 }
 
 void OCPP_get_TableAuthlocalAllData(void)
@@ -15131,7 +14882,7 @@ void OCPP_get_TableAuthlocalAllData(void)
 
     if( rc != SQLITE_OK )
     {
-    	DEBUG_INFO("SQL error: %s", zErrMsg);
+    	DEBUG_INFO("SQL error: %s\n", zErrMsg);
     }
 
     //return ver;
@@ -15152,7 +14903,7 @@ int OCPP_cleanLocalList()
 	return TRUE;
 }
 
-int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
+int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
 {
 	 int isSuccess = FALSE;
 	 int ret = 0;
@@ -15186,7 +14937,33 @@ int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiry
 	 return isSuccess;
 }
 
-void OCPP_deleteIdTag(char idTag[])
+void OCPP_getIdTagFromLocalList(char idTag[])
+{
+    int rc = 0;
+   // const char* data = "Callback function called";
+    char sql[100];
+    char zErrMsg[100];
+
+    memset(sql, 0, 100);
+    memset(zErrMsg, 0, 100);
+    memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
+    memset(&idTagQuery, 0, sizeof(idTagQuery));
+
+    //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
+    sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
+
+    /* Execute SQL statement */
+    rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
+
+    if( rc != SQLITE_OK )
+    {
+    	DEBUG_INFO("SQL error: %s\n", zErrMsg);
+    }
+
+   //return ver;
+}
+
+void OCPP_deleteIdTagFromLocalList(char idTag[])
 {
 	//int ver = 0;
 	//int isSuccess = FALSE;
@@ -15202,7 +14979,7 @@ void OCPP_deleteIdTag(char idTag[])
 	rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
 	if( rc != SQLITE_OK )
 	{
-		DEBUG_INFO("SQL error: %s", zErrMsg);
+		DEBUG_INFO("SQL error: %s\n", zErrMsg);
 	}
 }
 

+ 5 - 3
EVSE/Modularization/ocppfiles/MessageHandler.h

@@ -563,12 +563,14 @@ void storeTempStopTransaction(int gun_index);
 //===============================================
 int SettingChargingRecord(int target, int transactionId);
 int addBuff(int gun_idx, int user_id, int cmd_sn);
+int OCPP_cleanLocalCache();
+int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status);
+void OCPP_getIdTagFromLocalCache(char idTag[]);
 void OCPP_getListVerion();
 int OCPP_cleanLocalList();
 int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status);
-int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status);
-void OCPP_getIdTag(char idTag[]);
-void OCPP_deleteIdTag(char idTag[]);
+void OCPP_getIdTagFromLocalList(char idTag[]);
+void OCPP_deleteIdTagFromLocalList(char idTag[]);
 
 
 #endif