|
@@ -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)
|
|
|
{
|
|
|
//=====================================================
|