Skip to content

Commit da797ef

Browse files
C030_N211 cellular api
1 parent f61dee1 commit da797ef

22 files changed

+1742
-17
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
19+
#if !defined(MBED_CONF_NSAPI_PRESENT)
20+
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
21+
#endif
22+
23+
#include "CellularUtil.h" // for CELLULAR_ helper macros
24+
#include "CellularTargets.h"
25+
26+
#ifndef CELLULAR_DEVICE
27+
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
28+
#endif
29+
30+
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
31+
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
32+
#endif
33+
34+
#include "greentea-client/test_env.h"
35+
#include "unity.h"
36+
#include "utest.h"
37+
38+
#include "mbed.h"
39+
40+
#include "AT_CellularPower.h"
41+
#include "CellularDevice.h"
42+
#include "../../cellular_tests_common.h"
43+
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
44+
45+
#define NETWORK_TIMEOUT (180*1000)
46+
47+
static CellularDevice *cellular_device;
48+
49+
static void urc_callback()
50+
{
51+
}
52+
53+
static void wait_for_power(CellularPower *pwr)
54+
{
55+
nsapi_error_t err = pwr->set_device_ready_urc_cb(&urc_callback);
56+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
57+
58+
int sanity_count = 0;
59+
err = pwr->set_at_mode();
60+
while (err != NSAPI_ERROR_OK) {
61+
sanity_count++;
62+
wait(1);
63+
TEST_ASSERT(sanity_count < 40);
64+
err = pwr->set_at_mode();
65+
}
66+
67+
TEST_ASSERT(pwr->is_device_ready() == NSAPI_ERROR_OK);
68+
69+
pwr->remove_device_ready_urc_cb(&urc_callback);
70+
}
71+
72+
static void test_power_interface()
73+
{
74+
const char *devi = CELLULAR_STRINGIFY(CELLULAR_DEVICE);
75+
cellular_device = CellularDevice::get_default_instance();
76+
cellular_device->set_timeout(9000);
77+
CellularPower *pwr = cellular_device->open_power();
78+
TEST_ASSERT(pwr != NULL);
79+
80+
nsapi_error_t err = pwr->on();
81+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
82+
wait_for_power(pwr);
83+
84+
TEST_ASSERT(pwr->set_power_level(1, 0, MBED_CONF_APP_CELLULAR_SIM_PIN) == NSAPI_ERROR_OK);
85+
86+
err = pwr->reset();
87+
TEST_ASSERT(err == NSAPI_ERROR_OK);
88+
wait_for_power(pwr);
89+
90+
wait(1);
91+
err = pwr->opt_power_save_mode(0, 0);
92+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
93+
if (err == NSAPI_ERROR_DEVICE_ERROR) {
94+
if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0)) { // TELIT_HE910 and QUECTEL_BG96 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command
95+
TEST_ASSERT(((AT_CellularPower *)pwr)->get_device_error().errCode == 100 && // 100 == unknown command for modem
96+
((AT_CellularPower *)pwr)->get_device_error().errType == 3); // 3 == CME error from the modem
97+
}
98+
}
99+
100+
wait(1);
101+
err = pwr->opt_receive_period(0, CellularPower::EDRXEUTRAN_NB_S1_mode, 3);
102+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
103+
if (err == NSAPI_ERROR_DEVICE_ERROR) {
104+
if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0)) { // TELIT_HE910 and QUECTEL_BG96 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command
105+
TEST_ASSERT(((AT_CellularPower *)pwr)->get_device_error().errCode == 100 && // 100 == unknown command for modem
106+
((AT_CellularPower *)pwr)->get_device_error().errType == 3); // 3 == CME error from the modem
107+
}
108+
}
109+
110+
err = pwr->off();
111+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
112+
113+
}
114+
115+
using namespace utest::v1;
116+
117+
static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
118+
{
119+
greentea_case_failure_abort_handler(source, reason);
120+
return STATUS_ABORT;
121+
}
122+
123+
static Case cases[] = {
124+
Case("CellularPower test interface", test_power_interface, greentea_failure_handler)
125+
};
126+
127+
static utest::v1::status_t test_setup(const size_t number_of_cases)
128+
{
129+
GREENTEA_SETUP(10 * 60, "default_auto");
130+
return verbose_test_setup_handler(number_of_cases);
131+
}
132+
133+
static Specification specification(test_setup, cases);
134+
135+
int main()
136+
{
137+
#if MBED_CONF_MBED_TRACE_ENABLE
138+
trace_open();
139+
#endif
140+
int ret = Harness::run(specification);
141+
#if MBED_CONF_MBED_TRACE_ENABLE
142+
trace_close();
143+
#endif
144+
return ret;
145+
}

