Przeglądaj źródła

2022-01-28 / Simon Xue

Simon Xue 3 lat temu
rodzic
commit
b19d80a2b6

+ 574 - 0
EVSE/Modularization/Module_Systex.c

@@ -0,0 +1,574 @@
+/*
+ * 	Module_RFID.c
+ *
+ *  Created on: 2019-10-24
+ *  Update: 2020-10-19
+ *  Author: Eason Yang
+ *	Version: V0.03
+ *
+ * History 
+ * 1. Added : Reyax code.
+ *
+ *
+ *
+ *
+ *
+ */
+
+#include "Module_Systex.h"
+
+#define RequestLength		600
+#define ResponseLength		600
+
+//==================================
+// PRINT OUT LOG FORMAT
+//==================================
+#define SystemLogMessage
+#define DEBUG_INFO_1(format, args...) StoreLogMessage("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN_1(format, args...) StoreLogMessage("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR_1(format, args...) StoreLogMessage("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//==================================
+// HOST ID, offset = 0, length = 2 bytes , 
+//==================================
+unsigned char HOST_ID_CreditCard[] = {0x31, 0x30};//信用卡
+unsigned char HOST_ID_eTicket_Polling[] = {0x35, 0x30};//電子票證
+
+
+//==================================
+// Transaction Type, offset = 2, length = 2 bytes , 
+//==================================
+unsigned char TRANS_TYPE_Sale[] = {0x31, 0x31};	//消費交易 : 信用卡,票證,掃碼支付
+unsigned char TRANS_TYPE_Void[] = {0x30, 0x35};//取消交易 : 信用卡,
+unsigned char TRANS_TYPE_Refund[] = {0x31, 0x32};//退貨交易 : 信用卡,票證,掃碼支付
+
+unsigned char TRANS_TYPE_Pre_Auth[] = {0x31, 0x33};	//預授權交易 : 信用卡
+unsigned char TRANS_TYPE_Pre_Auth_Complete[] = {0x33, 0x31};	//預授權完成交易 : 信用卡 
+unsigned char TRANS_TYPE_Pre_Auth_Cancel[] = {0x33, 0x32};	//取消預授權交易 : 信用卡 
+
+unsigned char TRANS_TYPE_UnionSettlement[] = {0x35, 0x41};	//批次結帳請款
+
+
+//==================================
+// SystemLog message
+//==================================
+#ifdef SystemLogMessage
+int StoreLogMessage(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]RFID_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);
+	system(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
+
+//==========================================
+// Module's command send/receive
+//==========================================
+int SendRequest(int uart, unsigned char* cmd, int length)
+{
+	int len, TotalRtn=0, Rtn,i;
+	unsigned int StartTime;
+	unsigned char LRC=0;
+	unsigned char SendBuffer[RequestLength+4], RecvBuf[8];
+
+	len=length+3;
+	memset(SendBuffer,0,RequestLength+4);
+	SendBuffer[0]=0x02;
+	memcpy(SendBuffer+1,cmd,length);
+	SendBuffer[length+1]=0x03;
+	for(i=1;i<=length+1;i++)
+	{
+		LRC^=SendBuffer[i];
+	}
+	SendBuffer[length+2]=LRC;
+	
+	//sleep(2); //required to make flush work, for some reason
+	//for(int i=0;i<len;i++)
+		//printf("%x\n",SendBuffer[i]);
+	//printf("strlen(SendBuffer)=%d\n",strlen(SendBuffer));
+	//printf("SendBuffer[0]=%x,SendBuffer[601]=%x,SendBuffer[602]=%x \n",SendBuffer[i],SendBuffer[601],SendBuffer[602]);
+	//tcflush(uart,TCIOFLUSH);
+	while(1)
+	{
+			Rtn=write(uart, SendBuffer+TotalRtn, len-TotalRtn);
+			if(Rtn>0)
+			{	
+				TotalRtn+=Rtn;
+				if(TotalRtn>=len)
+				{
+					//printf("Rtn=%d,TotalRtn=%d\n",Rtn,TotalRtn);	
+					break;
+				}
+			}
+			else
+			{
+				DEBUG_INFO_1("SendRequest: write fail (%d / %d)\n", TotalRtn,len);
+				return -1;
+			}		
+	}
+	
+	//usleep(100000);
+	TotalRtn=0;
+	memset(SendBuffer,0,RequestLength+4);
+	StartTime = time(NULL);
+	while(1)
+	{
+			Rtn=read(uart, SendBuffer+TotalRtn, 2-TotalRtn);
+			if(Rtn>0)
+			{	
+				TotalRtn+=Rtn;
+				if(TotalRtn>=2)
+				{
+					if((SendBuffer[0]==0x06)&&(SendBuffer[1]==0x06))
+						return TotalRtn;
+					else
+					{
+						DEBUG_INFO_1("SendRequest: not recv ACKACK(%x, %x)\n", SendBuffer[0],SendBuffer[1]);
+						return -1;
+					}			
+				}
+			}
+			else
+			{
+				if((time(NULL)-StartTime)>3)
+				{	
+					DEBUG_INFO_1("SendRequest: read fail (%d / 6)\n", TotalRtn);
+					return -1;
+				}
+			}		
+	}
+}
+
+int RecvResponse(int uart, unsigned char* rx)
+{
+	int len, TotalRtn=0, Rtn,i;
+	unsigned int StartTime;
+	unsigned char LRC=0, counter=0;
+	unsigned char RecvBuffer[ResponseLength+4], tmpBuf[16];
+
+reRecv:
+	len=ResponseLength+3;
+	memset(RecvBuffer,0,ResponseLength+4);
+	LRC=0;
+	TotalRtn=0;
+	StartTime = time(NULL);
+	while(1)
+	{
+			Rtn=read(uart, RecvBuffer+TotalRtn, len-TotalRtn);
+			if(Rtn>0)
+			{	
+				TotalRtn+=Rtn;
+				//for(int i=0;i<TotalRtn;i++)
+					//printf("%x",RecvBuffer[i]);
+				//printf("\n");	
+				if(TotalRtn>=len)
+				{
+					if((RecvBuffer[0]!=0x02)||(RecvBuffer[ResponseLength+1]!=0x03))
+					{
+						memset(tmpBuf,0,sizeof(tmpBuf));
+						tmpBuf[0]=tmpBuf[1]=0x06;
+						Rtn=write(uart, tmpBuf, 2);
+						DEBUG_INFO_1("RecvResponse: Not Response format (STX=%c , ETX=%c)\n", RecvBuffer[0],RecvBuffer[ResponseLength+1]);
+						return -1;
+					}	
+					for(i=1;i<=ResponseLength+1;i++)
+					{
+						LRC^=RecvBuffer[i];
+					}
+					if(RecvBuffer[ResponseLength+2]!=LRC)
+					{
+						if(counter++<2)
+						{	
+							memset(tmpBuf,0,sizeof(tmpBuf));
+							tmpBuf[0]=tmpBuf[1]=0x15;
+							Rtn=write(uart, tmpBuf, 2);
+							goto reRecv;
+						}
+						else
+						{
+							memset(tmpBuf,0,sizeof(tmpBuf));
+							tmpBuf[0]=tmpBuf[1]=0x06;
+							Rtn=write(uart, tmpBuf, 2);
+							DEBUG_INFO_1("RecvResponse: 2 times LRC Error (%d / %d)\n", LRC,RecvBuffer[ResponseLength+2]);
+							return -1;
+						}	
+					}	
+					memset(tmpBuf,0,sizeof(tmpBuf));
+					memcpy(tmpBuf,RecvBuffer+1,8 );
+					if((strstr(tmpBuf,"00000000")==NULL)&&(strstr(tmpBuf,"000000TD")==NULL))
+					{
+						memset(tmpBuf,0,sizeof(tmpBuf));
+						tmpBuf[0]=tmpBuf[1]=0x06;
+						Rtn=write(uart, tmpBuf, 2);
+						DEBUG_INFO_1("RecvResponse: Response Code failed (%s)\n", tmpBuf);
+						return -1;
+					}
+					memset(tmpBuf,0,sizeof(tmpBuf));
+					tmpBuf[0]=tmpBuf[1]=0x06;
+					Rtn=write(uart, tmpBuf, 2);
+					memcpy(rx,RecvBuffer+1,ResponseLength);
+					return ResponseLength;
+				}
+			}
+			else
+			{
+				if((time(NULL)-StartTime)>40)//卡機30 seconds timeout
+				{	
+					DEBUG_INFO_1("RecvResponse: read fail (%d / %d)\n", TotalRtn,len);
+					return -1;
+				}
+			}		
+	}
+}
+
+//==========================================
+// CreditCardPreAuth
+// Input :
+//		PreCost : 預扣金額*100, e.g., $1234 = 123400, $1234.56=123456
+//		EVSEID: EVSE ID, max length is 18
+// Output :
+//		ApprovalNo : EDC簽單調閱編號或授權碼[信用卡退貨交易, max length is 12
+//		RRN : 信用卡交易序號, max length is 12
+//		CardNum: 卡號,max length is 20
+//		VemData : 無人自助設備交易資訊 交易別31/32 (預授權完成/預授權取消) 必要欄位 資訊來源為交易別13 (預授權)的回傳, max length is 64
+//==========================================
+int CreditCardPreAuth(int Fd, int PreCost,unsigned char *EVSEID, struct TransInfo *TransInfoReturn)
+{
+	unsigned char Buffer[RequestLength], *ptr, tmpbuf[12];
+	
+	memset(Buffer,0x20,RequestLength);
+	ptr=Buffer;
+	strncpy(ptr,HOST_ID_CreditCard,2);//Host ID
+	ptr+=2;
+	strncpy(ptr,TRANS_TYPE_Pre_Auth,2);//Transaction type
+	ptr+=2;
+	memset(tmpbuf,0,sizeof(tmpbuf));
+	sprintf(tmpbuf,"%d", PreCost);
+	if(strlen(tmpbuf)>12)
+	{
+		DEBUG_INFO_1("CreditCardPreAuth: Wrong PreCost (PreCost=%d)\n", PreCost);
+		return -1;
+	}	
+	memset(ptr,0x30,12);
+	strncpy(ptr+12-(strlen(tmpbuf)+2),tmpbuf,strlen(tmpbuf));//Trans Amount
+	ptr+=12;//Trans Amount
+	ptr+=12;//Approval No
+	ptr+=20;//Card No
+	strncpy(ptr,EVSEID, strlen(EVSEID));
+	ptr+=18;//Store Id	
+	//ptr+=2;//Period
+	if(SendRequest(Fd, Buffer, RequestLength)>0)
+	{
+		memset(Buffer,0,RequestLength);
+		if(RecvResponse(Fd,Buffer)>0)
+		{
+			//for(int i=0;i<RequestLength;i++)
+				//printf("%x, ",Buffer[i] );
+			strncpy(TransInfoReturn->TransAmount,Buffer+44,12);	
+			strncpy(TransInfoReturn->TransDate,Buffer+56,6);	
+			strncpy(TransInfoReturn->TransTime,Buffer+62,6);	
+			strncpy(TransInfoReturn->StoreId,Buffer+97,18);
+			strncpy(TransInfoReturn->ApprovalNo,Buffer+12,12);
+			strncpy(TransInfoReturn->RRN,Buffer+124,12);
+			strncpy(TransInfoReturn->CardNo,Buffer+24,20);
+			strncpy(TransInfoReturn->VemData,Buffer+246,64);
+			return 1;
+		}	
+		else
+		{
+			DEBUG_INFO_1("CreditCardPreAuth: RecvResponse failed\n");
+			return -1;
+		}	
+	}	
+	else
+	{
+		DEBUG_INFO_1("CreditCardPreAuth: SendRequest failed\n");
+		return -1;
+	}	
+}
+
+//==========================================
+// CreditCardAuthComplete
+// Input :
+//		PreCost : 扣金額*100, e.g., $1234 = 123400, $1234.56=123456
+//		EVSEID: EVSE ID, max length is 18
+//		VemData : the VEM data from CreditCardPreAuth, max length is 64
+// Output :
+//==========================================
+int CreditCardPreAuthComplete(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *VemData,struct TransInfo *TransInfoReturn)
+{
+	unsigned char Buffer[RequestLength], *ptr, tmpbuf[12];
+	
+	memset(Buffer,0x20,RequestLength);
+	ptr=Buffer;
+	strncpy(ptr,HOST_ID_CreditCard,2);//Host ID
+	ptr+=2;
+	strncpy(ptr,TRANS_TYPE_Pre_Auth_Complete,2);//Transaction type
+	ptr+=2;
+	memset(tmpbuf,0,sizeof(tmpbuf));
+	sprintf(tmpbuf,"%d", PreCost);
+	if(strlen(tmpbuf)>12)
+	{
+		DEBUG_INFO_1("CreditCardAuthComplete: Wrong PreCost (PreCost=%d)\n", PreCost);
+		return -1;
+	}	
+	memset(ptr,0x30,12);
+	strncpy(ptr+12-(strlen(tmpbuf)+2),tmpbuf,strlen(tmpbuf));//Trans Amount
+	ptr+=12;//Trans Amount
+	ptr+=12;//Approval No
+	ptr+=20;//Card No
+	strncpy(ptr,EVSEID, strlen(EVSEID));
+	ptr+=18;//Store Id	
+	//ptr+=2;//Period
+	strncpy(Buffer+500,VemData,64);
+	if(SendRequest(Fd, Buffer, RequestLength)>0)
+	{
+		memset(Buffer,0,RequestLength);
+		if(RecvResponse(Fd,Buffer)>0)
+		{
+			strncpy(TransInfoReturn->TransAmount,Buffer+44,12);	
+			strncpy(TransInfoReturn->TransDate,Buffer+56,6);	
+			strncpy(TransInfoReturn->TransTime,Buffer+62,6);	
+			strncpy(TransInfoReturn->StoreId,Buffer+97,18);
+			strncpy(TransInfoReturn->ApprovalNo,Buffer+12,12);
+			strncpy(TransInfoReturn->RRN,Buffer+124,12);
+			strncpy(TransInfoReturn->CardNo,Buffer+24,20);
+			strncpy(TransInfoReturn->VemData,Buffer+246,64);
+			return 1;
+		}	
+		else
+		{
+			DEBUG_INFO_1("CreditCardAuthComplete: RecvResponse failed\n");
+			return -1;
+		}	
+	}	
+	else
+	{
+		DEBUG_INFO_1("CreditCardAuthComplete: SendRequest failed\n");
+		return -1;
+	}	
+}
+
+//==========================================
+// CreditCardPreAuthCancel
+// Input :
+//		PreCost : 預扣金額*100, e.g., $1234 = 123400, $1234.56=123456
+//		EVSEID: EVSE ID, max length is 18
+//		ApprovalNo: max length is 12
+//		CardNum :  max length is 20
+// Output :
+//==========================================
+int CreditCardPreAuthCancel(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *ApprovalNo, unsigned char *CardNum,unsigned char *VemData)
+{
+	unsigned char Buffer[RequestLength], *ptr, tmpbuf[12];
+	
+	memset(Buffer,0x20,RequestLength);
+	ptr=Buffer;
+	strncpy(ptr,HOST_ID_CreditCard,2);//Host ID
+	ptr+=2;
+	strncpy(ptr,TRANS_TYPE_Pre_Auth_Cancel,2);//Transaction type
+	ptr+=2;
+	memset(tmpbuf,0,sizeof(tmpbuf));
+	sprintf(tmpbuf,"%d", PreCost);
+	if(strlen(tmpbuf)>12)
+	{
+		DEBUG_INFO_1("CreditCardPreAuthCancel: Wrong PreCost (PreCost=%d)\n", PreCost);
+		return -1;
+	}	
+	memset(ptr,0x30,12);
+	strncpy(ptr+12-(strlen(tmpbuf)+2),tmpbuf,strlen(tmpbuf));//Trans Amount
+	ptr+=12;//Trans Amount
+	strncpy(ptr,ApprovalNo, strlen(ApprovalNo));
+	ptr+=12;//Approval No
+	strncpy(ptr,CardNum, strlen(CardNum));
+	ptr+=20;//Card No
+	strncpy(ptr,EVSEID, strlen(EVSEID));
+	ptr+=18;//Store Id	
+	//ptr+=2;//Period
+	strncpy(Buffer+500,VemData,64);
+	if(SendRequest(Fd, Buffer, RequestLength)>0)
+	{
+		memset(Buffer,0,RequestLength);
+		if(RecvResponse(Fd,Buffer)>0)
+		{
+			return 1;
+		}	
+		else
+		{
+			DEBUG_INFO_1("CreditCardPreAuthCancel: RecvResponse failed\n");
+			return -1;
+		}	
+	}	
+	else
+	{
+		DEBUG_INFO_1("CreditCardPreAuthCancel: SendRequest failed\n");
+		return -1;
+	}	
+}
+
+//==========================================
+// CreditCardPreAuthCancel
+// Input :
+//		PreCost : 預扣金額*100, e.g., $1234 = 123400, $1234.56=123456
+//		EVSEID: EVSE ID, max length is 18
+//		ApprovalNo: max length is 12
+//		CardNum :  max length is 20
+// Output :
+//==========================================
+int CreditCardUnionSettlement(int Fd,unsigned char *EVSEID,struct TransInfo *TransInfoReturn)
+{
+	unsigned char Buffer[RequestLength], *ptr, tmpbuf[12];
+	
+	memset(Buffer,0x20,RequestLength);
+	ptr=Buffer;
+	strncpy(ptr,HOST_ID_CreditCard,2);//Host ID
+	ptr+=2;
+	strncpy(ptr,TRANS_TYPE_UnionSettlement,2);//Transaction type
+	ptr+=2;
+	/*memset(tmpbuf,0,sizeof(tmpbuf));
+	sprintf(tmpbuf,"%d", PreCost);
+	if(strlen(tmpbuf)>12)
+	{
+		DEBUG_INFO_1("CreditCardPreAuthCancel: Wrong PreCost (PreCost=%d)\n", PreCost);
+		return -1;
+	}	
+	memset(ptr,0x30,12);
+	strncpy(ptr+12-(strlen(tmpbuf)+2),tmpbuf,strlen(tmpbuf));//Trans Amount
+	*/
+	ptr+=12;//Trans Amount
+	//strncpy(ptr,ApprovalNo, strlen(ApprovalNo));
+	ptr+=12;//Approval No
+	//strncpy(ptr,CardNum, strlen(CardNum));
+	ptr+=20;//Card No
+	strncpy(ptr,EVSEID, strlen(EVSEID));
+	ptr+=18;//Store Id	
+	//ptr+=2;//Period
+	if(SendRequest(Fd, Buffer, RequestLength)>0)
+	{
+		memset(Buffer,0,RequestLength);
+		if(RecvResponse(Fd,Buffer)>0)
+		{
+			strncpy(TransInfoReturn->TransAmount,Buffer+44,12);	
+			strncpy(TransInfoReturn->TransDate,Buffer+56,6);	
+			strncpy(TransInfoReturn->TransTime,Buffer+62,6);	
+			strncpy(TransInfoReturn->StoreId,Buffer+97,18);
+			strncpy(TransInfoReturn->ApprovalNo,Buffer+12,12);
+			strncpy(TransInfoReturn->RRN,Buffer+124,12);
+			strncpy(TransInfoReturn->CardNo,Buffer+24,20);
+			strncpy(TransInfoReturn->VemData,Buffer+246,64);
+			return 1;
+		}	
+		else
+		{
+			DEBUG_INFO_1("CreditCardUnionSettlement: RecvResponse failed\n");
+			return -1;
+		}	
+	}	
+	else
+	{
+		DEBUG_INFO_1("CreditCardUnionSettlement: SendRequest failed\n");
+		return -1;
+	}	
+}
+#if 0
+int InitComPort()
+{
+	int fd;
+	struct termios tios;
+
+	fd = open("/dev/ttyS2", O_RDWR);
+	if(fd<=0)
+	{
+		DEBUG_INFO_1("open /dev/ttyS2 NG\n");
+		return -1;
+	}
+
+	ioctl (fd, TCGETS, &tios);
+	tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
+	tios.c_lflag = 0;
+	tios.c_iflag = 0;
+	tios.c_oflag = 0;
+	tios.c_cc[VMIN]=0;
+	tios.c_cc[VTIME]=(unsigned char)5;		// timeout 500ms
+	tios.c_lflag=0;
+	tcflush(fd, TCIFLUSH);
+	ioctl (fd, TCSETS, &tios);
+
+	return fd;
+}
+
+int main(int argc, char *argv[])
+{
+	int UartFd;
+	struct TransInfo		ReturnTransInfo;
+	
+	
+	UartFd=InitComPort();
+	if(UartFd<0)
+	{	
+		printf("InitComPort NG\n");
+		return;
+	}
+
+	//sleep(3);
+	memset(&ReturnTransInfo,0,sizeof(struct TransInfo));
+	printf("CreditCardPreAuth......\n");
+	 if(CreditCardPreAuth(UartFd, 1000,"TCC EVSE", &ReturnTransInfo)<=0)
+	{
+		printf("CreditCardPreAuth NG\n");
+		return;
+	}	
+	printf("ApprovalNo=%s\n",ReturnTransInfo.ApprovalNo);
+	printf("RRN=%s\n",ReturnTransInfo.RRN);
+	printf("CardNum=%s\n",ReturnTransInfo.CardNo);
+	printf("VemData=%s\n",ReturnTransInfo.VemData);
+	
+	
+	
+	sleep(20);
+	if(CreditCardPreAuthCancel(UartFd, 1000,"TCC EVSE", &ReturnTransInfo.ApprovalNo, &ReturnTransInfo.CardNo,&ReturnTransInfo.VemData)<=0)
+	{
+		printf("CreditCardPreAuthCancel NG\n");
+		//return;
+	}	
+	/*
+	printf("CreditCardPreAuthComplete......\n");
+	 if(CreditCardPreAuthComplete(UartFd, 500,"TCC EVSE", &ReturnTransInfo.VemData, &ReturnTransInfo)<=0)
+	{
+		printf("CreditCardPreAuthComplete NG\n");
+		return;
+	}	
+	*/
+	
+	sleep(15);
+	if(CreditCardUnionSettlement(UartFd,"TCC EVSE",&ReturnTransInfo)<=0)
+	{
+		printf("CreditCardUnionSettlement NG\n");
+		//return;
+	}	
+
+	
+}
+#endif

+ 68 - 0
EVSE/Modularization/Module_Systex.h

@@ -0,0 +1,68 @@
+/*
+ * 	Module_RFID.h
+ *
+ *  Created on: 2019-10-24
+ *  Update: 2020-10-19
+ *  Author: Eason Yang
+ *	Version: V0.03
+ *
+ * History
+ * 1. Added : Reyax constant.
+ *
+ *
+ *
+ *
+ *
+ */
+ 
+#ifndef LIB_Systex_H_
+#define LIB_Systex_H_
+
+#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>	/* Standard input/output definitions */
+#include    <stdlib.h>
+#include    <unistd.h>	/* UNIX standard function definitions */
+#include    <fcntl.h>	/* File control definitions */
+#include    <termios.h>	/* POSIX terminal control definitions */
+#include    <errno.h>	/* Error number definitions */
+#include 	<string.h>	/* String function definitions */
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include	<stdbool.h>
+
+
+
+struct TransInfo
+{
+	unsigned char TransDate[6];	//交易日期
+	unsigned char TransTime[6];	//交易時間
+	unsigned char ApprovalNo[12];		//EDC簽單調閱編號或授權碼[信用卡退貨交易] (左靠右補空白)
+	unsigned char StoreId[18];		//櫃號,機號,發票號碼(左靠右補空白)
+	unsigned char RRN[12];		//信用卡交易序號
+	unsigned char CardNo[20];		//卡號(左靠右補空白),卡號部份隱藏
+	unsigned char TransAmount[12];		//交易金額
+	unsigned char VemData[64];		//無人自助設備交易資訊 交易別31/32 (預授權完成/預授權取消) 必要欄位 資訊來源為交易別13 (預授權)的回傳
+};
+
+int CreditCardPreAuth(int Fd, int PreCost,unsigned char *EVSEID, struct TransInfo *TransInfoReturn);
+int CreditCardPreAuthComplete(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *VemData,struct TransInfo *TransInfoReturn);
+int CreditCardPreAuthCancel(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *ApprovalNo, unsigned char *CardNum,unsigned char *VemData);
+int CreditCardUnionSettlement(int Fd,unsigned char *EVSEID,struct TransInfo *TransInfoReturn);
+#endif

+ 67 - 0
EVSE/Projects/DD360Tcci/Apps/CSU/Module_Systex.h

@@ -0,0 +1,67 @@
+/*
+ * 	Module_RFID.h
+ *
+ *  Created on: 2019-10-24
+ *  Update: 2020-10-19
+ *  Author: Eason Yang
+ *	Version: V0.03
+ *
+ * History
+ * 1. Added : Reyax constant.
+ *
+ *
+ *
+ *
+ *
+ */
+ 
+#ifndef LIB_Systex_H_
+#define LIB_Systex_H_
+
+#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>	/* Standard input/output definitions */
+#include    <stdlib.h>
+#include    <unistd.h>	/* UNIX standard function definitions */
+#include    <fcntl.h>	/* File control definitions */
+#include    <termios.h>	/* POSIX terminal control definitions */
+#include    <errno.h>	/* Error number definitions */
+#include 	<string.h>	/* String function definitions */
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include	<stdbool.h>
+
+
+
+struct TransInfo
+{
+	unsigned char TransDate[6];	//交易日期
+	unsigned char TransTime[6];	//交易時間
+	unsigned char ApprovalNo[12];		//EDC簽單調閱編號或授權碼[信用卡退貨交易] (左靠右補空白)
+	unsigned char StoreId[18];		//櫃號,機號,發票號碼(左靠右補空白)
+	unsigned char RRN[12];		//信用卡交易序號
+	unsigned char CardNo[20];		//卡號(左靠右補空白),卡號部份隱藏
+	unsigned char TransAmount[12];		//交易金額
+	unsigned char VemData[64];		//無人自助設備交易資訊 交易別31/32 (預授權完成/預授權取消) 必要欄位 資訊來源為交易別13 (預授權)的回傳
+};
+
+int CreditCardPreAuth(int Fd, int PreCost,unsigned char *EVSEID, struct TransInfo *TransInfoReturn);
+int CreditCardPreAuthComplete(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *VemData,struct TransInfo *TransInfoReturn);
+int CreditCardPreAuthCancel(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *ApprovalNo, unsigned char *CardNum);
+#endif

+ 108 - 19
EVSE/Projects/DD360Tcci/Apps/CSU/RFID.c

@@ -11,6 +11,9 @@
 
 #include "main.h"
 #include "../timeout.h"
+static DcCommonInfo *ShmDcCommonData = NULL;
+static struct SysInfoData *pSysInfo = NULL;
+#define PREAUTHMONEY 2000
 
 //------------------------------------------------------------------------------
 static char *rfidPortName = "/dev/ttyS2";
@@ -116,6 +119,7 @@ bool RfidStopCharging(void)
                      pSysConfig->UserId);
             return true;
         } else {
+        	strcpy((char *)pSysConfig->UserId, "");
             return false;
         }
     }
