|
@@ -1194,6 +1194,42 @@ int CreatShareMemory()
|
|
|
//===============================================
|
|
|
// SQLite3 related routine
|
|
|
//===============================================
|
|
|
+int getReceiptInfo(uint8_t gun_index, char *receiptInfo)
|
|
|
+{
|
|
|
+ int result = PASS;
|
|
|
+ double totalEnergy=0.0;
|
|
|
+ double totalPrice=0.0;
|
|
|
+
|
|
|
+ json_object *receipt = json_object_new_object();
|
|
|
+ json_object *receiptAry = json_object_new_array();
|
|
|
+
|
|
|
+ for(uint8_t idxHour=0;idxHour<ARRAY_SIZE(ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod);idxHour++)
|
|
|
+ {
|
|
|
+ json_object *receiptDetail = json_object_new_object();
|
|
|
+
|
|
|
+ json_object_object_add(receiptDetail, "hour", json_object_new_int(idxHour));
|
|
|
+ json_object_object_add(receiptDetail, "chargedEnergy", json_object_new_double(ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idxHour]));
|
|
|
+ json_object_object_add(receiptDetail, "periodPrice", json_object_new_double(ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idxHour]*ShmSysConfigAndInfo->SysConfig.BillingData.Fee[idxHour]));
|
|
|
+
|
|
|
+ totalEnergy += ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idxHour];
|
|
|
+ totalPrice += ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idxHour]*ShmSysConfigAndInfo->SysConfig.BillingData.Fee[idxHour];
|
|
|
+
|
|
|
+ json_object_array_add(receiptAry, receiptDetail);
|
|
|
+ }
|
|
|
+ json_object_object_add(receipt, "receiptDetail", receiptAry);
|
|
|
+ json_object_object_add(receipt, "totalChargedEnergy", json_object_new_double(totalEnergy));
|
|
|
+ json_object_object_add(receipt, "totalPrice", json_object_new_double(totalPrice));
|
|
|
+ json_object_object_add(receipt, "serviceProvider", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor));
|
|
|
+ json_object_object_add(receipt, "serviceProviderAddress", json_object_new_string("Address"));
|
|
|
+ json_object_object_add(receipt, "serviceProviderTel", json_object_new_string("TEL"));
|
|
|
+ json_object_object_add(receipt, "chargerBoxId", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
|
|
|
+
|
|
|
+ sprintf(receiptInfo, "%s", json_object_to_json_string_ext(receipt, JSON_C_TO_STRING_PLAIN));
|
|
|
+ json_object_put(receipt);
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
int DB_Open(sqlite3 *db)
|
|
|
{
|
|
|
int result = PASS;
|
|
@@ -1213,6 +1249,20 @@ int DB_Open(sqlite3 *db)
|
|
|
"finalCost text"
|
|
|
");";
|
|
|
|
|
|
+ char* createRecordBufSql="CREATE TABLE IF NOT EXISTS charging_record_buffer("
|
|
|
+ "reservationId text, "
|
|
|
+ "transactionId text, "
|
|
|
+ "startMethod text, "
|
|
|
+ "userId text, "
|
|
|
+ "dateTimeStart text, "
|
|
|
+ "dateTimeStop text,"
|
|
|
+ "socStart text, "
|
|
|
+ "socStop text, "
|
|
|
+ "chargeEnergy text, "
|
|
|
+ "stopReason text, "
|
|
|
+ "finalCost text"
|
|
|
+ ");";
|
|
|
+
|
|
|
char* createCfgSql="CREATE TABLE IF NOT EXISTS `config` ( "
|
|
|
"`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
|
|
|
"`item` TEXT NOT NULL, "
|
|
@@ -1240,6 +1290,16 @@ int DB_Open(sqlite3 *db)
|
|
|
DEBUG_INFO( "Opened local charging record table successfully\n");
|
|
|
}
|
|
|
|
|
|
+ if (sqlite3_exec(db, createRecordBufSql, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_ERROR( "Create local charging record buffer table error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Opened local charging record buffer table successfully\n");
|
|
|
+ }
|
|
|
+
|
|
|
if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
{
|
|
|
result = FAIL;
|
|
@@ -1256,11 +1316,166 @@ int DB_Open(sqlite3 *db)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+int DB_Check_Record_Buf(sqlite3 *db, int gun_index)
|
|
|
+{
|
|
|
+ int result = PASS;
|
|
|
+ char* errMsg = NULL;
|
|
|
+ char sqlStr[4096];
|
|
|
+ char **rs;
|
|
|
+ int rows, cols;
|
|
|
+
|
|
|
+ if(sqlite3_open(DB_FILE, &db))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlite3_get_table(db, "select * from charging_record_buffer", &rs, &rows, &cols, &errMsg);
|
|
|
+
|
|
|
+ if(rows>0)
|
|
|
+ {
|
|
|
+ // Copy record buffer
|
|
|
+ for(int idxRow=1;idxRow<=rows;idxRow++)
|
|
|
+ {
|
|
|
+ if(strcmp(rs[(idxRow*cols)+3], "0") == 0)
|
|
|
+ {
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ sprintf(sqlStr, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
|
|
|
+ "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');",
|
|
|
+ rs[(idxRow*cols)+0],
|
|
|
+ rs[(idxRow*cols)+1],
|
|
|
+ rs[(idxRow*cols)+2],
|
|
|
+ rs[(idxRow*cols)+3],
|
|
|
+ rs[(idxRow*cols)+4],
|
|
|
+ rs[(idxRow*cols)+5],
|
|
|
+ rs[(idxRow*cols)+6],
|
|
|
+ rs[(idxRow*cols)+7],
|
|
|
+ rs[(idxRow*cols)+8],
|
|
|
+ rs[(idxRow*cols)+9],
|
|
|
+ rs[(idxRow*cols)+10]);
|
|
|
+
|
|
|
+ if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Copy local charging record buffer error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Copy local charging record buffer successfully\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Delete buffer
|
|
|
+ if (sqlite3_exec(db, "delete from charging_record_buffer", 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Delete local charging record buffer error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Delete local charging record buffer successfully\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO("There is not any charging record buffer.\n", gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_free_table(rs);
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+int DB_Update_Record_Buf(sqlite3 *db, int gun_index)
|
|
|
+{
|
|
|
+ int result = PASS;
|
|
|
+ char* errMsg = NULL;
|
|
|
+ char sqlStr[4096];
|
|
|
+
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
|
|
|
+ {
|
|
|
+ sprintf(sqlStr, "insert into charging_record_buffer(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
|
|
|
+ "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%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,
|
|
|
+ "Power Loss",
|
|
|
+ ShmOCPP16Data->Cost.FinalCost[gun_index].description);
|
|
|
+ }
|
|
|
+ else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
|
|
|
+ {
|
|
|
+ sprintf(sqlStr, "insert into charging_record_buffer(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
|
|
|
+ "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%f');",
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
|
|
|
+ ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId,
|
|
|
+ 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,
|
|
|
+ "Power Loss",
|
|
|
+ ShmOCPP20Data->CostUpdated.totalCost);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(sqlite3_open(DB_FILE, &db))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Delete buffer
|
|
|
+ if (sqlite3_exec(db, "delete from charging_record_buffer", 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Delete local charging record buffer error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Delete local charging record buffer successfully\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Insert record buffer
|
|
|
+ if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Insert local charging record buffer error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Insert local charging record buffer successfully\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_close(db);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
int DB_Insert_Record(sqlite3 *db, int gun_index)
|
|
|
{
|
|
|
int result = PASS;
|
|
|
char* errMsg = NULL;
|
|
|
- char sqlStr[1024];
|
|
|
+ char sqlStr[4096];
|
|
|
+ char receiptInfo[2048];
|
|
|
+
|
|
|
+ getReceiptInfo(gun_index, receiptInfo);
|
|
|
+ DEBUG_INFO("Receipt Info: %s\n", receiptInfo);
|
|
|
|
|
|
if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
|
|
|
{
|
|
@@ -1294,6 +1509,7 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
|
|
|
ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason,
|
|
|
ShmOCPP20Data->CostUpdated.totalCost);
|
|
|
}
|
|
|
+ //DEBUG_INFO("sqlStr= %s\n", sqlStr);
|
|
|
|
|
|
if(sqlite3_open(DB_FILE, &db))
|
|
|
{
|
|
@@ -1303,7 +1519,18 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DEBUG_INFO( "Local charging record database open successfully.\n");
|
|
|
+ // Delete buffer
|
|
|
+ if (sqlite3_exec(db, "delete from charging_record_buffer", 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Delete local charging record buffer error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Delete local charging record buffer successfully\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Insert charging record
|
|
|
if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
{
|
|
|
result = FAIL;
|
|
@@ -1346,10 +1573,8 @@ int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t isOperactive)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DEBUG_INFO( "Local charging record database open successfully.\n");
|
|
|
-
|
|
|
sprintf(sqlStr, "insert or replace into config (item, connector, val) values('isOperactive', %d, %d);", gun_index, isOperactive);
|
|
|
- DEBUG_INFO("sqlStr= %s\n", sqlStr);
|
|
|
+ //DEBUG_INFO("sqlStr= %s\n", sqlStr);
|
|
|
if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
{
|
|
|
result = FAIL;
|
|
@@ -1385,7 +1610,6 @@ int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DEBUG_INFO( "Local config query database open successfully.\n");
|
|
|
sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
|
|
|
|
|
|
if(rows>0)
|
|
@@ -1411,6 +1635,7 @@ int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//======================================================
|
|
|
// Peripheral initial
|
|
|
//======================================================
|
|
@@ -2770,7 +2995,7 @@ void setRequest(unsigned char gun_index,unsigned char isOn)
|
|
|
if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == OFF)
|
|
|
{
|
|
|
ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest = ON;
|
|
|
- DEBUG_INFO("Gun-%d Output relay sts: ON \n",gun_index);
|
|
|
+ DEBUG_INFO("Gun-%d permission request: ON \n",gun_index);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -2778,7 +3003,7 @@ void setRequest(unsigned char gun_index,unsigned char isOn)
|
|
|
if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON)
|
|
|
{
|
|
|
ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest = OFF;
|
|
|
- DEBUG_INFO("Gun-%d Output relay sts: OFF \n",gun_index);
|
|
|
+ DEBUG_INFO("Gun-%d permission request: OFF \n",gun_index);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -4429,6 +4654,7 @@ int main(void)
|
|
|
ShmCharger->gun_info[gun_index].isDoEvReadyOnce = OFF;
|
|
|
ShmCharger->gun_info[gun_index].resultAuthorization = DEFAULT_RFID;
|
|
|
if(ShmCharger->isCcsEnable)system("pkill Module_CCS");
|
|
|
+ DB_Check_Record_Buf(localDb, gun_index);
|
|
|
}
|
|
|
|
|
|
if(((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)) ||
|
|
@@ -5109,6 +5335,9 @@ int main(void)
|
|
|
DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent: %d\n", gun_index, ShmCharger->gun_info[gun_index].targetCurrent);
|
|
|
DEBUG_INFO("===============================================================\n");
|
|
|
ftime(&startTime[gun_index][TMR_IDX_LOGPPRINTOUT]);
|
|
|
+
|
|
|
+ getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
|
|
|
+ DB_Update_Record_Buf(localDb, gun_index);
|
|
|
}
|
|
|
}
|
|
|
|