Skip to content

Commit 0813b96

Browse files
author
Ari Parkkila
committed
Cellular: Unify set_at_mode and init_module into init()
1 parent 2dde5a4 commit 0813b96

23 files changed

+88
-141
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
232232
dev.close_sms();
233233
}
234234

235+
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init)
236+
{
237+
FileHandle_stub fh1;
238+
AT_CellularDevice dev(&fh1);
239+
EXPECT_EQ(dev.init(), NSAPI_ERROR_OK);
240+
}
241+
242+
235243
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready)
236244
{
237245
EventQueue que;
@@ -278,13 +286,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
278286
EXPECT_TRUE(0 == dev.get_send_delay());
279287
}
280288

281-
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module)
282-
{
283-
FileHandle_stub fh1;
284-
AT_CellularDevice dev(&fh1);
285-
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module());
286-
}
287-
288289
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
289290
{
290291
FileHandle_stub fh1;

UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,6 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_off)
7575
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.off());
7676
}
7777

78-
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_at_mode)
79-
{
80-
EventQueue que;
81-
FileHandle_stub fh1;
82-
ATHandler at(&fh1, que, 0, ",");
83-
84-
AT_CellularPower pow(at);
85-
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
86-
EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_at_mode());
87-
88-
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
89-
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_at_mode());
90-
}
91-
9278
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_power_level)
9379
{
9480
EventQueue que;

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti
166166
return NSAPI_ERROR_UNSUPPORTED;
167167
}
168168

169-
nsapi_error_t AT_CellularDevice::init_module()
169+
nsapi_error_t AT_CellularDevice::init()
170170
{
171171
return NSAPI_ERROR_OK;
172172
}

UNITTESTS/stubs/AT_CellularPower_stub.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ nsapi_error_t AT_CellularPower::off()
4040
return NSAPI_ERROR_OK;
4141
}
4242