@@ -140,10 +144,11 @@ static void UserScanFunction(void)
     }
 
     //當前沒有選槍
+    /*
     if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL) {
         strcpy((char *)pSysConfig->UserId, "");
         return;
-    }
+    }*/
 
     // 先判斷現在是否可以提供刷卡
     // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
@@ -182,6 +187,7 @@ static void UserScanFunction(void)
     }
 
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+
     // Stop Charging For AC
     /*if (pGunIndexInfo->AcGunIndex > 0 &&
             stopReq == DEFAULT_AC_INDEX &&
@@ -228,18 +234,29 @@ static void UserScanFunction(void)
         } else if ((pGunIndexInfo->AcGunIndex > 0 &&
                     pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
                    pDcChargingInfo->SystemStatus == S_AUTHORIZING) {*/
-    if (pDcChargingInfo->SystemStatus == S_AUTHORIZING ) {
+    if (pSysInfo->SystemPage == _PAGE_AUTHORIZE && pDcChargingInfo->SystemStatus == S_IDLE) {
             log_info("// LCM => Authorizing");
-
+            confirmSelGun(pSysInfo->CurGunSelected);
             setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
+            StartSystemTimeoutDet(Timeout_Authorizing);
+            if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTH) {
+            	if (ShmDcCommonData->PreAuth_Result > 0) {
+            		pDcChargingInfo->SystemStatus = S_AUTHORIZING;
+            		AuthorizingStart();
+            		ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
+            	} else if (ShmDcCommonData->PreAuth_Result < 0) {
+            		pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
+            		ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
+            		ShmDcCommonData->PreAuth_Result = 0;
+            	}
+            }
 
             // LCM => Authorizing
-            pSysInfo->SystemPage = _PAGE_PLUGIN;
-
+            //pSysInfo->SystemPage = _PAGE_AUTHORIZE;
             // 進入確認卡號狀態
-            AuthorizingStart();
+
     } else {
-        strcpy((char *)pSysConfig->UserId, "");
+        //strcpy((char *)pSysConfig->UserId, "");
     }
 
     return;
