Skip to content

Commit 1afece7

Browse files
authored
Merge pull request #11488 from kivaisan/fix_cellular_get_interface_name
Cellular: Fix get_interface_name to not include leading zero
2 parents 4f7339a + ab71b2d commit 1afece7

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ class def_AT_CTX : public AT_CellularContext {
178178
int _op;
179179
};
180180

181+
class AT_CTX_cid: public AT_CellularContext {
182+
public:
183+
AT_CTX_cid(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
184+
AT_CellularContext(at, device, apn) {}
185+
virtual ~AT_CTX_cid() {}
186+
187+
void set_cid(int cid)
188+
{
189+
_cid = cid;
190+
}
191+
};
192+
181193
static int network_cb_count;
182194
static void network_cb(nsapi_event_t ev, intptr_t intptr)
183195
{
@@ -250,6 +262,22 @@ TEST_F(TestAT_CellularContext, get_ip_address)
250262
EXPECT_TRUE(ip != NULL);
251263
}
252264

265+
TEST_F(TestAT_CellularContext, get_interface_name)
266+
{
267+
EventQueue que;
268+
FileHandle_stub fh1;
269+
ATHandler at(&fh1, que, 0, ",");
270+
AT_CellularDevice dev(&fh1);
271+
AT_CTX_cid ctx(at, &dev);
272+
273+
char ifn[5];
274+
EXPECT_TRUE(NULL == ctx.get_interface_name(ifn));
275+
276+
ctx.set_cid(1);
277+
EXPECT_STREQ("ce1", ctx.get_interface_name(ifn));
278+
EXPECT_STREQ("ce1", ifn);
279+
}
280+
253281
TEST_F(TestAT_CellularContext, attach)
254282
{
255283
EventQueue que;
@@ -746,5 +774,4 @@ TEST_F(TestAT_CellularContext, get_timeout_for_operation)
746774

747775
ctx1._op = -1;
748776
EXPECT_EQ(1800 * 1000, ctx1.do_op());
749-
750777
}

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ char *AT_CellularContext::get_interface_name(char *interface_name)
244244
return NULL;
245245
}
246246
MBED_ASSERT(interface_name);
247-
sprintf(interface_name, "ce%02d", _cid);
247+
sprintf(interface_name, "ce%d", _cid);
248248
return interface_name;
249249
}
250250

0 commit comments

Comments
 (0)