Explorar o código

Merge branch 'AW-Regular' of https://git.phihong.com.tw:30000/System_Integration/CSU3_AM335x into AW-Regular

8009 %!s(int64=2) %!d(string=hai) anos
pai
achega
81579f903d

+ 26 - 0
EVSE/GPL/etherwake/Makefile

@@ -0,0 +1,26 @@
+.PHONY: clean uninstall
+
+prefix ?= /usr
+exec_prefix ?= $(prefix)
+bindir ?= $(exec_prefix)/bin
+
+ETHERWAKE_src = ether-wake.c
+ETHERWAKE_bin = ether-wake
+ETHERWAKE_tgt = $(DESTDIR)$(bindir)/etherwake
+
+all: $(ETHERWAKE_bin)
+#$(CC) -O -Wall -o $(TARGET) ether-wake.c
+
+$(ETHERWAKE_bin): $(ETHERWAKE_src)
+
+$(ETHERWAKE_tgt): $(ETHERWAKE_bin)
+	install -d $(DESTDIR)$(bindir)
+	install -m 0755 $^ $@
+
+clean:
+	rm $(ETHERWAKE_bin)
+
+install: $(ETHERWAKE_tgt)
+
+uninstall:
+	rm $(ETHERWAKE_tgt)

BIN=BIN
EVSE/GPL/etherwake/ether-wake


+ 392 - 0
EVSE/GPL/etherwake/ether-wake.c