43-
nsapi_error_t AT_CellularPower::set_at_mode()
44-
{
45-
return NSAPI_ERROR_OK;
46-
}
47-
4843
nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset)
4944
{
5045
return NSAPI_ERROR_OK;

UNITTESTS/target_h/myCellularDevice.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ class myCellularDevice : public CellularDevice {
109109

110110
virtual void modem_debug_on(bool on) {}
111111

112+
virtual nsapi_error_t init()
113+
{
114+
return NSAPI_ERROR_OK;
115+
}
116+
112117
virtual nsapi_error_t is_ready()
113118
{
114119
return NSAPI_ERROR_OK;
@@ -124,11 +129,6 @@ class myCellularDevice : public CellularDevice {
124129
return NSAPI_ERROR_OK;
125130
}
126131

127-
virtual nsapi_error_t init_module()
128-
{
129-
return 0;
130-
}
131-
132132
virtual CellularContext *get_context_list() const
133133
{
134134
return _context_list;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ static void wait_for_power(CellularPower *pwr)
5656
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
5757

5858
int sanity_count = 0;
59-
err = pwr->set_at_mode();
59+
err = cellular_device->init();
6060
while (err != NSAPI_ERROR_OK) {
6161
sanity_count++;
6262
wait(1);
6363
TEST_ASSERT(sanity_count < 40);
64-
err = pwr->set_at_mode();
64+
err = cellular_device->init();
6565
}
6666

6767
TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK);

features/cellular/framework/API/CellularDevice.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,18 @@ class CellularDevice {
250250
*/
251251
virtual void modem_debug_on(bool on) = 0;
252252

253+
/** Initialize cellular device must be called right after module is ready.
254+
* For example, when multiple cellular modules are supported in a single driver this function
255+
* detects and adapts to an actual module at runtime.
256+
*
257+
* @return NSAPI_ERROR_OK on success
258+
* NSAPI_ERROR_NO_MEMORY on case of memory failure
259+
* NSAPI_ERROR_UNSUPPORTED if current model is not detected
260+
* NSAPI_ERROR_DEVICE_ERROR if model information could not be read
261+
*
262+
*/
263+
virtual nsapi_error_t init() = 0;
264+
253265
/** Check whether the device is ready to accept commands.
254266
*
255267
* @return NSAPI_ERROR_OK on success
@@ -279,18 +291,6 @@ class CellularDevice {
279291
*/
280292
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0) = 0;
281293

282-
/** Initialize cellular module must be called right after module is ready.
283-
* For example, when multiple modules are supported in a single AT driver this function detects
284-
* and adapts to an actual module at runtime.
285-
*
286-
* @return NSAPI_ERROR_OK on success
287-
* NSAPI_ERROR_NO_MEMORY on case of memory failure
288-
* NSAPI_ERROR_UNSUPPORTED if current model is not detected
289-
* NSAPI_ERROR_DEVICE_ERROR if model information could not be read
290-
*
291-
*/
292-
virtual nsapi_error_t init_module() = 0;
293-
294294
/** Get the linked list of CellularContext instances
295295
*
296296
* @return Pointer to first item in linked list

features/cellular/framework/API/CellularPower.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CellularPower {
4242
* Device power on/off is modem/board specific behavior and must be done on inherited class if needed.
4343
* Power on is done by toggling power pin/button.
4444
*
45-
* @remark set_at_mode must be called to initialise modem
45+
* @remark init must be called to initialize cellular device
4646
*
4747
* @return NSAPI_ERROR_OK on success
4848
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
@@ -58,15 +58,6 @@ class CellularPower {
5858
*/
5959
virtual nsapi_error_t off() = 0;
6060

61-
/** Set AT command mode. Blocking until success or failure.
62-
*
63-
* @remark must be called after power on to prepare correct AT mode
64-
*
65-
* @return NSAPI_ERROR_OK on success
66-
* NSAPI_ERROR_DEVICE_ERROR on failure
67-
*/
68-
virtual nsapi_error_t set_at_mode() = 0;
69-
7061
/** Set cellular device power level by enabling/disabling functionality.
7162
*
7263
* @param func_level:

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,18 @@ void AT_CellularDevice::modem_debug_on(bool on)
366366
ATHandler::set_debug_list(_modem_debug_on);
367367
}
368368

369+
nsapi_error_t AT_CellularDevice::init()
370+
{
371+
_at->lock();
372+
_at->flush();
373+
_at->cmd_start("ATE0"); // echo off
374+
_at->cmd_stop_read_resp();
375+
376+
_at->cmd_start("AT+CMEE=1"); // verbose responses
377+
_at->cmd_stop_read_resp();
378+
return _at->unlock_return_error();
379+
}
380+
369381
nsapi_error_t AT_CellularDevice::is_ready()
370382
{
371383
_at->lock();
@@ -513,20 +525,3 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti
513525

514526
return _at->unlock_return_error();
515527
}
516-
517-
nsapi_error_t AT_CellularDevice::init_module()
518-
{
519-
#if MBED_CONF_MBED_TRACE_ENABLE
520-
CellularInformation *information = open_information();
521-
if (information) {
522-
char *pbuf = new char[100];
523-
nsapi_error_t ret = information->get_model(pbuf, sizeof(*pbuf));
524-
close_information();
525-
if (ret == NSAPI_ERROR_OK) {
526-
tr_info("Model %s", pbuf);
527-
}
528-
delete[] pbuf;
529-
}
530-
#endif
531-
return NSAPI_ERROR_OK;
532-
}

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ class AT_CellularDevice : public CellularDevice {
7070

7171
virtual void modem_debug_on(bool on);
7272

73+
virtual nsapi_error_t init();
74+
7375
virtual nsapi_error_t is_ready();
7476

7577
virtual nsapi_error_t set_ready_cb(Callback<void()> callback);
7678

7779
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0);
7880

79-
virtual nsapi_error_t init_module();
8081

8182
virtual ATHandler *get_at_handler(FileHandle *fh);
8283

0 commit comments

Comments
 (0)