Browse Source

2020-03-18 / Kathy Yeh

1. modify offline / online transaction logic
2. add LocalPreAuthorize function
3. modify file path to absolute path
Kathy_Yeh 5 years ago
parent
commit
238e43a696

+ 188 - 18
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -1282,8 +1282,8 @@ void CheckSystemValue(void)
 		//==============================================
 		if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
 		{
-			sendStartTransactionRequest(gun_index);
 			ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
+			sendStartTransactionRequest(gun_index);
 			clientTime.StartTransaction = time((time_t*)NULL);
 			clientTime.MeterValues[gun_index] = time((time_t*)NULL);
 		 }
@@ -1293,8 +1293,8 @@ void CheckSystemValue(void)
 		//==============================================
 		if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
 		{
-			sendStopTransactionRequest(gun_index);
 			ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
+			sendStopTransactionRequest(gun_index);
 			clientTime.StopTransaction = time((time_t*)NULL);
 		}
 
@@ -1589,7 +1589,7 @@ int sendAuthorizeRequest(int gun_index)
 	DEBUG_INFO("sendAuthorizeRequest \n");
 
 	//Local Authorize
-	if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))
+	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);
 		if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
@@ -2732,6 +2732,15 @@ int sendStopTransactionRequest(int gun_index)
 	queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
 
 	LWS_Send(queuedata);
+
+
+
+	int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
+
+	if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
+	{
+		SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
+	}
 #if 0
 	sprintf(tempdata, "StopTransaction,%d", (gun_index));
 	if(hashmap_operation(0, guid, tempdata) == 1)
@@ -4130,7 +4139,7 @@ int handleClearCacheRequest(char *uuid, char *payload)
     char rmFileCmd[100]={0};
     struct stat stats;
     DEBUG_INFO("handle  ClearCacheRequest\n");
-    stat("../Storage/OCPP", &stats);
+    stat("/Storage/OCPP", &stats);
 
     // Check for directory existence
     if (S_ISDIR(stats.st_mode) == 1)
@@ -10266,6 +10275,8 @@ void handleStartTransactionResponse(char *payload, int gun_index)
 	int c = 0;
 	char *loc;
 	int transactionIdInt = 0;
+	FILE *outfile;
+	char data[100]={0};
 //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
 	DEBUG_INFO("handleStartTransactionResponse\n");
 
@@ -10345,12 +10356,46 @@ void handleStartTransactionResponse(char *payload, int gun_index)
 	sstr[c] = '\0';
 	ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
 	transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
-	TransactionId[gun_index] = transactionIdInt;
-	DEBUG_INFO("gun_index: %d\n", gun_index);
-	DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
+
 	ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
 	ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
 
+
+	//-----------Start : write to the Queue TransactionId file -----------------//
+	if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
+	{
+		//DEBUG_INFO("QueueTransactionId exist.\n");
+	}
+	else
+	{
+		//DEBUG_INFO("QueueTransactionId not exist\n");
+		FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
+
+		if(log == NULL)
+		{
+			DEBUG_INFO("Can't Create File QueueTransactionId \n");
+			return ;
+		}
+		else
+		{
+			fclose(log);
+		}
+	}
+
+	// open file for writing
+	outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
+	//DEBUG_INFO("data=%s\n",data);
+	sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);  // GunIndex, idtag, TransactionId
+	fputs(data, outfile);
+	//fputs("\n", outfile);
+	fclose (outfile);
+	//-------------End:  write to the Queue TransactionId file------------------------------------------//
+
+	TransactionId[gun_index] = transactionIdInt;
+	//DEBUG_INFO("gun_index: %d\n", gun_index);
+	//DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
+
+
 #ifdef SystemLogMessage
 DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
 DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
@@ -13562,7 +13607,7 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 
 	//DEBUG_INFO("filename=%s\n",filename);
 	//DEBUG_INFO("url=%s\n",url);
-	sprintf(FilePath,"../mnt/%s",filename);
+	sprintf(FilePath,"/mnt/%s",filename);
 
 	if((access(FilePath,F_OK))!=-1)
 	{
@@ -13571,7 +13616,7 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 		system(rmFileCmd);
 	}
 	memset(ftpbuf, 0, sizeof(ftpbuf));
-	sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
+	sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
 			//sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
 	systemresult = system(ftpbuf);
 
@@ -13602,7 +13647,7 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 	IPbuffer = inet_ntoa(*((struct in_addr*)
 				 	 server->h_addr_list[0]));
 #endif