@@ -0,0 +1,392 @@
+/* ether-wake.c: Send a magic packet to wake up sleeping machines. */
+
+static char version_msg[] =
+"etherwake.c: v1.09 11/12/2003 Donald Becker, http://www.scyld.com/";
+static char brief_usage_msg[] =
+"usage: etherwake [-i <ifname>] [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n"
+"   Use '-u' to see the complete set of options.\n";
+static char usage_msg[] =
+"usage: etherwake [-i <ifname>] [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n"
+"\n"
+"	This program generates and transmits a Wake-On-LAN (WOL)\n"
+"	\"Magic Packet\", used for restarting machines that have been\n"
+"	soft-powered-down (ACPI D3-warm state).\n"
+"	It currently generates the standard AMD Magic Packet format, with\n"
+"	an optional password appended.\n"
+"\n"
+"	The single required parameter is the Ethernet MAC (station) address\n"
+"	of the machine to wake or a host ID with known NSS 'ethers' entry.\n"
+"	The MAC address may be found with the 'arp' program while the target\n"
+"	machine is awake.\n"
+"\n"
+"	Options:\n"
+"		-b	Send wake-up packet to the broadcast address.\n"
+"		-D	Increase the debug level.\n"
+"		-i ifname	Use interface IFNAME instead of the default 'eth0'.\n"
+"		-p <pw>		Append the four or six byte password PW to the packet.\n"
+"					A password is only required for a few adapter types.\n"
+"					The password may be specified in ethernet hex format\n"
+"					or dotted decimal (Internet address)\n"
+"		-p 00:22:44:66:88:aa\n"
+"		-p 192.168.1.1\n";
+
+/*
+	This program generates and transmits a Wake-On-LAN (WOL) "Magic Packet",
+	used for restarting machines that have been soft-powered-down
+	(ACPI D3-warm state).  It currently generates the standard AMD Magic Packet
+	format, with an optional password appended.
+
+	This software may be used and distributed according to the terms
+	of the GNU Public License, incorporated herein by reference.
+	Contact the author for use under other terms.
+
+	This source file was originally part of the network tricks package, and
+	is now distributed to support the Scyld Beowulf system.
+	Copyright 1999-2003 Donald Becker and Scyld Computing Corporation.
+
+	The author may be reached as becker@scyld, or C/O
+	 Scyld Computing Corporation
+	 914 Bay Ridge Road, Suite 220
+	 Annapolis MD 21403
+
+  Notes:
+  On some systems dropping root capability allows the process to be
+  dumped, traced or debugged.
+  If someone traces this program, they get control of a raw socket.
+  Linux handles this safely, but beware when porting this program.
+
+  An alternative to needing 'root' is using a UDP broadcast socket, however
+  doing so only works with adapters configured for unicast+broadcast Rx
+  filter.  That configuration consumes more power.
+*/
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <ctype.h>
+#include <string.h>
+
+#if 0							/* Only exists on some versions. */
+#include <ioctls.h>
+#endif
+
+#include <sys/socket.h>
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <linux/if.h>
+
+#include <features.h>
+#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
+#include <netpacket/packet.h>
+#include <net/ethernet.h>
+#else
+#include <asm/types.h>
+#include <linux/if_packet.h>
+#include <linux/if_ether.h>
+#endif
+#include <netdb.h>
+#include <netinet/ether.h>
+
+/* Grrr, no consistency between include versions.
+   Enable this if setsockopt() isn't declared with your library. */
+#if 0
+extern int setsockopt __P ((int __fd, int __level, int __optname,
+							__ptr_t __optval, int __optlen));
+#else				/* New, correct head files.  */
+#include <sys/socket.h>
+#endif
+
+u_char outpack[1000];
+int outpack_sz = 0;
+int debug = 0;
+u_char wol_passwd[6];
+int wol_passwd_sz = 0;
+
+static int opt_no_src_addr = 0, opt_broadcast = 0;
+
+static int get_dest_addr(const char *arg, struct ether_addr *eaddr);
+static int get_fill(unsigned char *pkt, struct ether_addr *eaddr);
+static int get_wol_pw(const char *optarg);
+
+int main(int argc, char *argv[])
+{
+	char *ifname = "eth0";
+	int one = 1;				/* True, for socket options. */
+	int s;						/* Raw socket */
+	int errflag = 0, verbose = 0, do_version = 0;
+	int perm_failure = 0;
+	int i, c, pktsize;
+#if defined(PF_PACKET)
+	struct sockaddr_ll whereto;
+#else
+	struct sockaddr whereto;	/* who to wake up */
+#endif
+	struct ether_addr eaddr;
+
+	while ((c = getopt(argc, argv, "bDi:p:uvV")) != -1)
+		switch (c) {
+		case 'b': opt_broadcast++;	break;
+		case 'D': debug++;			break;
+		case 'i': ifname = optarg;	break;
+		case 'p': get_wol_pw(optarg); break;
+		case 'u': printf("%s",usage_msg); return 0;
+		case 'v': verbose++;		break;
+		case 'V': do_version++;		break;
+		case '?':
+			errflag++;
+		}
+	if (verbose || do_version)
+		printf("%s\n", version_msg);
+	if (errflag) {
+		fprintf(stderr,"%s", brief_usage_msg);
+		return 3;
+	}
+
+	if (optind == argc) {
+		fprintf(stderr, "Specify the Ethernet address as 00:11:22:33:44:55.\n");
+		return 3;
+	}
+
+	/* Note: PF_INET, SOCK_DGRAM, IPPROTO_UDP would allow SIOCGIFHWADDR to
+	   work as non-root, but we need SOCK_PACKET to specify the Ethernet
+	   destination address. */
+#if defined(PF_PACKET)
+	s = socket(PF_PACKET, SOCK_RAW, 0);
+#else
+	s = socket(AF_INET, SOCK_PACKET, SOCK_PACKET);
+#endif
+	if (s < 0) {
+		if (errno == EPERM)
+			fprintf(stderr, "etherwake: This program must be run as root.\n");
+		else
+			perror("etherwake: socket");
+		perm_failure++;
+	}
+	/* Don't revert if debugging allows a normal user to get the raw socket. */
+	setuid(getuid());
+
+	/* We look up the station address before reporting failure so that
+	   errors may be reported even when run as a normal user.
+	*/
+	if (get_dest_addr(argv[optind], &eaddr) != 0)
+		return 3;
+	if (perm_failure && ! debug)
+		return 2;
+
+	pktsize = get_fill(outpack, &eaddr);
+
+	/* Fill in the source address, if possible.
+	   The code to retrieve the local station address is Linux specific. */
+	if (! opt_no_src_addr) {
+		struct ifreq if_hwaddr;
+		const char *hwaddr = if_hwaddr.ifr_hwaddr.sa_data;
+
+		strcpy(if_hwaddr.ifr_name, ifname);
+		if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) < 0) {
+			fprintf(stderr, "SIOCGIFHWADDR on %s failed: %s\n", ifname,
+					strerror(errno));
+			/* Magic packets still work if our source address is bogus, but
+			   we fail just to be anal. */
+			return 1;
+		}
+		memcpy(outpack+6, if_hwaddr.ifr_hwaddr.sa_data, 6);
+
+		if (verbose) {
+			printf("The hardware address (SIOCGIFHWADDR) of %s is type %d  "
+				   "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n", ifname,
+				   if_hwaddr.ifr_hwaddr.sa_family, hwaddr[0], hwaddr[1],
+				   hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);
+		}
+	}
+
+	if (wol_passwd_sz > 0) {
+		memcpy(outpack+pktsize, wol_passwd, wol_passwd_sz);
+		pktsize += wol_passwd_sz;
+	}
+
+	if (verbose > 1) {
+		printf("The final packet is: ");
+		for (i = 0; i < pktsize; i++)
+			printf(" %2.2x", outpack[i]);
+		printf(".\n");
+	}
+
+	/* This is necessary for broadcasts to work */
+	if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&one, sizeof(one)) < 0)
+		perror("setsockopt: SO_BROADCAST");
+
+#if defined(PF_PACKET)
+	{
+		struct ifreq ifr;
+		strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+		if (ioctl(s, SIOCGIFINDEX, &ifr) == -1) {
+			fprintf(stderr, "SIOCGIFINDEX on %s failed: %s\n", ifname,
+					strerror(errno));
+			return 1;
+		}
+		memset(&whereto, 0, sizeof(whereto));
+		whereto.sll_family = AF_PACKET;
+		whereto.sll_ifindex = ifr.ifr_ifindex;
+		/* The manual page incorrectly claims the address must be filled.
+		   We do so because the code may change to match the docs. */
+		whereto.sll_halen = ETH_ALEN;
+		memcpy(whereto.sll_addr, outpack, ETH_ALEN);
+
+	}
+#else
+	whereto.sa_family = 0;
+	strcpy(whereto.sa_data, ifname);
+#endif
+
+	if ((i = sendto(s, outpack, pktsize, 0, (struct sockaddr *)&whereto,
+					sizeof(whereto))) < 0)
+		perror("sendto");
+	else if (debug)
+		printf("Sendto worked ! %d.\n", i);
+
+#ifdef USE_SEND
+	if (bind(s, (struct sockaddr *)&whereto, sizeof(whereto)) < 0)
+		perror("bind");
+	else if (send(s, outpack, 100, 0) < 0)
+		perror("send");
+#endif
+#ifdef USE_SENDMSG
+	{
+		struct msghdr msghdr = { 0,};
+		struct iovec iovector[1];
+		msghdr.msg_name = &whereto;
+		msghdr.msg_namelen = sizeof(whereto);
+		msghdr.msg_iov = iovector;
+		msghdr.msg_iovlen = 1;
+		iovector[0].iov_base = outpack;
+		iovector[0].iov_len = pktsize;
+		if ((i = sendmsg(s, &msghdr, 0)) < 0)
+			perror("sendmsg");
+		else if (debug)
+			printf("sendmsg worked, %d (%d).\n", i, errno);
+	}
+#endif
+
+	return 0;
+}
+
+/* Convert the host ID string to a MAC address.
+   The string may be a
+	Host name
+    IP address string
+	MAC address string
+*/
+
+static int get_dest_addr(const char *hostid, struct ether_addr *eaddr)
+{
+	struct ether_addr *eap;
+
+	eap = ether_aton(hostid);
+	if (eap) {
+		*eaddr = *eap;
+		if (debug)
+			fprintf(stderr, "The target station address is %s.\n",
+					ether_ntoa(eaddr));
+	} else if (ether_hostton(hostid, eaddr) == 0) {
+		if (debug)
+			fprintf(stderr, "Station address for hostname %s is %s.\n",
+					hostid, ether_ntoa(eaddr));
+	} else {
+		(void)fprintf(stderr,
+					  "etherwake: The Magic Packet host address must be "
+					  "specified as\n"
+					  "  - a station address, 00:11:22:33:44:55, or\n"
+					  "  - a hostname with a known 'ethers' entry.\n");
+		return -1;
+	}
+	return 0;
+}
+
+
+static int get_fill(unsigned char *pkt, struct ether_addr *eaddr)
+{
+	int offset, i;
+	unsigned char *station_addr = eaddr->ether_addr_octet;
+
+	if (opt_broadcast)
+		memset(pkt+0, 0xff, 6);
+	else
+		memcpy(pkt, station_addr, 6);
+	memcpy(pkt+6, station_addr, 6);
+	pkt[12] = 0x08;				/* Or 0x0806 for ARP, 0x8035 for RARP */
+	pkt[13] = 0x42;
+	offset = 14;
+
+	memset(pkt+offset, 0xff, 6);
+	offset += 6;
+
+	for (i = 0; i < 16; i++) {
+		memcpy(pkt+offset, station_addr, 6);
+		offset += 6;
+	}
+	if (debug) {
+		fprintf(stderr, "Packet is ");
+		for (i = 0; i < offset; i++)
+			fprintf(stderr, " %2.2x", pkt[i]);
+		fprintf(stderr, ".\n");
+	}
+	return offset;
+}
+
+static int get_wol_pw(const char *optarg)
+{
+	int passwd[6];
+	int byte_cnt;
+	int i;
+
+	byte_cnt = sscanf(optarg, "%2x:%2x:%2x:%2x:%2x:%2x",
+					  &passwd[0], &passwd[1], &passwd[2],
+					  &passwd[3], &passwd[4], &passwd[5]);
+	if (byte_cnt < 4)
+		byte_cnt = sscanf(optarg, "%d.%d.%d.%d",
+						  &passwd[0], &passwd[1], &passwd[2], &passwd[3]);
+	if (byte_cnt < 4) {
+		fprintf(stderr, "Unable to read the Wake-On-LAN password.\n");
+		return 0;
+	}
+	printf(" The Magic packet password is %2.2x %2.2x %2.2x %2.2x (%d).\n",
+		   passwd[0], passwd[1], passwd[2], passwd[3], byte_cnt);
+	for (i = 0; i < byte_cnt; i++)
+		wol_passwd[i] = passwd[i];
+	return wol_passwd_sz = byte_cnt;
+}
+
+#if 0
+{
+	to = (struct sockaddr_in *)&whereto;
+	to->sin_family = AF_INET;
+	if (inet_aton(target, &to->sin_addr)) {
+		hostname = target;
+	}
+	memset (&sa, 0, sizeof sa);
+	sa.sa_family = AF_INET;
+	strncpy (sa.sa_data, interface, sizeof sa.sa_data);
+	sendto (sock, buf, bufix + len, 0, &sa, sizeof sa);
+	strncpy (sa.sa_data, interface, sizeof sa.sa_data);
+#if 1
+	sendto (sock, buf, bufix + len, 0, &sa, sizeof sa);
+#else
+	bind (sock, &sa, sizeof sa);
+	connect();
+	send (sock, buf, bufix + len, 0);
+#endif
+}
+#endif
+
+
+/*
+ * Local variables:
+ *  compile-command: "gcc -O -Wall -o ether-wake ether-wake.c"
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  c-indent-level: 4
+ *  tab-width: 4
+ * End:
+ */

