Skip to content

Commit 8560f02

Browse files
feat(module): add support for sequans GM02S modem
1 parent 3fc26a5 commit 8560f02

File tree

9 files changed

+278
-2
lines changed

9 files changed

+278
-2
lines changed

components/esp_modem/include/cxx_include/esp_modem_api.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ std::unique_ptr<DCE> create_SIM7070_dce(const dce_config *config, std::shared_pt
8484
*/
8585
std::unique_ptr<DCE> create_SIM7000_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif);
8686

87-
8887
/**
8988
* @brief Create DCE based on SIM800 module
9089
*/
@@ -95,6 +94,11 @@ std::unique_ptr<DCE> create_SIM800_dce(const dce_config *config, std::shared_ptr
9594
*/
9695
std::unique_ptr<DCE> create_BG96_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif);
9796

97+
/**
98+
* @brief Create DCE based on Sequans GM02S module
99+
*/
100+
std::unique_ptr<DCE> create_SQNGM02S_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif);
101+
98102
/**
99103
* @brief Create generic DCE
100104
*/

components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ enum class ModemType {
118118
SIM7000, /*!< Derived from the GenericModule, specifics applied to SIM7000 model */
119119
BG96, /*!< Derived from the GenericModule, specifics applied to BG69 model */
120120
SIM800, /*!< Derived from the GenericModule with specifics applied to SIM800 model */
121+
SQNGM02S, /*!< Derived from the GenericModule, specifics applied to GM02S model */
121122
};
122123

123124
/**
@@ -178,6 +179,8 @@ class Factory {
178179
return build_shared_module<SIM7000>(cfg, std::forward<Args>(args)...);
179180
case ModemType::BG96:
180181
return build_shared_module<BG96>(cfg, std::forward<Args>(args)...);
182+
case ModemType::SQNGM02S:
183+
return build_shared_module<SQNGM02S>(cfg, std::forward<Args>(args)...);
181184
case ModemType::GenericModule:
182185
return build_shared_module<GenericModule>(cfg, std::forward<Args>(args)...);
183186
default:
@@ -207,6 +210,8 @@ class Factory {
207210
return build_unique<SIM7000>(cfg, std::forward<Args>(args)...);
208211
case ModemType::BG96:
209212
return build_unique<BG96>(cfg, std::forward<Args>(args)...);
213+
case ModemType::SQNGM02S:
214+
return build_unique<SQNGM02S>(cfg, std::forward<Args>(args)...);
210215
case ModemType::GenericModule:
211216
return build_unique<GenericModule>(cfg, std::forward<Args>(args)...);
212217
default:
@@ -229,6 +234,8 @@ class Factory {
229234
return build<SIM7000>(cfg, std::forward<Args>(args)...);
230235
case ModemType::BG96:
231236
return build<BG96>(cfg, std::forward<Args>(args)...);
237+
case ModemType::SQNGM02S:
238+
return build<SQNGM02S>(cfg, std::forward<Args>(args)...);
232239
case ModemType::GenericModule:
233240
return build<GenericModule>(cfg, std::forward<Args>(args)...);
234241
default:

components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ class BG96: public GenericModule {
177177
command_result set_pdp_context(PdpContext &pdp) override;
178178
};
179179

180+
class SQNGM02S : public GenericModule
181+
{
182+
using GenericModule::GenericModule;
183+
184+
public:
185+
command_result connect(PdpContext &pdp);
186+
bool setup_data_mode() override;
187+
};
188+
180189
/**
181190
* @}
182191
*/

components/esp_modem/include/esp_modem_c_api_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ typedef enum esp_modem_dce_device {
6060
ESP_MODEM_DCE_BG96,
6161
ESP_MODEM_DCE_EC20,
6262
ESP_MODEM_DCE_SIM800,
63+
ESP_MODEM_DCE_SQNGM02S,
6364
ESP_MODEM_DCE_CUSTOM
6465
} esp_modem_dce_device_t;
6566

