Browse Source

2020-04-13 / Kathy Yeh
1. modify queue_operation() logic

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

+ 7 - 1
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -38,7 +38,6 @@
 #include	"TransactionQueue.h"
 
 
-
 #define PASS				1
 #define FAIL				-1
 
@@ -11265,6 +11264,7 @@ void handleError(char *id, char *errorCode, char *errorDescription,char *payload
 //===============================================
 int initialConfigurationTable(void)
 {
+	//clock_t start_t, end_t, total_t;
 	FILE *fp;
 	FILE *outfile;
 	char str[200]={0};
@@ -11272,6 +11272,8 @@ int initialConfigurationTable(void)
 	int c = 0;
 	char *loc;
 	printf("initialConfigurationTable  \n");
+	//start_t = clock();
+	//printf("Starting of the program, start_t = %ld\n", start_t);
 	memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
 
 
@@ -11996,6 +11998,10 @@ int initialConfigurationTable(void)
 
 	}
 
+	//end_t = clock();
+	//printf("End of the big loop, end_t = %ld\n", end_t);
+	//total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
+	//printf("Total time taken by CPU: %f\n", total_t  );
 
 	return 0;
 }

+ 43 - 36
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -33,11 +33,12 @@
 #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
@@ -52,7 +53,6 @@ pthread_t pid;
 extern int server_sign;
 
 extern void CheckSystemValue(void);
-//extern int TransactionMessageAttemptsGet(void);
 extern int FirstHeartBeatResponse(void);
 extern void OCPP_get_TableAuthlocalAllData(void);
 extern int TransactionMessageAttemptsGet(void);
@@ -101,6 +101,9 @@ static int TransactionQueueInterval = 10;//3;
 static int TransactionQueueNum = 0;
 static int OfflineTransactionQueueNum = 0;  // Number of offline transactions
 static int  OfflineTransaction = 0;
+static int IsUsing = FALSE;
+static int IsFinished = FALSE;
+
 int defaultWaitingTime = 10; //10 second
 char OcppPath[160]={0};
 char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
@@ -865,24 +868,6 @@ if(fp == NULL) {
 	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)
-	{
-		sprintf(rmFileCmd,"rm -f %s","/Storage/OCPP/TransactionRelatedQueue");
-		system(rmFileCmd);
-	}
-
-	result = FALSE;
-
-	return result;
-}
-#endif
-
 if( fgets (str, 1200, fp)!=NULL ) {
 	/* writing content to stdout */
 	//DEBUG_INFO("str=%s",str);
@@ -1525,25 +1510,47 @@ void CheckTransactionPacket(char *uuid)
 
 }
 
-/* type: 0 (showqueue ); type: 1(showfront); type: 2(delq) type: 3 (sentqueue)  type: 4 (addq) type: 5(store queue to /Storage/OCPP/ )*/
+//---- type: 0 (showqueue ); type: 1(showfront); type: 2(delq) type: 3 (sentqueue)  type: 4 (addq) type: 5(store queue to /Storage/OCPP/ ) ---//
 int queue_operation(int type, char *frontUUID, char *frontData)
 {
-
-	pthread_mutex_unlock(&lock_sentData);
-	pthread_mutex_lock(&lock_sentData);
 	int result=0;
-	if(type == 0)   				// show items in queue
-			result = showqueue();
-	else if(type  == 1)   			// show first item
-			result = showfront(frontUUID, frontData);
-	else if(type == 2)   			// delete item
-			result = delq();
-	else if(type == 3)          	// sent items in queue
-			result = sentqueue();
-	else if(type == 4)         		// add items to the queue
-		   result = addq(frontUUID, frontData);
-
-	pthread_mutex_unlock(&lock_sentData);
+	while(1)
+	{
+		if (!IsUsing )
+		{
+			IsUsing = TRUE;
+			//pthread_mutex_unlock(&lock_sentData);
+			//pthread_mutex_lock(&lock_sentData);
+
+			if(type == 0)   				// show items in queue
+			{
+				result = showqueue();
+			}
+			else if(type  == 1)   			// show first item
+			{
+				result = showfront(frontUUID, frontData);
+			}
+			else if(type == 2)   			// delete item
+			{
+				result = delq();
+			}
+			else if(type == 3)          	// sent items in queue
+			{
+				result = sentqueue();
+			}
+			else if(type == 4)         		// add items to the queue
+			{
+				result = addq(frontUUID, frontData);
+			}
+
+			//pthread_mutex_unlock(&lock_sentData);
+
+			//IsFinished = TRUE;
+			IsUsing = FALSE;
+			break;
+		}
+	}
+	//IsFinished = FALSE;
 
 	return result;
 }