+ 47 - 47
EVSE/Projects/AW-CCS/Apps/main.c

@@ -819,7 +819,7 @@ uint8_t ocpp_get_auth_result(uint8_t isValidParent, ...)
 					DEBUG_INFO("Authorize.ResponseIdTagInfo.ParentIdTag : %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
 					DEBUG_INFO("StartTransaction[%d].ResponseIdTagInfo.ParentIdTag : %s \n", gun_index ,ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
 					*/
-					
+
 					if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) &&
 					   (strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (char*)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag)==0))
 						result = PASS;
@@ -833,7 +833,7 @@ uint8_t ocpp_get_auth_result(uint8_t isValidParent, ...)
 					DEBUG_INFO("Authorize.Response_idTokenInfo.groupIdToken.idToken : %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken);
 					DEBUG_INFO("TransactionEvent[%d].Response_idTokenInfo.groupIdToken.idToken : %s \n", gun_index, ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.groupIdToken.idToken);
 					*/
-					
+
 					if((strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Accepted")==0) &&
 					   ((strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.groupIdToken.idToken) == 0) ||
 						(strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value) == 0)))
@@ -2372,7 +2372,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	free(buf);
 
 	system("rm -f /mnt/EvseConfig.bin");
-	
+
 	// SysConfig in flash is empty (0xffffffff)
 	if((strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName)) ||
 	   (strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber)) ||