components/esp_modem/include/generate/esp_modem_command_declare.inc

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,69 @@ ESP_MODEM_DECLARE_DCE_COMMAND(set_gnss_power_mode, command_result, 1, INT_IN(p1,
290290
*/ \
291291
ESP_MODEM_DECLARE_DCE_COMMAND(get_gnss_power_mode, command_result, 1, INT_OUT(p1, mode)) \
292292
\
293-
293+
/**
294+
* @brief Configure PSM
295+
* @param[in] mode psm mode (0 - off, 1 - on, 2 - off & discard stored params)
296+
* @return OK, FAIL or TIMEOUT
297+
*/ \
298+
ESP_MODEM_DECLARE_DCE_COMMAND(config_psm, command_result, 3, INT_IN(p1, mode), STRING_IN(p2, tau), STRING_IN(p3, active_time)) \
299+
\
300+
/**
301+
* @brief Configure CEREG urc
302+
* @param[in] value
303+
* value = 0 - Disable network URC
304+
* value = 1 - Enable network URC
305+
* value = 2 - Enable network URC with location information
306+
* value = 3 - Enable network URC with location information and EMM cause
307+
* value = 4 - Enable network URC with location information and PSM value
308+
* value = 5 - Enable network URC with location information and PSM value, EMM cause
309+
*/ \
310+
ESP_MODEM_DECLARE_DCE_COMMAND(config_network_registration_urc, command_result, 1, INT_IN(p1, value)) \
311+
\
312+
/**
313+
* @brief Gets the current network registration state
314+
* @param[out] state The current network registration state
315+
* state = 0 - Not registered, MT is not currently searching an operator to register to
316+
* state = 1 - Registered, home network
317+
* state = 2 - Not registered, but MT is currently trying to attach or searching an operator to register to
318+
* state = 3 - Registration denied
319+
* state = 4 - Unknown
320+
* state = 5 - Registered, Roaming
321+
* state = 6 - Registered, for SMS only, home network (NB-IoT only)
322+
* state = 7 - Registered, for SMS only, roaming (NB-IoT only)
323+
* state = 8 - Attached for emergency bearer services only
324+
* state = 9 - Registered for CSFB not preferred, home network
325+
* state = 10 - Registered for CSFB not preferred, roaming
326+
*/ \
327+
ESP_MODEM_DECLARE_DCE_COMMAND(get_network_registration_state, command_result, 1, INT_OUT(p1,state)) \
328+
\
329+
/**
330+
* @brief Configures the mobile termination error (+CME ERROR)
331+
* @param[in] mode The form of the final result code
332+
* mode = 0 - Disable, use and send ERROR instead
333+
* mode = 1 - Enable, use numeric error values
334+
* mode = 2 - Enable, result code and use verbose error values
335+
*/ \
336+
ESP_MODEM_DECLARE_DCE_COMMAND(config_mobile_termination_error, command_result, 1, INT_IN(p1, mode)) \
337+
\
338+
/**
339+
* @brief Configure eDRX
340+
* @param[in] mode
341+
* mode = 0 - Disable
342+
* mode = 1 - Enable
343+
* mode = 2 - Enable + URC
344+
* mode = 3 - Disable + Reset parameter.
345+
* @param[in] access_technology
346+
* act = 0 - ACT is not using eDRX (used in URC)
347+
* act = 1 - EC-GSM-IoT (A/Gb mode)
348+
* act = 2 - GSM (A/Gb mode)
349+
* act = 3 - UTRAN (Iu mode)
350+
* act = 4 - E-UTRAN (WB-S1 mode)
351+
* act = 5 - E-UTRAN (NB-S1 mode)
352+
* @param[in] edrx_value nible string containing encoded eDRX time
353+
* @param[in] ptw_value nible string containing encoded Paging Time Window
354+
*/ \
355+
ESP_MODEM_DECLARE_DCE_COMMAND(config_edrx, command_result, 3, INT_IN(p1, mode), INT_IN(p2, access_technology), STRING_IN(p3, edrx_value), STRING_IN(p4, ptw_value)) \
294356

295357
#ifdef GENERATE_DOCS
296358
// cat ../include/generate/esp_modem_command_declare.inc | clang++ -E -P -CC -xc++ -I../include -DGENERATE_DOCS - | sed -n '1,/DCE command documentation/!p'

components/esp_modem/src/esp_modem_api.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ std::unique_ptr<DCE> create_BG96_dce(const dce_config *config, std::shared_ptr<D
6666
return create_modem_dce(dce_factory::ModemType::BG96, config, std::move(dte), netif);
6767
}
6868

69+
std::unique_ptr<DCE> create_SQNGM02S_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif)
70+
{
71+
return create_modem_dce(dce_factory::ModemType::SQNGM02S, config, std::move(dte), netif);
72+
}
73+
6974
std::unique_ptr<DCE> create_generic_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif)
7075
{
7176
return create_modem_dce(dce_factory::ModemType::GenericModule, config, std::move(dte), netif);

components/esp_modem/src/esp_modem_c_api.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,74 @@ extern "C" esp_err_t esp_modem_get_gnss_power_mode(esp_modem_dce_t *dce_wrap, in
439439
return ret;
440440
}
441441

442+
extern "C" esp_err_t esp_modem_config_psm(esp_modem_dce_t *dce_wrap, int mode, const char *tau, const char *active_time)
443+
{
444+
if (dce_wrap == nullptr || dce_wrap->dce == nullptr || mode > 3) {
445+
return ESP_ERR_INVALID_ARG;
446+
}
447+
448+
if (mode == 1 && (strlen(tau) != 8 || strlen(active_time) != 8)) {
449+
return ESP_ERR_INVALID_ARG;
450+
}
451+
452+
return command_response_to_esp_err(dce_wrap->dce->config_psm(mode, std::string(tau), std::string(active_time)));
453+
}
454+
455+
extern "C" esp_err_t esp_modem_config_network_registration_urc(esp_modem_dce_t *dce_wrap, int value)
456+
{
457+
if (dce_wrap == nullptr || dce_wrap->dce == nullptr || value > 5)
458+
{
459+
return ESP_ERR_INVALID_ARG;
460+
}
461+
462+
return command_response_to_esp_err(dce_wrap->dce->configure_network_registration_urc(value));
463+
}
464+
465+
extern "C" esp_err_t esp_modem_get_network_registration_state(esp_modem_dce_t *dce_wrap, int *p_state)
466+
{
467+
if (dce_wrap == nullptr || dce_wrap->dce == nullptr || p_state == nullptr)
468+
{
469+
return ESP_ERR_INVALID_ARG;
470+
}
471+
472+
int state;
473+
auto ret = command_response_to_esp_err(dce_wrap->dce->get_network_registration_state(state));
474+
475+
if (ret == ESP_OK)
476+
{
477+
*p_state = state;
478+
}
479+
return ret;
480+
}
481+
482+
extern "C" esp_err_t esp_modem_config_mobile_termination_error(esp_modem_dce_t *dce_wrap, int mode)
483+
{
484+
if (dce_wrap == nullptr || dce_wrap->dce == nullptr || mode > 2)
485+
{
486+
return ESP_ERR_INVALID_ARG;
487+
}
488+
489+
return command_response_to_esp_err(dce_wrap->dce->config_mobile_termination_error(mode));
490+
}
491+
492+
extern "C" esp_err_t esp_modem_config_edrx(esp_modem_dce_t *dce, int value, const char *access_technology)
493+
{
494+
495+
}
496+
497+
extern "C" esp_err_t esp_modem_sqns_gm02s_connect(esp_modem_dce_t *dce, const esp_modem_PdpContext_t *pdp_context)
498+
{
499+
if (dce_wrap == nullptr || dce_wrap->dce == nullptr || dce_wrap->modem_type != ESP_MODEM_DCE_SQNGM02S)
500+
{
501+
return ESP_ERR_INVALID_ARG;
502+
}
503+
504+
esp_modem::PdpContext pdp{pdp_context->apn};
505+
pdp.context_id = pdp_context->context_id;
506+
pdp.protocol_type = pdp_context->protocol_type;
507+
return command_response_to_esp_err(static_cast<SQNGM02S *>(dce_wrap->dce->get_module())->connect(pdp));
508+
}
509+
442510
extern "C" esp_err_t esp_modem_reset(esp_modem_dce_t *dce_wrap)
443511
{
444512
return command_response_to_esp_err(dce_wrap->dce->reset());

components/esp_modem/src/esp_modem_command_library.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,71 @@ command_result get_gnss_power_mode(CommandableIf *t, int &mode)
607607
return command_result::OK;
608608
}
609609

610+
command_result config_psm(CommandableIf *t, int enabled, const std::string &TAU, const std::string &activeTime)
611+
{
612+
ESP_LOGV(TAG, "%s", __func__);
613+
if (enabled == true)
614+
{
615+
return generic_command_common(t, "AT+CPSMS=1,,,\"" + TAU + "\"" + ",\"" + activeTime + "\"\r", 500);
616+
}
617+
return generic_command_common(t, "AT+CPSMS=" + std::to_string(enabled), 500);
618+
}
619+
620+
command_result config_network_registration_urc(CommandableIf *t, int value)
621+
{
622+
ESP_LOGV(TAG, "%s", __func__);
623+
return generic_command_common(t,"AT+CEREG=" + std::to_string(state) + "\r", 500);
624+
}
625+
626+
command_result get_network_registration_state(CommandableIf *t, int& state)
627+
{
628+
ESP_LOGV(TAG, "%s", __func__);
629+
std::string out;
630+
631+
auto ret = generic_get_string(t, "AT+CEREG?\r", out, 500);
632+
if (ret != command_result::OK) {
633+
return ret;
634+
}
635+
636+
constexpr std::string_view pattern = "+CEREG: ";
637+
int state_pos_start;
638+
int state_pos_end;
639+
if (out.find(pattern) == std::string::npos || (state_pos_start = out.find(',')) == std::string::npos) {
640+
return command_result::FAIL;
641+
}
642+
643+
if (out.find(pattern) == std::string::npos || (state_pos_end = out.find(',',state_pos_start)) == std::string::npos){
644+
if (std::from_chars(out.data() + state_pos_start, out.data() + out.size(), state).ec == std::errc::invalid_argument) {
645+
return command_result::FAIL;
646+
}
647+
} else if (std::from_chars(out.data() + state_pos_start, out.data() + state_pos_end, state).ec == std::errc::invalid_argument) {
648+
return command_result::FAIL;
649+
}
650+
651+
return command_result::OK;
652+
}
653+
654+
command_result config_mobile_termination_error(CommandableIf *t, int value)
655+
{
656+
ESP_LOGV(TAG, "%s", __func__);
657+
return generic_command_common(t, "AT+CMEE=" + std::to_string(value) + "\r");
658+
}
659+
command_result config_edrx(int mode, int access_technology, const std::string &edrx_value, const std::string &ptw_value)
660+
{
661+
if (mode == 1 || enabled == 2)
662+
{
663+
return dce_commands::generic_command_common(dte.get(),
664+
"AT+SQNEDRX=" +
665+
std::to_string(mode) +
666+
"," +
667+
std::to_string(access_technology) +
668+
",\"" +
669+
edrx_value +
670+
"\",\"" +
671+
ptw_value + "\"\r");
672+
}
673+
return dce_commands::generic_command_common(dte.get(), "AT+SQNEDRX=" + std::to_string(mode), 500);
674+
}
610675
command_result set_gnss_power_mode_sim76xx(CommandableIf *t, int mode)
611676
{
612677
ESP_LOGV(TAG, "%s", __func__ );

components/esp_modem/src/esp_modem_modules.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,59 @@ command_result BG96::set_pdp_context(esp_modem::PdpContext &pdp)
8787
return dce_commands::set_pdp_context(dte.get(), pdp, 300);
8888
}
8989

90+
command_result urc_callback(uint8_t *line, size_t len)
91+
{
92+
ESP_LOGI("WalterModem", "Received: %s", line);
93+
if (strstr((const char *)line, "+CEREG: 1"))
94+
{
95+
return command_result::OK; // Succesfully registered
96+
}
97+
else if (strstr((const char *)line, "+CEREG: 5"))
98+
{
99+
return command_result::OK; // Succesfully registered
100+
}
101+
else if (strstr((const char *)line, "+CEREG: 3"))
102+
{
103+
return command_result::FAIL; // Permission denied
104+
}
105+
return command_result::TIMEOUT;
106+
}
107+
108+
command_result SQNGM02S::connect(PdpContext &pdp)
109+
{
110+
command_result res;
111+
res = set_pdp_context(pdp);
112+
if (res != command_result::OK)
113+
return res;
114+
res = config_network_registration_urc(1);
115+
if (res != command_result::OK)
116+
return res;
117+
118+
res = set_radio_state(1);
119+
if (res != command_result::OK)
120+
return res;
121+
122+
//wait for +CEREG: 5 or +CEREG: 1.
123+
124+
do
125+
{
126+
res = dte->command("", urc_callback, 20000, '\r');
127+
} while (res == command_result::TIMEOUT);
128+
129+
if (res != command_result::OK)
130+
return res;
131+
132+
res = config_network_registration_urc(0);
133+
if (res != command_result::OK)
134+
return res;
135+
136+
return command_result::OK;
137+
}
138+
139+
bool SQNGM02S::setup_data_mode()
140+
{
141+
ESP_LOGI("SQNGM02S", "setyp data mode");
142+
return set_echo(false) == command_result::OK;
143+
// PDP context has already been set before hand because SEQUANS modem must have already been connected/registered before setting up cmux
144+
}
90145
}

0 commit comments

Comments
 (0)