Skip to content
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

Allow EVerest to start even if the LEM module is not able to communic… #917

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions modules/LemDCBM400600/main/lem_dcbm_400600_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,10 @@
namespace module::main {

void LemDCBM400600Controller::init() {
try {
this->time_sync_helper->set_time_config_params(config.meter_timezone, config.meter_dst);
call_with_retry([this]() { this->fetch_meter_id_from_device(); }, this->config.init_number_of_http_retries,
this->config.init_retry_wait_in_milliseconds);
} catch (HttpClientError& http_client_error) {
EVLOG_error << "Initialization of LemDCBM400600Controller failed with http "
"client error: "
<< http_client_error.what();
throw;
} catch (DCBMUnexpectedResponseException& dcbm_error) {
EVLOG_error << "Initialization of LemDCBM400600Controller failed due an "
"unexpected device response: "
<< dcbm_error.what();
throw;
}

EVLOG_info << "LEM DCBM 400/600: Try to communicate with the device";
this->time_sync_helper->set_time_config_params(config.meter_timezone, config.meter_dst);
call_with_retry([this]() { this->fetch_meter_id_from_device(); }, this->config.init_number_of_http_retries,
this->config.init_retry_wait_in_milliseconds);
this->time_sync_helper->restart_unsafe_period();
}

Expand Down
3 changes: 3 additions & 0 deletions modules/LemDCBM400600/main/lem_dcbm_400600_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class LemDCBM400600Controller {
types::powermeter::TransactionStartResponse start_transaction(const types::powermeter::TransactionReq& value);
types::powermeter::TransactionStopResponse stop_transaction(const std::string& transaction_id);
types::powermeter::Powermeter get_powermeter();
inline bool is_initialized() {
return ("" != meter_id);
}
inline std::string get_public_key_ocmf() {
return public_key_ocmf;
}
Expand Down
27 changes: 16 additions & 11 deletions modules/LemDCBM400600/main/powermeterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,37 @@ void powermeterImpl::init() {
mod->config.resilience_transaction_request_retries, mod->config.resilience_transaction_request_retry_delay,
mod->config.cable_id, mod->config.tariff_id, mod->config.meter_timezone, mod->config.meter_dst,
mod->config.SC, mod->config.UV, mod->config.UD});

this->controller->init();
}

void powermeterImpl::ready() {
// Start the live_measure_publisher thread, which periodically publishes the live measurements of the device
this->live_measure_publisher_thread = std::thread([this] {
this->publish_public_key_ocmf(this->controller->get_public_key_ocmf());
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
try {
this->publish_powermeter(this->controller->get_powermeter());
// if the communication error is set, clear the error
if (this->error_state_monitor->is_error_active("powermeter/CommunicationFault",
"Communication timed out")) {
// need to update LEM status since we have recovered from a communication loss
this->controller->update_lem_status();
clear_error("powermeter/CommunicationFault", "Communication timed out");
if (!this->controller->is_initialized()) {
this->controller->init();
std::this_thread::sleep_for(
std::chrono::milliseconds(mod->config.resilience_initial_connection_retry_delay));
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
this->publish_powermeter(this->controller->get_powermeter());
// if the communication error is set, clear the error
if (this->error_state_monitor->is_error_active("powermeter/CommunicationFault",
"Communication timed out")) {
// need to update LEM status since we have recovered from a communication loss
this->controller->update_lem_status();
clear_error("powermeter/CommunicationFault", "Communication timed out");
}
}
} catch (LemDCBM400600Controller::DCBMUnexpectedResponseException& dcbm_exception) {
EVLOG_error << "Failed to publish powermeter value due to an invalid device response: "
<< dcbm_exception.what();
} catch (HttpClientError& client_error) {
EVLOG_error << "Failed to publish powermeter value due to an http error: " << client_error.what();
if (!this->error_state_monitor->is_error_active("powermeter/CommunicationFault",
"Communication timed out")) {
EVLOG_error << "Failed to communicate with the powermeter due to http error: "
<< client_error.what();
auto error =
this->error_factory->create_error("powermeter/CommunicationFault", "Communication timed out",
"This error is raised due to communication timeout");
Expand Down
Loading