|
@@ -942,6 +942,11 @@ int DB_Initial()
|
|
|
"slot integer UNIQUE, connectionData text);";
|
|
|
|
|
|
|
|
|
+ char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
|
|
|
+ "occurDatetime text,"
|
|
|
+ "message_type text,"
|
|
|
+ "message_content text)";
|
|
|
+
|
|
|
//sqlite3_config(SQLITE_CONFIG_URI, 1);
|
|
|
if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
|
|
|
{
|
|
@@ -1003,6 +1008,16 @@ int DB_Initial()
|
|
|
DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
|
|
|
}
|
|
|
|
|
|
+ if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
|
|
|
+ }
|
|
|
+
|
|
|
//sqlite3_close(db);
|
|
|
}
|
|
|
|
|
@@ -2966,6 +2981,42 @@ int DB_deleteNetworkProfile(int slot)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+int getCurrentYear()
|
|
|
+{
|
|
|
+ int result = 0;
|
|
|
+ time_t CurrentTime;
|
|
|
+ struct tm *tm;
|
|
|
+
|
|
|
+ CurrentTime = time(NULL);
|
|
|
+ tm=localtime(&CurrentTime);
|
|
|
+ result = (tm->tm_year + 1900);
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
|
|
|
+{
|
|
|
+ int result = PASS;
|
|
|
+ char* errMsg = NULL;
|
|
|
+ char sqlStr[8192];
|
|
|
+
|
|
|
+ sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
|
|
|
+
|
|
|
+ if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ sprintf(sqlStr, "delete from ocpp20_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
|
|
|
+ if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
//==========================================
|
|
|
// Check time passed since today
|
|
|
//==========================================
|
|
@@ -8278,12 +8329,13 @@ int sendTransactionEventRequest(int gun_index)
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
|
|
|
storeTempStopTransaction(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
- if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
|
|
|
+ }
|
|
|
else
|
|
|
+ {
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
|
|
|
+ }
|
|
|
+
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
|
|
|
}
|
|
@@ -8393,12 +8445,13 @@ int sendTransactionEventRequest(int gun_index)
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
|
|
|
storeTempStopTransaction(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
- if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
|
|
|
+ }
|
|
|
else
|
|
|
+ {
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
|
|
|
+ }
|
|
|
+
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
|
|
|
}
|
|
@@ -8507,12 +8560,13 @@ int sendTransactionEventRequest(int gun_index)
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
|
|
|
storeTempStopTransaction(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
- if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
|
|
|
+ }
|
|
|
else
|
|
|
+ {
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
|
|
|
+ }
|
|
|
+
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
|
|
|
}
|
|
@@ -8614,12 +8668,13 @@ int sendTransactionEventRequest(int gun_index)
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
|
|
|
storeTempStopTransaction(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
- if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
|
|
|
+ }
|
|
|
else
|
|
|
+ {
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
|
|
|
+ }
|
|
|
+
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
|
|
|
}
|
|
@@ -8727,12 +8782,13 @@ int sendTransactionEventRequest(int gun_index)
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
|
|
|
storeTempStopTransaction(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
- if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
|
|
|
+ }
|
|
|
else
|
|
|
+ {
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
|
|
|
+ }
|
|
|
+
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
|
|
|
sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
|
|
|
}
|
|
@@ -8884,6 +8940,10 @@ int sendTransactionEventRequest(int gun_index)
|
|
|
}
|
|
|
|
|
|
queue_operation(QUEUE_OPERATION_ADD, guid, message);
|
|
|
+ if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
|
|
|
+ OCPP_insert_transaction_msg(YES, message);
|
|
|
+ else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
|
|
|
+ OCPP_insert_transaction_msg(NO, message);
|
|
|
|
|
|
return result;
|
|
|
}
|