Skip to content

Commit 07d2ce6

Browse files
Antti Kauppilaadbridge
authored andcommitted
LoRa regions unittested, stubs licences revisited
1 parent 323ea12 commit 07d2ce6

File tree

62 files changed

+1073
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1073
-287
lines changed

UNITTESTS/features/lorawan/loraphyas923/Test_LoRaPHYAS923.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,83 @@
1818
#include "gtest/gtest.h"
1919
#include "LoRaPHYAS923.h"
2020

21+
#include "LoRaPHY_stub.h"
22+
23+
class my_radio : public LoRaRadio
24+
{
25+
public:
26+
27+
virtual void init_radio(radio_events_t *events){};
28+
29+
virtual void radio_reset(){};
30+
31+
virtual void sleep(void){};
32+
33+
virtual void standby(void){};
34+
35+
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
36+
uint32_t datarate, uint8_t coderate,
37+
uint32_t bandwidth_afc, uint16_t preamble_len,
38+
uint16_t symb_timeout, bool fix_len,
39+
uint8_t payload_len,
40+
bool crc_on, bool freq_hop_on, uint8_t hop_period,
41+
bool iq_inverted, bool rx_continuous){};
42+
43+
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
44+
uint32_t bandwidth, uint32_t datarate,
45+
uint8_t coderate, uint16_t preamble_len,
46+
bool fix_len, bool crc_on, bool freq_hop_on,
47+
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
48+
49+
virtual void send(uint8_t *buffer, uint8_t size){};
50+
51+
virtual void receive(void){};
52+
53+
virtual void set_channel(uint32_t freq){};
54+
55+
virtual uint32_t random(void){};
56+
57+
virtual uint8_t get_status(void){return uint8_value;};
58+
59+
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
60+
61+
virtual void set_public_network(bool enable){};
62+
63+
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
64+
65+
virtual bool perform_carrier_sense(radio_modems_t modem,
66+
uint32_t freq,
67+
int16_t rssi_threshold,
68+
uint32_t max_carrier_sense_time){ return bool_value;};
69+
70+
virtual void start_cad(void){};
71+
72+
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
73+
74+
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
75+
76+
virtual void lock(void){};
77+
78+
virtual void unlock(void){};
79+
80+
bool bool_value;
81+
uint8_t uint8_value;
82+
};
83+
2184
class Test_LoRaPHYAS923 : public testing::Test {
2285
protected:
2386
LoRaPHYAS923 *object;
87+
my_radio radio;
2488

2589
virtual void SetUp()
2690
{
91+
LoRaPHY_stub::radio = &radio;
2792
object = new LoRaPHYAS923();
2893
}
2994

3095
virtual void TearDown()
3196
{
97+
LoRaPHY_stub::radio = NULL;
3298
delete object;
3399
}
34100
};
@@ -38,3 +104,40 @@ TEST_F(Test_LoRaPHYAS923, constructor)
38104
EXPECT_TRUE(object);
39105
}
40106

