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"
1
19
#include " QUECTEL_BG96_ControlPlane_netif.h"
20
+ #include " CellularLog.h"
21
+
22
+ using namespace mbed_cellular_util ;
2
23
3
24
namespace mbed {
4
25
@@ -7,21 +28,26 @@ QUECTEL_BG96_ControlPlane_netif::QUECTEL_BG96_ControlPlane_netif(ATHandler &at,
7
28
8
29
nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::send (const void *data, nsapi_size_t size)
9
30
{
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;
14
33
}
15
34
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;
17
43
}
18
44
19
45
nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::recv (void *buffer, nsapi_size_t size)
20
46
{
21
47
_at.lock ();
22
48
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:" );
25
51
// skip 3 params: "nipdr",<total_receive_length>,<have_read_length>
26
52
_at.skip_param (3 );
27
53
// get to <unread_length>
@@ -32,20 +58,22 @@ nsapi_size_or_error_t QUECTEL_BG96_ControlPlane_netif::recv(void *buffer, nsapi_
32
58
_at.unlock ();
33
59
return NSAPI_ERROR_WOULD_BLOCK;
34
60
}
61
+ if ((nsapi_size_t )unread_length > size) {
62
+ tr_warn (" recv %d/%d" , size, unread_length);
63
+ unread_length = size;
64
+ }
35
65
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 );
38
67
_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);
43
71
_at.resp_stop ();
44
- nsapi_error_t err = _at.get_last_error ();
45
- _at.unlock ();
46
72
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;
49
77
}
50
78
51
79
return NSAPI_ERROR_WOULD_BLOCK;
0 commit comments