@@ -2418,7 +2418,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 		sleep(3);
 		system("/usr/bin/run_evse_restart.sh");
 	}
-	
+
 	DEBUG_INFO("Load SysConfigData OK\n");
 
 	ShmCharger->isCcsEnable = OFF;
@@ -2431,9 +2431,9 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	#ifdef ENABLE_CCS
 	ShmCharger->isCcsEnable = ON;
 	#endif
-	
+
 	DEBUG_INFO("Is CCS Enable: %s \n",((ShmCharger->isCcsEnable == ON)?"YES":"NO"));
-	
+
 	RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo);
 
 	return PASS;
@@ -3389,8 +3389,8 @@ int isMatchStartUser(unsigned char gun_index)
 		// Big endian
 		switch(rfid.snType)
 		{
-			case RFID_SN_TYPE_6BYTE:
-				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
+			case RFID_SN_TYPE_8BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7]);
 				break;
 			case RFID_SN_TYPE_7BYTE:
 				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
@@ -3409,8 +3409,8 @@ int isMatchStartUser(unsigned char gun_index)
 		// Little endian
 		switch(rfid.snType)
 		{
-			case RFID_SN_TYPE_6BYTE:
-				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+			case RFID_SN_TYPE_8BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
 				break;
 			case RFID_SN_TYPE_7BYTE:
 				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
@@ -3447,8 +3447,8 @@ int isMatchPresentUser()
 		// Big endian
 		switch(rfid.snType)
 		{
-			case RFID_SN_TYPE_6BYTE:
-				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
+			case RFID_SN_TYPE_8BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7]);
 				break;
 			case RFID_SN_TYPE_7BYTE:
 				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