@@ -259,24 +276,26 @@ void AuthorizeToCharge()
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
-    if(!isAuthorizedComplete())
-        StartSystemTimeoutDet(Timeout_Authorizing);
-    else {
-        //StopSystemTimeoutDet();
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+    if(isAuthorizedComplete())
+    {
+       // StopSystemTimeoutDet();
         StartSystemTimeoutDet(Timeout_WaitBalance);
         if (ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance != FAIL_BALANCE_PRICES) {
             StopSystemTimeoutDet();
             // 判斷後台回覆狀態
             if (canStartCharging()) {
             // LCM => Authorize complete
+            	pDcChargingInfo->SystemStatus = S_AUTHORIZING;
                 pSysInfo->SystemPage = _PAGE_PLUGIN;
                 log_info("Wait Gun(%d) plugin",pSysInfo->CurGunSelected);
                 DetectPluginStart();
                 log_info("Gun(%d) Balance: %f",pSysInfo->CurGunSelected,
                         ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
             } else {
-                // LCM => Authorize fail
-                pSysInfo->SystemPage = _PAGE_PAY_FAIL;
+                log_info("LCM => Authorize fail");
+                //pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
                 strcpy((char *)pSysConfig->UserId, "");
             }
         }
@@ -288,21 +307,25 @@ void ScannerCardProcess(void)
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
 
-    if (!isDetectPlugin() && pSysInfo->SystemPage == _PAGE_PLUGIN &&
+    if (!isDetectPlugin() && pSysInfo->SystemPage == _PAGE_AUTHORIZE &&
+    		pDcChargingInfo->SystemStatus == S_IDLE &&
             pSysWarning->Level != WARN_LV_ER /*&&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE*/) {
+    	//setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
         isCardScan = true;
         // 處理刷卡及驗證卡號的動作
         UserScanFunction();
     }
 
-    /*if (pSysInfo->SystemPage == _PAGE_PLUGIN) {
+    if (pDcChargingInfo->SystemStatus == S_AUTHORIZING && pSysInfo->SystemPage == _PAGE_AUTHORIZE ) {
         AuthorizeToCharge();
-    } else if (pSysInfo->SystemPage == _PAGE_PLUGIN) {
+    } else if (pSysInfo->SystemPage == _PAGE_AUTHORIZE_FAIL) {
         StartSystemTimeoutDet(Timeout_VerifyFail);
         isCardScan = false;
-    } else */if (pSysInfo->SystemPage == _PAGE_PLUGIN) {
+    } else if ( pSysInfo->SystemPage == _PAGE_PLUGIN) {
         StartSystemTimeoutDet(Timeout_WaitPlug);
     } else {
         isCardScan = false;
@@ -342,17 +365,82 @@ void CreateRfidFork(void)
 
     rfidRecPid = fork();
     if (rfidRecPid == 0) {
+        char localTime[128] = {0};
+        struct timeb SeqEndTime;
+        struct tm *tm;
+        pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
         int fd = -1;
         int isContinue = 1;
         RFID rfid = {0};
         fd = InitialRfidPort();
         struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+        ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
 
         //log_info("RFID fork Child's PID is %d", getpid());
-
+        int result = 0;
         while (isContinue) {
             usleep(500000);
-
+            ftime(&SeqEndTime);
+            SeqEndTime.time = time(NULL);
+            tm = localtime(&SeqEndTime.time);
+
+            if (tm->tm_hour == 23 && tm->tm_min == 00 && result == 0) {
+				result = CreditCardUnionSettlement(fd,"TCC Test",&ShmDcCommonData->pCreditCard[0]);
+				if (result > 0) {
+					log_info("CreditCardUnionSettlement OK");
+					log_info("Get Money:%s",ShmDcCommonData->pCreditCard[0].TransAmount);
+				} else
+					log_info("CreditCardUnionSettlement FAIL");
+			}
+            if (ShmDcCommonData->PreAuth_Result != 0 && ShmDcCommonData->PreAuth_Config != _CREDITCARD_IDLE)
+            	continue;
+
+            switch(ShmDcCommonData->PreAuth_Config) {
+            case _CREDITCARD_IDLE:
+            	ShmDcCommonData->PreAuth_Result = 0;
+            	break;
+            case _CREDITCARD_PREAUTH:
+				ShmDcCommonData->PreAuth_Result = CreditCardPreAuth(fd, PREAUTHMONEY,"TCC Test", &ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
+				ShmDcCommonData->PreAuth_Result = 1;
+				if (ShmDcCommonData->PreAuth_Result > 0 ) {
+					//strncpy((char *)pSysConfig->UserId, (char *)ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo,20);
+					strcpy((char *)pSysConfig->UserId,"Ph Test");
+					log_info("Credit Card Pass card number:%s",ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo);
+
+				} else if (ShmDcCommonData->PreAuth_Result < 0) {
+					log_info("Credit Card Fail");
+					pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
+				}
+
+            	break;
+            case _CREDITCARD_PREAUTHCOMPLETE:
+            	ShmDcCommonData->PreAuth_Result = CreditCardPreAuthComplete(fd, ShmDcCommonData->finalcost[pSysInfo->CurGunSelected] ,"TCC Test",
+            	            			&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].VemData[0],
+            							&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
+            	if (ShmDcCommonData->PreAuth_Result > 0 ) {
+            		log_info("Credit Card Spend Money:%d",ShmDcCommonData->finalcost[pSysInfo->CurGunSelected]);
+            	} else {
+            		log_info("PAYING FAIL");
+            	}
+            	pSysInfo->SystemPage = _PAGE_COMPLETE;
+            	break;
+            case _CREDITCARD_CANCEL:
+            	ShmDcCommonData->PreAuth_Result = CreditCardPreAuthCancel(fd,PREAUTHMONEY,"TCC Test",
+					&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].ApprovalNo[0],
+					&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo[0],
+					&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].VemData[0]);
+
+				if (ShmDcCommonData->PreAuth_Result > 0 ) {
+					strcpy((char *)pSysConfig->UserId,"");
+					log_info("Card Reader Stop");
+
+				} else if (ShmDcCommonData->PreAuth_Result < 0) {
+					log_info("Car Reader Stop Fail");
+				}
+
+            	break;
+            }
+            /*
             // 刷卡判斷
             if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
                     !pSysConfig->isRFID) {
@@ -436,6 +524,7 @@ void CreateRfidFork(void)
                 }
             }
             log_info("card number = %s", pSysConfig->UserId);
+            */
         }
     }
 }

+ 121 - 78
EVSE/Projects/DD360Tcci/Apps/CSU/main.c

@@ -148,7 +148,7 @@ static uint8_t getCurLcmPage(void)
 
 static void systemPageRestoreInit(void)
 {
-    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
+    pSysInfo->SystemPage = _PAGE_IDLE;
 }
 
 //------------------------------------------------------------------------------
@@ -178,7 +178,7 @@ void destroySelGun(uint8_t curGun)
     if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
         if (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
                 ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
-            changeLcmPage(_PAGE_AUTHORIZE);
+            changeLcmPage(_PAGE_SELECT_GUN);
         }
         ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
         StopGunInfoTimeoutDet(LEFT_GUN_NUM);
@@ -197,7 +197,7 @@ void destroySelGun(uint8_t curGun)
     if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
         if (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
                 ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
-            changeLcmPage(_PAGE_AUTHORIZE);
+            changeLcmPage(_PAGE_SELECT_GUN);
         }
         ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
         StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
@@ -266,10 +266,10 @@ void confirmSelGun(uint8_t selGun)
         ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
         //printf("confirmSelGun right");
     }
-    changeLcmPage(_PAGE_PLUGIN);
+    //changeLcmPage(_PAGE_PLUGIN);
 
     //StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
-    StartSystemTimeoutDet(Timeout_ReturnViewPage);
+    //StartSystemTimeoutDet(Timeout_ReturnViewPage);
 }
 
 static void GetFirmwareVersion(void)
@@ -1496,23 +1496,25 @@ void _AuthorizedTimeout(void)
         //isCardScan = false;
         SetIsCardScan(false);
 
-        pSysInfo->SystemPage = _PAGE_AUTHORIZE;
+        pSysInfo->SystemPage = _PAGE_SELECT_GUN;
         //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
         strcpy((char *)pSysConfig->UserId, "");
         ClearAuthorizedFlag();
-        StartSystemTimeoutDet(Timeout_ReturnViewPage);
+     //   StartSystemTimeoutDet(Timeout_ReturnViewPage);
     //}
 }
 
-void _DetectPlugInTimeout(void)
+void _DetectPlugInTimeout(uint8_t gunIndex)
 {
     log_info("*********** _DetectPlugInTimeout *********** ");
     strcpy((char *)pSysConfig->UserId, "");
-    StopSystemTimeoutDet();
-    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
-    StartSystemTimeoutDet(Timeout_ReturnViewPage);
+    //StopSystemTimeoutDet();
+    StopGunInfoTimeoutDet(gunIndex);
+    if (pSysInfo->CurGunSelected == gunIndex)
+    	pSysInfo->SystemPage = _PAGE_IDLE;
     ClearDetectPluginFlag();
-	//setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
+    strcpy((char *)pSysConfig->UserId, "");
+	setChargerMode(gunIndex, S_IDLE);
     //systemPageRestoreInit();
 }
 
@@ -1571,7 +1573,7 @@ void _LinkErrorTimeout(uint8_t gunIndex)
 {
 	log_info("*********** _LinkErrorTimeout ***********");
 	setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
-	pSysInfo->SystemPage = _PAGE_AUTHORIZE;
+	pSysInfo->SystemPage = _PAGE_SELECT_GUN;
 }
 
 //===============================================
@@ -2481,21 +2483,17 @@ void CreateTimeoutFork(void)
             case Timeout_ReturnViewPage:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_VIEWPAGE_TIMEOUT) {
                     StopSystemTimeoutDet();
-                    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-                    if (pDcChargingInfo->SystemStatus == S_AUTHORIZING || pDcChargingInfo->SystemStatus == S_COMPLETE )
-                        setChargerMode(pSysInfo->CurGunSelected, MODE_IDLE);
+                    pSysInfo->SystemPage = _PAGE_IDLE;
                 }
             	break;
             case Timeout_Authorizing:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
-                    log_error("Authorizing Timeout");
+                    //log_error("Authorizing Timeout");
                     _AuthorizedTimeout();
                     if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
                         ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
                         pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
                         log_error("Author timeout restart DoComm");
-                        system("killall Module_DoComm");
                     }
                 }
                 break;
@@ -2512,9 +2510,9 @@ void CreateTimeoutFork(void)
                 }
                 break;
             case Timeout_VerifyFail:
-                /*
+
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
-                    if (pSysInfo->SystemPage ==_LCM_START_AUTHORIZE_FAIL ) {
+                    /*if (pSysInfo->SystemPage ==_LCM_START_AUTHORIZE_FAIL ) {
                         StopSystemTimeoutDet();
                         _AutoReturnTimeout();
                         //destroySelGun(pSysInfo->CurGunSelected);
@@ -2527,20 +2525,22 @@ void CreateTimeoutFork(void)
                             //sleep(1);
                             //system("/root/Module_DoComm &");
                         }
-                    } else if (pSysInfo->SystemPage ==_LCM_STOP_RFID_FAIL ) {
+                    } else*/ if (pSysInfo->SystemPage ==_PAGE_AUTHORIZE_FAIL ) {
                         StopSystemTimeoutDet();
-                        pSysInfo->SystemPage = _LCM_VIEW;
+                        pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+                        setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
                     }
-                }*/
+                }
                 break;
-
+                /*
             case Timeout_WaitPlug:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
                     _DetectPlugInTimeout();
 
-                    //destroySelGun(pSysInfo->CurGunSelected);
+                    destroySelGun(pSysInfo->CurGunSelected);
                 }
                 break;
+                */
 /*
             case Timeout_ReturnToChargingGunDet:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
@@ -2554,11 +2554,13 @@ void CreateTimeoutFork(void)
                 }
                 break;
 */
+
             case Timeout_AuthorizingForStop:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
                     strcpy((char *)pSysConfig->UserId, "");
                     ClearAuthorizedFlag();
                     StopSystemTimeoutDet();
+                    pSysInfo->SystemPage = _PAGE_SELECT_GUN;
                 }
                 break;
             case Timeout_Terminating:
@@ -2580,6 +2582,12 @@ void CreateTimeoutFork(void)
                         GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL);
                         */
                 switch (pDcChargingInfo->TimeoutFlag) {
+                case Timeout_WaitPlug:
+                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
+                        _DetectPlugInTimeout(gunIndex);
+                        destroySelGun(gunIndex);
+                    }
+                    break;
                 case Timeout_EVCCID_Link:
                 if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= EVCCID_LINK_TIMEOUT) {
                     _evccidlinktimeout(gunIndex);
@@ -2634,6 +2642,7 @@ void CreateTimeoutFork(void)
                     if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= PLUGOUTGUN_TIMEOUT) {
                         setChargerMode(gunIndex, MODE_IDLE);
                         destroySelGun(gunIndex); //Jerry add
+                        StopGunInfoTimeoutDet(gunIndex);
                         systemPageRestoreInit();
                     }
                     break;
@@ -2854,7 +2863,7 @@ void OcppRemoteStartChk()
                 isGunUsingStatus = true;
             }
             if (pDcChargingInfo->RemoteStartFlag == YES) {
-            	_remotestarting = true;
+            	//_remotestarting = true;
             }
         }
 
@@ -3772,6 +3781,7 @@ void ResetIdleData(uint8_t gunIndex)
     pDcChargingInfo->PresentChargingVoltage = 0;//DS60-120 add
     pDcChargingInfo->PresentChargingCurrent = 0;//DS60-120 add
     pDcChargingInfo->RemoteStartFlag = NO;
+    pDcChargingInfo->Replug_flag = FALSE;
     strcpy((char *)pDcChargingInfo->StartDateTime, "");
     strcpy((char *)pDcChargingInfo->StopDateTime, "");
     strcpy((char *)pDcChargingInfo->StartUserId, "");
@@ -3780,6 +3790,8 @@ void ResetIdleData(uint8_t gunIndex)
     ClearDetectPluginFlag();
     //Jerry add
     memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
+    memset(&ShmDcCommonData->pCreditCard[gunIndex], 0, sizeof(TransInfo));
+
     ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
     destroySelGun(gunIndex);
     ResetDetAlarmStatus(gunIndex); //recovery OVP status code
@@ -3788,7 +3800,8 @@ void ResetIdleData(uint8_t gunIndex)
     }
     //strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
     ReleaseAlarmCode(gunIndex);
-    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
+    if (pSysInfo->SystemPage != _PAGE_SELECT_GUN)
+    	pSysInfo->SystemPage = _PAGE_IDLE;
 }
 void CheckErrorCode(uint8_t gunIndex)
 {
@@ -3821,6 +3834,8 @@ void AuthorizeStopCharging(uint8_t gunIndex)
 
     checkOCPPReqStop(gunIndex);
 
+    //RfidStopCharging();
+
 }
 void showversion()
 {
@@ -3960,7 +3975,7 @@ int main(void)
     }
     log_info("===== Create DB End ===== ");
 
-    ChangeLcmByIndex(_PAGE_AUTHORIZE);
+    ChangeLcmByIndex(_PAGE_SELECT_GUN);
 
     sleep(1);
     //***** 須新增的偵測 *****//
@@ -4067,15 +4082,19 @@ int main(void)
                 }
                 isChargingAverageState();
                 // For RemoteStart Using
+
                 if (pDcChargingInfo->RemoteStartFlag == YES && pDcChargingInfo->IsAvailable) {
 					log_info("-------- IDLE Remote Start(%d) --------", gunIndex);
 					ChangeGunSelectByIndex(gunIndex);
 					setChargerMode(gunIndex, MODE_AUTHORIZING);
 					break;
                 }
-                if (pSysInfo->CurGunSelected == gunIndex) {
-                    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
-                }
+
+                // 讀卡邏輯
+                //ScannerCardProcess();
+                if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_IDLE) {
+                	StartSystemTimeoutDet(Timeout_ReturnViewPage);
+				}
                 goto CheckStatus;
                 break;
             case S_RESERVATION:
@@ -4104,6 +4123,7 @@ CheckStatus:
                 // Refresh Error Status
                 if (pSysWarning->Level == WARN_LV_ER) {
                     CheckErrorCode(gunIndex);
+                    pSysInfo->SystemPage = _PAGE_MAINTAIN;
                     if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton)
                         pSysInfo->SystemPage = _PAGE_ERROR;
                     continue;
@@ -4121,17 +4141,28 @@ CheckStatus:
                     systemPageRestoreInit();
                     setChargerMode(gunIndex, MODE_IDLE);
                 }
+                if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_SELECT_GUN) {
+					pSysInfo->SystemPage = _PAGE_IDLE;
+				}
                 break;
 
             case S_AUTHORIZING:
                 if (isModeChange(gunIndex)) {
                     log_info("============================= S_AUTHORIZING(%x) ============================= ", gunIndex);
+                    StartSystemTimeoutDet(Timeout_AuthorizingForStop);
+                    pDcChargingInfo->Replug_flag = TRUE;
                 }
-                // 讀卡邏輯
-                ScannerCardProcess();
+
+				ScannerCardProcess();
                 // 隨插即充
                 //autoStartCharging(gunIndex);
-
+                if (pSysInfo->SystemPage == _PAGE_PLUGIN) {
+                	StopSystemTimeoutDet();
+                	StartGunInfoTimeoutDet(gunIndex,Timeout_WaitPlug);
+                }
+                if (pSysInfo->SystemPage == _PAGE_PLUGOUT) {
+                	StartSystemTimeoutDet(Timeout_VerifyFail);
+                }
                 if (isDetectPlugin()) {
                     // 卡號驗證成功後,等待充電槍插入充電車
                     if (pDcChargingInfo->RemoteStartFlag == YES) {
@@ -4171,7 +4202,8 @@ CheckStatus:
                         }
                     }
 
-                    if (!GetIsCardScan() && pSysInfo->CurGunSelected == gunIndex) {
+                    if (!GetIsCardScan() && pSysInfo->CurGunSelected == gunIndex &&
+                    		pSysInfo->SystemPage != _PAGE_AUTHORIZE_FAIL) {
                         pSysInfo->SystemPage = _PAGE_PLUGIN;
                     }
                 }
@@ -4183,11 +4215,13 @@ CheckStatus:
                     if (pSysInfo->OrderCharging != NO_DEFINE) {
                         pSysInfo->OrderCharging = NO_DEFINE;
                         pDcChargingInfo->_SaftyDetect = FALSE;
-                        pDcChargingInfo->Replug_flag = TRUE;
+
                     }
                     StopSystemTimeoutDet();
+                    StopGunInfoTimeoutDet(gunIndex);
                     gettimeofday(&pDcChargingInfo->PreChargeTimer, NULL);
                 }
+
                 setChargerMode(gunIndex, S_PREPARNING);
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->SystemPage = _PAGE_PRECHARGE;
@@ -4356,46 +4390,15 @@ CheckStatus:
 
                 // Check Stop Charging
                 AuthorizeStopCharging(gunIndex);
-
+                if (pSysInfo->SystemPage == _PAGE_STOP_CONFIRM_LEFT ||
+                		pSysInfo->SystemPage == _PAGE_STOP_CONFIRM_RIGHT)
+                	break;
                 // LCM => Charging
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->SystemPage = _PAGE_CHARGING;
                 }
                 break;
 
-            case S_ALARM:
-                if (isModeChange(gunIndex)) {
-                    log_info("============================= S_ALARM(%x)  ============================= ", gunIndex);
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
-                          strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
-                    }
-                    UpdateErrorCodeToOcpp(gunIndex);
-                    if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
-                      OcppStopTransation(gunIndex);
-                    }
-                    TheEndCharging(gunIndex);
-                    StopGunInfoTimeoutDet(gunIndex);
-                }
-
-                if (pSysWarning->Level == WARN_LV_ER) {
-                    pSysInfo->SystemPage = _PAGE_MAINTAIN;
-                    if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton)
-                        pSysInfo->SystemPage = _PAGE_ERROR;
-                    continue;
-                }
-                if (pDcChargingInfo->Replug_flag == TRUE) {
-                	setChargerMode(gunIndex, MODE_IDLE);
-                	pSysInfo->SystemPage = _PAGE_PLUGOUT;
-                }
-                if (pDcChargingInfo->ConnectorPlugIn == NO ) {
-                	pSysInfo->SystemPage = _PAGE_PLUGOUT;
-                    StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
-                }
-                if (pSysInfo->CurGunSelected == gunIndex) {
-                    pSysInfo->SystemPage = _PAGE_COMPLETE;
-                }
-                break;
-
             case S_TERMINATING:
                 if (isModeChange(gunIndex)) {
                     log_info("============================= S_TERMINATING(%x) ============================= ", gunIndex);
@@ -4432,7 +4435,7 @@ CheckStatus:
                 if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
 					break;
                 }