107+
TEST_F(Test_LoRaPHYAS923, get_alternate_DR)
108+
{
109+
EXPECT_TRUE(2 == object->get_alternate_DR(1));
110+
}
111+
112+
TEST_F(Test_LoRaPHYAS923, set_next_channel)
113+
{
114+
channel_selection_params_t next_channel;
115+
lorawan_time_t backoff_time = 0;
116+
lorawan_time_t time = 0;
117+
uint8_t ch = 1;
118+
119+
next_channel.aggregate_timeoff = 0;
120+
LoRaPHY_stub::uint8_value = 0;
121+
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
122+
123+
next_channel.aggregate_timeoff = 1;
124+
radio.bool_value = false;
125+
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
126+
127+
next_channel.aggregate_timeoff = 0;
128+
LoRaPHY_stub::uint8_value = 1;
129+
EXPECT_TRUE(LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
130+
131+
radio.bool_value = true;
132+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
133+
}
134+
135+
TEST_F(Test_LoRaPHYAS923, apply_DR_offset)
136+
{
137+
//0, 1, 2, 3, 4, 5, -1, -2
138+
for (int i=0; i < 8; i++) {
139+
uint8_t val = i>5?5:2;
140+
EXPECT_TRUE(object->apply_DR_offset(0, i));
141+
}
142+
}
143+

UNITTESTS/features/lorawan/loraphyau915/Test_LoRaPHYAU915.cpp

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,83 @@
1818
#include "gtest/gtest.h"
1919
#include "LoRaPHYAU915.h"
2020

21+
#include "LoRaPHY_stub.h"
22+
23+
class my_radio : public LoRaRadio
24+
{
25+
public:
26+
27+
virtual void init_radio(radio_events_t *events){};
28+
29+
virtual void radio_reset(){};
30+
31+
virtual void sleep(void){};
32+
33+
virtual void standby(void){};
34+
35+
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
36+
uint32_t datarate, uint8_t coderate,
37+
uint32_t bandwidth_afc, uint16_t preamble_len,
38+
uint16_t symb_timeout, bool fix_len,
39+
uint8_t payload_len,
40+
bool crc_on, bool freq_hop_on, uint8_t hop_period,
41+
bool iq_inverted, bool rx_continuous){};
42+
43+
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
44+
uint32_t bandwidth, uint32_t datarate,
45+
uint8_t coderate, uint16_t preamble_len,
46+
bool fix_len, bool crc_on, bool freq_hop_on,
47+
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
48+
49+
virtual void send(uint8_t *buffer, uint8_t size){};
50+
51+
virtual void receive(void){};
52+
53+
virtual void set_channel(uint32_t freq){};
54+
55+
virtual uint32_t random(void){};
56+
57+
virtual uint8_t get_status(void){return uint8_value;};
58+
59+
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
60+
61+
virtual void set_public_network(bool enable){};
62+
63+
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
64+
65+
virtual bool perform_carrier_sense(radio_modems_t modem,
66+
uint32_t freq,
67+
int16_t rssi_threshold,
68+
uint32_t max_carrier_sense_time){ return bool_value;};
69+
70+
virtual void start_cad(void){};
71+
72+
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
73+
74+
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
75+
76+
virtual void lock(void){};
77+
78+
virtual void unlock(void){};
79+
80+
bool bool_value;
81+
uint8_t uint8_value;
82+
};
83+
2184
class Test_LoRaPHYAU915 : public testing::Test {
2285
protected:
2386
LoRaPHYAU915 *object;
87+
my_radio radio;
2488

2589
virtual void SetUp()
2690
{
91+
LoRaPHY_stub::radio = &radio;
2792
object = new LoRaPHYAU915();
2893
}
2994

3095
virtual void TearDown()
3196
{
97+
LoRaPHY_stub::radio = NULL;
3298
delete object;
3399
}
34100
};
@@ -38,3 +104,129 @@ TEST_F(Test_LoRaPHYAU915, constructor)
38104
EXPECT_TRUE(object);
39105
}
40106

