Skip to content

Add support for Telit Cinterion TX62 #448

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ class ATHandler {
*/
void write_hex_string(const char *str, size_t size, bool quote_string = true);

/** Get the error detected during read_int()
*
* @return the latest negative integer error got from read_int().
*/
int32_t get_last_read_error() const;

/** Reads as string and converts result to integer. Supports only non-negative integers.
*
* @return the non-negative integer or -1 in case of error.
Expand Down Expand Up @@ -599,6 +605,7 @@ class ATHandler {
nsapi_error_t _last_err;
int _last_3gpp_error;
device_err_t _last_at_err;
int32_t _last_read_error{};
uint16_t _oob_string_max_length;
char *_output_delimiter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ namespace mbed {
* @{
*/

/// Radio Access Technology type
enum RadioAccessTechnologyType {
CATM1, ///< LTE CAT-M or LTE-M
CATNB ///< NB-IoT (Narrowband IoT)
};

/// CellularContext is CellularInterface/NetworkInterface with extensions for cellular connectivity
class CellularContext : public CellularInterface {

Expand Down Expand Up @@ -158,6 +164,7 @@ class CellularContext : public CellularInterface {
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
const char *pwd = 0) = 0;
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0) = 0;
virtual void set_access_technology(RadioAccessTechnologyType rat = CATM1) = 0;
virtual bool is_connected() = 0;

/** Same as NetworkInterface::get_default_instance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ class CellularDevice {
*/
void set_retry_timeout_array(const uint16_t timeout[], int array_len);

/**
* @brief Enable serial multiplexing according to <a href="https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1516">3GPP TS 27.010</a>, if implemented
* on this modem.
*
* @return Error code or success
*/
virtual nsapi_error_t enable_cmux() { return NSAPI_ERROR_UNSUPPORTED;};

protected: //Common functions
friend class AT_CellularNetwork;
friend class AT_CellularContext;
Expand Down Expand Up @@ -453,6 +461,8 @@ class CellularDevice {
CellularStateMachine *_state_machine;
Callback<void(nsapi_event_t, intptr_t)> _status_cb;

bool _cmux_enabled = false;

private: //Member variables
CellularNetwork *_nw;
char _sim_pin[MAX_PIN_SIZE + 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "rtos/Semaphore.h"
#include "AT_CellularDevice.h"

#include <optional>

const int MAX_APN_LENGTH = 63 + 1;

Expand Down Expand Up @@ -54,6 +55,7 @@ class AT_CellularContext : public CellularContext {
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
const char *pwd = 0);
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0);
virtual void set_access_technology(RadioAccessTechnologyType rat = CATM1);

// from CellularContext
virtual nsapi_error_t get_pdpcontext_params(pdpContextList_t &params_list);
Expand Down Expand Up @@ -115,6 +117,13 @@ class AT_CellularContext : public CellularContext {
*/
virtual const char *get_nonip_context_type_str();

/**
* @brief Set the cellular technology and band based on the \c _rat and \c _band class variables.
*
* Modems which support this functionality should override this in their CellularContext implementations.
*/
virtual void enable_access_technology() {}

private:
#if NSAPI_PPP_AVAILABLE
nsapi_error_t open_data_channel();
Expand All @@ -130,6 +139,8 @@ class AT_CellularContext : public CellularContext {
nsapi_error_t check_operation(nsapi_error_t err, ContextOperation op);
void ciot_opt_cb(mbed::CellularNetwork::CIoT_Supported_Opt ciot_opt);
virtual void do_connect_with_retry();

protected:
void set_cid(int cid);

private:
Expand All @@ -146,6 +157,7 @@ class AT_CellularContext : public CellularContext {
bool _cp_req;
bool _is_connected;
ATHandler &_at;
std::optional<RadioAccessTechnologyType> _rat;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class AT_CellularDevice : public CellularDevice {

virtual nsapi_error_t set_baud_rate(int baud_rate);

nsapi_error_t enable_cmux() override;

#if MBED_CONF_CELLULAR_USE_SMS
virtual CellularSMS *open_sms();

Expand Down
18 changes: 18 additions & 0 deletions connectivity/cellular/source/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ nsapi_error_t AT_CellularContext::connect()
}
call_network_cb(NSAPI_STATUS_CONNECTING);

set_device_ready();

_at.lock();
bool valid_context = get_context();
_at.unlock();
if(!valid_context) {
set_new_context(_cid);
}

do_user_authentication();

enable_access_technology();

nsapi_error_t err = _device->attach_to_network();
_cb_data.error = check_operation(err, OP_CONNECT);
_retry_count = 0;
Expand Down Expand Up @@ -278,6 +291,11 @@ void AT_CellularContext::set_credentials(const char *apn, const char *uname, con
_pwd = pwd;
}

void AT_CellularContext::set_access_technology(RadioAccessTechnologyType rat)
{
_rat = rat;
}

// PDP Context handling
void AT_CellularContext::delete_current_context()
{
Expand Down
26 changes: 25 additions & 1 deletion connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ nsapi_error_t AT_CellularDevice::init()
_at.flush();
_at.at_cmd_discard("E0", "");
if (_at.get_last_error() == NSAPI_ERROR_OK) {
_at.at_cmd_discard("+CMEE", "=1");
// Enable verbose error messages
_at.at_cmd_discard("+CMEE", "=2");
_at.at_cmd_discard("+CFUN", "=1");
if (_at.get_last_error() == NSAPI_ERROR_OK) {
break;
Expand Down Expand Up @@ -623,6 +624,29 @@ nsapi_error_t AT_CellularDevice::set_baud_rate(int baud_rate)
return error;
}

nsapi_error_t AT_CellularDevice::enable_cmux()
{
setup_at_handler();

_at.lock();
for (int retry = 1; retry <= 3; retry++) {
_at.clear_error();
_at.flush();
_at.at_cmd_discard("E0", "");
if (_at.get_last_error() == NSAPI_ERROR_OK) {
_at.at_cmd_discard("+CMUX", "=0");
if (_at.get_last_error() == NSAPI_ERROR_OK) {
_cmux_enabled = true;
break;
}
}
tr_debug("Wait 100ms to init modem");
rtos::ThisThread::sleep_for(100ms); // let modem have time to get ready
}

return _at.unlock_return_error();
}

nsapi_error_t AT_CellularDevice::set_baud_rate_impl(int baud_rate)
{
return _at.at_cmd_discard("+IPR", "=", "%d", baud_rate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn)
return NSAPI_ERROR_DEVICE_ERROR;
}
if (mode != NWModeAutomatic) {
// Force operator registration
return _at.at_cmd_discard("+COPS", "=0");
}
return NSAPI_ERROR_OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ nsapi_size_or_error_t AT_CellularStack::socket_recvfrom(nsapi_socket_t handle, S

if (socket->closed) {
tr_info("recvfrom socket %d closed", socket->id);
return 0;
return NSAPI_ERROR_NO_CONNECTION;
}

nsapi_size_or_error_t ret_val = NSAPI_ERROR_OK;
Expand Down
9 changes: 8 additions & 1 deletion connectivity/cellular/source/framework/device/ATHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ using namespace std::chrono_literals;
#define PROCESS_URC_TIME 20ms

// Suppress logging of very big packet payloads, maxlen is approximate due to write/read are cached
#define DEBUG_MAXLEN 60
#define DEBUG_MAXLEN 120
#define DEBUG_END_MARK "..\r"

const char *mbed::OK = "OK\r\n";
Expand Down Expand Up @@ -697,6 +697,11 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
return buf_idx;
}

int32_t ATHandler::get_last_read_error() const
{
return _last_read_error;
}

int32_t ATHandler::read_int()
{
if (!ok_to_proceed() || !_stop_tag || _stop_tag->found) {
Expand All @@ -711,9 +716,11 @@ int32_t ATHandler::read_int()
errno = 0;
long result = std::strtol(buff, NULL, 10);
if ((result == LONG_MIN || result == LONG_MAX) && errno == ERANGE) {
_last_read_error = result;
return -1; // overflow/underflow
}
if (result < 0) {
_last_read_error = result;
return -1; // negative values are unsupported
}
if (*buff == '\0') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace std::chrono_literals;

// timeout to wait for AT responses
#define TIMEOUT_POWER_ON 1s
#define TIMEOUT_SIM_PIN 1s
#define TIMEOUT_SIM_PIN 10s
#define TIMEOUT_NETWORK 10s
/** CellularStateMachine does connecting up to packet service attach, and
* after that it's up to CellularContext::connect() to connect to PDN.
Expand Down
2 changes: 1 addition & 1 deletion connectivity/drivers/cellular/GEMALTO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# SPDX-License-Identifier: Apache-2.0

if("COMPONENT_GEMALTO_CINTERION=1" IN_LIST MBED_TARGET_DEFINITIONS)
add_subdirectory(CINTERION)
add_subdirectory(COMPONENT_GEMALTO_CINTERION)
endif()
Loading
Loading