|
@@ -59,7 +59,8 @@ static uint8_t DeductResultReq[2] = {0};
|
|
|
static int LineStatusCode[2] = {0};
|
|
|
static unsigned int LedIntensity = 0;
|
|
|
static int TimeZoneOffset = 0;
|
|
|
-
|
|
|
+int RxLen;
|
|
|
+char Rxdata[1024];
|
|
|
//------------------------------------------------------------------------------
|
|
|
static void removeFaultCodeToBuf(uint8_t *Code);
|
|
|
static void addFaultCodeToBuf(uint8_t *Code);
|
|
@@ -157,6 +158,23 @@ static int string2ByteArray(char *input, uint8_t *output)
|
|
|
return loop + 1;
|
|
|
}
|
|
|
|
|
|
+int string2Date(char* input, uint8_t* output)
|
|
|
+{
|
|
|
+ int loop = 0;
|
|
|
+ int i = 0;
|
|
|
+
|
|
|
+ while (input[loop] != '\0') {
|
|
|
+ loop++;
|
|
|
+ }
|
|
|
+ loop++;
|
|
|
+
|
|
|
+ while (input[loop] != '\0') {
|
|
|
+ output[i++] = input[loop++];
|
|
|
+ }
|
|
|
+ output[loop] = '\0';
|
|
|
+
|
|
|
+ return loop + 1;
|
|
|
+}
|
|
|
static void unixSocketSigPipeHandle(int sig)
|
|
|
{
|
|
|
log_error("socket packet error %x", sig);
|
|
@@ -181,11 +199,28 @@ static void setTcpStatus(uint8_t setValue)
|
|
|
//------------------------------------------------------------------------------
|
|
|
//--- TCP socket function ---
|
|
|
//------------------------------------------------------------------------------
|
|
|
-static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
|
|
|
+static int sendTcpSocket(int fd, uint8_t* data, uint16_t dataLen)
|
|
|
{
|
|
|
int size = -1;
|
|
|
+ int i;
|
|
|
+ char _info[1024];
|
|
|
+ int len = 0;
|
|
|
+
|
|
|
+ // ReadCmdline show network package
|
|
|
+ if (ShmDcCommonData->showNetPackage) {
|
|
|
+ len = 0;
|
|
|
+ len += sprintf(&_info[len], "Net Tx[%d]:", dataLen);
|
|
|
+ for (i = 0; i < dataLen; i++) {
|
|
|
+ if (i == 0)
|
|
|
+ len += sprintf(&_info[len], "[%X]\t", data[i]);
|
|
|
+ else
|
|
|
+ len += sprintf(&_info[len], "%X ", data[i]);
|
|
|
+ }
|
|
|
+ len += sprintf(&_info[len], "\n");
|
|
|
+ printf("%s", _info);
|
|
|
+ }
|
|
|
|
|
|
- size = send(fd, data, dataLen , 0);
|
|
|
+ size = send(fd, data, dataLen, 0);
|
|
|
if ((size < 0) || (errno == EAGAIN)) {
|
|
|
if (size < 0) {
|
|
|
log_error("Send Socket Size = %d, EAGAIN error %d:%s", size, errno, strerror(errno));
|
|
@@ -195,15 +230,34 @@ static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
|
|
|
return size;
|
|
|
}
|
|
|
|
|
|
-static int recvTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
|
|
|
+static int recvTcpSocket(int fd, uint8_t* data, uint16_t dataLen, uint8_t ishead)
|
|
|
{
|
|
|
int size = -1;
|
|
|
- uint8_t *pdata = (uint8_t *)data;
|
|
|
+ int i;
|
|
|
+ uint8_t* pdata = (uint8_t*)data;
|
|
|
|
|
|
size = recv(fd, pdata, dataLen, MSG_WAITALL);
|
|
|
if ((errno == EAGAIN) || (size < 0)) {
|
|
|
log_error("Receive Socket Size = %d, EAGAIN error %d:%s", size, errno, strerror(errno));
|
|
|
}
|
|
|
+ // ReadCmdline show network package
|
|
|
+ if (ShmDcCommonData->showNetPackage) {
|
|
|
+ if (ishead) {
|
|
|
+ RxLen = 0;
|
|
|
+ RxLen += sprintf(&Rxdata[RxLen], "Net Rx[%d]:", size);
|
|
|
+ }
|
|
|
+ for (i = 0; i < dataLen; i++) {
|
|
|
+ if (ishead && i == 0)
|
|
|
+ RxLen += sprintf(&Rxdata[RxLen], "[%X]\t", data[i]);
|
|
|
+ else
|
|
|
+ RxLen += sprintf(&Rxdata[RxLen], "%X ", data[i]);
|
|
|
+ }
|
|
|
+ if (!ishead) {
|
|
|
+ RxLen += sprintf(&Rxdata[RxLen], "\n");
|
|
|
+ printf("%s", Rxdata);
|
|
|
+ strcpy(Rxdata, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return size;
|
|
|
}
|
|
@@ -427,7 +481,15 @@ static void clearMiscCommand(void)
|
|
|
{
|
|
|
gDoCommGblData.MiscCmd = 0;
|
|
|
}
|
|
|
-
|
|
|
+int timecmp(uint8_t* time1, uint8_t* time2)
|
|
|
+{
|
|
|
+ for (int i = 0; i < strlen(time1); i++) {
|
|
|
+ if (time1[i] != time2[i]) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return TRUE;
|
|
|
+}
|
|
|
static int qrCodeUrlInfoHandle(uint8_t *data)
|
|
|
{
|
|
|
//int len = 0;
|
|
@@ -436,7 +498,8 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
|
|
|
uint16_t timeLen = 0;
|
|
|
struct timeb SeqEndTime;
|
|
|
struct tm *tm;
|
|
|
-
|
|
|
+ char _setTime[50];
|
|
|
+ uint8_t cmdBuf[128];
|
|
|
if ((char *)&data[0] == '\0') {
|
|
|
log_error("QR code date error");
|
|
|
return FAIL;
|
|
@@ -454,19 +517,21 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
|
|
|
tm->tm_min);
|
|
|
|
|
|
//copy QR code string
|
|
|
- if (strncmp((char *)localTime, (char *)&data[0], timeLen - 2) != 0) {
|
|
|
- memset(pSysConfig->SystemId, '\0', sizeof(pSysConfig->SystemId));
|
|
|
- //printf("data = %s", data);
|
|
|
- //len =
|
|
|
+ memset(ShmDcCommonData->QRCodeString, '\0', sizeof(ShmDcCommonData->QRCodeString));
|
|
|
+ //printf("data = %s", data);
|
|
|
+ //len =
|
|
|
|
|
|
- string2ByteArray((char *)data, (uint8_t *)pSysConfig->SystemId);
|
|
|
- //printf("SystemId = %s", pSysConfig->SystemId);
|
|
|
- //log_info("SystemId:%s",pSysConfig->SystemId);
|
|
|
+ string2ByteArray((char *)data, (uint8_t *)ShmDcCommonData->QRCodeString);
|
|
|
+ string2Date((char*)data, (uint8_t*)_setTime);
|
|
|
+ //printf("SystemId = %s", pSysConfig->SystemId);
|
|
|
+ if (!timecmp(localTime, _setTime)) {
|
|
|
+ log_info("Set Timer:%s", _setTime);
|
|
|
+ sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
|
|
|
+ system((char*)cmdBuf);
|
|
|
+ system("hwclock -w -u");
|
|
|
+ system("hwclock -s");
|
|
|
}
|
|
|
- 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");
|
|
@@ -839,7 +904,34 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
|
|
|
case MISC_CMD_TIME_OFFSET:
|
|
|
TimeZoneOffset = value;
|
|
|
log_info("Time Zone Offset: %d", TimeZoneOffset);
|
|
|
- ShmDcCommonData->TzOffset = TimeZoneOffset;
|
|
|
+ ShmDcCommonData->TZOffset = TimeZoneOffset;
|
|
|
+ /*
|
|
|
+ if (TimeZoneOffset == 480) {
|
|
|
+ system("export TZ=CST-8");
|
|
|
+ log_info("Set Time Zone CST 8");
|
|
|
+ }
|
|
|
+ */
|
|
|
+ break;
|
|
|
+ case MISC_CMD_DEFAULT_PRICE_REQ:
|
|
|
+ if (value != YES)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ gMoreInfoReq[plugNum].bits.DefaultPriceReq = YES;
|
|
|
+ break;
|
|
|
+ case MISC_CMD_USER_PRICE_REQ:
|
|
|
+ if (value != YES)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ gMoreInfoReq[plugNum].bits.UserPriceReq = YES;
|
|
|
+ break;
|
|
|
+ case MISC_CMD_RECEIPT_REQ:
|
|
|
+ if (value != YES)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ gMoreInfoReq[plugNum].bits.ReceiptReq = YES;
|
|
|
break;
|
|
|
default:
|
|
|
clearMiscCommand();
|
|
@@ -917,25 +1009,38 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
|
|
|
ShmSelectGunInfo->PricesInfo[plugNum].Balance = transPricesUnit(ntohl(pAccountInfo->Balance));
|
|
|
ShmSelectGunInfo->PricesInfo[plugNum].Discount = transPricesUnit(ntohl(pAccountInfo->Discount));
|
|
|
ShmSelectGunInfo->PricesInfo[plugNum].TransactionId = ntohl(pAccountInfo->Transaction);
|
|
|
+ ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost = transPricesUnit(ntohl(pAccountInfo->EnergyCost));
|
|
|
+ ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee = transPricesUnit(ntohl(pAccountInfo->ParkingFee));
|
|
|
|
|
|
if ((pricesInfo[plugNum].UserPrices != ShmSelectGunInfo->PricesInfo[plugNum].UserPrices) ||
|
|
|
(pricesInfo[plugNum].Balance != ShmSelectGunInfo->PricesInfo[plugNum].Balance) ||
|
|
|
(pricesInfo[plugNum].Discount != ShmSelectGunInfo->PricesInfo[plugNum].Discount) ||
|
|
|
- (pricesInfo[plugNum].TransactionId != ShmSelectGunInfo->PricesInfo[plugNum].TransactionId)) {
|
|
|
+ (pricesInfo[plugNum].TransactionId != ShmSelectGunInfo->PricesInfo[plugNum].TransactionId) ||
|
|
|
+ (pricesInfo[plugNum].EnergyCost != ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost) ||
|
|
|
+ (pricesInfo[plugNum].ParkingFee != ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee)) {
|
|
|
pricesInfo[plugNum].UserPrices = ShmSelectGunInfo->PricesInfo[plugNum].UserPrices;
|
|
|
pricesInfo[plugNum].Balance = ShmSelectGunInfo->PricesInfo[plugNum].Balance;
|
|
|
pricesInfo[plugNum].Discount = ShmSelectGunInfo->PricesInfo[plugNum].Discount;
|
|
|
pricesInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
|
|
|
+ pricesInfo[plugNum].ParkingFee = ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee;
|
|
|
+ pricesInfo[plugNum].EnergyCost = ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost;
|
|
|
+ if (ShmSelectGunInfo->PricesInfo[plugNum].TransactionId != 0) {
|
|
|
|
|
|
- log_info("id = %d, transaction id = %d, user prices = %.2f, Discount = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s",
|
|
|
- plugNum,
|
|
|
- ShmSelectGunInfo->PricesInfo[plugNum].TransactionId,
|
|
|
- ShmSelectGunInfo->PricesInfo[plugNum].UserPrices,
|
|
|
- ShmSelectGunInfo->PricesInfo[plugNum].Discount,
|
|
|
- pDcChargingInfo->ChargingFee,
|
|
|
- ShmSelectGunInfo->PricesInfo[plugNum].Balance,
|
|
|
- (uint8_t *)GetCurrency(pSysConfig->BillingData.Currency)
|
|
|
- );
|
|
|
+ //ShmDcCommonData->TransactionInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
|
|
|
+ //UpdateDeductInfoStatus(plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
|
|
|
+
|
|
|
+ log_info("id = %d, transaction id = %d, user prices = %.2f, Discount = %.2f, Account balances = %.2f, currency = %s",
|
|
|
+ plugNum,
|
|
|
+ ShmSelectGunInfo->PricesInfo[plugNum].TransactionId,
|
|
|
+ ShmSelectGunInfo->PricesInfo[plugNum].UserPrices,
|
|
|
+ ShmSelectGunInfo->PricesInfo[plugNum].Discount,
|
|
|
+ ShmSelectGunInfo->PricesInfo[plugNum].Balance,
|
|
|
+ (uint8_t*)GetCurrency(pSysConfig->BillingData.Currency)
|
|
|
+ );
|
|
|
+ log_info("Total Cost:%.2f", pDcChargingInfo->ChargingFee);
|
|
|
+ log_info("Parking Fee:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee);
|
|
|
+ log_info("Energy Cost:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return PASS;
|
|
@@ -1300,15 +1405,24 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
|
|
|
{
|
|
|
strcpy(&ReservationIdTag[plugNum][0], (char *)&pCsuResult->Data.Data[1]);
|
|
|
}
|
|
|
- if(reservationState != ReservationState[plugNum])
|
|
|
+ if(reservationState != ReservationState[plugNum] ||
|
|
|
+ (strcmp((char*)ShmDcCommonData->pGunInfo[plugNum].ReservationID, (char*)ReservationIdTag[plugNum]) != EQUAL) )
|
|
|
{
|
|
|
log_info("id = %d reservation is %s", pCsuResult->Head.ID, reservationState ? "trigger" : "expired");
|
|
|
if(reservationState)
|
|
|
{
|
|
|
log_info("id = %d reservation idTag: %s", pCsuResult->Head.ID, (char *)&ReservationIdTag[plugNum][0]);
|
|
|
+ pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(plugNum);
|
|
|
+ strcpy(&ShmDcCommonData->pGunInfo[plugNum].ReservationID[0], (char*)&pCsuResult->Data.Data[1]);
|
|
|
+
|
|
|
+ pDcChargingInfo->SystemStatus = S_RESERVATION;
|
|
|
+ } else {
|
|
|
+ if (pDcChargingInfo->SystemStatus == S_RESERVATION && pSysInfo->WaitForPlugit == NO)
|
|
|
+ pDcChargingInfo->SystemStatus = S_IDLE;
|
|
|
}
|
|
|
}
|
|
|
ReservationState[plugNum] = reservationState;
|
|
|
+ ShmDcCommonData->pGunInfo[plugNum].ReservationStatus = reservationState;
|
|
|
break;
|
|
|
|
|
|
case REG_REMOTE_START_NO_ID:
|
|
@@ -1361,7 +1475,69 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
|
|
|
return COMMAND_RESULT_NG;
|
|
|
}
|
|
|
break;
|
|
|
-
|
|
|
+ case REG_READ_CABINET_SYSTEMID:
|
|
|
+ if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
|
|
|
+ return COMMAND_RESULT_NG;
|
|
|
+ }
|
|
|
+ if (strcmp((char*)pSysConfig->SystemId, (char*)pCsuResult->Data.Data) != 0) {
|
|
|
+ strcpy((char*)pSysConfig->SystemId, (char*)pCsuResult->Data.Data);
|
|
|
+ log_info("System ID:%s", pSysConfig->SystemId);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case REG_READ_DEFAULT_PRICE:
|
|
|
+ if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
|
|
|
+ return COMMAND_RESULT_NG;
|
|
|
+ }
|
|
|
+ gMoreInfoReq[plugNum].bits.DefaultPriceReq = NO;
|
|
|
+ if (strcmp((char*)ShmDcCommonData->DefaultPriceString, (char*)pCsuResult->Data.Data) != EQUAL) {
|
|
|
+ strcpy((char*)ShmDcCommonData->DefaultPriceString, (char*)pCsuResult->Data.Data);
|
|
|
+ log_info("Default Price:%s", ShmDcCommonData->DefaultPriceString);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case REG_READ_USER_PRICE:
|
|
|
+ if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
|
|
|
+ return COMMAND_RESULT_NG;
|
|
|
+ }
|
|
|
+ gMoreInfoReq[plugNum].bits.UserPriceReq = NO;
|
|
|
+ if (strcmp((char*)ShmDcCommonData->UserPriceString, (char*)pCsuResult->Data.Data) != EQUAL) {
|
|
|
+ strcpy((char*)ShmDcCommonData->UserPriceString, (char*)pCsuResult->Data.Data);
|
|
|
+ log_info("User Price:%s", ShmDcCommonData->UserPriceString);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case REG_RECEIPT_INFO:
|
|
|
+ if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
|
|
|
+ return COMMAND_RESULT_NG;
|
|
|
+ }
|
|
|
+ gMoreInfoReq[plugNum].bits.ReceiptReq = NO;
|
|
|
+ if (strcmp((char*)ShmDcCommonData->pGunInfo[plugNum].ReceiptInfo, (char*)pCsuResult->Data.Data) != EQUAL) {
|
|
|
+ strcpy((char*)ShmDcCommonData->pGunInfo[plugNum].ReceiptInfo, (char*)pCsuResult->Data.Data);
|
|
|
+ log_info("Gun%d Receipt:%s", plugNum, ShmDcCommonData->pGunInfo[plugNum].ReceiptInfo);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case REG_POWER_CONSUMPTION_INFO:
|
|
|
+ if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
|
|
|
+ return COMMAND_RESULT_NG;
|
|
|
+ }
|
|
|
+
|
|
|
+ PowConsumValue* pValue =NULL;
|
|
|
+ pValue = (PowConsumValue*)&pCsuResult->Data.Data[0];
|
|
|
+
|
|
|
+ pValue->Gun1_Consumption = ntohl(pValue->Gun1_Consumption);
|
|
|
+ pValue->Gun2_Consumption = ntohl(pValue->Gun2_Consumption);
|
|
|
+ pValue->Gun3_Consumption = ntohl(pValue->Gun3_Consumption);
|
|
|
+ pValue->Gun4_Consumption = ntohl(pValue->Gun4_Consumption);
|
|
|
+ memcpy((char*)&ShmDcCommonData->pConsumption.Gun1_Consumption, (char*)&pValue->Gun1_Consumption, sizeof(uint32_t));
|
|
|
+ memcpy((char*)&ShmDcCommonData->pConsumption.Gun2_Consumption, (char*)&pValue->Gun2_Consumption, sizeof(uint32_t));
|
|
|
+ memcpy((char*)&ShmDcCommonData->pConsumption.Gun3_Consumption, (char*)&pValue->Gun3_Consumption, sizeof(uint32_t));
|
|
|
+ memcpy((char*)&ShmDcCommonData->pConsumption.Gun4_Consumption, (char*)&pValue->Gun4_Consumption, sizeof(uint32_t));
|
|
|
+
|
|
|
+ log_info("Gun1_Consumption:%f", ShmDcCommonData->pConsumption.Gun1_Consumption);
|
|
|
+ log_info("Gun2_Consumption:%f", ShmDcCommonData->pConsumption.Gun2_Consumption);
|
|
|
+ log_info("Gun3_Consumption:%f", ShmDcCommonData->pConsumption.Gun3_Consumption);
|
|
|
+ log_info("Gun4_Consumption:%f", ShmDcCommonData->pConsumption.Gun4_Consumption);
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -1400,11 +1576,6 @@ static int composeSocketData(int fd,
|
|
|
|
|
|
// Not Let ask cabinet version trasmit into FAIL Network
|
|
|
|
|
|
- if (reg == REG_CABINET_DCM_VERSION || reg == REG_CABINET_OTHER_VERSION ||
|
|
|
- reg == REG_TOTAL_PSU_QUANTITY || reg == REG_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);
|
|
@@ -1413,14 +1584,19 @@ static int composeSocketData(int fd,
|
|
|
}
|
|
|
|
|
|
//receive result head
|
|
|
- if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head))) < 0) {
|
|
|
+ if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head),1)) < 0) {
|
|
|
log_error("TCP socket RX head fail = %d", size);
|
|
|
- gDoCommGblData.DisConnCount++;
|
|
|
+ // 若收不到以下封包,不產生錯誤
|
|
|
+ if (reg != REG_CABINET_DCM_VERSION && reg != REG_CABINET_OTHER_VERSION &&
|
|
|
+ reg != REG_TOTAL_PSU_QUANTITY && reg != REG_PSU_VERSION &&
|
|
|
+ reg != REG_READ_CABINET_SYSTEMID) {
|
|
|
+ gDoCommGblData.DisConnCount++;
|
|
|
+ }
|
|
|
return FAIL;
|
|
|
}
|
|
|
|
|
|
//receive result raw data
|
|
|
- if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen)) < 0) {
|
|
|
+ if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen,0)) < 0) {
|
|
|
log_error("TCP socket RX data fail = %d", size);
|
|
|
gDoCommGblData.DisConnCount++;
|
|
|
return FAIL;
|
|
@@ -1514,12 +1690,12 @@ static int readChargerStationInfo(int fd)
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
-
|
|
|
+/*
|
|
|
static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactionInfo *transactionInfo)
|
|
|
{
|
|
|
int ret = PASS;
|
|
|
- uint8_t dataBuf[22] = {0};
|
|
|
- int i;
|
|
|
+ uint8_t dataBuf[104] = {0};
|
|
|
+ //int i;
|
|
|
|
|
|
memset((char *)dataBuf, 0x00, sizeof(dataBuf));
|
|
|
dataBuf[0] = transactionInfo->DeductResult;
|
|
@@ -1535,28 +1711,33 @@ static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactio
|
|
|
dataBuf[7] = (amount >> 16) & 0xFF;
|
|
|
dataBuf[8] = (amount >> 8) & 0xFF;
|
|
|
dataBuf[9] = (amount & 0xFF);
|
|
|
- memcpy((char *)&dataBuf[10], transactionInfo->ApprovalNo,9);
|
|
|
- /*
|
|
|
- for(i=0;i<22;i++) {
|
|
|
- log_info("dataBuf[%d]:0x%x",i,dataBuf[i]);
|
|
|
- }
|
|
|
- */
|
|
|
- log_info("Gun[%d] TransactionId:%d DeductResult:%d IsDonateInvoice:%d Amount:%f",
|
|
|
- gunIndex,transactionInfo->TransactionId,transactionInfo->DeductResult,transactionInfo->IsDonateInvoice,transactionInfo->Amount);
|
|
|
+ memcpy((char *)&dataBuf[10], transactionInfo->pCreditCard.ApprovalNo,9);
|
|
|
+ memcpy((char *)&dataBuf[19], transactionInfo->pCreditCard.VemData, 64);
|
|
|
+ memcpy((char*)&dataBuf[83], transactionInfo->pCreditCard.CardNo, 20);
|
|
|
+
|
|
|
+ log_info("Gun[%d] TransactionId:%d DeductResult:%d IsDonateInvoice:%d Amount:%f Approva Num:'%s' VemData:'%s' CardNo:'%s'",
|
|
|
+ transactionInfo->ConnectorID,
|
|
|
+ transactionInfo->TransactionId,
|
|
|
+ transactionInfo->DeductResult,
|
|
|
+ transactionInfo->IsDonateInvoice,
|
|
|
+ transactionInfo->Amount,
|
|
|
+ transactionInfo->pCreditCard.ApprovalNo,
|
|
|
+ transactionInfo->pCreditCard.VemData,
|
|
|
+ transactionInfo->pCreditCard.CardNo);
|
|
|
// copy deduct result to dataBuf here
|
|
|
|
|
|
if ((ret = composeSocketData(fd,
|
|
|
id,
|
|
|
OP_WRITE_DATA,
|
|
|
REG_DEDUCT_INFO,
|
|
|
- 22,
|
|
|
+ 104,
|
|
|
&dataBuf[0])) == FAIL) {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
-
|
|
|
+*/
|
|
|
static int writeWaitPlugItState(int fd, uint8_t id)
|
|
|
{
|
|
|
int ret = PASS;
|
|
@@ -1714,13 +1895,18 @@ static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
|
|
|
if ((strlen((char *)pUserID) <= 0) || (pUserID == NULL)) {
|
|
|
return FAIL;
|
|
|
}
|
|
|
-
|
|
|
+ uint8_t data[50];
|
|
|
+ int datalen = strlen((char*)pUserID);
|
|
|
+ memcpy((uint8_t*)data, pUserID, datalen);
|
|
|
+ data[datalen] = '\0';
|
|
|
+ data[datalen+1] = ShmDcCommonData->AuthroizeType;
|
|
|
+ datalen += 2;
|
|
|
return composeSocketData(fd,
|
|
|
id,
|
|
|
OP_WRITE_DATA,
|
|
|
REG_USER_ID,
|
|
|
- strlen((char *)pUserID),
|
|
|
- pUserID);
|
|
|
+ datalen,
|
|
|
+ &data[0]);
|
|
|
}
|
|
|
|
|
|
static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
|
|
@@ -1919,6 +2105,21 @@ static int readCabinetEachPSUVersion(int fd, uint8_t id,uint8_t n_psu)
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
+
|
|
|
+static int readReceiptInfo(int fd, uint8_t id)
|
|
|
+{
|
|
|
+ int ret = PASS;
|
|
|
+
|
|
|
+ ret = composeSocketData(fd,
|
|
|
+ id,
|
|
|
+ OP_READ_DATA,
|
|
|
+ REG_RECEIPT_INFO,
|
|
|
+ 0,
|
|
|
+ NULL);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
static int writeDispenserStatus(int fd, uint8_t gunID)
|
|
|
{
|
|
|
uint8_t warningCount = 0;
|
|
@@ -1983,7 +2184,58 @@ static int readConnectorID(int fd)
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
+static int readSystemID(int fd)
|
|
|
+{
|
|
|
+ int ret = PASS;
|
|
|
+
|
|
|
+ ret = composeSocketData(fd,
|
|
|
+ ID_REGISTER,
|
|
|
+ OP_READ_DATA,
|
|
|
+ REG_READ_CABINET_SYSTEMID,
|
|
|
+ 0,
|
|
|
+ NULL);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+static int readDefaultPrice(int fd)
|
|
|
+{
|
|
|
+ int ret = PASS;
|
|
|
+
|
|
|
+ ret = composeSocketData(fd,
|
|
|
+ ID_REGISTER,
|
|
|
+ OP_READ_DATA,
|
|
|
+ REG_READ_DEFAULT_PRICE,
|
|
|
+ 0,
|
|
|
+ NULL);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+static int readUserPrice(int fd, uint8_t gunID)
|
|
|
+{
|
|
|
+ int ret = PASS;
|
|
|
+
|
|
|
+ ret = composeSocketData(fd,
|
|
|
+ gunID,
|
|
|
+ OP_READ_DATA,
|
|
|
+ REG_READ_USER_PRICE,
|
|
|
+ 0,
|
|
|
+ NULL);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+static int readConsumptionInfo(int fd)
|
|
|
+{
|
|
|
+ int ret = PASS;
|
|
|
+
|
|
|
+ ret = composeSocketData(fd,
|
|
|
+ ID_REGISTER,
|
|
|
+ OP_READ_DATA,
|
|
|
+ REG_POWER_CONSUMPTION_INFO,
|
|
|
+ 0,
|
|
|
+ NULL);
|
|
|
|
|
|
+ return ret;
|
|
|
+}
|
|
|
static int WriteModelName(int fd)
|
|
|
{
|
|
|
int ret = PASS;
|
|
@@ -2182,9 +2434,9 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
|
|
|
if (readChargingCapability(fd, gunID) == PASS) {
|
|
|
gMoreInfoReq[plugNum].bits.FinalCostReq = false;
|
|
|
pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
|
|
|
- ShmDcCommonData->finalcost[plugNum] = pDcChargingInfo->ChargingFee;
|
|
|
- ShmDcCommonData->finalcost_flag[plugNum] = TRUE;
|
|
|
- log_info("Gun %d get final cost %d", plugNum, pDcChargingInfo->ChargingFee);
|
|
|
+ //ShmDcCommonData->TransactionInfo[plugNum].Amount = pDcChargingInfo->ChargingFee;
|
|
|
+ ShmDcCommonData->pGunInfo[plugNum].finalcost_flag = TRUE;
|
|
|
+ log_info("Gun %d get final cost %f", plugNum, pDcChargingInfo->ChargingFee);
|
|
|
}
|
|
|
}
|
|
|
curReg = REG_PLUG_IN_STATE;
|
|
@@ -2232,9 +2484,39 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
|
|
|
writeConnectorState(fd, plugNum, gunID);
|
|
|
ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
}
|
|
|
- curReg = REG_QRCODE_URL_INFO;
|
|
|
+ curReg = REG_DISPENSER_REQUEST;
|
|
|
break;
|
|
|
+ case REG_DISPENSER_REQUEST:
|
|
|
+ /*
|
|
|
+ gConnectorActReq[plugNum].bits.ChargingCancel = ShmDcCommonData->OperateIDLE[plugNum];
|
|
|
+ if (gConnectorActReq[plugNum].Value != 0)
|
|
|
+ {
|
|
|
+ if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
+ DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
|
|
|
+ if (writeDispenserRequest(fd, gunID, plugNum) == PASS)
|
|
|
+ {
|
|
|
+ gConnectorActReq[plugNum].Value = 0;
|
|
|
+ log_info("Gun %d CHARGING_CANCEL OK", plugNum);
|
|
|
+ ShmDcCommonData->OperateIDLE[plugNum] = 0;
|
|
|
+ }
|
|
|
+ ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+ curReg = REG_QRCODE_URL_INFO;
|
|
|
+ break;
|
|
|
+ case REG_QRCODE_URL_INFO:
|
|
|
+ if (gunID == 1) {
|
|
|
+ if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
|
|
|
+ DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0
|
|
|
+ ) {
|
|
|
+ readQRcodeURLAndSystemDate(fd);
|
|
|
+ ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ curReg = REG_READ_CABINET_SYSTEMID;
|
|
|
+ break;
|
|
|
//case REG_USER_ID:
|
|
|
// writeUserID(fd, gunID, uint8_t *pUserID);
|
|
|
// break;
|
|
@@ -2278,29 +2560,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
|
|
|
//case REG_PRESENT_CHARGING_INFO:
|
|
|
// break;
|
|
|
|
|
|
- case REG_QRCODE_URL_INFO:
|
|
|
- if (gunID == 1) {
|
|
|
- if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
|
|
|
- DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0
|
|
|
- ) {
|
|
|
- readQRcodeURLAndSystemDate(fd);
|
|
|
- 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 if (gMoreInfoReq[plugNum].Value != 0) {
|
|
|
- curReg = REG_RESERVATION_IDTAG;
|
|
|
- } else {
|
|
|
- isContinue = 0;
|
|
|
- }
|
|
|
- //curReg = REG_SOFTWARE_UPDATE;
|
|
|
- break;
|
|
|
|
|
|
//case REG_WAIT_PLUG_IT_STATE:
|
|
|
// if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME / 10)) {
|
|
@@ -2322,56 +2582,119 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
|
|
|
//case REG_PSU_VERSION:
|
|
|
// break;
|
|
|
|
|
|
+
|
|
|
+ //case REG_DISPENSER_REQUEST:
|
|
|
+ // break;
|
|
|
+
|
|
|
+
|
|
|
+ case REG_READ_CABINET_SYSTEMID:
|
|
|
+ if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
+ DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
+ readSystemID(fd);
|
|
|
+ ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
+ }
|
|
|
+ curReg = REG_POWER_CONSUMPTION_INFO;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case REG_POWER_CONSUMPTION_INFO:
|
|
|
+ if (pSysConfig->ShowInformation || ShmDcCommonData->DebugFlag) {
|
|
|
+ if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
+ DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
+ readConsumptionInfo(fd);
|
|
|
+ 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 if (gMoreInfoReq[plugNum].Value != 0) {
|
|
|
+ curReg = REG_RESERVATION_IDTAG;
|
|
|
+ } else {
|
|
|
+ isContinue = 0;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
case REG_RESERVATION_IDTAG:
|
|
|
- if(gMoreInfoReq[plugNum].bits.ReservationReq)
|
|
|
+ if (gMoreInfoReq[plugNum].bits.ReservationReq)
|
|
|
{
|
|
|
if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
- DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
- if(readReservationState(fd, gunID) == PASS)
|
|
|
+ DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
+ if (readReservationState(fd, gunID) == PASS)
|
|
|
{
|
|
|
gMoreInfoReq[plugNum].bits.ReservationReq = ReservationState[plugNum] == NO ? NO : YES;
|
|
|
}
|
|
|
ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
}
|
|
|
}
|
|
|
- curReg = REG_DISPENSER_REQUEST;
|
|
|
+ curReg = REG_REMOTE_START_NO_ID;
|
|
|
break;
|
|
|
-
|
|
|
- //case REG_DISPENSER_REQUEST:
|
|
|
- // break;
|
|
|
- case REG_DISPENSER_REQUEST:
|
|
|
- if (gConnectorActReq[plugNum].Value != 0)
|
|
|
- {
|
|
|
- if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
- DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (writeDispenserRequest(fd, gunID, plugNum) == PASS)
|
|
|
- {
|
|
|
- gConnectorActReq[plugNum].Value = 0;
|
|
|
- log_info("Gun %d CHARGING_CANCEL OK");
|
|
|
- }
|
|
|
- ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
- }
|
|
|
- }
|
|
|
- curReg = REG_REMOTE_START_NO_ID;
|
|
|
- break;
|
|
|
case REG_REMOTE_START_NO_ID:
|
|
|
- if(gMoreInfoReq[plugNum].bits.RemoteStartNoID)
|
|
|
+ if (gMoreInfoReq[plugNum].bits.RemoteStartNoID)
|
|
|
{
|
|
|
if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
- DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
- if(readRemoteStartNoIDState(fd) == PASS)
|
|
|
+ DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
+ if (readRemoteStartNoIDState(fd) == PASS)
|
|
|
{
|
|
|
gMoreInfoReq[plugNum].bits.RemoteStartNoID = RemoteStartNoIDState == NO ? NO : YES;
|
|
|
}
|
|
|
ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
}
|
|
|
}
|
|
|
- curReg = REG_REFUND_AMOUNT;
|
|
|
+ curReg = REG_STATION_INFO;
|
|
|
break;
|
|
|
+ case REG_STATION_INFO:
|
|
|
+ if (gMoreInfoReq[plugNum].bits.StationInfoReq)
|
|
|
+ {
|
|
|
+ if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
+ DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
|
|
|
+ if (readChargerStationInfo(fd) == PASS)
|
|
|
+ {
|
|
|
+ gMoreInfoReq[plugNum].bits.StationInfoReq = NO;
|
|
|
+ }
|
|
|
+ ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //isContinue = 0;
|
|
|
+ curReg = REG_READ_DEFAULT_PRICE;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case REG_READ_DEFAULT_PRICE:
|
|
|
+ if (gMoreInfoReq[plugNum].bits.DefaultPriceReq)
|
|
|
+ {
|
|
|
+ if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
+ DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
+ readDefaultPrice(fd);
|
|
|
+ ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ curReg = REG_READ_USER_PRICE;
|
|
|
+ break;
|
|
|
+ case REG_READ_USER_PRICE:
|
|
|
+ if (gMoreInfoReq[plugNum].bits.UserPriceReq)
|
|
|
+ {
|
|
|
+ if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
+ DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
+ readUserPrice(fd,gunID);
|
|
|
+ ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ curReg = REG_RECEIPT_INFO;
|
|
|
+ break;
|
|
|
+ case REG_RECEIPT_INFO:
|
|
|
+ if (gMoreInfoReq[plugNum].bits.ReceiptReq)
|
|
|
+ {
|
|
|
+ if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
+ DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
+ readReceiptInfo(fd, gunID);
|
|
|
+ ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ curReg = REG_REFUND_AMOUNT;
|
|
|
+ break;
|
|
|
case REG_REFUND_AMOUNT:
|
|
|
curReg = REG_PREPAYMENT_INFO;
|
|
|
break;
|
|
@@ -2385,25 +2708,10 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
|
|
|
break;
|
|
|
|
|
|
case REG_CONNECTOR_QR_CODE:
|
|
|
- curReg = REG_STATION_INFO;
|
|
|
- break;
|
|
|
-
|
|
|
- case REG_STATION_INFO:
|
|
|
- if(gMoreInfoReq[plugNum].bits.StationInfoReq)
|
|
|
- {
|
|
|
- if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
|
|
|
- DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
|
|
|
-
|
|
|
- if(readChargerStationInfo(fd) == PASS)
|
|
|
- {
|
|
|
- gMoreInfoReq[plugNum].bits.StationInfoReq = NO;
|
|
|
- }
|
|
|
- ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
- }
|
|
|
- }
|
|
|
isContinue = 0;
|
|
|
break;
|
|
|
|
|
|
+
|
|
|
default:
|
|
|
log_error("error curReg = %x", curReg);
|
|
|
gDoCommGblData.MiscCmd = 0;
|
|
@@ -2791,6 +3099,7 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
|
|
|
+ system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
|
|
|
sprintf(tmpbuf,
|
|
|
"/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
|
|
|
pSysConfig->SystemId);
|