Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Test_LoRaPHYUS915.cpp
00001 /* 00002 * Copyright (c) 2018, Arm Limited and affiliates 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "gtest/gtest.h" 00019 #include "LoRaPHYUS915.h" 00020 #include "LoRaPHY_stub.h" 00021 00022 class my_radio : public LoRaRadio 00023 { 00024 public: 00025 00026 virtual void init_radio(radio_events_t *events){}; 00027 00028 virtual void radio_reset(){}; 00029 00030 virtual void sleep(void){}; 00031 00032 virtual void standby(void){}; 00033 00034 virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth, 00035 uint32_t datarate, uint8_t coderate, 00036 uint32_t bandwidth_afc, uint16_t preamble_len, 00037 uint16_t symb_timeout, bool fix_len, 00038 uint8_t payload_len, 00039 bool crc_on, bool freq_hop_on, uint8_t hop_period, 00040 bool iq_inverted, bool rx_continuous){}; 00041 00042 virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev, 00043 uint32_t bandwidth, uint32_t datarate, 00044 uint8_t coderate, uint16_t preamble_len, 00045 bool fix_len, bool crc_on, bool freq_hop_on, 00046 uint8_t hop_period, bool iq_inverted, uint32_t timeout){}; 00047 00048 virtual void send(uint8_t *buffer, uint8_t size){}; 00049 00050 virtual void receive(void){}; 00051 00052 virtual void set_channel(uint32_t freq){}; 00053 00054 virtual uint32_t random(void){}; 00055 00056 virtual uint8_t get_status(void){return uint8_value;}; 00057 00058 virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){}; 00059 00060 virtual void set_public_network(bool enable){}; 00061 00062 virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){}; 00063 00064 virtual bool perform_carrier_sense(radio_modems_t modem, 00065 uint32_t freq, 00066 int16_t rssi_threshold, 00067 uint32_t max_carrier_sense_time){ return bool_value;}; 00068 00069 virtual void start_cad(void){}; 00070 00071 virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; }; 00072 00073 virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){}; 00074 00075 virtual void lock(void){}; 00076 00077 virtual void unlock(void){}; 00078 00079 bool bool_value; 00080 uint8_t uint8_value; 00081 }; 00082 00083 class Test_LoRaPHYUS915 : public testing::Test { 00084 protected: 00085 LoRaPHYUS915 *object; 00086 my_radio radio; 00087 00088 virtual void SetUp() 00089 { 00090 LoRaPHY_stub::radio = &radio; 00091 object = new LoRaPHYUS915(); 00092 } 00093 00094 virtual void TearDown() 00095 { 00096 LoRaPHY_stub::radio = NULL; 00097 delete object; 00098 } 00099 }; 00100 00101 TEST_F(Test_LoRaPHYUS915, constructor) 00102 { 00103 EXPECT_TRUE(object); 00104 } 00105 00106 TEST_F(Test_LoRaPHYUS915, restore_default_channels) 00107 { 00108 object->restore_default_channels(); 00109 } 00110 00111 TEST_F(Test_LoRaPHYUS915, rx_config) 00112 { 00113 rx_config_params_t p; 00114 00115 radio.uint8_value = 1; 00116 EXPECT_TRUE(!object->rx_config(&p)); 00117 00118 radio.uint8_value = 0; 00119 p.is_repeater_supported = true; 00120 EXPECT_TRUE(object->rx_config(&p)); 00121 00122 p.is_repeater_supported = false; 00123 EXPECT_TRUE(object->rx_config(&p)); 00124 } 00125 00126 TEST_F(Test_LoRaPHYUS915, tx_config) 00127 { 00128 tx_config_params_t p; 00129 int8_t tx; 00130 lorawan_time_t time; 00131 EXPECT_TRUE(object->tx_config(&p, &tx, &time)); 00132 } 00133 00134 TEST_F(Test_LoRaPHYUS915, link_ADR_request) 00135 { 00136 adr_req_params_t params; 00137 int8_t dr_out; 00138 int8_t tx_power_out; 00139 uint8_t nb_rep_out; 00140 uint8_t nb_bytes_parsed; 00141 00142 EXPECT_TRUE(0 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00143 00144 LoRaPHY_stub::uint8_value = 1; 00145 LoRaPHY_stub::ch_mask_value = 6; 00146 LoRaPHY_stub::adr_parse_count = 2; 00147 EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00148 00149 LoRaPHY_stub::adr_parse_count = 2; 00150 LoRaPHY_stub::ch_mask_value = 7; 00151 EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00152 00153 LoRaPHY_stub::adr_parse_count = 2; 00154 LoRaPHY_stub::ch_mask_value = 5; 00155 LoRaPHY_stub::uint8_value = 6; 00156 EXPECT_TRUE(6 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00157 00158 LoRaPHY_stub::adr_parse_count = 2; 00159 LoRaPHY_stub::ch_mask_value = 66; 00160 LoRaPHY_stub::uint8_value = 7; 00161 EXPECT_TRUE(7 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00162 } 00163 00164 TEST_F(Test_LoRaPHYUS915, accept_rx_param_setup_req) 00165 { 00166 rx_param_setup_req_t p; 00167 EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p)); 00168 00169 radio.bool_value = true; 00170 p.frequency = 923300000 - 1; 00171 EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p)); 00172 00173 radio.bool_value = true; 00174 p.frequency = 927500000 + 1; 00175 p.datarate = 6; 00176 LoRaPHY_stub::bool_counter = 0; 00177 LoRaPHY_stub::bool_table[0] = true; 00178 EXPECT_TRUE(2 == object->accept_rx_param_setup_req(&p)); 00179 } 00180 00181 TEST_F(Test_LoRaPHYUS915, get_alternate_DR) 00182 { 00183 EXPECT_TRUE(0 == object->get_alternate_DR(0)); 00184 00185 EXPECT_TRUE(4 == object->get_alternate_DR(1)); 00186 } 00187 00188 TEST_F(Test_LoRaPHYUS915, set_next_channel) 00189 { 00190 channel_selection_params_t params; 00191 uint8_t channel; 00192 lorawan_time_t time; 00193 lorawan_time_t timeoff; 00194 00195 params.current_datarate = 4; 00196 params.aggregate_timeoff = 0; 00197 LoRaPHY_stub::uint8_value = 0; 00198 EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(¶ms, &channel, &time, &timeoff)); 00199 00200 radio.bool_value = false; 00201 params.aggregate_timeoff = 1; 00202 EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(¶ms, &channel, &time, &timeoff)); 00203 00204 params.aggregate_timeoff = 0; 00205 LoRaPHY_stub::uint8_value = 1; 00206 EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(¶ms, &channel, &time, &timeoff)); 00207 } 00208 00209 TEST_F(Test_LoRaPHYUS915, apply_DR_offset) 00210 { 00211 //10, 9, 8, 8 00212 //11, 10, 9, 8 00213 //12, 11, 10, 9 00214 //13, 12, 11, 10 00215 //13, 13, 12, 11 00216 00217 for (int i = 0; i < 5; i++) { 00218 for (int j=0; j < 4; j++ ) { 00219 uint8_t val = 10 + i; 00220 val -= j; 00221 if (val > 13) val = 13; 00222 if (val < 8) val = 8; 00223 EXPECT_TRUE(val == object->apply_DR_offset(i, j)); 00224 } 00225 } 00226 } 00227 00228 TEST_F(Test_LoRaPHYUS915, set_tx_cont_mode) 00229 { 00230 cw_mode_params_t p; 00231 object->set_tx_cont_mode(&p, 0); 00232 00233 p.datarate = 4; 00234 object->set_tx_cont_mode(&p, 0); 00235 }
Generated on Tue Aug 9 2022 00:37:22 by
1.7.2