Skip to content

Commit feee2a2

Browse files
author
Ari Parkkila
committed
Cellular: Fix Non-IP of Quectel/BG96 modem driver
Add missing license headers. Remove semaphores to allow async operation. Change hex format to allow binary payload. Limit payload size to 100 bytes. Fix missing plus char at +QCFGEXT.
1 parent 7fd637b commit feee2a2

File tree

5 files changed

+53
-23
lines changed

5 files changed

+53
-23
lines changed

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ void ATHandler::set_send_delay(uint16_t send_delay)
16371637
_at_send_delay = send_delay;
16381638
}
16391639

1640-
void ATHandler::write_hex_string(char *str, size_t size)
1640+
void ATHandler::write_hex_string(const char *str, size_t size)
16411641
{
16421642
// do common checks before sending subparameter
16431643
if (check_cmd_send() == false) {

features/cellular/framework/AT/ATHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class ATHandler {
433433
* @param str input buffer to be converted to hex ascii
434434
* @param size of the input param str
435435
*/
436-
void write_hex_string(char *str, size_t size);
436+
void write_hex_string(const char *str, size_t size);
437437

438438
/** Reads as string and converts result to integer. Supports only non-negative integers.
439439
*

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ nsapi_error_t QUECTEL_BG96_CellularContext::activate_non_ip_context()
8484

8585
// Open the NIDD connection
8686
nsapi_size_or_error_t ret = _at.at_cmd_discard("+QCFGEXT", "=\"nipd\",1");
87-
8887
if (ret == NSAPI_ERROR_OK) {
89-
_semaphore.try_acquire_for(NIDD_OPEN_URC_TIMEOUT);
88+
_at.lock();
89+
_at.set_at_timeout(NIDD_OPEN_URC_TIMEOUT);
90+
_at.resp_start("+QIND:");
91+
urc_nidd();
92+
_at.restore_at_timeout();
93+
_at.unlock();
9094
if (_cid == -1) {
9195
return NSAPI_ERROR_NO_CONNECTION;
9296
}
@@ -142,7 +146,6 @@ void QUECTEL_BG96_CellularContext::urc_nidd_open()
142146
} else {
143147
tr_error("NIDD connection open failed with error: %d", err);
144148
}
145-
_semaphore.release();
146149
}
147150

148151
void QUECTEL_BG96_CellularContext::urc_nidd_close()

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class QUECTEL_BG96_CellularContext: public AT_CellularContext {
3737
virtual void deactivate_non_ip_context();
3838
virtual void deactivate_context();
3939
virtual void activate_context();
40-
rtos::Semaphore _semaphore;
4140

4241
private:
4342
void urc_nidd();

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_ControlPlane_netif.cpp

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "CellularUtil.h"
119
#include "QUECTEL_BG96_ControlPlane_netif.h"
20+
#include "CellularLog.h"
21+
22+
using namespace mbed_cellular_util;
223

324
namespace mbed {
425

@@ -7,21 +28,26 @@ QUECTEL_BG96_ControlPlane_netif::QUECTEL_BG96_ControlPlane_netif(ATHandler &at,
728

829
nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::send(const void *data, nsapi_size_t size)
930
{
10-
nsapi_size_or_error_t err = _at.at_cmd_discard("+QCFGEXT", "=\"nipds\",0,", "%s%d", data, size);
11-
12-
if (err == NSAPI_ERROR_OK) {
13-
return size;
31+
if (size > 100) { // from BG96_NIDD_AT_Commands_Manual_V1.0
32+
return NSAPI_ERROR_PARAMETER;
1433
}
1534

16-
return err;
35+
_at.lock();
36+
_at.cmd_start("AT+QCFGEXT=\"nipds\",1,");
37+
_at.write_hex_string((const char *)data, size);
38+
_at.write_int(2 * size);
39+
_at.cmd_stop_read_resp();
40+
nsapi_error_t err = _at.unlock_return_error();
41+
42+
return (err == NSAPI_ERROR_OK) ? size : err;
1743
}
1844

1945
nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::recv(void *buffer, nsapi_size_t size)
2046
{
2147
_at.lock();
2248

23-
_at.cmd_start_stop("QCFGEXT", "=", "%s%d", "nipdr", 0);
24-
_at.resp_start("+QCFGEXT: ");
49+
_at.cmd_start_stop("+QCFGEXT", "=", "%s%d", "nipdr", 0);
50+
_at.resp_start("+QCFGEXT:");
2551
// skip 3 params: "nipdr",<total_receive_length>,<have_read_length>
2652
_at.skip_param(3);
2753
// get to <unread_length>
@@ -32,20 +58,22 @@ nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::recv(void *buffer, nsapi_
3258
_at.unlock();
3359
return NSAPI_ERROR_WOULD_BLOCK;
3460
}
61+
if ((nsapi_size_t)unread_length > size) {
62+
tr_warn("recv %d/%d", size, unread_length);
63+
unread_length = size;
64+
}
3565

36-
_at.cmd_start_stop("QCFGEXT", "=", "%s%d", "nipdr", unread_length);
37-
66+
_at.cmd_start_stop("+QCFGEXT", "=", "%s%d%d", "nipdr", unread_length, 1);
3867
_at.resp_start("+QCFGEXT:");
39-
// skip "nipdr"
40-
_at.skip_param();
41-
int read_length = _at.read_int();
42-
_at.read_string((char *)buffer, read_length);
68+
_at.skip_param(); // skip "nipdr"
69+
nsapi_size_t read_length = _at.read_int();
70+
ssize_t read_len = _at.read_hex_string((char *)buffer, read_length);
4371
_at.resp_stop();
44-
nsapi_error_t err = _at.get_last_error();
45-
_at.unlock();
4672

47-
if (err == NSAPI_ERROR_OK && read_length) {
48-
return read_length;
73+
nsapi_error_t err = _at.unlock_return_error();
74+
75+
if (err == NSAPI_ERROR_OK && read_len) {
76+
return read_len;
4977
}
5078

5179
return NSAPI_ERROR_WOULD_BLOCK;

0 commit comments

Comments
 (0)