Browse Source

2020-03-17 / Kathy Yeh
1. modify GetChargingProfileRequest() logic
2. modify clearChargingProfile function
3. modify file path to Absolute path
4. modify oflline transaction errror

Kathy_Yeh 5 năm trước cách đây
mục cha
commit
a4cba86af1

+ 24 - 19
EVSE/Modularization/ocppfiles/JsonParser.c

@@ -8,6 +8,7 @@
 #include        "SystemLogMessage.h"
 
 
+
 #define MESSAGE_TYPE_CALL			2
 #define MESSAGE_TYPE_CALLRESULT		3
 #define MESSAGE_TYPE_CALLERROR		4
@@ -16,13 +17,6 @@
 #define FAIL						-1
 
 
-
-//extern map_t hashMap;
-//extern data_struct_t* mapItem;  --- remove temporally
-//extern data_struct_t mapItem[0];
-//extern struct node Node;
-//extern void split(char **arr, char *str, const char *del);
-
 void CallErrorHandler(char *id, char *errorCode, char *errorDescription,char *payload);
 int CallHandler(char *uuid, char *str1,char *payload);
 void CallResultHandler(char *str1,char *payload, int gun_index);
@@ -163,8 +157,6 @@ void ReceivedMessage(void *in, size_t len)
 
 			case MESSAGE_TYPE_CALLRESULT:
 
-				//DEBUG_INFO("MESSAGE_TYPE_CALLRESULT\n");
-
 			   	c = 0;
 			   	templen= 4+3+strlen(UniqueId)-1;
 			   	while ((c+ templen) < (strlen(tempin)-1))
@@ -195,22 +187,35 @@ void ReceivedMessage(void *in, size_t len)
 
 		            i=0;
 			   		sprintf(Action, "%s", *(arr+i++));
-			   	//	printf("Action=%s\n",Action);
 
 			   		gun_index = atoi(*(arr+i++));
-			   	//	printf("gun_index=%d\n",gun_index);
 
-			   	//	#ifdef Debug
-			   	//	DEBUG_INFO("<<<<<%s response\n", Action);
-			   	//	DEBUG_INFO("Payload: %s\n", Payload);
-			   	//	#endif
 			   		CallResultHandler(Action, Payload, gun_index);
+			   		free(testdup);
 
-			   	//	#ifdef Debug
-			   	//	DEBUG_INFO("After pull hash length: %d\n", hashmap_length(hashMap));
-			   	//	#endif
+#if 0  //test ( receive -send )
+			   		char difftest[34]={0};
+			   		time_t seconds;
+			   		seconds = time(NULL);
 
-			   		free(testdup);
+			   		for(int i=3; i<37; i++)
+			   		{
+			   		  difftest[i-3]= UniqueId[i];
+			   		}
+
+			   	//	printf("\n test difftest=%s\n",difftest);
+
+			   //	printf("\n test digit difftest=%d\n",atoi(difftest));
+			   //	printf("\n testseconds=%d\n",seconds);
+
+			   		printf("\n receive -send =%d\n",((int)(seconds)-atoi(difftest)));
+			   		if(((int)(seconds)-atoi(difftest)) > 1)
+			   		{
+			   			DEBUG_INFO("(int)(seconds)-atoi(difftest)=%d\n",(int)(seconds)-atoi(difftest));
+			   		}
+
+
+#endif
 			   	}
 
 			   	break;

+ 124 - 35
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -48,22 +48,22 @@
 #define TRUE 1       		// Option 1
 
 //ChargePointMaxProfile
-#define ChargePointMaxProfile_JSON     "../Storage/OCPP/ChargePointMaxProfile.json"
+#define ChargePointMaxProfile_JSON     "/Storage/OCPP/ChargePointMaxProfile.json"
 
 //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"
+#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 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"
+#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;
@@ -1280,7 +1280,7 @@ void CheckSystemValue(void)
 		//==============================================
 		// Charger start transaction
 		//==============================================
