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_LoRaPHYCN470.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 "LoRaPHYCN470.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_LoRaPHYCN470 : public testing::Test { 00085 protected: 00086 LoRaPHYCN470 *object; 00087 my_radio radio; 00088 00089 virtual void SetUp() 00090 { 00091 00092 LoRaPHY_stub::radio = &radio; 00093 object = new LoRaPHYCN470(); 00094 } 00095 00096 virtual void TearDown() 00097 { 00098 00099 LoRaPHY_stub::radio = NULL; 00100 delete object; 00101 } 00102 }; 00103 00104 TEST_F(Test_LoRaPHYCN470, constructor) 00105 { 00106 EXPECT_TRUE(object); 00107 } 00108 00109 TEST_F(Test_LoRaPHYCN470, set_next_channel) 00110 { 00111 channel_selection_params_t params; 00112 uint8_t channel; 00113 lorawan_time_t time; 00114 lorawan_time_t timeoff; 00115 00116 params.current_datarate = 4; 00117 params.aggregate_timeoff = 0; 00118 LoRaPHY_stub::uint8_value = 0; 00119 EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(¶ms, &channel, &time, &timeoff)); 00120 00121 radio.bool_value = false; 00122 params.aggregate_timeoff = 1; 00123 EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(¶ms, &channel, &time, &timeoff)); 00124 00125 params.aggregate_timeoff = 0; 00126 LoRaPHY_stub::uint8_value = 1; 00127 EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(¶ms, &channel, &time, &timeoff)); 00128 } 00129 00130 TEST_F(Test_LoRaPHYCN470, rx_config) 00131 { 00132 rx_config_params_t p; 00133 00134 radio.uint8_value = 1; 00135 EXPECT_TRUE(!object->rx_config(&p)); 00136 00137 radio.uint8_value = 0; 00138 p.is_repeater_supported = true; 00139 EXPECT_TRUE(object->rx_config(&p)); 00140 00141 p.is_repeater_supported = false; 00142 EXPECT_TRUE(object->rx_config(&p)); 00143 } 00144 00145 TEST_F(Test_LoRaPHYCN470, tx_config) 00146 { 00147 tx_config_params_t p; 00148 int8_t tx; 00149 lorawan_time_t time; 00150 p.tx_power = 9; 00151 EXPECT_TRUE(object->tx_config(&p, &tx, &time)); 00152 } 00153 00154 TEST_F(Test_LoRaPHYCN470, link_ADR_request) 00155 { 00156 adr_req_params_t params; 00157 int8_t dr_out; 00158 int8_t tx_power_out; 00159 uint8_t nb_rep_out; 00160 uint8_t nb_bytes_parsed; 00161 00162 LoRaPHY_stub::uint8_value = 1; 00163 LoRaPHY_stub::ch_mask_value = 6; 00164 LoRaPHY_stub::adr_parse_count = 2; 00165 EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00166 00167 LoRaPHY_stub::adr_parse_count = 2; 00168 LoRaPHY_stub::ch_mask_value = 7; 00169 EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00170 00171 LoRaPHY_stub::adr_parse_count = 2; 00172 LoRaPHY_stub::ch_mask_value = 5; 00173 LoRaPHY_stub::uint8_value = 6; 00174 EXPECT_TRUE(6 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00175 00176 LoRaPHY_stub::adr_parse_count = 2; 00177 LoRaPHY_stub::ch_mask_value = 66; 00178 LoRaPHY_stub::uint8_value = 7; 00179 EXPECT_TRUE(7 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed)); 00180 } 00181 00182 TEST_F(Test_LoRaPHYCN470, accept_rx_param_setup_req) 00183 { 00184 rx_param_setup_req_t p; 00185 EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p)); 00186 00187 radio.bool_value = true; 00188 p.frequency = 923300000 - 1; 00189 EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p)); 00190 00191 radio.bool_value = true; 00192 p.frequency = 927500000 + 1; 00193 p.datarate = 6; 00194 LoRaPHY_stub::bool_counter = 0; 00195 LoRaPHY_stub::bool_table[0] = true; 00196 EXPECT_TRUE(2 == object->accept_rx_param_setup_req(&p)); 00197 } 00198 00199
Generated on Tue Aug 9 2022 00:37:22 by
1.7.2