123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <string.h>
- #include <stdint.h>
- #include "../Config.h"
- #include "../Log/log.h"
- #include "../Define/define.h"
- #include "../ShareMemory/shmMem.h"
- #include "../SelectGun/SelectGun.h"
- #include "main.h"
- #include "../timeout.h"
- static char *rfidPortName = "/dev/ttyS2";
- static DcCommonInfo* ShmDcCommonData = NULL;
- static bool isCardScan = false;
- static bool canStartCharging(void)
- {
- uint8_t index = 0;
- char buf2[16] = "";
- memset(buf2, 0, ARRAY_SIZE(buf2));
- struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
- for (index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
- sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
- }
- sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
-
- if (strcmp(buf2, "Accepted") == EQUAL) {
- return true;
- }
- return false;
- }
- bool isAutorCompleteHandle()
- {
-
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-
-
-
- if (isAuthorizedComplete()) {
-
- if (canStartCharging() == false) {
- strcpy((char *)pSysConfig->UserId, "");
- ClearAuthorizedFlag();
- }
- return true;
- }
- return false;
- }
- bool RfidStopCharging(void)
- {
-
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL ) {
- strcpy((char *)pSysConfig->UserId, "");
- return false;
- }
- struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
- if (pDcChargingInfo->isRemoteStart) {
- } else {
- if (strcmp((char *)pSysConfig->UserId, (char *)pDcChargingInfo->StartUserId) == EQUAL) {
- ChargingTerminalProcess(pSysInfo->CurGunSelected);
- strcpy((char *)pSysConfig->UserId, "");
- log_info("index = %d, card number = %s, UserId = %s ",
- pSysInfo->CurGunSelected,
- pDcChargingInfo->StartUserId,
- pSysConfig->UserId);
- return true;
- } else {
- return false;
- }
- }
- return false;
- }
- static void UserScanFunction(void)
- {
-
-
-
-
-
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-
- struct ChargingInfoData *pDcChargingInfo = NULL;
-
-
- if (IsAuthorizingMode()) {
- isAutorCompleteHandle();
- }
-
- if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL) {
- strcpy((char *)pSysConfig->UserId, "");
- return;
- }
-
-
-
-
- if (pSysInfo->SystemPage == _LCM_MAINTAIN) {
- strcpy((char *)pSysConfig->UserId, "");
- return;
- }
-
- if (strlen((char *)pSysConfig->UserId) <= 0) {
- return;
- }
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-
-
- if (pDcChargingInfo->SystemStatus == S_AUTHORIZING ) {
- log_info("// LCM => Authorizing");
- setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
-
- pSysInfo->SystemPage = _LCM_START_AUTHORIZING;
-
- AuthorizingStart();
- } else {
- strcpy((char *)pSysConfig->UserId, "");
- }
- return;
- }
- bool GetIsCardScan(void)
- {
- return isCardScan;
- }
- void SetIsCardScan(bool value)
- {
- isCardScan = value;
- }
- void AuthorizeToCharge()
- {
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
- struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);
- ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
- if (!isAuthorizedComplete()) {
-
- } else {
- StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
- StartSystemTimeoutDet(Timeout_WaitBalance);
- if (ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance != FAIL_BALANCE_PRICES) {
- StopSystemTimeoutDet();
-
- if (canStartCharging()) {
-
- if (!pDcChargingInfo->ConnectorPlugIn)
- pSysInfo->SystemPage = _LCM_WAIT_PLUGIN;
- log_info("Wait Gun(%d) plugin",pSysInfo->CurGunSelected);
- DetectPluginStart(pSysInfo->CurGunSelected);
- log_info("Gun(%d) Balance: %f",pSysInfo->CurGunSelected,
- ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
- } else {
-
-
- pSysInfo->SystemPage = _LCM_START_AUTHORIZE_FAIL;
- strcpy((char *)pSysConfig->UserId, "");
- ShmDcCommonData->AuthroizeType = IdTokenType_Central;
- }
- }
- ClearAuthorizedFlag();
- }
- }
- 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();
- if (!isDetectPlugin(pSysInfo->CurGunSelected) && pSysInfo->SystemPage == _LCM_START_SCAN &&
- pSysWarning->Level != WARN_LV_ER
- ) {
- isCardScan = true;
-
- UserScanFunction();
- }
- if (pSysInfo->SystemPage == _LCM_START_AUTHORIZING) {
- AuthorizeToCharge();
- } else if (pSysInfo->SystemPage == _LCM_START_AUTHORIZE_FAIL) {
- StartSystemTimeoutDet(Timeout_VerifyFail);
- isCardScan = false;
-
-
- } else {
- isCardScan = false;
- }
- }
- 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 = B19200 | 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;
- }
- void CreateRfidFork(void)
- {
- pid_t rfidRecPid;
- rfidRecPid = fork();
- if (rfidRecPid == 0) {
- int fd = -1;
- int isContinue = 1;
- RFID rfid = {0};
- fd = InitialRfidPort();
- int module_type = MODULE_EWT;
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
-
- while (isContinue) {
- usleep(500000);
-
- if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
- !pSysConfig->isRFID) {
- continue;
- }
- if (getRequestCardSN(fd, module_type, &rfid) == false) {
- continue;
- }
-
- if (strlen((char *)pSysConfig->UserId) != 0) {
- continue;
- }
- if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
- switch (rfid.snType) {
- case RFID_SN_TYPE_6BYTE:
- sprintf((char *) pSysConfig->UserId,
- "%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3],
- rfid.currentCard[4], rfid.currentCard[5]);
- break;
- case RFID_SN_TYPE_7BYTE:
- sprintf((char *) pSysConfig->UserId,
- "%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]);
- break;
- case RFID_SN_TYPE_10BYTE:
- sprintf((char *) pSysConfig->UserId,
- "%02X%02X%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],
- rfid.currentCard[8], rfid.currentCard[9]);
- break;
- case RFID_SN_TYPE_4BYTE:
- sprintf((char *) pSysConfig->UserId,
- "%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3]);
- break;
- }
- } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) {
- switch (rfid.snType) {
- case RFID_SN_TYPE_6BYTE:
- sprintf((char *) pSysConfig->UserId,
- "%02X%02X%02X%02X%02X%02X",
- 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 *) pSysConfig->UserId,
- "%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]);
- break;
- case RFID_SN_TYPE_10BYTE:
- sprintf((char *) pSysConfig->UserId,
- "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[9], rfid.currentCard[8],
- 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_4BYTE:
- sprintf((char *) pSysConfig->UserId,
- "%02X%02X%02X%02X",
- rfid.currentCard[3], rfid.currentCard[2],
- rfid.currentCard[1], rfid.currentCard[0]);
- break;
- }
- }
- log_info("card number = %s", pSysConfig->UserId);
- if (strlen((char*)pSysConfig->UserId) != 0) {
- ShmDcCommonData->AuthroizeType = IdTokenType_ISO14443;
- }
- if (rfid.cardType == ISO14443A) {
- sethaltCard(fd, module_type);
- } else if (rfid.cardType == IS014443B) {
- } else if (rfid.cardType == FELICA) {
- }
- }
- }
- }
|