Przeglądaj źródła

Merge branch 'master' into AW-CCS

FolusWen 4 lat temu
rodzic
commit
abcb251704

+ 2 - 2
EVSE/Modularization/Makefile

@@ -83,8 +83,8 @@ Module_UpgradeLib:
 
 Module_EventLogging:
 	rm -f Module_EventLogging
-	$(CC) -D $(Project) -I ../Projects -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EventLogging.o Module_EventLogging.c
-	$(CC) -o Module_EventLogging Module_EventLogging.o
+	$(CC) -D $(Project) -I ../Projects -I ./ocppfiles -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EventLogging.o Module_EventLogging.c
+	$(CC) -L ./ocppfiles -lsqlite3 -o Module_EventLogging Module_EventLogging.o
 	rm -f Module_EventLogging.o
 	mv -f Module_EventLogging ../rootfs/root
 

+ 113 - 13
EVSE/Modularization/Module_EventLogging.c

@@ -26,6 +26,7 @@
 #include	<time.h>
 #include	<ctype.h>
 #include 	<ifaddrs.h>
+#include	<sqlite3.h>
 #include	"define.h"
 
 #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
@@ -38,23 +39,25 @@
 #define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define PASS				1
 #define FAIL				-1
+#define DB_FILE							"/Storage/EventLog/Eventlog.db"
 
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData 			*ShmStatusCodeData;
 
+sqlite3 *localDb;
+
 void trim(char *s);
 int mystrcmp(char *p1,char *p2);
 void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
 void split(char **arr, char *str, const char *del);
 
-
-#ifdef SystemLogMessage
 int StoreLogMsg(const char *fmt, ...)
 {
 	char Buf[4096+256];
 	char buffer[4096];
 	time_t CurrentTime;
 	struct tm *tm;
+	struct timeval tv;
 	va_list args;
 
 	va_start(args, fmt);
@@ -64,19 +67,22 @@ int StoreLogMsg(const char *fmt, ...)
 	memset(Buf,0,sizeof(Buf));
 	CurrentTime = time(NULL);
 	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/Eventlog/[%04d.%02d]EventLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
+
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/Eventlog/[%04d.%02d]EventLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
 			buffer,
 			tm->tm_year+1900,tm->tm_mon+1);
 #ifdef SystemLogMessage
 	system(Buf);
 #endif
 
-	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);
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
+#endif
 
 	return rc;
 }
-#endif
 
 int StoreEventLogMsg(const char *fmt, ...)
 {
@@ -84,6 +90,7 @@ int StoreEventLogMsg(const char *fmt, ...)
 	char buffer[4096];
 	time_t CurrentTime;
 	struct tm *tm;
+	struct timeval tv;
 	va_list args;
 
 	va_start(args, fmt);
@@ -93,11 +100,12 @@ int StoreEventLogMsg(const char *fmt, ...)
 	memset(Buf,0,sizeof(Buf));
 	CurrentTime = time(NULL);
 	tm=localtime(&CurrentTime);
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
 
 	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
 	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/EventLog/[%04d.%02d]%s_%s_EventLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/EventLog/[%04d.%02d]%s_%s_EventLog",
+					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
 					buffer,
 					tm->tm_year+1900,tm->tm_mon+1,
 					ShmSysConfigAndInfo->SysConfig.ModelName,
@@ -105,8 +113,8 @@ int StoreEventLogMsg(const char *fmt, ...)
 	}
 	else
 	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/EventLog/[%04d.%02d]EventLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/EventLog/[%04d.%02d]EventLog",
+					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
 					buffer,
 					tm->tm_year+1900,tm->tm_mon+1);
 	}
@@ -116,7 +124,7 @@ int StoreEventLogMsg(const char *fmt, ...)
 #endif
 
 #ifdef ConsloePrintLog
-	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);
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
 #endif
 
 	return rc;
@@ -132,9 +140,9 @@ int DiffTimeb(struct timeb ST, struct timeb ET)
 	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
 }
 
-//=================================
+//==========================================
 // Common routine
-//=================================
+//==========================================
 void trim(char *s)
 {
     int i=0, j, k, l=0;
@@ -297,6 +305,90 @@ int InitShareMemory()
     return result;
 }
 
+//==========================================
+// SQLite routne
+//==========================================
+int DB_Open(sqlite3 *db)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char* createRecordSql="CREATE TABLE IF NOT EXISTS event_record("
+					      "idx integer primary key AUTOINCREMENT, "
+						  "occurDatetime text NOT NULL, "
+						  "statusCode text NOT NULL"
+						  ");";
+
+	//sqlite3_config(SQLITE_CONFIG_URI, 1);
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		DEBUG_INFO( "Local event record database open successfully.\n");
+
+		if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_ERROR( "Create local event record table error message: %s\n", errMsg);
+		}
+		else
+		{
+			DEBUG_INFO( "Opened local event record table successfully\n");
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Insert_Record(sqlite3 *db, uint8_t *statusCode)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char sqlStr[1024];
+
+	sprintf(sqlStr, "insert into event_record(occurDatetime, statusCode) values(CURRENT_TIMESTAMP, '%s');", statusCode);
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		DEBUG_INFO( "Local event record database open successfully.\n");
+		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "Insert local event record error message: %s\n", errMsg);
+		}
+		else
+		{
+			DEBUG_INFO( "Insert local event record successfully\n");
+		}
+
+		sprintf(sqlStr, "delete from event_record where idx < (select idx from event_record order by idx desc limit 1)-2000;");
+		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "delete local event_record error message: %s\n", errMsg);
+		}
+		else
+		{
+			DEBUG_INFO( "delete local event record successfully\n");
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
 //================================================
 // Main process
 //================================================
@@ -318,6 +410,11 @@ int main(void)
 		return 0;
 	}
 
