takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Test_LoRaPHYAS923.cpp Source File

Test_LoRaPHYAS923.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 "LoRaPHYAS923.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_LoRaPHYAS923 : public testing::Test {
00085 protected:
00086     LoRaPHYAS923 *object;
00087     my_radio radio;
00088 
00089     virtual void SetUp()
00090     {
00091         LoRaPHY_stub::radio = &radio;
00092         object = new LoRaPHYAS923();
00093     }
00094 
00095     virtual void TearDown()
00096     {
00097         LoRaPHY_stub::radio = NULL;
00098         delete object;
00099     }
00100 };
00101 
00102 TEST_F(Test_LoRaPHYAS923, constructor)
00103 {
00104     EXPECT_TRUE(object);
00105 }
00106 
00107 TEST_F(Test_LoRaPHYAS923, get_alternate_DR)
00108 {
00109     EXPECT_TRUE(2 == object->get_alternate_DR(1));
00110 }
00111 
00112 TEST_F(Test_LoRaPHYAS923, set_next_channel)
00113 {
00114     channel_selection_params_t next_channel;
00115     lorawan_time_t backoff_time = 0;
00116     lorawan_time_t time = 0;
00117     uint8_t ch = 1;
00118 
00119     next_channel.aggregate_timeoff = 0;
00120     LoRaPHY_stub::uint8_value = 0;
00121     EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
00122 
00123     next_channel.aggregate_timeoff = 1;
00124     radio.bool_value = false;
00125     EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
00126 
00127     next_channel.aggregate_timeoff = 0;
00128     LoRaPHY_stub::uint8_value = 1;
00129     EXPECT_TRUE(LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
00130 
00131     radio.bool_value = true;
00132     EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
00133 }
00134 
00135 TEST_F(Test_LoRaPHYAS923, apply_DR_offset)
00136 {
00137     //0, 1, 2, 3, 4, 5, -1, -2
00138     for (int i=0; i < 8; i++) {
00139         uint8_t val = i>5?5:2;
00140         EXPECT_TRUE(object->apply_DR_offset(0, i));
00141     }
00142 }
00143