features/cellular/TESTS/api/cellular_sms/main.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,40 +110,40 @@ static void test_sms_initialize_text_mode()
110110
static void test_sms_initialize_pdu_mode()
111111
{
112112
nsapi_error_t err = sms->initialize(CellularSMS::CellularSMSMmodePDU);
113-
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
113+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR &&
114114
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
115115
}
116116

117117
static void test_set_cscs()
118118
{
119119
nsapi_error_t err = sms->set_cscs("IRA");
120-
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
120+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR &&
121121
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
122122
err = sms->set_cscs("UCS2");
123-
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
123+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR &&
124124
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
125125
err = sms->set_cscs("GSM");
126-
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
126+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR &&
127127
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
128128
}
129129

130130
static void test_set_csca()
131131
{
132132
nsapi_error_t err = sms->set_csca("55555", 129);
133-
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
133+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR &&
134134
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
135135
err = sms->set_csca("+35855555", 145);
136-
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
136+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR &&
137137
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
138138
err = sms->set_csca(service_center_address, service_address_type);
139-
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
139+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR &&
140140
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
141141
}
142142

143143
static void test_set_cpms_me()
144144
{
145145
nsapi_error_t err = sms->set_cpms("ME", "ME", "ME");
146-
TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR &&
146+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR &&
147147
((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY));
148148
}
149149

@@ -170,7 +170,8 @@ static void test_set_cpms_sm()
170170
static void test_sms_send()
171171
{
172172
const int msg_len = strlen(TEST_MESSAGE);
173-
TEST_ASSERT(sms->send_sms(MBED_CONF_APP_CELLULAR_PHONE_NUMBER, TEST_MESSAGE, msg_len) == msg_len);
173+
nsapi_error_t err = sms->send_sms(MBED_CONF_APP_CELLULAR_PHONE_NUMBER, TEST_MESSAGE, msg_len);
174+
TEST_ASSERT(err == msg_len || err == NSAPI_ERROR_UNSUPPORTED);
174175
}
175176

176177
static void test_get_sms()
@@ -186,21 +187,24 @@ static void test_get_sms()
186187

187188
wait(7);
188189

189-
TEST_ASSERT(sms->get_sms(buf, buf_len, phone_num, SMS_MAX_PHONE_NUMBER_SIZE, time_stamp, SMS_MAX_TIME_STAMP_SIZE, &buf_size) == buf_len - 1);
190-
TEST_ASSERT(strcmp(phone_num, MBED_CONF_APP_CELLULAR_PHONE_NUMBER) == 0);
191-
TEST_ASSERT(strcmp(buf, TEST_MESSAGE) == 0);
192-
TEST_ASSERT(buf_size == 0);
190+
nsapi_error_t err = sms->get_sms(buf, buf_len, phone_num, SMS_MAX_PHONE_NUMBER_SIZE, time_stamp, SMS_MAX_TIME_STAMP_SIZE, &buf_size);
191+
if(err != NSAPI_ERROR_UNSUPPORTED) {
192+
TEST_ASSERT(err == buf_len - 1);
193+
TEST_ASSERT(strcmp(phone_num, MBED_CONF_APP_CELLULAR_PHONE_NUMBER) == 0);
194+
TEST_ASSERT(strcmp(buf, TEST_MESSAGE) == 0);
195+
TEST_ASSERT(buf_size == 0);
196+
}
193197
TEST_ASSERT(callbacks_received > 0);
194198
callbacks_received = 0;
195-
196199
}
197200

