forked from EVerest/libocpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reset with ongoing transaction (EVerest#128)
* Start with 'reset with ongoing transaction'. Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Start with database related things to store a transaction message from the queue in the database, so it can be sent after reboot if it is not sended yet. Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Implement database insert / remove / get functions. Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Add database base class in common library so the transactions in the queue can be stored in both versions (16 and 201). Put transaction in database as soon as it is received. Remove transaction message from database when reply is received. Some small improvements in for loop with copying / reference. Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Add evse id to reset callback. Store scheduled 'OnIdle' reset so it an be performed as soon as the charging has stopped. Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Add evseid to is_reset_allowed_callback Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Add documentation. Reset when all evse id's stopped charging. Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * 'initialize' sqlite db member in the constructor. Add documentation Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Make it possible to call the reset multiple times. Also call the availability handler on reset. Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Add two templates for conversion from message type to string. Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Change start() function and add optional boot reason. Signed-off-by: Maaike <[email protected]> * Add documentation about start function Signed-off-by: Maaike <[email protected]> * sqlite bind text fixes. Signed-off-by: Maaike <[email protected]> * Set flag to persist availability after reboot / reset Signed-off-by: Maaike <[email protected]> * Add persist to as well Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Review comments about race conditions Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * Fill transaction database after bootnotification is receveived and 'accepted' Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * change database handler to shared ptr instead of unique ptr Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> * clang-format Signed-off-by: Kai-Uwe Hermann <[email protected]> --------- Signed-off-by: Maaike Zijderveld, Alfen <[email protected]> Signed-off-by: Maaike <[email protected]> Signed-off-by: Kai-Uwe Hermann <[email protected]> Co-authored-by: Kai-Uwe Hermann <[email protected]>
- Loading branch information
1 parent
9ff3ab9
commit 1fb526c
Showing
16 changed files
with
456 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest | ||
|
||
#pragma once | ||
|
||
#include <deque> | ||
#include <memory> | ||
#include <sqlite3.h> | ||
#include <string> | ||
|
||
#include <ocpp/common/types.hpp> | ||
|
||
namespace ocpp::common { | ||
|
||
struct DBTransactionMessage { | ||
json json_message; | ||
std::string message_type; | ||
int32_t message_attempts; | ||
DateTime timestamp; | ||
std::string unique_id; | ||
}; | ||
|
||
class DatabaseHandlerBase { | ||
protected: | ||
sqlite3* db; | ||
|
||
public: | ||
/// | ||
/// \brief Base database handler class. | ||
/// | ||
/// Other database classes should derive from this class and only use the functions after `db` is initialized. | ||
/// Class handles some common database functionality like inserting and removing transaction messages. | ||
/// | ||
/// \warning The 'db' variable is not initialized, the deriving class should do that. | ||
/// | ||
DatabaseHandlerBase() noexcept; | ||
|
||
/// \brief Get transaction messages from transaction messages queue table. | ||
/// \return The transaction messages. | ||
std::vector<DBTransactionMessage> get_transaction_messages(); | ||
|
||
/// \brief Insert a new transaction message that needs to be sent to the CSMS. | ||
/// \param transaction_message The message to be stored. | ||
/// \return True on success. | ||
bool insert_transaction_message(const DBTransactionMessage& transaction_message); | ||
|
||
/// \brief Remove a transaction message from the database. | ||
/// \param unique_id The unique id of the transaction message. | ||
/// \return True on success. | ||
void remove_transaction_message(const std::string& unique_id); | ||
}; | ||
|
||
} // namespace ocpp::common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.