diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp index 33e92ca411..5ad4ac140b 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp @@ -297,6 +297,10 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke port = _at.read_int(); usorf_sz = _at.read_int(); + if (usorf_sz > size) { + usorf_sz = size; + } + // Must use what +USORF returns here as it may be less or more than we asked for if (usorf_sz > socket->pending_bytes) { socket->pending_bytes = 0; @@ -304,9 +308,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke socket->pending_bytes -= usorf_sz; } - if (usorf_sz > size) { - usorf_sz = size; - } _at.read_bytes(&ch, 1); _at.read_bytes((uint8_t *)buffer + count, usorf_sz); _at.resp_stop(); diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp index cdce035e50..5bfd6ba0dc 100644 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp @@ -54,11 +54,6 @@ void UBLOX_N2XX::NPIN_URC() _at->read_string(simstr, sizeof(simstr)); } -AT_CellularNetwork *UBLOX_N2XX::open_network_impl(ATHandler &at) -{ - return new UBLOX_N2XX_CellularNetwork(at); -} - AT_CellularContext *UBLOX_N2XX::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) { return new UBLOX_N2XX_CellularContext(at, this, apn, cp_req, nonip_req); @@ -69,7 +64,6 @@ AT_CellularSMS *UBLOX_N2XX::open_sms_impl(ATHandler &at) return new UBLOX_N2XX_CellularSMS(at); } - nsapi_error_t UBLOX_N2XX::init() { _at->set_at_timeout(5000); diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h index 8836a017a5..4f96b1e772 100644 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h @@ -18,11 +18,20 @@ #ifndef UBLOX_N2XX_H_ #define UBLOX_N2XX_H_ +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_UBLOX_N2XX_TX +#define MBED_CONF_UBLOX_N2XX_TX D1 +#endif +#ifndef MBED_CONF_UBLOX_N2XX_RX +#define MBED_CONF_UBLOX_N2XX_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + #include "mbed.h" #include "CellularLog.h" #include "AT_CellularDevice.h" +#include "AT_CellularNetwork.h" #include "UBLOX_N2XX_CellularSMS.h" -#include "UBLOX_N2XX_CellularNetwork.h" #include "UBLOX_N2XX_CellularContext.h" namespace mbed { @@ -41,7 +50,6 @@ public: protected: // AT_CellularDevice - virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); virtual AT_CellularSMS *open_sms_impl(ATHandler &at); diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularNetwork.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularNetwork.cpp deleted file mode 100644 index b800b4018a..0000000000 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularNetwork.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2019, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "UBLOX_N2XX_CellularNetwork.h" - -using namespace mbed; - -UBLOX_N2XX_CellularNetwork::UBLOX_N2XX_CellularNetwork(ATHandler &atHandler): AT_CellularNetwork(atHandler) -{ - _op_act = RAT_UNKNOWN; -} - -UBLOX_N2XX_CellularNetwork::~UBLOX_N2XX_CellularNetwork() -{ - if (_connection_status_cb) { - _connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_ERROR_CONNECTION_LOST); - } -} - -nsapi_error_t UBLOX_N2XX_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat) // Not understandable, RAT (+CEDRXS) -{ - switch (opRat) { -#if defined(TARGET_UBLOX_C030_N211) - case RAT_NB1: - break; -#endif - default: { - _op_act = RAT_UNKNOWN; - return NSAPI_ERROR_UNSUPPORTED; - } - } - - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularNetwork.h b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularNetwork.h deleted file mode 100644 index be9308ec77..0000000000 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularNetwork.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2019, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UBLOX_N2XX_CELLULAR_NETWORK_H_ -#define UBLOX_N2XX_CELLULAR_NETWORK_H_ - -#include "AT_CellularNetwork.h" - -namespace mbed { - -class UBLOX_N2XX_CellularNetwork : public AT_CellularNetwork { - -public: - - UBLOX_N2XX_CellularNetwork(ATHandler &atHandler); - virtual ~UBLOX_N2XX_CellularNetwork(); - -protected: - - virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); -}; - -} // namespace mbed - -#endif // UBLOX_N2XX_CELLULAR_NETWORK_H_ diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp index d9d8b2ebde..9730b6dd40 100644 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp @@ -119,17 +119,17 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_sendto_impl(CellularSocke return NSAPI_ERROR_PARAMETER; } - int sent_len = 0, len = 0; - char *dataStr = (char *) malloc((size * 2) + 1); - memset(dataStr, 0, size*2+1); + int sent_len = 0; + char *dataStr = new char [(size * 2) + 1](); + if (!dataStr) + return NSAPI_ERROR_NO_MEMORY; char_str_to_hex_str((const char*)data, size, dataStr); - len = strlen(dataStr); _at.cmd_start("AT+NSOST="); _at.write_int(socket->id); _at.write_string(address.get_ip_address()); _at.write_int(address.get_port()); - _at.write_int(len/2); + _at.write_int(size); _at.write_string(dataStr); _at.cmd_stop(); @@ -153,15 +153,12 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_recvfrom_impl(CellularSoc nsapi_size_t read_blk, usorf_sz, count = 0, length = size*2; bool success = true; char ipAddress[NSAPI_IP_SIZE]; - char *tmpBuf = (char *) malloc(size*2+1); - memset(tmpBuf, 0, size*2+1); int port = 0; Timer timer; if (socket->pending_bytes == 0) { _at.process_oob(); if (socket->pending_bytes == 0) { - free(tmpBuf); return NSAPI_ERROR_WOULD_BLOCK; } } @@ -183,6 +180,11 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_recvfrom_impl(CellularSoc _at.read_string(ipAddress, sizeof(ipAddress)); port = _at.read_int(); usorf_sz = _at.read_int(); + if (usorf_sz > length) { + usorf_sz = length; + } + _at.read_hex_string((char *)buffer + count, usorf_sz*2+1); + _at.resp_stop(); // Must use what +NSORF returns here as it may be less or more than we asked for if (usorf_sz >= socket->pending_bytes) { @@ -191,12 +193,6 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_recvfrom_impl(CellularSoc socket->pending_bytes -= usorf_sz; } - if (usorf_sz > length) { - usorf_sz = length; - } - _at.read_string(tmpBuf + count, usorf_sz*2+1); - _at.resp_stop(); - if (usorf_sz > 0) { count += (usorf_sz*2); length -= (usorf_sz*2); @@ -220,10 +216,7 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_recvfrom_impl(CellularSoc socket->pending_bytes = 0; if (!count || (_at.get_last_error() != NSAPI_ERROR_OK)) { - free(tmpBuf); return NSAPI_ERROR_WOULD_BLOCK; - } else { - nsapi_error_size = count; } if (success && socket->proto == NSAPI_UDP && address) { @@ -232,9 +225,6 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_recvfrom_impl(CellularSoc address->set_port(port); } - hex_str_to_char_str(tmpBuf, count, (char*) buffer); - - free(tmpBuf); return nsapi_error_size = count/2; }