|
@@ -29,12 +29,13 @@
|
|
|
#define TMR_IDX_9 9
|
|
|
|
|
|
#define TIMEOUT_SPEC_HANDSHAKING 180000
|
|
|
-#define TIMEOUT_SPEC_AUTH 15000
|
|
|
+#define TIMEOUT_SPEC_AUTH 10000
|
|
|
#define TIMEOUT_SPEC_HANDSHAKING_LED 185000
|
|
|
#define TIMEOUT_SPEC_LOGPPRINTOUT 30000
|
|
|
|
|
|
#define MtdBlockSize 0x600000
|
|
|
|
|
|
+#define DB_FILE "/Storage/ChargeLog/localCgargingRecord.db"
|
|
|
//==========================
|
|
|
// Declare method
|
|
|
//==========================
|
|
@@ -428,22 +429,28 @@ 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"
|
|
|
- ");";
|
|
|
+ char* createRecordSql="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"
|
|
|
+ ");";
|
|
|
+
|
|
|
+ char* createCfgSql="CREATE TABLE `config` ( "
|
|
|
+ "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
|
|
|
+ "`item` TEXT NOT NULL, "
|
|
|
+ "`connector` INTEGER NOT NULL, "
|
|
|
+ "`val` TEXT NOT NULL, unique(item,connector) on conflict replace);";
|
|
|
|
|
|
//sqlite3_config(SQLITE_CONFIG_URI, 1);
|
|
|
- if(sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db))
|
|
|
+ if(sqlite3_open(DB_FILE, &db))
|
|
|
{
|
|
|
result = FAIL;
|
|
|
DEBUG_INFO( "Can't open database: %s\r\n", sqlite3_errmsg(db));
|
|
@@ -452,7 +459,8 @@ int DB_Open(sqlite3 *db)
|
|
|
else
|
|
|
{
|
|
|
DEBUG_INFO( "Local charging record database open successfully.\r\n");
|
|
|
- if (sqlite3_exec(db, createSql, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+
|
|
|
+ if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
{
|
|
|
result = FAIL;
|
|
|
DEBUG_INFO( "Create local charging record table error message: %s\n", errMsg);
|
|
@@ -461,6 +469,17 @@ int DB_Open(sqlite3 *db)
|
|
|
{
|
|
|
DEBUG_INFO( "Opened local charging record table successfully\n");
|
|
|
}
|
|
|
+
|
|
|
+ if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Create local config table error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Opened local config table successfully\n");
|
|
|
+ }
|
|
|
+
|
|
|
sqlite3_close(db);
|
|
|
}
|
|
|
|
|
@@ -510,6 +529,83 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t isOperactive)
|
|
|
+{
|
|
|
+ uint8_t result = false;
|
|
|
+ char* errMsg = NULL;
|
|
|
+ char sqlStr[1024];
|
|
|
+ srand(time(NULL));
|
|
|
+
|
|
|
+ if(sqlite3_open(DB_FILE, &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");
|
|
|
+
|
|
|
+ sprintf(sqlStr, "insert or replace into config (item, connector, val) values('isOperactive', %d, %d);", gun_index, isOperactive);
|
|
|
+ DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
|
|
|
+ if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "update config error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO("update connector-%d config item isOperactive to %d\r\n", gun_index, isOperactive);
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
|
|
|
+{
|
|
|
+ uint8_t result = true;
|
|
|
+ char* errMsg = NULL;
|
|
|
+ char sqlStr[1024];
|
|
|
+ char **rs;
|
|
|
+ int rows, cols;
|
|
|
+
|
|
|
+ sprintf(sqlStr, "select * from config where item='isOperactive' and connector=%d;", gun_index);
|
|
|
+ DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
|
|
|
+
|
|
|
+ if(sqlite3_open(DB_FILE, &db))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Can't open database: %s\r\n", sqlite3_errmsg(db));
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Local config query database open successfully.\r\n");
|
|
|
+ sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
|
|
|
+
|
|
|
+ if(rows>0)
|
|
|
+ {
|
|
|
+ for(int idxRow=1;idxRow<=rows;idxRow++)
|
|
|
+ {
|
|
|
+ if(strcmp(rs[(idxRow*cols)+3], "0") == 0)
|
|
|
+ {
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ DEBUG_INFO("%s, %s, %s, %s\r\n", rs[(idxRow*cols)+0], rs[(idxRow*cols)+1], rs[(idxRow*cols)+2], rs[(idxRow*cols)+3]);
|
|
|
+ DEBUG_INFO("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow*cols)+3]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_free_table(rs);
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
//======================================================
|
|
|
// Peripheral initial
|
|
|
//======================================================
|
|
@@ -942,6 +1038,9 @@ int Initialization()
|
|
|
if(DB_Open(localDb) != PASS)
|
|
|
result = FAIL;
|
|
|
|
|
|
+ for(int gun_index=0;gun_index< AC_QUANTITY;gun_index++)
|
|
|
+ ShmCharger->gun_info[gun_index].isOperactive = DB_Get_Operactive(localDb, gun_index);
|
|
|
+
|
|
|
rfidFd = InitRfidPort();
|
|
|
|
|
|
wtdFd = InitWatchDog();
|
|
@@ -1075,7 +1174,7 @@ void get_firmware_version(unsigned char gun_index)
|
|
|
strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
|
|
|
|
|
|
// Get CSU root file system version
|
|
|
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.18.60.XXXX.B0");
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.19.60.XXXX.B0");
|
|
|
|
|
|
// Get AC connector type from model name
|
|
|
for(uint8_t idx=0;idx<3;idx++)
|
|
@@ -2106,19 +2205,30 @@ int main(void)
|
|
|
{
|
|
|
if(strcmp((char*)ShmOCPP16Data->ChangeAvailability[gun_index].Type, "Operative") == 0)
|
|
|
{
|
|
|
- if(isMode(gun_index, SYS_MODE_MAINTAIN))
|
|
|
- {
|
|
|
- setChargerMode(gun_index, SYS_MODE_IDLE);
|
|
|
- ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = OFF;
|
|
|
- }
|
|
|
+ DB_Update_Operactive(localDb, gun_index, true);
|
|
|
+ ShmCharger->gun_info[gun_index].isOperactive = DB_Get_Operactive(localDb, gun_index);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(isMode(gun_index, SYS_MODE_IDLE))
|
|
|
- {
|
|
|
- setChargerMode(gun_index, SYS_MODE_MAINTAIN);
|
|
|
- ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = OFF;
|
|
|
- }
|
|
|
+ DB_Update_Operactive(localDb, gun_index, false);
|
|
|
+ ShmCharger->gun_info[gun_index].isOperactive = DB_Get_Operactive(localDb, gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+ ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = OFF;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ShmCharger->gun_info[gun_index].isOperactive)
|
|
|
+ {
|
|
|
+ if(isMode(gun_index, SYS_MODE_MAINTAIN))
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, SYS_MODE_IDLE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(isMode(gun_index, SYS_MODE_IDLE))
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, SYS_MODE_MAINTAIN);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2786,9 +2896,8 @@ int main(void)
|
|
|
{
|
|
|
if((ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
|
|
|
(ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) ||
|
|
|
- !ShmOCPP16Data->OcppConnStatus ) &&
|
|
|
- (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod != START_METHOD_BLE) ||
|
|
|
- (!ShmOCPP16Data->OcppConnStatus&&(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)))
|
|
|
+ !ShmOCPP16Data->OcppConnStatus ) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod != START_METHOD_BLE) ||
|
|
|
+ (!ShmOCPP16Data->OcppConnStatus&&(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)))
|
|
|
{
|
|
|
if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) ||
|
|
|
(ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) ||
|