mirror of
https://github.com/esphome/esphome.git
synced 2024-12-27 07:51:43 +01:00
public dce
This commit is contained in:
parent
4f7bd585e9
commit
7260eb6225
2 changed files with 21 additions and 17 deletions
|
@ -24,6 +24,8 @@ static const uint8_t CONFIG_MODEM_UART_EVENT_TASK_PRIORITY = 5;
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace modem {
|
namespace modem {
|
||||||
|
|
||||||
|
using namespace esp_modem;
|
||||||
|
|
||||||
ModemComponent *global_modem_component; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
ModemComponent *global_modem_component; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
|
||||||
#define ESPHL_ERROR_CHECK(err, message) \
|
#define ESPHL_ERROR_CHECK(err, message) \
|
||||||
|
@ -94,7 +96,7 @@ void ModemComponent::setup() {
|
||||||
this->dte_config_.task_priority = CONFIG_MODEM_UART_EVENT_TASK_PRIORITY;
|
this->dte_config_.task_priority = CONFIG_MODEM_UART_EVENT_TASK_PRIORITY;
|
||||||
this->dte_config_.dte_buffer_size = CONFIG_MODEM_UART_RX_BUFFER_SIZE / 2;
|
this->dte_config_.dte_buffer_size = CONFIG_MODEM_UART_RX_BUFFER_SIZE / 2;
|
||||||
|
|
||||||
this->dte_ = esp_modem::create_uart_dte(&this->dte_config_);
|
this->dte_ = create_uart_dte(&this->dte_config_);
|
||||||
|
|
||||||
assert(this->dte_);
|
assert(this->dte_);
|
||||||
|
|
||||||
|
@ -131,16 +133,16 @@ void ModemComponent::setup() {
|
||||||
|
|
||||||
switch (this->model_) {
|
switch (this->model_) {
|
||||||
case ModemModel::BG96:
|
case ModemModel::BG96:
|
||||||
this->dce_ = create_BG96_dce(&dce_config, this->dte_, this->ppp_netif_);
|
this->dce = create_BG96_dce(&dce_config, this->dte_, this->ppp_netif_);
|
||||||
break;
|
break;
|
||||||
case ModemModel::SIM800:
|
case ModemModel::SIM800:
|
||||||
this->dce_ = create_SIM800_dce(&dce_config, this->dte_, this->ppp_netif_);
|
this->dce = create_SIM800_dce(&dce_config, this->dte_, this->ppp_netif_);
|
||||||
break;
|
break;
|
||||||
case ModemModel::SIM7000:
|
case ModemModel::SIM7000:
|
||||||
this->dce_ = create_SIM7000_dce(&dce_config, this->dte_, this->ppp_netif_);
|
this->dce = create_SIM7000_dce(&dce_config, this->dte_, this->ppp_netif_);
|
||||||
break;
|
break;
|
||||||
case ModemModel::SIM7600:
|
case ModemModel::SIM7600:
|
||||||
this->dce_ = create_SIM7600_dce(&dce_config, this->dte_, this->ppp_netif_);
|
this->dce = create_SIM7600_dce(&dce_config, this->dte_, this->ppp_netif_);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGE(TAG, "Unknown model");
|
ESP_LOGE(TAG, "Unknown model");
|
||||||
|
@ -148,7 +150,7 @@ void ModemComponent::setup() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(this->dce_);
|
assert(this->dce);
|
||||||
|
|
||||||
this->started_ = true;
|
this->started_ = true;
|
||||||
this->poweron();
|
this->poweron();
|
||||||
|
@ -171,18 +173,18 @@ void ModemComponent::start_connect_() {
|
||||||
|
|
||||||
global_modem_component->got_ipv4_address_ = false; // why not this ?
|
global_modem_component->got_ipv4_address_ = false; // why not this ?
|
||||||
|
|
||||||
this->dce_->set_mode(esp_modem::modem_mode::CMUX_MANUAL_COMMAND);
|
this->dce->set_mode(modem_mode::CMUX_MANUAL_COMMAND);
|
||||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||||
|
|
||||||
command_result res = command_result::TIMEOUT;
|
command_result res = command_result::TIMEOUT;
|
||||||
|
|
||||||
// int retry = 0;
|
// int retry = 0;
|
||||||
// while (res != command_result::OK) {
|
// while (res != command_result::OK) {
|
||||||
// res = this->dce_->sync();
|
// res = this->dce->sync();
|
||||||
// if (res != command_result::OK) {
|
// if (res != command_result::OK) {
|
||||||
// ESP_LOGW(TAG, "modem not responding");
|
// ESP_LOGW(TAG, "modem not responding");
|
||||||
// ESP_LOGI(TAG, "Status: %d", (int) this->get_status());
|
// ESP_LOGI(TAG, "Status: %d", (int) this->get_status());
|
||||||
// this->dce_->set_command_mode();
|
// this->dce->set_command_mode();
|
||||||
// App.feed_wdt();
|
// App.feed_wdt();
|
||||||
// vTaskDelay(pdMS_TO_TICKS(7000));
|
// vTaskDelay(pdMS_TO_TICKS(7000));
|
||||||
// }
|
// }
|
||||||
|
@ -191,7 +193,7 @@ void ModemComponent::start_connect_() {
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
res = this->dce_->sync();
|
res = this->dce->sync();
|
||||||
|
|
||||||
if (res != command_result::OK) {
|
if (res != command_result::OK) {
|
||||||
ESP_LOGW(TAG, "Unable to sync modem. Will retry later");
|
ESP_LOGW(TAG, "Unable to sync modem. Will retry later");
|
||||||
|
@ -200,7 +202,7 @@ void ModemComponent::start_connect_() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->dte_config_.uart_config.flow_control == ESP_MODEM_FLOW_CONTROL_HW) {
|
if (this->dte_config_.uart_config.flow_control == ESP_MODEM_FLOW_CONTROL_HW) {
|
||||||
if (command_result::OK != this->dce_->set_flow_control(2, 2)) {
|
if (command_result::OK != this->dce->set_flow_control(2, 2)) {
|
||||||
ESP_LOGE(TAG, "Failed to set the set_flow_control mode");
|
ESP_LOGE(TAG, "Failed to set the set_flow_control mode");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -213,8 +215,8 @@ void ModemComponent::start_connect_() {
|
||||||
if (!this->pin_code_.empty()) {
|
if (!this->pin_code_.empty()) {
|
||||||
bool pin_ok = true;
|
bool pin_ok = true;
|
||||||
ESP_LOGV(TAG, "Set pin code: %s", this->pin_code_.c_str());
|
ESP_LOGV(TAG, "Set pin code: %s", this->pin_code_.c_str());
|
||||||
if (this->dce_->read_pin(pin_ok) == command_result::OK && !pin_ok) {
|
if (this->dce->read_pin(pin_ok) == command_result::OK && !pin_ok) {
|
||||||
ESP_MODEM_THROW_IF_FALSE(this->dce_->set_pin(this->pin_code_) == command_result::OK, "Cannot set PIN!");
|
ESP_MODEM_THROW_IF_FALSE(this->dce->set_pin(this->pin_code_) == command_result::OK, "Cannot set PIN!");
|
||||||
vTaskDelay(pdMS_TO_TICKS(2000)); // Need to wait for some time after unlocking the SIM
|
vTaskDelay(pdMS_TO_TICKS(2000)); // Need to wait for some time after unlocking the SIM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,7 +225,7 @@ void ModemComponent::start_connect_() {
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||||
|
|
||||||
if (this->dce_->set_mode(esp_modem::modem_mode::CMUX_MODE)) {
|
if (this->dce->set_mode(modem_mode::CMUX_MODE)) {
|
||||||
ESP_LOGD(TAG, "Modem has correctly entered multiplexed command/data mode");
|
ESP_LOGD(TAG, "Modem has correctly entered multiplexed command/data mode");
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "Failed to configure multiplexed command mode... exiting");
|
ESP_LOGE(TAG, "Failed to configure multiplexed command mode... exiting");
|
||||||
|
|
|
@ -18,6 +18,8 @@ using esphome::esp_log_printf_; // esp_modem will use esphome logger (needed if
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace modem {
|
namespace modem {
|
||||||
|
|
||||||
|
using namespace esp_modem;
|
||||||
|
|
||||||
static const char *const TAG = "modem";
|
static const char *const TAG = "modem";
|
||||||
|
|
||||||
enum class ModemComponentState {
|
enum class ModemComponentState {
|
||||||
|
@ -57,6 +59,7 @@ class ModemComponent : public Component {
|
||||||
this->model_ = this->modem_model_map_.count(model) ? modem_model_map_[model] : ModemModel::UNKNOWN;
|
this->model_ = this->modem_model_map_.count(model) ? modem_model_map_[model] : ModemModel::UNKNOWN;
|
||||||
}
|
}
|
||||||
bool get_status() { return gpio_get_level(this->status_pin_); }
|
bool get_status() { return gpio_get_level(this->status_pin_); }
|
||||||
|
std::unique_ptr<DCE> dce;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
gpio_num_t rx_pin_ = gpio_num_t::GPIO_NUM_NC;
|
gpio_num_t rx_pin_ = gpio_num_t::GPIO_NUM_NC;
|
||||||
|
@ -77,9 +80,8 @@ class ModemComponent : public Component {
|
||||||
{"SIM7070", ModemModel::SIM7070},
|
{"SIM7070", ModemModel::SIM7070},
|
||||||
{"SIM7070_GNSS", ModemModel::SIM7070_GNSS},
|
{"SIM7070_GNSS", ModemModel::SIM7070_GNSS},
|
||||||
{"SIM7600", ModemModel::SIM7600}};
|
{"SIM7600", ModemModel::SIM7600}};
|
||||||
std::shared_ptr<esp_modem::DTE> dte_;
|
std::shared_ptr<DTE> dte_;
|
||||||
std::unique_ptr<esp_modem::DCE> dce_; // public ?
|
esp_netif_t *ppp_netif_{nullptr};
|
||||||
esp_modem::esp_netif_t *ppp_netif_{nullptr};
|
|
||||||
esp_modem_dte_config_t dte_config_;
|
esp_modem_dte_config_t dte_config_;
|
||||||
ModemComponentState state_{ModemComponentState::STOPPED};
|
ModemComponentState state_{ModemComponentState::STOPPED};
|
||||||
void start_connect_();
|
void start_connect_();
|
||||||
|
|
Loading…
Reference in a new issue