-	sprintf(FilePath,"../mnt/%s",filename);
+	sprintf(FilePath,"/mnt/%s",filename);
 
 	if((access(FilePath,F_OK))!=-1)
 	{
@@ -13613,7 +13658,7 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 
 	memset(ftpbuf, 0, sizeof(ftpbuf));
 
-	sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
+	sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
 	//sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
 	//DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
 		//sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
@@ -13641,7 +13686,7 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 	//DEBUG_INFO("filename=%s\n",filename);
 	//DEBUG_INFO("url=%s\n",url);
 
-	sprintf(FilePath,"%s","../mnt/upload_file.txt");
+	sprintf(FilePath,"%s","/mnt/upload_file.txt");
 
 	if((access(FilePath,F_OK))!=-1)
 	{
@@ -13650,7 +13695,7 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 		system(rmFileCmd);
 	}
 
-	FILE *fp = fopen("../mnt/upload_file.txt", "w+");
+	FILE *fp = fopen("/mnt/upload_file.txt", "w+");
 
 	if(fp == NULL)
 	{
@@ -13667,7 +13712,7 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 	}
 
 	memset(ftpbuf, 0, sizeof(ftpbuf));
-	sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
+	sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
 	systemresult = system(ftpbuf);
 
 	DEBUG_INFO("systemresult=%d\n",systemresult);
@@ -14265,14 +14310,129 @@ void SetHeartBeatWithNOResponse(void)
 	HeartBeatWithNOResponse = 0;
 }
 
-int GetTransactionId(int gunindex)
+void splitstring(char *src,const char *separator,char **dest,int *num) {
+	/*
+		src 源字串的首地址(buf的地址)
+		separator 指定的分割字元
+		dest 接收子字串的陣列
+		num 分割後子字串的個數
+	*/
+     char *pNext;
+     int count = 0;
+     if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
+        return;
+     if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
+        return;
+     pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
+     while(pNext != NULL) {
+          *dest++ = pNext;
+          ++count;
+         pNext = (char *)strtok(NULL,separator);  //必須使用(char *)進行強制型別轉換
+    }
+    *num = count;
+}
+
+int GetTransactionId(int gunindex, unsigned char idTag[])
 {
-	return TransactionId[gunindex];
+	char ch;
+	FILE *fptr1;
+	int temptransactionId;
+	char str[100]={0};
+
+	temptransactionId = 0;
+	/*------ Read the file ----------------*/
+	fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
+	ch=fgetc(fptr1);
+	//printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
+	rewind(fptr1);
+	if(ch!=EOF)
+	{
+	   // printf("%c",ch);
+		while (fgets(str, 100, fptr1) != NULL)
+		{
+			str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
+
+			if(str[0]=='\0')
+			{
+				break;
+			}
+			char *revbuf[8] = {0}; //存放分割後的子字串
+			int num = 0;//分割後子字串的個數
+			printf(" Now the content of the file 44444 is : \n");
+			splitstring(str,",",revbuf,&num); //呼叫函式進行分割
+			printf(" Now the content of the file 5555 is : \n");
+			if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
+			{
+				temptransactionId = atoi(revbuf[2]);
+				break;
+			}
+		}
+	}
+
+	fclose(fptr1);
+	/*------- End of reading ---------------*/
+	return temptransactionId;
 }
 
-void SetTransactionIdZero(int gunindex)
+void SetTransactionIdZero(int transactionId)
 {
-	TransactionId[gunindex] = 0;
+	//TransactionId[gunindex] = 0;
+    char ch;
+    FILE *fptr1, *fptr2;
+	int temptransactionId;
+    char str[100]={0}, temp[] = "/Storage/OCPP/temp.txt";
+	printf("\n\n Delete a specific line from a file :\n");
+	printf("-----------------------------------------\n");
+	//scanf("%s",fname);
+    fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
+    if (!fptr1)
+	{
+            printf(" File not found or unable to open the input file!!\n");
+            return ;
+    }
+    fptr2 = fopen(temp, "w"); // open the temporary file in write mode
+    if (!fptr2)
+	{
+            printf("Unable to open a temporary file to write!!\n");
+            fclose(fptr1);
+            return ;
+    }
+
+    ch=fgetc(fptr1);
+    //printf(" Now the content of the file %s is : \n",fname);
+
+    rewind(fptr1);
+    if(ch!=EOF)
+    {
+    	// copy all contents to the temporary file except the specific line
+    	while (fgets(str, 100, fptr1) != NULL)
+    	{
+    		str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
+
+    		if(str[0]=='\0')
+    		{
+    			break;
+    		}
+
+    		char *revbuf[8] = {0}; //存放分割後的子字串
+    		int num = 0;//分割後子字串的個數
+
+    		splitstring(str,",",revbuf,&num); //呼叫函式進行分割
+
+    		temptransactionId = atoi(revbuf[2]);
+    		if(transactionId != temptransactionId)
+    		{
+    			fprintf(fptr2, "%s", str);
+    		}
+    	}
+
+    }
+    fclose(fptr1);
+    fclose(fptr2);
+    remove("/Storage/OCPP/QueueTransactionId");  		// remove the original file
+    rename(temp, "/Storage/OCPP/QueueTransactionId"); 	// rename the temporary file to original name
+/*------ Read the file ----------------*/
+
 }
 
 int InternetDisconnect(void)
