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_LoRaPHYAU915.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 "LoRaPHYAU915.h" 00020 00021 #include "LoRaPHY_stub.h" 00022 00023 class my_radio : public LoRaRadio 00024 { 00025 public: 00026 00027 virtual void init_radio(radio_events_t *events){}; 00028 00029 virtual void radio_reset(){}; 00030 00031 virtual void sleep(void){}; 00032 00033 virtual void standby(void){}; 00034 00035 virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth, 00036 uint32_t datarate, uint8_t coderate, 00037 uint32_t bandwidth_afc, uint16_t preamble_len, 00038 uint16_t symb_timeout, bool fix_len, 00039 uint8_t payload_len, 00040 bool crc_on, bool freq_hop_on, uint8_t hop_period, 00041 bool iq_inverted, bool rx_continuous){}; 00042 00043 virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev, 00044 uint32_t bandwidth, uint32_t datarate, 00045 uint8_t coderate, uint16_t preamble_len, 00046 bool fix_len, bool crc_on, bool freq_hop_on, 00047 uint8_t hop_period, bool iq_inverted, uint32_t timeout){}; 00048 00049 virtual void send(uint8_t *buffer, uint8_t size){}; 00050 00051 virtual void receive(void){}; 00052 00053 virtual void set_channel(uint32_t freq){}; 00054 00055 virtual uint32_t random(void){}; 00056 00057 virtual uint8_t get_status(void){return uint8_value;}; 00058 00059 virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){}; 00060 00061 virtual void set_public_network(bool enable){}; 00062 00063 virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){}; 00064 00065 virtual bool perform_carrier_sense(radio_modems_t modem, 00066 uint32_t freq, 00067 int16_t rssi_threshold, 00068 uint32_t max_carrier_sense_time){ return bool_value;}; 00069 00070 virtual void start_cad(void){}; 00071 00072 virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; }; 00073 00074 virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){}; 00075 00076 virtual void lock(void){}; 00077 00078 virtual void unlock(void){}; 00079 00080 bool bool_value; 00081 uint8_t uint8_value; 00082 }; 00083 00084 class Test_LoRaPHYAU915 : public testing::Test { 00085 protected: 00086 LoRaPHYAU915 *object; 00087 my_radio radio; 00088 00089 virtual void SetUp() 00090 { 00091 LoRaPHY_stub::radio = &radio; 00092 object = new LoRaPHYAU915(); 00093 } 00094 00095 virtual void TearDown() 00096 { 00097 LoRaPHY_stub::radio = NULL; 00098 delete object; 00099 } 00100 }; 00101 00102 TEST_F(Test_LoRaPHYAU915, constructor) 00103 { 00104 EXPECT_TRUE(object); 00105 } 00106 00107 TEST_F(Test_LoRaPHYAU915, rx_config) 00108 { 00109 rx_config_params_t p; 00110 00111 radio.uint8_value = 1; 00112 EXPECT_TRUE(!object->rx_config(&p)); 00113 00114 radio.uint8_value = 0; 00115 p.is_repeater_supported = true; 00116 EXPECT_TRUE(object->rx_config(&p)); 00117 00118 p.is_repeater_supported = false; 00119 EXPECT_TRUE(object->rx_config(&p)); 00120 } 00121 00122 TEST_F(Test_LoRaPHYAU915, tx_config) 00123 { 00124 tx_config_params_t p; 00125 int8_t tx; 00126 lorawan_time_t time; 00127 p.tx_power = 9; 00128 EXPECT_TRUE(object->tx_config(&p, &tx, &time)); 00129 } 00130 00131 TEST_F(Test_LoRaPHYAU915, link_ADR_request) 00132 { 00133 adr_req_params_t params; 00134 int8_t dr_out; 00135 int8_t tx_power_out; 00136 uint8_t nb_rep_out; 00137 uint8_t nb_bytes_parsed; 00138 00139 LoRaPHY_stub::uint8_value = 1; 00140 LoRaPHY_stub::ch_mask_value = 6; 00141 LoRaPHY_stub::adr_parse_count = 2; 00142 EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00143 00144 LoRaPHY_stub::adr_parse_count = 2; 00145 LoRaPHY_stub::ch_mask_value = 7; 00146 EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00147 00148 LoRaPHY_stub::adr_parse_count = 2; 00149 LoRaPHY_stub::ch_mask_value = 5; 00150 LoRaPHY_stub::uint8_value = 6; 00151 EXPECT_TRUE(6 == 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 = 66; 00155 LoRaPHY_stub::uint8_value = 7; 00156 EXPECT_TRUE(7 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00157 } 00158 00159 TEST_F(Test_LoRaPHYAU915, accept_rx_param_setup_req) 00160 { 00161 rx_param_setup_req_t p; 00162 radio.bool_value = false; 00163 EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p)); 00164 00165 radio.bool_value = true; 00166 p.frequency = 923300000 - 1; 00167 EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p)); 00168 00169 radio.bool_value = true; 00170 p.frequency = 927500000 + 1; 00171 p.datarate = 6; 00172 LoRaPHY_stub::bool_counter = 0; 00173 LoRaPHY_stub::bool_table[0] = true; 00174 EXPECT_TRUE(2 == object->accept_rx_param_setup_req(&p)); 00175 00176 radio.bool_value = true; 00177 p.frequency = 923300000 + 600000; 00178 LoRaPHY_stub::bool_counter = 0; 00179 LoRaPHY_stub::bool_table[0] = true; 00180 LoRaPHY_stub::bool_table[1] = true; 00181 EXPECT_TRUE(7 == object->accept_rx_param_setup_req(&p)); 00182 } 00183 00184 TEST_F(Test_LoRaPHYAU915, get_alternate_DR) 00185 { 00186 EXPECT_TRUE(0 == object->get_alternate_DR(0)); 00187 00188 EXPECT_TRUE(6 == object->get_alternate_DR(1)); 00189 } 00190 00191 TEST_F(Test_LoRaPHYAU915, set_next_channel) 00192 { 00193 channel_selection_params_t params; 00194 uint8_t channel; 00195 lorawan_time_t time; 00196 lorawan_time_t timeoff; 00197 00198 params.current_datarate = 6; 00199 params.aggregate_timeoff = 0; 00200 LoRaPHY_stub::uint8_value = 0; 00201 EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(¶ms, &channel, &time, &timeoff)); 00202 00203 radio.bool_value = false; 00204 params.aggregate_timeoff = 1; 00205 EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(¶ms, &channel, &time, &timeoff)); 00206 00207 params.aggregate_timeoff = 0; 00208 LoRaPHY_stub::uint8_value = 1; 00209 EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(¶ms, &channel, &time, &timeoff)); 00210 } 00211 00212 TEST_F(Test_LoRaPHYAU915, apply_DR_offset) 00213 { 00214 // { DR_8, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_0 00215 // { DR_9, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_1 00216 // { DR_10, DR_9, DR_8, DR_8, DR_8, DR_8 }, // DR_2 00217 // { DR_11, DR_10, DR_9, DR_8, DR_8, DR_8 }, // DR_3 00218 // { DR_12, DR_11, DR_10, DR_9, DR_8, DR_8 }, // DR_4 00219 // { DR_13, DR_12, DR_11, DR_10, DR_9, DR_8 }, // DR_5 00220 // { DR_13, DR_13, DR_12, DR_11, DR_10, DR_9 }, // DR_6 00221 00222 for (int i = 0; i < 7; i++) { 00223 for (int j=0; j < 6; j++ ) { 00224 uint8_t val = 8 + i; 00225 val -= j; 00226 if (val > 13) val = 13; 00227 if (val < 8) val = 8; 00228 EXPECT_TRUE(val == object->apply_DR_offset(i, j)); 00229 } 00230 } 00231 }
Generated on Tue Aug 9 2022 00:37:22 by
1.7.2