Skip to content

Commit

Permalink
Allow EVerest to start even if the LEM module is not able to communic…
Browse files Browse the repository at this point in the history
…ate with the device - in that case just raise the communication error (#917)

Signed-off-by: florinmihut <[email protected]>
  • Loading branch information
florinmihut authored and hikinggrass committed Oct 25, 2024
1 parent b92e846 commit 0853a74
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
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

0 comments on commit 0853a74

Please sign in to comment.