Browse Source

Merge branch 'master' of https://git.phihong.com.tw:30000/System_Integration/CSU3_AM335x

Alston 5 years ago
parent
commit
f9beecfe89

BIN
EVSE/Modularization/OcppBackend


+ 11 - 2
EVSE/Projects/AW-Regular/Apps/Makefile

@@ -6,7 +6,7 @@ Lib_Module_RFID = -L../../../Modularization -lModule_RFID
 Lib_Module_Upgrade = "-L../../../Modularization" -lModule_Upgrade
 
 all: CopyFile apps
-apps: Module_InternalComm_Task Module_FactoryConfig_Task Module_EventLogging_Task Module_AlarmDetect_Task Module_CSU_Task
+apps: Module_InternalComm_Task Module_FactoryConfig_Task Module_EventLogging_Task Module_AlarmDetect_Task Module_CSU_Task Module_Speaker_Task
 
 
 Module_InternalComm_Task:
@@ -57,8 +57,17 @@ Module_CSU_Task:
 	$(CC) -o main main.o ${Lib_Module_RFID} ${Lib_Module_Upgrade}
 	rm -f *.o
 	mv -f main ../Images/root		
+	@echo \
+
+Module_Speaker_Task:
+	@echo "===== Module_Speaker_Task ===================================="
+	rm -f Module_Speaker
+	$(CC) "-I../../"  -O0 -g3 -Wall -c -fmessage-length=0 -o Module_Speaker.o  "./Module_Speaker.c"
+	$(CC) -o Module_Speaker Module_Speaker.o 
+	rm -f *.o
+	mv -f Module_Speaker ../Images/root	
 	@echo \ 
-	
+
 CopyFile: 
 	rm -rfv ../Images/root
 	mkdir -p ../Images/root

+ 2 - 2
EVSE/Projects/AW-Regular/Apps/Module_FactoryConfig.c

@@ -226,8 +226,8 @@ int main(int argc, char *argv[])
 	// System configuration
 	time_t t = time(NULL);
 	struct tm tm = *localtime(&t);