-                if (pSysInfo->CurGunSelected == gunIndex) {
+                if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_PAYING) {
                     pSysInfo->SystemPage = _PAGE_COMPLETE;
                 }
                 break;
@@ -4445,7 +4448,6 @@ CheckStatus:
                     }
                     TheEndCharging(gunIndex);
                     StopSystemTimeoutDet();
-                    pSysInfo->SystemPage = _PAGE_COMPLETE;
                 }
 
                 //if (pSysInfo->SystemPage == _LCM_ERROR) {
@@ -4455,18 +4457,59 @@ CheckStatus:
 
                 if (pDcChargingInfo->ConnectorPlugIn == NO ) {
                     StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
-                    pSysInfo->SystemPage = _PAGE_EXIT;
+                    if (pSysInfo->CurGunSelected == gunIndex) {
+                    	pSysInfo->SystemPage = _PAGE_EXIT;
+                    	break;
+                    }
                 }
 
                 if (pSysInfo->CurGunSelected == gunIndex) {
-                    if (pDcChargingInfo->Replug_flag == TRUE)
-    					pSysInfo->SystemPage = _PAGE_PLUGOUT;
-    				 else
-    					pSysInfo->SystemPage = _PAGE_COMPLETE;
+					pSysInfo->SystemPage = _PAGE_COMPLETE;
                 }
 
                 break;
 
