Browse Source

2020-01-09 /Kathy Yeh
[Module_OcppBackend]1. add system log for ocpp message
2.modfiy system status & create previous system status array
3.modify set charging profile logic
4. modify logic for OcppConnStatus
5. modfiy stop Transaction meter error
6. modify define.h for ocpp module

Kathy_Yeh 5 years ago
parent
commit
b9c4bb19b5

File diff suppressed because it is too large
+ 410 - 242
EVSE/Modularization/ocppfiles/MessageHandler.c


+ 1 - 0
EVSE/Modularization/ocppfiles/MessageHandler.h

@@ -15,6 +15,7 @@ struct StructProfile
 	struct StructPeriod	Period[10];
 };
 
+
 //===============================================
 // Common routine
 //===============================================

+ 30 - 12
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -29,9 +29,7 @@
 #include 	<ifaddrs.h>
 #include 	"libwebsockets.h"
 #include 	<lws_config.h>
-
 #include	"hashmap.h"
-
 #include    "SystemLogMessage.h"
 #include 	"ShareMemory.h"
 #include 	<pthread.h>
@@ -39,6 +37,7 @@
 #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)
@@ -56,8 +55,8 @@ struct lws 								*wsi_client;
 struct lws_context 						*context;
 static int sendbuffer = 0;
 extern int server_sign;
-extern int TransactionMessageAttemptsValue;
-extern int TransactionMessageRetryIntervalValue;
+//extern int TransactionMessageAttemptsValue;
+//extern int TransactionMessageRetryIntervalValue;
 //extern int server_pending;
 
 //extern struct OCPP16Data 				*ShmOCPP16Data;
@@ -69,6 +68,7 @@ extern int TransactionMessageAttemptsGet(void);
 extern int TransactionMessageRetryIntervalGet(void);
 extern int GetOcppConnStatus(void);
 
+
 pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
 pthread_mutex_t lock_sentData = PTHREAD_MUTEX_INITIALIZER;
 
@@ -107,7 +107,7 @@ static int ConnectionEstablished=0;
 static int TransactionMessageResend = 1;
 static int TransactionQueueInterval = 10;//3; // TransactionMessageAttempts
 static int TransactionQueueNum = 0;
-static int  OfflineTransaction = 0;  // 1:offline  0: online
+static int  OfflineTransaction = 0;
 int defaultWaitingTime = 10; //10 second
 
 extern int BootNotificationInterval;
@@ -353,7 +353,7 @@ int SendData(struct lws *wsi)
 
     memcpy (out + LWS_SEND_BUFFER_PRE_PADDING, SendBuffer, len );
 
-    DEBUG_INFO("out + LWS_SEND_BUFFER_PRE_PADDING = %s\n", out + LWS_SEND_BUFFER_PRE_PADDING);
+    DEBUG_OCPPMESSAGE_INFO("out + LWS_SEND_BUFFER_PRE_PADDING = %s\n", out + LWS_SEND_BUFFER_PRE_PADDING);
     n = lws_write(wsi, out + LWS_SEND_BUFFER_PRE_PADDING, len, LWS_WRITE_TEXT);
 
     memset(SendBuffer, 0, len);
@@ -462,9 +462,8 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 			((char *)in)[len] = '\0';
 			#ifdef SystemLogMessage
 			DEBUG_INFO("LWS_CALLBACK_CLIENT_RECEIVE, RX length: %d\n", (int)len);
-			//DEBUG_INFO("Message: %s\n", (char *)in);
 			#endif
-
+			DEBUG_OCPPMESSAGE_INFO("%s\n", (char *)in);
 			ReceivedMessage(in, len);
 
 			break;
