Преглед изворни кода

2020-02-11 / Kathy Yeh
1. modify error: Reservation of a Connector - Expire
2. modify error : Reservation of a Connector - Faulted

Kathy_Yeh пре 5 година
родитељ
комит
a76d0738c0

+ 16 - 15
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -44,8 +44,6 @@
 
 
 
-
-
 #define PASS				1
 #define FAIL				-1
 
@@ -1547,13 +1545,15 @@ void CheckSystemValue(void)
 		{
 			DEBUG_INFO("reserve expired !!!   \n");
 			memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
-			ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
+			//ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
 		}
+
+#if 0
 		else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
 						(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
 						(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
 		{
-			ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
+			//ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
 		}
 		else
 		{
@@ -1569,7 +1569,7 @@ void CheckSystemValue(void)
 						//if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
 						if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
 						{
-							ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
+							//ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
 
 						}
 
@@ -1584,7 +1584,7 @@ void CheckSystemValue(void)
 						//if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
 						if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
 						{
-							ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
+							//ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
 
 						}
 
@@ -1599,7 +1599,7 @@ void CheckSystemValue(void)
 						//if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
 						if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
 						{
-							ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
+							//ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
 
 						}
 
@@ -1618,7 +1618,7 @@ void CheckSystemValue(void)
 						//if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
 						if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
 						{
-							ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
+							//ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
 
 						}
 
@@ -1628,6 +1628,7 @@ void CheckSystemValue(void)
 			}// END OF ELSE
 
 		 }// END OF check Transaction active
+#endif
 	  }//END OF Check if Reserve is expired
 
 	  //==========================================
@@ -4374,10 +4375,10 @@ int handleClearCacheRequest(char *uuid, char *payload)
     {
     	DEBUG_ERROR("open AuthorizationCache file successful\n");
 
-        //* 清空?件 */
+        //* 清空? 件 */
         ftruncate(fd,0);
 
-        //* ?�新设置?�件?�移??*/
+        //* ? 新设置? 件? 移??*/
         lseek(fd,0,SEEK_SET);
 
         close(fd);
@@ -6444,7 +6445,7 @@ void* GetDiagnosticsProcess(void* data)
 	char * pch;
 
 //	[2,"137d88c7-a403-4ead-bb2d-fc6ec90531c1","GetDiagnostics",{"location":"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/","retries":0,"retryInterval":0,"startTime":"0001-01-01T00:00:00.000Z","stopTime":"0001-01-01T00:00:00.000Z"}]
-	char *str = (char*) data; // ?��?輸入資�?
+	char *str = (char*) data; // ?  ?輸入資 ?
 
 	retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
 
@@ -6677,7 +6678,7 @@ void* GetDiagnosticsProcess(void* data)
 end:
 //	json_object_put(obj);
 	DiagnosticsStatusNotificationStatus = 0; //Idle
-	pthread_exit(NULL/*(void *) fname*/); // ?��?子執行�?
+	pthread_exit(NULL/*(void *) fname*/); // ?  ?子執行 ?
 
 }
 
@@ -9498,7 +9499,7 @@ void *UpdateFirmwareProcess(void *data)
 	//int i = 0;
 	char *loc;
 	char sstr[300]={ 0 };
-	char *str = (char*) data; // ?��?輸入資�?
+	char *str = (char*) data; // ?  ?輸入資 ?
 	DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
 
 	//***************location **************/
@@ -12778,7 +12779,7 @@ void OCPP_deleteIdTag(char *idTag)
     if(selectSqlCount  == 0)
     {
        	//Insert
-    	//sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "      "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
+    	//sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "      "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
     	sprintf(sql,"INSERT INTO ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ", idTag, parentTage, expiryDate, status, version);
 
     	DEBUG_INFO("sql:%s\n", sql);
@@ -12967,7 +12968,7 @@ void LWS_Send(char * str)
 	pthread_mutex_unlock(&lock);
 	lws_callback_on_writable(wsi_client);
 	lws_service(context, 10000);//timeout_ms
-	//usleep(10000); // 等�??��?微�?
+	//usleep(10000); // 等 ??  ?微 ?
 	//DEBUG_INFO("Send message end\n");
 }
 

+ 31 - 142
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -37,6 +37,13 @@
 #include	"sqlite3.h"
 
 
+
+#if 0
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#endif
+
 #define Debug
 //#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define PASS				1
@@ -611,38 +618,14 @@ int ConnectWsServer()
 	return result;
 }
 
-#if 0
-struct _node {
-	char uuid[37];
-	char data[2000];
-	struct _node *next;//struct node *next;
-}node;
-typedef struct _node  *pnode;
-
-struct _node staticNodeArray[100]={0};
-#endif
-
 //void createq();
 int showfront(char *uuid, char *data);
 int addq(char *uuid, char *data) ;
 int delq();
 int sentqueue();