+            case S_ALARM:
+                if (isModeChange(gunIndex)) {
+                    log_info("============================= S_ALARM(%x)  ============================= ", gunIndex);
+                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
+                          strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
+                    }
+                    UpdateErrorCodeToOcpp(gunIndex);
+                    if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
+                      OcppStopTransation(gunIndex);
+                    }
+                    TheEndCharging(gunIndex);
+                    StopGunInfoTimeoutDet(gunIndex);
+                }
+
+                if (pSysWarning->Level == WARN_LV_ER) {
+					pSysInfo->SystemPage = _PAGE_MAINTAIN;
+					if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton)
+						pSysInfo->SystemPage = _PAGE_ERROR;
+					continue;
+				}
+                if (pDcChargingInfo->ConnectorPlugIn == NO ) {
+					if (pDcChargingInfo->Replug_flag == TRUE) {
+						pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+						pDcChargingInfo->SystemStatus = S_IDLE;
+					}
+					else {
+						StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
+						pSysInfo->SystemPage = _PAGE_EXIT;
+					}
+					break;
+				}
+                if (pSysInfo->SystemPage == _PAGE_PAYING)
+                	break;
+
+                if (pSysInfo->CurGunSelected == gunIndex) {
+                	if (pDcChargingInfo->Replug_flag == TRUE)
+                		pSysInfo->SystemPage = _PAGE_PLUGOUT;
+                	else
+                		pSysInfo->SystemPage = _PAGE_COMPLETE;
+				}
+                break;
             case S_MAINTAIN:
                 if (isModeChange(gunIndex)) {
                     log_info("============================= S_MAINTAIN(%x) ============================= ", gunIndex);

+ 3 - 3
EVSE/Projects/DD360Tcci/Apps/CSU/main.h

@@ -27,10 +27,10 @@
 
 #define uSEC_VAL                                (1000000)
 #define SELFTEST_TIMEOUT                        (60)//45
-#define RETURN_VIEWPAGE_TIMEOUT                 (120)
+#define RETURN_VIEWPAGE_TIMEOUT                 (30)
 #define AUTHORIZE_TIMEOUT                       (30)//30
 #define BALANCE_TIMEOUT                         (15)//15
-#define AUTHORIZE_FAIL_TIMEOUT                  (120)
+#define AUTHORIZE_FAIL_TIMEOUT                  (5)
 #define AUTHORIZE_STOP_TIMEOUT                  (30)
 #define LINKERROR_TIMEOUT						(120)
 #define RETURN_TO_CHARGING_PAGE                 (30)
@@ -66,7 +66,7 @@
 
 //------------------------------------------------------------------------------
 bool isDetectPlugin(void);
-void _DetectPlugInTimeout(void);
+void _DetectPlugInTimeout(uint8_t gunIndex);
 void _evccidlinktimeout(uint8_t gunIndex);
 void StartSystemTimeoutDet(uint8_t flag);
 void StopSystemTimeoutDet(void);

+ 43 - 1
EVSE/Projects/DD360Tcci/Apps/Config.h

@@ -144,6 +144,7 @@ enum _CCS_GUN_TYPE {
 };
 
 enum _PAGE_TCC_INDEX {
+	// Face 1
     _PAGE_NONE                   = 0x00,
     _PAGE_IDLE,
     _PAGE_AUTHORIZE,
@@ -153,6 +154,13 @@ enum _PAGE_TCC_INDEX {
     _PAGE_COMPLETE,
 	_PAGE_PLUGOUT,
 	_PAGE_EXIT,
+	_PAGE_AUTHORIZE_FAIL,
+	_PAGE_SELECT_GUN,
+	_PAGE_PAYING,
+	_PAGE_STOP_CONFIRM_LEFT = 13,
+	_PAGE_STOP_CONFIRM_RIGHT,
+	_PAGE_SENSING,
+	// Face 2
     _PAGE_FUNCTION_SELECT,
     _PAGE_REFUND_SENSEING,
     _PAGE_REFUNDING,
@@ -286,7 +294,22 @@ enum _CCS_TYPE {
     _CCS_TYPE_CCS1 = 0,
     _CCS_TYPE_CCS2 = 1,
 };
-
+enum _WEATHER_TYPE {
+	_WEATHER_TYPE_SUN = 1,
+	_WEATHER_TYPE_CLOUDY,
+	_WEATHER_TYPE_RAIN,
+	_WEATHER_TYPE_THUNDER,
+	_WEATHER_TYPE_SNOW,
+	_WEATHER_TYPE_FOG,
+};
+enum _CREDITCARD_STATUS {
+	_CREDITCARD_IDLE,
+	_CREDITCARD_PREAUTH,
+	_CREDITCARD_PREAUTHCOMPLETE,
+	_CREDITCARD_CANCEL,
+	_CREDITCARD_SETTLEMENT,
+	_CREDITCARD_START,
+};
 //------------------------------------------------------------------------------
 //struct StructMeter {
 //    float curMeterValue;
@@ -394,6 +417,18 @@ enum _LCM_UPGRADE_RESULT {
     _LCM_UPGRADE_RESULT_FAIL,
 };
 
+typedef struct stTransInfo
+{
+	unsigned char TransDate[6];	//交易日期
+	unsigned char TransTime[6];	//交易時間
+	unsigned char ApprovalNo[12];		//EDC簽單調閱編號或授權碼[信用卡退貨交易] (左靠右補空白)
+	unsigned char StoreId[18];		//櫃號,機號,發票號碼(左靠右補空白)
+	unsigned char RRN[12];		//信用卡交易序號
+	unsigned char CardNo[20];		//卡號(左靠右補空白),卡號部份隱藏
+	unsigned char TransAmount[12];		//交易金額
+	unsigned char VemData[64];		//無人自助設備交易資訊 交易別31/32 (預授權完成/預授權取消) 必要欄位 資訊來源為交易別13 (預授權)的回傳
+}TransInfo;
+
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
     uint8_t CcsVersion;
@@ -437,6 +472,13 @@ typedef struct StDcCommonInfo {
     int                 PaymentFailId;
     unsigned char       PaymentFailString[32];
 
+    int WeatherID;
+    float Temperature;
+    char PresentTime[128];
+    TransInfo pCreditCard[2];
+    int finalcost[2];
+    int PreAuth_Config;
+    int PreAuth_Result;
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 1 - 1
EVSE/Projects/DD360Tcci/Apps/Define/define.c

@@ -5,7 +5,7 @@
 #include "define.h"
 
 //------------------------------------------------------------------------------
-char Currency[54][3]=
+char Currency[54][4]=
 {
 "AED", // - Emirati Dirham
 "ARS", // - Argentine Peso

+ 10 - 6
EVSE/Projects/DD360Tcci/Apps/Makefile

@@ -62,6 +62,10 @@ RatedCurrent_H = -include$(ModularizationPath)/Module_RatedCurrent.h
 InfypwrPsuComm_H = -include$(ModularizationPath)/Infypwr_PsuCommObj.h
 InfypwrPsuComm_A = $(ModularizationPath)/libInfypwr_PsuCommObj.a
 
+Lib_Module_Systex = "-L$(ModularizationPath)" -lModule_Systex
+Module_Systex_H = -include$(ModularizationPath)/Module_Systex.h
+
+
 #common lib
 COMMON_OBJ_FILES = common.o \
 					$(DefineLib)/define.o \
@@ -124,7 +128,7 @@ EVENTLOG_SRC_FILES = $(patsubst %.o, %.c, $(EVENTLOG_OBJ_FILES))
 	$(CC) $(CFLAGS) -c $<
 
 #LCM Control
-LCM_OBJ_FILES = $(COMMON_OBJ_FILES) $(LcmLib)/Module_LcmControl.o \
+LCM_OBJ_FILES = $(COMMON_OBJ_FILES) $(Module_Systex_H) $(LcmLib)/Module_LcmControl.o \
 				$(LcmLib)/Lcm_Update.o $(LcmLib)/cbmp.o
 LCM_SRC_FILES = $(patsubst %.o, %.c, $(LCM_OBJ_FILES))
 %.o: %.c
@@ -153,11 +157,11 @@ apps: MainTask DoCommTask EvCommTask UpdateFWTask ChkSysTask \
 MainTask:
 	$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(ModuleUpgrade_H) $(RateCurrent_H) \
 		$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) \
-		$(CheckSystemTask_H) -o main
-	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
+		$(CheckSystemTask_H) $(Module_Systex_H) $(Lib_Module_Systex) -o main
+	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(Module_Systex_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
 	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o timeout.o timeout.c
 	#$(CC) $(DEFINE) $(CFLAGS) -c -o common.o common.c
-	#$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
+	#$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent) $(Lib_Module_Systex)
 
 DoCommTask:
 	$(CC) $(DEFINE) $(DOCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_DoComm
@@ -198,10 +202,10 @@ InternalCommTask:
 	#$(CC) $(TFLAGS) -o Module_InternalComm Module_InternalComm.o internalComm.o $(Lib_ModuleRelay)
 
 LcmControlTask:
-	$(CC) $(DEFINE) $(LCM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_LcmControl
+	$(CC) $(DEFINE) $(LCM_SRC_FILES)  $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_LcmControl
 	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
 	#$(CC) $(DEFINE) $(CFLAGS) -c -o Module_LcmControl.o $(LcmLib)/Module_LcmControl.c
-	#$(CC) -o Module_LcmControl Module_LcmControl.o define.o
+	#$(CC) -o Module_LcmControl Module_LcmControl.o define.o 
 
 PrimaryCommTask:
 	$(CC) $(DEFINE) $(PRIMARY_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_PrimaryComm

+ 2 - 12
EVSE/Projects/DD360Tcci/Apps/ModuleChkSysTask/Module_ChkSysTask.h

@@ -47,7 +47,7 @@
 #define _SYSTEM_TASK_LOST_ITEM_UPDATEFW     9
 
 ///*
-#define _SYSTEM_TASK_COUNT_MAIN             5 
+#define _SYSTEM_TASK_COUNT_MAIN             5
 #define _SYSTEM_TASK_COUNT_EVCOMM           2
 #define _SYSTEM_TASK_COUNT_INTERNALCOMM     2
 #define _SYSTEM_TASK_COUNT_EVENTLOGGING     1
@@ -57,17 +57,7 @@
 #define _SYSTEM_TASK_COUNT_PRODUCEUTILS     1
 #define _SYSTEM_TASK_COUNT_UPDATEFW         1
 //*/
-/*
-#define _SYSTEM_TASK_COUNT_MAIN             3 
-#define _SYSTEM_TASK_COUNT_EVCOMM           0
-#define _SYSTEM_TASK_COUNT_INTERNALCOMM     0
-#define _SYSTEM_TASK_COUNT_EVENTLOGGING     0
-#define _SYSTEM_TASK_COUNT_PRIMARYCOMM      0
-#define _SYSTEM_TASK_COUNT_LCM              0
-#define _SYSTEM_TASK_COUNT_DOCOMM           0
-#define _SYSTEM_TASK_COUNT_PRODUCEUTILS     0
-#define _SYSTEM_TASK_COUNT_UPDATEFW         0
-*/
+
 unsigned char CheckSystemTask(unsigned char systemPage);
 
 #endif /* CHECKSYSTEMTASK_H_ */

+ 157 - 340
EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.c

@@ -31,6 +31,7 @@
 
 //------------------------------------------------------------------------------
 static DoCommGblData gDoCommGblData             = {0};
+static MoreInfoReq gMoreInfoReq                 = {0};
 
 static struct SysConfigData *pSysConfig         = NULL;
 static struct SysInfoData *pSysInfo             = NULL;
@@ -49,7 +50,7 @@ static struct WARNING_CODE_INFO gPreSysWarningInfo = {0};
 
 // Hexdump
 char old_Hexdump[10240];
-uint8_t psu_num= 0;
+
 //------------------------------------------------------------------------------
 static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
@@ -443,6 +444,8 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
                       tm->tm_hour,
                       tm->tm_min);
 
+
+
     //copy QR code string
     if (strncmp((char *)localTime, (char *)&data[0], timeLen - 2) != 0) {
         memset(pSysConfig->SystemId, '\0', sizeof(pSysConfig->SystemId));
@@ -451,6 +454,10 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
         string2ByteArray((char *)data, (uint8_t *)pSysConfig->SystemId);
         //printf("SystemId =  %s", pSysConfig->SystemId);
     }
+    sprintf(ShmDcCommonData->PresentTime, "%04d/%02d/%02d",
+                      tm->tm_year + 1900,
+                      tm->tm_mon + 1,
+                      tm->tm_mday);
 
     //if ((char *)&data[len] == '\0') {
     //    log_error("power cabinet system date error");
@@ -673,6 +680,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
             log_info("Remote start charging plugNum = %d", plugNum);
 
+#if defined DD360Audi
             if (getSelGunWaitToAuthor(plugNum) == FAIL) {
                 log_error("Remote start gun already charging");
                 break;
@@ -686,7 +694,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     strcpy((char *)pSysConfig->UserId, "");
                     pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
-                    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
+                    pSysInfo->SystemPage = _LCM_SELECT_GUN;
                     GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                     pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
@@ -698,15 +706,18 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     strcpy((char *)pSysConfig->UserId, "");
                     pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
-                    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
+                    pSysInfo->SystemPage = _LCM_SELECT_GUN;
                     GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                     pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
-                //pSysInfo->CurGunSelected = (plugNum);
+                pSysInfo->CurGunSelected = (plugNum);
                 pSysInfo->CurGunSelectedByAc = NO_DEFINE;
             }
-
+#else
+            pSysInfo->CurGunSelected = (plugNum);
+            pSysInfo->CurGunSelectedByAc = NO_DEFINE;
+#endif //DD360Audi
             setConfirmSelGun(pSysInfo->CurGunSelected);
 
             ShmOCPP16Data->CsMsg.bits[plugNum].RemoteStartTransactionReq = YES;
@@ -724,7 +735,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
             strcpy((char *)pSysConfig->UserId, "");
             pSysInfo->WaitForPlugit = NO;
-            pSysInfo->SystemPage = _PAGE_COMPLETE;
+            //pSysInfo->SystemPage = _LCM_SELECT_GUN;
             GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
             pSysInfo->SystemTimeoutFlag = Timeout_None;
             destroySelectGun(plugNum);
@@ -744,7 +755,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 ClearDetectPluginFlag();
                 strcpy((char *)pSysConfig->UserId, "");
                 pSysInfo->WaitForPlugit = NO;
-                pSysInfo->SystemPage = _PAGE_COMPLETE;
+                //pSysInfo->SystemPage = _LCM_SELECT_GUN;
                 GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                 pSysInfo->SystemTimeoutFlag = Timeout_None;
                 destroySelectGun(plugNum);
@@ -764,16 +775,16 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             log_info("Authorize By EVCCID:%d",pSysConfig->isAuthrizeByEVCCID);
             //clearMiscCommand();
         	break;
-        case MISC_CMD_LED_INTENSITY:
-            pSysConfig->LedInfo.Intensity = value;
-            log_info("LED Intensity:%d",pSysConfig->LedInfo.Intensity);
-            break;
         case MISC_CMD_RESERVATION:
-            pDcChargingInfo->ReservationTrigger = value;
             break;
-        case MISC_CMD_CHANGELCM_INFO:
-            pDcChargingInfo->ChangeLcmPage = value;
+        case MISC_CMD_CHANGE_LCM_PAGE:
+            break;
+        case MISC_CMD_QR_CODE_REQ:
+            break;
+        case MISC_CMD_STATION_INFO_REQ:
+            gMoreInfoReq.bits.StationInfoReq = YES;
             break;
+
         default:
             clearMiscCommand();
             break;
@@ -859,6 +870,7 @@ static void addFaultCodeToBuf(uint8_t *Code)
                Code,
                strlen((char *)Code));
         pSysWarning->WarningCount++;
+        log_info("Warning Code:%s",Code);
     }
 }
 
@@ -1032,29 +1044,7 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
 
     return PASS;
 }
-void GetCabientDcmRevHandle(uint8_t *data)
-{
-	PCDCMVer *pVersion = (PCDCMVer *)&data[0];
-	strcpy(ShmDcCommonData->CabinetModelName , pVersion->CabinetModelName);
-	strcpy(ShmDcCommonData->CabinetBoolLoaderVersion, pVersion->CabinetBoolLoaderVersion);
-	strcpy(ShmDcCommonData->CabinetKernelVersion , pVersion->CabinetKernelVersion);
-	strcpy(ShmDcCommonData->CabinetRFSystemVersion , pVersion->CabinetRFSystemVersion);
-	strcpy(ShmDcCommonData->CabinetPrimaryVersion , pVersion->CabinetPrimaryVersion);
-	strcpy(ShmDcCommonData->CabinetIPAddr , pVersion->CabinetIPAddr);
-}
-void GetCabientOtherRevHandle(uint8_t *data)
-{
-	PCOthVer *pVersion = (PCOthVer *)&data[0];
-	strcpy(ShmDcCommonData->CabinetRelay0Version , pVersion->CabinetRelay0Version);
-	strcpy(ShmDcCommonData->CabinetRelay1Version , pVersion->CabinetRelay1Version);
-	strcpy(ShmDcCommonData->CabinetFanVersion , pVersion->CabinetFanVersion);
-}
-void GetCabientEachPsuRevHandle(uint8_t *data)
-{
-	PCnPsuVer *pVersion = (PCnPsuVer *)&data[0];
-	strcpy(ShmDcCommonData->PsuVer[pVersion->n_PSU].DCVersion, pVersion->DCVersion);
-	strcpy(ShmDcCommonData->PsuVer[pVersion->n_PSU].FPCVersion, pVersion->FPCVersion);
-}
+
 static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_t reg)
 {
     int ret = PASS;
@@ -1196,21 +1186,36 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
             pDcChargingInfo->GroundFaultStatus = gfd->Status;
         }
         break;
-    case REG_GET_CABINET_DCM_VERSION:
-    	GetCabientDcmRevHandle(pCsuResult->Data.Data);
-        break;
-    case REG_GET_CABINET_OTHER_VERSION:
-    	GetCabientOtherRevHandle(pCsuResult->Data.Data);
-        break;
-    case REG_GET_CABINET_PSU_NUMBER:
-        if(ShmDcCommonData->PSU_Number == 0 || ShmDcCommonData->PSU_Number != pCsuResult->Data.Data[0]) {
-            ShmDcCommonData->PSU_Number = pCsuResult->Data.Data[0];
-            log_info("PSU Numbers:%d",ShmDcCommonData->PSU_Number);
+
+    case REG_STATION_INFO:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
         }
+        StationVar _stationInfo;
+        memset((char *)&_stationInfo, 0x00, sizeof(StationVar));
+
+        memcpy(_stationInfo.StationName, (char *)&pCsuResult->Data.Data[0], 64);
+        memcpy(_stationInfo.StationID, (char *)&pCsuResult->Data.Data[64], 16);
+        _stationInfo.WeatherID |= (pCsuResult->Data.Data[80] << 24);
+        _stationInfo.WeatherID |= (pCsuResult->Data.Data[81] << 16);
+        _stationInfo.WeatherID |= (pCsuResult->Data.Data[82] << 8);
+        _stationInfo.WeatherID |= pCsuResult->Data.Data[83];
+        uint8_t *pFloat = (uint8_t *)&_stationInfo.Temperature;
+        *(pFloat + 3) = pCsuResult->Data.Data[84];
+        *(pFloat + 2) = pCsuResult->Data.Data[85];
+        *(pFloat + 1) = pCsuResult->Data.Data[86];
+        *(pFloat) = pCsuResult->Data.Data[87];
+
+        ShmDcCommonData->WeatherID = _stationInfo.WeatherID;
+        ShmDcCommonData->Temperature = _stationInfo.Temperature;
+
+        log_info("Station Name: %s, ID: %s, Weather: %d, Temperature: %.1f",
+                _stationInfo.StationName,
+                _stationInfo.StationID,
+                _stationInfo.WeatherID,
+                _stationInfo.Temperature);
         break;
-    case REG_GET_CABINET_PSU_VERSION:
-    	GetCabientEachPsuRevHandle(pCsuResult->Data.Data);
-        break;
+
     default:
         break;
     }
@@ -1247,13 +1252,6 @@ static int composeSocketData(int fd,
 
     //Hexdump((uint8_t *)&csuCmdPkt, sendPktLen);
 
-    // Not Let ask cabinet version trasmit into FAIL Network
-
-    if (reg == REG_GET_CABINET_DCM_VERSION || reg == REG_GET_CABINET_OTHER_VERSION ||
-    		reg == REG_GET_CABINET_PSU_NUMBER || reg == REG_GET_CABINET_PSU_VERSION) {
-    	gDoCommGblData.DisConnCount = 0;
-    }
-
     //send command packet
     if ((size = sendTcpSocket(fd, (uint8_t *)&csuCmdPkt, sendPktLen)) < 0) {
         log_error("TCP socket send packet fail = %d", size);
@@ -1289,6 +1287,22 @@ static int composeSocketData(int fd,
     return ret;
 }
 
+static int readChargerStationInfo(int fd)
+{
+    int ret = PASS;
+
+    if ((ret = composeSocketData(fd,
+                                 ID_REGISTER,
+                                 OP_READ_DATA,
+                                 REG_STATION_INFO,
+                                 0,
+                                 NULL)) == FAIL) {
+        return ret;
+    }
+
+    return ret;
+}
+
 static int writeWaitPlugItState(int fd, uint8_t id)
 {
     int ret = PASS;
@@ -1474,14 +1488,14 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
                 sizeof(ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode));
 
         strncpy(&vendorErrorCodeTmp[plugNum][0], "", WARNING_CODE_SIZE);
-
     } else if ((pDcChargingInfo->SystemStatus <= S_PREPARING_FOR_EVSE) ||
                (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0) ||
                (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1)) {
         pConnState->State = CONN_ST_PREPARING;    //preparing
     } else if (pDcChargingInfo->SystemStatus == S_CHARGING) {
         pConnState->State = CONN_ST_CHARGING;    //charging
-    } else if (pDcChargingInfo->SystemStatus == S_TERMINATING) {
+    } else if (pDcChargingInfo->SystemStatus == S_TERMINATING ||
+            pDcChargingInfo->SystemStatus == S_COMPLETE) {
         pConnState->State = CONN_ST_TERMINATING;    //terminating
     } else if ((pDcChargingInfo->SystemStatus == S_ALARM) ||
                (pDcChargingInfo->SystemStatus == S_FAULT)) {
@@ -1496,11 +1510,10 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
                     WARNING_CODE_SIZE);
             vendorErrorCodeTmp[plugNum][6] = '\0';
             /*
-                log_info("1 ID = %d, VendorErrorCode = %s",
-                         plugNum,
-                         (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
-                _VenderErrorCodeFlag = true;
-            */
+            log_info("1 ID = %d, VendorErrorCode = %s",
+                     plugNum,
+                     (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+                     */
         } else {
             if (strncmp(&vendorErrorCodeTmp[plugNum][0],
                         (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
@@ -1510,9 +1523,11 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
                         (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
                         WARNING_CODE_SIZE);
                 vendorErrorCodeTmp[plugNum][6] = '\0';
+                /*
                 log_info("2 ID = %d, VendorErrorCode = %s",
                          plugNum,
                          (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+                         */
             }
         }
     }
@@ -1597,59 +1612,6 @@ static int readChargingCapability(int fd, uint8_t id)
     return ret;
 }
 
-static int readCabinetDCMVersion(int fd, uint8_t id)
-{
-    int ret = PASS;
-
-    ret = composeSocketData(fd,
-                            id,
-                            OP_READ_DATA,
-                            REG_GET_CABINET_DCM_VERSION,
-                            0,
-                            NULL);
-
-    return ret;
-}
-static int readCabinetOtherVersion(int fd, uint8_t id)
-{
-    int ret = PASS;
-
-    ret = composeSocketData(fd,
-                            id,
-                            OP_READ_DATA,
-							REG_GET_CABINET_OTHER_VERSION,
-                            0,
-                            NULL);
-
-    return ret;
-}
-static int readCabinetPSUNumber(int fd, uint8_t id)
-{
-    int ret = PASS;
-
-    ret = composeSocketData(fd,
-                            id,
-                            OP_READ_DATA,
-							REG_GET_CABINET_PSU_NUMBER,
-                            0,
-                            NULL);
-
-    return ret;
-}
-static int readCabinetEachPSUVersion(int fd, uint8_t id,uint8_t n_psu)
-{
-    int ret = PASS;
-    uint8_t data_buf[0] = {0};
-    data_buf[0] = n_psu;
-    ret = composeSocketData(fd,
-                            id,
-                            OP_READ_DATA,
-							REG_GET_CABINET_PSU_VERSION,
-							sizeof(data_buf),
-							&data_buf[0]);
-
-    return ret;
-}
 static int writeDispenserStatus(int fd, uint8_t gunID)
 {
     uint8_t warningCount = 0;
@@ -1714,62 +1676,7 @@ static int readConnectorID(int fd)
 
     return ret;
 }
-static int writeShowRefundPage(int fd, uint8_t id)
-{
-    int ret = PASS;
-    DispenserRequest* pDispenserRequest = NULL;
-
-    pDispenserRequest->Command = REQ_REFUND_REQUEST;
-    pDispenserRequest->Parameter = ntohl((uint32_t)ShmDcCommonData->_RefundRequest);
 
-    if ((ret = composeSocketData(fd,
-                                 id,
-                                 OP_WRITE_DATA,
-                                 REG_DISPENSER_REQUEST,
-                                 sizeof(DispenserRequest),
-                                 (uint8_t *)pDispenserRequest)) == FAIL) {
-        return ret;
-    }
-    ShmDcCommonData->_RefundRequest = FALSE;
-    return ret;
-}
-static int writeRefundCancelPage(int fd, uint8_t id)
-{
-    int ret = PASS;
-    DispenserRequest* pDispenserRequest = NULL;
-    pDispenserRequest->Command = REQ_REFUND_CANCEL;
-    pDispenserRequest->Parameter = ntohl((uint32_t)ShmDcCommonData->_RefundCancel);
-
-    if ((ret = composeSocketData(fd,
-                                 id,
-                                 OP_WRITE_DATA,
-                                 REG_DISPENSER_REQUEST,
-                                 sizeof(DispenserRequest),
-                                 (uint8_t *)pDispenserRequest)) == FAIL) {
-        return ret;
-    }
-    ShmDcCommonData->_RefundCancel = FALSE;
-    return ret;
-}
-static int writeShowInvociePage(int fd, uint8_t id)
-{
-    int ret = PASS;
-    DispenserRequest* pDispenserRequest = NULL;
-
-    pDispenserRequest->Command = REQ_INVOICE_REQUEST;
-    pDispenserRequest->Parameter = ntohl((uint32_t)ShmDcCommonData->_InvoiceRequest);
-
-    if ((ret = composeSocketData(fd,
-                                 id,
-                                 OP_WRITE_DATA,
-                                 REG_DISPENSER_REQUEST,
-                                 sizeof(DispenserRequest),
-                                 (uint8_t *)pDispenserRequest)) == FAIL) {
-        return ret;
-    }
-    ShmDcCommonData->_InvoiceRequest = FALSE;
-    return ret;
-}
 static int WriteModelName(int fd)
 {
     int ret = PASS;
@@ -1795,45 +1702,7 @@ static int WriteModelName(int fd)
 
     return ret;
 }
-static int readRefundAmount(int fd, uint8_t id)
-{
-    int ret = PASS;
 
-    ret = composeSocketData(fd,
-                            id,
-                            OP_READ_DATA,
-                            REG_GET_REFUND_AMOUNT,
-                            0,
-                            NULL);
-
-    return ret;
-}
-static int readPrepaymentInfo(int fd, uint8_t id)
-{
-    int ret = PASS;
-
-    ret = composeSocketData(fd,
-                            id,
-                            OP_READ_DATA,
-                            REG_GET_PREPAYMOUNT_INFO,
-                            0,
-                            NULL);
-
-    return ret;
-}
-static int readPrepaymentFail(int fd, uint8_t id)
-{
-    int ret = PASS;
-
-    ret = composeSocketData(fd,
-                            id,
-                            OP_READ_DATA,
-                            REG_GET_PREPAYMOUNT_FAIL_INFO,
-                            0,
-                            NULL);
-
-    return ret;
-}
 static void calDisconnectCount(uint8_t *pValue, uint8_t maxCount)
 {
     sleep(3); //wait 1 second
@@ -1907,7 +1776,7 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
 #if defined DD360Audi
     gunID = gDoCommGblData.ConnectorID[pSysInfo->CurGunSelected];
     //gunID = gDoCommGblData.ConnectorID[plugNum];
-    if (pSysConfig->AutoAuth_Disable) {
+    if (pSysConfig->AuthorisationMode) {
         gunID = ID_REGISTER;
         ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0;
     }
@@ -2042,16 +1911,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                 writeConnectorState(fd, plugNum, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
-
-            //check misc command from power cabinet
-            if (gDoCommGblData.MiscCmd != 0) {
-                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
-                    log_error("misc command failed = %x", gDoCommGblData.MiscCmd);
-                }
-                curReg = gDoCommGblData.MiscCmd;
-            } else {
-                curReg = REG_QRCODE_URL_INFO;
-            }
+            curReg = REG_QRCODE_URL_INFO;
             break;
 
         //case REG_USER_ID:
@@ -2063,8 +1923,20 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //    break;
 
         case REG_MISC_CONTROL:
+            gMoreInfoReq.Value = 0;
             readMiscCommand(fd, gunID);
-            isContinue = 0;
+
+            if(gMoreInfoReq.Value == 0)
+            {
+                isContinue = 0;
+            }
+            else
+            {
+                if(gMoreInfoReq.bits.StationInfoReq)
+                {
+                    curReg = REG_STATION_INFO;
+                }
+            }
             break;
 
         case REG_REPORT_CSU_VERSION:
@@ -2098,7 +1970,18 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
-            isContinue = 0;
+
+            //check misc command from power cabinet
+            if (gDoCommGblData.MiscCmd != 0) {
+                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
+                    log_error("misc command failed = %x", gDoCommGblData.MiscCmd);
+                }
+                curReg = gDoCommGblData.MiscCmd;
+            } else if(gMoreInfoReq.bits.StationInfoReq) {
+                curReg = REG_STATION_INFO;
+            } else {
+                isContinue = 0;
+            }
             //curReg = REG_SOFTWARE_UPDATE;
             break;
 
@@ -2109,21 +1992,48 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //    }
         //    isContinue = 0;
         //    break;
-        case REG_GET_RESERVATION_IDTAG:
+
+        //case REG_CABINET_DCM_VERSION:
+        //    break;
+
+        //case REG_CABINET_OTHER_VERSION:
+        //    break;
+
+        //case REG_TOTAL_PSU_QUANTITY:
+        //    break;
+
+        //case REG_PSU_VERSION:
+        //    break;
+
+        case REG_RESERVATION_IDTAG:
             break;
-        case REG_DISPENSER_REQUEST:
+
+        //case REG_DISPENSER_REQUEST:
+        //    break;
+
+        case REG_REMOTE_START_NO_ID:
             break;
-        case REG_GET_REMOTESTART_WITHOUTID:
+
+        case REG_REFUND_AMOUNT:
             break;
-        case REG_GET_REFUND_AMOUNT:
-            ShmDcCommonData->_ChangeLCMRequest = TRUE;
+
+        case REG_PREPAYMENT_INFO:
             break;
-        case REG_GET_PREPAYMOUNT_INFO:
-            ShmDcCommonData->_ChangeLCMRequest = TRUE;
+
+        case REG_PAYMENT_FAIL_REASON:
             break;
-        case REG_GET_PREPAYMOUNT_FAIL_INFO:
-            ShmDcCommonData->_ChangeLCMRequest = TRUE;
+
+        case REG_CONNECTOR_QR_CODE:
             break;
+
+        case REG_STATION_INFO:
+            if(readChargerStationInfo(fd) == PASS)
+            {
+                gMoreInfoReq.bits.StationInfoReq = NO;
+            }
+            isContinue = 0;
+            break;
+
         default:
             log_error("error curReg = %x", curReg);
             gDoCommGblData.MiscCmd = 0;
@@ -2148,96 +2058,12 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 //
 //    return NO;
 //}
-void TccProcess(int fd,uint8_t plugNum, uint8_t gunID)
-{
-    struct timeb AuthNowTime = {0};
-    switch (pSysInfo->SystemPage) {
-    case _PAGE_REFUNDING:
-        // To Get Refund Amount result
-        break;
-    case _PAGE_PAY_SENSING:
-        // To Get Invoice result
-        break;
-    case _PAGE_FUNCTION_SELECT:
-        if (ShmDcCommonData->_RefundRequest) {
-            ftime(&AuthNowTime);
-            if (DiffTimeb(gRegTimeUp[plugNum][REG_DISPENSER_REQUEST], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
-                    DiffTimeb(gRegTimeUp[plugNum][REG_DISPENSER_REQUEST], AuthNowTime) < 0
-               ) {
-                writeShowRefundPage(fd, gunID);
-                ftime(&gRegTimeUp[plugNum][REG_DISPENSER_REQUEST]);
-            }
-        }
-        break;
-    case _PAGE_REFUND_SENSEING:
-        if (ShmDcCommonData->_RefundCancel) {
-            ftime(&AuthNowTime);
-            if (DiffTimeb(gRegTimeUp[plugNum][REG_DISPENSER_REQUEST], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
-                    DiffTimeb(gRegTimeUp[plugNum][REG_DISPENSER_REQUEST], AuthNowTime) < 0
-               ) {
-                writeRefundCancelPage(fd, gunID);
-                ftime(&gRegTimeUp[plugNum][REG_DISPENSER_REQUEST]);
-            }
-        }
-        break;
-    case _PAGE_DONATE_SELECT:
-        if (ShmDcCommonData->_InvoiceRequest) {
-            ftime(&AuthNowTime);
-            if (DiffTimeb(gRegTimeUp[plugNum][REG_DISPENSER_REQUEST], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
-                    DiffTimeb(gRegTimeUp[plugNum][REG_DISPENSER_REQUEST], AuthNowTime) < 0
-               ) {
-                writeShowInvociePage(fd, gunID);
-                ftime(&gRegTimeUp[plugNum][REG_DISPENSER_REQUEST]);
-            }
-        }
-        break;
-    }
-}
+
 static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8_t gunID)
 {
     uint8_t i = 0;
     struct timeb AuthNowTime = {0};
-
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
-    // Get Power Cabinet Version information
-
-    if (pSysConfig->ShowInformation == YES && pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
-    	// Get Power Cabinet DCM Version
-        ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_GET_CABINET_DCM_VERSION], AuthNowTime) > LOOP_RETRY_TIME ||
-                DiffTimeb(gRegTimeUp[plugNum][REG_GET_CABINET_DCM_VERSION], AuthNowTime) < 0
-           ) {
-            readCabinetDCMVersion(fd, gunID);
-            ftime(&gRegTimeUp[plugNum][REG_GET_CABINET_DCM_VERSION]);
-        }
-        // Get Power Cabinet Relay and Fan Version
-		ftime(&AuthNowTime);
-		if (DiffTimeb(gRegTimeUp[plugNum][REG_GET_CABINET_OTHER_VERSION], AuthNowTime) > LOOP_RETRY_TIME ||
-				DiffTimeb(gRegTimeUp[plugNum][REG_GET_CABINET_OTHER_VERSION], AuthNowTime) < 0
-		   ) {
-			readCabinetOtherVersion(fd, gunID);
-			ftime(&gRegTimeUp[plugNum][REG_GET_CABINET_OTHER_VERSION]);
-		}
-		// Get Power Cabinet PSU Numbers
-		ftime(&AuthNowTime);
-		if (DiffTimeb(gRegTimeUp[plugNum][REG_GET_CABINET_PSU_NUMBER], AuthNowTime) > LOOP_RETRY_TIME ||
-				DiffTimeb(gRegTimeUp[plugNum][REG_GET_CABINET_PSU_NUMBER], AuthNowTime) < 0
-		   ) {
-			readCabinetPSUNumber(fd, gunID);
-			ftime(&gRegTimeUp[plugNum][REG_GET_CABINET_PSU_NUMBER]);
-		}
-		// Get Power Cabinet each PSU Version
-		if (ShmDcCommonData->PSU_Number > 0) {
-			for(i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
-				if (DiffTimeb(gRegTimeUp[plugNum][REG_GET_CABINET_PSU_VERSION], AuthNowTime) > LOOP_RETRY_TIME ||
-						DiffTimeb(gRegTimeUp[plugNum][REG_GET_CABINET_PSU_VERSION], AuthNowTime) < 0
-				   ) {
-					readCabinetEachPSUVersion(fd, gunID,i);
-					ftime(&gRegTimeUp[plugNum][REG_GET_CABINET_PSU_VERSION]);
-				}
-			}
-		}
-    }
 
     switch (pDcChargingInfo->SystemStatus) {
     case S_IDLE:
@@ -2246,14 +2072,11 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_ALARM:
     case S_AUTHORIZING:
         checkAuthorProcess(fd, plugNum);
-        if (pDcChargingInfo->SystemStatus == S_IDLE) {
-            TccProcess( fd, plugNum,  gunID);
-        }
+
         //authorization complete, write wait plug it state
         if (ShmSelectGunInfo->PricesInfo[plugNum].Balance == FAIL_BALANCE_PRICES) {
             break;
         }
-        // For TCC Using
 
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
@@ -2271,6 +2094,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
             ftime(&gRegTimeUp[plugNum][REG_MISC_CONTROL]);
         }
         */
+
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
@@ -2353,7 +2177,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_PREPARING_FOR_EVSE: //insaulation test
     case S_CCS_PRECHARGE_ST0:
     case S_CCS_PRECHARGE_ST1:
+
         writeChargingTarget(fd, plugNum, gunID);
+
 		if (pDcChargingInfo->PantographFlag)
 			writeGroundFaultDetection(fd, 1, gunID);
 
@@ -2409,19 +2235,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (pDcChargingInfo->SystemStatus != S_TERMINATING) {
-            if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
-                    DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
-               ) {
-                if (readChargePermission(fd, gunID) == 0) {
-                    log_info("Stop charging by power cabinet's permission = %d, %d",
-                             plugNum,
-                             REG_CHARGING_PERMISSION);
-                    pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
-                    //printf("%d StopChargeFlag = %d\n", plugNum, pDcChargingInfo->StopChargeFlag);
-                }
-                ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
+            if (readChargePermission(fd, gunID) == 0) {
+                log_info("Stop charging by power cabinet's permission = %d, %d",
+                         plugNum,
+                         REG_CHARGING_PERMISSION);
+                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                //printf("%d StopChargeFlag = %d\n", plugNum, pDcChargingInfo->StopChargeFlag);
             }
+            ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
         }
         writeChargingTarget(fd, plugNum, gunID);
 
@@ -2578,13 +2402,6 @@ int main(int argc, char *argv[])
                 if (initDone == DISPENSER_SOCKET_RECONN) {
                     break;
                 }
-                initDone = messageTrigger(fd,
-                                          plugNum,
-                                          gunID,
-                                          REG_MISC_CONTROL);
-                if (initDone == DISPENSER_SOCKET_RECONN) {
-                    break;
-                }
             }
         }
 

+ 31 - 40
EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.h

@@ -80,16 +80,18 @@
 #define REG_QRCODE_URL_INFO                     0X10
 #define REG_WAIT_PLUG_IT_STATE                  0x11
 #define REG_Ground_Fault_Detection              0x12
-#define REG_GET_CABINET_DCM_VERSION             0x13
-#define REG_GET_CABINET_OTHER_VERSION           0x14
-#define REG_GET_CABINET_PSU_NUMBER              0x15
-#define REG_GET_CABINET_PSU_VERSION             0x16
-#define REG_GET_RESERVATION_IDTAG               0x17
+#define REG_CABINET_DCM_VERSION                 0x13
+#define REG_CABINET_OTHER_VERSION               0x14
+#define REG_TOTAL_PSU_QUANTITY                  0x15
+#define REG_PSU_VERSION                         0x16
+#define REG_RESERVATION_IDTAG                   0x17
 #define REG_DISPENSER_REQUEST                   0x18
-#define REG_GET_REMOTESTART_WITHOUTID           0x19
-#define REG_GET_REFUND_AMOUNT                   0x1A
-#define REG_GET_PREPAYMOUNT_INFO                0x1B
-#define REG_GET_PREPAYMOUNT_FAIL_INFO           0x1C
+#define REG_REMOTE_START_NO_ID                  0x19
+#define REG_REFUND_AMOUNT                       0x1A
+#define REG_PREPAYMENT_INFO                     0x1B
+#define REG_PAYMENT_FAIL_REASON                 0x1C
+#define REG_CONNECTOR_QR_CODE                   0x1D
+#define REG_STATION_INFO                        0x1E
 
 //------------------------------------------------------------------------------
 //--- dispenser result ---
@@ -121,7 +123,6 @@
 #define MISC_CMD_WEB_STOP_CHARGING              (0x000B)
 #define MISC_CMD_AUTH_DISABLE					(0x000C)
 #define MISC_CMD_EVCCID_ENABLE					(0x000D)
-#define MISC_CMD_LED_INTENSITY                  (0x000E)
 
 #define MISC_CMD_HARDWARE_REBOOT                (0x0101)
 #define MISC_CMD_SOFTWARE_RESTART               (0x0102)
@@ -129,18 +130,34 @@
 #define MISC_CMD_REMOTE_STOP_CHARGING           (0x0104)
 #define MISC_CMD_REMOTE_UNLOCK                  (0x0105)
 #define MISC_CMD_RESERVATION                    (0x0106)
-#define MISC_CMD_CHANGELCM_INFO                 (0x0107)
+#define MISC_CMD_CHANGE_LCM_PAGE                (0x0107)
+#define MISC_CMD_QR_CODE_REQ                    (0x0108)
+#define MISC_CMD_STATION_INFO_REQ               (0x0109)
 
 #define ST_UPDATE_FIRMWARE                      (0x01)
 #define ST_NO_UPDATE_FIRMWARE                   (0x02)
 
-#define REQ_REFUND_REQUEST                      (0x0001)
-#define REQ_REFUND_CANCEL                       (0x0002)
-#define REQ_INVOICE_REQUEST                     (0x0003)
 //------------------------------------------------------------------------------
 #pragma pack(push)
 #pragma pack(1)
 
+typedef union
+{
+    unsigned int Value;
+    struct
+    {
+        unsigned int StationInfoReq:1;              // 0: no effect,                1: need to request StationInfo
+        unsigned int res:31;
+    }bits;
+} MoreInfoReq;
+
+typedef struct StStationVar {
+    char StationName[64];
+    char StationID[16];
+    int WeatherID;
+    float Temperature;
+} StationVar;
+
 typedef struct StConnectorState {
     uint8_t State;
     uint8_t WarningCode[6];
@@ -251,32 +268,6 @@ typedef struct StAccountInfo {
     uint8_t Reserved[3];
 } AccountInfo;
 
-typedef struct stCabinetDCMVersion {
-    uint8_t CabinetModelName[32];
-    uint8_t CabinetBoolLoaderVersion[32];
-    uint8_t CabinetKernelVersion[32];
-    uint8_t CabinetRFSystemVersion[32];
-    uint8_t CabinetPrimaryVersion[32];
-    uint8_t CabinetIPAddr[32];
-}PCDCMVer;
-
-typedef struct stCabinetOtherVersion {
-    uint8_t CabinetRelay0Version[32];
-    uint8_t CabinetRelay1Version[32];
-    uint8_t CabinetFanVersion[32];
-}PCOthVer;
-
-typedef struct stCabinetEachPsuVersion {
-	uint8_t n_PSU;
-	uint8_t DCVersion[32];
-	uint8_t FPCVersion[32];
-}PCnPsuVer;
-
-typedef struct StDispenserRequest {
-    uint16_t Command;
-    uint32_t Parameter;
-} DispenserRequest;
-
 #pragma pack(pop)
 
 #endif /* _DO_COMM_H_ */

+ 2 - 4
EVSE/Projects/DD360Tcci/Apps/ModuleInternalComm/RelayBoard.c

@@ -1564,8 +1564,7 @@ static void SetLedColor(void)
                 led_color.Connect_1_Blue = _colorBuf;
                 led_color.Connect_1_Red = COLOR_MIN_LV;
             }else if ( chargingData_1->SystemStatus == S_UPDATE ||
-                    chargingData_1->SystemStatus == S_MAINTAIN ||
-                    chargingData_1->SystemStatus == S_ALARM ) {
+                    chargingData_1->SystemStatus == S_MAINTAIN ) {
                 led_color.Connect_1_Green = COLOR_MIN_LV;
                 led_color.Connect_1_Blue = COLOR_MIN_LV;
                 led_color.Connect_1_Red = _colorBuf;
@@ -1599,8 +1598,7 @@ static void SetLedColor(void)
                 led_color.Connect_2_Blue = _colorBuf;
                 led_color.Connect_2_Red = COLOR_MIN_LV;
             }else if ( chargingData_2->SystemStatus == S_UPDATE ||
-                    chargingData_2->SystemStatus == S_MAINTAIN ||
-                    chargingData_2->SystemStatus == S_ALARM) {
+                    chargingData_2->SystemStatus == S_MAINTAIN) {
                 led_color.Connect_2_Green = COLOR_MIN_LV;
                 led_color.Connect_2_Blue = COLOR_MIN_LV;
                 led_color.Connect_2_Red = _colorBuf;

+ 376 - 136
EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -24,13 +24,14 @@
 static struct SysConfigData *pSysConfig = NULL;
 static struct SysInfoData *pSysInfo = NULL;
 static struct WARNING_CODE_INFO *pSysWarning = NULL;
-
+static struct OCPP16Data *ShmOCPP16Data = NULL;
 static struct FanModuleData *ShmFanModuleData;
 static struct PrimaryMcuData *ShmPrimaryMcuData;
 static SelectGunInfo *ShmSelectGunInfo = NULL;
 static struct ChargingInfoData *pDcChargingInfo = NULL;
 static DcCommonInfo *ShmDcCommonData            = NULL;
-
+//int CardReadFd = -1;
+static char *rfidPortName = "/dev/ttyS2";
 short _currentPage              = _PAGE_NONE;
 uint8_t _totalCount;
 uint8_t _showInformIndex = 0;
@@ -42,16 +43,22 @@ int _port;
 char *pPortName           = "/dev/ttyS3";
 char *moduleName          = "DMT80480T070_09WT";
 bool is_show = false;
+bool is_stop = false;
 uint8_t _everyPageRollChange;
 uint8_t _btn_press = 0;
 short _btn_press_id = 0;
-struct timeval returnIdleTimer;
+uint8_t _btn_press_count = 0;
 int _Text_Running_Count = 86;
 int Battery_Test = 0;
 extern void UpdateLcmFunction(DcCommonInfo *ShmDcCommonData,int _lcmport);
 //==========================================
 // Open and Close RS232 and R/W
 //==========================================
+void AuthorizingStart(void)
+{
+    ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
+    pSysInfo->AuthorizeFlag = YES;
+}
 unsigned long GetClockTimeoutValue(struct timespec _start_time)
 {
     struct timespec ts_end;
@@ -92,6 +99,32 @@ void CloseCommunicationLcmPort()
     close(_port);
 }
 
+void setSelGunWaitToAuthor(uint8_t curSel)
+{
+    if (curSel == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
+        log_info("setSelGunWaitToAuthor left");
+
+    } else if (curSel == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
+        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
+        log_info("setSelGunWaitToAuthor right");
+
+    }
+}
+void confirmSelGun(uint8_t selGun)
+{
+    if (selGun == LEFT_GUN_NUM) {
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
+        //printf("confirmSelGun left");
+    } else if (selGun == RIGHT_GUN_NUM) {
+        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
+        //printf("confirmSelGun right");
+    }
+    //changeLcmPage(_PAGE_PLUGIN);
+
+    //StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
+    //StartSystemTimeoutDet(Timeout_ReturnViewPage);
+}
 void GetDeviceInfoStatus(short address, uint8_t len)
 {
     uint8_t cmd[8];
@@ -138,132 +171,171 @@ void CheckDonateSelectPress()
 }
 void CheckIdlePress()
 {
-    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
-    log_info("LCM Enter Authorize Page");
+	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+	if (pDcChargingInfo->Replug_flag) {
+		pSysInfo->SystemPage = _PAGE_PLUGOUT;
+		log_info("IDLE Enter REPLUG Page");
+	}
+    pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+    log_info("IDLE Enter Select Gun Page");
+}
+void CheckReturnPress()
+{
+	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+	//pDcChargingInfo->SystemStatus = S_IDLE;
+	//pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+	ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
+	ShmDcCommonData->PreAuth_Result = 0;
+	strcpy((char *)pSysConfig->UserId, "");
+
+}
+void CheckStopPress()
+{
+	is_stop = TRUE;
+	//ChangeDisplay2Value(_ConfirmStopIcon,is_stop);
+	if (pSysInfo->CurGunSelected == LEFT_GUN_NUM)
+		pSysInfo->SystemPage = _PAGE_STOP_CONFIRM_LEFT;
+	else
+		pSysInfo->SystemPage = _PAGE_STOP_CONFIRM_RIGHT;
+}
+void CheckStopConfirmPress()
+{
+	int result;
+	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+	pDcChargingInfo->SystemStatus = S_TERMINATING;
+	pSysInfo->SystemPage = _PAGE_PAYING;
+	is_stop = FALSE;
+	ShmDcCommonData->finalcost[pSysInfo->CurGunSelected] = (int)pDcChargingInfo->ChargingFee;
+	ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTHCOMPLETE;
+	ShmDcCommonData->PreAuth_Result = 0;
+
+}
+void CheckStopCancelPress()
+{
+	is_stop = FALSE;
+	ChangeDisplay2Value(_ConfirmStopIcon,is_stop);
+	pSysInfo->SystemPage = _PAGE_CHARGING;
+}
+void CheckConfirmGun(uint8_t gunIndex)
+{
+	pSysInfo->CurGunSelected = gunIndex;
+   	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+	if (pDcChargingInfo->SystemStatus == S_IDLE) {
+		confirmSelGun(gunIndex);
+		setSelGunWaitToAuthor(gunIndex);
+		pSysInfo->SystemPage = _PAGE_AUTHORIZE;
+		pDcChargingInfo->SystemStatus = S_AUTHORIZING;
+		// Set Card Reader
+		ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTH;
+		ShmDcCommonData->PreAuth_Result = 0;
+		//
+		AuthorizingStart();
+	}
 }
 void CheckTouchPress(short id)
 {
-    GetDeviceInfoStatus(id,1);
 
-    if (_btn_press >= 1 && _btn_press_id == id) {
+    GetDeviceInfoStatus(id,1);
+    if (_btn_press >= 1 && _btn_press_id == id ) {
+    	_btn_press_count++;
+    }
+    if (_btn_press >= 1 && _btn_press_id == id && _btn_press_count >= 3) {
         ChangeDisplay2Value(id, 0);
+        log_info("Press id : 0x%04x",id);
+        _btn_press_count = 0;
         switch (id) {
         case _Touch_LeftGun:
-            if(pSysInfo->CurGunSelected != LEFT_GUN_NUM) {
-                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
-                log_info("LCM left Gun down...............................%x %x %x",
-                        pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
-                if (pDcChargingInfo->SystemStatus == S_IDLE &&
-                    (pSysInfo->SystemPage <_PAGE_REFUND_SENSEING ||
-                    pSysInfo->SystemPage > _PAGE_REFUND_NONE ||
-                    pSysInfo->SystemPage != _PAGE_PAY_ETICKET_SUCCESS ||
-                    pSysInfo->SystemPage != _PAGE_PAY_MPAY_SUCCESS) ) {
-                    log_info("Reset LCM to IDLE");
-                    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
-                    gettimeofday(&returnIdleTimer, NULL);
-                }
-
-            }
+        	if (pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
+        		log_info("Authorize Page can't select gun");
+        		return;
+        	}
+        	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
             pSysInfo->CurGunSelected = LEFT_GUN_NUM;
+            if(pDcChargingInfo->SystemStatus == S_IDLE) {
+            	pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+            }
+            // Show log
+        	if(pSysInfo->CurGunSelected != LEFT_GUN_NUM) {
+				log_info("LCM left Gun down...............................%x %x %x",
+						pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
+			}
             break;
         case _Touch_RightGun:
-            if (pSysInfo->CurGunSelected != RIGHT_GUN_NUM) {
-                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
-                log_info("LCM right Gun down...............................%x %x %x",
-                        pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
-                if (pDcChargingInfo->SystemStatus == S_IDLE &&
-                    (pSysInfo->SystemPage <_PAGE_REFUND_SENSEING ||
-                    pSysInfo->SystemPage > _PAGE_REFUND_NONE ||
-                    pSysInfo->SystemPage != _PAGE_PAY_ETICKET_SUCCESS ||
-                    pSysInfo->SystemPage != _PAGE_PAY_MPAY_SUCCESS) ) {
-                    log_info("Reset LCM to IDLE");
-                    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
-                    gettimeofday(&returnIdleTimer, NULL);
-                }
+        	if (pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
+				log_info("Authorize Page can't select gun");
+				return;
+			}
+			pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
+			pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
+            if(pDcChargingInfo->SystemStatus == S_IDLE) {
+            	pSysInfo->SystemPage = _PAGE_SELECT_GUN;
             }
-            pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
+			// Show log
+			if(pSysInfo->CurGunSelected != RIGHT_GUN_NUM) {
+				log_info("LCM Right Gun down...............................%x %x %x",
+						pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
+			}
             break;
         case _Touch_Return:
-        	CheckIdlePress();
+        	CheckReturnPress();
         	break;
         case _Touch_IDLE:
             CheckIdlePress();
             break;
+        case _Touch_Stop:
+        	CheckStopPress();
+        	is_stop = TRUE;
+        	break;
+        case _Touch_Stop_Confirm:
+        	CheckStopConfirmPress();
+        	is_stop = FALSE;
+        	break;
+        case _Touch_Stop_Cancel:
+        	CheckStopCancelPress();
+        	is_stop = FALSE;
+        	break;
+        case _Touch_ConfirmLeft:
+        	CheckConfirmGun(LEFT_GUN_NUM);
+        	break;
+        case _Touch_ConfirmRight:
+        	CheckConfirmGun(RIGHT_GUN_NUM);
+        	break;
         } // switch
+
     }   //if (_btn_press >= 3)
 }
 
 void CheckLCMPressed()
 {
     pid_t Pid = fork();
-    int i = 0;
-    int index = 0;
     if ( Pid == 0 ) {
         while (1) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-            CheckTouchPress(_Touch_LeftGun);
-            CheckTouchPress(_Touch_RightGun);
+        	if (pSysInfo->SystemPage != _PAGE_SELECT_GUN) {
+				CheckTouchPress(_Touch_LeftGun);
+				CheckTouchPress(_Touch_RightGun);
+        	}
             switch (pSysInfo->SystemPage) {
             case _PAGE_IDLE:
 				CheckTouchPress(_Touch_IDLE);
                 break;
-            case _PAGE_AUTHORIZE:
-                CheckScreenModePress();
-                break;
-            case _PAGE_FUNCTION_SELECT:
-                break;
-            case _PAGE_MEMBER_SELECT:
-                CheckMemberSelectPress();
-                break;
-            case _PAGE_DONATE:
-                CheckDonatePress();
-                break;
-            case _PAGE_DONATE_SELECT:
-                CheckDonateSelectPress();
-                break;
-// ********************** Test *******************
-/*
-            case _PAGE_PRECHARGE:
-               // if ((i/100) %2 == 0)
-               //     ChangeDisplay2Value(0x109A,i%100);
-               // else
-               //     ChangeDisplay2Value(0x109A,100-(i%100));
-
-                break;
+            case _PAGE_SELECT_GUN:
+				CheckTouchPress(_Touch_ConfirmLeft);
+				CheckTouchPress(_Touch_ConfirmRight);
+            	break;
+            ///*
             case _PAGE_CHARGING:
-            	pSysConfig->BillingData.isBilling = TRUE;
-                pDcChargingInfo->PresentChargingPower = i;
-                pDcChargingInfo->PresentChargedEnergy = i/6;
-                pDcChargingInfo->ChargingFee = i;
-                pDcChargingInfo->RemainChargingDuration = i;
-                pDcChargingInfo->EvBatterySoc = i/6;
-
-                break;
-            case _PAGE_COMPLETE:
-                pDcChargingInfo->PresentChargedEnergy = i;
-                pDcChargingInfo->ChargingFee = i;
-                pDcChargingInfo->EvBatterySoc = i/6;
-                pSysConfig->BillingData.isBilling = TRUE;
-                ChangeCarBonValue(i);
-                pSysConfig->isQRCode = 1;
-                break;
-            case _PAGE_PLUGOUT:
-            	pSysConfig->isQRCode = 1;
+				CheckTouchPress(_Touch_Stop);
+            	break;
+            case _PAGE_AUTHORIZE:
             	CheckTouchPress(_Touch_Return);
             	break;
-// ************************************************ */
+            case _PAGE_STOP_CONFIRM_LEFT:
+            case _PAGE_STOP_CONFIRM_RIGHT:
+				CheckTouchPress(_Touch_Stop_Confirm);
+				CheckTouchPress(_Touch_Stop_Cancel);
+            	break;
             } // switch
             usleep(5000);
-
-            /*
-            i++;
-            if (i == 600 ) {
-				index >= 8 ? index = 1 : index++;
-                pSysInfo->SystemPage = index;
-                i = 0;
-
-            }//*/
-
         } //while
     } // if pid
     log_info("Create LCM fork:%d",Pid);
@@ -330,7 +402,8 @@ void ReadMsgFromLcm(uint8_t *msg, uint8_t readLen)
                 strcpy((char *)pSysInfo->LcmHwRev, moduleName);
             if (key == 0x0014)
                 _currentPage = *(msg + 8);
-            if ( key >= _Touch_LeftGun && key <=_Touch_IDLE ) {
+            if ( key >= _Touch_LeftGun && key <=_Touch_ConfirmRight ) {
+
                 _btn_press_id = key;
                 _btn_press = *(msg + 8);
             }
@@ -507,19 +580,19 @@ void ChangeCurPage()
     if (_currentPage != pSysInfo->PageIndex) {
         switch (pSysInfo->SystemPage) {
         case _PAGE_AUTHORIZE:
-			gettimeofday(&returnIdleTimer, NULL);
             break;
         case _PAGE_PLUGIN:
             break;
         case _PAGE_PRECHARGE:
             break;
         case _PAGE_CHARGING:
+        	is_stop = false;
             break;
         case _PAGE_COMPLETE:
             break;
         }
         _currentPage = pSysInfo->PageIndex;
-
+        log_info("Chagne Page:%d",pSysInfo->PageIndex);
         ChangeToOtherPage(pSysInfo->PageIndex);
     }
 }
@@ -540,7 +613,6 @@ void showGunWorkingType()
 {
     if (pSysInfo->CurGunSelected == LEFT_GUN_NUM) {
 
-
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
         if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
                 pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
@@ -565,7 +637,7 @@ void showGunWorkingType()
         } else if (pDcChargingInfo->Type == _Type_Chademo) {
             ChangeDisplay2Value(_RightGun_status,_ICON_Right_CHAdeMo_Off);
         }
-    } else {
+    } else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM){
         // Left Gun
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
         if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
@@ -590,6 +662,30 @@ void showGunWorkingType()
         } else if (pDcChargingInfo->Type == _Type_Chademo) {
             ChangeDisplay2Value(_RightGun_status,_ICON_Right_CHAdeMO_ON);
         }
+    } else {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
+        if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
+                pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
+            ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CCS1_Off);
+
+        } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
+                pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
+            ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CCS2_Off);
+        } else if (pDcChargingInfo->Type == _Type_Chademo) {
+            ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CHAdeMO_Off);
+        }
+        // Set Right Gun
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
+        if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
+                pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
+            ChangeDisplay2Value(_RightGun_status,_ICON_Right_CCS1_Off);
+
+        } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
+                pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
+            ChangeDisplay2Value(_RightGun_status,_ICON_Right_CCS2_Off);
+        } else if (pDcChargingInfo->Type == _Type_Chademo) {
+            ChangeDisplay2Value(_RightGun_status,_ICON_Right_CHAdeMo_Off);
+        }
     }
 
 }
