Skip to content

Commit 19b2494

Browse files
author
Ari Parkkila
committed
Cellular: AT remove_urc_handler changed to set_urc_handler(prefix, 0)
1 parent e49f90f commit 19b2494

File tree

6 files changed

+27
-25
lines changed

6 files changed

+27
-25
lines changed

UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ TEST_F(TestATHandler, test_ATHandler_remove_urc_handler)
174174
mbed::Callback<void()> cb(&urc_callback);
175175
at.set_urc_handler(ch, cb);
176176

177-
//This does nothing!!!
178-
at.remove_urc_handler(ch);
177+
at.set_urc_handler(ch, 0);
179178
}
180179

181180
TEST_F(TestATHandler, test_ATHandler_get_last_error)
@@ -996,10 +995,10 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
996995
filehandle_stub_table = table9;
997996
filehandle_stub_table_pos = 0;
998997

998+
at.set_urc_handler("urc: ", &urc_callback);
999999
at.set_urc_handler("urc: ", NULL);
10001000
at.resp_start();
1001-
// Match URC consumes to CRLF -> nothing to read after that -> ERROR
1002-
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
1001+
EXPECT_EQ(at.get_last_error(), NSAPI_ERROR_OK);
10031002

10041003
char table10[] = "urc: info\r\ngarbage\r\nprefix: info\r\nOK\r\n\0";
10051004
at.flush();

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,13 @@ void ATHandler::set_is_filehandle_usable(bool usable)
160160
_is_fh_usable = usable;
161161
}
162162

163-
nsapi_error_t ATHandler::set_urc_handler(const char *prefix, mbed::Callback<void()> callback)
163+
nsapi_error_t ATHandler::set_urc_handler(const char *prefix, Callback<void()> callback)
164164
{
165+
if (!callback) {
166+
remove_urc_handler(prefix);
167+
return NSAPI_ERROR_OK;
168+
}
169+
165170
if (find_urc_handler(prefix)) {
166171
tr_warn("URC already added with prefix: %s", prefix);
167172
return NSAPI_ERROR_OK;
@@ -311,7 +316,7 @@ void ATHandler::process_oob()
311316

312317
void ATHandler::set_filehandle_sigio()
313318
{
314-
_fileHandle->sigio(mbed::Callback<void()>(this, &ATHandler::event));
319+
_fileHandle->sigio(Callback<void()>(this, &ATHandler::event));
315320
}
316321

317322
void ATHandler::reset_buffer()

features/cellular/framework/AT/ATHandler.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,13 @@ class ATHandler {
120120
*/
121121
nsapi_error_t unlock_return_error();
122122

123-
/** Set the urc callback for urc. If urc is found when parsing AT responses, then call if called.
124-
* If urc is already set then it's not set twice.
123+
/** Set callback function for URC
125124
*
126-
* @param prefix Register urc prefix for callback. Urc could be for example "+CMTI: "
127-
* @param callback Callback, which is called if urc is found in AT response
125+
* @param prefix URC text to look for, e.g. "+CMTI:"
126+
* @param callback function to call on prefix, or 0 to remove callback
128127
* @return NSAPI_ERROR_OK or NSAPI_ERROR_NO_MEMORY if no memory
129128
*/
130-
nsapi_error_t set_urc_handler(const char *prefix, mbed::Callback<void()> callback);
131-
132-
/** Remove urc handler from linked list of urc's
133-
*
134-
* @param prefix Register urc prefix for callback. Urc could be for example "+CMTI: "
135-
*/
136-
void remove_urc_handler(const char *prefix);
129+
nsapi_error_t set_urc_handler(const char *prefix, Callback<void()> callback);
137130

138131
ATHandler *_nextATHandler; // linked list
139132

@@ -229,6 +222,11 @@ class ATHandler {
229222
#endif
230223
FileHandle *_fileHandle;
231224
private:
225+
/** Remove urc handler from linked list of urc's
226+
*
227+
* @param prefix Register urc prefix for callback. Urc could be for example "+CMTI: "
228+
*/
229+
void remove_urc_handler(const char *prefix);
232230

233231
void set_error(nsapi_error_t err);
234232

@@ -242,7 +240,7 @@ class ATHandler {
242240
struct oob_t {
243241
const char *prefix;
244242
int prefix_len;
245-
mbed::Callback<void()> cb;
243+
Callback<void()> cb;
246244
oob_t *next;
247245
};
248246
oob_t *_oobs;

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ AT_CellularNetwork::~AT_CellularNetwork()
104104

105105
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
106106
if (has_registration((RegistrationType)type) != RegistrationModeDisable) {
107-
_at.remove_urc_handler(at_reg[type].urc_prefix);
107+
_at.set_urc_handler(at_reg[type].urc_prefix, 0);
108108
}
109109
}
110110

111-
_at.remove_urc_handler("NO CARRIER");
112-
_at.remove_urc_handler("+CGEV:");
111+
_at.set_urc_handler("NO CARRIER", 0);
112+
_at.set_urc_handler("+CGEV:", 0);
113113
}
114114

115115
void AT_CellularNetwork::urc_no_carrier()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ GEMALTO_CINTERION_CellularStack::GEMALTO_CINTERION_CellularStack(ATHandler &atHa
3939

4040
GEMALTO_CINTERION_CellularStack::~GEMALTO_CINTERION_CellularStack()
4141
{
42-
_at.remove_urc_handler("^SIS:");
43-
_at.remove_urc_handler("^SISW:");
44-
_at.remove_urc_handler("^SISR:");
42+
_at.set_urc_handler("^SIS:", 0);
43+
_at.set_urc_handler("^SISW:", 0);
44+
_at.set_urc_handler("^SISR:", 0);
4545
}
4646

4747
GEMALTO_CINTERION_CellularStack::CellularSocket *GEMALTO_CINTERION_CellularStack::find_socket(int sock_id)

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularPower.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ nsapi_error_t QUECTEL_BG96_CellularPower::set_device_ready_urc_cb(mbed::Callback
3232

3333
void QUECTEL_BG96_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
3434
{
35-
_at.remove_urc_handler(DEVICE_READY_URC);
35+
_at.set_urc_handler(DEVICE_READY_URC, 0);
3636
}

0 commit comments

Comments
 (0)