mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
clang tidy
This commit is contained in:
parent
868f5357c1
commit
315bb61628
2 changed files with 49 additions and 49 deletions
|
@ -67,15 +67,15 @@ void ModemComponent::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Initing netif");
|
ESP_LOGCONFIG(TAG, "Initing netif");
|
||||||
esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &ModemComponent::got_ip_event_handler, nullptr);
|
esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &ModemComponent::got_ip_event_handler, nullptr);
|
||||||
ESP_LOGD(TAG, "Initializing esp_modem");
|
ESP_LOGD(TAG, "Initializing esp_modem");
|
||||||
this->modem_netif_init();
|
this->modem_netif_init_();
|
||||||
this->dte_init();
|
this->dte_init_();
|
||||||
|
|
||||||
this->started_ = true;
|
this->started_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModemComponent::loop() {
|
void ModemComponent::loop() {
|
||||||
const int now = millis();
|
const int now = millis();
|
||||||
if (!ModemComponent::check_modem_component_state_timings()) {
|
if (!ModemComponent::check_modem_component_state_timings_()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (this->state_) {
|
switch (this->state_) {
|
||||||
|
@ -85,13 +85,13 @@ void ModemComponent::loop() {
|
||||||
this->power_pin_->digital_write(true);
|
this->power_pin_->digital_write(true);
|
||||||
ESP_LOGD(TAG, "Modem turn on");
|
ESP_LOGD(TAG, "Modem turn on");
|
||||||
if (this->pwrkey_pin_) {
|
if (this->pwrkey_pin_) {
|
||||||
this->set_state(ModemComponentState::TURNING_ON_PWRKEY);
|
this->set_state_(ModemComponentState::TURNING_ON_PWRKEY);
|
||||||
} else {
|
} else {
|
||||||
this->set_state(ModemComponentState::SYNC);
|
this->set_state_(ModemComponentState::SYNC);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, "Can't turn on modem power pin because it is not configured, go to turn on pwrkey");
|
ESP_LOGD(TAG, "Can't turn on modem power pin because it is not configured, go to turn on pwrkey");
|
||||||
this->set_state(ModemComponentState::TURNING_ON_RESET);
|
this->set_state_(ModemComponentState::TURNING_ON_RESET);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ void ModemComponent::loop() {
|
||||||
case ModemComponentState::TURNING_OFF_POWER:
|
case ModemComponentState::TURNING_OFF_POWER:
|
||||||
this->power_pin_->digital_write(false);
|
this->power_pin_->digital_write(false);
|
||||||
ESP_LOGD(TAG, "modem turn off");
|
ESP_LOGD(TAG, "modem turn off");
|
||||||
this->set_state(ModemComponentState::TURNING_ON_POWER);
|
this->set_state_(ModemComponentState::TURNING_ON_POWER);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// The state holds the power key
|
// The state holds the power key
|
||||||
|
@ -107,10 +107,10 @@ void ModemComponent::loop() {
|
||||||
if (pwrkey_pin_) {
|
if (pwrkey_pin_) {
|
||||||
this->pwrkey_pin_->digital_write(false);
|
this->pwrkey_pin_->digital_write(false);
|
||||||
ESP_LOGD(TAG, "pwrkey turn on");
|
ESP_LOGD(TAG, "pwrkey turn on");
|
||||||
this->set_state(ModemComponentState::TURNING_OFF_PWRKEY);
|
this->set_state_(ModemComponentState::TURNING_OFF_PWRKEY);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, "Can't turn on pwrkey pin because it is not configured, go to reset power modem");
|
ESP_LOGD(TAG, "Can't turn on pwrkey pin because it is not configured, go to reset power modem");
|
||||||
this->set_state(ModemComponentState::TURNING_ON_POWER);
|
this->set_state_(ModemComponentState::TURNING_ON_POWER);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -119,7 +119,7 @@ void ModemComponent::loop() {
|
||||||
case ModemComponentState::TURNING_OFF_PWRKEY:
|
case ModemComponentState::TURNING_OFF_PWRKEY:
|
||||||
this->pwrkey_pin_->digital_write(true);
|
this->pwrkey_pin_->digital_write(true);
|
||||||
ESP_LOGD(TAG, "pwrkey turn off");
|
ESP_LOGD(TAG, "pwrkey turn off");
|
||||||
this->set_state(ModemComponentState::SYNC);
|
this->set_state_(ModemComponentState::SYNC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// The state of the beginning of the reset of the modem
|
// The state of the beginning of the reset of the modem
|
||||||
|
@ -127,10 +127,10 @@ void ModemComponent::loop() {
|
||||||
if (reset_pin_) {
|
if (reset_pin_) {
|
||||||
this->reset_pin_->digital_write(false);
|
this->reset_pin_->digital_write(false);
|
||||||
ESP_LOGD(TAG, "turn on reset");
|
ESP_LOGD(TAG, "turn on reset");
|
||||||
this->set_state(ModemComponentState::TURNING_OFF_RESET);
|
this->set_state_(ModemComponentState::TURNING_OFF_RESET);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, "Can't turn on reset pin because it is not configured, go to turn on pwkey");
|
ESP_LOGD(TAG, "Can't turn on reset pin because it is not configured, go to turn on pwkey");
|
||||||
this->set_state(ModemComponentState::TURNING_OFF_POWER);
|
this->set_state_(ModemComponentState::TURNING_OFF_POWER);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -139,14 +139,14 @@ void ModemComponent::loop() {
|
||||||
case ModemComponentState::TURNING_OFF_RESET:
|
case ModemComponentState::TURNING_OFF_RESET:
|
||||||
this->reset_pin_->digital_write(true);
|
this->reset_pin_->digital_write(true);
|
||||||
ESP_LOGD(TAG, "turn off reset");
|
ESP_LOGD(TAG, "turn off reset");
|
||||||
this->set_state(ModemComponentState::SYNC);
|
this->set_state_(ModemComponentState::SYNC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// The state of waiting for the modem to connect, response to "AT" "OK"
|
// The state of waiting for the modem to connect, response to "AT" "OK"
|
||||||
case ModemComponentState::SYNC:
|
case ModemComponentState::SYNC:
|
||||||
if (this->dce->sync() == esp_modem::command_result::OK) {
|
if (this->dce_->sync() == esp_modem::command_result::OK) {
|
||||||
ESP_LOGD(TAG, "sync OK");
|
ESP_LOGD(TAG, "sync OK");
|
||||||
this->set_state(ModemComponentState::REGISTRATION_IN_NETWORK);
|
this->set_state_(ModemComponentState::REGISTRATION_IN_NETWORK);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, "Wait sync");
|
ESP_LOGD(TAG, "Wait sync");
|
||||||
}
|
}
|
||||||
|
@ -155,11 +155,11 @@ void ModemComponent::loop() {
|
||||||
|
|
||||||
// The state of waiting for the modem to register in the network
|
// The state of waiting for the modem to register in the network
|
||||||
case ModemComponentState::REGISTRATION_IN_NETWORK:
|
case ModemComponentState::REGISTRATION_IN_NETWORK:
|
||||||
if (get_rssi()) {
|
if (get_rssi_()) {
|
||||||
ESP_LOGD(TAG, "Starting modem connection");
|
ESP_LOGD(TAG, "Starting modem connection");
|
||||||
ESP_LOGD(TAG, "SIgnal quality: rssi=%d", get_rssi());
|
ESP_LOGD(TAG, "SIgnal quality: rssi=%d", get_rssi_());
|
||||||
this->set_state(ModemComponentState::CONNECTING);
|
this->set_state_(ModemComponentState::CONNECTING);
|
||||||
this->dce->set_data();
|
this->dce_->set_data();
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, "Wait RSSI");
|
ESP_LOGD(TAG, "Wait RSSI");
|
||||||
}
|
}
|
||||||
|
@ -185,14 +185,14 @@ void ModemComponent::loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModemComponent::modem_netif_init() {
|
void ModemComponent::modem_netif_init_() {
|
||||||
esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP();
|
esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP();
|
||||||
this->modem_netif_ = esp_netif_new(&netif_ppp_config);
|
this->modem_netif_ = esp_netif_new(&netif_ppp_config);
|
||||||
assert(this->modem_netif_);
|
assert(this->modem_netif_);
|
||||||
ESP_LOGD(TAG, "netif create succes");
|
ESP_LOGD(TAG, "netif create succes");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModemComponent::dte_init() {
|
void ModemComponent::dte_init_() {
|
||||||
esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG();
|
esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG();
|
||||||
/* setup UART specific configuration based on kconfig options */
|
/* setup UART specific configuration based on kconfig options */
|
||||||
dte_config.uart_config.tx_io_num = this->tx_pin_;
|
dte_config.uart_config.tx_io_num = this->tx_pin_;
|
||||||
|
@ -203,20 +203,20 @@ void ModemComponent::dte_init() {
|
||||||
dte_config.task_stack_size = this->uart_event_task_stack_size_;
|
dte_config.task_stack_size = this->uart_event_task_stack_size_;
|
||||||
dte_config.task_priority = this->uart_event_task_priority_;
|
dte_config.task_priority = this->uart_event_task_priority_;
|
||||||
dte_config.dte_buffer_size = this->uart_rx_buffer_size_ / 2;
|
dte_config.dte_buffer_size = this->uart_rx_buffer_size_ / 2;
|
||||||
this->dte = esp_modem::create_uart_dte(&dte_config);
|
this->dte_ = esp_modem::create_uart_dte(&dte_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModemComponent::dce_init() {
|
void ModemComponent::dce_init_() {
|
||||||
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG(this->apn_.c_str());
|
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG(this->apn_.c_str());
|
||||||
this->dce = esp_modem::create_SIM800_dce(&dce_config, dte, this->modem_netif_);
|
this->dce_ = esp_modem::create_SIM800_dce(&dce_config, dte_, this->modem_netif_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModemComponent::check_modem_component_state_timings() {
|
bool ModemComponent::check_modem_component_state_timings_() {
|
||||||
const int now = millis();
|
const int now = millis();
|
||||||
ModemComponentStateTiming timing = this->modemComponentStateTimingMap[this->state_];
|
ModemComponentStateTiming timing = this->modem_component_state_timing_map_[this->state_];
|
||||||
if (timing.time_limit && ((this->change_state_ + timing.time_limit) < now)) {
|
if (timing.time_limit && ((this->change_state_ + timing.time_limit) < now)) {
|
||||||
ESP_LOGE(TAG, "State time limit %s", this->state_to_string(this->state_));
|
ESP_LOGE(TAG, "State time limit %s", this->state_to_string_(this->state_));
|
||||||
this->set_state(ModemComponentState::TURNING_ON_RESET);
|
this->set_state_(ModemComponentState::TURNING_ON_RESET);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!timing.poll_period) {
|
if (!timing.poll_period) {
|
||||||
|
@ -230,23 +230,23 @@ bool ModemComponent::check_modem_component_state_timings() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModemComponent::set_state(ModemComponentState state) {
|
void ModemComponent::set_state_(ModemComponentState state) {
|
||||||
// execute before transition to state
|
// execute before transition to state
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case ModemComponentState::SYNC:
|
case ModemComponentState::SYNC:
|
||||||
this->dce_init();
|
this->dce_init_();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ESP_LOGCONFIG(TAG, "Modem component change state from %s to %s", this->state_to_string(this->state_),
|
ESP_LOGCONFIG(TAG, "Modem component change state from %s to %s", this->state_to_string_(this->state_),
|
||||||
this->state_to_string(state));
|
this->state_to_string_(state));
|
||||||
this->state_ = state;
|
this->state_ = state;
|
||||||
this->change_state_ = millis();
|
this->change_state_ = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *ModemComponent::state_to_string(ModemComponentState state) {
|
const char *ModemComponent::state_to_string_(ModemComponentState state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case ModemComponentState::TURNING_ON_POWER:
|
case ModemComponentState::TURNING_ON_POWER:
|
||||||
return "TURNING_ON_POWER";
|
return "TURNING_ON_POWER";
|
||||||
|
@ -303,9 +303,9 @@ void ModemComponent::dump_connect_params() {
|
||||||
ESP_LOGCONFIG(TAG, " DNS2: %s", network::IPAddress(&dns_info.ip.u_addr.ip4).str().c_str());
|
ESP_LOGCONFIG(TAG, " DNS2: %s", network::IPAddress(&dns_info.ip.u_addr.ip4).str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int ModemComponent::get_rssi() {
|
int ModemComponent::get_rssi_() {
|
||||||
int rssi = 0, ber = 0;
|
int rssi = 0, ber = 0;
|
||||||
esp_modem::command_result errr = this->dce->get_signal_quality(rssi, ber);
|
esp_modem::command_result errr = this->dce_->get_signal_quality(rssi, ber);
|
||||||
// esp_err_t err = esp_modem::esp_modem_get_signal_quality(dce, &rssi, &ber);
|
// esp_err_t err = esp_modem::esp_modem_get_signal_quality(dce, &rssi, &ber);
|
||||||
if (errr != esp_modem::command_result::OK) {
|
if (errr != esp_modem::command_result::OK) {
|
||||||
ESP_LOGE(TAG, "esp_modem_get_signal_quality failed with");
|
ESP_LOGE(TAG, "esp_modem_get_signal_quality failed with");
|
||||||
|
@ -326,7 +326,7 @@ network::IPAddress ModemComponent::get_ip_address() {
|
||||||
void ModemComponent::got_ip_event_handler(void *arg, esp_event_base_t event_base, int event_id, void *event_data) {
|
void ModemComponent::got_ip_event_handler(void *arg, esp_event_base_t event_base, int event_id, void *event_data) {
|
||||||
ESP_LOGD(TAG, "IP event! %" PRIu32, event_id);
|
ESP_LOGD(TAG, "IP event! %" PRIu32, event_id);
|
||||||
if (event_id == IP_EVENT_PPP_GOT_IP) {
|
if (event_id == IP_EVENT_PPP_GOT_IP) {
|
||||||
global_modem_component->set_state(ModemComponentState::CONNECTED);
|
global_modem_component->set_state_(ModemComponentState::CONNECTED);
|
||||||
esp_netif_dns_info_t dns_info;
|
esp_netif_dns_info_t dns_info;
|
||||||
|
|
||||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
|
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
|
||||||
|
@ -346,7 +346,7 @@ void ModemComponent::got_ip_event_handler(void *arg, esp_event_base_t event_base
|
||||||
ESP_LOGD(TAG, "GOT ip event!!!");
|
ESP_LOGD(TAG, "GOT ip event!!!");
|
||||||
} else if (event_id == IP_EVENT_PPP_LOST_IP) {
|
} else if (event_id == IP_EVENT_PPP_LOST_IP) {
|
||||||
ESP_LOGD(TAG, "Modem Disconnect from PPP Server");
|
ESP_LOGD(TAG, "Modem Disconnect from PPP Server");
|
||||||
global_modem_component->set_state(ModemComponentState::TURNING_ON_RESET);
|
global_modem_component->set_state_(ModemComponentState::TURNING_ON_RESET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ class ModemComponent : public Component {
|
||||||
bool powerdown();
|
bool powerdown();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::map<ModemComponentState, ModemComponentStateTiming> modemComponentStateTimingMap = {
|
std::map<ModemComponentState, ModemComponentStateTiming> modem_component_state_timing_map_ = {
|
||||||
{ModemComponentState::TURNING_ON_POWER, ModemComponentStateTiming(2000, 0)},
|
{ModemComponentState::TURNING_ON_POWER, ModemComponentStateTiming(2000, 0)},
|
||||||
{ModemComponentState::TURNING_OFF_POWER, ModemComponentStateTiming(2000, 0)},
|
{ModemComponentState::TURNING_OFF_POWER, ModemComponentStateTiming(2000, 0)},
|
||||||
{ModemComponentState::TURNING_ON_PWRKEY, ModemComponentStateTiming(2000, 0)},
|
{ModemComponentState::TURNING_ON_PWRKEY, ModemComponentStateTiming(2000, 0)},
|
||||||
|
@ -88,19 +88,19 @@ class ModemComponent : public Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void got_ip_event_handler(void *arg, esp_event_base_t event_base, int event_id, void *event_data);
|
static void got_ip_event_handler(void *arg, esp_event_base_t event_base, int event_id, void *event_data);
|
||||||
void modem_netif_init();
|
void modem_netif_init_();
|
||||||
void dte_init();
|
void dte_init_();
|
||||||
void dce_init();
|
void dce_init_();
|
||||||
|
|
||||||
bool check_modem_component_state_timings();
|
bool check_modem_component_state_timings_();
|
||||||
int get_rssi();
|
int get_rssi_();
|
||||||
int get_modem_voltage();
|
int get_modem_voltage_();
|
||||||
const char *get_state();
|
const char *get_state_();
|
||||||
void set_state(ModemComponentState state);
|
void set_state_(ModemComponentState state);
|
||||||
const char *state_to_string(ModemComponentState state);
|
const char *state_to_string_(ModemComponentState state);
|
||||||
|
|
||||||
std::shared_ptr<esp_modem::DTE> dte{nullptr};
|
std::shared_ptr<esp_modem::DTE> dte_{nullptr};
|
||||||
std::unique_ptr<esp_modem::DCE> dce{nullptr};
|
std::unique_ptr<esp_modem::DCE> dce_{nullptr};
|
||||||
ModemType type_{MODEM_TYPE_UNKNOWN};
|
ModemType type_{MODEM_TYPE_UNKNOWN};
|
||||||
InternalGPIOPin *reset_pin_{nullptr};
|
InternalGPIOPin *reset_pin_{nullptr};
|
||||||
InternalGPIOPin *power_pin_{nullptr};
|
InternalGPIOPin *power_pin_{nullptr};
|
||||||
|
|
Loading…
Reference in a new issue