-	strcpy((char*)SysConfig.ModelName, "AWLU770100W1P0");
-	strcpy((char*)SysConfig.SerialNumber, "D19520001A0");
+	strcpy((char*)SysConfig.ModelName, "AWLU700100W1PH");
+	strcpy((char*)SysConfig.SerialNumber, "D1904A001A0");
 	sprintf((char*)SysConfig.SystemId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
 	sprintf((char*)SysConfig.SystemDateTime, "%d-%d-%d %d:%d:%d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
 	SysConfig.AuthorisationMode = 0;	// 0:PH card	1: OCPP backend		2: PH backend	3: Free Mode

File diff suppressed because it is too large
+ 667 - 441
EVSE/Projects/AW-Regular/Apps/Module_InternalComm.c


+ 1 - 1
EVSE/Projects/AW-Regular/Apps/Module_InternalComm.h

@@ -1,7 +1,7 @@
 /*
  * Module_InternalComm.h
  *
- *  Created on: 2019?8?28?
+ *  Created on: 2019年8月28日
  *      Author: USER
  */
 

+ 285 - 0
EVSE/Projects/AW-Regular/Apps/Module_Speaker.c

@@ -0,0 +1,285 @@
+/*
+ * Module_Speaker.c
+ *
+ *  Created on: 2019年12月23日
+ *      Author: USER
+ */
+
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include	"define.h"
+#include	"main.h"
+
+#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 EVENT_INFO(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+#define Debug
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+#define ON					1
+#define OFF					0
+
+#define INTERVAL_1			100000
+#define INTERVAL_2			50000
+
+unsigned char speaker_type = SPEAKER_STOP;
+unsigned char pre_speaker_type = SPEAKER_STOP;
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct Charger					*ShmCharger;
+
+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;
+	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/SystemLog/%04d-%02d_%s_%s_SystemLog",
+			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,
+			ShmSysConfigAndInfo->SysConfig.ModelName,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
+#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);
+
+	return rc;
+}
+#endif
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+}
+
+//=================================
+// Common routine
+//=================================
+void trim(char *s)
+{
+    int i=0, j, k, l=0;
+
+    while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
+        i++;
+
+    j = strlen(s)-1;
+    while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
+        j--;
+
+    if(i==0 && j==strlen(s)-1) { }
+    else if(i==0) s[j+1] = '\0';
+    else {
+        for(k=i; k<=j; k++) s[l++] = s[k];
+        s[l] = '\0';
+    }
+}
+
+int mystrcmp(char *p1,char *p2)
+{
+    while(*p1==*p2)
+    {
+        if(*p1=='\0' || *p2=='\0')
+            break;
+        p1++;
+        p2++;
+    }
+    if(*p1=='\0' && *p2=='\0')
+        return(PASS);
+    else
+        return(FAIL);
+}
+
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
+{
+	strncpy(dest, src + start, cnt);
+	dest[cnt] = 0;
+}
+
+void split(char **arr, char *str, const char *del)
+{
+	char *s = strtok(str, del);
+
+	while(s != NULL)
+	{
+		*arr++ = s;
+		s = strtok(NULL, del);
+	}
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//Initial ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	//Initial ShmStatusCodeData
+	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	//Initial ShmCharger
+	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
+		#endif
+		result = FAIL;
+	}
+
+	return result;
+}
+
+//================================================
+// Main process
+//================================================
+int main(void)
+{
+	if(InitShareMemory() == FAIL)
+	{
+		DEBUG_ERROR("InitShareMemory NG\n");
+
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return FAIL;
+	}
+
+	for(;;)
+	{
+		if(ShmCharger->isSpeakerOn == ON)
+		{
+			switch(ShmCharger->speaker_type)
+			{
+				case SPEAKER_STOP:
+					DEBUG_INFO("SPEAKER_STOP...\r\n");
+					ShmCharger->isSpeakerOn = OFF;
+					break;
+				case SPEAKER_ALWAYS_ON:
+					break;
+				case SPEAKER_SHORT:
+					system("echo 1 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_1);
+					system("echo 0 > /sys/class/gpio/gpio65/value");
+
+					ShmCharger->isSpeakerOn = OFF;
+					DEBUG_INFO("SPEAKER_SHORT...\r\n");
+					break;
+				case SPEAKER_LONG:
+					break;
+				case SPEAKER_INTERVAL_SHORT:
+					break;
+				case SPEAKER_INTERVAL_LONG:
+					break;
+				case SPEAKER_INTERVAL_3COUNT:
+					system("echo 1 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_2);
+					system("echo 0 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_2);
+					system("echo 1 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_2);
+					system("echo 0 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_2);
+					system("echo 1 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_2);
+					system("echo 0 > /sys/class/gpio/gpio65/value");
+
+					ShmCharger->isSpeakerOn = OFF;
+					DEBUG_INFO("SPEAKER_INTERVAL_3COUNT...\r\n");
+					break;
+			}
+		}
+	}
+}
+

+ 57 - 18
EVSE/Projects/AW-Regular/Apps/main.c

@@ -27,8 +27,9 @@
 #define TMR_IDX_8					8
 #define TMR_IDX_9 					9
 
-#define TIMEOUT_SPEC_HANDSHAKING	180000
-#define TIMEOUT_SPEC_AUTH			30000
+#define TIMEOUT_SPEC_HANDSHAKING		180000
+#define TIMEOUT_SPEC_AUTH				30000
+#define TIMEOUT_SPEC_HANDSHAKING_LED	185000
 
 #define MtdBlockSize 				0x600000
 
@@ -484,7 +485,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	{
 		ChkSum+=buf[wrd];
 	}
-	memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+	memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
 
 	//================================================
 	// Load configuration from mtdblock11
@@ -533,7 +534,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 		{
 			ChkSum+=buf[wrd];
 		}
-		memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+		memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
 
 		//================================================
 		// Load configuration from mtdblock12 (Factory default)
@@ -582,7 +583,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 			{
 				ChkSum+=buf[wrd];
 			}
-			memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+			memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
 			if(ChkSum!=ChkSumOrg)
 			{
 				DEBUG_WARN("factory default  SysConfigData checksum NG, restore factory default\r\n");
@@ -614,7 +615,6 @@ void InitEthernet()
 	char tmpbuf[256];
 	//unsigned int address;
 
-	DEBUG_INFO("11111111111111111111");
 	//Init Eth0 for internet
 	if(isInterfaceUp("eth0")==PASS)
 	{
@@ -628,7 +628,7 @@ void InitEthernet()
 		ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
 		system(tmpbuf);
 	}
-	DEBUG_INFO("2222222222222222");
+
 	if(isInterfaceUp("eth1")==PASS)
 	{
 		//Init Eth1 for administrator tool
@@ -638,7 +638,7 @@ void InitEthernet()
 		ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
 		system(tmpbuf);
 	}
-	DEBUG_INFO("3333333333333333333333");
+
 
     //Run DHCP client if enabled
 	system("killall udhcpc");
@@ -662,6 +662,7 @@ int SpawnTask()
 	system ("pkill OcppBackend");
 	system ("pkill Module_AlarmDetect");
 	system ("pkill Module_InternalComm");
+	system ("pkill Module_Speaker");
 
 	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
 	{
@@ -673,9 +674,13 @@ int SpawnTask()
 	}
 
 	system("/root/Module_EventLogging &");
-	system("/root/OcppBackend &");
+	if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0)
+	{
+		system("/root/OcppBackend &");
+	}
 	system("/root/Module_AlarmDetect &");
 	system("/root/Module_InternalComm &");
+	system ("/root/Module_Speaker &");
 
 	return PASS;
 }
@@ -1213,6 +1218,15 @@ void setLedMotion(unsigned char gun_index,unsigned char led_mode)
 		case LED_ACTION_ALL_OFF:
 			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_ALL_OFF;
 			break;
+		case LED_RELAY_ON:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_RELAY_ON;
+			break;
+		case LED_RELAY_OFF:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_RELAY_OFF;
+			break;
+		case LED_ACTION_HANDSHAKE_FAIL:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_HANDSHAKE_FAIL;
+			break;
 	}
 }
 
@@ -1354,6 +1368,11 @@ int main(void)
 	// Main loop
 	for(;;)
 	{
+		//==========================================
+		// Synchronize share memory from OCPP struct
+		//==========================================
+		ShmSysConfigAndInfo->SysInfo.OcppConnStatus = ShmOCPP16Data->OcppConnStatus;
+
 		//==========================================
 		// Something need run in Idle mode
 		//==========================================
@@ -1486,14 +1505,13 @@ int main(void)
 						ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
 						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = 0;
 						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
+						setLedMotion(gun_index,LED_ACTION_IDLE);
 					}
 
-					if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) && (ShmCharger->rfidReq == ON)) ||
+					if((ShmCharger->rfidReq == ON) ||
 					   (ShmSysConfigAndInfo->SysConfig.Bluetooth.isRequestStart == ON) ||
 					   (ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq == ON))
 					{
-						setSpeaker(ON,SPEAKER_SHORT);
-
 						// User id
 						memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
 
@@ -1644,7 +1662,23 @@ int main(void)
 						switch(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod)
 						{
 							case START_METHOD_BACKEND:
-								setChargerMode(gun_index, MODE_PREPARING);
+								if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
+								  (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_OCPP))
+								{
+									if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0))
+									{
+										setSpeaker(ON,SPEAKER_SHORT);
+										setChargerMode(gun_index, MODE_PREPARING);
+									}
+									else
+									{
+										setSpeaker(ON,SPEAKER_INTERVAL_3COUNT);
+										setChargerMode(gun_index, MODE_IDLE);
+									}
+
+									ShmCharger->rfidReq = OFF;
+									ShmOCPP16Data->SpMsg.bits.AuthorizeConf = OFF;
+								}
 								break;
 							case START_METHOD_RFID:
 								if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