-		if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
+		if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
 		{
 			sendStartTransactionRequest(gun_index);
 			ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
@@ -1291,7 +1291,7 @@ void CheckSystemValue(void)
 		//==============================================
 		// Charger stop transaction
 		//==============================================
-		if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
+		if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
 		{
 			sendStopTransactionRequest(gun_index);
 			ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
@@ -1387,7 +1387,7 @@ void CheckSystemValue(void)
 	//==============================================
 	// Meter report
 	//==============================================
-	if((server_sign == TRUE) &&  ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
+	if(/*(server_sign == TRUE) &&*/  ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
 	{
 		//check Transaction active
 		if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
@@ -1402,7 +1402,7 @@ void CheckSystemValue(void)
 
 				if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
 				{
-					sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
+					sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
 					if((access(filenmae,F_OK))!=-1)
 					{
 						DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
@@ -1424,7 +1424,7 @@ void CheckSystemValue(void)
 
 				if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
 				{
-					sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
+					sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
 					if((access(filenmae,F_OK))!=-1)
 					{
 						DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
@@ -1446,7 +1446,7 @@ void CheckSystemValue(void)
 
 				if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
 				{
-					sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
+					sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
 					if((access(filenmae,F_OK))!=-1)
 					{
 						DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
@@ -1469,7 +1469,7 @@ void CheckSystemValue(void)
 
 				if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
 				{
-					sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
+					sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
 					if((access(filenmae,F_OK))!=-1)
 					{
 						DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
@@ -4218,8 +4218,9 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 	int connectorIsNULL = FALSE;
 	int chargingProfilePurposeIsNULL = FALSE;
 	int stackLevelIsNULL = FALSE;
+	int GotoEnd = FALSE;
 	FILE *fptr1, *fptr2;
-	char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
+	char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json";
     int n_chargingProfile=0;
     char sLineWord[1060]={0};
 
@@ -4319,10 +4320,10 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 				{
 					strcpy(fname, ChargePointMaxProfile_JSON);
 				}
-		//		else
-		//		{
-		//			strcpy(fname, TxDefaultProfile_0_JSON);
-		//		}
+				else
+				{
+					strcpy(fname, TxDefaultProfile_0_JSON);
+				}
 
 				break;
 
@@ -4379,7 +4380,14 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 
 	if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
 	{
-		//clear the whole contents of a file in C
+		//clear file in C
+		sprintf(str,"rm -f %s",fname);
+		system(str);
+
+		// clear temp file
+		sprintf(str,"rm -f %s",temp);
+		system(str);
+#if 0
 		fclose(fopen(ChargePointMaxProfile_JSON, "w"));
 		fclose(fopen(TxDefaultProfile_0_JSON, "w"));
 		fclose(fopen(TxDefaultProfile_1_JSON, "w"));
@@ -4387,12 +4395,9 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 
 		fclose(fopen(TxProfile_1_JSON, "w"));
 		fclose(fopen(TxProfile_2_JSON, "w"));
-#if 0
-		fclose(fopen(ChargingProfile_0_JSON, "w"));
-		fclose(fopen(ChargingProfile_1_JSON, "w"));
-		fclose(fopen(ChargingProfile_2_JSON, "w"));
 #endif
 		sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
+		goto end;
 	}
 	else
 	{
@@ -4483,7 +4488,23 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 			{
 				if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
 				{
-					if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
+					if(stackLevelIsNULL == TRUE)//((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
+					{
+						fclose(fptr1);
+						fclose(fptr2);
+						sprintf(str,"rm -f %s",fname);
+						system(str);
+
+						// clear temp file
+						sprintf(str,"rm -f %s",temp);
+						system(str);
+						sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
+						clearflag = TRUE;
+						GotoEnd = TRUE;
+						break;
+
+					}
+					else if((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt))
 					{
 						sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
 						clearflag = TRUE;
@@ -4517,9 +4538,16 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 			memset(sLineWord, 0, sizeof sLineWord);
 		}
 
-        if(clearflag == FALSE)
+
+        if((clearflag == FALSE) && (GotoEnd == TRUE))
         {
         	sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
+        	sprintf(str,"rm -f %s",temp);
+        	system(str);
+        	goto end;
+        }
+        else
+        {
         	goto end;
         }
 
@@ -8273,7 +8301,7 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 	//int lno=0;//, linectr = 0;
 	//int modifyflag = FALSE;
 	char filename[MAX]={0};
-	char tempfile[] = "../Storage/OCPP/temp.json";
+	char tempfile[] = "/Storage/OCPP/temp.json";
 	//int  resultRename=0;
 	char rmFileCmd[50]={0};
 	char tempchargingProfilePurposeStr[30]={0};
@@ -9738,7 +9766,7 @@ void handleAuthorizeResponse(char *payload, int gun_index)
 	int parentIdTagISNULL=FALSE;
 	char sstr[160]={ 0 };
 	char* filename = AuthorizationCache_JSON;
-	char tempfile[] = "../Storage/OCPP/temp.json";
+	char tempfile[] = "/Storage/OCPP/temp.json";
 	int c = 0;
 	char *loc;
 	int  resultRename=0;
@@ -10811,7 +10839,7 @@ int initialConfigurationTable(void)
 		char keystr[60]={0};
 		char readonlystr[10]={0};
 		char valuestr[100]={0};
-		fp = fopen("../Storage/OCPP/OCPPConfiguration" , "r");
+		fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
 		if(fp == NULL) {
 			DEBUG_INFO("Error opening file");
 			return FALSE;
@@ -11182,7 +11210,7 @@ int initialConfigurationTable(void)
 void StoreConfigurationTable(void)
 {
 	FILE *outfile;
-	outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
+	outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
 	if(outfile == NULL)
 	{
 		DEBUG_INFO("Error opening file");
@@ -14309,6 +14337,7 @@ void GetChargingProfileRequest(int gunindex)
 	memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
 	memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
 	memset(&TxProfile,0,sizeof(struct StructProfile));
+	memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
 
 	DEBUG_INFO("GetChargingProfileRequest\n");
 
@@ -14530,6 +14559,26 @@ void GetChargingProfileRequest(int gunindex)
 	  				  strcpy(tempvalidFromStr,"");
 	  			}
 
+
+	  			//***********validTo **************/
+	  			c = 0;
+	  			loc = strstr(sLineWord, "validTo");
+	  			if(loc != NULL)
+	  			{
+	  			  memset(sstr ,0, sizeof(sstr) );
+	  			  while (loc[3+strlen("validTo")+c] != '\"')
+	  			  {
+	  			  	 sstr[c] = loc[3+strlen("validTo")+c];
+	  			  	 c++;
+	  			  }
+	  			  sstr[c] = '\0';
+	  			  strcpy(tempvalidToStr,sstr);
+	  			}
+	  			else
+	  			{
+	  			  strcpy(tempvalidToStr,"");
+	  			}
+
 	  			//***********duration**************/
 	  			c = 0;
 	  			loc = strstr(sLineWord, "duration");
@@ -14706,6 +14755,7 @@ void GetChargingProfileRequest(int gunindex)
 	  	switch(gunindex + 1)
 	  	{
 	  		case 0:
+	  			  strcpy(fname, TxDefaultProfile_0_JSON );
 	  			  break;
 
 	  		case 1:
@@ -14903,7 +14953,26 @@ void GetChargingProfileRequest(int gunindex)
 	  	  			strcpy(tempvalidFromStr,"");
 	  	  		}
 
-	  	  		//***********validFrom**************/
+	  	  		//***********validTo **************/
+	  	  	  	c = 0;
+	  	  	  	loc = strstr(sLineWord, "validTo");
+	  	  	  	if(loc != NULL)
+	  	  	  	{
+	  	  	  	  	memset(sstr ,0, sizeof(sstr) );
+	  	  	  	  	while (loc[3+strlen("validTo")+c] != '\"')
+	  	  	  	  	{
+	  	  	  	  		sstr[c] = loc[3+strlen("validTo")+c];
+	  	  	  	  		c++;
+	  	  	  	  	}
+	  	  	  	  	sstr[c] = '\0';
+	  	  	  	  	strcpy(tempvalidToStr,sstr);
+	  	  	  	}
+	  	  	  	else
+	  	  	  	{
+	  	  	  	  	strcpy(tempvalidToStr,"");
+	  	  	  	}
+
+	  	  		//***********duration**************/
 	  	  		c = 0;
 	  	  		loc = strstr(sLineWord, "duration");
 	  	  		if(loc != NULL)
@@ -15340,6 +15409,24 @@ void GetChargingProfileRequest(int gunindex)
 	  				  	  strcpy(tempvalidFromStr,"");
 	  				  }
 
+	  				  //***********validTo**************/
+	  				  c = 0;
+	  				  loc = strstr(sLineWord, "validTo");
+	  				  if(loc != NULL)
+	  				  {
+	  					  memset(sstr ,0, sizeof(sstr) );
+	  					  while (loc[3+strlen("validTo")+c] != '\"')
+	  					  {
+	  						  sstr[c] = loc[3+strlen("validTo")+c];
+	  						  c++;
+	  					  }
+	  					  sstr[c] = '\0';
+	  					  strcpy(tempvalidToStr,sstr);
+	  				  }
+	  				  else
+	  				  {
+	  					  strcpy(tempvalidToStr,"");
+	  				  }
 
 	  				  //***********duration**************/
 	  				  c = 0;
@@ -15645,6 +15732,7 @@ void GetChargingProfileRequest(int gunindex)
 	  				ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
 	  				ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
 	  				ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
+	  				strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
 	  				strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
 	  				strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
 	  				strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
@@ -15675,6 +15763,7 @@ void GetChargingProfileRequest(int gunindex)
 	  				ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
 	  				ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
 	  				ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
+	  				strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
 	  				strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
 	  				strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
 	  				strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);

+ 64 - 50
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -33,12 +33,10 @@
 #include    	"MessageHandler.h"
 #include	"sqlite3.h"
 
-
 #ifndef SPEC_LATEST_SUPPORTED
 #define SPEC_LATEST_SUPPORTED 13
 #endif
 
-
 #define Debug
 //#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define PASS				1
@@ -298,11 +296,27 @@ int strposs(char *source, char *substr, int idx)
    return result;
 }
 
+//static int testnum = 0;
 char *random_uuid( char buf[37] )
 {
     const char *c = "89ab";
     char *p = buf;
     int n;
+
+#if 0 // test
+    time_t seconds;
+
+    seconds = time(NULL);
+    testnum = testnum % 999;
+    testnum = testnum + 1;
+
+    //printf("\n testnum:%d\n", testnum);
+    //printf("\n seconds:%d\n", seconds);
+
+    sprintf(p, "%03d%034d", testnum, seconds);
+    //printf("\n p:%s\n", p);
+#endif
+#if 1
     for( n = 0; n < 16; ++n )
     {
         int b = rand()%255;
@@ -330,7 +344,9 @@ char *random_uuid( char buf[37] )
                 break;
         }
     }
+
     *p = 0;
+#endif
     return buf;
 }
 
@@ -763,7 +779,7 @@ char *loc;
 char rmFileCmd[100]={0};
 struct stat stats;
 
-stat("../Storage/OCPP", &stats);
+stat("/Storage/OCPP", &stats);
 
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
@@ -772,21 +788,21 @@ if (S_ISDIR(stats.st_mode) == 1)
 }
 else
 {
-	//DEBUG_INFO("\n OCPP directory not exist, create dir \n");
-	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
+	DEBUG_INFO("\n OCPP directory not exist, create dir \n");
+	sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 	system(rmFileCmd);
 }
 
 memset(rmFileCmd, 0, sizeof rmFileCmd);
 
-if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
+if((access("/Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
 {
 	//DEBUG_INFO("TransactionRelatedQueue exist.\n");
 }
 else
 {
 	//DEBUG_INFO("TransactionRelatedQueue not exist\n");
-	FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
+	FILE *log = fopen("/Storage/OCPP/TransactionRelatedQueue", "w+");
 
 	if(log == NULL)
 	{
@@ -801,20 +817,21 @@ else
 
 
 /* opening file for reading */
-fp = fopen("../Storage/OCPP/TransactionRelatedQueue" , "r");
+fp = fopen("/Storage/OCPP/TransactionRelatedQueue" , "r");
 if(fp == NULL) {
 	DEBUG_INFO("Error opening TransactionRelatedQueue file");
 	return FALSE;
 }
 
+#if 0
 if(fgetc(fp)==EOF)
 {
 	//DEBUG_INFO("It is end of file");
 	fclose(fp);
 	memset(rmFileCmd, 0, sizeof rmFileCmd);
-	if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
+	if((access("/Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
 	{
-		sprintf(rmFileCmd,"rm -f %s","../Storage/OCPP/TransactionRelatedQueue");
+		sprintf(rmFileCmd,"rm -f %s","/Storage/OCPP/TransactionRelatedQueue");
 		system(rmFileCmd);
 	}
 
@@ -822,17 +839,17 @@ if(fgetc(fp)==EOF)
 
 	return result;
 }
+#endif
 
 if( fgets (str, 1200, fp)!=NULL ) {
 	/* writing content to stdout */
 	//DEBUG_INFO("str=%s",str);
-
 	if ((str[0] == '\n')||(strcmp(str,"")==0))
 	{
 		DEBUG_INFO("It is a blank line");
 		fclose(fp);
 		memset(rmFileCmd, 0, sizeof rmFileCmd);
-		sprintf(rmFileCmd,"rm -f %s","../Storage/OCPP/TransactionRelatedQueue");
+		sprintf(rmFileCmd,"rm -f %s","/Storage/OCPP/TransactionRelatedQueue");
 		system(rmFileCmd);
 		result = FALSE;
 
@@ -858,8 +875,6 @@ if( fgets (str, 1200, fp)!=NULL ) {
 		strcpy(data,str);
 		result = TRUE;
 	}
-
-	//return 1;
 }
 else
 {
@@ -867,7 +882,6 @@ else
 	strcpy(uuid,"");
 	strcpy(data,"");
 	result = FALSE;
-	//return 0;
 }
 fclose(fp);
 return result;
@@ -878,30 +892,30 @@ int addq(char *uuid, char *data) {
 FILE *outfile;
 char rmFileCmd[100]={0};
 struct stat stats;
-stat("../Storage/OCPP", &stats);
-//DEBUG_INFO("addq\n");
+stat("/Storage/OCPP", &stats);
+DEBUG_INFO("addq\n");
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
 {
-	//DEBUG_INFO("\n OCPP directory exist \n");
+	DEBUG_INFO("\n OCPP directory exist \n");
 }
 else
 {
 	//DEBUG_INFO("\n OCPP directory not exist, create dir \n");
-	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
+	sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 	system(rmFileCmd);
 }
 
 memset(rmFileCmd, 0, sizeof rmFileCmd);
 
-if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
+if((access("/Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
 {
 	//DEBUG_INFO("TransactionRelatedQueue exist.\n");
 }
 else
 {
 	//DEBUG_INFO("TransactionRelatedQueue not exist\n");
-	FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
+	FILE *log = fopen("/Storage/OCPP/TransactionRelatedQueue", "w+");
 
 	if(log == NULL)
 	{
@@ -915,7 +929,7 @@ else
 }
 
 // open file for writing
-outfile = fopen ("../Storage/OCPP/TransactionRelatedQueue", "a");
+outfile = fopen ("/Storage/OCPP/TransactionRelatedQueue", "a");
 //DEBUG_INFO("data=%s\n",data);
 fputs(data, outfile);
 fputs("\n", outfile);
@@ -926,38 +940,38 @@ return 0;
 }
 
 int delq() {
-char tempfile[] = "../Storage/OCPP/temp.json";
+char tempfile[] = "/Storage/OCPP/temp.json";
 FILE *infile;
 FILE *outfile;
 int  resultRename=0;
 char filename[60]={0};
 char rmFileCmd[100]={0};
 struct stat stats;
-stat("../Storage/OCPP", &stats);
+stat("/Storage/OCPP", &stats);
 
 DEBUG_INFO("delq()\n");
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
 {
-	//DEBUG_INFO("\n OCPP directory exist \n");
+	DEBUG_INFO("\n OCPP directory exist \n");
 }
 else
 {
-	//DEBUG_INFO("\n OCPP directory not exist, create dir \n");
-	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
+	DEBUG_INFO("\n OCPP directory not exist, create dir \n");
+	sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 	system(rmFileCmd);
 }
 
 memset(rmFileCmd, 0, sizeof rmFileCmd);
 
-if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
+if((access("/Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
 {
 	//DEBUG_INFO("TransactionRelatedQueue exist.\n");
 }
 else
 {
 	//DEBUG_INFO("TransactionRelatedQueue not exist\n");
-	FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
+	FILE *log = fopen("/Storage/OCPP/TransactionRelatedQueue", "w+");
 
 	if(log == NULL)
 	{
@@ -971,8 +985,8 @@ else
 }
 
 // open file for writing
-strcpy(filename, "../Storage/OCPP/TransactionRelatedQueue");
-infile = fopen ("../Storage/OCPP/TransactionRelatedQueue", "r");
+strcpy(filename, "/Storage/OCPP/TransactionRelatedQueue");
+infile = fopen ("/Storage/OCPP/TransactionRelatedQueue", "r");
 outfile = fopen (tempfile, "w");
 
 /*检测到文件结束标识返回1,否则返回0。*/
@@ -1043,7 +1057,7 @@ return 0;
 int showqueue() {
 char rmFileCmd[100]={0};
 struct stat stats;
-stat("../Storage/OCPP", &stats);
+stat("/Storage/OCPP", &stats);
 
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
@@ -1053,20 +1067,20 @@ if (S_ISDIR(stats.st_mode) == 1)
 else
 {
 	//DEBUG_INFO("\n OCPP directory not exist, create dir \n");
-	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
+	sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 	system(rmFileCmd);
 }
 
 memset(rmFileCmd, 0, sizeof rmFileCmd);
 
-if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
+if((access("/Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
 {
 	//DEBUG_INFO("TransactionRelatedQueue exist.\n");
 }
 else
 {
 	//DEBUG_INFO("TransactionRelatedQueue not exist\n");
-	FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
+	FILE *log = fopen("/Storage/OCPP/TransactionRelatedQueue", "w+");
 
 	if(log == NULL)
 	{
@@ -1079,7 +1093,7 @@ else
 	}
 }
 
-FILE *fp = fopen("../Storage/OCPP/TransactionRelatedQueue", "r");
+FILE *fp = fopen("/Storage/OCPP/TransactionRelatedQueue", "r");
 char line[1200]={0};
 // check if file exist (and you can open it) or not
 if (fp == NULL) {
@@ -1115,7 +1129,7 @@ int c = 0;
 char *loc;
 
 DEBUG_INFO("sentqueue\n");
-stat("../Storage/OCPP", &stats);
+stat("/Storage/OCPP", &stats);
 
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
@@ -1125,14 +1139,14 @@ if (S_ISDIR(stats.st_mode) == 1)
 else
 {
 	//DEBUG_INFO("\n OCPP directory not exist, create dir \n");
-	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
+	sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 	system(rmFileCmd);
 }
 
 memset(rmFileCmd, 0, sizeof rmFileCmd);
 
 /* opening file for reading */
-fp = fopen("../Storage/OCPP/TransactionRelatedQueue" , "r");
+fp = fopen("/Storage/OCPP/TransactionRelatedQueue" , "r");
 if(fp == NULL) {
 	DEBUG_INFO("Error opening file");
 	return FALSE;
@@ -1181,10 +1195,10 @@ if( fgets (str, 1200, fp)!=NULL ) {
 		{
 			sprintf(tempdata, "StartTransaction,%d", (tempconnectorId-1));
 		}
-		else if(tempconnectorId == 0)
-		{
-			sprintf(tempdata, "StartTransaction,%d", 0);
-		}
+		//else if(tempconnectorId == 0)
+		//{
+		//	sprintf(tempdata, "StartTransaction,%d", 0);
+		//}
 
 
 		memset(sstr ,0, sizeof(sstr) );
@@ -1440,7 +1454,7 @@ char rmFileCmd[100]={0};
 struct stat stats;
 
 //
-stat("../Storage/OCPP", &stats);
+stat("/Storage/OCPP", &stats);
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
 {
@@ -1449,16 +1463,16 @@ if (S_ISDIR(stats.st_mode) == 1)
 else
 {
 	DEBUG_INFO("\n directory not exist, create dir \n");
-	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
+	sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 	system(rmFileCmd);
 }
 
 memset(rmFileCmd, 0, sizeof rmFileCmd);
 
-if((access("../Storage/OCPP/MessageSent",F_OK))!=-1)
+if((access("/Storage/OCPP/MessageSent",F_OK))!=-1)
 {
 	DEBUG_INFO("MessageSent file exist.\n");
-	sprintf(rmFileCmd,"rm -f %s","../Storage/OCPP/MessageSent");
+	sprintf(rmFileCmd,"rm -f %s","/Storage/OCPP/MessageSent");
 	system(rmFileCmd);
 }
 memset(rmFileCmd, 0, sizeof rmFileCmd);
@@ -1495,7 +1509,7 @@ int main(void)
 	}
 
 	//Create OCPP dir
-	stat("../Storage/OCPP", &stats);
+	stat("/Storage/OCPP", &stats);
 
 	// Check for directory existence
 	if (S_ISDIR(stats.st_mode) == 1)
@@ -1505,7 +1519,7 @@ int main(void)
 	else
 	{
 		DEBUG_INFO("\n OCPP directory not exist, create dir \n");
-		sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
+		sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 		system(rmFileCmd);
 	}
 
@@ -1516,7 +1530,7 @@ int main(void)
 
 	sqlite3_config(SQLITE_CONFIG_URI,1);
 
-	if(sqlite3_open("file:/../Storage/OCPP/charger.db", &db))
+	if(sqlite3_open("file:/Storage/OCPP/charger.db", &db))
 	{
 		#ifdef Debug
 		DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));

+ 16 - 17
EVSE/Modularization/ocppfiles/hashmap.c

@@ -14,9 +14,8 @@
 #include <unistd.h>     /*Unix 標準函數定義*/
 #include "SystemLogMessage.h"
 
-
 typedef enum boolean { FALSE, TRUE } BOOL;
-static pthread_mutex_t m;
+static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
 
 #if 0
 #define INITIAL_SIZE (2000)//(256)
@@ -615,7 +614,7 @@ char rmFileCmd[100]={0};
 struct stat stats;
 char tempstring[100]={0};
 
-stat("../Storage/OCPP", &stats);
+stat("/Storage/OCPP", &stats);
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
 {
@@ -624,20 +623,20 @@ if (S_ISDIR(stats.st_mode) == 1)
 else
 {
 	printf("\n directory not exist, create dir \n");
-	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
+	sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 	system(rmFileCmd);
 }
 
 memset(&rmFileCmd, 0, sizeof rmFileCmd);
 
-if((access("../Storage/OCPP/MessageSent",F_OK))!=-1)
+if((access("/Storage/OCPP/MessageSent",F_OK))!=-1)
 {
 	//printf("MessageSent exist.\n");
 }
 else
 {
 	printf("MessageSent not exist\n");
-	FILE *log = fopen("../Storage/OCPP/MessageSent", "w+");
+	FILE *log = fopen("/Storage/OCPP/MessageSent", "w+");
 
 	if(log == NULL)
 	{
@@ -651,7 +650,7 @@ else
 }
 
 // open file for writing
-outfile = fopen ("../Storage/OCPP/MessageSent", "a");
+outfile = fopen ("/Storage/OCPP/MessageSent", "a");
 sprintf(tempstring,"%s,%s\n", uuid,data);
 fputs(tempstring, outfile);
 fclose (outfile);
@@ -670,7 +669,7 @@ int MessageSent_get(char *uuid, char *data)
 	char *loc;
 	char rmFileCmd[100]={0};
 	struct stat stats;
-	stat("../Storage/OCPP", &stats);
+	stat("/Storage/OCPP", &stats);
 
 	// Check for directory existence
 	if (S_ISDIR(stats.st_mode) == 1)
@@ -680,20 +679,20 @@ int MessageSent_get(char *uuid, char *data)
 	else
 	{
 		printf("\n directory not exist, create dir \n");
-		sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
+		sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 		system(rmFileCmd);
 	}
 
 	memset(&rmFileCmd, 0, sizeof rmFileCmd);
 
-	if((access("../Storage/OCPP/MessageSent",F_OK))!=-1)
+	if((access("/Storage/OCPP/MessageSent",F_OK))!=-1)
 	{
 		//printf("MessageSent exist.\n");
 	}
 	else
 	{
 		printf("MessageSent not exist\n");
-		FILE *log = fopen("../Storage/OCPP/MessageSent", "w+");
+		FILE *log = fopen("/Storage/OCPP/MessageSent", "w+");
 
 		if(log == NULL)
 		{
@@ -708,7 +707,7 @@ int MessageSent_get(char *uuid, char *data)
 
 
 	/* opening file for reading */
-	fp = fopen("../Storage/OCPP/MessageSent" , "r");
+	fp = fopen("/Storage/OCPP/MessageSent" , "r");
 	if(fp == NULL) {
 		printf("Error opening file");
 		return FALSE;
@@ -782,7 +781,7 @@ int MessageSent_get(char *uuid, char *data)
 
 int MessageSent_remove(char *uuid, char *data)
 {
-char tempfile[] = "../Storage/OCPP/temp1.json";
+char tempfile[] = "/Storage/OCPP/temp1.json";
 FILE *infile;
 FILE *outfile;
 int  resultRename=0;
@@ -806,14 +805,14 @@ else
 
 memset(&rmFileCmd, 0, sizeof rmFileCmd);
 
-if((access("../Storage/OCPP/MessageSent",F_OK))!=-1)
+if((access("/Storage/OCPP/MessageSent",F_OK))!=-1)
 {
 	//printf("MessageSent exist.\n");
 }
 else
 {
 	printf("MessageSent not exist\n");
-	FILE *log = fopen("../Storage/OCPP/MessageSent", "w+");
+	FILE *log = fopen("/Storage/OCPP/MessageSent", "w+");
 
 	if(log == NULL)
 	{
@@ -830,8 +829,8 @@ else
 sprintf(tempstring,"%s,%s", uuid,data);
 
 // open file for writing
-strcpy(filename, "../Storage/OCPP/MessageSent");
-infile = fopen ("../Storage/OCPP/MessageSent", "r");
+strcpy(filename, "/Storage/OCPP/MessageSent");
+infile = fopen ("/Storage/OCPP/MessageSent", "r");
 outfile = fopen (tempfile, "w");
 
 /*检测到文件结束标识返回1,否则返回0。*/