Skip to content

Commit ffb4f92

Browse files
Artistic style applied and updated power function
1 parent a8abecc commit ffb4f92

File tree

10 files changed

+50
-96
lines changed

10 files changed

+50
-96
lines changed

features/cellular/framework/AT/AT_CellularStack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class AT_CellularStack : public NetworkStack, public AT_CellularBase
9898
bool started; // socket has been opened on modem stack
9999
bool tx_ready; // socket is ready for sending on modem stack
100100
bool rx_avail; // socket has data for reading on modem stack
101-
volatile nsapi_size_t pending_bytes; // The number of received bytes pending
101+
nsapi_size_t pending_bytes; // The number of received bytes pending
102102
};
103103

104104
/**

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Arm Limited and affiliates.
2+
* Copyright (c) 2018, Arm Limited and affiliates.
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Arm Limited and affiliates.
2+
* Copyright (c) 2018, Arm Limited and affiliates.
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,13 +20,14 @@
2020

2121
#include "AT_CellularDevice.h"
2222

23-
namespace mbed {
23+
namespace mbed
24+
{
2425

2526
class UBLOX_AT : public AT_CellularDevice
2627
{
2728

2829
public:
29-
UBLOX_AT(events::EventQueue &queue);
30+
UBLOX_AT(events::EventQueue &queue);
3031
virtual ~UBLOX_AT();
3132

3233
public: // CellularDevice

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Arm Limited and affiliates.
2+
* Copyright (c) 2018, Arm Limited and affiliates.
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -167,8 +167,8 @@ nsapi_error_t UBLOX_AT_CellularNetwork::open_data_channel()
167167
}
168168

169169
bool UBLOX_AT_CellularNetwork::activate_profile(const char* apn,
170-
const char* username,
171-
const char* password)
170+
const char* username,
171+
const char* password)
172172
{
173173
bool activated = false;
174174
bool success = false;
@@ -224,7 +224,7 @@ bool UBLOX_AT_CellularNetwork::activate_profile(const char* apn,
224224
// 1 = PAP (Password Authentication Protocol)
225225
// 2 = CHAP (Challenge Handshake Authentication Protocol)
226226
for (int protocol = nsapi_security_to_modem_security(NSAPI_SECURITY_NONE);
227-
success && (protocol <= nsapi_security_to_modem_security(NSAPI_SECURITY_CHAP)); protocol++) {
227+
success && (protocol <= nsapi_security_to_modem_security(NSAPI_SECURITY_CHAP)); protocol++) {
228228
if ((_auth == NSAPI_SECURITY_UNKNOWN) || (nsapi_security_to_modem_security(_auth) == protocol)) {
229229
_at.cmd_start("AT+UPSD=0,6,");
230230
_at.write_int(protocol);
@@ -257,8 +257,7 @@ int UBLOX_AT_CellularNetwork::nsapi_security_to_modem_security(nsapi_security_t
257257
{
258258
int modem_security = 3;
259259

260-
switch (nsapi_security)
261-
{
260+
switch (nsapi_security) {
262261
case NSAPI_SECURITY_NONE:
263262
modem_security = 0;
264263
break;
@@ -330,15 +329,17 @@ const char *UBLOX_AT_CellularNetwork::get_gateway()
330329

331330
nsapi_error_t UBLOX_AT_CellularNetwork::detach()
332331
{
332+
nsapi_error_t err;
333+
333334
_at.lock();
334335
_at.cmd_start("AT+CGATT=0");
335336
_at.cmd_stop();
336337
_at.resp_start();
337338
_at.resp_stop();
338-
_at.unlock();
339+
err = _at.unlock_return_error();
339340

340341
// wait added to process CGREG and UUPSDD URC, which comes after detach.
341342
wait_ms(50);
342343

343-
return _at.get_last_error();
344-
}
344+
return err;
345+
}

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Arm Limited and affiliates.
2+
* Copyright (c) 2018, Arm Limited and affiliates.
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,8 @@
2121
#include "AT_CellularNetwork.h"
2222
#include "APN_db.h"
2323

24-
namespace mbed {
24+
namespace mbed
25+
{
2526

2627
class UBLOX_AT_CellularNetwork : public AT_CellularNetwork
2728
{
@@ -45,13 +46,9 @@ class UBLOX_AT_CellularNetwork : public AT_CellularNetwork
4546

4647
private:
4748

48-
/** The profile to use (on board the modem).
49-
*/
50-
#define PROFILE "0"
51-
5249
/** Length of IMSI buffer.
5350
*/
54-
#define MAX_IMSI_LENGTH 15
51+
static const int MAX_IMSI_LENGTH = 15;
5552

