50
50
static UARTSerial cellular_serial (MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
51
51
static EventQueue queue (8 * EVENTS_EVENT_SIZE);
52
52
static rtos::Semaphore network_semaphore (0 );
53
- static CellularConnectionFSM cellularConnectionFSM;
53
+ static CellularConnectionFSM * cellularConnectionFSM;
54
54
static CellularConnectionFSM::CellularState cellular_target_state;
55
55
static CellularSMS* sms;
56
56
static char service_center_address[SMS_MAX_PHONE_NUMBER_SIZE];
@@ -65,9 +65,35 @@ static bool cellular_status(int state, int next_state)
65
65
return true ;
66
66
}
67
67
68
- static void init ()
68
+ static void createFSM ()
69
69
{
70
- // the service center address is checked before any modification tests on it
70
+ #if defined (MDMRTS) && defined (MDMCTS)
71
+ cellular_serial.set_flow_control (SerialBase::RTSCTS, MDMRTS, MDMCTS);
72
+ #endif
73
+ cellularConnectionFSM = new CellularConnectionFSM ();
74
+ cellularConnectionFSM->set_serial (&cellular_serial);
75
+ cellularConnectionFSM->set_callback (&cellular_status);
76
+
77
+ TEST_ASSERT (cellularConnectionFSM->init () == NSAPI_ERROR_OK);
78
+ TEST_ASSERT (cellularConnectionFSM->start_dispatch () == NSAPI_ERROR_OK);
79
+ cellularConnectionFSM->set_sim_pin (MBED_CONF_APP_CELLULAR_SIM_PIN);
80
+
81
+ CellularDevice *device = cellularConnectionFSM->get_device ();
82
+ TEST_ASSERT (device != NULL );
83
+ device->set_timeout (30000 );
84
+
85
+ }
86
+ static void store_service_center_address ()
87
+ {
88
+ // Frist we need to go SIM_PIN state to make sure that we can get service address and device ready to accept AT commands
89
+ createFSM ();
90
+ cellular_target_state = CellularConnectionFSM::STATE_SIM_PIN;
91
+ TEST_ASSERT (cellularConnectionFSM->continue_to_state (cellular_target_state) == NSAPI_ERROR_OK);
92
+ TEST_ASSERT (network_semaphore.wait (NETWORK_TIMEOUT) == 1 ); // cellular network searching may take several minutes
93
+
94
+ delete cellularConnectionFSM;
95
+ cellularConnectionFSM = NULL ;
96
+
71
97
ATHandler *at_init = new ATHandler (&cellular_serial, queue, 30000 , " \r " );
72
98
at_init->cmd_start (" AT+CSCA?" );
73
99
at_init->cmd_stop ();
@@ -82,41 +108,27 @@ static void init()
82
108
TEST_ASSERT (at_init->get_last_error () == NSAPI_ERROR_OK);
83
109
84
110
delete at_init;
85
-
86
- #if defined (MDMRTS) && defined (MDMCTS)
87
- cellular_serial.set_flow_control (SerialBase::RTSCTS, MDMRTS, MDMCTS);
88
- #endif
89
- cellularConnectionFSM.set_serial (&cellular_serial);
90
- cellularConnectionFSM.set_callback (&cellular_status);
91
-
92
- TEST_ASSERT (cellularConnectionFSM.init () == NSAPI_ERROR_OK);
93
- TEST_ASSERT (cellularConnectionFSM.start_dispatch () == NSAPI_ERROR_OK);
94
-
95
-
96
- CellularDevice *device = cellularConnectionFSM.get_device ();
97
-
98
- TEST_ASSERT (device != NULL );
99
- device->set_timeout (30000 );
100
-
101
- sms = device->open_sms (&cellular_serial);
102
- TEST_ASSERT (sms != NULL );
103
-
104
- wait (3 );
105
-
106
111
}
107
112
108
- static void activate_context ()
113
+ static void init ()
109
114
{
110
- CellularNetwork *network = cellularConnectionFSM.get_network ();
115
+ // First store current service address
116
+ store_service_center_address ();
117
+
118
+ createFSM ();
119
+ CellularNetwork *network = cellularConnectionFSM->get_network ();
111
120
112
121
TEST_ASSERT (network != NULL );
113
122
TEST_ASSERT (network->set_credentials (MBED_CONF_APP_APN, NULL , NULL ) == NSAPI_ERROR_OK);
114
123
115
- cellularConnectionFSM.set_sim_pin (MBED_CONF_APP_CELLULAR_SIM_PIN);
116
-
117
124
cellular_target_state = CellularConnectionFSM::STATE_REGISTERING_NETWORK;
118
- TEST_ASSERT (cellularConnectionFSM. continue_to_state (cellular_target_state) == NSAPI_ERROR_OK);
125
+ TEST_ASSERT (cellularConnectionFSM-> continue_to_state (cellular_target_state) == NSAPI_ERROR_OK);
119
126
TEST_ASSERT (network_semaphore.wait (NETWORK_TIMEOUT) == 1 ); // cellular network searching may take several minutes
127
+
128
+ sms = cellularConnectionFSM->get_device ()->open_sms (&cellular_serial);
129
+ TEST_ASSERT (sms != NULL );
130
+
131
+ wait (3 );
120
132
}
121
133
122
134
static void test_sms_initialize_text_mode ()
@@ -132,8 +144,6 @@ static void test_sms_initialize_pdu_mode()
132
144
static void test_set_cscs ()
133
145
{
134
146
TEST_ASSERT (sms->set_cscs (" IRA" ) == NSAPI_ERROR_OK);
135
- TEST_ASSERT (sms->set_cscs (" 8859-1" ) == NSAPI_ERROR_OK);
136
- TEST_ASSERT (sms->set_cscs (" PCCP437" ) == NSAPI_ERROR_OK);
137
147
TEST_ASSERT (sms->set_cscs (" UCS2" ) == NSAPI_ERROR_OK);
138
148
TEST_ASSERT (sms->set_cscs (" GSM" ) == NSAPI_ERROR_OK);
139
149
}
@@ -203,7 +213,7 @@ static void test_delete_all_messages()
203
213
// send a message so that there is something to delete
204
214
test_sms_send ();
205
215
wait (7 );
206
- TEST_ASSERT (sms->delete_all_messages () == NSAPI_ERROR_OK);
216
+ TEST_ASSERT (sms->delete_all_messages () == NSAPI_ERROR_OK);
207
217
callbacks_received = 0 ;
208
218
}
209
219
@@ -226,7 +236,6 @@ static utest::v1::status_t greentea_failure_handler(const Case *const source, co
226
236
227
237
static Case cases[] = {
228
238
Case (" CellularSMS init" , init, greentea_failure_handler),
229
- Case (" CellularSMS activate context" , activate_context, greentea_failure_handler),
230
239
Case (" CellularSMS test ME for storage" , test_set_cpms_me, greentea_failure_handler),
231
240
Case (" CellularSMS test initialize to PDU mode" , test_sms_initialize_pdu_mode, greentea_failure_handler),
232
241
Case (" CellularSMS test character sets" , test_set_cscs, greentea_failure_handler),
0 commit comments