Skip to content

Commit adf9165

Browse files
author
Cruz Monrreal
authored
Merge pull request #8405 from hasnainvirk/QOS_impl_with_utests
[LoRaWAN]: Adding QOS in response to LinkADRReq and fixing class C bugs
2 parents af19a39 + 9c3f73b commit adf9165

19 files changed

+448
-221
lines changed

UNITTESTS/features/lorawan/loramac/Test_LoRaMac.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ TEST_F(Test_LoRaMac, get_backoff_timer_event_id)
527527

528528
TEST_F(Test_LoRaMac, clear_tx_pipe)
529529
{
530-
EXPECT_EQ(LORAWAN_STATUS_OK, object->clear_tx_pipe()); //timer id == 0
530+
EXPECT_EQ(LORAWAN_STATUS_NO_OP, object->clear_tx_pipe()); //timer id == 0
531531

532532
my_phy phy;
533533
object->bind_phy(phy);
@@ -543,6 +543,12 @@ TEST_F(Test_LoRaMac, clear_tx_pipe)
543543
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize(NULL, my_cb));
544544
EventQueue_stub::int_value = 0;
545545
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->clear_tx_pipe());
546+
loramac_mhdr_t machdr;
547+
machdr.bits.mtype = MCPS_UNCONFIRMED;
548+
uint8_t buf[1];
549+
buf[0] = 'T';
550+
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_DUTYCYCLE_RESTRICTED;
551+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->send(&machdr, 15, buf, 1));
546552

547553
EventQueue_stub::int_value = 1;
548554
EXPECT_EQ(LORAWAN_STATUS_OK, object->clear_tx_pipe());
@@ -558,3 +564,12 @@ TEST_F(Test_LoRaMac, get_current_slot)
558564
object->get_current_slot();
559565
}
560566

567+
TEST_F(Test_LoRaMac, get_QOS_level)
568+
{
569+
EXPECT_EQ(1, object->get_QOS_level());
570+
}
571+
572+
TEST_F(Test_LoRaMac, get_prev_QOS_level)
573+
{
574+
EXPECT_EQ(1, object->get_prev_QOS_level());
575+
}

UNITTESTS/features/lorawan/loraphy/Test_LoRaPHY.cpp

