|
@@ -405,6 +405,272 @@ static char * UnitOfMeasureStr[] = {
|
|
|
MACROSTR(K),
|
|
|
MACROSTR(Percent)
|
|
|
};
|
|
|
+//=========================================
|
|
|
+// TTIA routine
|
|
|
+//=========================================
|
|
|
+int sendTTIAInfo(uint8_t gun_index)
|
|
|
+{
|
|
|
+ static int sn = 0;
|
|
|
+
|
|
|
+ int result = FAIL;
|
|
|
+ struct hostent *server;
|
|
|
+ int udp_socket_fd;
|
|
|
+ struct sockaddr_in dest_addr = {0};
|
|
|
+
|
|
|
+ uint8_t tx_buf[80] = {0};
|
|
|
+ uint8_t logBuf[256]= {0};
|
|
|
+ uint8_t tempIndex, socStart, socEnd;
|
|
|
+ uint16_t PresentChargedEnergy;
|
|
|
+ struct tm tmStart, tmEnd;
|
|
|
+
|
|
|
+ DEBUG_INFO("sendTTIAInfo...\n");
|
|
|
+
|
|
|
+ if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
|
|
|
+ {
|
|
|
+ if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
|
|
|
+ {
|
|
|
+ tempIndex = ((gun_index==2) ? 1: 0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tempIndex = gun_index;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int index = 0; index < CHAdeMO_QUANTITY; index++)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
|
|
|
+ {
|
|
|
+ socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
|
|
|
+ socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
|
|
|
+ PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(gunType[gun_index] == GUN_TYPE_CCS)
|
|
|
+ {
|
|
|
+
|
|
|
+ if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
|
|
|
+ {
|
|
|
+ tempIndex = ((gun_index==2) ? 1: 0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tempIndex = gun_index;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int index = 0; index < CCS_QUANTITY; index++)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
|
|
|
+ {
|
|
|
+ socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
|
|
|
+ socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
|
|
|
+ PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(gunType[gun_index] == GUN_TYPE_GBT)
|
|
|
+ {
|
|
|
+
|
|
|
+ if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
|
|
|
+ {
|
|
|
+ tempIndex = ((gun_index==2) ? 1: 0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tempIndex = gun_index;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (int index = 0; index < GB_QUANTITY; index++)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
|
|
|
+ {
|
|
|
+ socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
|
|
|
+ socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
|
|
|
+ PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(gunType[gun_index] == GUN_TYPE_DO)
|
|
|
+ {
|
|
|
+ tempIndex = gun_index;
|
|
|
+
|
|
|
+ for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
|
|
|
+ {
|
|
|
+ socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
|
|
|
+ socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
|
|
|
+ PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
|
|
|
+ {
|
|
|
+ tempIndex = 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tempIndex = gun_index;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int index = 0; index < AC_QUANTITY; index++)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
|
|
|
+ {
|
|
|
+ socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
|
|
|
+ socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
|
|
|
+ PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
|
|
|
+ }
|
|
|
+ }// END
|
|
|
+ }
|
|
|
+
|
|
|
+ // Message assembly
|
|
|
+ sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
|
|
|
+ tx_buf[4] = 0x02; // Protocol Version
|
|
|
+ tx_buf[5] = 0xb0; // Message ID
|
|
|
+ tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
|
|
|
+ tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
|
|
|
+ tx_buf[8] = 0x00; // CarID low byte
|
|
|
+ tx_buf[9] = 0x00; // CarID high byte
|
|
|
+ tx_buf[10] = 0x00; // ID Storage
|
|
|
+ tx_buf[11] = 0x00; // Driver lowest byte
|
|
|
+ tx_buf[12] = 0x00; // Driver 2nd byte
|
|
|
+ tx_buf[13] = 0x00; // Driver 3rd byte
|
|
|
+ tx_buf[14] = 0x00; // Driver highest byte
|
|
|
+ tx_buf[15] = sn & 0xff; // Sequence SN low byte
|
|
|
+ tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
|
|
|
+ tx_buf[17] = 0x00; // Reserve
|
|
|
+ tx_buf[18] = 60 & 0xff; // Payload length low byte
|
|
|
+ tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
|
|
|
+
|
|
|
+ // EVSE provider
|
|
|
+ memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
|
|
|
+
|
|
|
+ // EVSE provider
|
|
|
+ tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
|
|
|
+
|
|
|
+ // EVSE id
|
|
|
+ tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
|
|
|
+
|
|
|
+ // Connector id
|
|
|
+ tx_buf[37] = gun_index;
|
|
|
+
|
|
|
+ // EVSE station
|
|
|
+ memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
|
|
|
+
|
|
|
+ // Vehicle SN
|
|
|
+ memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
|
|
|
+
|
|
|
+ // Mileage
|
|
|
+ tx_buf[61] = 0x00; // lowest byte
|
|
|
+ tx_buf[62] = 0x00; // 2nd byte
|
|
|
+ tx_buf[63] = 0x00; // highest byte
|
|
|
+
|
|
|
+ // Start date time 6 bytes
|
|
|
+ if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
|
|
|
+ {
|
|
|
+ tx_buf[64] = (tmStart.tm_year-2000);
|
|
|
+ tx_buf[65] = tmStart.tm_mon;
|
|
|
+ tx_buf[66] = tmStart.tm_mday;
|
|
|
+ tx_buf[67] = tmStart.tm_hour;
|
|
|
+ tx_buf[68] = tmStart.tm_min;
|
|
|
+ tx_buf[69] = tmStart.tm_sec;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Stop date time 6 bytes
|
|
|
+ if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
|
|
|
+ {
|
|
|
+ tx_buf[70] = (tmEnd.tm_year-2000);
|
|
|
+ tx_buf[71] = tmEnd.tm_mon;
|
|
|
+ tx_buf[72] = tmEnd.tm_mday;
|
|
|
+ tx_buf[73] = tmEnd.tm_hour;
|
|
|
+ tx_buf[74] = tmEnd.tm_min;
|
|
|
+ tx_buf[75] = tmEnd.tm_sec;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Session energy 2 bytes
|
|
|
+ tx_buf[76] = PresentChargedEnergy & 0xff;
|
|
|
+ tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
|
|
|
+
|
|
|
+ // Start SOC 1 byte
|
|
|
+ tx_buf[78] = socStart;
|
|
|
+
|
|
|
+ // Stop SOC 1 byte
|
|
|
+ tx_buf[79] = socEnd;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // Open socket
|
|
|
+ udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
+ if(udp_socket_fd == -1)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("UDP socket create failed!\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Get server DNS entry
|
|
|
+ server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
|
|
|
+ if (server == NULL)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Build the server's Internet address
|
|
|
+ bzero((char *) &dest_addr, sizeof(dest_addr));
|
|
|
+ dest_addr.sin_family = AF_INET;
|
|
|
+ bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
|
|
|
+ dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
|
|
|
+
|
|
|
+ if(sendto(udp_socket_fd, tx_buf, strlen((char*)tx_buf), 0, &dest_addr, sizeof(dest_addr)) >= 0)
|
|
|
+ {
|
|
|
+ for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
|
|
|
+ {
|
|
|
+ sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
|
|
|
+ }
|
|
|
+ DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
|
|
|
+ DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
|
|
|
+ DEBUG_TTIA_INFO("----- Header -----\n");
|
|
|
+ DEBUG_TTIA_INFO("ProtocolID: APTS\n");
|
|
|
+ DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
|
|
|
+ DEBUG_TTIA_INFO("MessageID: 0xB0\n");
|
|
|
+ DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
|
|
|
+ DEBUG_TTIA_INFO("CarID: 0x0000\n");
|
|
|
+ DEBUG_TTIA_INFO("IDStorage: 0x00\n");
|
|
|
+ DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
|
|
|
+ DEBUG_TTIA_INFO("Sequence: %d\n", sn);
|
|
|
+ DEBUG_TTIA_INFO("Reserved: 0x00\n");
|
|
|
+ DEBUG_TTIA_INFO("Len: 80\n");
|
|
|
+ DEBUG_TTIA_INFO("----- Payload -----\n");
|
|
|
+ DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
|
|
|
+ DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
|
|
|
+ DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
|
|
|
+ DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
|
|
|
+ DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
|
|
|
+ DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
|
|
|
+ DEBUG_TTIA_INFO("EV mileage: 000000\n");
|
|
|
+ DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
|
|
|
+ DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
|
|
|
+ DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
|
|
|
+ DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
|
|
|
+ DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
|
|
|
+ DEBUG_TTIA_INFO("==================================\n");
|
|
|
+ sn++;
|
|
|
+ result = PASS;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("UDP sent out fail.\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
|
|
|
//=========================================
|
|
|
// Save configuration
|
|
@@ -3482,6 +3748,7 @@ void CheckSystemValue(void)
|
|
|
{
|
|
|
ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
|
|
|
sendStopTransactionRequest(gun_index);
|
|
|
+ if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
|
|
|
clientTime.StopTransaction = time((time_t*)NULL);
|
|
|
}
|
|
|
|