Skip to content

Cellular: Fix get_interface_name to not include leading zero #11488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ class def_AT_CTX : public AT_CellularContext {
int _op;
};

class AT_CTX_cid: public AT_CellularContext {
public:
AT_CTX_cid(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
AT_CellularContext(at, device, apn) {}
virtual ~AT_CTX_cid() {}

void set_cid(int cid)
{
_cid = cid;
}
};

static int network_cb_count;
static void network_cb(nsapi_event_t ev, intptr_t intptr)
{
Expand Down Expand Up @@ -250,6 +262,22 @@ TEST_F(TestAT_CellularContext, get_ip_address)
EXPECT_TRUE(ip != NULL);
}

TEST_F(TestAT_CellularContext, get_interface_name)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularDevice dev(&fh1);
AT_CTX_cid ctx(at, &dev);

char ifn[5];
EXPECT_TRUE(NULL == ctx.get_interface_name(ifn));

ctx.set_cid(1);
EXPECT_STREQ("ce1", ctx.get_interface_name(ifn));
EXPECT_STREQ("ce1", ifn);
}

TEST_F(TestAT_CellularContext, attach)
{
EventQueue que;
Expand Down Expand Up @@ -746,5 +774,4 @@ TEST_F(TestAT_CellularContext, get_timeout_for_operation)

ctx1._op = -1;
EXPECT_EQ(1800 * 1000, ctx1.do_op());

}
2 changes: 1 addition & 1 deletion features/cellular/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ char *AT_CellularContext::get_interface_name(char *interface_name)
return NULL;
}
MBED_ASSERT(interface_name);
sprintf(interface_name, "ce%02d", _cid);
sprintf(interface_name, "ce%d", _cid);
return interface_name;
}

Expand Down