Skip to content

Commit

Permalink
Fill transaction database after bootnotification is receveived and 'a…
Browse files Browse the repository at this point in the history
…ccepted'

Signed-off-by: Maaike Zijderveld, Alfen <[email protected]>
  • Loading branch information
maaikez committed Aug 17, 2023
1 parent 93fae4a commit 53772b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
37 changes: 20 additions & 17 deletions include/ocpp/common/message_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,6 @@ template <typename M> class MessageQueue {
new_message(false),
uuid_generator(boost::uuids::random_generator()) {

std::vector<ocpp::common::DBTransactionMessage> transaction_messages =
database_handler.get_transaction_messages();

if (!transaction_messages.empty()) {
for (auto& transaction_message : transaction_messages) {
std::shared_ptr<ControlMessage<M>> message =
std::make_shared<ControlMessage<M>>(transaction_message.json_message);
message->messageType = string_to_messagetype(transaction_message.message_type);
message->timestamp = transaction_message.timestamp;
message->message_attempts = transaction_message.message_attempts;
transaction_message_queue.push_back(message);
}

this->new_message = true;
}

this->send_callback = send_callback;
this->in_flight = nullptr;
this->worker_thread = std::thread([this]() {
Expand Down Expand Up @@ -316,7 +300,26 @@ 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, common::DatabaseHandlerBase& databaseHandler) :
MessageQueue(send_callback, transaction_message_attempts, transaction_message_retry_interval, {},
databaseHandler){};
databaseHandler){}

void get_transaction_messages_from_db()
{
std::vector<ocpp::common::DBTransactionMessage> transaction_messages =
database_handler.get_transaction_messages();

if (!transaction_messages.empty()) {
for (auto& transaction_message : transaction_messages) {
std::shared_ptr<ControlMessage<M>> message =
std::make_shared<ControlMessage<M>>(transaction_message.json_message);
message->messageType = string_to_messagetype(transaction_message.message_type);
message->timestamp = transaction_message.timestamp;
message->message_attempts = transaction_message.message_attempts;
transaction_message_queue.push_back(message);
}

this->new_message = true;
}
}

/// \brief pushes a new \p call message onto the message queue
template <class T> void push(Call<T> call) {
Expand Down
3 changes: 3 additions & 0 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,9 @@ void ChargePoint::handle_boot_notification_response(CallResult<BootNotificationR
this->registration_status = msg.status;

if (this->registration_status == RegistrationStatusEnum::Accepted) {
// get transaction messages from db (if there are any) so they can be sent again.
message_queue->get_transaction_messages_from_db();

// set timers
if (msg.interval > 0) {
this->heartbeat_timer.interval([this]() { this->heartbeat_req(); }, std::chrono::seconds(msg.interval));
Expand Down

0 comments on commit 53772b1

Please sign in to comment.