@@ -613,7 +612,7 @@ stat("../Storage/OCPP", &stats);
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
 {
-	DEBUG_INFO("\n OCPP directory exist \n");
+	//DEBUG_INFO("\n OCPP directory exist \n");
 }
 else
 {
@@ -626,7 +625,7 @@ memset(&rmFileCmd, 0, sizeof rmFileCmd);
 
 if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
 {
-	DEBUG_INFO("TransactionRelatedQueue exist.\n");
+	//DEBUG_INFO("TransactionRelatedQueue exist.\n");
 }
 else
 {
@@ -651,7 +650,7 @@ if(fp == NULL) {
 	DEBUG_INFO("Error opening TransactionRelatedQueue file");
 	return FALSE;
 }
-printf("test\n");
+
 if( fgets (str, 1200, fp)!=NULL ) {
 	/* writing content to stdout */
 
@@ -691,7 +690,7 @@ if( fgets (str, 1200, fp)!=NULL ) {
 }
 else
 {
-	DEBUG_INFO("queue is null\n");
+	//DEBUG_INFO("queue is null\n");
 	strcpy(uuid,"");
 	strcpy(data,"");
 	result = FALSE;
@@ -1323,6 +1322,8 @@ return 0;
 //================================================
 int main(void)
 {
+	char rmFileCmd[100]={0};
+	struct stat stats;
 	pthread_t t;
 	#ifdef SystemLogMessage
 	DEBUG_INFO("Initialization...\n");
@@ -1333,6 +1334,23 @@ int main(void)
 		return FAIL;
 	}
 
+	//Create OCPP dir
+	stat("../Storage/OCPP", &stats);
+
+	// Check for directory existence
+	if (S_ISDIR(stats.st_mode) == 1)
+	{
+		DEBUG_INFO("\n OCPP directory exist \n");
+	}
+	else
+	{
+		DEBUG_INFO("\n OCPP directory not exist, create dir \n");
+		sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
+		system(rmFileCmd);
+	}
+
+	memset(&rmFileCmd, 0, sizeof rmFileCmd);
+
 	//Create Process: Resend Transaction
 	pthread_create(&t, NULL, processTransactionQueue, NULL); //
 

+ 28 - 1
EVSE/Modularization/ocppfiles/SystemLogMessage.c

@@ -4,7 +4,7 @@
 #include 	<string.h>
 #include	<time.h>
 #include	<stdarg.h>
-#include 	<unistd.h>
+//#include    "SystemLogMessage.h"
 
 #define Debug
 #define SystemLogMessage
@@ -35,4 +35,31 @@ int StoreLogMsg(const char *fmt, ...)
 	#endif
 	return rc;
 }
+
+int StoreOcppMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >>  /Storage/OCPP/[%04d.%02d]OcppMessage",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+	printf("buffer: %s\n",Buf );
+	//execl("sh", "sh", "-c", Buf, NULL);//system((const char*)Buf);
+	system((const char*)Buf);
+	#ifdef Debug
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+	#endif
+	return rc;
+}
 #endif

+ 2 - 0
EVSE/Modularization/ocppfiles/SystemLogMessage.h

@@ -5,7 +5,9 @@
 #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)
+#define DEBUG_OCPPMESSAGE_INFO(format, args...) StoreOcppMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
 int StoreLogMsg(const char *fmt, ...);
+int StoreOcppMsg(const char *fmt, ...);
 
 #endif

+ 3 - 3
EVSE/Projects/define.h

@@ -2963,7 +2963,7 @@ struct StructSampledValue
 struct StructMeterValue
 {
 	unsigned char 				TimeStamp[28];
-	struct StructSampledValue	*SampledValue;
+	struct StructSampledValue	SampledValue[10];
 };
 struct StructConfigurationKeyItems
 {
@@ -3055,7 +3055,7 @@ struct StructStopTransaction
 															"UnlockCommand",
 															"DeAuthorized"
 														*/
-	struct StructMeterValue		*TransactionData;
+	struct StructMeterValue		TransactionData[0];
 	struct StructIdTagInfo		ResponseIdTagInfo;
 };
 
@@ -3179,7 +3179,7 @@ struct StructMeterValues
 {
 	int					 			ConnectorId;
 	int 							TransactionId;
-	struct StructMeterValue			*MeterValue;
+	struct StructMeterValue			MeterValue[0];
 };
 struct StructRemoteStartTransaction
 {

Some files were not shown because too many files changed in this diff