|
@@ -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
|
|
|
}
|
|
|
|