@@ -1655,10 +1689,12 @@ int main(void)
 									   (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREEMODE) ||
 									   (!ShmOCPP16Data->OcppConnStatus&&(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREEMODE)))
 									{
+										setSpeaker(ON,SPEAKER_SHORT);
 										setChargerMode(gun_index, MODE_PREPARING);
 									}
 									else
 									{
+										setSpeaker(ON,SPEAKER_INTERVAL_3COUNT);
 										setChargerMode(gun_index, MODE_IDLE);
 									}
 
@@ -1674,8 +1710,6 @@ int main(void)
 						}
 					}
 
-					setLedMotion(gun_index,LED_ACTION_AUTHED);
-
 					break;
 				case MODE_PREPARING:
 					if(isModeChange(gun_index))
@@ -1695,7 +1729,12 @@ int main(void)
 						 * 	TODO:
 						 * 	1. HANDSHAKING timeout process
 						 */
-						setChargerMode(gun_index, MODE_IDLE);
+						setLedMotion(gun_index, LED_ACTION_HANDSHAKE_FAIL);
+
+						if(DiffTimeb(startTime[TMR_IDX_HANDSHAKING]) > TIMEOUT_SPEC_HANDSHAKING_LED)
+						{
+							setChargerMode(gun_index, MODE_IDLE);
+						}
 					}
 					else if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
 					{
@@ -1706,12 +1745,12 @@ int main(void)
 						ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = ON;
 						setChargerMode(gun_index, MODE_CHARGING);
 					}