@@ -3467,8 +3467,8 @@ int isMatchPresentUser()
 		// Little endian
 		switch(rfid.snType)
 		{
-			case RFID_SN_TYPE_6BYTE:
-				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+			case RFID_SN_TYPE_8BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
 				break;
 			case RFID_SN_TYPE_7BYTE:
 				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
@@ -3621,7 +3621,7 @@ void setLedMotion(unsigned char gun_index,unsigned char led_mode)
 // Request on/off set
 //===============================================
 void setRequest(unsigned char gun_index,unsigned char isOn)
-{							
+{
 	if(isOn == ON)
 	{
 		if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == OFF)
@@ -3652,7 +3652,7 @@ int getRequest(unsigned char gun_index)
 // Relay on/off set
 //===============================================
 void setRelay(unsigned char gun_index,unsigned char isOn)
-{							
+{
 	if(isOn == ON)
 	{
 		if(ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn == OFF)
@@ -4717,7 +4717,7 @@ void checkChargingProfileLimit(uint8_t gun_index, uint8_t system_mode)
 void checkStopReason(uint8_t gun_index)
 {
 	sleep(2);
-	
+
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		memset(ShmOCPP16Data->StopTransaction[gun_index].IdTag, 0x00, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].IdTag));
@@ -4744,7 +4744,7 @@ void checkStopReason(uint8_t gun_index)
 		else if(ShmCharger->gun_info[gun_index].rfidReq || ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop)
 		{
 			sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
-			
+
 			if(!isMatchStartUser(gun_index))
 			{
 				memcpy((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].IdTag));
@@ -4772,7 +4772,7 @@ void checkStopReason(uint8_t gun_index)
 		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.0);
 		presentChargedEnergyUpdate(gun_index);
 		DEBUG_INFO("Gun-[%d] : PresentChargedEnergy [ %.4f ].\n",gun_index ,ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy);
-		
+
 		ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = ON;
 	}
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
@@ -4801,7 +4801,7 @@ void checkStopReason(uint8_t gun_index)
 		else if(ShmCharger->gun_info[gun_index].rfidReq || ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop)
 		{
 			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "Local");
-			
+
 			if(!isMatchStartUser(gun_index))
 			{
 				memcpy((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, (char*)ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
@@ -4835,7 +4835,7 @@ void checkStopReason(uint8_t gun_index)
 		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.0);
 		presentChargedEnergyUpdate(gun_index);
 		DEBUG_INFO("Gun-[%d] : PresentChargedEnergy [ %.4f ].\n",gun_index ,ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy);
-		
+
 		ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
 	}
 
@@ -4985,8 +4985,8 @@ void checkRfidAuthrize()
 					// Big endian
 					switch(rfid.snType)
 					{
-						case RFID_SN_TYPE_6BYTE:
-							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
+						case RFID_SN_TYPE_8BYTE:
+							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7]);
 							break;
 						case RFID_SN_TYPE_7BYTE:
 							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
@@ -5005,8 +5005,8 @@ void checkRfidAuthrize()
 					// Little endian
 					switch(rfid.snType)
 					{
-						case RFID_SN_TYPE_6BYTE:
-							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+						case RFID_SN_TYPE_8BYTE:
+							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
 							break;
 						case RFID_SN_TYPE_7BYTE:
 							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
@@ -5055,7 +5055,7 @@ void checkRfidAuthrize()
 					ShmCharger->isGetAuthResult = FALSE;
 					isCheckdResult = FALSE;
 				}
-				
+
 				isReadable = FALSE;
 			}
 		}
@@ -5147,7 +5147,7 @@ void checkRfidAuthrize()
 									setSpeaker(ON, SPEAKER_SHORT);
 									ShmCharger->isAuthrizing = FALSE;
 								}
-								
+
 								isReadable = FALSE;
 							}
 						}