@@ -671,14 +767,14 @@ void ChangeChargingFeeValue(float fee)
     string2ByteArray(value, cmd);
     DisplayValueToLcm(_Text_Money, cmd, sizeof(cmd));
 }
-void ChangeCarBonValue(int data)
+void ChangeCarBonValue(float data)
 {
     uint8_t cmd[10];
     uint8_t value[10];
-
+    float _carbon = 0;
     memset(cmd, 0x00, sizeof(cmd));
-
-    sprintf((char *) value, "-%d", data);
+    _carbon = (data*9)/10*2.36 - data*0.637;
+    sprintf((char *) value, "%.1fkg", _carbon);
     string2ByteArray(value, cmd);
     DisplayValueToLcm(_Text_Carbon, cmd, sizeof(cmd));
 }
@@ -699,14 +795,14 @@ void ChangeChargingEnergyValue(float energy)
     else
     	ChangeDisplay2Value(_EnergyBar,(int)energy);
 
-    sprintf((char *) value, "%d", (int)energy);
+    sprintf((char *) value, "%.1f", energy);
     string2ByteArray(value, cmd);
     DisplayValueToLcm(_Text_Energy, cmd, sizeof(cmd));
 }
 uint8_t _battery_display_count = 0;
 void ChangeBattMapAndValue(int soc)
 {
-    int i = (soc*36)/100;
+    int i = (soc*37)/100;
     uint8_t cmd[5];
     uint8_t value[5];
 
@@ -719,22 +815,21 @@ void ChangeBattMapAndValue(int soc)
 		_battery_display_count = 0;
 	}
 
