Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LoRaPHY.h Source File

LoRaPHY.h

Go to the documentation of this file.
00001 /**
00002  *  @file LoRaPHY.h
00003  *
00004  *  @brief An abstract class providing radio object to children and
00005  *         provide base for implementing LoRa PHY layer
00006  *
00007  *  \code
00008  *   ______                              _
00009  *  / _____)             _              | |
00010  * ( (____  _____ ____ _| |_ _____  ____| |__
00011  *  \____ \| ___ |    (_   _) ___ |/ ___)  _ \
00012  *  _____) ) ____| | | || |_| ____( (___| | | |
00013  * (______/|_____)_|_|_| \__)_____)\____)_| |_|
00014  *   (C)2013 Semtech
00015  *  ___ _____ _   ___ _  _____ ___  ___  ___ ___
00016  * / __|_   _/_\ / __| |/ / __/ _ \| _ \/ __| __|
00017  * \__ \ | |/ _ \ (__| ' <| _| (_) |   / (__| _|
00018  * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
00019  * embedded.connectivity.solutions===============
00020  *
00021  * \endcode
00022  *
00023  * Description: LoRa PHY layer
00024  *
00025  * License: Revised BSD License, see LICENSE.TXT file include in the project
00026  *
00027  * Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jaeckle ( STACKFORCE )
00028  *
00029  * Copyright (c) 2017, Arm Limited and affiliates.
00030  * SPDX-License-Identifier: BSD-3-Clause
00031  *
00032  */
00033 
00034 #ifndef MBED_OS_LORAPHY_BASE_
00035 #define MBED_OS_LORAPHY_BASE_
00036 
00037 #include "platform/NonCopyable.h"
00038 
00039 #include "system/LoRaWANTimer.h"
00040 #include "LoRaRadio.h"
00041 #include "lora_phy_ds.h"
00042 
00043 /** LoRaPHY Class
00044  * Parent class for LoRa regional PHY implementations
00045  */
00046 class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
00047 
00048 public:
00049     virtual ~LoRaPHY();
00050 
00051     /** Initialize LoRaPHY
00052      *
00053      *  LoRaMac calls this to initialize LoRaPHY.
00054      *
00055      * @param lora_time a pointer to LoRaWANTimeHandler object
00056      */
00057     void initialize(LoRaWANTimeHandler *lora_time);
00058 
00059     /** Stores a reference to Radio object.
00060      *
00061      * Application is responsible for constructing a 'LoRaRadio' object
00062      * which is passed down to the PHY layer.
00063      *
00064      * @param radio    a reference to radio driver object
00065      */
00066     void set_radio_instance(LoRaRadio &radio);
00067 
00068     /** Puts radio in sleep mode.
00069      *
00070      * Requests the radio driver to enter sleep mode.
00071      */
00072     void put_radio_to_sleep(void);
00073 
00074     /** Puts radio in standby mode.
00075      *
00076      * Requests the radio driver to enter standby mode.
00077      */
00078     void put_radio_to_standby(void);
00079 
00080     /** Puts radio in receive mode.
00081      *
00082      * Requests the radio driver to enter receive mode.
00083      */
00084     void handle_receive(void);
00085 
00086     /** Delegates MAC layer request to transmit packet.
00087      *
00088      * @param buf    a pointer to the data which needs to be transmitted
00089      *
00090      * @param size   size of the data in bytes
00091      */
00092     void handle_send(uint8_t *buf, uint8_t size);
00093 
00094     /** Enables/Disables public network mode.
00095      *
00096      * Public and private LoRaWAN network constitute different preambles and
00097      * Net IDs. This API isused to tell the radio which network mode is in use.
00098      *
00099      * @param set    true or false
00100      */
00101     void setup_public_network_mode(bool set);
00102 
00103     /** Provides a random number from radio.
00104      *
00105      * Returns a 32-bit random unsigned integer value based upon RSSI
00106      * measurements.
00107      *
00108      * @return    a 32-bit long random number
00109      *
00110      */
00111     uint32_t get_radio_rng();
00112 
00113     /**
00114      * @brief calculate_backoff Calculates and applies duty cycle back-off time.
00115      *                          Explicitly updates the band time-off.
00116      *
00117      * @param joined                Set to true, if the node has already joined a network, otherwise false.
00118      * @param last_tx_was_join_req  Set to true, if the last uplink was a join request.
00119      * @param dc_enabled            Set to true, if the duty cycle is enabled, otherwise false.
00120      * @param channel               The current channel index.
00121      * @param elapsed_time          Elapsed time since the start of the node.
00122      * @param tx_toa                Time-on-air of the last transmission.
00123      */
00124     void calculate_backoff(bool joined, bool last_tx_was_join_req, bool dc_enabled, uint8_t channel,
00125                            lorawan_time_t elapsed_time, lorawan_time_t tx_toa);
00126 
00127     /**
00128       * Tests if a channel is on or off in the channel mask
00129       */
00130     bool mask_bit_test(const uint16_t *mask, unsigned bit);
00131 
00132     /**
00133       * Tests if a channel is on or off in the channel mask
00134       */
00135     void mask_bit_set(uint16_t *mask, unsigned bit);
00136 
00137     /**
00138       * Tests if a channel is on or off in the channel mask
00139       */
00140     void mask_bit_clear(uint16_t *mask, unsigned bit);
00141 
00142     /** Entertain a new channel request MAC command.
00143      *
00144      * MAC command subsystem processes the new channel request coming form
00145      * the network server and then MAC layer asks the PHY layer to entertain
00146      * the request.
00147      *
00148      * @param channel_id The channel ID.
00149      * @param new_channel A pointer to the new channel's parameters.
00150      *
00151      * @return bit mask, according to the LoRaWAN spec 1.0.2.
00152      */
00153     virtual uint8_t request_new_channel(int8_t channel_id, channel_params_t *new_channel);
00154 
00155     /** Process PHY layer state after a successful transmission.
00156      * @brief set_last_tx_done Updates times of the last transmission for the particular channel and
00157      *                         band upon which last transmission took place.
00158      * @param channel The channel in use.
00159      * @param joined Boolean telling if node has joined the network.
00160      * @param last_tx_done_time The last TX done time.
00161      */
00162     virtual void set_last_tx_done(uint8_t channel, bool joined, lorawan_time_t last_tx_done_time);
00163 
00164     /** Enables default channels only.
00165      *
00166      * Falls back to a channel mask where only default channels are enabled, all
00167      * other channels are disabled.
00168      */
00169     virtual void restore_default_channels();
00170 
00171     /** Processes the incoming CF-list.
00172      *
00173      * Handles the payload containing CF-list and enables channels defined
00174      * therein.
00175      *
00176      * @param payload Payload to process.
00177      * @param size Size of the payload.
00178      *
00179      */
00180     virtual void apply_cf_list(const uint8_t *payload, uint8_t size);
00181 
00182     /** Calculates the next datarate to set, when ADR is on or off.
00183      *
00184      * @param restore_channel_mask    A boolean set restore channel mask in case
00185      *                                of failure.
00186      *
00187      * @param dr_out                  The calculated datarate for the next TX.
00188      *
00189      * @param tx_power_out            The TX power for the next TX.
00190      *
00191      * @param adr_ack_counter         The calculated ADR acknowledgement counter.
00192      *
00193      * @return True, if an ADR request should be performed.
00194      */
00195     bool get_next_ADR(bool restore_channel_mask, int8_t &dr_out,
00196                       int8_t &tx_power_out, uint32_t &adr_ack_counter);
00197 
00198     /** Configure radio reception.
00199      *
00200      * @param [in] config    A pointer to the RX configuration.
00201      *
00202      * @return True, if the configuration was applied successfully.
00203      */
00204     virtual bool rx_config(rx_config_params_t  *config);
00205 
00206     /** Computing Receive Windows
00207      *
00208      * The algorithm tries to calculate the length of receive windows (i.e.,
00209      * the minimum time it should remain to acquire a lock on the Preamble
00210      * for synchronization) and the error offset which compensates for the system
00211      * timing errors. Basic idea behind the algorithm is to optimize for the
00212      * reception of last 'min_rx_symbols' symbols out of transmitted Premable
00213      * symbols. The algorithm compensates for the clock drifts, tick granularity
00214      * and system wake up time (from sleep state) by opening the window early for
00215      * the lower SFs. For higher SFs, the symbol time is large enough that we can
00216      * afford to open late (hence the positive offset).
00217      * The table below shows the calculated values for SF7 to SF12 with 125 kHz
00218      * bandwidth.
00219      *
00220      * +----+-----+----------+---------+-------------------------+----------------------+-------------------------+
00221      * | SF | BW (kHz) | rx_error (ms) | wake_up (ms) | min_rx_symbols | window_timeout(symb) | window_offset(ms) |
00222      * +----+-----+----------+---------+-------------------------+----------------------+-------------------------+
00223      * |  7 |      125 |             5 |            5 |              5 |                   18 |                -7 |
00224      * |  8 |      125 |             5 |            5 |              5 |                   10 |                -4 |
00225      * |  9 |      125 |             5 |            5 |              5 |                    6 |                 2 |
00226      * | 10 |      125 |             5 |            5 |              5 |                    6 |                14 |
00227      * | 11 |      125 |             5 |            5 |              5 |                    6 |                39 |
00228      * | 12 |      125 |             5 |            5 |              5 |                    6 |                88 |
00229      * +----+-----+----------+---------+-------------------------+----------------------+-------------------------+
00230      *
00231      * For example for SF7, the receive window will open at downlink start time
00232      * plus the offset calculated and will remain open for the length window_timeout.
00233      *
00234      *             Symbol time = 1.024 ms
00235      *             Downlink start: T = Tx + 1s (+/- 20 us)
00236      *                               |
00237      *                               |
00238      *                               |
00239      *                               |
00240      *                               |
00241      *                               +---+---+---+---+---+---+---+---+
00242      *                               |       8 Preamble Symbols      |
00243      *                               +---+---+---+---+---+---+---+---+
00244      *   | RX Window start time = T +/- Offset
00245      *   +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
00246      *   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
00247      *   +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
00248      *
00249      * Similarly for SF12:
00250      *
00251      *             Symbol time = 32.768 ms
00252      *             Downlink start: T = Tx + 1s (+/- 20 us)
00253      *                |
00254      *                |
00255      *                |
00256      *                |
00257      *                |
00258      *                +---+---+---+---+---+---+---+---+
00259      *                |       8 Preamble Symbols      |
00260      *                +---+---+---+---+---+---+---+---+
00261      *                           | RX Window start time = T +/- Offset
00262      *                           +---+---+---+---+---+---+
00263      *                           |   |   |   |   |   |   |
00264      *                           +---+---+---+---+---+---+
00265      */
00266     /*!
00267      * Computes the RX window timeout and offset.
00268      *
00269      * @param [in] datarate         The RX window datarate index to be used.
00270      *
00271      * @param [in] min_rx_symbols   The minimum number of symbols required to
00272      *                              detect an RX frame.
00273      *
00274      * @param [in] rx_error         The maximum timing error of the receiver
00275      *                              in milliseconds. The receiver will turn on
00276      *                              in a [-rxError : +rxError] ms interval around
00277      *                              RxOffset.
00278      *
00279      * @param [out] rx_conf_params  Pointer to the structure that needs to be
00280      *                              filled with receive window parameters.
00281      *
00282      */
00283     virtual void compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
00284                                        uint32_t rx_error,
00285                                        rx_config_params_t  *rx_conf_params);
00286 
00287     /** Configure radio transmission.
00288      *
00289      * @param [in]  tx_config    Structure containing tx parameters.
00290      *
00291      * @param [out] tx_power     The TX power which will be set.
00292      *
00293      * @param [out] tx_toa       The time-on-air of the frame.
00294      *
00295      * @return True, if the configuration was applied successfully.
00296      */
00297     virtual bool tx_config(tx_config_params_t *tx_config, int8_t *tx_power,
00298                            lorawan_time_t *tx_toa);
00299 
00300     /** Processes a Link ADR Request.
00301      *
00302      * @param [in]  params          A pointer ADR request parameters.
00303      *
00304      * @param [out] dr_out          The datarate applied.
00305      *
00306      * @param [out] tx_power_out    The TX power applied.
00307      *
00308      * @param [out] nb_rep_out      The number of repetitions to apply.
00309      *
00310      * @param [out] nb_bytes_parsed The number of bytes parsed.
00311      *
00312      * @return The status of the operation, according to the LoRaMAC specification.
00313      */
00314     virtual uint8_t link_ADR_request(adr_req_params_t *params,
00315                                      int8_t *dr_out, int8_t *tx_power_out,
00316                                      uint8_t *nb_rep_out,
00317                                      uint8_t *nb_bytes_parsed);
00318 
00319     /** Accept or rejects RxParamSetupReq MAC command
00320      *
00321      * The function processes a RX parameter setup request in response to
00322      * server MAC command for RX setup.
00323      *
00324      * @param [in] params    A pointer to rx parameter setup request.
00325      *
00326      * @return The status of the operation, according to the LoRaWAN specification.
00327      */
00328     virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t *params);
00329 
00330     /**
00331      * @brief accept_tx_param_setup_req Makes decision whether to accept or reject TxParamSetupReq MAC command.
00332      *
00333      * @param ul_dwell_time The uplink dwell time.
00334      * @param dl_dwell_time The downlink dwell time.
00335      *
00336      * @return True to let the MAC know that the request is
00337      *         accepted and MAC can apply TX parameters received
00338      *         form Network Server. Otherwise false is returned.
00339      */
00340     virtual bool accept_tx_param_setup_req(uint8_t ul_dwell_time, uint8_t dl_dwell_time);
00341 
00342     /** Processes a DlChannelReq MAC command.
00343      *
00344      * @param channel_id The channel ID to add the frequency.
00345      * @param rx1_frequency The alternative frequency for the Rx1 window.
00346      *
00347      * @return The status of the operation, according to the LoRaWAN specification.
00348      */
00349     virtual uint8_t dl_channel_request(uint8_t channel_id, uint32_t rx1_frequency);
00350 
00351     /** Alternates the datarate of the channel for the join request.
00352      *
00353      * @param nb_trials    Number of trials to be made on one given data rate.
00354      *
00355      * @return             The datarate to apply .
00356      */
00357     virtual int8_t get_alternate_DR(uint8_t nb_trials);
00358 
00359     /** Searches and sets the next available channel.
00360      *
00361      * If there are multiple channels found available, one of them is selected
00362      * randomly.
00363      *
00364      * @param [in]  nextChanParams Parameters for the next channel.
00365      *
00366      * @param [out] channel The next channel to use for TX.
00367      *
00368      * @param [out] time The time to wait for the next transmission according to the duty cycle.
00369      *
00370      * @param [out] aggregatedTimeOff Updates the aggregated time off.
00371      *
00372      * @return Function status [1: OK, 0: Unable to find a channel on the current datarate].
00373      */
00374     virtual lorawan_status_t set_next_channel(channel_selection_params_t *nextChanParams,
00375                                               uint8_t *channel, lorawan_time_t *time,
00376                                               lorawan_time_t *aggregatedTimeOff);
00377 
00378     /** Adds a channel to the channel list.
00379      *
00380      * Verifies the channel parameters and if everything is found legitimate,
00381      * adds that particular channel to the channel list and updates the channel
00382      * mask.
00383      *
00384      * @param [in] new_channel A pointer to the parameters for the new channel.
00385      * @param [in] id          Channel ID
00386      *
00387      * @return LORAWAN_STATUS_OK if everything goes fine, negative error code
00388      *         otherwise.
00389      */
00390     virtual lorawan_status_t add_channel(const channel_params_t *new_channel, uint8_t id);
00391 
00392     /** Removes a channel from the channel list.
00393      *
00394      * @param [in] channel_id Index of the channel to be removed
00395      *
00396      * @return True, if the channel was removed successfully.
00397      */
00398     virtual bool remove_channel(uint8_t channel_id);
00399 
00400     /** Puts the radio into continuous wave mode.
00401      *
00402      * @param [in] continuous_wave   A pointer to the function parameters.
00403      *
00404      * @param [in] frequency         Frequency to transmit at
00405      */
00406     virtual void set_tx_cont_mode(cw_mode_params_t  *continuous_wave,
00407                                   uint32_t frequency = 0);
00408 
00409     /** Computes new data rate according to the given offset
00410      *
00411      * @param [in] dr The current datarate.
00412      *
00413      * @param [in] dr_offset The offset to be applied.
00414      *
00415      * @return     The computed datarate.
00416      */
00417     virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset);
00418 
00419     /**
00420      * @brief reset_to_default_values resets some parameters to default values
00421      * @param params Pointer to MAC protocol parameters which will be reset
00422      * @param init If true, most of the values will be modified
00423      */
00424     void reset_to_default_values(loramac_protocol_params  *params, bool init = false);
00425 
00426 public:
00427     /**
00428      * @brief get_next_lower_tx_datarate Gets the next lower datarate
00429      * @param datarate Current TX datarate
00430      * @return Lower datarate than given one or minimum if lower cannot be found anymore
00431      */
00432     int8_t get_next_lower_tx_datarate(int8_t datarate);
00433 
00434     /**
00435      * @brief get_minimum_rx_datarate Gets the minimum RX datarate supported by a device
00436      * @return Minimum RX datarate
00437      */
00438     uint8_t get_minimum_rx_datarate();
00439 
00440     /**
00441      * @brief get_minimum_tx_datarate Gets the minimum TX datarate supported by a device
00442      * @return Minimum TX datarate
00443      */
00444     uint8_t get_minimum_tx_datarate();
00445 
00446     /**
00447      * @brief get_default_tx_datarate Gets the default TX datarate
00448      * @return default TX datarate
00449      */
00450     uint8_t get_default_tx_datarate();
00451 
00452     /**
00453      * @brief get_default_max_tx_datarate Gets the maximum achievable data rate for
00454      *        LoRa modulation. This will always be the highest data rate achievable with
00455      *        LoRa as defined in the regional specifications.
00456      * @return Maximum achievable data rate with LoRa modulation.
00457      */
00458     uint8_t get_default_max_tx_datarate();
00459 
00460     /**
00461      * @brief get_default_tx_power Gets the default TX power
00462      * @return Default TX power
00463      */
00464     uint8_t get_default_tx_power();
00465 
00466     /**
00467      * @brief get_max_payload Gets maximum amount in bytes which device can send
00468      * @param datarate A datarate to use
00469      * @param use_repeater If true repeater table is used, otherwise payloads table is used
00470      * @return Maximum number of bytes for payload
00471      */
00472     uint8_t get_max_payload(uint8_t datarate, bool use_repeater = false);
00473 
00474     /**
00475      * @brief get_maximum_frame_counter_gap Gets maximum frame counter gap
00476      * @return Maximum frame counter gap
00477      */
00478     uint16_t get_maximum_frame_counter_gap();
00479 
00480     /**
00481      * @brief get_ack_timeout Gets timeout value for ACK to be received
00482      * @return ACK timeout
00483      */
00484     uint32_t get_ack_timeout();
00485 
00486     /**
00487      * @brief get_default_rx2_frequency Gets default RX2 frequency
00488      * @return RX2 frequency
00489      */
00490     uint32_t get_default_rx2_frequency();
00491 
00492     /**
00493      * @brief get_default_rx2_datarate Gets default RX2 datarate
00494      * @return RX2 datarate
00495      */
00496     uint8_t get_default_rx2_datarate();
00497 
00498     /**
00499      * @brief get_channel_mask Gets the channel mask
00500      * @param get_default If true the default mask is returned, otherwise the current mask is returned
00501      * @return A channel mask
00502      */
00503     uint16_t *get_channel_mask(bool get_default = false);
00504 
00505     /**
00506      * @brief get_max_nb_channels Gets maximum number of channels supported
00507      * @return Number of channels
00508      */
00509     uint8_t get_max_nb_channels();
00510 
00511     /**
00512      * @brief get_phy_channels Gets PHY channels
00513      * @return PHY channels
00514      */
00515     channel_params_t *get_phy_channels();
00516 
00517     /**
00518      * @brief is_custom_channel_plan_supported Checks if custom channel plan is supported
00519      * @return True if custom channel plan is supported, false otherwise
00520      */
00521     bool is_custom_channel_plan_supported();
00522 
00523     /**
00524      * @brief get_rx_time_on_air(...) calculates the time the received spent on air
00525      * @return time spent on air in milliseconds
00526      */
00527     uint32_t get_rx_time_on_air(uint8_t modem, uint16_t pkt_len);
00528 
00529 public: //Verifiers
00530 
00531     /**
00532      * @brief verify_rx_datarate Verifies that given RX datarate is valid
00533      * @param datarate Datarate to check
00534      * @return true if given datarate is valid, false otherwise
00535      */
00536     bool verify_rx_datarate(uint8_t datarate);
00537 
00538     /**
00539      * @brief verify_tx_datarate Verifies that given TX datarate is valid
00540      * @param datarate Datarate to check
00541      * @param use_default If true validation is done against default value
00542      * @return true if given datarate is valid, false otherwise
00543      */
00544     bool verify_tx_datarate(uint8_t datarate, bool use_default = false);
00545 
00546     /**
00547      * @brief verify_tx_power Verifies that given TX power is valid
00548      * @param tx_power Power to check
00549      * @return True if valid, false otherwise
00550      */
00551     bool verify_tx_power(uint8_t tx_power);
00552 
00553     /**
00554      * @brief verify_duty_cycle Verifies that given cycle is valid
00555      * @param cycle Cycle to check
00556      * @return True if valid, false otherwise
00557      */
00558     bool verify_duty_cycle(bool cycle);
00559 
00560     /**
00561      * @brief verify_nb_join_trials Verifies that given number of trials is valid
00562      * @param nb_join_trials Number to check
00563      * @return True if valid, false otherwise
00564      */
00565     bool verify_nb_join_trials(uint8_t nb_join_trials);
00566 
00567 protected:
00568     LoRaPHY();
00569 
00570     /**
00571      * Looks up corresponding band for a frequency. Returns -1 if not in any band.
00572      */
00573     int lookup_band_for_frequency(uint32_t freq) const;
00574 
00575     /**
00576      * Verifies, if a frequency is within a given band.
00577      */
00578     virtual bool verify_frequency_for_band(uint32_t freq, uint8_t band) const;
00579 
00580     /**
00581      * Verifies, if a value is in a given range.
00582      */
00583     bool val_in_range(int8_t value, int8_t min, int8_t max);
00584 
00585     /**
00586      * Verifies, if a datarate is available on an active channel.
00587      */
00588     bool verify_channel_DR(uint16_t *channelsMask, int8_t dr);
00589 
00590     /**
00591      * Disables a channel in a given channels mask.
00592      */
00593     bool disable_channel(uint16_t *channel_mask, uint8_t id, uint8_t max_channels);
00594 
00595     /**
00596      * Counts number of bits on in a given mask
00597      */
00598     uint8_t count_bits(uint16_t mask, uint8_t nb_bits);
00599 
00600     /**
00601      * Counts the number of active channels in a given channels mask.
00602      */
00603     uint8_t num_active_channels(uint16_t *channel_mask, uint8_t start_idx,
00604                                 uint8_t stop_idx);
00605 
00606     /**
00607      * Copy channel masks.
00608      */
00609     void copy_channel_mask(uint16_t *dest_mask, uint16_t *src_mask, uint8_t len);
00610 
00611     /**
00612      * Updates the time-offs of the bands.
00613      */
00614     lorawan_time_t update_band_timeoff(bool joined, bool dutyCycle, band_t  *bands,
00615                                        uint8_t nb_bands);
00616 
00617     /**
00618      * Parses the parameter of an LinkAdrRequest.
00619      */
00620     uint8_t parse_link_ADR_req(const uint8_t *payload, uint8_t payload_size,
00621                                link_adr_params_t *adr_params);
00622 
00623     /**
00624      * Verifies and updates the datarate, the TX power and the number of repetitions
00625      * of a LinkAdrRequest.
00626      */
00627     uint8_t verify_link_ADR_req(verify_adr_params_t *verify_params, int8_t *dr,
00628                                 int8_t *tx_pow, uint8_t *nb_rep);
00629 
00630     /**
00631      * Computes the RX window timeout and the RX window offset.
00632      */
00633     void get_rx_window_params(float t_symbol, uint8_t min_rx_symbols,
00634                               float rx_error, float wakeup_time,
00635                               uint32_t *window_length, uint32_t *window_length_ms,
00636                               int32_t *window_offset,
00637                               uint8_t phy_dr);
00638 
00639     /**
00640      * Computes the txPower, based on the max EIRP and the antenna gain.
00641      */
00642     int8_t compute_tx_power(int8_t txPowerIndex, float maxEirp, float antennaGain);
00643 
00644     /**
00645      * Provides a random number in the range provided.
00646      */
00647     int32_t get_random(int32_t min, int32_t max);
00648 
00649     /**
00650      * Get next lower data rate
00651      */
00652     int8_t get_next_lower_dr(int8_t dr, int8_t min_dr);
00653 
00654     /**
00655      * Get channel bandwidth depending upon data rate table index
00656      */
00657     uint8_t get_bandwidth(uint8_t dr_index);
00658 
00659     uint8_t enabled_channel_count(uint8_t datarate,
00660                                   const uint16_t *mask, uint8_t *enabledChannels,
00661                                   uint8_t *delayTx);
00662 
00663     bool is_datarate_supported(const int8_t datarate) const;
00664 
00665 private:
00666 
00667     /**
00668      * Computes the symbol time for LoRa modulation.
00669      */
00670     float compute_symb_timeout_lora(uint8_t phy_dr, uint32_t bandwidth);
00671 
00672     /**
00673      * Computes the symbol time for FSK modulation.
00674      */
00675     float compute_symb_timeout_fsk(uint8_t phy_dr);
00676 
00677 protected:
00678     LoRaRadio *_radio;
00679     LoRaWANTimeHandler *_lora_time;
00680     loraphy_params_t  phy_params;
00681 };
00682 
00683 #endif /* MBED_OS_LORAPHY_BASE_ */