@@ -5173,7 +5173,7 @@ void checkRfidAuthrize()
 									break;
 								}
 							}
-							
+
 							isReadable = TRUE;
 						}
 					}
@@ -5649,7 +5649,7 @@ int main(void)
 					ShmCharger->gun_info[gun_index].isRemoteStartWait = ON;
 					DEBUG_INFO("Remote start without connector id... \n");
 				}
-				
+
 				refreshStartTimer(&startTime[gun_index][TMR_IDX_CLEAN_REMOTE_START_WAIT]);
 			}
 			else
@@ -5773,7 +5773,7 @@ int main(void)
 						else
 							setChargerMode(gun_index, SYS_MODE_IDLE);
 
-						// The system identifies 1 phase or 3 phases depending on the model name 
+						// The system identifies 1 phase or 3 phases depending on the model name
 						ShmSysConfigAndInfo->SysConfig.AcPhaseCount = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') ||
 																	   (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') ||
 																	   (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')
@@ -5802,7 +5802,7 @@ int main(void)
 						ShmCharger->gun_info[gun_index].targetCurrent = 0xFF;
 						ocpp_set_unlocker_req(gun_index, OFF);
 						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId = -1;
-						
+
 						// Response StopTransactionConf
 						ocpp_set_stoptransaction_conf(gun_index, OFF);
 						memset(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId));
@@ -6119,7 +6119,7 @@ int main(void)
 									  (!ocpp_get_connection_status() && (isValidLocalWhiteCard() == PASS) && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_LOCALLIST)))
 									{
 										memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
-										
+
 										ShmCharger->gun_info[gun_index].resultAuthorization = VALIDATED_RFID;
 										DEBUG_INFO("Authorize pass [EVCCID].\n");
 										setSpeaker(ON, SPEAKER_SHORT);
@@ -6185,7 +6185,7 @@ int main(void)
 							setRequest(gun_index, ON);
 						}
 					}
-					
+
 					// If control pilot detect Bx, skip watch dog time out.
 					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) ||
 						(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C))
@@ -6534,9 +6534,9 @@ int main(void)
 					{
 						DEBUG_INFO("The connector was connected to the EV before.\n");
 						//Cancel CCS task negotiating
-						ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;	
+						ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;
 						ShmCharger->gun_info[gun_index].acCcsInfo.EVSENotification = NOTIFICATION_STOP;
-						ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;	
+						ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;
 					}
 
 					// Use RFID card to stop handshaking