-#if 0
-int storequeue();
-int readfiletoqueue();
-#endif
 void CheckTransactionPacket(char *uuid);
 int queue_operation(int type, char *frontUUID, char *frontData);
 
-#if 0
-pnode  front, rear;
-
-void createq() {
-	//front = rear = (pnode)malloc(sizeof(node)); --- remove temporally
-	//front->next = rear->next = NULL;
-	front = rear = NULL;
-}
-#endif
 
 int showfront(char *uuid, char *data) {
 
@@ -664,7 +647,7 @@ if (S_ISDIR(stats.st_mode) == 1)
 }
 else
 {
-	DEBUG_INFO("\n OCPP directory not exist, create dir \n");
+	//DEBUG_INFO("\n OCPP directory not exist, create dir \n");
 	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
 	system(rmFileCmd);
 }
@@ -677,7 +660,7 @@ if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
 }
 else
 {
-	DEBUG_INFO("TransactionRelatedQueue not exist\n");
+	//DEBUG_INFO("TransactionRelatedQueue not exist\n");
 	FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
 
 	if(log == NULL)
@@ -727,8 +710,8 @@ if( fgets (str, 1200, fp)!=NULL ) {
 		}
 		sstr[c] = '\0';
 
-		DEBUG_INFO("\n uuid:%s", sstr);
-		DEBUG_INFO("\n data:%s", str);
+		//DEBUG_INFO("\n uuid:%s", sstr);
+		//DEBUG_INFO("\n data:%s", str);
 		strcpy(uuid,sstr);
 		strcpy(data,str);
 		result = TRUE;
@@ -747,28 +730,6 @@ else
 fclose(fp);
 return result;
 
-#if 0
-	pnode  p;
-	p = front;
-
-		if(p)
-		{
-			//printf("姓名 %s 電話 %s\n", p->name, p->phone);
-			printf("\n uuid:%s", p->uuid);
-			printf("\n data:%s", p->data);
-		    strcpy(uuid,p->uuid);
-		    strcpy(data,p->data);
-		    return 1;
-		}
-		else
-		{
-			printf("queue is null\n");
-			strcpy(uuid,"");
-			strcpy(data,"");
-			return 0;
-		}
-#endif
-
 }
 
 int addq(char *uuid, char *data) {
@@ -776,7 +737,7 @@ FILE *outfile;
 char rmFileCmd[100]={0};
 struct stat stats;
 stat("../Storage/OCPP", &stats);
-DEBUG_INFO("addq\n");
+//DEBUG_INFO("addq\n");
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
 {
@@ -784,7 +745,7 @@ if (S_ISDIR(stats.st_mode) == 1)
 }
 else
 {
-	DEBUG_INFO("\n OCPP directory not exist, create dir \n");
+	//DEBUG_INFO("\n OCPP directory not exist, create dir \n");
 	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
 	system(rmFileCmd);
 }
@@ -797,7 +758,7 @@ if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
 }
 else
 {
-	DEBUG_INFO("TransactionRelatedQueue not exist\n");
+	//DEBUG_INFO("TransactionRelatedQueue not exist\n");
 	FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
 
 	if(log == NULL)
@@ -813,49 +774,13 @@ else
 
 // open file for writing
 outfile = fopen ("../Storage/OCPP/TransactionRelatedQueue", "a");
-DEBUG_INFO("data=%s\n",data);
+//DEBUG_INFO("data=%s\n",data);
 fputs(data, outfile);
 fputs("\n", outfile);
 fclose (outfile);
 TransactionQueueNum = TransactionQueueNum + 1;
 return 0;
 
-#if 0
-	//pnode  p = (pnode )malloc(sizeof(node));   --- remove temporally
-	int nodeCurrentFreeIndex =0;
-	for (int i = 0; i < 100; i++)  // Worst case 100+1
-	   if (staticNodeArray[i].uuid[0] == 0)  // Worst case 100
-		   nodeCurrentFreeIndex = i;
-
-	pnode  p = &staticNodeArray[nodeCurrentFreeIndex];
-	memset(p, 0, sizeof(node));
-
-		if(p)
-		{
-			strcpy(p->uuid, uuid);
-			strcpy(p->data, data);
-			//printf("請輸入姓名 ");
-			//scanf("%s", p->name);
-			//printf("請輸入電話 ");
-			//scanf("%s", p->phone);
-			p->next = NULL;
-			if(rear)
-			{
-				rear->next = p;
-				rear = p;
-			}
-			else
-			{
-				front = rear = p;
-			}
-		}
-		else
-		{
-			printf("無法取得記憶體空間新增資料\n");
-		}
-#endif
-
-
 }
 
 int delq() {
@@ -875,7 +800,7 @@ if (S_ISDIR(stats.st_mode) == 1)
 }
 else
 {
-	DEBUG_INFO("\n OCPP directory not exist, create dir \n");
+	//DEBUG_INFO("\n OCPP directory not exist, create dir \n");
 	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
 	system(rmFileCmd);
 }