-
-					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B))
+					else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B))
 					{
 						setLedMotion(gun_index,LED_ACTION_CONNECTED);
 					}
 
+
 					break;
 				case MODE_CHARGING:
 					if(isModeChange(gun_index))

+ 3 - 0
EVSE/Projects/AW-Regular/Apps/main.h

@@ -126,6 +126,9 @@
 #define LED_ACTION_BLE_DISABLE      	11
 #define LED_ACTION_DEBUG            	12
 #define LED_ACTION_ALL_OFF          	13
+#define LED_RELAY_ON               	 	14
+#define LED_RELAY_OFF               	15
+#define LED_ACTION_HANDSHAKE_FAIL   	16
 
 #define START_METHOD_MANUAL 			0
 #define START_METHOD_RFID	 			1

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


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


+ 5 - 1
EVSE/Projects/BYTON-GB/Apps/Makefile

@@ -5,7 +5,6 @@ export PATH=/bin:/sbin:/usr/bin:$(SDK_PATH_TARGET)/usr/bin:$PATH
 Lib_Module_RFID = -L../../../Modularization -lModule_RFID
 Lib_Module_Upgrade = "-L../../../Modularization" -lModule_Upgrade
 
-
 all: CopyFile apps
 apps: Module_InternalComm_Task Module_FactoryConfig_Task Module_EventLogging_Task Module_AlarmDetect_Task Module_CSU_Task
 
@@ -21,6 +20,11 @@ Module_InternalComm_Task:
 	
 Module_FactoryConfig_Task:
 	@echo "===== Module_FactoryConfig_Task =================================="
+	rm -f Module_FactoryConfig
+	gcc "-I../../" -o Module_FactoryConfig "./Module_FactoryConfig.c"
+	mkdir -p /Storage/SystemLog	
+	./Module_FactoryConfig -f;true
+	cp /mnt/FactoryDefaultConfig.bin ../Images 
 	rm -f Module_FactoryConfig 
 	$(CC) "-I../../" -O0 -g3 -Wall -c -fmessage-length=0 -o Module_FactoryConfig.o "./Module_FactoryConfig.c"
 	$(CC) -o Module_FactoryConfig Module_FactoryConfig.o 

+ 2 - 0
EVSE/Projects/BYTON-GB/Apps/Module_AlarmDetect.c

@@ -608,6 +608,7 @@ int main(void)
 			//=====================================
 			// Current DC leak detection
 			//=====================================
+			/*
 			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)
 			{
 				if(Alarm_Counter[gun_index].Dc_Leak > FILTER_SPEC)
@@ -634,6 +635,7 @@ int main(void)
 					DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \r\n");
 				}
 			}
+			*/
 
 			//=====================================
 			// MCU self test fail detection

+ 3 - 3
EVSE/Projects/BYTON-GB/Apps/Module_EventLogging.c

@@ -276,7 +276,7 @@ int main(void)
 						memcpy(EventCodeTmp,FaultStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
 						if(((tmp>>BitCount)&0x01)==0)//Recovered
 						{
-							EventCodeTmp[0]=1;
+							EventCodeTmp[0]='1';
 							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]&=~(1<<BitCount);
 						}
 						else
@@ -301,7 +301,7 @@ int main(void)
 						memcpy(EventCodeTmp,AlarmStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
 						if(((tmp>>BitCount)&0x01)==0)//Recovered
 						{
-							EventCodeTmp[0]=1;
+							EventCodeTmp[0]='1';
 							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]&=(0<<BitCount);
 						}
 						else
