Skip to content

Commit 09e2a7e

Browse files
author
Ari Parkkila
committed
Cellular: Unify set_at_mode and init_module into init()
1 parent 7f7ffbe commit 09e2a7e

23 files changed

+83
-134
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
@@ -222,6 +222,14 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
222222
dev.close_sms();
223223
}
224224

225+
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init)
226+
{
227+
FileHandle_stub fh1;
228+
AT_CellularDevice dev(&fh1);
229+
EXPECT_EQ(dev.init(), NSAPI_ERROR_OK);
230+
}
231+
232+
225233
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_is_ready)
226234
{
227235
EventQueue que;
@@ -268,13 +276,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
268276
EXPECT_TRUE(0 == dev.get_send_delay());
269277
}
270278

271-
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module)
272-
{
273-
FileHandle_stub fh1;
274-
AT_CellularDevice dev(&fh1);
275-
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module());
276-
}
277-
278279
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
279280
{
280281
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
@@ -159,7 +159,7 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti
159159
return NSAPI_ERROR_UNSUPPORTED;
160160
}
161161

162-
nsapi_error_t AT_CellularDevice::init_module()
162+
nsapi_error_t AT_CellularDevice::init()
163163
{
164164
return NSAPI_ERROR_OK;
165165
}

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
@@ -248,6 +248,18 @@ class CellularDevice {
248248
*/
249249
virtual void modem_debug_on(bool on) = 0;
250250

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

280-
/** Initialize cellular module must be called right after module is ready.
281-
* For example, when multiple modules are supported in a single AT driver this function detects
282-
* and adapts to an actual module at runtime.
283-
*
284-
* @return NSAPI_ERROR_OK on success
285-
* NSAPI_ERROR_NO_MEMORY on case of memory failure
286-
* NSAPI_ERROR_UNSUPPORTED if current model is not detected
287-
* NSAPI_ERROR_DEVICE_ERROR if model information could not be read
288-
*
289-
*/
290-
virtual nsapi_error_t init_module() = 0;
291-
292292
/** Get the linked list of CellularContext instances
293293
*
294294
* @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
@@ -400,6 +400,18 @@ void AT_CellularDevice::modem_debug_on(bool on)
400400
}
401401
}
402402

403+
nsapi_error_t AT_CellularDevice::init()
404+
{
405+
_at->lock();
406+
_at->flush();
407+
_at->cmd_start("ATE0"); // echo off
408+
_at->cmd_stop_read_resp();
409+
410+
_at->cmd_start("AT+CMEE=1"); // verbose responses
411+
_at->cmd_stop_read_resp();
412+
return _at->unlock_return_error();
413+
}
414+
403415
nsapi_error_t AT_CellularDevice::is_ready()
404416
{
405417
_at->lock();
@@ -547,20 +559,3 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti
547559

548560
return _at->unlock_return_error();
549561
}
550-
551-
nsapi_error_t AT_CellularDevice::init_module()
552-
{
553-
#if MBED_CONF_MBED_TRACE_ENABLE
554-
CellularInformation *information = open_information();
555-
if (information) {
556-
char *pbuf = new char[100];
557-
nsapi_error_t ret = information->get_model(pbuf, sizeof(*pbuf));
558-
close_information();
559-
if (ret == NSAPI_ERROR_OK) {
560-
tr_info("Model %s", pbuf);
561-
}
562-
delete[] pbuf;
563-
}
564-
#endif
565-
return NSAPI_ERROR_OK;
566-
}

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +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();
80-
8181
ATHandler *_atHandlers;
8282

8383
ATHandler *get_at_handler(FileHandle *fh);

features/cellular/framework/AT/AT_CellularPower.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ nsapi_error_t AT_CellularPower::off()
4242
return NSAPI_ERROR_UNSUPPORTED;
4343
}
4444

45-
nsapi_error_t AT_CellularPower::set_at_mode()
46-
{
47-
_at.lock();
48-
_at.flush();
49-
_at.cmd_start("ATE0"); // echo off
50-
_at.cmd_stop_read_resp();
51-
52-
_at.cmd_start("AT+CMEE=1"); // verbose responses
53-
_at.cmd_stop_read_resp();
54-
return _at.unlock_return_error();
55-
}
56-
5745
nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset)
5846
{
5947
_at.lock();

features/cellular/framework/AT/AT_CellularPower.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ class AT_CellularPower : public CellularPower, public AT_CellularBase {
3838

3939
virtual nsapi_error_t off();
4040

41-
virtual nsapi_error_t set_at_mode();
42-
4341
virtual nsapi_error_t set_power_level(int func_level, int do_reset = 0);
4442

4543
virtual nsapi_error_t reset();

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ bool CellularStateMachine::device_ready()
394394
void CellularStateMachine::state_device_ready()
395395
{
396396
_cellularDevice.set_timeout(TIMEOUT_POWER_ON);
397-
_cb_data.error = _power->set_at_mode();
397+
_cb_data.error = _cellularDevice.init();
398398
if (_cb_data.error == NSAPI_ERROR_OK) {
399399
if (device_ready()) {
400400
enter_to_state(STATE_SIM_PIN);
@@ -702,10 +702,10 @@ void CellularStateMachine::cellular_event_changed(nsapi_event_t ev, intptr_t ptr
702702
}
703703
}
704704

705-
void CellularStateMachine::ready_urc_cb()
705+
void CellularStateMachine::device_ready_cb()
706706
{
707-
tr_debug("Device ready URC func called");
708-
if (_state == STATE_DEVICE_READY && _power->set_at_mode() == NSAPI_ERROR_OK) {
707+
tr_debug("Device ready callback");
708+
if (_state == STATE_DEVICE_READY && _cellularDevice.init() == NSAPI_ERROR_OK) {
709709
tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next");
710710
_queue.cancel(_event_id);
711711
_event_id = -1;

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const
4646
return new GEMALTO_CINTERION_CellularContext(at, this, apn);
4747
}
4848

49-
nsapi_error_t GEMALTO_CINTERION::init_module()
49+
nsapi_error_t GEMALTO_CINTERION::init()
5050
{
51+
nsapi_error_t err = AT_CellularDevice::init();
52+
if (err != NSAPI_ERROR_OK) {
53+
return err;
54+
}
55+
5156
CellularInformation *information = open_information();
5257
if (!information) {
5358
return NSAPI_ERROR_NO_MEMORY;

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class GEMALTO_CINTERION : public AT_CellularDevice {
3131
protected: // AT_CellularDevice
3232
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
3333
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
34-
public:
35-
virtual nsapi_error_t init_module();
34+
protected:
3635
virtual uint16_t get_send_delay() const;
36+
virtual nsapi_error_t init();
3737
};
3838

3939
} // namespace mbed

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,17 @@ AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at)
8383
return new QUECTEL_BC95_CellularInformation(at);
8484
}
8585

86+
nsapi_error_t QUECTEL_BC95::init()
87+
{
88+
_at->lock();
89+
_at->flush();
90+
_at->cmd_start("AT");
91+
_at->cmd_stop_read_resp();
92+
93+
_at->cmd_start("AT+CMEE="); // verbose responses
94+
_at->write_int(1);
95+
_at->cmd_stop_read_resp();
96+
97+
return _at->unlock_return_error();
98+
}
99+

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class QUECTEL_BC95 : public AT_CellularDevice {
3535
virtual AT_CellularPower *open_power_impl(ATHandler &at);
3636
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
3737
virtual AT_CellularInformation *open_information_impl(ATHandler &at);
38+
virtual nsapi_error_t init();
3839

3940
public: // NetworkInterface
4041
void handle_urc(FileHandle *fh);

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,6 @@ QUECTEL_BC95_CellularPower::~QUECTEL_BC95_CellularPower()
2929

3030
}
3131

32-
nsapi_error_t QUECTEL_BC95_CellularPower::set_at_mode()
33-
{
34-
_at.lock();
35-
_at.flush();
36-
_at.cmd_start("AT");
37-
_at.cmd_stop_read_resp();
38-
39-
_at.cmd_start("AT+CMEE="); // verbose responses
40-
_at.write_int(1);
41-
_at.cmd_stop_read_resp();
42-
43-
return _at.unlock_return_error();
44-
}
45-
4632
nsapi_error_t QUECTEL_BC95_CellularPower::reset()
4733
{
4834
_at.lock();

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class QUECTEL_BC95_CellularPower : public AT_CellularPower {
2828
virtual ~QUECTEL_BC95_CellularPower();
2929

3030
public: //from CellularPower
31-
virtual nsapi_error_t set_at_mode();
32-
3331
virtual nsapi_error_t reset();
3432
};
3533

features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ uint16_t TELIT_HE910::get_send_delay() const
5858
return DEFAULT_DELAY_BETWEEN_AT_COMMANDS;
5959
}
6060

61+
nsapi_error_t TELIT_HE910::init()
62+
{
63+
nsapi_error_t err = AT_CellularDevice::init();
64+
if (err != NSAPI_ERROR_OK) {
65+
return err;
66+
}
67+
_at->lock();
68+
_at->cmd_start("AT&K0;&C1;&D0");
69+
_at->cmd_stop_read_resp();
70+
71+
return _at->unlock_return_error();
72+
}

features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ class TELIT_HE910 : public AT_CellularDevice {
3434
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
3535
virtual AT_CellularPower *open_power_impl(ATHandler &at);
3636
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
37-
38-
public: // from CellularDevice
3937
virtual uint16_t get_send_delay() const;
38+
virtual nsapi_error_t init();
4039
};
4140
} // namespace mbed
4241
#endif /* CELLULAR_TARGETS_TELIT_HE910_TELIT_HE910_H_ */

0 commit comments

Comments
 (0)