@@ -888,7 +813,7 @@ if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
 }
 else
 {
-	DEBUG_INFO("TransactionRelatedQueue not exist\n");
+	//DEBUG_INFO("TransactionRelatedQueue not exist\n");
 	FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
 
 	if(log == NULL)
@@ -916,7 +841,7 @@ rewind(infile);
 
 if(c == EOF)
 {
-	DEBUG_INFO("TransactionRelatedQueue is  NULL\n");
+	//DEBUG_INFO("TransactionRelatedQueue is  NULL\n");
 
 	fclose(infile);
 	fclose(outfile);
@@ -956,45 +881,20 @@ else
 
 	resultRename = rename(tempfile, filename);
 
+
 	if(resultRename == 0)
 	{
-		DEBUG_INFO("TransactionRelatedQueue file renamed successfully");
+		//DEBUG_INFO("TransactionRelatedQueue file renamed successfully");
 	}
 	else
 	{
-		DEBUG_INFO("Error: unable to rename the TransactionRelatedQueue file");
+		//DEBUG_INFO("Error: unable to rename the TransactionRelatedQueue file");
 	}
 
+
 }
 
 return 0;
-
-#if 0
-	pnode  p;
-
-	if(front)
-	{
-		p = front;
-		if(front->next)
-			front = front->next;
-		else
-			front = rear = NULL;
-		printf("delete uuid: %s data: %s\n", p->uuid, p->data);
-			//free(p);   --- remove temporally
-
-			//new
-		memset(p, 0, sizeof(node));
-		p=NULL;
-
-	}
-	else
-	{
-		printf("queue is Empty\n");
-		printf("\n delete: queue is null");
-	}
-
-	return 0;
-#endif
 }
 
 int showqueue() {
@@ -1009,7 +909,7 @@ if (S_ISDIR(stats.st_mode) == 1)
 }
 else
 {
-	DEBUG_INFO("\n OCPP directory not exist, create dir \n");
+	//DEBUG_INFO("\n OCPP directory not exist, create dir \n");
 	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
 	system(rmFileCmd);
 }
@@ -1022,7 +922,7 @@ if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
 }
 else
 {
-	DEBUG_INFO("TransactionRelatedQueue not exist\n");
+	//DEBUG_INFO("TransactionRelatedQueue not exist\n");
 	FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
 
 	if(log == NULL)
@@ -1050,18 +950,7 @@ while(fgets(line, sizeof line, fp) != NULL) {
 
 fclose(fp);
 return 0;
-#if 0
-	pnode  p;
-	p = front;
-
-	while(p)
-	{
-		printf("uuid: %s data: %s\n", p->uuid, p->data);
-		p = p->next;
-	}
 
-	return 0;
-#endif
 }
 
 int sentqueue(){
@@ -1081,7 +970,7 @@ if (S_ISDIR(stats.st_mode) == 1)
 }
 else
 {
-	DEBUG_INFO("\n OCPP directory not exist, create dir \n");
+	//DEBUG_INFO("\n OCPP directory not exist, create dir \n");
 	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
 	system(rmFileCmd);
 }
@@ -1098,21 +987,21 @@ if(fp == NULL) {
 if( fgets (str, 1200, fp)!=NULL ) {
 	/* writing content to stdout */
 	//puts(str);
-	DEBUG_INFO("\n uuid:%s", "");
-	DEBUG_INFO("\n data:%s", str);
+	//DEBUG_INFO("\n uuid:%s", "");
+	//DEBUG_INFO("\n data:%s", str);
 	LWS_Send(str);
 	result = TRUE;
 	//return 1;
 }
 else
 {
-	DEBUG_INFO("queue is null\n");
+	//DEBUG_INFO("queue is null\n");
 
 	result = FALSE;
 	//return 0;
 }
 fclose(fp);
-DEBUG_INFO("sentqueue end\n");
+//DEBUG_INFO("sentqueue end\n");
 return result;
 }
 
@@ -1186,7 +1075,7 @@ void CheckTransactionPacket(char *uuid)
 	int queueNotEmpty = 0;
 	int cmpResult = 0;
 
-	queue_operation(0,"","");//showqueue(); ---> remove temporally
+	//queue_operation(0,"","");//showqueue(); ---> remove temporally
 	queueNotEmpty = queue_operation(1,frontUUID, frontData);//showfront(frontUUID, frontData);  ---> remove temporally
 
 	if(queueNotEmpty == 1)
@@ -1196,7 +1085,7 @@ void CheckTransactionPacket(char *uuid)
 
 		if (cmpResult == 0)
 		{
-			DEBUG_INFO("TransactionPacket Compare All right!\n");
+			//DEBUG_INFO("TransactionPacket Compare All right!\n");
 			queue_operation(2,"","");//delq(); ---> remove temporally
 		}