@@ -326,7 +326,7 @@ int main(void)
 						memcpy(EventCodeTmp,InfoStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
 						if(((tmp>>BitCount)&0x01)==0)//Recovered
 						{
-							EventCodeTmp[0]=1;
+							EventCodeTmp[0]='1';
 							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]&=(0<<BitCount);
 						}
 						else

+ 144 - 81
EVSE/Projects/BYTON-GB/Apps/Module_FactoryConfig.c

@@ -36,6 +36,9 @@
 #define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define PASS				1
 #define FAIL				-1
+#define OUTPUT_FLASH		0x01
+#define OUTPUT_FILE			0x02
+
 
 struct SysConfigData 			SysConfig;
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
@@ -186,24 +189,35 @@ int InitShareMemory()
     return result;
 }
 
+void helpOutput(void)
+{
+	printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
+	printf("Generate factory default configuration value\r\n\r\n");
+	printf("OPTION:\r\n");
+	printf("	-a Write to file(/mnt) & flash\r\n");
+	printf("	-f Write to file(/mnt)\r\n");
+	printf("	-m Write to flash\r\n");
+}
+
 //================================================
 // Main process
 //================================================
-int main(void)
+int main(int argc, char *argv[])
 {
-
-	unsigned int i,Chk;
+	unsigned char outType=0;
+	unsigned int i,Chk,MtdBlockSize=0x600000;
 	unsigned char *ptr;
 	int fd,wrd;
 
-	ptr=malloc(sizeof(struct SysConfigData));
+	ptr=malloc(MtdBlockSize);
 	if(ptr==NULL)
 	{
-		DEBUG_ERROR("malloc for SysConfigData NG\r\n");
-
+		#ifdef SystemLogMessage
+		StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
+		#endif
 		return 0;
 	}
-	memset(ptr,0,sizeof(struct SysConfigData));
+	memset(ptr,0,MtdBlockSize);
 	memset(&SysConfig,0,sizeof(struct SysConfigData));
 
 	/*
@@ -213,7 +227,7 @@ int main(void)
 	time_t t = time(NULL);
 	struct tm tm = *localtime(&t);
 	strcpy((char*)SysConfig.ModelName, "AWLU770100W1P0");
-	strcpy((char*)SysConfig.SerialNumber, "D195200001A0");
+	strcpy((char*)SysConfig.SerialNumber, "D19520001A0");
 	sprintf((char*)SysConfig.SystemId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
 	sprintf((char*)SysConfig.SystemDateTime, "%d-%d-%d %d:%d:%d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
 	SysConfig.AuthorisationMode = 0;	// 0:PH card	1: OCPP backend		2: PH backend	3: Free Mode
@@ -254,7 +268,7 @@ int main(void)
 	SysConfig.OfflinePolicy = 0;			// 0: Local list	1: PH RFID		2: Free		3: Deny
 	SysConfig.OfflineMaxChargeEnergy = 0;	// 0: Same as MaxChargeEnergy	Other: 1~65535KWH
 	SysConfig.OfflineMaxChargeDuration = 0; // 0: Same as MaxChargeDuration Other: 1~65535 minutes
-	strcpy((char*)SysConfig.OcppServerURL, "ws://evsocket.phihong.com.tw/");
+	strcpy((char*)SysConfig.OcppServerURL, "ws://192.168.0.246:8080/ocpp/");
 	sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
 
 
@@ -263,94 +277,143 @@ int main(void)
 
 	// Calculate CRC
 	Chk=0;
-	for(i=0;i<(sizeof(struct SysConfigData)-4);i++)
+	for(i=0;i<(MtdBlockSize-4);i++)
 	{
 		Chk+=*(ptr+i);
 	}
-	SysConfig.Checksum=Chk;
+	memcpy(	ptr+MtdBlockSize-4,&Chk,4);
 
-	// Save factory default setting value to file
-	fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
-	if (fd < 0)
-	{
-
-		DEBUG_ERROR("open /mnt/FactoryDefaultConfig.bin NG\r\n");
-
-		free(ptr);
-		return 0;
-	}
-	wrd=write(fd, &SysConfig, sizeof(struct SysConfigData));
-	close(fd);
-	if(wrd!=(sizeof(struct SysConfigData)))
+	/*
+	 * Parameter process
+	 */
+	if(argc>1)
 	{
-		DEBUG_ERROR("write /mnt/FactoryDefaultConfig.bin NG\r\n");
-
-		free(ptr);
-		return 0;
+		char *arg = argv[1];
+		switch(arg[0])
+		{
+			case '-':
+				switch(arg[1])
+				{
+					case 'a':
+						outType |= OUTPUT_FILE;
+						outType |= OUTPUT_FLASH;
+						break;
+					case 'f':
+						outType |= OUTPUT_FILE;
+						break;
+					case 'm':
+						outType |= OUTPUT_FLASH;
+						break;
+					default:
+						helpOutput();
+						break;
+				}
+				break;
+			default:
+				helpOutput();
+				break;
+		}
 	}
-
-	// Save factory default setting value to flash factory default setting block
-	fd = open("/dev/mtdblock12", O_RDWR);
-	if (fd < 0)
+	else
 	{
-
-		DEBUG_ERROR("open /dev/mtdblock12 NG\r\n");
-
-		free(ptr);
-		return 0;
+		helpOutput();
 	}
-	wrd=write(fd, &SysConfig, sizeof(struct SysConfigData));
-	close(fd);
-	if(wrd!=(sizeof(struct SysConfigData)))
-	{
-		DEBUG_ERROR("write /dev/mtdblock12 NG\r\n");
 
-		free(ptr);
-		return 0;
-	}
-
-	// Save factory default setting value to flash backup setting block
-	fd = open("/dev/mtdblock11", O_RDWR);
-	if (fd < 0)
-	{
-		DEBUG_ERROR("open /dev/mtdblock11 NG\r\n");
-
-		free(ptr);
-		return 0;
-	}
-	wrd=write(fd, &SysConfig, sizeof(struct SysConfigData));
-	close(fd);
-	if(wrd!=(sizeof(struct SysConfigData)))
+	/*
+	 * Configuration bin file generate
+	 */
+	if((outType&OUTPUT_FILE)>0)
 	{
-		DEBUG_ERROR("write /dev/mtdblock11 NG\r\n");
-
-		free(ptr);
-		return 0;
+		// Save factory default setting value to file
+		fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
+		if (fd < 0)
+		{
+
+			DEBUG_ERROR("open /mnt/FactoryDefaultConfig.bin NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			DEBUG_ERROR("write /mnt/FactoryDefaultConfig.bin NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+
+		DEBUG_INFO("FactoryConfig write to file in /mnt OK.\r\n");
 	}
 
-	// Save factory default setting value to flash setting block
-	fd = open("/dev/mtdblock10", O_RDWR);
-	if (fd < 0)
-	{
-		DEBUG_ERROR("open /dev/mtdblock10 NG\r\n");
-
-		free(ptr);
-		return 0;
-	}
-	wrd=write(fd, &SysConfig, sizeof(struct SysConfigData));
-	close(fd);
-	if(wrd!=(sizeof(struct SysConfigData)))
+	/*
+	 * Flash memory write
+	 */
+	if((outType&OUTPUT_FLASH)>0)
 	{
-		DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
-
-		free(ptr);
-		return 0;
+		// Save factory default setting value to flash factory default setting block
+		fd = open("/dev/mtdblock12", O_RDWR);
+		if (fd < 0)
+		{
+
+			DEBUG_ERROR("open /dev/mtdblock12 NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			DEBUG_ERROR("write /dev/mtdblock12 NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+
+		// Save factory default setting value to flash backup setting block
+		fd = open("/dev/mtdblock11", O_RDWR);
+		if (fd < 0)
+		{
+			DEBUG_ERROR("open /dev/mtdblock11 NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			DEBUG_ERROR("write /dev/mtdblock11 NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+
+		// Save factory default setting value to flash setting block
+		fd = open("/dev/mtdblock10", O_RDWR);
+		if (fd < 0)
+		{
+			DEBUG_ERROR("open /dev/mtdblock10 NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+
+		DEBUG_INFO("FactoryConfig write to flash OK\r\n");
 	}
 
 	free(ptr);
 
-	DEBUG_INFO("FactoryConfig OK\r\n");
-
-
 	return FAIL;
 }

+ 56 - 5
EVSE/Projects/BYTON-GB/Apps/Module_InternalComm.c

@@ -198,7 +198,7 @@ int InitShareMemory()
 		result = FAIL;
 	}
 
-	//Initial ShmOcppModuleKey
+	//Initial ShmCharger
 	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), IPC_CREAT | 0777)) < 0)
 	{
 		#ifdef SystemLogMessage
@@ -711,6 +711,7 @@ unsigned char Query_AC_MCU_Status(unsigned char fd, unsigned char targetAddr, Ac
 			Ret_Buf->meter_state = rx[16];
 			Ret_Buf->pp_state = rx[17];
 			Ret_Buf->rating_current = rx[18];
+			Ret_Buf->rotatory_switch = rx[19];
 
 			result = PASS;
 		}
@@ -1261,6 +1262,37 @@ unsigned char Config_AC_MCU_LEGACY_REQUEST(unsigned char fd, unsigned char targe
 	return result;
 }
 
+unsigned char Query_AC_GUN_PLUGIN_TIMES(unsigned char fd, unsigned char targetAddr, Gun_Plugin_Times *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_CONFIG_GUN_PLUGIN_TIMES, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 0)
+	{
+		if(len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			Ret_Buf-> GunPluginTimes = ((uint32_t)rx[6] | (((uint32_t)rx[7])<<8) | (((uint32_t)rx[8])<<16) | (((uint32_t)rx[9])<<24));
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
 unsigned char Config_AC_MaxCurrent_And_CpPwmDuty(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Cp_Pwm_Duty*Set_Buf)
 {
 	unsigned char result = FAIL;
@@ -1526,7 +1558,7 @@ int main(void)
 				memcpy(ShmCharger->evseId.serial_number, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmCharger->evseId.serial_number));
 				if(Config_Serial_Number(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
 				{
-					DEBUG_INFO("MCU-%d set serial number OK...\r\n");
+					DEBUG_INFO("MCU-%d set serial number : %.12s\r\n",gun_index,ShmCharger->evseId.serial_number);
 					ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass = PASS;
 
 					failCount[gun_index] = 0;
@@ -1549,7 +1581,7 @@ int main(void)
 				memcpy(ShmCharger->evseId.model_name, ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmCharger->evseId.model_name));
 				if(Config_Model_Name(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
 				{
-					DEBUG_INFO("MCU-%d set model name OK...\r\n");
+					DEBUG_INFO("MCU-%d set model name : %.14s\r\n",gun_index,ShmCharger->evseId.model_name);
 					ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass = PASS;
 
 					failCount[gun_index] = 0;
@@ -1601,6 +1633,25 @@ int main(void)
 					failCount[gun_index]++;
 			}
 
+			//===============================
+			// Query gun plug-in times
+			//===============================
+			if(Query_AC_GUN_PLUGIN_TIMES(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].gunPluginTimes) == PASS)
+			{
+				DEBUG_INFO("MCU-%d get gun plugin times : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
+
+				ShmSysConfigAndInfo->SysConfig.AcPlugInTimes = (float)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes;
+
+				failCount[gun_index] = 0;
+			}
+			else
+			{
+
+				DEBUG_WARN("MCU-%d get gun plugin times fail...%d\r\n", gun_index, failCount[gun_index]);
+				if(failCount[gun_index]<1000)
+					failCount[gun_index]++;
+			}
+
 			//===============================
 			// Query temperature
 			//===============================
@@ -1635,6 +1686,7 @@ int main(void)
 				DEBUG_INFO("MCU-%d get Meter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
 				DEBUG_INFO("MCU-%d get PP State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
 				DEBUG_INFO("MCU-%d get Rating Current : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
+				DEBUG_INFO("MCU-%d get Rotatory switch : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
 
 				ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState = ShmCharger->gun_info[gun_index].primaryMcuState.cp_state;
 				ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotDuty = (ShmCharger->gun_info[gun_index].primaryMcuState.current_limit>51?(unsigned char)((ShmCharger->gun_info[gun_index].primaryMcuState.current_limit/2.5)+64):(unsigned char)(ShmCharger->gun_info[gun_index].primaryMcuState.current_limit/0.6));
@@ -1887,7 +1939,6 @@ int main(void)
 				tmMcu.tm_sec = ShmCharger->gun_info[gun_index].rtc.sec;
 				mcuTime.time = mktime(&tmMcu);
 
-
 				if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin && !ShmOCPP16Data->OcppConnStatus)
 				{
 					if(abs(DiffTimeb(csuTime, mcuTime)) > 10000)
@@ -2043,7 +2094,7 @@ int main(void)
 				}
 			}
 		}
-		sleep(3);
+		usleep(100000);
 	}
 
 	return FAIL;

+ 2 - 1
EVSE/Projects/BYTON-GB/Apps/Module_InternalComm.h

@@ -1,7 +1,7 @@
 /*
  * Module_InternalComm.h
  *
- *  Created on: 2019Ś~8¤ë28¤é
+ *  Created on: 2019?8?28?
  *      Author: USER
  */
 
@@ -44,6 +44,7 @@ enum MESSAGE_COMMAND
 	CMD_CONFIG_AC_LED = 0x88,
 	CMD_CONFIG_CURRENT_LINIT = 0x89,
 	CMD_CONFIG_MCU_MODE = 0x8A,
+	CMD_CONFIG_GUN_PLUGIN_TIMES = 0x2D,
 
 	CMD_UPDATE_START = 0xe0,
 	CMD_UPDATE_ABOARD = 0xe1,

File diff suppressed because it is too large
+ 312 - 409
EVSE/Projects/BYTON-GB/Apps/main.c


+ 32 - 2
EVSE/Projects/BYTON-GB/Apps/main.h

@@ -127,6 +127,21 @@
 #define LED_ACTION_DEBUG            	12
 #define LED_ACTION_ALL_OFF          	13
 
+#define START_METHOD_MANUAL 			0
+#define START_METHOD_RFID	 			1
+#define START_METHOD_BACKEND 			2
+#define START_METHOD_BLE	 			3
+
+#define AUTH_MODE_PH_RFID				0
+#define AUTH_MODE_OCPP					1
+#define AUTH_MODE_PH_BACKEND			2
+#define AUTH_MODE_FREEMODE				3
+
+#define OFF_POLICY_LOCALLIST			0
+#define OFF_POLICY_PH_RFID				1
+#define OFF_POLICY_FREEMODE				2
+#define OFF_POLICY_NOCHARGE				3
+
 #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)
@@ -245,14 +260,15 @@ typedef struct AC_PRIMARY_MCU
 {
 	unsigned char cp_state;
 	unsigned int  current_limit;
-	unsigned int  cp_voltage_positive;
-	unsigned int  cp_voltage_negtive;
+	float cp_voltage_positive;
+	float cp_voltage_negtive;
 	unsigned char locker_state;
 	unsigned char relay_state;
 	unsigned char shutter_state;
 	unsigned char meter_state;
 	unsigned char pp_state;
 	unsigned char rating_current;
+	unsigned char rotatory_switch;
 }Ac_Primary_Mcu;
 
 typedef struct AC_PRIMARY_MCU_ALARM
@@ -357,6 +373,18 @@ typedef struct FW_UPGRADE_INFO
 	char location[384];
 }Fw_Upgrade_Info;
 
+typedef struct GUN_PLUGIN_TIMES
+{
+	uint32_t GunPluginTimes;
+
+}Gun_Plugin_Times;
+
+typedef struct INTERNAL_SYSTEM_STATUS
+{
+	unsigned char SystemStatus;
+	unsigned char PreviousSystemStatus;
+}Internal_Sysyem_status;
+
 typedef struct GUN_INFO
 {
 	Ver 											ver;
@@ -376,6 +404,8 @@ typedef struct GUN_INFO
 	Ac_Primary_Mcu_Cp_Pwm_Duty						primaryMcuCp_Pwn_Duty;
 	Other_Alarm_Code								otherAlarmCode;
 	Pilot_Voltage									PilotVoltage;
+	Gun_Plugin_Times								gunPluginTimes;
+	Internal_Sysyem_status							internalSystemStatus;
 }Gun_Info;
 
 struct Charger

BIN
EVSE/rootfs/root/OcppBackend


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