|
@@ -78,7 +78,7 @@ struct Charger *ShmCharger;
|
|
|
struct timeb startTime[AC_QUANTITY][10];
|
|
|
struct timeb startChargingTime[AC_QUANTITY];
|
|
|
struct timeb endChargingTime[AC_QUANTITY];
|
|
|
-
|
|
|
+sqlite3 *localDb;
|
|
|
|
|
|
//=================================
|
|
|
// Common routine
|
|
@@ -184,6 +184,17 @@ int DiffTimeb(struct timeb ST, struct timeb ET)
|
|
|
return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
|
|
|
}
|
|
|
|
|
|
+void getDateTimeString(char* result)
|
|
|
+{
|
|
|
+ time_t CurrentTime;
|
|
|
+ struct tm *tm;
|
|
|
+
|
|
|
+ CurrentTime = time(NULL);
|
|
|
+ tm=localtime(&CurrentTime);
|
|
|
+
|
|
|
+ sprintf(result, "%04d.%02d.%02d %02d:%02d:%02d", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
|
|
|
+}
|
|
|
+
|
|
|
//======================================================
|
|
|
// Check interface status
|
|
|
//======================================================
|
|
@@ -393,6 +404,96 @@ int CreatShareMemory()
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+//===============================================
|
|
|
+// SQLite3 related routine
|
|
|
+//===============================================
|
|
|
+int DB_Open(sqlite3 *db)
|
|
|
+{
|
|
|
+ int result = PASS;
|
|
|
+ char* errMsg = NULL;
|
|
|
+ char* createSql="CREATE TABLE IF NOT EXISTS charging_record("
|
|
|
+ "idx integer primary key AUTOINCREMENT, "
|
|
|
+ "reservationId text, "
|
|
|
+ "transactionId text, "
|
|
|
+ "startMethod text, "
|
|
|
+ "userId text, "
|
|
|
+ "dateTimeStart text, "
|
|
|
+ "dateTimeStop text,"
|
|
|
+ "socStart text, "
|
|
|
+ "socStop text, "
|
|
|
+ "chargeEnergy text, "
|
|
|
+ "stopReason text"
|
|
|
+ ");";
|
|
|
+
|
|
|
+ //sqlite3_config(SQLITE_CONFIG_URI, 1);
|
|
|
+ if(sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Can't open database: %s\r\n", sqlite3_errmsg(db));
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Local charging record database open successfully.\r\n");
|
|
|
+ if (sqlite3_exec(db, createSql, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Create local charging record table error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Opened local charging record table successfully\n");
|
|
|
+ }
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+int DB_Insert_Record(sqlite3 *db, int gun_index)
|
|
|
+{
|
|
|
+ int result = PASS;
|
|
|
+ char* errMsg = NULL;
|
|
|
+ char insertSql[1024];
|
|
|
+
|
|
|
+ sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
|
|
|
+ "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
|
|
|
+ ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
|
|
|
+ ShmOCPP16Data->StopTransaction[gun_index].StopReason);
|
|
|
+
|
|
|
+ if(sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Can't open database: %s\r\n", sqlite3_errmsg(db));
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Local charging record database open successfully.\r\n");
|
|
|
+ if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Insert local charging record error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Insert local charging record successfully\n");
|
|
|
+ }
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
//======================================================
|
|
|
// Peripheral initial
|
|
|
//======================================================
|
|
@@ -778,6 +879,8 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
|
|
|
|
|
|
int Initialization()
|
|
|
{
|
|
|
+ int result = PASS;
|
|
|
+
|
|
|
LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
|
|
|
|
|
|
InitGPIO();
|
|
@@ -786,9 +889,15 @@ int Initialization()
|
|
|
|
|
|
rfidFd = InitRfidPort();
|
|
|
|
|
|
- DEBUG_INFO("Initialization OK\r\n");
|
|
|
+ if((DB_Open(localDb) != PASS) || (rfidFd < 0))
|
|
|
+ result = FAIL;
|
|
|
|
|
|
- return PASS;
|
|
|
+ if(result == PASS)
|
|
|
+ DEBUG_INFO("Initialization OK.\r\n");
|
|
|
+ else
|
|
|
+ DEBUG_INFO("Initialization Fail.\r\n");
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
//=====================================================
|
|
@@ -1623,7 +1732,6 @@ int main(void)
|
|
|
ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = 0;
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
|
|
|
- setLedMotion(gun_index,LED_ACTION_IDLE);
|
|
|
}
|
|
|
|
|
|
if(((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)) ||
|
|
@@ -1756,7 +1864,6 @@ int main(void)
|
|
|
|
|
|
if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH)
|
|
|
{
|
|
|
-
|
|
|
// Authorization timeout process.
|
|
|
ShmCharger->gun_info[gun_index].rfidReq = OFF;
|
|
|
setChargerMode(gun_index, SYS_MODE_IDLE);
|
|
@@ -1823,7 +1930,9 @@ int main(void)
|
|
|
else if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
|
|
|
{
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].OutputEnergy = 0;
|
|
|
- ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ((float)ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
|
|
|
+ getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime);
|
|
|
+ ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmCharger->gun_info[gun_index].powerConsumption.power_consumption;
|
|
|
memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
|
|
|
|
|
|
memcpy((char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StartTransaction[gun_index].IdTag));
|
|
@@ -1971,7 +2080,8 @@ int main(void)
|
|
|
ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ((float)ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0) - ShmOCPP16Data->StartTransaction[gun_index].MeterStart;
|
|
|
ftime(&endChargingTime[gun_index]);
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
|
|
|
-
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmOCPP16Data->StartTransaction[gun_index].MeterStart)/100.0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].OutputEnergy = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmOCPP16Data->StartTransaction[gun_index].MeterStart)/100.0;
|
|
|
// Charging profile
|
|
|
|
|
|
}
|
|
@@ -2027,7 +2137,10 @@ int main(void)
|
|
|
}
|
|
|
|
|
|
memcpy((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].IdTag));
|
|
|
+ ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmCharger->gun_info[gun_index].powerConsumption.power_consumption;
|
|
|
ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = ON;
|
|
|
+
|
|
|
+ getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
|
|
|
}
|
|
|
|
|
|
setRelay(gun_index,OFF);
|
|
@@ -2039,6 +2152,7 @@ int main(void)
|
|
|
ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;
|
|
|
ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = OFF;
|
|
|
|
|
|
+ DB_Insert_Record(localDb, gun_index);
|
|
|
setChargerMode(gun_index, SYS_MODE_IDLE);
|
|
|
}
|
|
|
}
|
|
@@ -2160,6 +2274,7 @@ int main(void)
|
|
|
sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
|
|
|
ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
|
|
|
DEBUG_WARN("Firmware upgrade fail.\r\n");
|
|
|
+ system("/usr/bin/run_evse_restart.sh");
|
|
|
}
|
|
|
}
|
|
|
}
|