-	if (i==36)
-		ChangeDisplay2Value(_ChargingIcon,_ICON_Battery_35);
-	else {
+	if (i>=37)
+		ChangeDisplay2Value(_Battery_Circle,_ICON_Battery_36);
+	else if (pSysInfo->SystemPage == _PAGE_CHARGING){
 		if (_battery_display_ani) {
-			ChangeDisplay2Value(_ChargingIcon, _ICON_Battery_0+(int)i);
+			ChangeDisplay2Value(_Battery_Circle, _ICON_Battery_0+i);
 		} else {
-			ChangeDisplay2Value(_ChargingIcon, _ICON_Battery_0+(int)i+1);
+			ChangeDisplay2Value(_Battery_Circle, _ICON_Battery_0+i+1);
 		}
-	}
+	} else
+		ChangeDisplay2Value(_Battery_Circle, _ICON_Battery_0+i);
 
     memset(cmd, 0x00, sizeof(cmd));
     memset(value, 0x00, sizeof(value));
-    if (pSysInfo->SystemPage == _PAGE_CHARGING)
-    	sprintf((char *)value, "%d", soc);
-    else
-    	sprintf((char *)value, "%d%%", soc);
+
+    sprintf((char *)value, "%d%%", soc);
 
     string2ByteArray(value, cmd);
     DisplayValueToLcm(_Text_BatterySoc, cmd, sizeof(cmd));
@@ -746,10 +841,10 @@ unsigned long GetPreChargeTimeoutValue(struct timeval _sour_time)
 
     return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
-void ChangeTimeValue(uint8_t time)
+void ChangeTimeValue(int time)
 {
-    uint8_t cmd[2];
-    uint8_t value[2];
+    uint8_t cmd[6];
+    uint8_t value[6];
 
     memset(cmd, 0x00, sizeof(cmd));
     sprintf((char *) value, "%d", time);
@@ -791,37 +886,102 @@ void CabinetChangeLCMProcess()
         break;
     }
 }
