mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: Removed boiler plate code
parent
9cc1caa031
commit
77e8374058
|
@ -430,3 +430,25 @@ void ATHandler::flush()
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
nsapi_error_t ATHandler::at_cmd_str(const char *cmd, const char* cmd_chr, char *resp_buf, size_t buf_size, const char* format, ...)
|
||||
{
|
||||
read_string(resp_buf, buf_size);
|
||||
return ATHandler_stub::nsapi_error_value;
|
||||
}
|
||||
|
||||
nsapi_error_t ATHandler::at_cmd_int(const char *cmd, const char* cmd_chr, int &resp, const char* format, ...)
|
||||
{
|
||||
resp = read_int();
|
||||
return ATHandler_stub::nsapi_error_value;
|
||||
}
|
||||
|
||||
void ATHandler::cmd_start_stop(const char *cmd, const char* cmd_chr, const char* format, ...)
|
||||
{
|
||||
}
|
||||
|
||||
nsapi_error_t ATHandler::at_cmd_discard(const char *cmd, const char* cmd_chr, const char* format, ...)
|
||||
{
|
||||
return ATHandler_stub::nsapi_error_value;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "rtos/ThisThread.h"
|
||||
#include "Kernel.h"
|
||||
#include "CellularUtil.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
@ -61,6 +62,19 @@ static const uint8_t map_3gpp_errors[][2] = {
|
|||
{ 146, 46 }, { 178, 65 }, { 179, 66 }, { 180, 48 }, { 181, 83 }, { 171, 49 },
|
||||
};
|
||||
|
||||
bool ATHandler::ok_to_proceed()
|
||||
{
|
||||
if (_last_err != NSAPI_ERROR_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
|
||||
_nextATHandler(0),
|
||||
_fileHandle(NULL), // filehandle is set by set_file_handle()
|
||||
|
@ -404,12 +418,7 @@ int ATHandler::get_char()
|
|||
|
||||
void ATHandler::skip_param(uint32_t count)
|
||||
{
|
||||
if (_last_err || !_stop_tag || _stop_tag->found) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed() || !_stop_tag || _stop_tag->found) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -438,11 +447,7 @@ void ATHandler::skip_param(uint32_t count)
|
|||
|
||||
void ATHandler::skip_param(ssize_t len, uint32_t count)
|
||||
{
|
||||
if (_last_err || !_stop_tag || _stop_tag->found) {
|
||||
return;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed() || !_stop_tag || _stop_tag->found) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -462,11 +467,7 @@ void ATHandler::skip_param(ssize_t len, uint32_t count)
|
|||
|
||||
ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
|
||||
{
|
||||
if (_last_err) {
|
||||
return -1;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -490,11 +491,7 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
|
|||
|
||||
ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
|
||||
{
|
||||
if (_last_err || !_stop_tag || (_stop_tag->found && read_even_stop_tag == false)) {
|
||||
return -1;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed() || !_stop_tag || (_stop_tag->found && read_even_stop_tag == false)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -560,11 +557,7 @@ ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
|
|||
|
||||
ssize_t ATHandler::read_hex_string(char *buf, size_t size)
|
||||
{
|
||||
if (_last_err || !_stop_tag || _stop_tag->found) {
|
||||
return -1;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed() || !_stop_tag || _stop_tag->found) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -636,11 +629,7 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
|
|||
|
||||
int32_t ATHandler::read_int()
|
||||
{
|
||||
if (_last_err || !_stop_tag || _stop_tag->found) {
|
||||
return -1;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed() || !_stop_tag || _stop_tag->found) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -899,11 +888,7 @@ void ATHandler::resp(const char *prefix, bool check_urc)
|
|||
|
||||
void ATHandler::resp_start(const char *prefix, bool stop)
|
||||
{
|
||||
if (_last_err) {
|
||||
return;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -929,11 +914,7 @@ void ATHandler::resp_start(const char *prefix, bool stop)
|
|||
// check urc because of error as urc
|
||||
bool ATHandler::info_resp()
|
||||
{
|
||||
if (_last_err || _resp_stop.found) {
|
||||
return false;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed() || _resp_stop.found) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -963,11 +944,7 @@ bool ATHandler::info_resp()
|
|||
|
||||
bool ATHandler::info_elem(char start_tag)
|
||||
{
|
||||
if (_last_err) {
|
||||
return false;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1152,11 +1129,7 @@ const char *ATHandler::mem_str(const char *dest, size_t dest_len, const char *sr
|
|||
|
||||
void ATHandler::cmd_start(const char *cmd)
|
||||
{
|
||||
if (_last_err != NSAPI_ERROR_OK) {
|
||||
return;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1169,6 +1142,114 @@ void ATHandler::cmd_start(const char *cmd)
|
|||
_cmd_start = true;
|
||||
}
|
||||
|
||||
void ATHandler::handle_args(const char* format, va_list list)
|
||||
{
|
||||
while (*format != '\0') {
|
||||
if (*format == 'd') {
|
||||
int i = va_arg(list, int);
|
||||
write_int(i);
|
||||
} else if (*format == 's') {
|
||||
char * str = (char *)va_arg(list, char*);
|
||||
write_string(str);
|
||||
} else if (*format == 'b') {
|
||||
uint8_t *bytes = va_arg(list, uint8_t*);
|
||||
int size = va_arg(list, int);
|
||||
write_bytes(bytes, size);
|
||||
}
|
||||
++format;
|
||||
}
|
||||
}
|
||||
|
||||
void ATHandler::handle_start(const char *cmd, const char *cmd_chr)
|
||||
{
|
||||
int len = 0;
|
||||
memcpy(_cmd_buffer, "AT", 2);
|
||||
len +=2;
|
||||
memcpy(_cmd_buffer + len, cmd, strlen(cmd));
|
||||
len += strlen(cmd);
|
||||
|
||||
if (cmd_chr && strlen(cmd_chr)) {
|
||||
memcpy(_cmd_buffer + len, cmd_chr, strlen(cmd_chr));
|
||||
len += strlen(cmd_chr);
|
||||
}
|
||||
_cmd_buffer[len] = '\0';
|
||||
cmd_start(_cmd_buffer);
|
||||
}
|
||||
|
||||
void ATHandler::cmd_start_stop(const char *cmd, const char* cmd_chr, const char* format, ...)
|
||||
{
|
||||
handle_start(cmd, cmd_chr);
|
||||
|
||||
va_list list;
|
||||
va_start(list, format);
|
||||
handle_args(format, list);
|
||||
va_end(list);
|
||||
|
||||
cmd_stop();
|
||||
}
|
||||
|
||||
nsapi_error_t ATHandler::at_cmd_str(const char *cmd, const char* cmd_chr, char *resp_buf, size_t buf_size, const char* format, ...)
|
||||
{
|
||||
lock();
|
||||
|
||||
handle_start(cmd, cmd_chr);
|
||||
|
||||
va_list list;
|
||||
va_start(list, format);
|
||||
handle_args(format, list);
|
||||
va_end(list);
|
||||
|
||||
cmd_stop();
|
||||
|
||||
memcpy(_cmd_buffer, cmd, strlen(cmd));
|
||||
_cmd_buffer[strlen(cmd)] = ':';
|
||||
_cmd_buffer[strlen(cmd)+1] = '\0';
|
||||
resp_start(_cmd_buffer);
|
||||
|
||||
read_string(resp_buf, buf_size);
|
||||
resp_stop();
|
||||
return unlock_return_error();
|
||||
}
|
||||
|
||||
nsapi_error_t ATHandler::at_cmd_int(const char *cmd, const char* cmd_chr, int &resp, const char* format, ...)
|
||||
{
|
||||
lock();
|
||||
|
||||
handle_start(cmd, cmd_chr);
|
||||
|
||||
va_list list;
|
||||
va_start(list, format);
|
||||
handle_args(format, list);
|
||||
va_end(list);
|
||||
|
||||
cmd_stop();
|
||||
char temp[16];
|
||||
size_t len = strlen(cmd);
|
||||
memcpy(temp, cmd, len);
|
||||
temp[len] = ':';
|
||||
temp[len+1] = '\0';
|
||||
resp_start(temp);
|
||||
|
||||
resp = read_int();
|
||||
resp_stop();
|
||||
return unlock_return_error();
|
||||
}
|
||||
|
||||
nsapi_error_t ATHandler::at_cmd_discard(const char *cmd, const char* cmd_chr, const char* format, ...)
|
||||
{
|
||||
lock();
|
||||
|
||||
handle_start(cmd, cmd_chr);
|
||||
|
||||
va_list list;
|
||||
va_start(list, format);
|
||||
handle_args(format, list);
|
||||
va_end(list);
|
||||
|
||||
cmd_stop_read_resp();
|
||||
return unlock_return_error();
|
||||
}
|
||||
|
||||
void ATHandler::write_int(int32_t param)
|
||||
{
|
||||
// do common checks before sending subparameter
|
||||
|
@ -1207,11 +1288,7 @@ void ATHandler::write_string(const char *param, bool useQuotations)
|
|||
|
||||
void ATHandler::cmd_stop()
|
||||
{
|
||||
if (_last_err != NSAPI_ERROR_OK) {
|
||||
return;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed()) {
|
||||
return;
|
||||
}
|
||||
// Finish with CR
|
||||
|
@ -1227,11 +1304,7 @@ void ATHandler::cmd_stop_read_resp()
|
|||
|
||||
size_t ATHandler::write_bytes(const uint8_t *data, size_t len)
|
||||
{
|
||||
if (_last_err != NSAPI_ERROR_OK) {
|
||||
return 0;
|
||||
}
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
if (!ok_to_proceed()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1275,25 +1348,18 @@ size_t ATHandler::write(const void *data, size_t len)
|
|||
// do common checks before sending subparameters
|
||||
bool ATHandler::check_cmd_send()
|
||||
{
|
||||
if (_last_err != NSAPI_ERROR_OK) {
|
||||
if (!ok_to_proceed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_is_fh_usable) {
|
||||
_last_err = NSAPI_ERROR_BUSY;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't write delimiter if flag was set so
|
||||
if (!_use_delimiter) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Don't write delimiter if this is the first subparameter
|
||||
if (_cmd_start) {
|
||||
_cmd_start = false;
|
||||
} else {
|
||||
if (write(&_delimiter, 1) != 1) {
|
||||
if (_use_delimiter && write(&_delimiter, 1) != 1) {
|
||||
// writing of delimiter failed, return. write() already have set the _last_err
|
||||
return false;
|
||||
}
|
||||
|
@ -1374,10 +1440,7 @@ bool ATHandler::sync(int timeout_ms)
|
|||
// especially a common response like OK could be response to previous request.
|
||||
clear_error();
|
||||
_start_time = rtos::Kernel::get_ms_count();
|
||||
cmd_start("AT+CMEE?");
|
||||
cmd_stop();
|
||||
resp_start("+CMEE:");
|
||||
resp_stop();
|
||||
at_cmd_discard("+CMEE", "?");
|
||||
if (!_last_err) {
|
||||
_at_timeout = timeout;
|
||||
unlock();
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "PlatformMutex.h"
|
||||
#include "Callback.h"
|
||||
#include <cstdarg>
|
||||
|
||||
namespace mbed {
|
||||
|
||||
|
@ -260,6 +261,54 @@ public:
|
|||
*/
|
||||
virtual void cmd_start(const char *cmd);
|
||||
|
||||
/**
|
||||
* @brief cmd_start_stop Starts an AT command, writes given variadic arguments and stops the command. Use this
|
||||
* command when you need multiple responses to be handled.
|
||||
* NOTE: Does not lock ATHandler for process!
|
||||
*
|
||||
* @param cmd AT command in form +<CMD> (will be used also in response reading, no extra chars allowed)
|
||||
* @param cmd_chr Char to be added to specific AT command: '?', '=' or ''. Will be used as such so '=1' is valid as well.
|
||||
* @param format Format string for variadic arguments to be added to AT command; No separator needed.
|
||||
* Use %d for integer, %s for string and %b for byte string (requires 2 arguments: string and length)
|
||||
*/
|
||||
void cmd_start_stop(const char *cmd, const char* cmd_chr, const char* format = "", ...);
|
||||
|
||||
/**
|
||||
* @brief at_cmd_str Send an AT command and read 1 line string response. Locks and unlocks ATHandler for operation
|
||||
* @param cmd AT command in form +<CMD> (will be used also in response reading, no extra chars allowed)
|
||||
* @param cmd_chr Char to be added to specific AT command: '?', '=' or ''. Will be used as such so '=1' is valid as well.
|
||||
* @param resp_buf Response buffer
|
||||
* @param resp_buf_size Response buffer size
|
||||
* @param format Format string for variadic arguments to be added to AT command; No separator needed.
|
||||
* Use %d for integer, %s for string and %b for byte string (requires 2 arguments: string and length)
|
||||
* @return @return last error that happened when parsing AT responses
|
||||
*/
|
||||
nsapi_error_t at_cmd_str(const char *cmd, const char* cmd_chr, char *resp_buf, size_t resp_buf_size, const char* format = "", ...);
|
||||
|
||||
/**
|
||||
* @brief at_cmd_int Send an AT command and read 1 line integer response. Locks and unlocks ATHandler for operation
|
||||
* @param cmd AT command in form +<CMD> (will be used also in response reading, no extra chars allowed)
|
||||
* @param cmd_chr Char to be added to specific AT command: '?', '=' or ''. Will be used as such so '=1' is valid as well.
|
||||
* @param resp Integer to hold response
|
||||
* @param format Format string for variadic arguments to be added to AT command; No separator needed.
|
||||
* Use %d for integer, %s for string and %b for byte string (requires 2 arguments: string and length)
|
||||
* @return @return last error that happened when parsing AT responses
|
||||
*/
|
||||
nsapi_error_t at_cmd_int(const char *cmd, const char* cmd_chr, int &resp, const char* format = "", ...);
|
||||
|
||||
/**
|
||||
* @brief at_cmd_discard Send an AT command and read and discard a response. Locks and unlocks ATHandler for operation
|
||||
* @param cmd AT command in form +<CMD> (will be used also in response reading, no extra chars allowed)
|
||||
* @param cmd_chr Char to be added to specific AT command: '?', '=' or ''. Will be used as such so '=1' is valid as well.
|
||||
* @param resp Integer to hold response
|
||||
* @param format Format string for variadic arguments to be added to AT command; No separator needed.
|
||||
* Use %d for integer, %s for string and %b for byte string (requires 2 arguments: string and length)
|
||||
* @return @return last error that happened when parsing AT responses
|
||||
*/
|
||||
nsapi_error_t at_cmd_discard(const char *cmd, const char* cmd_chr, const char* format = "", ...);
|
||||
|
||||
public:
|
||||
|
||||
/** Writes integer type AT command subparameter. Starts with the delimiter if not the first param after cmd_start.
|
||||
* In case of failure when writing, the last error is set to NSAPI_ERROR_DEVICE_ERROR.
|
||||
*
|
||||
|
@ -497,6 +546,19 @@ private:
|
|||
// time when a command or an URC processing was started
|
||||
uint64_t _start_time;
|
||||
|
||||
char _cmd_buffer[BUFF_SIZE];
|
||||
|
||||
private:
|
||||
//Handles the arguments from given variadic list
|
||||
void handle_args(const char* format, va_list list);
|
||||
|
||||
//Starts an AT command based on given parameters
|
||||
void handle_start(const char *cmd, const char *cmd_chr);
|
||||
|
||||
//Checks that ATHandler does not have a pending error condition and filehandle is usable
|
||||
bool ok_to_proceed();
|
||||
|
||||
private:
|
||||
// Gets char from receiving buffer.
|
||||
// Resets and fills the buffer if all are already read (receiving position equals receiving length).
|
||||
// Returns a next char or -1 on failure (also sets error flag)
|
||||
|
|
|
@ -301,9 +301,8 @@ nsapi_error_t AT_CellularContext::delete_current_context()
|
|||
{
|
||||
tr_info("Delete context %d", _cid);
|
||||
_at.clear_error();
|
||||
_at.cmd_start("AT+CGDCONT=");
|
||||
_at.write_int(_cid);
|
||||
_at.cmd_stop_read_resp();
|
||||
|
||||
_at.at_cmd_discard("+CGDCONT", "=", "%d", _cid);
|
||||
|
||||
if (_at.get_last_error() == NSAPI_ERROR_OK) {
|
||||
_cid = -1;
|
||||
|
@ -320,19 +319,13 @@ nsapi_error_t AT_CellularContext::do_user_authentication()
|
|||
if (!get_property(PROPERTY_AT_CGAUTH)) {
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
_at.cmd_start("AT+CGAUTH=");
|
||||
_at.write_int(_cid);
|
||||
_at.write_int(_authentication_type);
|
||||
|
||||
const bool stored_debug_state = _at.get_debug();
|
||||
_at.set_debug(false);
|
||||
|
||||
_at.write_string(_uname);
|
||||
_at.write_string(_pwd);
|
||||
_at.at_cmd_discard("+CGAUTH", "=", "%d%d%s%s", _cid, _authentication_type, _uname, _pwd);
|
||||
|
||||
_at.set_debug(stored_debug_state);
|
||||
|
||||
_at.cmd_stop_read_resp();
|
||||
if (_at.get_last_error() != NSAPI_ERROR_OK) {
|
||||
return NSAPI_ERROR_AUTH_FAILURE;
|
||||
}
|
||||
|
@ -359,8 +352,8 @@ bool AT_CellularContext::get_context()
|
|||
{
|
||||
bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_PDP_TYPE);
|
||||
bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_PDP_TYPE);
|
||||
_at.cmd_start("AT+CGDCONT?");
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.cmd_start_stop("+CGDCONT", "?");
|
||||
_at.resp_start("+CGDCONT:");
|
||||
_cid = -1;
|
||||
int cid_max = 0; // needed when creating new context
|
||||
|
@ -437,13 +430,8 @@ bool AT_CellularContext::set_new_context(int cid)
|
|||
}
|
||||
|
||||
//apn: "If the value is null or omitted, then the subscription value will be requested."
|
||||
bool success = false;
|
||||
_at.cmd_start("AT+CGDCONT=");
|
||||
_at.write_int(cid);
|
||||
_at.write_string(pdp_type_str);
|
||||
_at.write_string(_apn);
|
||||
_at.cmd_stop_read_resp();
|
||||
success = (_at.get_last_error() == NSAPI_ERROR_OK);
|
||||
|
||||
bool success = (_at.at_cmd_discard("+CGDCONT", "=", "%d%s%s", cid, pdp_type_str, _apn) == NSAPI_ERROR_OK);
|
||||
|
||||
if (success) {
|
||||
_pdp_type = pdp_type;
|
||||
|
@ -480,9 +468,7 @@ nsapi_error_t AT_CellularContext::activate_non_ip_context()
|
|||
void AT_CellularContext::activate_context()
|
||||
{
|
||||
tr_info("Activate PDP context %d", _cid);
|
||||
_at.cmd_start("AT+CGACT=1,");
|
||||
_at.write_int(_cid);
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+CGACT", "=1,", "%d", _cid);
|
||||
if (_at.get_last_error() == NSAPI_ERROR_OK) {
|
||||
_is_context_activated = true;
|
||||
}
|
||||
|
@ -589,8 +575,7 @@ nsapi_error_t AT_CellularContext::open_data_channel()
|
|||
|
||||
tr_info("CellularContext PPP connect");
|
||||
if (get_property(PROPERTY_AT_CGDATA)) {
|
||||
_at.cmd_start("AT+CGDATA=\"PPP\",");
|
||||
_at.write_int(_cid);
|
||||
_at.cmd_start_stop("+CGDATA", "=\"PPP\",", "%d", _cid);
|
||||
} else {
|
||||
MBED_ASSERT(_cid >= 0 && _cid <= 99);
|
||||
_at.cmd_start("ATD*99***");
|
||||
|
@ -598,8 +583,8 @@ nsapi_error_t AT_CellularContext::open_data_channel()
|
|||
_at.write_int(_cid);
|
||||
_at.write_string("#", false);
|
||||
_at.use_delimiter(true);
|
||||
_at.cmd_stop();
|
||||
}
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.resp_start("CONNECT", true);
|
||||
if (_at.get_last_error()) {
|
||||
|
@ -719,9 +704,7 @@ void AT_CellularContext::deactivate_non_ip_context()
|
|||
|
||||
void AT_CellularContext::deactivate_context()
|
||||
{
|
||||
_at.cmd_start("AT+CGACT=0,");
|
||||
_at.write_int(_cid);
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+CGACT", "=0,", "%d", _cid);
|
||||
}
|
||||
|
||||
void AT_CellularContext::check_and_deactivate_context()
|
||||
|
@ -745,9 +728,7 @@ void AT_CellularContext::check_and_deactivate_context()
|
|||
|
||||
if (_new_context_set) {
|
||||
_at.clear_error();
|
||||
_at.cmd_start("AT+CGDCONT=");
|
||||
_at.write_int(_cid);
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+CGDCONT", "=", "%d", _cid);
|
||||
}
|
||||
|
||||
_at.restore_at_timeout();
|
||||
|
@ -758,9 +739,7 @@ nsapi_error_t AT_CellularContext::get_apn_backoff_timer(int &backoff_timer)
|
|||
// If apn is set
|
||||
if (_apn) {
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CABTRDP=");
|
||||
_at.write_string(_apn);
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+CABTRDP", "=", "%s", _apn);
|
||||
_at.resp_start("+CABTRDP:");
|
||||
if (_at.info_resp()) {
|
||||
_at.skip_param();
|
||||
|
@ -779,9 +758,7 @@ nsapi_error_t AT_CellularContext::get_rate_control(
|
|||
{
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+CGAPNRC=");
|
||||
_at.write_int(_cid);
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+CGAPNRC", "=", "%d", _cid);
|
||||
|
||||
_at.resp_start("+CGAPNRC:");
|
||||
_at.read_int();
|
||||
|
@ -823,9 +800,7 @@ nsapi_error_t AT_CellularContext::get_pdpcontext_params(pdpContextList_t ¶ms
|
|||
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+CGCONTRDP=");
|
||||
_at.write_int(_cid);
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+CGCONTRDP", "=", "%d", _cid);
|
||||
|
||||
_at.resp_start("+CGCONTRDP:");
|
||||
pdpcontext_params_t *params = NULL;
|
||||
|
|
|
@ -184,10 +184,10 @@ nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state)
|
|||
char simstr[MAX_SIM_RESPONSE_LENGTH];
|
||||
_at->lock();
|
||||
_at->flush();
|
||||
_at->cmd_start("AT+CPIN?");
|
||||
_at->cmd_stop();
|
||||
_at->resp_start("+CPIN:");
|
||||
ssize_t len = _at->read_string(simstr, sizeof(simstr));
|
||||
nsapi_error_t error = _at->at_cmd_str("+CPIN", "?", simstr, sizeof(simstr));
|
||||
ssize_t len = strlen(simstr);
|
||||
_at->unlock();
|
||||
|
||||
if (len != -1) {
|
||||
if (len >= 5 && memcmp(simstr, "READY", 5) == 0) {
|
||||
state = SimStateReady;
|
||||
|
@ -204,9 +204,6 @@ nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state)
|
|||
tr_warn("SIM not readable.");
|
||||
state = SimStateUnknown; // SIM may not be ready yet or +CPIN may be unsupported command
|
||||
}
|
||||
_at->resp_stop();
|
||||
nsapi_error_t error = _at->get_last_error();
|
||||
_at->unlock();
|
||||
#if MBED_CONF_MBED_TRACE_ENABLE
|
||||
switch (state) {
|
||||
case SimStatePinNeeded:
|
||||
|
@ -240,16 +237,14 @@ nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin)
|
|||
}
|
||||
|
||||
_at->lock();
|
||||
_at->cmd_start("AT+CPIN=");
|
||||
|
||||
const bool stored_debug_state = _at->get_debug();
|
||||
_at->set_debug(false);
|
||||
|
||||
_at->write_string(sim_pin);
|
||||
_at->at_cmd_discard("+CPIN", "=,", "%s", sim_pin);
|
||||
|
||||
_at->set_debug(stored_debug_state);
|
||||
|
||||
_at->cmd_stop_read_resp();
|
||||
return _at->unlock_return_error();
|
||||
}
|
||||
|
||||
|
@ -431,41 +426,34 @@ nsapi_error_t AT_CellularDevice::init()
|
|||
{
|
||||
_at->lock();
|
||||
_at->flush();
|
||||
_at->cmd_start("ATE0"); // echo off
|
||||
_at->cmd_stop_read_resp();
|
||||
_at->at_cmd_discard("E0", "");
|
||||
|
||||
_at->cmd_start("AT+CMEE=1"); // verbose responses
|
||||
_at->cmd_stop_read_resp();
|
||||
_at->at_cmd_discard("+CMEE", "=1");
|
||||
|
||||
_at->cmd_start("AT+CFUN=1"); // set full functionality
|
||||
_at->cmd_stop_read_resp();
|
||||
_at->at_cmd_discard("+CFUN", "=1");
|
||||
|
||||
return _at->unlock_return_error();
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularDevice::shutdown()
|
||||
{
|
||||
_at->lock();
|
||||
if (_state_machine) {
|
||||
_state_machine->reset();
|
||||
}
|
||||
CellularDevice::shutdown();
|
||||
_at->cmd_start("AT+CFUN=0");// set to minimum functionality
|
||||
_at->cmd_stop_read_resp();
|
||||
return _at->unlock_return_error();
|
||||
|
||||
return _at->at_cmd_discard("+CFUN", "=0");
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularDevice::is_ready()
|
||||
{
|
||||
_at->lock();
|
||||
_at->cmd_start("AT");
|
||||
_at->cmd_stop_read_resp();
|
||||
_at->at_cmd_discard("", "");
|
||||
|
||||
// we need to do this twice because for example after data mode the first 'AT' command will give modem a
|
||||
// stimulus that we are back to command mode.
|
||||
_at->clear_error();
|
||||
_at->cmd_start("AT");
|
||||
_at->cmd_stop_read_resp();
|
||||
_at->at_cmd_discard("", "");
|
||||
|
||||
return _at->unlock_return_error();
|
||||
}
|
||||
|
@ -480,9 +468,7 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti
|
|||
|
||||
if (periodic_time == 0 && active_time == 0) {
|
||||
// disable PSM
|
||||
_at->cmd_start("AT+CPSMS=");
|
||||
_at->write_int(0);
|
||||
_at->cmd_stop_read_resp();
|
||||
_at->at_cmd_discard("+CPSMS", "=0");
|
||||
} else {
|
||||
const int PSMTimerBits = 5;
|
||||
|
||||
|
@ -583,13 +569,8 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti
|
|||
at[8] = '\0';
|
||||
|
||||
// request for both GPRS and LTE
|
||||
_at->cmd_start("AT+CPSMS=");
|
||||
_at->write_int(1);
|
||||
_at->write_string(pt);
|
||||
_at->write_string(at);
|
||||
_at->write_string(pt);
|
||||
_at->write_string(at);
|
||||
_at->cmd_stop_read_resp();
|
||||
|
||||
_at->at_cmd_discard("+CPSMS", "=1,", "%s%s%s%s", pt, at, pt, at);
|
||||
|
||||
if (_at->get_last_error() != NSAPI_ERROR_OK) {
|
||||
tr_warn("Power save mode not enabled!");
|
||||
|
|
|
@ -58,14 +58,7 @@ nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_si
|
|||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CGSN=");
|
||||
_at.write_int(type);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+CGSN:");
|
||||
_at.read_string(buf, buf_size);
|
||||
_at.resp_stop();
|
||||
return _at.unlock_return_error();
|
||||
return _at.at_cmd_str("+CGSN", "=", buf, buf_size, "%d", type);
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_t buf_size)
|
||||
|
@ -103,11 +96,5 @@ nsapi_error_t AT_CellularInformation::get_iccid(char *buf, size_t buf_size)
|
|||
if (buf == NULL || buf_size == 0) {
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CCID?");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+CCID:");
|
||||
_at.read_string(buf, buf_size);
|
||||
_at.resp_stop();
|
||||
return _at.unlock_return_error();
|
||||
return _at.at_cmd_str("+CCID", "?", buf, buf_size);
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ struct at_reg_t {
|
|||
};
|
||||
|
||||
static const at_reg_t at_reg[] = {
|
||||
{ CellularNetwork::C_EREG, "AT+CEREG", "+CEREG:"},
|
||||
{ CellularNetwork::C_GREG, "AT+CGREG", "+CGREG:"},
|
||||
{ CellularNetwork::C_REG, "AT+CREG", "+CREG:"}
|
||||
{ CellularNetwork::C_EREG, "+CEREG", "+CEREG:"},
|
||||
{ CellularNetwork::C_GREG, "+CGREG", "+CGREG:"},
|
||||
{ CellularNetwork::C_REG, "+CREG", "+CREG:"}
|
||||
};
|
||||
|
||||
#if MBED_CONF_MBED_TRACE_ENABLE
|
||||
|
@ -189,61 +189,41 @@ nsapi_error_t AT_CellularNetwork::set_registration_urc(RegistrationType type, bo
|
|||
if (mode == RegistrationModeDisable) {
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
} else {
|
||||
_at.lock();
|
||||
if (urc_on) {
|
||||
_at.cmd_start(at_reg[index].cmd);
|
||||
const uint8_t ch_eq = '=';
|
||||
_at.write_bytes(&ch_eq, 1);
|
||||
_at.write_int((int)mode);
|
||||
return _at.at_cmd_discard(at_reg[index].cmd, "=", "%d", mode);
|
||||
} else {
|
||||
_at.cmd_start(at_reg[index].cmd);
|
||||
_at.write_string("=0", false);
|
||||
return _at.at_cmd_discard(at_reg[index].cmd, "=0");
|
||||
}
|
||||
|
||||
_at.cmd_stop_read_resp();
|
||||
return _at.unlock_return_error();
|
||||
}
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularNetwork::get_network_registering_mode(NWRegisteringMode &mode)
|
||||
{
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+COPS?");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+COPS:");
|
||||
mode = (NWRegisteringMode)_at.read_int();
|
||||
_at.resp_stop();
|
||||
|
||||
return _at.unlock_return_error();
|
||||
int ret;
|
||||
nsapi_error_t error = _at.at_cmd_int("+COPS", "?", ret);
|
||||
mode = (NWRegisteringMode)ret;
|
||||
return error;
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn)
|
||||
{
|
||||
_at.lock();
|
||||
|
||||
if (!plmn) {
|
||||
tr_debug("Automatic network registration");
|
||||
_at.cmd_start("AT+COPS?");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+COPS:");
|
||||
int mode = _at.read_int();
|
||||
_at.resp_stop();
|
||||
if (mode != 0) {
|
||||
_at.clear_error();
|
||||
_at.cmd_start("AT+COPS=0");
|
||||
_at.cmd_stop_read_resp();
|
||||
NWRegisteringMode mode;
|
||||
get_network_registering_mode(mode);
|
||||
|
||||
if (mode != NWModeAutomatic) {
|
||||
return _at.at_cmd_discard("+COPS", "=0");
|
||||
}
|
||||
} else {
|
||||
tr_debug("Manual network registration to %s", plmn);
|
||||
_at.cmd_start("AT+COPS=1,2,");
|
||||
_at.write_string(plmn);
|
||||
if (_op_act != RAT_UNKNOWN) {
|
||||
_at.write_int(_op_act);
|
||||
return _at.at_cmd_discard("+COPS", "=1,2,", "%s%d", plmn, _op_act);
|
||||
} else {
|
||||
return _at.at_cmd_discard("+COPS", "=1,2", "%s", plmn);
|
||||
}
|
||||
_at.cmd_stop_read_resp();
|
||||
}
|
||||
|
||||
return _at.unlock_return_error();
|
||||
}
|
||||
|
||||
void AT_CellularNetwork::read_reg_params(RegistrationType type, registration_params_t ®_params)
|
||||
|
@ -290,16 +270,12 @@ void AT_CellularNetwork::read_reg_params(RegistrationType type, registration_par
|
|||
nsapi_error_t AT_CellularNetwork::set_attach()
|
||||
{
|
||||
_at.lock();
|
||||
AttachStatus status;
|
||||
get_attach(status);
|
||||
|
||||
_at.cmd_start("AT+CGATT?");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+CGATT:");
|
||||
int attached_state = _at.read_int();
|
||||
_at.resp_stop();
|
||||
if (attached_state != 1) {
|
||||
if (status == Detached) {
|
||||
tr_debug("Network attach");
|
||||
_at.cmd_start("AT+CGATT=1");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+CGATT", "=1");
|
||||
}
|
||||
|
||||
return _at.unlock_return_error();
|
||||
|
@ -307,31 +283,19 @@ nsapi_error_t AT_CellularNetwork::set_attach()
|
|||
|
||||
nsapi_error_t AT_CellularNetwork::get_attach(AttachStatus &status)
|
||||
{
|
||||
_at.lock();
|
||||
int attach_status;
|
||||
nsapi_error_t err = _at.at_cmd_int("+CGATT", "?", attach_status);
|
||||
status = (attach_status == 1) ? Attached : Detached;
|
||||
|
||||
_at.cmd_start("AT+CGATT?");
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.resp_start("+CGATT:");
|
||||
if (_at.info_resp()) {
|
||||
int attach_status = _at.read_int();
|
||||
status = (attach_status == 1) ? Attached : Detached;
|
||||
}
|
||||
_at.resp_stop();
|
||||
|
||||
return _at.unlock_return_error();
|
||||
return err;
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularNetwork::detach()
|
||||
{
|
||||
_at.lock();
|
||||
|
||||
tr_debug("Network detach");
|
||||
_at.cmd_start("AT+CGATT=0");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+CGATT", "=0");
|
||||
|
||||
_at.cmd_start("AT+COPS=2");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+COPS", "=2");
|
||||
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED);
|
||||
|
||||
|
@ -361,8 +325,7 @@ nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount
|
|||
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+COPS=?");
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+COPS", "?");
|
||||
|
||||
_at.resp_start("+COPS:");
|
||||
|
||||
|
@ -400,15 +363,7 @@ nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(CIoT_Supported_Op
|
|||
Callback<void(CIoT_Supported_Opt)> network_support_cb)
|
||||
{
|
||||
_ciotopt_network_support_cb = network_support_cb;
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+CCIOTOPT=");
|
||||
_at.write_int(1); //enable CCIOTOPTI URC
|
||||
_at.write_int(supported_opt);
|
||||
_at.write_int(preferred_opt);
|
||||
_at.cmd_stop_read_resp();
|
||||
|
||||
return _at.unlock_return_error();
|
||||
return _at.at_cmd_discard("+CCIOTOPT", "=1,", "%d%d", supported_opt, preferred_opt);
|
||||
}
|
||||
|
||||
void AT_CellularNetwork::urc_cciotopti()
|
||||
|
@ -425,8 +380,7 @@ nsapi_error_t AT_CellularNetwork::get_ciot_ue_optimization_config(CIoT_Supported
|
|||
{
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+CCIOTOPT?");
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+CCIOTOPT", "?");
|
||||
|
||||
_at.resp_start("+CCIOTOPT:");
|
||||
_at.read_int();
|
||||
|
@ -450,8 +404,7 @@ nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int *ber)
|
|||
{
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+CSQ");
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+CSQ", "");
|
||||
|
||||
_at.resp_start("+CSQ:");
|
||||
int t_rssi = _at.read_int();
|
||||
|
@ -492,8 +445,7 @@ nsapi_error_t AT_CellularNetwork::get_operator_params(int &format, operator_t &o
|
|||
{
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+COPS?");
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+COPS", "?");
|
||||
|
||||
_at.resp_start("+COPS:");
|
||||
_at.read_int(); //ignore mode
|
||||
|
@ -523,8 +475,7 @@ nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_nam
|
|||
{
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+COPN");
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+COPN", "");
|
||||
|
||||
_at.resp_start("+COPN:");
|
||||
operator_names_t *names = NULL;
|
||||
|
@ -540,8 +491,7 @@ nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_nam
|
|||
|
||||
void AT_CellularNetwork::get_context_state_command()
|
||||
{
|
||||
_at.cmd_start("AT+CGACT?");
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+CGACT", "?");
|
||||
_at.resp_start("+CGACT:");
|
||||
}
|
||||
|
||||
|
@ -597,12 +547,9 @@ nsapi_error_t AT_CellularNetwork::get_registration_params(RegistrationType type,
|
|||
|
||||
_at.lock();
|
||||
|
||||
const char *rsp[] = { "+CEREG:", "+CGREG:", "+CREG:"};
|
||||
_at.cmd_start(at_reg[i].cmd);
|
||||
_at.write_string("?", false);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start(rsp[i]);
|
||||
_at.cmd_start_stop(at_reg[i].cmd, "?");
|
||||
|
||||
_at.resp_start(at_reg[i].urc_prefix);
|
||||
(void)_at.read_int(); // ignore urc mode subparam
|
||||
read_reg_params(type, reg_params);
|
||||
_at.resp_stop();
|
||||
|
@ -670,15 +617,7 @@ nsapi_error_t AT_CellularNetwork::set_receive_period(int mode, EDRXAccessTechnol
|
|||
uint_to_binary_str(edrx_value, edrx, 5, 4);
|
||||
edrx[4] = '\0';
|
||||
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+CEDRXS=");
|
||||
_at.write_int(mode);
|
||||
_at.write_int(act_type);
|
||||
_at.write_string(edrx);
|
||||
_at.cmd_stop_read_resp();
|
||||
|
||||
return _at.unlock_return_error();
|
||||
return _at.at_cmd_discard("+CEDRXS", "=", "%d%d%s", mode, act_type, edrx);
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularNetwork::set_packet_domain_event_reporting(bool on)
|
||||
|
@ -687,10 +626,5 @@ nsapi_error_t AT_CellularNetwork::set_packet_domain_event_reporting(bool on)
|
|||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CGEREP=");
|
||||
_at.write_int(on ? 1 : 0); // discard unsolicited result codes when MT TE link is reserved (e.g. in on line data mode); otherwise forward them directly to the TE
|
||||
_at.cmd_stop_read_resp();
|
||||
|
||||
return _at.unlock_return_error();
|
||||
return _at.at_cmd_discard("+CGEREP", "=", "%d", on ? 1 : 0);
|
||||
}
|
||||
|
|
|
@ -213,10 +213,8 @@ nsapi_error_t AT_CellularSMS::set_cnmi()
|
|||
if (!get_property(PROPERTY_AT_CNMI)) {
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CNMI=2,1");
|
||||
_at.cmd_stop_read_resp();
|
||||
return _at.unlock_return_error();
|
||||
|
||||
return _at.at_cmd_discard("+CNMI", "=2,1");
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularSMS::set_cmgf(int msg_format)
|
||||
|
@ -224,11 +222,8 @@ nsapi_error_t AT_CellularSMS::set_cmgf(int msg_format)
|
|||
if (!get_property(PROPERTY_AT_CMGF)) {
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CMGF=");
|
||||
_at.write_int(msg_format);
|
||||
_at.cmd_stop_read_resp();
|
||||
return _at.unlock_return_error();
|
||||
|
||||
return _at.at_cmd_discard("+CMGF", "=", "%d", msg_format);
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularSMS::set_csmp(int fo, int vp, int pid, int dcs)
|
||||
|
@ -236,14 +231,8 @@ nsapi_error_t AT_CellularSMS::set_csmp(int fo, int vp, int pid, int dcs)
|
|||
if (!get_property(PROPERTY_AT_CSMP)) {
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CSMP=");
|
||||
_at.write_int(fo);
|
||||
_at.write_int(vp);
|
||||
_at.write_int(pid);
|
||||
_at.write_int(dcs);
|
||||
_at.cmd_stop_read_resp();
|
||||
return _at.unlock_return_error();
|
||||
|
||||
return _at.at_cmd_discard("+CSMP", "=", "%d%d%d%d", fo, vp, pid, dcs);
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularSMS::set_csdh(int show_header)
|
||||
|
@ -251,11 +240,8 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header)
|
|||
if (!get_property(PROPERTY_AT_CSDH)) {
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CSDH=");
|
||||
_at.write_int(show_header);
|
||||
_at.cmd_stop_read_resp();
|
||||
return _at.unlock_return_error();
|
||||
|
||||
return _at.at_cmd_discard("+CSDH", "=", "%d", show_header);
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode)
|
||||
|
@ -422,9 +408,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
|
|||
wait_ms(_sim_wait_time);
|
||||
|
||||
if (_mode == CellularSMSMmodeText) {
|
||||
_at.cmd_start("AT+CMGS=");
|
||||
_at.write_string(phone_number + remove_plus_sign);
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+CMGS", "=", "%s", phone_number + remove_plus_sign);
|
||||
|
||||
wait_ms(_sim_wait_time);
|
||||
_at.resp_start("> ", true);
|
||||
|
@ -485,9 +469,8 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
|
|||
pdu_len = strlen(pdu_str);
|
||||
|
||||
// specification says that service center number should not be included so we subtract -2 from pdu_len as we use '00' for automatic service center number
|
||||
_at.cmd_start("AT+CMGS=");
|
||||
_at.write_int((pdu_len - 2) / 2);
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.cmd_start_stop("+CMGS", "=", "%d", (pdu_len - 2) / 2);
|
||||
|
||||
wait_ms(_sim_wait_time);
|
||||
_at.resp_start("> ", true);
|
||||
|
@ -540,44 +523,25 @@ void AT_CellularSMS::set_sms_callback(Callback<void()> func)
|
|||
|
||||
nsapi_error_t AT_CellularSMS::set_cpms(const char *memr, const char *memw, const char *mems)
|
||||
{
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CPMS=");
|
||||
_at.write_string(memr);
|
||||
_at.write_string(memw);
|
||||
_at.write_string(mems);
|
||||
_at.cmd_stop_read_resp();
|
||||
|
||||
return _at.unlock_return_error();
|
||||
return _at.at_cmd_discard("+CPMS", "=", "%s%s%s", memr, memw, mems);
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularSMS::set_csca(const char *sca, int type)
|
||||
{
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CSCA=");
|
||||
_at.write_string(sca);
|
||||
_at.write_int(type);
|
||||
_at.cmd_stop_read_resp();
|
||||
|
||||
return _at.unlock_return_error();
|
||||
return _at.at_cmd_discard("+CSCA", "=", "%s%d", sca, type);
|
||||
}
|
||||
|
||||
nsapi_size_or_error_t AT_CellularSMS::set_cscs(const char *chr_set)
|
||||
{
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CSCS=");
|
||||
_at.write_string(chr_set);
|
||||
_at.cmd_stop_read_resp();
|
||||
|
||||
return _at.unlock_return_error();
|
||||
return _at.at_cmd_discard("+CSCS", "=", "%s", chr_set);
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularSMS::delete_sms(sms_info_t *sms)
|
||||
{
|
||||
_at.lock();
|
||||
for (int i = 0; i < sms->parts; i++) {
|
||||
_at.cmd_start("AT+CMGD=");
|
||||
_at.write_int(sms->msg_index[i]);
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+CMGD", "=", "%d", sms->msg_index[i]);
|
||||
}
|
||||
|
||||
return _at.unlock_return_error();
|
||||
|
@ -589,10 +553,7 @@ nsapi_error_t AT_CellularSMS::delete_sms(sms_info_t *sms)
|
|||
// that was corrupted. So we need to have delete all messages.
|
||||
nsapi_error_t AT_CellularSMS::delete_all_messages()
|
||||
{
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CMGD=1,4");
|
||||
_at.cmd_stop_read_resp();
|
||||
return _at.unlock_return_error();
|
||||
return _at.at_cmd_discard("+CMGD", "=1,4");
|
||||
}
|
||||
|
||||
// read msg in text mode
|
||||
|
@ -603,9 +564,7 @@ nsapi_size_or_error_t AT_CellularSMS::read_sms_from_index(int msg_index, char *b
|
|||
* +CMGR: <stat>,<oa>,<alpha>,<scts>[,<tooa>,<fo>,<pid>,<dcs>,<sca>,<tosca>,<length>]<CR><LF><data><CR><LF>OK<CR><LF>
|
||||
*/
|
||||
wait_ms(_sim_wait_time);
|
||||
_at.cmd_start("AT+CMGR=");
|
||||
_at.write_int(msg_index);
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+CMGR", "=", "%d", msg_index);
|
||||
|
||||
// TODO: NOTE: If the selected <mem1> can contain different types of SMs (e.g. SMS-DELIVERs, SMS-SUBMITs, SMS-STATUS-REPORTs and SMS-COMMANDs),
|
||||
// the response may be a mix of the responses of different SM types. TE application can recognize the response format by examining the third response parameter.
|
||||
|
@ -662,9 +621,7 @@ nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t *sms, char *buf, char
|
|||
|
||||
for (int i = 0; i < sms->parts; i++) {
|
||||
wait_ms(_sim_wait_time);
|
||||
_at.cmd_start("AT+CMGR=");
|
||||
_at.write_int(sms->msg_index[i]);
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+CMGR", "=", "%d", sms->msg_index[i]);
|
||||
_at.resp_start("+CMGR:");
|
||||
|
||||
if (_at.info_resp()) {
|
||||
|
@ -1041,11 +998,10 @@ nsapi_error_t AT_CellularSMS::list_messages()
|
|||
// the response may be a mix of the responses of different SM types. TE application can recognize the response format by examining the third response parameter.
|
||||
// for now we assume that only SMS-DELIVER messages are read.
|
||||
if (_mode == CellularSMSMmodePDU) {
|
||||
_at.cmd_start("AT+CMGL=4");
|
||||
_at.cmd_start_stop("+CMGL", "=4");
|
||||
} else {
|
||||
_at.cmd_start("AT+CMGL=\"ALL\"");
|
||||
_at.cmd_start_stop("+CMGL", "=\"ALL\"");
|
||||
}
|
||||
_at.cmd_stop();
|
||||
|
||||
sms_info_t *info = NULL;
|
||||
// init for 1 so that in text mode we will add to the correct place without any additional logic in addInfo() in text mode
|
||||
|
|
|
@ -59,9 +59,7 @@ const char *AT_CellularStack::get_ip_address()
|
|||
{
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+CGPADDR=");
|
||||
_at.write_int(_cid);
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+CGPADDR", "=");
|
||||
|
||||
_at.resp_start("+CGPADDR:");
|
||||
|
||||
|
|
|
@ -34,12 +34,10 @@ nsapi_size_or_error_t AT_ControlPlane_netif::send(const void *cpdata, nsapi_size
|
|||
{
|
||||
//CSODCP
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CSODCP=");
|
||||
_at.write_int(_cid);
|
||||
_at.write_int(cpdata_length);
|
||||
_at.write_bytes((uint8_t *)cpdata, cpdata_length);
|
||||
|
||||
return _at.unlock_return_error();
|
||||
nsapi_size_or_error_t err = _at.at_cmd_discard("+CSODCP", "=", "%d%d%b", _cid, cpdata_length, cpdata, cpdata_length);
|
||||
|
||||
return (err == NSAPI_ERROR_OK) ? cpdata_length : err;
|
||||
}
|
||||
|
||||
nsapi_size_or_error_t AT_ControlPlane_netif::recv(void *cpdata, nsapi_size_t cpdata_length)
|
||||
|
@ -55,8 +53,9 @@ nsapi_size_or_error_t AT_ControlPlane_netif::recv(void *cpdata, nsapi_size_t cpd
|
|||
}
|
||||
|
||||
memcpy(cpdata, _recv_buffer, _recv_len);
|
||||
|
||||
return _recv_len = 0;
|
||||
size_t recv = _recv_len;
|
||||
_recv_len = 0;
|
||||
return recv;
|
||||
}
|
||||
|
||||
void AT_ControlPlane_netif::attach(void (*callback)(void *), void *data)
|
||||
|
|
|
@ -70,17 +70,8 @@ ControlPlane_netif *QUECTEL_BG96_CellularContext::get_cp_netif()
|
|||
nsapi_error_t QUECTEL_BG96_CellularContext::do_user_authentication()
|
||||
{
|
||||
if (_pwd && _uname) {
|
||||
_at.cmd_start("AT+QICSGP=");
|
||||
_at.write_int(_cid);
|
||||
_at.write_int(1); // IPv4
|
||||
_at.write_string(_apn);
|
||||
_at.write_string(_uname);
|
||||
_at.write_string(_pwd);
|
||||
_at.write_int(_authentication_type);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
if (_at.get_last_error() != NSAPI_ERROR_OK) {
|
||||
if (_at.at_cmd_discard("+QICSGP", "=", "%d%d%s%s%s%d", _cid, 1,
|
||||
_apn, _uname, _pwd, _authentication_type) != NSAPI_ERROR_OK) {
|
||||
return NSAPI_ERROR_AUTH_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -90,17 +81,9 @@ nsapi_error_t QUECTEL_BG96_CellularContext::do_user_authentication()
|
|||
|
||||
nsapi_error_t QUECTEL_BG96_CellularContext::activate_non_ip_context()
|
||||
{
|
||||
_at.lock();
|
||||
|
||||
// Open the NIDD connection
|
||||
_at.cmd_start("AT+QCFGEXT=\"nipd\",1");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
|
||||
nsapi_size_or_error_t ret = _at.get_last_error();
|
||||
|
||||
_at.unlock();
|
||||
nsapi_size_or_error_t ret = _at.at_cmd_discard("+QCFGEXT", "=\"nipd\",1");
|
||||
|
||||
if (ret == NSAPI_ERROR_OK) {
|
||||
_semaphore.try_acquire_for(NIDD_OPEN_URC_TIMEOUT);
|
||||
|
@ -115,28 +98,21 @@ nsapi_error_t QUECTEL_BG96_CellularContext::activate_non_ip_context()
|
|||
void QUECTEL_BG96_CellularContext::activate_context()
|
||||
{
|
||||
tr_info("Activate PDP context %d", _cid);
|
||||
_at.cmd_start("AT+QIACT=");
|
||||
_at.write_int(_cid);
|
||||
_at.cmd_stop_read_resp();
|
||||
if (_at.get_last_error() == NSAPI_ERROR_OK) {
|
||||
|
||||
if (_at.at_cmd_discard("+QIACT", "=", "%d", _cid) == NSAPI_ERROR_OK) {
|
||||
_is_context_activated = true;
|
||||
}
|
||||
}
|
||||
|
||||
void QUECTEL_BG96_CellularContext::deactivate_context()
|
||||
{
|
||||
_at.cmd_start("AT+QIDEACT=");
|
||||
_at.write_int(_cid);
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+QIDEACT", "=", "%d", _cid);
|
||||
}
|
||||
|
||||
void QUECTEL_BG96_CellularContext::deactivate_non_ip_context()
|
||||
{
|
||||
// Close the NIDD connection
|
||||
_at.cmd_start("AT+QCFGEXT=\"nipd\",0");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
_at.at_cmd_discard("+QCFGEXT", "=\"nipd\",0");
|
||||
}
|
||||
|
||||
void QUECTEL_BG96_CellularContext::urc_nidd()
|
||||
|
@ -178,30 +154,16 @@ nsapi_error_t QUECTEL_BG96_CellularContext::setup_control_plane_opt()
|
|||
{
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+QCFGEXT=\"pdp_type\",");
|
||||
_at.write_int(NIDD_PDP_CONTEXT_ID);
|
||||
_at.write_string("Non-IP");
|
||||
_at.write_string(_apn);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
_at.cmd_start("AT+CFUN=0");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
_at.cmd_start("AT+CFUN=1");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
_at.at_cmd_discard("+QCFGEXT", "=\"pdp_type\",", "%d%s%s", NIDD_PDP_CONTEXT_ID, "Non-IP", _apn);
|
||||
|
||||
_at.at_cmd_discard("+CFUN", "=0");
|
||||
|
||||
_at.at_cmd_discard("+CFUN", "=1");
|
||||
|
||||
// Configure Non-IP outgoing data type - 0 for no exception data
|
||||
_at.cmd_start("AT+QCFGEXT=\"nipdcfg\",0,");
|
||||
_at.write_string(_apn);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
nsapi_error_t err = _at.at_cmd_discard("+QCFGEXT", "=\"nipdcfg\",0,", "%s", _apn);
|
||||
|
||||
if (_at.get_last_error() == NSAPI_ERROR_OK) {
|
||||
if (err == NSAPI_ERROR_OK) {
|
||||
_cp_in_use = true;
|
||||
if (_nonip_req) {
|
||||
_pdp_type = NON_IP_PDP_TYPE;
|
||||
|
|
|
@ -29,13 +29,7 @@ QUECTEL_BG96_CellularInformation::~QUECTEL_BG96_CellularInformation()
|
|||
// According to BG96_AT_Commands_Manual_V2.0
|
||||
nsapi_error_t QUECTEL_BG96_CellularInformation::get_iccid(char *buf, size_t buf_size)
|
||||
{
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+QCCID");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+QCCID:");
|
||||
_at.read_string(buf, buf_size);
|
||||
_at.resp_stop();
|
||||
return _at.unlock_return_error();
|
||||
return _at.at_cmd_str("+QCCID", "", buf, buf_size);
|
||||
}
|
||||
|
||||
} /* namespace mbed */
|
||||
|
|
|
@ -35,37 +35,27 @@ nsapi_error_t QUECTEL_BG96_CellularNetwork::set_access_technology_impl(RadioAcce
|
|||
|
||||
switch (opsAct) {
|
||||
case RAT_CATM1:
|
||||
_at.cmd_start("AT+QCFG=\"nwscanseq\",020301");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.cmd_start("AT+QCFG=\"nwscanmode\",3,1");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.cmd_start("AT+QCFG=\"iotopmode\",0,1");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+QCFG", "=\"nwscanseq\",020301");
|
||||
_at.at_cmd_discard("+QCFG", "=\"nwscanmode\",3,1");
|
||||
_at.at_cmd_discard("+QCFG", "=\"iotopmode\",0,1");
|
||||
break;
|
||||
case RAT_NB1:
|
||||
_at.cmd_start("AT+QCFG=\"nwscanseq\",030201");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.cmd_start("AT+QCFG=\"nwscanmode\",3,1");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.cmd_start("AT+QCFG=\"iotopmode\",1,1");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+QCFG", "=\"nwscanseq\",030201");
|
||||
_at.at_cmd_discard("+QCFG", "=\"nwscanmode\",3,1");
|
||||
_at.at_cmd_discard("+QCFG", "=\"iotopmode\",1,1");
|
||||
break;
|
||||
case RAT_GSM:
|
||||
case RAT_GSM_COMPACT:
|
||||
case RAT_UTRAN:
|
||||
case RAT_EGPRS:
|
||||
_at.cmd_start("AT+QCFG=\"nwscanseq\",010203");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.cmd_start("AT+QCFG=\"nwscanmode\",1,1");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+QCFG", "=\"nwscanseq\",010203");
|
||||
_at.at_cmd_discard("+QCFG", "=\"nwscanmode\",1,1");
|
||||
break;
|
||||
default:
|
||||
_at.cmd_start("AT+QCFG=\"nwscanseq\",020301");
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.cmd_start("AT+QCFG=\"nwscanmode\",0,1"); //auto mode
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.cmd_start("AT+QCFG=\"iotopmode\",2,1"); //auto mode
|
||||
_at.cmd_stop_read_resp();
|
||||
_at.at_cmd_discard("+QCFG", "=\"nwscanseq\",020301");
|
||||
_at.at_cmd_discard("+QCFG", "=\"nwscanmode\",0,1");
|
||||
_at.at_cmd_discard("+QCFG", "=\"iotopmode\",2,1");
|
||||
|
||||
_at.unlock();
|
||||
_op_act = RAT_UNKNOWN;
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
|
@ -77,8 +67,7 @@ nsapi_error_t QUECTEL_BG96_CellularNetwork::set_access_technology_impl(RadioAcce
|
|||
void QUECTEL_BG96_CellularNetwork::get_context_state_command()
|
||||
{
|
||||
// read active contexts
|
||||
_at.cmd_start("AT+QIACT?");
|
||||
_at.cmd_stop();
|
||||
_at.cmd_start_stop("+QIACT", "?");
|
||||
_at.resp_start("+QIACT:");
|
||||
}
|
||||
|
||||
|
|
|
@ -55,15 +55,8 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
|
|||
|
||||
_at.lock();
|
||||
if (socket->proto == NSAPI_TCP) {
|
||||
_at.cmd_start("AT+QIOPEN=");
|
||||
_at.write_int(_cid);
|
||||
_at.write_int(request_connect_id);
|
||||
_at.write_string("TCP");
|
||||
_at.write_string(address.get_ip_address());
|
||||
_at.write_int(address.get_port());
|
||||
_at.write_int(socket->localAddress.get_port());
|
||||
_at.write_int(0);
|
||||
_at.cmd_stop();
|
||||
_at.at_cmd_discard("+QIOPEN", "=", "%d%d%s%s%d%d%d", _cid, request_connect_id, "TCP",
|
||||
address.get_ip_address(), address.get_port(), socket->localAddress.get_port(), 0);
|
||||
|
||||
handle_open_socket_response(modem_connect_id, err);
|
||||
|
||||
|
@ -73,21 +66,10 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
|
|||
_at.unlock();
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
_at.cmd_start("AT+QICLOSE=");
|
||||
_at.write_int(modem_connect_id);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
_at.at_cmd_discard("+QICLOSE", "=", "%d", modem_connect_id);
|
||||
|
||||
_at.cmd_start("AT+QIOPEN=");
|
||||
_at.write_int(_cid);
|
||||
_at.write_int(request_connect_id);
|
||||
_at.write_string("TCP");
|
||||
_at.write_string(address.get_ip_address());
|
||||
_at.write_int(address.get_port());
|
||||
_at.write_int(socket->localAddress.get_port());
|
||||
_at.write_int(0);
|
||||
_at.cmd_stop();
|
||||
_at.at_cmd_discard("+QIOPEN", "=", "%d%d%s%s%d%d%d", _cid, request_connect_id, "TCP",
|
||||
address.get_ip_address(), address.get_port(), socket->localAddress.get_port(), 0);
|
||||
|
||||
handle_open_socket_response(modem_connect_id, err);
|
||||
}
|
||||
|
@ -95,11 +77,7 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
|
|||
|
||||
// If opened successfully BUT not requested one, close it
|
||||
if (!err && (modem_connect_id != request_connect_id)) {
|
||||
_at.cmd_start("AT+QICLOSE=");
|
||||
_at.write_int(modem_connect_id);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
_at.at_cmd_discard("+QICLOSE", "=", "%d", modem_connect_id);
|
||||
}
|
||||
|
||||
nsapi_error_t ret_val = _at.get_last_error();
|
||||
|
@ -158,19 +136,15 @@ bool QUECTEL_BG96_CellularStack::is_protocol_supported(nsapi_protocol_t protocol
|
|||
nsapi_error_t QUECTEL_BG96_CellularStack::socket_close_impl(int sock_id)
|
||||
{
|
||||
_at.set_at_timeout(BG96_CLOSE_SOCKET_TIMEOUT);
|
||||
_at.cmd_start("AT+QICLOSE=");
|
||||
_at.write_int(sock_id);
|
||||
_at.cmd_stop_read_resp();
|
||||
nsapi_error_t err = _at.at_cmd_discard("+QICLOSE", "=", "%d", sock_id);
|
||||
_at.restore_at_timeout();
|
||||
|
||||
return _at.get_last_error();
|
||||
return err;
|
||||
}
|
||||
|
||||
void QUECTEL_BG96_CellularStack::handle_open_socket_response(int &modem_connect_id, int &err)
|
||||
{
|
||||
// OK
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
// QIOPEN -> should be handled as URC?
|
||||
_at.set_at_timeout(BG96_CREATE_SOCKET_TIMEOUT);
|
||||
_at.resp_start("+QIOPEN:");
|
||||
|
@ -191,19 +165,9 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
|
|||
MBED_ASSERT(request_connect_id != -1);
|
||||
|
||||
if (socket->proto == NSAPI_UDP && !socket->connected) {
|
||||
_at.cmd_start("AT+QIOPEN=");
|
||||
_at.write_int(_cid);
|
||||
_at.write_int(request_connect_id);
|
||||
_at.write_string("UDP SERVICE");
|
||||
if (_stack_type == IPV4_STACK) {
|
||||
_at.write_string("127.0.0.1");
|
||||
} else if (_stack_type == IPV6_STACK || _stack_type == IPV4V6_STACK) {
|
||||
_at.write_string("0:0:0:0:0:0:0:1");
|
||||
}
|
||||
_at.write_int(remote_port);
|
||||
_at.write_int(socket->localAddress.get_port());
|
||||
_at.write_int(0);
|
||||
_at.cmd_stop();
|
||||
_at.at_cmd_discard("+QIOPEN", "=", "%d%d%s%s%d%d%d", _cid, request_connect_id, "UDP SERVICE",
|
||||
(_stack_type == IPV4_STACK) ? "127.0.0.1" : "0:0:0:0:0:0:0:1",
|
||||
remote_port, socket->localAddress.get_port(), 0);
|
||||
|
||||
handle_open_socket_response(modem_connect_id, err);
|
||||
|
||||
|
@ -214,31 +178,15 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
|
|||
}
|
||||
socket_close_impl(modem_connect_id);
|
||||
|
||||
_at.cmd_start("AT+QIOPEN=");
|
||||
_at.write_int(_cid);
|
||||
_at.write_int(request_connect_id);
|
||||
_at.write_string("UDP SERVICE");
|
||||
|
||||
if (_stack_type == IPV4_STACK) {
|
||||
_at.write_string("127.0.0.1");
|
||||
} else if (_stack_type == IPV6_STACK || _stack_type == IPV4V6_STACK) {
|
||||
_at.write_string("0:0:0:0:0:0:0:1");
|
||||
}
|
||||
_at.write_int(remote_port);
|
||||
_at.write_int(socket->localAddress.get_port());
|
||||
_at.write_int(0);
|
||||
_at.cmd_stop();
|
||||
_at.at_cmd_discard("+QIOPEN", "=", "%d%d%s%s%d%d%d", _cid, request_connect_id, "UDP SERVICE",
|
||||
(_stack_type == IPV4_STACK) ? "127.0.0.1" : "0:0:0:0:0:0:0:1",
|
||||
remote_port, socket->localAddress.get_port(), 0);
|
||||
|
||||
handle_open_socket_response(modem_connect_id, err);
|
||||
}
|
||||
} else if (socket->proto == NSAPI_UDP && socket->connected) {
|
||||
_at.cmd_start("AT+QIOPEN=");
|
||||
_at.write_int(_cid);
|
||||
_at.write_int(request_connect_id);
|
||||
_at.write_string("UDP");
|
||||
_at.write_string(socket->remoteAddress.get_ip_address());
|
||||
_at.write_int(socket->remoteAddress.get_port());
|
||||
_at.cmd_stop();
|
||||
_at.at_cmd_discard("+QIOPEN", "=", "%d%d%s%s%d", _cid, request_connect_id, "UDP",
|
||||
socket->remoteAddress.get_ip_address(), socket->remoteAddress.get_port());
|
||||
|
||||
handle_open_socket_response(modem_connect_id, err);
|
||||
|
||||
|
@ -249,13 +197,8 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
|
|||
}
|
||||
socket_close_impl(modem_connect_id);
|
||||
|
||||
_at.cmd_start("AT+QIOPEN=");
|
||||
_at.write_int(_cid);
|
||||
_at.write_int(request_connect_id);
|
||||
_at.write_string("UDP");
|
||||
_at.write_string(socket->remoteAddress.get_ip_address());
|
||||
_at.write_int(socket->remoteAddress.get_port());
|
||||
_at.cmd_stop();
|
||||
_at.at_cmd_discard("+QIOPEN", "=", "%d%d%s%s%d", _cid, request_connect_id, "UDP",
|
||||
socket->remoteAddress.get_ip_address(), socket->remoteAddress.get_port());
|
||||
|
||||
handle_open_socket_response(modem_connect_id, err);
|
||||
}
|
||||
|
@ -287,24 +230,15 @@ nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_sendto_impl(CellularSoc
|
|||
int sent_len_after = 0;
|
||||
|
||||
// Get the sent count before sending
|
||||
_at.cmd_start("AT+QISEND=");
|
||||
_at.write_int(socket->id);
|
||||
_at.write_int(0);
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.resp_start("+QISEND:");
|
||||
sent_len_before = _at.read_int();
|
||||
_at.resp_stop();
|
||||
_at.at_cmd_int("+QISEND", "=", sent_len_before, "%d%d", socket->id, 0);
|
||||
|
||||
// Send
|
||||
_at.cmd_start("AT+QISEND=");
|
||||
_at.write_int(socket->id);
|
||||
_at.write_int(size);
|
||||
if (socket->proto == NSAPI_UDP) {
|
||||
_at.write_string(address.get_ip_address());
|
||||
_at.write_int(address.get_port());
|
||||
_at.cmd_start_stop("+QISEND", "=", "%d%d%s%d", socket->id, size,
|
||||
address.get_ip_address(), address.get_port());
|
||||
} else {
|
||||
_at.cmd_start_stop("+QISEND", "=", "%d%d", socket->id, size);
|
||||
}
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.resp_start(">");
|
||||
_at.write_bytes((uint8_t *)data, size);
|
||||
|
@ -313,21 +247,15 @@ nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_sendto_impl(CellularSoc
|
|||
_at.resp_stop();
|
||||
|
||||
// Get the sent count after sending
|
||||
_at.cmd_start("AT+QISEND=");
|
||||
_at.write_int(socket->id);
|
||||
_at.write_int(0);
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.resp_start("+QISEND:");
|
||||
sent_len_after = _at.read_int();
|
||||
_at.resp_stop();
|
||||
nsapi_size_or_error_t err = _at.at_cmd_int("+QISEND", "=", sent_len_after, "%d%d", socket->id, 0);
|
||||
|
||||
if (_at.get_last_error() == NSAPI_ERROR_OK) {
|
||||
if (err == NSAPI_ERROR_OK) {
|
||||
sent_len = sent_len_after - sent_len_before;
|
||||
return sent_len;
|
||||
}
|
||||
|
||||
return _at.get_last_error();
|
||||
return err;
|
||||
}
|
||||
|
||||
nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
|
||||
|
@ -337,14 +265,13 @@ nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_recvfrom_impl(CellularS
|
|||
int port;
|
||||
char ip_address[NSAPI_IP_SIZE + 1];
|
||||
|
||||
_at.cmd_start("AT+QIRD=");
|
||||
_at.write_int(socket->id);
|
||||
if (socket->proto == NSAPI_TCP) {
|
||||
// do not read more than max size
|
||||
size = size > BG96_MAX_RECV_SIZE ? BG96_MAX_RECV_SIZE : size;
|
||||
_at.write_int(size);
|
||||
_at.cmd_start_stop("+QIRD", "=", "%d%d", socket->id, size);
|
||||
} else {
|
||||
_at.cmd_start_stop("+QIRD", "=", "%d", socket->id);
|
||||
}
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.resp_start("+QIRD:");
|
||||
recv_len = _at.read_int();
|
||||
|
|
|
@ -7,18 +7,7 @@ QUECTEL_BG96_ControlPlane_netif::QUECTEL_BG96_ControlPlane_netif(ATHandler &at,
|
|||
|
||||
nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::send(const void *data, nsapi_size_t size)
|
||||
{
|
||||
_at.lock();
|
||||
|
||||
_at.cmd_start("AT+QCFGEXT=\"nipds\",0,");
|
||||
_at.write_string((char *)data);
|
||||
_at.write_int(size);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
|
||||
nsapi_error_t err = _at.get_last_error();
|
||||
|
||||
_at.unlock();
|
||||
nsapi_size_or_error_t err = _at.at_cmd_discard("+QCFGEXT", "=\"nipds\",0,", "%s%d", data, size);
|
||||
|
||||
if (err == NSAPI_ERROR_OK) {
|
||||
return size;
|
||||
|
|
Loading…
Reference in New Issue