@@ -15863,6 +16023,16 @@ void GetChargingProfileRequest(int gunindex)
 						ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
 }
 
+void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
+{
+	ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
+	ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
+	ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
+	strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
+	strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
+
+}
+
 void LWS_Send(char * str)
 {
 	//=====================================================

+ 4 - 2
EVSE/Modularization/ocppfiles/MessageHandler.h

@@ -122,9 +122,11 @@ extern int queue_operation(int type, char *frontUUID, char *frontData);
 int GetOcppServerURL();
 int GetOcppPath();
 int GetOcppPort();
-int GetTransactionId(int gunindex);
-void SetTransactionIdZero(int gunindex);
+int GetTransactionId(int gunindex, unsigned char idTag[]);
+void SetTransactionIdZero(int transactionId);
 void GetChargingProfileRequest(int gunindex);
+void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[]);
+void splitstring(char *src,const char *separator,char **dest,int *num);
  //===============================================
  // sqlite related routine
  //===============================================

+ 107 - 17
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -33,10 +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
@@ -105,7 +107,7 @@ char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
 //===============================
 // OCPP SentQueue TransactionId
 //===============================
-static int SentQueueTransactionId[10]={0};
+//static int SentQueueTransactionId[10]={0};
 
 
 extern int BootNotificationInterval;
@@ -1113,18 +1115,24 @@ return 0;
 int sentqueue(){
 FILE *fp;
 int result = FALSE; // 1: TRUE  0:FALSE
-int temptransactionId = 0;
+int temptransactionId = 0, gettransactionId = 0;
 int tempconnectorId = 0;
-int gunIndex = 0;
+//int gunIndex = 0;
 char guid[37]={0};
 char tempdata[65]={0};
 char key_value[65]={0};
 int IsStopTransaction = FALSE;
+//int IsconnectorIdNULL = FALSE;
+//int IsIdtagNULL = FALSE;
 char str[1200]={0};
 char strcomposite[1200]={0};
 char rmFileCmd[100]={0};
 struct stat stats;
-char sstr[28]={ 0 };
+char sstr[28]={0};
+unsigned char IdtagStr[20]={0};
+unsigned char timestampStr[30]={0};
+int tempmeterStart = 0;
+int tempreservationId = 0;
 int c = 0;
 char *loc;
 
@@ -1165,8 +1173,7 @@ if( fgets (str, 1200, fp)!=NULL ) {
 		IsStopTransaction = TRUE;
     }
 
-
-	//*********************connectorId***************************/
+	//*********************Start:connectorId***************************/
 	loc = strstr(str, "connectorId");
 	c = 0;
 	memset(sstr ,0, sizeof(sstr) );
@@ -1179,17 +1186,42 @@ if( fgets (str, 1200, fp)!=NULL ) {
 		}
 		sstr[c] = '\0';
 		tempconnectorId = atoi(sstr);
+	}
+//	else
+//	{
+//		IsconnectorIdNULL = TRUE;
+//	}
+	//*********************End:connectorId***************************/
+
 
-		//DEBUG_INFO("\n tempconnectorId:%d\n", tempconnectorId);
+	//*********************Start:idTag***************************/
+	loc = strstr(str, "idTag");
+	c = 0;
+	memset(sstr ,0, sizeof(sstr) );
+	if(loc != NULL)
+	{
+		while (loc[3+strlen("idTag")+c] != '\"')
+		{
+			sstr[c] = loc[3+strlen("idTag")+c];
+			c++;
+		}
+		sstr[c] = '\0';
+		strcpy((char*)IdtagStr, sstr);
 	}