107+
TEST_F(Test_LoRaPHYAU915, rx_config)
108+
{
109+
rx_config_params_t p;
110+
111+
radio.uint8_value = 1;
112+
EXPECT_TRUE(!object->rx_config(&p));
113+
114+
radio.uint8_value = 0;
115+
p.is_repeater_supported = true;
116+
EXPECT_TRUE(object->rx_config(&p));
117+
118+
p.is_repeater_supported = false;
119+
EXPECT_TRUE(object->rx_config(&p));
120+
}
121+
122+
TEST_F(Test_LoRaPHYAU915, tx_config)
123+
{
124+
tx_config_params_t p;
125+
int8_t tx;
126+
lorawan_time_t time;
127+
p.tx_power = 9;
128+
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
129+
}
130+
131+
TEST_F(Test_LoRaPHYAU915, link_ADR_request)
132+
{
133+
adr_req_params_t params;
134+
int8_t dr_out;
135+
int8_t tx_power_out;
136+
uint8_t nb_rep_out;
137+
uint8_t nb_bytes_parsed;
138+
139+
LoRaPHY_stub::uint8_value = 1;
140+
LoRaPHY_stub::ch_mask_value = 6;
141+
LoRaPHY_stub::adr_parse_count = 2;
142+
EXPECT_TRUE(1 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
143+
144+
LoRaPHY_stub::adr_parse_count = 2;
145+
LoRaPHY_stub::ch_mask_value = 7;
146+
EXPECT_TRUE(1 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
147+
148+
LoRaPHY_stub::adr_parse_count = 2;
149+
LoRaPHY_stub::ch_mask_value = 5;
150+
LoRaPHY_stub::uint8_value = 6;
151+
EXPECT_TRUE(6 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
152+
153+
LoRaPHY_stub::adr_parse_count = 2;
154+
LoRaPHY_stub::ch_mask_value = 66;
155+
LoRaPHY_stub::uint8_value = 7;
156+
EXPECT_TRUE(7 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
157+
}
158+
159+
TEST_F(Test_LoRaPHYAU915, accept_rx_param_setup_req)
160+
{
161+
rx_param_setup_req_t p;
162+
radio.bool_value = false;
163+
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
164+
165+
radio.bool_value = true;
166+
p.frequency = 923300000 - 1;
167+
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
168+
169+
radio.bool_value = true;
170+
p.frequency = 927500000 + 1;
171+
p.datarate = 6;
172+
LoRaPHY_stub::bool_counter = 0;
173+
LoRaPHY_stub::bool_table[0] = true;
174+
EXPECT_TRUE(2 == object->accept_rx_param_setup_req(&p));
175+
176+
radio.bool_value = true;
177+
p.frequency = 923300000 + 600000;
178+
LoRaPHY_stub::bool_counter = 0;
179+
LoRaPHY_stub::bool_table[0] = true;
180+
LoRaPHY_stub::bool_table[1] = true;
181+
EXPECT_TRUE(7 == object->accept_rx_param_setup_req(&p));
182+
}
183+
184+
TEST_F(Test_LoRaPHYAU915, get_alternate_DR)
185+
{
186+
EXPECT_TRUE(0 == object->get_alternate_DR(0));
187+
188+
EXPECT_TRUE(6 == object->get_alternate_DR(1));
189+
}
190+
191+
TEST_F(Test_LoRaPHYAU915, set_next_channel)
192+
{
193+
channel_selection_params_t params;
194+
uint8_t channel;
195+
lorawan_time_t time;
196+
lorawan_time_t timeoff;
197+
198+
params.current_datarate = 6;
199+
params.aggregate_timeoff = 0;
200+
LoRaPHY_stub::uint8_value = 0;
201+
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&params, &channel, &time, &timeoff));
202+
203+
radio.bool_value = false;
204+
params.aggregate_timeoff = 1;
205+
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&params, &channel, &time, &timeoff));
206+
207+
params.aggregate_timeoff = 0;
208+
LoRaPHY_stub::uint8_value = 1;
209+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&params, &channel, &time, &timeoff));
210+
}
211+
212+
TEST_F(Test_LoRaPHYAU915, apply_DR_offset)
213+
{
214+
// { DR_8, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_0
215+
// { DR_9, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_1
216+
// { DR_10, DR_9, DR_8, DR_8, DR_8, DR_8 }, // DR_2
217+
// { DR_11, DR_10, DR_9, DR_8, DR_8, DR_8 }, // DR_3
218+
// { DR_12, DR_11, DR_10, DR_9, DR_8, DR_8 }, // DR_4
219+
// { DR_13, DR_12, DR_11, DR_10, DR_9, DR_8 }, // DR_5
220+
// { DR_13, DR_13, DR_12, DR_11, DR_10, DR_9 }, // DR_6
221+
222+
for (int i = 0; i < 7; i++) {
223+
for (int j=0; j < 6; j++ ) {
224+
uint8_t val = 8 + i;
225+
val -= j;
226+
if (val > 13) val = 13;
227+
if (val < 8) val = 8;
228+
EXPECT_TRUE(val == object->apply_DR_offset(i, j));
229+
}
230+
}
231+
}
232+

0 commit comments

Comments
 (0)