+	if(DB_Open(localDb) != PASS)
+	{
+		DEBUG_ERROR("Local database initial fail.\n");
+	}
+
 	for(;;)
 	{
 		//check Fault Status
@@ -347,6 +444,7 @@ int main(void)
 						}
 
 						EVENT_INFO("%s\n", EventCodeTmp);
+						DB_Insert_Record(localDb, EventCodeTmp);
 					}
 				}
 			}
@@ -378,6 +476,7 @@ int main(void)
 							AddFaultCodeToBuf(EventCodeDisp);
 						}
 						EVENT_INFO("%s\n", EventCodeTmp);
+						DB_Insert_Record(localDb, EventCodeTmp);
 					}
 				}
 			}
@@ -409,6 +508,7 @@ int main(void)
 							AddFaultCodeToBuf(EventCodeDisp);
 						}
 						EVENT_INFO("%s\n", EventCodeTmp);
+						DB_Insert_Record(localDb, EventCodeTmp);
 					}
 				}
 			}

+ 2 - 0
EVSE/Projects/AW-CCS/Apps/main.c

@@ -852,6 +852,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 				DEBUG_WARN("factory default  SysConfigData checksum NG, restore factory default\n");
 				free(buf);
 				system("cd /root;./Module_FactoryConfig -m");
+				system("rm -f /Storage/OCPP/OCPPConfiguration");
 				system("sync");
 				sleep(5);
 				system("reboot -f");
@@ -2742,6 +2743,7 @@ int main(void)
 						ftime(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
 						setLedMotion(gun_index,LED_ACTION_AUTHED);
 						ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_DUTY_5;	
+
 						system("/root/Module_CCS");
 					}
 					

+ 4 - 1
EVSE/Projects/AW-Regular/Apps/Module_InternalComm.c

@@ -33,7 +33,7 @@
 
 //#define SIMULATION
 
-#define FAIL_SPEC_COMM		1000
+#define FAIL_SPEC_COMM		100
 #define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define PASS				1
 #define FAIL				0
@@ -2630,6 +2630,9 @@ int main(void)
 			//===============================
 			if(failCount[gun_index] >= FAIL_SPEC_COMM)
 			{
+				if((0 <= failCount[gun_index]%FAIL_SPEC_COMM) && (failCount[gun_index]%FAIL_SPEC_COMM < 10))
+					sleep(10);
+				
 				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout == OFF)
 				{
 					DEBUG_ERROR("Primary MCU-%d communication fault", gun_index);

+ 2 - 1
EVSE/Projects/AW-Regular/Apps/main.c

@@ -1255,7 +1255,7 @@ void get_firmware_version(unsigned char gun_index)
 	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.56.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.57.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -2163,6 +2163,7 @@ int main(void)
 				}
 
 				system("cd /root;./Module_FactoryConfig -m");
+				system("rm -f /Storage/OCPP/OCPPConfiguration");
 				system("sync");
 				sleep(5);
 				system("reboot -f");

BIN
EVSE/Projects/AW-Regular/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/AW-Regular/Images/ramdisk.gz


+ 4 - 1
EVSE/Projects/Noodoe/Apps/Module_InternalComm.c

@@ -33,7 +33,7 @@
 
 //#define SIMULATION
 
-#define FAIL_SPEC_COMM		1000
+#define FAIL_SPEC_COMM		100
 #define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define PASS				1
 #define FAIL				0
@@ -2630,6 +2630,9 @@ int main(void)
 			//===============================
 			if(failCount[gun_index] >= FAIL_SPEC_COMM)
 			{
+				if((0 <= failCount[gun_index]%FAIL_SPEC_COMM) && (failCount[gun_index]%FAIL_SPEC_COMM < 10))
+					sleep(10);
+				
 				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout == OFF)
 				{
 					DEBUG_ERROR("Primary MCU-%d communication fault", gun_index);

+ 2 - 1
EVSE/Projects/Noodoe/Apps/main.c

@@ -1255,7 +1255,7 @@ void get_firmware_version(unsigned char gun_index)
 	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.43.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.44.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -2163,6 +2163,7 @@ int main(void)
 				}
 
 				system("cd /root;./Module_FactoryConfig -m");
+				system("rm -f /Storage/OCPP/OCPPConfiguration");
 				system("sync");
 				sleep(5);
 				system("reboot -f");

BIN
EVSE/Projects/Noodoe/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/Noodoe/Images/ramdisk.gz