198201
static void test_delete_all_messages()
199202
{
200203
//send a message so that there is something to delete
201204
test_sms_send();
202205
wait(7);
203-
TEST_ASSERT(sms->delete_all_messages() == NSAPI_ERROR_OK);
206+
nsapi_error_t err = sms->delete_all_messages();
207+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
204208
callbacks_received = 0;
205209
}
206210

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright (c) 2017, 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+
#ifndef CELLULAR_API_CELLULARPOWER_H_
18+
#define CELLULAR_API_CELLULARPOWER_H_
19+
20+
#include "nsapi_types.h"
21+
#include "Callback.h"
22+
23+
namespace mbed {
24+
25+
/**
26+
* Class CellularPower
27+
*
28+
* An interface that provides power handling functions for modem/module.
29+
*/
30+
class CellularPower {
31+
protected:
32+
// friend of CellularDevice so that it's the only way to close/delete this class.
33+
friend class CellularDevice;
34+
35+
/**
36+
* virtual Destructor
37+
*/
38+
virtual ~CellularPower() {}
39+
40+
public:
41+
/* Access technology used in method opt_receive_period */
42+
enum EDRXAccessTechnology {
43+
EDRXGSM_EC_GSM_IoT_mode = 1,
44+
EDRXGSM_A_Gb_mode,
45+
EDRXUTRAN_Iu_mode,
46+
EDRXEUTRAN_WB_S1_mode,
47+
EDRXEUTRAN_NB_S1_mode
48+
};
49+
50+
/** Set cellular device power on. Default implementation is empty.
51+
* Device power on/off is modem/board specific behavior and must be done on inherited class if needed.
52+
* Power on is done by toggling power pin/button.
53+
*
54+
* @remark set_at_mode must be called to initialise modem
55+
*
56+
* @return NSAPI_ERROR_OK on success
57+
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
58+
*/
59+
virtual nsapi_error_t on() = 0;
60+
61+
/** Set cellular device power off. Default implementation is empty.
62+
* Device power on/off is modem/board specific behavior and must be done on inherited class if needed.
63+
* Power off is done by toggling power pin/button.
64+
*
65+
* @return NSAPI_ERROR_OK on success
66+
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
67+
*/
68+
virtual nsapi_error_t off() = 0;
69+
70+
/** Set AT command mode. Blocking until success or failure.
71+
*
72+
* @remark must be called after power on to prepare correct AT mode
73+
*
74+
* @return NSAPI_ERROR_OK on success
75+
* NSAPI_ERROR_DEVICE_ERROR on failure
76+
*/
77+
virtual nsapi_error_t set_at_mode() = 0;
78+
79+
/** Set cellular device power level by enabling/disabling functionality.
80+
*
81+
* @param func_level:
82+
* 0 minimum functionality
83+
* 1 full functionality. Enable (turn on) the transmit and receive RF circuits for all supported radio access technologies.
84+
* For MTs supporting +CSRA, this equals the RATs indicated by the response of +CSRA=?. Current +CSRA setting is ignored.
85+
* It is not required that the MT transmit and receive RF circuits are in a disabled state for this setting to have effect.
86+
* 2 disable (turn off) MT transmit RF circuits only
87+
* 3 disable (turn off) MT receive RF circuits only
88+
* 4 disable (turn off) both MT transmit and receive RF circuits
89+
* @param do_reset 0 for do not reset, 1 for reset the device when changing the functionality
90+
*
91+
* @remark See 3GPP TS 27.007 CFUN for more details
92+
*
93+
* @return NSAPI_ERROR_OK on success
94+
* NSAPI_ERROR_DEVICE_ERROR on failure
95+
*/
96+
virtual nsapi_error_t set_power_level(int func_level, int do_reset = 0, const char *sim_pin = NULL) = 0;
97+
98+
/** Reset and wake-up cellular device.
99+
*
100+
* @return NSAPI_ERROR_OK on success
101+
* NSAPI_ERROR_DEVICE_ERROR on failure
102+
*/
103+
virtual nsapi_error_t reset() = 0;
104+
105+
/** Opt for power save setting on cellular device. If both parameters are zero, this disables PSM.
106+
*
107+
* @remark See 3GPP TS 27.007 PSM for details
108+
*
109+
* @param periodic_time Timeout in seconds IoT subsystem is not expecting messaging
110+
* @param active_time Timeout in seconds IoT subsystem waits for response
111+
*
112+
* @return NSAPI_ERROR_OK on success
113+
* NSAPI_ERROR_DEVICE_ERROR on failure
114+
*/
115+
virtual nsapi_error_t opt_power_save_mode(int periodic_time, int active_time) = 0;
116+
117+
/** Opt for discontinuous reception on cellular device.
118+
*
119+
* @remark See 3GPP TS 27.007 eDRX for details.
120+
*
121+
* @param mode disable or enable the use of eDRX
122+
* @param act_type type of access technology
123+
* @param edrx_value requested edxr value. Extended DRX parameters information element.
124+
*
125+
* @return NSAPI_ERROR_OK on success
126+
* NSAPI_ERROR_DEVICE_ERROR on failure
127+
*/
128+
virtual nsapi_error_t opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) = 0;
129+
130+
/** Check whether the device is ready to accept commands.
131+
*
132+
* @return NSAPI_ERROR_OK on success
133+
* NSAPI_ERROR_DEVICE_ERROR on failure
134+
*/
135+
virtual nsapi_error_t is_device_ready() = 0;
136+
137+
/** Set URC callback function for device specific ready urc. URC is defined in device specific
138+
* power API. Used in startup sequence to listen when device is ready
139+
* for using at commands and possible sim.
140+
*
141+
* @param callback Callback function called when urc received
142+
*
143+
* @return NSAPI_ERROR_OK on success
144+
* NSAPI_ERROR_NO_MEMORY on memory failure
145+
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
146+
*/
147+
virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback) = 0;
148+
149+
/** Removes the device ready urc from the list of urc's.
150+
*
151+
* @param callback callback to remove from the list of urc's
152+
*/
153+
virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback) = 0;
154+
};
155+
156+
} // namespace mbed
157+
158+
#endif /* CELLULAR_API_CELLULARPOWER_H_ */

0 commit comments

Comments
 (0)