5653
/** The type of authentication to use.
5754
*/

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularPower.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Arm Limited and affiliates.
2+
* Copyright (c) 2018, Arm Limited and affiliates.
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularPower.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Arm Limited and affiliates.
2+
* Copyright (c) 2018, Arm Limited and affiliates.
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +20,8 @@
2020

2121
#include "AT_CellularPower.h"
2222

23-
namespace mbed {
23+
namespace mbed
24+
{
2425

2526
class UBLOX_AT_CellularPower : public AT_CellularPower
2627
{

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Arm Limited and affiliates.
2+
* Copyright (c) 2018, Arm Limited and affiliates.
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -107,17 +107,11 @@ void UBLOX_AT_CellularStack::UUPSDD_URC()
107107
clear_socket(socket);
108108
}
109109

110-
111110
int UBLOX_AT_CellularStack::get_max_socket_count()
112111
{
113112
return UBLOX_MAX_SOCKET;
114113
}
115114

116-
int UBLOX_AT_CellularStack::get_max_packet_size()
117-
{
118-
return UBLOX_MAX_PACKET_SIZE;
119-
}
120-
121115
bool UBLOX_AT_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
122116
{
123117
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
@@ -225,7 +219,7 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, cons
225219
_at.lock();
226220
_at.cmd_start("AT+USOCO=");
227221
_at.write_int(socket->id);
228-
_at.write_string(addr.get_ip_address(), true);
222+
_at.write_string(addr.get_ip_address());
229223
_at.write_int(addr.get_port());
230224
_at.cmd_stop();
231225
_at.resp_start();
@@ -245,22 +239,22 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
245239
const void *data, nsapi_size_t size)
246240
{
247241
int sent_len = 0;
248-
uint8_t ch = 0;
242+
uint8_t ch = 0, cont = 50;
249243

250-
_at.lock();
251244
if (socket->proto == NSAPI_UDP) {
252-
if (size > (nsapi_size_t) get_max_packet_size()) {
245+
if (size > UBLOX_MAX_PACKET_SIZE) {
253246
return NSAPI_ERROR_PARAMETER;
254247
}
255248
_at.cmd_start("AT+USOST=");
256249
_at.write_int(socket->id);
257-
_at.write_string(address.get_ip_address(), true);
250+
_at.write_string(address.get_ip_address());
258251
_at.write_int(address.get_port());
259252
_at.write_int(size);
260253
_at.cmd_stop();
261254
wait_ms(50);
262-
while (ch != '@') {
255+
while (ch != '@' && cont > 0) {
263256
_at.read_bytes(&ch, 1);
257+
cont--;
264258
}
265259
_at.write_bytes((uint8_t *)data, size);
266260

@@ -271,8 +265,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
271265

272266
if ((_at.get_last_error() == NSAPI_ERROR_OK)) {
273267
return sent_len;
274-
} else {
275-
socket->rx_avail = false;
276268
}
277269
} else if (socket->proto == NSAPI_TCP) {
278270
bool success = true;
@@ -289,8 +281,9 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
289281
_at.write_int(blk);
290282
_at.cmd_stop();
291283
wait_ms(50);
292-
while (ch != '@') {
284+
while (ch != '@' && cont > 0) {
293285
_at.read_bytes(&ch, 1);
286+
cont--;
294287
}
295288
_at.write_bytes((uint8_t *)buf, blk);
296289

@@ -300,7 +293,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
300293
_at.resp_stop();
301294

302295
if ((sent_len >= (int) blk) &&
303-
(_at.get_last_error() == NSAPI_ERROR_OK)) {
296+
(_at.get_last_error() == NSAPI_ERROR_OK)) {
304297
} else {
305298
success = false;
306299
}
@@ -314,7 +307,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
314307
return size - count;
315308
}
316309
}
317-
_at.unlock();
318310

319311
return _at.get_last_error();
320312
}
@@ -332,7 +324,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke
332324
int port = 0;
333325
Timer timer;
334326

335-
_at.lock();
336327
timer.start();
337328
if (socket->proto == NSAPI_UDP) {
338329
while (success && (size > 0)) {
@@ -363,7 +354,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke
363354
usorf_sz = size;
364355
}
365356
_at.read_bytes(&ch, 1);
366-
_at.read_bytes((uint8_t *)buffer + count , usorf_sz);
357+
_at.read_bytes((uint8_t *)buffer + count, usorf_sz);
367358
_at.resp_stop();
368359

369360
if (usorf_sz > 0) {
@@ -412,7 +403,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke
412403
usorf_sz = size;
413404
}
414405
_at.read_bytes(&ch, 1);
415-
_at.read_bytes((uint8_t *)buffer + count , usorf_sz);
406+
_at.read_bytes((uint8_t *)buffer + count, usorf_sz);
416407
_at.resp_stop();
417408

418409
if (usorf_sz > 0) {
@@ -435,8 +426,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke
435426
}
436427
}
437428
timer.stop();
438-
_at.unlock();
439-
440429

441430
if (!count || (_at.get_last_error() != NSAPI_ERROR_OK)) {
442431
return NSAPI_ERROR_WOULD_BLOCK;
@@ -453,29 +442,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke
453442
return nsapi_error_size;
454443
}
455444

456-
nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto(nsapi_socket_t handle, const SocketAddress &addr, const void *data, unsigned size)
457-
{
458-
CellularSocket *socket = (CellularSocket *)handle;
459-
if (!socket || !socket->created) {
460-
return NSAPI_ERROR_DEVICE_ERROR;
461-
}
462-
463-
nsapi_size_or_error_t ret_val = NSAPI_ERROR_OK;
464-
465-
/* Check parameters */
466-
if (addr.get_ip_version() == NSAPI_UNSPEC) {
467-
return NSAPI_ERROR_DEVICE_ERROR;
468-
}
469-
470-
_at.lock();
471-
472-
ret_val = socket_sendto_impl(socket, addr, data, size);
473-
474-
_at.unlock();
475-
476-
return ret_val;
477-
}
478-
479445
nsapi_error_t UBLOX_AT_CellularStack::socket_close_impl(int sock_id)
480446
{
481447
_at.lock();
@@ -484,9 +450,8 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_close_impl(int sock_id)
484450
_at.cmd_stop();
485451
_at.resp_start();
486452
_at.resp_stop();
487-
_at.unlock();
488453

489-
return _at.get_last_error();
454+
return _at.unlock_return_error();
490455
}
491456

492457
// Find or create a socket from the list.
@@ -561,19 +526,19 @@ nsapi_error_t UBLOX_AT_CellularStack::gethostbyname(const char *host, SocketAddr
561526
} else {
562527
// This interrogation can sometimes take longer than the usual 8 seconds
563528
_at.cmd_start("AT+UDNSRN=0,");
564-
_at.write_string(host, true);
529+
_at.write_string(host);
565530
_at.cmd_stop();
566531

567532
_at.set_at_timeout(60000);
568533
_at.resp_start("+UDNSRN:");
569534
if (_at.info_resp()) {
570535
_at.read_string(ipAddress, sizeof(ipAddress));
571-
_at.resp_stop();
572536

573537
if (address->set_ip_address(ipAddress)) {
574538
err = NSAPI_ERROR_OK;
575539
}
576540
}
541+
_at.resp_stop();
577542
_at.restore_at_timeout();
578543
}
579544
_at.unlock();

0 commit comments

Comments
 (0)