@@ -6544,9 +6544,9 @@ int main(void)
 					{
 						DEBUG_INFO("Use RFID card to stop handshaking.\n");
 						//Cancel CCS task negotiating
-						ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;	
+						ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;
 						ShmCharger->gun_info[gun_index].acCcsInfo.EVSENotification = NOTIFICATION_STOP;
-						ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;	
+						ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;
 					}
 					else
 					{
@@ -6561,20 +6561,20 @@ int main(void)
 						if(getDiffSecNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > (ShmCharger->timeoutSpec.Present_Timeout_Spec+5))
 						{
 							DEBUG_INFO("Handshaking timeout...\n");
-							
+
 							//Cancel CCS task negotiating
-							ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;	
+							ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;
 							ShmCharger->gun_info[gun_index].acCcsInfo.EVSENotification = NOTIFICATION_STOP;
-							ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;	
+							ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;
 						}
-					}		
+					}
 
 					if((ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty == ON) && ShmCharger->gun_info[gun_index].acCcsInfo.CpSetPWMDuty != CCS_PWM_DUTY_5)
 					{
 						ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_100;
-						ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;	
+						ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
 						ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = OFF;
-						
+
 						setChargerMode(gun_index, SYS_MODE_IDLE);
 					}
 					break;
@@ -6854,7 +6854,7 @@ int main(void)
 							DEBUG_INFO("==============================================================\n");
 							*/
 							refreshStartTimer(&startTime[gun_index][TMR_IDX_REFRESH_CHARGING_INFO]);
-							
+
 							getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
 							DB_Update_Record_Buf(localDb, gun_index);
 						}
@@ -7010,7 +7010,7 @@ int main(void)
 						setRequest(gun_index, OFF);
 						sleep(13);
 					}
-					
+
 					if(((ShmCharger->gun_info[gun_index].chargingMode != CHARGING_MODE_SOCKETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)) ||
 					   ((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_SOCKETE) && (!ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn)) ||
 					   ocpp_get_reset_req())
@@ -7025,7 +7025,7 @@ int main(void)
 						DB_Insert_Record(localDb, gun_index);
 						setChargerMode(gun_index, SYS_MODE_IDLE);
 					}
-					
+
 					break;
 				case SYS_MODE_ALARM:
 					setLedMotion(gun_index,LED_ACTION_ALARM);
@@ -7161,7 +7161,7 @@ int main(void)
 								sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
 								ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
 								DEBUG_WARN("Firmware upgrade fail.\n");
-								
+
 								sleep(5);
 								system("rm -rvf /mnt/* ");
 								close(wtdFd);

+ 12 - 12
EVSE/Projects/AX80/Apps/main.c

@@ -3440,8 +3440,8 @@ int isMatchStartUser(unsigned char gun_index)
 		// Big endian
 		switch(rfid.snType)
 		{
-			case RFID_SN_TYPE_6BYTE:
-				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
+			case RFID_SN_TYPE_8BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7]);
 				break;
 			case RFID_SN_TYPE_7BYTE:
 				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
@@ -3460,8 +3460,8 @@ int isMatchStartUser(unsigned char gun_index)
 		// Little endian
 		switch(rfid.snType)
 		{
-			case RFID_SN_TYPE_6BYTE:
-				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+			case RFID_SN_TYPE_8BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
 				break;
 			case RFID_SN_TYPE_7BYTE:
 				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
@@ -3493,8 +3493,8 @@ int isMatchPresentUser()
 		// Big endian
 		switch(rfid.snType)
 		{
-			case RFID_SN_TYPE_6BYTE:
-				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
+			case RFID_SN_TYPE_8BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7]);
 				break;
 			case RFID_SN_TYPE_7BYTE:
 				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
@@ -3513,8 +3513,8 @@ int isMatchPresentUser()
 		// Little endian
 		switch(rfid.snType)
 		{
-			case RFID_SN_TYPE_6BYTE:
-				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+			case RFID_SN_TYPE_8BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
 				break;
 			case RFID_SN_TYPE_7BYTE:
 				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
@@ -4931,8 +4931,8 @@ void checkRfidAuthrize()
 					// Big endian
 					switch(rfid.snType)
 					{
-						case RFID_SN_TYPE_6BYTE:
-							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
+						case RFID_SN_TYPE_8BYTE:
+							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7]);
 							break;
 						case RFID_SN_TYPE_7BYTE:
 							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
@@ -4951,8 +4951,8 @@ void checkRfidAuthrize()
 					// Little endian
 					switch(rfid.snType)
 					{
-						case RFID_SN_TYPE_6BYTE:
-							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+						case RFID_SN_TYPE_8BYTE:
+							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
 							break;
 						case RFID_SN_TYPE_7BYTE:
 							sprintf((char*)bufferRFID, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);