Lines changed: 121 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,17 @@ TEST_F(Test_LoRaPHY, calculate_backoff)
167167
{
168168
channel_params_t p[1];
169169
p[0].band = 0;
170+
p[0].dr_range.fields.min = DR_0;
171+
p[0].dr_range.fields.max = DR_5;
170172
object->get_phy_params().channels.channel_list = p;
171173
band_t b[1];
174+
b[0].duty_cycle = 0;
175+
b[0].higher_band_freq = 8689000;
176+
b[0].lower_band_freq = 8687000;
177+
b[0].max_tx_pwr = 20;
178+
b[0].last_join_tx_time = 0;
179+
b[0].last_tx_time = 0;
180+
b[0].off_time = 0;
172181
object->get_phy_params().bands.table = b;
173182
object->calculate_backoff(false, false, false, 0, 10, 12);
174183

@@ -180,6 +189,7 @@ TEST_F(Test_LoRaPHY, calculate_backoff)
180189
TEST_F(Test_LoRaPHY, mask_bit_test)
181190
{
182191
uint16_t buf;
192+
buf = 0x08;
183193
EXPECT_TRUE(!object->mask_bit_test(&buf, 0));
184194
}
185195

@@ -197,51 +207,58 @@ TEST_F(Test_LoRaPHY, mask_bit_clear)
197207

198208
TEST_F(Test_LoRaPHY, request_new_channel)
199209
{
200-
channel_params_t p;
201-
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
210+
band_t b;
211+
object->get_phy_params().bands.size = 1;
212+
b.higher_band_freq = 8689000;
213+
b.lower_band_freq = 8678000;
214+
b.duty_cycle = 0;
215+
b.last_join_tx_time = 0;
216+
b.last_tx_time = 0;
217+
b.max_tx_pwr = 20;
218+
b.off_time = 0;
219+
object->get_phy_params().bands.table = &b;
202220

203-
p.frequency = 0;
221+
channel_params_t p;
222+
//First 3 channels are set to be default
223+
p.band = 0;
224+
p.dr_range.fields.min = DR_0;
225+
p.dr_range.fields.max = DR_5;
226+
p.frequency = 8687000;
227+
p.rx1_frequency = 0;
228+
uint16_t dflt_msk = 0x07;
229+
object->get_phy_params().channels.default_mask = &dflt_msk;
230+
object->get_phy_params().channels.channel_list = &p;
204231
object->get_phy_params().custom_channelplans_supported = true;
205-
uint16_t list;
206-
object->get_phy_params().channels.default_mask = &list;
207-
channel_params_t pp;
208-
object->get_phy_params().channels.channel_list = &pp;
209-
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
210232

211-
//Default
212-
p.frequency = 2;
213-
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
233+
//Default channel, PARAMETER invalid
234+
EXPECT_TRUE(0 == object->request_new_channel(0, &p));
214235

215236
//Freq & DR invalid
216-
object->get_phy_params().max_channel_cnt = 2;
217-
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
237+
p.frequency = 12345;
238+
p.dr_range.fields.max = 12;
239+
object->get_phy_params().max_channel_cnt = 16;
240+
object->get_phy_params().min_tx_datarate = DR_0;
241+
object->get_phy_params().max_tx_datarate = DR_5;
242+
// Frequency and DR are invalid - LORAWAN_STATUS_FREQ_AND_DR_INVALID
243+
EXPECT_TRUE(0 == object->request_new_channel(0, &p));
218244

219245
//Freq invalid
220-
pp.frequency = 0;
221-
object->get_phy_params().default_max_datarate = 1;
222-
object->get_phy_params().max_tx_datarate = 8;
223-
p.dr_range.fields.max = 2;
224-
p.dr_range.fields.min = 0;
246+
p.frequency = 12345;
247+
p.dr_range.fields.max = DR_5;
225248
object->get_phy_params().default_channel_cnt = 3;
226249
EXPECT_TRUE(2 == object->request_new_channel(0, &p));
227250

228251
//DR invalid
229-
pp.frequency = 2;
230-
p.band = 0;
231-
object->get_phy_params().bands.size = 1;
232-
band_t b;
233-
object->get_phy_params().bands.table = &b;
234-
b.higher_band_freq = 5;
235-
b.lower_band_freq = 1;
252+
p.frequency = 8687000;
236253
p.dr_range.fields.max = 12;
237254
p.dr_range.fields.min = 1;
238255
EXPECT_TRUE(1 == object->request_new_channel(0, &p));
239256

240257
//STATUS_OK
241-
p.dr_range.fields.max = 2;
242-
uint16_t list2[16];
243-
p.dr_range.fields.min = 0;
244-
object->get_phy_params().channels.mask = list2;
258+
p.dr_range.fields.max = DR_5;
259+
p.dr_range.fields.min = DR_0;
260+
uint16_t ch_msk = 0x08;
261+
object->get_phy_params().channels.mask = &ch_msk;
245262
EXPECT_TRUE(3 == object->request_new_channel(0, &p));
246263
}
247264

@@ -272,19 +289,27 @@ TEST_F(Test_LoRaPHY, restore_default_channels)
272289
TEST_F(Test_LoRaPHY, apply_cf_list)
273290
{
274291
uint8_t list[16];
292+
memset(list, 0, 16);
275293
object->apply_cf_list(list, 0);
276294

277295
object->get_phy_params().cflist_supported = true;
278296
object->apply_cf_list(list, 0);
279297

280-
object->get_phy_params().default_channel_cnt = 2;
298+
object->get_phy_params().default_channel_cnt = 1;
281299
object->get_phy_params().cflist_channel_cnt = 0;
282300
object->get_phy_params().max_channel_cnt = 3;
283301

284-
uint16_t mask[8];
285-
channel_params_t p[8];
286-
object->get_phy_params().channels.default_mask = mask;
287-
object->get_phy_params().channels.mask = mask;
302+
uint16_t def_mask = 0x01;
303+
channel_params_t p[16];
304+
memset(p, 0, 16);
305+
//one default channel
306+
p[0].band = 0;
307+
p[0].dr_range.fields.min = DR_0;
308+
p[0].dr_range.fields.min = DR_5;
309+
p[0].frequency = 8687000;
310+
311+
object->get_phy_params().channels.default_mask = &def_mask;
312+
object->get_phy_params().channels.mask = &def_mask;
288313
object->get_phy_params().channels.channel_list = p;
289314
object->apply_cf_list(list, 16);
290315

@@ -325,6 +350,7 @@ TEST_F(Test_LoRaPHY, rx_config)
325350
uint8_t list2;
326351
object->get_phy_params().payloads_with_repeater.table = &list2;
327352
rx_config_params_t p;
353+
memset(&p, 0, sizeof(rx_config_params_t));
328354
p.datarate = 0;
329355
p.rx_slot = RX_SLOT_WIN_1;
330356
channel_params_t pp[1];
@@ -345,11 +371,22 @@ TEST_F(Test_LoRaPHY, rx_config)
345371
TEST_F(Test_LoRaPHY, compute_rx_win_params)
346372
{
347373
uint32_t list[1];
348-
list[0] = 0;
374+
list[0] = 125000;
349375
object->get_phy_params().bandwidths.table = list;
350-
uint8_t list2;
376+
uint8_t list2[1];
377+
list2[0]= 12;
351378
object->get_phy_params().datarates.table = &list2;
379+
channel_params_t ch_lst[16];
380+
memset(ch_lst, 0, sizeof(channel_params_t)*16);
381+
ch_lst[0].band = 0;
382+
ch_lst[0].dr_range.fields.min = DR_0;
383+
ch_lst[0].dr_range.fields.max = DR_5;
384+
ch_lst[0].frequency = 8687000;
385+
object->get_phy_params().channels.channel_list = ch_lst;
386+
object->get_phy_params().channels.channel_list_size = 16;
352387
rx_config_params_t p;
388+
memset(&p, 0, sizeof(rx_config_params_t));
389+
p.frequency = 8687000;
353390
object->compute_rx_win_params(0, 0, 0, &p);
354391

355392
p.datarate = 0;
@@ -368,20 +405,25 @@ TEST_F(Test_LoRaPHY, compute_rx_win_params)
368405
TEST_F(Test_LoRaPHY, tx_config)
369406
{
370407
band_t b;
408+
memset(&b, 0, sizeof(band_t));
371409
object->get_phy_params().bands.table = &b;
372410
channel_params_t pp;
411+
memset(&pp, 0, sizeof(channel_params_t));
373412
pp.band=0;
374413
object->get_phy_params().channels.channel_list = &pp;
375-
uint32_t list = 0;
414+
uint32_t list[1];
415+
list[0] = 125000;
376416
object->get_phy_params().bandwidths.table = &list;
377-
uint8_t list2;
417+
uint8_t list2[1];
418+
list2[0] = 12;
378419
object->get_phy_params().datarates.table = &list2;
379420
my_radio radio;
380421
object->set_radio_instance(radio);
381422
tx_config_params_t p;
423+
memset(&p, 0, sizeof(tx_config_params_t));
382424
p.channel=0;
383-
int8_t i;
384-
lorawan_time_t t;
425+
int8_t i = 20;
426+
lorawan_time_t t = 36;
385427
object->tx_config(&p, &i, &t);
386428

387429
p.datarate = 8;
@@ -392,7 +434,9 @@ TEST_F(Test_LoRaPHY, tx_config)
392434
TEST_F(Test_LoRaPHY, link_ADR_request)
393435
{
394436
adr_req_params_t p;
437+
memset(&p, 0, sizeof(adr_req_params_t));
395438
uint8_t b[100];
439+
memset(b, 0, 100);
396440
p.payload = b;
397441
b[0] = 0x03;
398442
b[1] = 1;
@@ -411,16 +455,17 @@ TEST_F(Test_LoRaPHY, link_ADR_request)
411455
b[14] = 0;
412456
b[15] = 0;
413457
p.payload_size = 16;
414-
int8_t i, j;
415-
uint8_t k, l;
416-
uint8_t t[5];
458+
int8_t i = 0, j = 0;
459+
uint8_t k = 0, l = 0;
460+
uint8_t t[5] = {12, 11, 10, 9, 8};
417461
t[0] = 0;
418-
object->get_phy_params().datarates.size = 1;
462+
object->get_phy_params().datarates.size = 5;
419463
object->get_phy_params().datarates.table = t;
420464
//Test without ADR payload does not make sense here.
421465

422-
object->get_phy_params().max_channel_cnt = 2;
423-
channel_params_t li[4];
466+
object->get_phy_params().max_channel_cnt = 16;
467+
channel_params_t li[16];
468+
memset(li, 0, sizeof(channel_params_t)*16);
424469
object->get_phy_params().channels.channel_list = li;
425470
li[0].frequency = 0;
426471
li[1].frequency = 5;
@@ -430,7 +475,7 @@ TEST_F(Test_LoRaPHY, link_ADR_request)
430475
//verify adr with p.adr_enabled = false
431476
EXPECT_TRUE(0 == object->link_ADR_request(&p, &i, &j, &k, &l));
432477

433-
p.current_nb_rep = 0;
478+
p.current_nb_trans = 0;
434479
EXPECT_TRUE(0 == object->link_ADR_request(&p, &i, &j, &k, &l));
435480

436481
p.adr_enabled = true;
@@ -484,9 +529,19 @@ TEST_F(Test_LoRaPHY, link_ADR_request)
484529
TEST_F(Test_LoRaPHY, accept_rx_param_setup_req)
485530
{
486531
my_radio radio;
532+
radio.bool_value = true;
487533
object->set_radio_instance(radio);
488534
rx_param_setup_req_t req;
489-
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&req));
535+
req.datarate = DR_0;
536+
req.dr_offset = 0;
537+
req.frequency = 8678000;
538+
band_t band[1];
539+
memset(band, 0, sizeof(band_t));
540+
band[0].higher_band_freq = 8688000;
541+
band[0].lower_band_freq = 8666000;
542+
object->get_phy_params().bands.size = 1;
543+
object->get_phy_params().bands.table = band;
544+
EXPECT_TRUE(0x07 == object->accept_rx_param_setup_req(&req));
490545
}
491546

492547
TEST_F(Test_LoRaPHY, accept_tx_param_setup_req)
@@ -504,8 +559,14 @@ TEST_F(Test_LoRaPHY, dl_channel_request)
504559
object->get_phy_params().dl_channel_req_supported = true;
505560
object->get_phy_params().bands.size = 1;
506561
band_t t[1];
562+
memset(t, 0, sizeof(band_t));
563+
t[0].higher_band_freq = 8688000;
564+
t[0].lower_band_freq = 8668000;
565+
object->get_phy_params().bands.size = 1;
507566
object->get_phy_params().bands.table = t;
508-
channel_params_t p[4];
567+
channel_params_t p[16];
568+
memset(p, 0, sizeof(channel_params_t) * 16);
569+
object->get_phy_params().channels.channel_list_size = 16;
509570
object->get_phy_params().channels.channel_list = p;
510571

511572
p[0].frequency = 0;
@@ -533,15 +594,21 @@ TEST_F(Test_LoRaPHY, get_alternate_DR)
533594
TEST_F(Test_LoRaPHY, set_next_channel)
534595
{
535596
channel_selection_params_t p;
536-
uint8_t ch;
537-
lorawan_time_t t1;
538-
lorawan_time_t t2;
597+
memset(&p, 0, sizeof(channel_selection_params_t));
598+
band_t band[1];
599+
memset(band, 0, sizeof(band_t));
600+
band[0].higher_band_freq = 8687000;
601+
object->get_phy_params().bands.size = 1;
602+
object->get_phy_params().bands.table = band;
603+
uint8_t ch = 5;
604+
lorawan_time_t t1 = 16;
605+
lorawan_time_t t2 = 32;
539606
p.aggregate_timeoff = 10000;
540607
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&p, &ch, &t1, &t2));
541608

542609
uint16_t list[16];
610+
memset(list, 0, 16);
543611
list[4] = 1;
544-
memcpy(list, "\0", 16);
545612
object->get_phy_params().channels.mask = list;
546613
object->get_phy_params().channels.mask_size = 1;
547614
p.aggregate_timeoff = 10000;
@@ -553,6 +620,7 @@ TEST_F(Test_LoRaPHY, set_next_channel)
553620
p.joined = false;
554621
p.dc_enabled = false;
555622
band_t b[4];
623+
memset(b, 0, sizeof(band_t)*4);
556624
object->get_phy_params().bands.size = 2;
557625
object->get_phy_params().bands.table = &b;
558626
b[0].off_time = 0;

UNITTESTS/features/lorawan/lorawaninterface/Test_LoRaWANInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ TEST_F(Test_LoRaWANInterface, add_app_callbacks)
201201

202202
TEST_F(Test_LoRaWANInterface, set_device_class)
203203
{
204-
object->set_device_class(CLASS_A);
204+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_device_class(CLASS_A));
205205
}
206206

207207
TEST_F(Test_LoRaWANInterface, get_tx_metadata)

0 commit comments

Comments
 (0)