+//	else
+//	{
+//		IsIdtagNULL = TRUE;
+//	}
+	//*********************End:idTag***************************/
 
 
-	//*********************StartTransaction***************************/
+	//*********************Start: StartTransaction***************************/
 	loc = strstr(str, "StartTransaction");
 	c = 0;
 	memset(sstr ,0, sizeof(sstr) );
 	if(loc != NULL)
 	{
+		// [2,0200000000000000000000000001584415776,StartTransaction,{connectorId:1,idTag:123,meterStart:100,reservationId:0,timestamp:2020-03-17T03:29:36Z}]
 		//DEBUG_INFO("\n sent queue StartTransaction\n");
 		if(tempconnectorId > 0)
 		{
@@ -1200,10 +1232,8 @@ if( fgets (str, 1200, fp)!=NULL ) {
 		//	sprintf(tempdata, "StartTransaction,%d", 0);
 		//}
 
-
+        //GUID
 		memset(sstr ,0, sizeof(sstr) );
-		//DEBUG_INFO("\n 0-0. sent queue str=%s\n",str);
-
 		c=0;
 		while (str[4+c] != '\"')
 		{
@@ -1212,9 +1242,64 @@ if( fgets (str, 1200, fp)!=NULL ) {
 		}
 		sstr[c] = '\0';
 		strcpy(guid, sstr);
-		//DEBUG_INFO("\n 0. sent queue sstr=%s\n",sstr);
 
 
+		//Idtag
+		loc = strstr(str, "idTag");
+		memset(sstr ,0, sizeof(sstr) );
+		c=0;
+		while (loc[3+strlen("idTag")+c] != '\"')
+		{
+			sstr[c] = loc[3+strlen("idTag")+c];
+			c++;
+	    }
+		sstr[c] = '\0';
+		strcpy((char*)IdtagStr, sstr);
+
+		//meterStart
+		loc = strstr(str, "meterStart");
+		c = 0;
+		memset(sstr ,0, sizeof(sstr) );
+		if(loc != NULL)
+		{
+			while (loc[strlen("meterStart")+2+c] != ',')
+			{
+				sstr[c] = loc[strlen("meterStart")+2+c];
+				c++;
+			}
+			sstr[c] = '\0';
+			tempmeterStart = atoi(sstr);
+
+		}
+
+		//reservationId
+		loc = strstr(str, "reservationId");
+		c = 0;
+		memset(sstr ,0, sizeof(sstr) );
+		if(loc != NULL)
+		{
+			while (loc[strlen("reservationId")+2+c] != ',')
+			{
+				sstr[c] = loc[strlen("reservationId")+2+c];
+				c++;
+			}
+			sstr[c] = '\0';
+			tempreservationId = atoi(sstr);
+
+		}
+
+		//timestamp
+		loc = strstr(str, "timestamp");
+		memset(sstr ,0, sizeof(sstr) );
+		c=0;
+		while (loc[3+strlen("timestamp")+c] != '\"')
+		{
+			sstr[c] = loc[3+strlen("timestamp")+c];
+			c++;
+		}
+		sstr[c] = '\0';
+		strcpy((char*)timestampStr, sstr);
+
 
 		if(hashmap_operation(1, guid, key_value) == TRUE)
 		{
@@ -1223,10 +1308,11 @@ if( fgets (str, 1200, fp)!=NULL ) {
 		else
 		{
 			hashmap_operation(0, guid, tempdata);
+            FillStartTransaction(tempconnectorId, IdtagStr, tempmeterStart, tempreservationId, timestampStr);
 			//DEBUG_INFO("\n 2. sent queue guid=%s\n",guid);
-
 		}
 	}
+	//*********************End: StartTransaction***************************/
 
 
 	//****************transactionId********************/
@@ -1247,6 +1333,7 @@ if( fgets (str, 1200, fp)!=NULL ) {
 		//puts(str);
 		//DEBUG_INFO("\n uuid:%s", "");
 		//DEBUG_INFO("\n data:%s", str);
+#if 0
 		if(IsStopTransaction == TRUE)
 		{
 			for(int i=0; i <10; i++)
@@ -1272,15 +1359,18 @@ if( fgets (str, 1200, fp)!=NULL ) {
 				gunIndex = tempconnectorId-1;
 			}
 		}
+#endif
+
 
 		//DEBUG_INFO("\n gunIndex=%d \n",gunIndex);
 		//DEBUG_INFO("\n temptransactionId=%d \n",temptransactionId);
 		//DEBUG_INFO("\n GetTransactionId(gunIndex)=%d \n",GetTransactionId(gunIndex));
 
-		if((GetTransactionId(gunIndex) != 0)&&(temptransactionId != GetTransactionId(gunIndex)))
+		gettransactionId = GetTransactionId(tempconnectorId, IdtagStr);
+		if((gettransactionId != 0)&&(temptransactionId != gettransactionId))
 		{
 			strncpy(strcomposite,str, (loc-str)+2+strlen("transactionId"));
-			sprintf(strcomposite+((loc-str)+2+strlen("transactionId")),"%d",GetTransactionId(gunIndex));
+			sprintf(strcomposite+((loc-str)+2+strlen("transactionId")),"%d",gettransactionId);
 			strcat(strcomposite, loc+strlen("transactionId")+2+c);
 			LWS_Send(strcomposite);
 		}
@@ -1289,9 +1379,9 @@ if( fgets (str, 1200, fp)!=NULL ) {
 			LWS_Send(str);
 		}
 
-		if((IsStopTransaction == TRUE)&&(GetTransactionId(gunIndex) != 0))
+		if((IsStopTransaction == TRUE)&&(gettransactionId != 0))
 		{
-			SetTransactionIdZero(gunIndex);
+			SetTransactionIdZero(gettransactionId);
 		}
 
 	 }