takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Test_LoRaPHYKR920.cpp Source File

Test_LoRaPHYKR920.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 "LoRaPHYKR920.h"
00020 #include "LoRaPHY_stub.h"
00021 #include "LoRaRadio.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){};
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 };
00082 
00083 class Test_LoRaPHYKR920 : public testing::Test {
00084 protected:
00085     LoRaPHYKR920 *object;
00086     my_radio radio;
00087 
00088     virtual void SetUp()
00089     {
00090         LoRaPHY_stub::radio = &radio;
00091         object = new LoRaPHYKR920();
00092     }
00093 
00094     virtual void TearDown()
00095     {
00096         LoRaPHY_stub::radio = NULL;
00097         delete object;
00098     }
00099 };
00100 
00101 TEST_F(Test_LoRaPHYKR920, constructor)
00102 {
00103     EXPECT_TRUE(object);
00104 }
00105 
00106 TEST_F(Test_LoRaPHYKR920, verify_frequency_for_band)
00107 {
00108     radio.bool_value = false;
00109     EXPECT_TRUE(false == object->verify_frequency_for_band(0, 0));
00110 
00111     radio.bool_value = true;
00112     EXPECT_TRUE(false == object->verify_frequency_for_band(0, 0));
00113 
00114     EXPECT_TRUE(true == object->verify_frequency_for_band(921100000, 0));
00115 }
00116 
00117 TEST_F(Test_LoRaPHYKR920, tx_config)
00118 {
00119     tx_config_params_t tx_config;
00120     int8_t tx_power = 0;
00121     lorawan_time_t time;
00122 
00123     tx_config.tx_power = 9;
00124     EXPECT_TRUE(true == object->tx_config(&tx_config, &tx_power, &time));
00125 }
00126 
00127 TEST_F(Test_LoRaPHYKR920, set_next_channel)
00128 {
00129     channel_selection_params_t next_channel;
00130     lorawan_time_t backoff_time = 0;
00131     lorawan_time_t time = 0;
00132     uint8_t ch = 1;
00133 
00134     next_channel.aggregate_timeoff = 0;
00135     LoRaPHY_stub::uint8_value = 0;
00136     EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
00137 
00138     next_channel.aggregate_timeoff = 1;
00139     radio.bool_value = false;
00140     EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
00141 
00142     next_channel.aggregate_timeoff = 0;
00143     LoRaPHY_stub::uint8_value = 1;
00144     EXPECT_TRUE(LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
00145 
00146     radio.bool_value = true;
00147     EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
00148 }
00149 
00150 TEST_F(Test_LoRaPHYKR920, set_tx_cont_mode)
00151 {
00152     cw_mode_params_t  params;
00153     params.tx_power  = 9;
00154     object->set_tx_cont_mode(&params, 0);
00155 }
00156