-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset with ongoing transaction #128
Conversation
7726349
to
5cac860
Compare
a1ff7bb
to
3320a1c
Compare
@@ -289,12 +314,13 @@ template <typename M> class MessageQueue { | |||
} | |||
|
|||
MessageQueue(const std::function<bool(json message)>& send_callback, const int transaction_message_attempts, | |||
const int transaction_message_retry_interval) : | |||
MessageQueue(send_callback, transaction_message_attempts, transaction_message_retry_interval, {}){}; | |||
const int transaction_message_retry_interval, common::DatabaseHandlerBase& databaseHandler) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to pass the databaseHandler as a std::shared_ptr here? It's already a sharedptr in the charge point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No in the chargepoint it is a unique ptr. I can make it a shared ptr if you want, then I can pass it as shared ptr of course. But actually the charge point is the 'owner' of the pointer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I totally forgot about that, then we'll have to check if the access to the database handler with a shared ptr is a good idea. unpacking the unique ptr here is definitely not recommended
lib/ocpp/v16/charge_point_impl.cpp
Outdated
@@ -47,7 +47,7 @@ ChargePointImpl::ChargePointImpl(const std::string& config, const std::filesyste | |||
this->message_queue = std::make_unique<ocpp::MessageQueue<v16::MessageType>>( | |||
[this](json message) -> bool { return this->websocket->send(message.dump()); }, | |||
this->configuration->getTransactionMessageAttempts(), this->configuration->getTransactionMessageRetryInterval(), | |||
this->external_notify); | |||
this->external_notify, *this->database_handler.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you would use the sharedptr here you would not have to unpack it to pass it
lib/ocpp/v201/charge_point.cpp
Outdated
// B12.FR.04 | ||
for (const auto &[evse_id, evse] : this->evses) { | ||
if (evse->has_active_transaction()) { | ||
callbacks.stop_transaction_callback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leads to a race condition with a TransactionEvent(Ended) because this TransactionEvent(Ended) could be queued faster than the response to Reset.req . This could be solved either by responding to this message before executing the stop_transaction_callback(s) or have a look at how this was solved for OCPP1.6: https://github.com/EVerest/libocpp/blob/main/lib/ocpp/v16/charge_point_impl.cpp#L1519 . A seperate threads waits for all transactions to be stopped before the reset_callback is called. There could be a (configurable) timeout for waiting for the responses (other than in implemented 1.6)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it, but not with the 5s because that's up to the charging station how long that can take. Can you take a look if this is better?
Also worked on the other comment about the message queue that is sending things before the accepted bootnotification. Is it better with this change?
Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
…m 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]>
Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
…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]>
…n be performed as soon as the charging has stopped. Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
…lability handler on reset. Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
Signed-off-by: Maaike <[email protected]>
Signed-off-by: Maaike <[email protected]>
Signed-off-by: Maaike <[email protected]>
Signed-off-by: Maaike <[email protected]>
Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
…ccepted' Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
b0d3aa9
to
32b9209
Compare
Signed-off-by: Kai-Uwe Hermann <[email protected]>
* 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]>
Reset with ongoing transaction.
Because we have to resend a transaction message if there is no 'ack' returned before rebooting, the database is also changed. I made this a draft review because I can not test it yet and I am a bit unsure about:
Thanks for looking into it!