+void changeWeatherValue(int _weather)
+{
+
+	switch (_weather) {
+	case _WEATHER_TYPE_SUN:
+		ChangeDisplay2Value(_WeatherIcon,_ICON_Weather_Sun);
+		break;
+	case _WEATHER_TYPE_CLOUDY:
+		ChangeDisplay2Value(_WeatherIcon,_ICON_Weather_Cloudy);
+		break;
+	case _WEATHER_TYPE_RAIN:
+		ChangeDisplay2Value(_WeatherIcon,_ICON_Weather_Rain);
+		break;
+	case _WEATHER_TYPE_THUNDER:
+		ChangeDisplay2Value(_WeatherIcon,_ICON_Weather_Thunder);
+		break;
+	case _WEATHER_TYPE_SNOW:
+		ChangeDisplay2Value(_WeatherIcon,_ICON_Weather_Snow);
+		break;
+	case _WEATHER_TYPE_FOG:
+		ChangeDisplay2Value(_WeatherIcon,_ICON_Weather_Fog);
+		break;
+	}
+}
+void changeWeekValue(int _week)
+{
+	ChangeDisplay2Value(_WeekIcon,_week);
+}
+void changeDegreeValue(int _degree)
+{
+    char value[16];
+    memset(value, 0x00, sizeof(value));
+    sprintf((char *)value,"%d",_degree);
+    DisplayValueToLcm(_Text_Tempture, (uint8_t *)value, sizeof(value));
+}
+void changeDateValue(char* _date)
+{
+    char value[16];
+    memset(value, 0x00, sizeof(value));
+    sprintf((char *)value,"%s",_date);
+	DisplayValueToLcm(_Text_Date, (uint8_t *)value, sizeof(value));
+}
+void changeLocationValue(int _location)
+{
+	ChangeDisplay2Value(_LocationIcon,_location);
+}
+int old_money = 0;
 void ProcessPageInfo()
 {
     // Show Gun Working and Type
-    float _current;
-    uint8_t precharg_time;
+
     showGunWorkingType();
+    if (pSysInfo->SystemPage == _PAGE_IDLE) {
+    	changeWeatherValue(ShmDcCommonData->WeatherID);
+    	changeWeekValue(3+114);
+    	changeDegreeValue((int)ShmDcCommonData->Temperature);
+    	changeDateValue(&ShmDcCommonData->PresentTime[0]);
+    	changeLocationValue(121);
+    }
+
+
     for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+
         if (pSysInfo->CurGunSelected == i) {
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
             //CabinetChangeLCMProcess();
 
             switch (pSysInfo->SystemPage) {
             case _PAGE_IDLE:
-            	gettimeofday(&returnIdleTimer, NULL);
+
             	break;
             case _PAGE_AUTHORIZE:
                 ShowHomePage();
-                if (GetTimeoutValue(returnIdleTimer) /uSEC_VAL >= RETURNIDLE_Timeout ) {
-                    pSysInfo->SystemPage = _PAGE_IDLE;
-                    gettimeofday(&returnIdleTimer, NULL);
+                /*
+                int card_result = CreditCardPreAuth(CardReadFd, PREAUTHMONEY,"TCC Test", &ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
+				if (card_result > 0 ) {
+					strcpy((char *)pSysConfig->UserId, (char *)ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo);
+				} else if (card_result < 0) {
+					pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
+				}*/
+                if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_CANCEL && ShmDcCommonData->PreAuth_Result != 0) {
+                	pDcChargingInfo->SystemStatus = S_IDLE;
+                	pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+                	ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
                 }
+
                 break;
             case _PAGE_PLUGIN:
-            	_Text_Running_Count = 86;
+            	_Text_Running_Count = _ICON_PrePare_1;
             	_everyPageRollChange = 0;
                 break;
             case _PAGE_PRECHARGE:
             	RefreshProgressAnimation();
             	if (_everyPageRollChange == 0) {
             		ChangeDisplay2Value(_PrepareBar,_Text_Running_Count);
-            		_Text_Running_Count >= 99 ? _Text_Running_Count = 86 : _Text_Running_Count++;
+            		_Text_Running_Count >= _ICON_PrePare_14 ? _Text_Running_Count = _ICON_PrePare_1 : _Text_Running_Count++;
             	}
                 break;
             case _PAGE_CHARGING:
@@ -840,13 +1000,13 @@ void ProcessPageInfo()
                 } else {
                     ChangeChargingEnergyValue(0);
                 }
-                if (pSysConfig->BillingData.isBilling &&
-                        pDcChargingInfo->ChargingFee >= 0) {
+                if ( pDcChargingInfo->ChargingFee >= 0) {
                     ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
+
                 }
                 if (pDcChargingInfo->RemainChargingDuration >= 0 &&
                         pDcChargingInfo->RemainChargingDuration <= TIME_MAX_SEC) {
-                	ChangeTimeValue(pDcChargingInfo->RemainChargingDuration);
+                	ChangeTimeValue(pDcChargingInfo->RemainChargingDuration/60);
                 } else {
                 	ChangeTimeValue(0);
                 }
@@ -860,10 +1020,10 @@ void ProcessPageInfo()
                 } else {
                     ChangeChargingEnergyValue(0);
                 }
-                if (pSysConfig->BillingData.isBilling &&
-                        pDcChargingInfo->ChargingFee >= 0) {
-                    ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
+                if ( ShmDcCommonData->finalcost[i] >= 0) {
+                    ChangeChargingFeeValue(ShmDcCommonData->finalcost[i]);
                 }
+                ChangeCarBonValue(pDcChargingInfo->PresentChargedEnergy);
                 ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
 
                 if (pSysConfig->isQRCode) {
@@ -880,6 +1040,7 @@ void ProcessPageInfo()
             case _PAGE_REFUND_SENSEING:
                 break;
             case _PAGE_PLUGOUT:
+
                 if (pSysConfig->isQRCode) {
                     if (pSysConfig->QRCodeMadeMode == NO) {
                         //uint8_t len = strlen((char *)pSysConfig->SystemId);
@@ -890,6 +1051,15 @@ void ProcessPageInfo()
                     }
                     //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
                 }
+            	break;
+            case _PAGE_PAYING:
+            	if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTHCOMPLETE) {
+            		if (ShmDcCommonData->PreAuth_Result != 0) {
+            			ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
+            			pSysInfo->SystemPage = _PAGE_COMPLETE;
+            		}
+            	}
+
             	break;
             }
         }
@@ -1071,7 +1241,8 @@ void InformationShow()
 }
 void DefautLayOut()
 {
-	for (int i = 0 ; i <= 0x72 ; i+=2 ) {
+	int i;
+	for (i = 0 ; i <= 0x6C ; i+=2 ) {
 		ChangeDisplay2Value(0x1000+i,1);
 		if (i == 0x38)
 			ChangeDisplay2Value(0x1000+i,85);
@@ -1080,9 +1251,68 @@ void DefautLayOut()
 		else if (i == 0x3A)
 			ChangeDisplay2Value(0x1000+i,99);
 	}
-
+	for (i = 0 ; i< 0x10 ; i+=2) {
+		if (i >= 0x08 && i <= 0x0B)
+			continue;
+		ChangeDisplay2Value(0x1200+i,1);
+	}
 	ChangeDisplay2Value(0x5000,1);
+	ChangeDisplay2Value(0x1002,0);
+
+		pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
+        if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
+                pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
+            ChangeDisplay2Value(_ConfirmLeftIcon,_ICON_WELCOMELEFTCCS1);
+            ChangeDisplay2Value(_PayFailLeftIcon,_ICON_PAYFAILLEFTCCS1);
+
+        } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
+                pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
+            ChangeDisplay2Value(_ConfirmLeftIcon,_ICON_WELCOMELEFTCCS2);
+            ChangeDisplay2Value(_PayFailLeftIcon,_ICON_PAYFAILLEFTCCS2);
+        } else if (pDcChargingInfo->Type == _Type_Chademo) {
+            ChangeDisplay2Value(_ConfirmLeftIcon,_ICON_WELCOMELEFTCHADEMO);
+            ChangeDisplay2Value(_PayFailLeftIcon,_ICON_PAYFAILLETCHADEMO);
+        }
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
+		if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
+				pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
+			ChangeDisplay2Value(_ConfirmRightIcon,_ICON_WELCOMERIGHTCCS1);
+			ChangeDisplay2Value(_PayFailRightIcon,_ICON_PAYFAILRIGHTCCS1);
+		} else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
+				pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
+			ChangeDisplay2Value(_ConfirmRightIcon,_ICON_WELCOMERIGHTCCS2);
+			ChangeDisplay2Value(_PayFailRightIcon,_ICON_PAYFAILRIGHTCCS2);
+		} else if (pDcChargingInfo->Type == _Type_Chademo) {
+            ChangeDisplay2Value(_ConfirmRightIcon,_ICON_WELCOMERIGHTCHADEMO);
+            ChangeDisplay2Value(_PayFailRightIcon,_ICON_PAYFAILRIGHTCHADEMO);
+		}
 }
+static int InitialRfidPort(void)
+{
+    int fd = open(rfidPortName, O_RDWR);
+    struct termios tios;
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+    if (fd != FAIL) {
+        ioctl (fd, TCGETS, &tios);
+        tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
+        tios.c_lflag = 0;
+        tios.c_iflag = 0;
+        tios.c_oflag = 0;
+        tios.c_cc[VMIN] = 0;
+        tios.c_cc[VTIME] = (uint8_t) 1;
+        tios.c_lflag = 0;
+        tcflush(fd, TCIFLUSH);
+        ioctl(fd, TCSETS, &tios);
+    }
+
+    if (fd < 0) {
+        pAlarmCode->AlarmEvents.bits.RfidModuleCommFail = 1;
+    }
+
+    return fd;
+}
+
 int main(void)
 {
     bool defaulttext = false;
@@ -1100,9 +1330,9 @@ int main(void)
     ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
     ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
     ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
+    ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
     struct StatusCodeData *ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();;
-    struct ChargingInfoData *pDcChargingInfo_0 = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
-    struct ChargingInfoData *pDcChargingInfo_1 = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
+
     _port = CreateCommunicationLcmPort();
     uint8_t changeWarningPriority = 0;
     uint8_t curWarningCount = 255;
@@ -1116,7 +1346,15 @@ int main(void)
     DefautLayOut();
     //return 0;
     //uint8_t index = 1;
+
+	int result = 0;
+
     ShmDcCommonData->PSU_Number = 12;
+    /*
+    CardReadFd = InitialRfidPort();
+    if (CardReadFd <0) {
+    	log_info("Card Read Port open fail!");
+    }*/
 
     CheckLCMPressed();
 
@@ -1129,6 +1367,7 @@ int main(void)
 
         } else {
             UpdateLcmFunction(ShmDcCommonData,_port);
+
             ///*
             // Warning 處理
             if (curWarningCount != pSysWarning->WarningCount) {
@@ -1175,6 +1414,7 @@ int main(void)
 
             ChangeCurPage();
             changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
+
             usleep(10000); //*/
 
             /*

+ 73 - 2
EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Module_LcmControl.h

@@ -5,7 +5,7 @@
 #include "../Define/define.h"
 
 //------------------------------------------------------------------------------
-
+#define PREAUTHMONEY						2000
 #define RETURNIDLE_Timeout					60
 #define DEFAULT_AC_INDEX                        (2)
 
@@ -52,6 +52,7 @@
 
 //#define NOODOE_QR_CODE_URL                    "https://ev-alpha-test.noodoe.com/station?id=" ////For Audi
 #define _StatuIcon				0x1000
+#define _ConfirmStopIcon		0x1002
 #define	_TccareIcon				0x1004
 #define _StartTouchIcon			0x1006
 #define _FurthureIcon			0x1010
@@ -97,6 +98,12 @@
 #define _Touch_RightGun			0x1082
 #define _Touch_Return			0x1084
 #define _Touch_IDLE				0x1086
+#define _Touch_Stop				0x1088
+#define _Touch_Stop_Confirm		0x108A
+#define _Touch_Stop_Cancel		0x108C
+#define _Touch_ConfirmLeft		0x1208
+#define _Touch_ConfirmRight		0x120A
+
 // Text String
 #define _Text_Power				0x1090
 #define _Text_Time				0x10A0
@@ -110,6 +117,21 @@
 #define _Text_Warming_2			0x1110
 #define _Text_Warming_3			0x1120
 #define _Text_Warming_4			0x1130
+#define _Text_Date				0x1140
+#define _Text_Tempture			0x1150
+
+#define _WeekIcon				0x1200
+#define _WeatherIcon			0x1202
+#define _LocationIcon			0x1204
+#define _StopChargeBtn			0x1206
+
+#define _ErrorIcon				0x120C
+#define _PayIcon				0x120E
+#define _ProgreePayIcon			0x1210
+#define _ConfirmLeftIcon		0x1212
+#define _ConfirmRightIcon		0x1214
+#define _PayFailLeftIcon		0x1216
+#define _PayFailRightIcon		0x1218
 
 // ICON Map Address
 enum _LCM_TCC_INDEX {
@@ -223,6 +245,14 @@ enum _ICON_LIST_ {
 	_ICON_Battery_33,
 	_ICON_Battery_34,
 	_ICON_Battery_35,
+	_ICON_Battery_36,
+	_ICON_Weather_Sun,
+	_ICON_Weather_Cloudy,
+	_ICON_Weather_Rain,
+	_ICON_Weather_Thunder,
+	_ICON_Weather_Snow,
+	_ICON_Weather_Fog,
+	/*
 	_ICON_Bar_1,
 	_ICON_Bar_2,
 	_ICON_Bar_3,
@@ -233,7 +263,8 @@ enum _ICON_LIST_ {
 	_ICON_Bar_8,
 	_ICON_Bar_9,
 	_ICON_Bar_10,
-	_ICON_PrePare_1,
+	*/
+	_ICON_PrePare_1   = 86,
 	_ICON_PrePare_2,
 	_ICON_PrePare_3,
 	_ICON_PrePare_4,
@@ -259,6 +290,46 @@ enum _ICON_LIST_ {
 	_ICON_Right_CCS1_ON,
 	_ICON_Right_CCS2_ON,
 	_ICON_Right_CHAdeMO_ON,
+	_ICON_WARMING,
+	_ICON_SELECT_TEXT,
+	_ICON_MONDAY,
+	_ICON_TUESDAY,
+	_ICON_WENSDAY,
+	_ICON_THRUDAY,
+	_ICON_FRIDAY,
+	_ICON_SATURDAY,
+	_ICON_SUNDAY,
+	_ICON_LOCATION_TAIPEI,
+
+	_ICON_PAYFAIL = 126,
+	_ICON_PROGREEPAY_1,
+	_ICON_PROGREEPAY_2,
+	_ICON_PROGREEPAY_3,
+	_ICON_PROGREEPAY_4,
+	_ICON_PROGREEPAY_5,
+	_ICON_PROGREEPAY_6,
+	_ICON_PROGREEPAY_7,
+	_ICON_PROGREEPAY_8,
+	_ICON_PROGREEPAY_9,
+	_ICON_PROGREEPAY_10,
+	_ICON_PROGREEPAY_11,
+	_ICON_PROGREEPAY_12,
+	_ICON_PROGREEPAY_13,
+	_ICON_PROGREEPAY_14,
+	_ICON_PROGREEPAY_15,
+	_ICON_STOPSERVICE,
+	_ICON_WELCOMELEFTCCS1,
+	_ICON_WELCOMELEFTCCS2,
+	_ICON_WELCOMELEFTCHADEMO,
+	_ICON_WELCOMERIGHTCCS1,
+	_ICON_WELCOMERIGHTCCS2,
+	_ICON_WELCOMERIGHTCHADEMO,
+	_ICON_PAYFAILLEFTCCS1,
+	_ICON_PAYFAILLEFTCCS2,
+	_ICON_PAYFAILLETCHADEMO,
+	_ICON_PAYFAILRIGHTCCS1,
+	_ICON_PAYFAILRIGHTCCS2,
+	_ICON_PAYFAILRIGHTCHADEMO,
 };
 
 

+ 0 - 1
EVSE/Projects/DD360Tcci/Apps/SelectGun/SelectGun.h

@@ -17,7 +17,6 @@
 
 #define LEFT_GUN_NUM                            (0)
 #define RIGHT_GUN_NUM                           (1)
-
 #define SEL_GUN_TIMEOUT                         (120)
 
 #define DESTROY_ALL_SEL                         (0x03)

+ 1 - 1
EVSE/Projects/DD360Tcci/Apps/ShareMemory/shmMem.c

@@ -505,7 +505,7 @@ void InitialShareMemoryInfo(void)
     memset(pSysInfo->FanModuleFwRev, 0, ARRAY_SIZE(pSysInfo->FanModuleFwRev));
     memset(pSysInfo->RelayModuleFwRev, 0, ARRAY_SIZE(pSysInfo->RelayModuleFwRev));
 
-    pSysInfo->SystemPage = _PAGE_AUTHORIZE;
+    pSysInfo->SystemPage = _PAGE_SELECT_GUN;
 
     pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
     pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;