Mistake on this page?
Report an issue in GitHub or email us
LoRaPHY.h
Go to the documentation of this file.
1 /**
2  * @file LoRaPHY.h
3  *
4  * @brief An abstract class providing radio object to children and
5  * provide base for implementing LoRa PHY layer
6  *
7  * \code
8  * ______ _
9  * / _____) _ | |
10  * ( (____ _____ ____ _| |_ _____ ____| |__
11  * \____ \| ___ | (_ _) ___ |/ ___) _ \
12  * _____) ) ____| | | || |_| ____( (___| | | |
13  * (______/|_____)_|_|_| \__)_____)\____)_| |_|
14  * (C)2013 Semtech
15  * ___ _____ _ ___ _ _____ ___ ___ ___ ___
16  * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
17  * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
18  * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
19  * embedded.connectivity.solutions===============
20  *
21  * \endcode
22  *
23  * Description: LoRa PHY layer
24  *
25  * License: Revised BSD License, see LICENSE.TXT file include in the project
26  *
27  * Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jaeckle ( STACKFORCE )
28  *
29  * Copyright (c) 2017, Arm Limited and affiliates.
30  * SPDX-License-Identifier: BSD-3-Clause
31  *
32  */
33 
34 #ifndef MBED_OS_LORAPHY_BASE_
35 #define MBED_OS_LORAPHY_BASE_
36 
37 #include "platform/NonCopyable.h"
38 
39 #include "system/LoRaWANTimer.h"
40 #include "LoRaRadio.h"
41 #include "lora_phy_ds.h"
42 
43 /** LoRaPHY Class
44  * Parent class for LoRa regional PHY implementations
45  */
46 class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
47 
48 public:
49  virtual ~LoRaPHY();
50 
51  /** Initialize LoRaPHY
52  *
53  * LoRaMac calls this to initialize LoRaPHY.
54  *
55  * @param lora_time a pointer to LoRaWANTimeHandler object
56  */
57  void initialize(LoRaWANTimeHandler *lora_time);
58 
59  /** Stores a reference to Radio object.
60  *
61  * Application is responsible for constructing a 'LoRaRadio' object
62  * which is passed down to the PHY layer.
63  *
64  * @param radio a reference to radio driver object
65  */
66  void set_radio_instance(LoRaRadio &radio);
67 
68  /** Puts radio in sleep mode.
69  *
70  * Requests the radio driver to enter sleep mode.
71  */
72  void put_radio_to_sleep(void);
73 
74  /** Puts radio in standby mode.
75  *
76  * Requests the radio driver to enter standby mode.
77  */
78  void put_radio_to_standby(void);
79 
80  /** Puts radio in receive mode.
81  *
82  * Requests the radio driver to enter receive mode.
83  */
84  void handle_receive(void);
85 
86  /** Delegates MAC layer request to transmit packet.
87  *
88  * @param buf a pointer to the data which needs to be transmitted
89  *
90  * @param size size of the data in bytes
91  */
92  void handle_send(uint8_t *buf, uint8_t size);
93 
94  /** Enables/Disables public network mode.
95  *
96  * Public and private LoRaWAN network constitute different preambles and
97  * Net IDs. This API isused to tell the radio which network mode is in use.
98  *
99  * @param set true or false
100  */
101  void setup_public_network_mode(bool set);
102 
103  /** Provides a random number from radio.
104  *
105  * Returns a 32-bit random unsigned integer value based upon RSSI
106  * measurements.
107  *
108  * @return a 32-bit long random number
109  *
110  */
111  uint32_t get_radio_rng();
112 
113  /**
114  * @brief calculate_backoff Calculates and applies duty cycle back-off time.
115  * Explicitly updates the band time-off.
116  *
117  * @param joined Set to true, if the node has already joined a network, otherwise false.
118  * @param last_tx_was_join_req Set to true, if the last uplink was a join request.
119  * @param dc_enabled Set to true, if the duty cycle is enabled, otherwise false.
120  * @param channel The current channel index.
121  * @param elapsed_time Elapsed time since the start of the node.
122  * @param tx_toa Time-on-air of the last transmission.
123  */
124  void calculate_backoff(bool joined, bool last_tx_was_join_req, bool dc_enabled, uint8_t channel,
125  lorawan_time_t elapsed_time, lorawan_time_t tx_toa);
126 
127  /**
128  * Tests if a channel is on or off in the channel mask
129  */
130  bool mask_bit_test(const uint16_t *mask, unsigned bit);
131 
132  /**
133  * Tests if a channel is on or off in the channel mask
134  */
135  void mask_bit_set(uint16_t *mask, unsigned bit);
136 
137  /**
138  * Tests if a channel is on or off in the channel mask
139  */
140  void mask_bit_clear(uint16_t *mask, unsigned bit);
141 
142  /** Entertain a new channel request MAC command.
143  *
144  * MAC command subsystem processes the new channel request coming form
145  * the network server and then MAC layer asks the PHY layer to entertain
146  * the request.
147  *
148  * @param channel_id The channel ID.
149  * @param new_channel A pointer to the new channel's parameters.
150  *
151  * @return bit mask, according to the LoRaWAN spec 1.0.2.
152  */
153  virtual uint8_t request_new_channel(int8_t channel_id, channel_params_t *new_channel);
154 
155  /** Process PHY layer state after a successful transmission.
156  * @brief set_last_tx_done Updates times of the last transmission for the particular channel and
157  * band upon which last transmission took place.
158  * @param channel The channel in use.
159  * @param joined Boolean telling if node has joined the network.
160  * @param last_tx_done_time The last TX done time.
161  */
162  virtual void set_last_tx_done(uint8_t channel, bool joined, lorawan_time_t last_tx_done_time);
163 
164  /** Enables default channels only.
165  *
166  * Falls back to a channel mask where only default channels are enabled, all
167  * other channels are disabled.
168  */
169  virtual void restore_default_channels();
170 
171  /** Processes the incoming CF-list.
172  *
173  * Handles the payload containing CF-list and enables channels defined
174  * therein.
175  *
176  * @param payload Payload to process.
177  * @param size Size of the payload.
178  *
179  */
180  virtual void apply_cf_list(const uint8_t *payload, uint8_t size);
181 
182  /** Calculates the next datarate to set, when ADR is on or off.
183  *
184  * @param restore_channel_mask A boolean set restore channel mask in case
185  * of failure.
186  *
187  * @param dr_out The calculated datarate for the next TX.
188  *
189  * @param tx_power_out The TX power for the next TX.
190  *
191  * @param adr_ack_counter The calculated ADR acknowledgement counter.
192  *
193  * @return True, if an ADR request should be performed.
194  */
195  bool get_next_ADR(bool restore_channel_mask, int8_t &dr_out,
196  int8_t &tx_power_out, uint32_t &adr_ack_counter);
197 
198  /** Configure radio reception.
199  *
200  * @param [in] config A pointer to the RX configuration.
201  *
202  * @return True, if the configuration was applied successfully.
203  */
204  virtual bool rx_config(rx_config_params_t *config);
205 
206  /** Computing Receive Windows
207  *
208  * The algorithm tries to calculate the length of receive windows (i.e.,
209  * the minimum time it should remain to acquire a lock on the Preamble
210  * for synchronization) and the error offset which compensates for the system
211  * timing errors. Basic idea behind the algorithm is to optimize for the
212  * reception of last 'min_rx_symbols' symbols out of transmitted Premable
213  * symbols. The algorithm compensates for the clock drifts, tick granularity
214  * and system wake up time (from sleep state) by opening the window early for
215  * the lower SFs. For higher SFs, the symbol time is large enough that we can
216  * afford to open late (hence the positive offset).
217  * The table below shows the calculated values for SF7 to SF12 with 125 kHz
218  * bandwidth.
219  *
220  * +----+-----+----------+---------+-------------------------+----------------------+-------------------------+
221  * | SF | BW (kHz) | rx_error (ms) | wake_up (ms) | min_rx_symbols | window_timeout(symb) | window_offset(ms) |
222  * +----+-----+----------+---------+-------------------------+----------------------+-------------------------+
223  * | 7 | 125 | 5 | 5 | 5 | 18 | -7 |
224  * | 8 | 125 | 5 | 5 | 5 | 10 | -4 |
225  * | 9 | 125 | 5 | 5 | 5 | 6 | 2 |
226  * | 10 | 125 | 5 | 5 | 5 | 6 | 14 |
227  * | 11 | 125 | 5 | 5 | 5 | 6 | 39 |
228  * | 12 | 125 | 5 | 5 | 5 | 6 | 88 |
229  * +----+-----+----------+---------+-------------------------+----------------------+-------------------------+
230  *
231  * For example for SF7, the receive window will open at downlink start time
232  * plus the offset calculated and will remain open for the length window_timeout.
233  *
234  * Symbol time = 1.024 ms
235  * Downlink start: T = Tx + 1s (+/- 20 us)
236  * |
237  * |
238  * |
239  * |
240  * |
241  * +---+---+---+---+---+---+---+---+
242  * | 8 Preamble Symbols |
243  * +---+---+---+---+---+---+---+---+
244  * | RX Window start time = T +/- Offset
245  * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
246  * | | | | | | | | | | | | | | | | | | |
247  * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
248  *
249  * Similarly for SF12:
250  *
251  * Symbol time = 32.768 ms
252  * Downlink start: T = Tx + 1s (+/- 20 us)
253  * |
254  * |
255  * |
256  * |
257  * |
258  * +---+---+---+---+---+---+---+---+
259  * | 8 Preamble Symbols |
260  * +---+---+---+---+---+---+---+---+
261  * | RX Window start time = T +/- Offset
262  * +---+---+---+---+---+---+
263  * | | | | | | |
264  * +---+---+---+---+---+---+
265  */
266  /*!
267  * Computes the RX window timeout and offset.
268  *
269  * @param [in] datarate The RX window datarate index to be used.
270  *
271  * @param [in] min_rx_symbols The minimum number of symbols required to
272  * detect an RX frame.
273  *
274  * @param [in] rx_error The maximum timing error of the receiver
275  * in milliseconds. The receiver will turn on
276  * in a [-rxError : +rxError] ms interval around
277  * RxOffset.
278  *
279  * @param [out] rx_conf_params Pointer to the structure that needs to be
280  * filled with receive window parameters.
281  *
282  */
283  virtual void compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
284  uint32_t rx_error,
285  rx_config_params_t *rx_conf_params);
286 
287  /** Configure radio transmission.
288  *
289  * @param [in] tx_config Structure containing tx parameters.
290  *
291  * @param [out] tx_power The TX power which will be set.
292  *
293  * @param [out] tx_toa The time-on-air of the frame.
294  *
295  * @return True, if the configuration was applied successfully.
296  */
297  virtual bool tx_config(tx_config_params_t *tx_config, int8_t *tx_power,
298  lorawan_time_t *tx_toa);
299 
300  /** Processes a Link ADR Request.
301  *
302  * @param [in] params A pointer ADR request parameters.
303  *
304  * @param [out] dr_out The datarate applied.
305  *
306  * @param [out] tx_power_out The TX power applied.
307  *
308  * @param [out] nb_rep_out The number of repetitions to apply.
309  *
310  * @param [out] nb_bytes_parsed The number of bytes parsed.
311  *
312  * @return The status of the operation, according to the LoRaMAC specification.
313  */
314  virtual uint8_t link_ADR_request(adr_req_params_t *params,
315  int8_t *dr_out, int8_t *tx_power_out,
316  uint8_t *nb_rep_out,
317  uint8_t *nb_bytes_parsed);
318 
319  /** Accept or rejects RxParamSetupReq MAC command
320  *
321  * The function processes a RX parameter setup request in response to
322  * server MAC command for RX setup.
323  *
324  * @param [in] params A pointer to rx parameter setup request.
325  *
326  * @return The status of the operation, according to the LoRaWAN specification.
327  */
328  virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t *params);
329 
330  /**
331  * @brief accept_tx_param_setup_req Makes decision whether to accept or reject TxParamSetupReq MAC command.
332  *
333  * @param ul_dwell_time The uplink dwell time.
334  * @param dl_dwell_time The downlink dwell time.
335  *
336  * @return True to let the MAC know that the request is
337  * accepted and MAC can apply TX parameters received
338  * form Network Server. Otherwise false is returned.
339  */
340  virtual bool accept_tx_param_setup_req(uint8_t ul_dwell_time, uint8_t dl_dwell_time);
341 
342  /** Processes a DlChannelReq MAC command.
343  *
344  * @param channel_id The channel ID to add the frequency.
345  * @param rx1_frequency The alternative frequency for the Rx1 window.
346  *
347  * @return The status of the operation, according to the LoRaWAN specification.
348  */
349  virtual uint8_t dl_channel_request(uint8_t channel_id, uint32_t rx1_frequency);
350 
351  /** Alternates the datarate of the channel for the join request.
352  *
353  * @param nb_trials Number of trials to be made on one given data rate.
354  *
355  * @return The datarate to apply .
356  */
357  virtual int8_t get_alternate_DR(uint8_t nb_trials);
358 
359  /** Searches and sets the next available channel.
360  *
361  * If there are multiple channels found available, one of them is selected
362  * randomly.
363  *
364  * @param [in] nextChanParams Parameters for the next channel.
365  *
366  * @param [out] channel The next channel to use for TX.
367  *
368  * @param [out] time The time to wait for the next transmission according to the duty cycle.
369  *
370  * @param [out] aggregatedTimeOff Updates the aggregated time off.
371  *
372  * @return Function status [1: OK, 0: Unable to find a channel on the current datarate].
373  */
375  uint8_t *channel, lorawan_time_t *time,
376  lorawan_time_t *aggregatedTimeOff);
377 
378  /** Adds a channel to the channel list.
379  *
380  * Verifies the channel parameters and if everything is found legitimate,
381  * adds that particular channel to the channel list and updates the channel
382  * mask.
383  *
384  * @param [in] new_channel A pointer to the parameters for the new channel.
385  * @param [in] id Channel ID
386  *
387  * @return LORAWAN_STATUS_OK if everything goes fine, negative error code
388  * otherwise.
389  */
390  virtual lorawan_status_t add_channel(const channel_params_t *new_channel, uint8_t id);
391 
392  /** Removes a channel from the channel list.
393  *
394  * @param [in] channel_id Index of the channel to be removed
395  *
396  * @return True, if the channel was removed successfully.
397  */
398  virtual bool remove_channel(uint8_t channel_id);
399 
400  /** Puts the radio into continuous wave mode.
401  *
402  * @param [in] continuous_wave A pointer to the function parameters.
403  *
404  * @param [in] frequency Frequency to transmit at
405  */
406  virtual void set_tx_cont_mode(cw_mode_params_t *continuous_wave,
407  uint32_t frequency = 0);
408 
409  /** Computes new data rate according to the given offset
410  *
411  * @param [in] dr The current datarate.
412  *
413  * @param [in] dr_offset The offset to be applied.
414  *
415  * @return The computed datarate.
416  */
417  virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset);
418 
419  /**
420  * @brief reset_to_default_values resets some parameters to default values
421  * @param params Pointer to MAC protocol parameters which will be reset
422  * @param init If true, most of the values will be modified
423  */
424  void reset_to_default_values(loramac_protocol_params *params, bool init = false);
425 
426 public:
427  /**
428  * @brief get_next_lower_tx_datarate Gets the next lower datarate
429  * @param datarate Current TX datarate
430  * @return Lower datarate than given one or minimum if lower cannot be found anymore
431  */
432  int8_t get_next_lower_tx_datarate(int8_t datarate);
433 
434  /**
435  * @brief get_minimum_rx_datarate Gets the minimum RX datarate supported by a device
436  * @return Minimum RX datarate
437  */
438  uint8_t get_minimum_rx_datarate();
439 
440  /**
441  * @brief get_minimum_tx_datarate Gets the minimum TX datarate supported by a device
442  * @return Minimum TX datarate
443  */
444  uint8_t get_minimum_tx_datarate();
445 
446  /**
447  * @brief get_default_tx_datarate Gets the default TX datarate
448  * @return default TX datarate
449  */
450  uint8_t get_default_tx_datarate();
451 
452  /**
453  * @brief get_default_max_tx_datarate Gets the maximum achievable data rate for
454  * LoRa modulation. This will always be the highest data rate achievable with
455  * LoRa as defined in the regional specifications.
456  * @return Maximum achievable data rate with LoRa modulation.
457  */
458  uint8_t get_default_max_tx_datarate();
459 
460  /**
461  * @brief get_default_tx_power Gets the default TX power
462  * @return Default TX power
463  */
464  uint8_t get_default_tx_power();
465 
466  /**
467  * @brief get_max_payload Gets maximum amount in bytes which device can send
468  * @param datarate A datarate to use
469  * @param use_repeater If true repeater table is used, otherwise payloads table is used
470  * @return Maximum number of bytes for payload
471  */
472  uint8_t get_max_payload(uint8_t datarate, bool use_repeater = false);
473 
474  /**
475  * @brief get_maximum_frame_counter_gap Gets maximum frame counter gap
476  * @return Maximum frame counter gap
477  */
479 
480  /**
481  * @brief get_ack_timeout Gets timeout value for ACK to be received
482  * @return ACK timeout
483  */
484  uint32_t get_ack_timeout();
485 
486  /**
487  * @brief get_default_rx2_frequency Gets default RX2 frequency
488  * @return RX2 frequency
489  */
490  uint32_t get_default_rx2_frequency();
491 
492  /**
493  * @brief get_default_rx2_datarate Gets default RX2 datarate
494  * @return RX2 datarate
495  */
496  uint8_t get_default_rx2_datarate();
497 
498  /**
499  * @brief get_channel_mask Gets the channel mask
500  * @param get_default If true the default mask is returned, otherwise the current mask is returned
501  * @return A channel mask
502  */
503  uint16_t *get_channel_mask(bool get_default = false);
504 
505  /**
506  * @brief get_max_nb_channels Gets maximum number of channels supported
507  * @return Number of channels
508  */
509  uint8_t get_max_nb_channels();
510 
511  /**
512  * @brief get_phy_channels Gets PHY channels
513  * @return PHY channels
514  */
516 
517  /**
518  * @brief is_custom_channel_plan_supported Checks if custom channel plan is supported
519  * @return True if custom channel plan is supported, false otherwise
520  */
522 
523  /**
524  * @brief get_rx_time_on_air(...) calculates the time the received spent on air
525  * @return time spent on air in milliseconds
526  */
527  uint32_t get_rx_time_on_air(uint8_t modem, uint16_t pkt_len);
528 
529 public: //Verifiers
530 
531  /**
532  * @brief verify_rx_datarate Verifies that given RX datarate is valid
533  * @param datarate Datarate to check
534  * @return true if given datarate is valid, false otherwise
535  */
536  bool verify_rx_datarate(uint8_t datarate);
537 
538  /**
539  * @brief verify_tx_datarate Verifies that given TX datarate is valid
540  * @param datarate Datarate to check
541  * @param use_default If true validation is done against default value
542  * @return true if given datarate is valid, false otherwise
543  */
544  bool verify_tx_datarate(uint8_t datarate, bool use_default = false);
545 
546  /**
547  * @brief verify_tx_power Verifies that given TX power is valid
548  * @param tx_power Power to check
549  * @return True if valid, false otherwise
550  */
551  bool verify_tx_power(uint8_t tx_power);
552 
553  /**
554  * @brief verify_duty_cycle Verifies that given cycle is valid
555  * @param cycle Cycle to check
556  * @return True if valid, false otherwise
557  */
558  bool verify_duty_cycle(bool cycle);
559 
560  /**
561  * @brief verify_nb_join_trials Verifies that given number of trials is valid
562  * @param nb_join_trials Number to check
563  * @return True if valid, false otherwise
564  */
565  bool verify_nb_join_trials(uint8_t nb_join_trials);
566 
567 protected:
568  LoRaPHY();
569 
570  /**
571  * Looks up corresponding band for a frequency. Returns -1 if not in any band.
572  */
573  int lookup_band_for_frequency(uint32_t freq) const;
574 
575  /**
576  * Verifies, if a frequency is within a given band.
577  */
578  virtual bool verify_frequency_for_band(uint32_t freq, uint8_t band) const;
579 
580  /**
581  * Verifies, if a value is in a given range.
582  */
583  bool val_in_range(int8_t value, int8_t min, int8_t max);
584 
585  /**
586  * Verifies, if a datarate is available on an active channel.
587  */
588  bool verify_channel_DR(uint16_t *channelsMask, int8_t dr);
589 
590  /**
591  * Disables a channel in a given channels mask.
592  */
593  bool disable_channel(uint16_t *channel_mask, uint8_t id, uint8_t max_channels);
594 
595  /**
596  * Counts number of bits on in a given mask
597  */
598  uint8_t count_bits(uint16_t mask, uint8_t nb_bits);
599 
600  /**
601  * Counts the number of active channels in a given channels mask.
602  */
603  uint8_t num_active_channels(uint16_t *channel_mask, uint8_t start_idx,
604  uint8_t stop_idx);
605 
606  /**
607  * Copy channel masks.
608  */
609  void copy_channel_mask(uint16_t *dest_mask, uint16_t *src_mask, uint8_t len);
610 
611  /**
612  * Updates the time-offs of the bands.
613  */
614  lorawan_time_t update_band_timeoff(bool joined, bool dutyCycle, band_t *bands,
615  uint8_t nb_bands);
616 
617  /**
618  * Parses the parameter of an LinkAdrRequest.
619  */
620  uint8_t parse_link_ADR_req(const uint8_t *payload, uint8_t payload_size,
621  link_adr_params_t *adr_params);
622 
623  /**
624  * Verifies and updates the datarate, the TX power and the number of repetitions
625  * of a LinkAdrRequest.
626  */
627  uint8_t verify_link_ADR_req(verify_adr_params_t *verify_params, int8_t *dr,
628  int8_t *tx_pow, uint8_t *nb_rep);
629 
630  /**
631  * Computes the RX window timeout and the RX window offset.
632  */
633  void get_rx_window_params(float t_symbol, uint8_t min_rx_symbols,
634  float rx_error, float wakeup_time,
635  uint32_t *window_length, uint32_t *window_length_ms,
636  int32_t *window_offset,
637  uint8_t phy_dr);
638 
639  /**
640  * Computes the txPower, based on the max EIRP and the antenna gain.
641  */
642  int8_t compute_tx_power(int8_t txPowerIndex, float maxEirp, float antennaGain);
643 
644  /**
645  * Provides a random number in the range provided.
646  */
647  int32_t get_random(int32_t min, int32_t max);
648 
649  /**
650  * Get next lower data rate
651  */
652  int8_t get_next_lower_dr(int8_t dr, int8_t min_dr);
653 
654  /**
655  * Get channel bandwidth depending upon data rate table index
656  */
657  uint8_t get_bandwidth(uint8_t dr_index);
658 
659  uint8_t enabled_channel_count(uint8_t datarate,
660  const uint16_t *mask, uint8_t *enabledChannels,
661  uint8_t *delayTx);
662 
663  bool is_datarate_supported(const int8_t datarate) const;
664 
665 private:
666 
667  /**
668  * Computes the symbol time for LoRa modulation.
669  */
670  float compute_symb_timeout_lora(uint8_t phy_dr, uint32_t bandwidth);
671 
672  /**
673  * Computes the symbol time for FSK modulation.
674  */
675  float compute_symb_timeout_fsk(uint8_t phy_dr);
676 
677 protected:
678  LoRaRadio *_radio;
679  LoRaWANTimeHandler *_lora_time;
680  loraphy_params_t phy_params;
681 };
682 
683 #endif /* MBED_OS_LORAPHY_BASE_ */
bool val_in_range(int8_t value, int8_t min, int8_t max)
Verifies, if a value is in a given range.
uint8_t get_default_rx2_datarate()
get_default_rx2_datarate Gets default RX2 datarate
bool verify_tx_power(uint8_t tx_power)
verify_tx_power Verifies that given TX power is valid
TX configuration parameters.
Definition: lora_phy_ds.h:275
void handle_send(uint8_t *buf, uint8_t size)
Delegates MAC layer request to transmit packet.
uint8_t get_minimum_rx_datarate()
get_minimum_rx_datarate Gets the minimum RX datarate supported by a device
uint8_t num_active_channels(uint16_t *channel_mask, uint8_t start_idx, uint8_t stop_idx)
Counts the number of active channels in a given channels mask.
uint8_t get_default_tx_datarate()
get_default_tx_datarate Gets the default TX datarate
uint8_t get_max_payload(uint8_t datarate, bool use_repeater=false)
get_max_payload Gets maximum amount in bytes which device can send
virtual void apply_cf_list(const uint8_t *payload, uint8_t size)
Processes the incoming CF-list.
virtual void set_tx_cont_mode(cw_mode_params_t *continuous_wave, uint32_t frequency=0)
Puts the radio into continuous wave mode.
virtual int8_t get_alternate_DR(uint8_t nb_trials)
Alternates the datarate of the channel for the join request.
bool verify_channel_DR(uint16_t *channelsMask, int8_t dr)
Verifies, if a datarate is available on an active channel.
void setup_public_network_mode(bool set)
Enables/Disables public network mode.
virtual bool remove_channel(uint8_t channel_id)
Removes a channel from the channel list.
virtual void set_last_tx_done(uint8_t channel, bool joined, lorawan_time_t last_tx_done_time)
Process PHY layer state after a successful transmission.
bool verify_tx_datarate(uint8_t datarate, bool use_default=false)
verify_tx_datarate Verifies that given TX datarate is valid
virtual bool tx_config(tx_config_params_t *tx_config, int8_t *tx_power, lorawan_time_t *tx_toa)
Configure radio transmission.
virtual uint8_t link_ADR_request(adr_req_params_t *params, int8_t *dr_out, int8_t *tx_power_out, uint8_t *nb_rep_out, uint8_t *nb_bytes_parsed)
Processes a Link ADR Request.
uint8_t verify_link_ADR_req(verify_adr_params_t *verify_params, int8_t *dr, int8_t *tx_pow, uint8_t *nb_rep)
Verifies and updates the datarate, the TX power and the number of repetitions of a LinkAdrRequest...
uint8_t count_bits(uint16_t mask, uint8_t nb_bits)
Counts number of bits on in a given mask.
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:169
uint32_t lorawan_time_t
Timer time variable definition.
virtual lorawan_status_t set_next_channel(channel_selection_params_t *nextChanParams, uint8_t *channel, lorawan_time_t *time, lorawan_time_t *aggregatedTimeOff)
Searches and sets the next available channel.
void mask_bit_clear(uint16_t *mask, unsigned bit)
Tests if a channel is on or off in the channel mask.
Structure used to store ADR values received from network for verification (legality) purposes...
Definition: lora_phy_ds.h:368
uint32_t get_rx_time_on_air(uint8_t modem, uint16_t pkt_len)
get_rx_time_on_air(...) calculates the time the received spent on air
LoRaPHY Class Parent class for LoRa regional PHY implementations.
Definition: LoRaPHY.h:46
/ _____) _ | | ( (____ _____ ____ _| |_ _____ ____| |__ ____ | ___ | (_ _) ___ |/ ___) _ \ _____) ) _...
Definition: LoRaWANTimer.h:29
uint32_t get_default_rx2_frequency()
get_default_rx2_frequency Gets default RX2 frequency
virtual lorawan_status_t add_channel(const channel_params_t *new_channel, uint8_t id)
Adds a channel to the channel list.
void put_radio_to_sleep(void)
Puts radio in sleep mode.
virtual bool verify_frequency_for_band(uint32_t freq, uint8_t band) const
Verifies, if a frequency is within a given band.
uint8_t get_default_max_tx_datarate()
get_default_max_tx_datarate Gets the maximum achievable data rate for LoRa modulation.
enum lorawan_status lorawan_status_t
lorawan_status_t contains status codes in response to stack operations
void mask_bit_set(uint16_t *mask, unsigned bit)
Tests if a channel is on or off in the channel mask.
void copy_channel_mask(uint16_t *dest_mask, uint16_t *src_mask, uint8_t len)
Copy channel masks.
virtual void restore_default_channels()
Enables default channels only.
void initialize(LoRaWANTimeHandler *lora_time)
Initialize LoRaPHY.
int8_t compute_tx_power(int8_t txPowerIndex, float maxEirp, float antennaGain)
Computes the txPower, based on the max EIRP and the antenna gain.
uint16_t * get_channel_mask(bool get_default=false)
get_channel_mask Gets the channel mask
bool is_custom_channel_plan_supported()
is_custom_channel_plan_supported Checks if custom channel plan is supported
uint8_t get_minimum_tx_datarate()
get_minimum_tx_datarate Gets the minimum TX datarate supported by a device
virtual uint8_t dl_channel_request(uint8_t channel_id, uint32_t rx1_frequency)
Processes a DlChannelReq MAC command.
The parameter structure for the function RegionNextChannel.
Definition: lora_phy_ds.h:430
uint8_t parse_link_ADR_req(const uint8_t *payload, uint8_t payload_size, link_adr_params_t *adr_params)
Parses the parameter of an LinkAdrRequest.
virtual uint8_t request_new_channel(int8_t channel_id, channel_params_t *new_channel)
Entertain a new channel request MAC command.
int32_t get_random(int32_t min, int32_t max)
Provides a random number in the range provided.
uint32_t get_ack_timeout()
get_ack_timeout Gets timeout value for ACK to be received
void calculate_backoff(bool joined, bool last_tx_was_join_req, bool dc_enabled, uint8_t channel, lorawan_time_t elapsed_time, lorawan_time_t tx_toa)
calculate_backoff Calculates and applies duty cycle back-off time.
Contains rx parameter setup request coming from network server.
Definition: lora_phy_ds.h:412
void get_rx_window_params(float t_symbol, uint8_t min_rx_symbols, float rx_error, float wakeup_time, uint32_t *window_length, uint32_t *window_length_ms, int32_t *window_offset, uint8_t phy_dr)
Computes the RX window timeout and the RX window offset.
bool get_next_ADR(bool restore_channel_mask, int8_t &dr_out, int8_t &tx_power_out, uint32_t &adr_ack_counter)
Calculates the next datarate to set, when ADR is on or off.
virtual bool rx_config(rx_config_params_t *config)
Configure radio reception.
bool disable_channel(uint16_t *channel_mask, uint8_t id, uint8_t max_channels)
Disables a channel in a given channels mask.
uint8_t get_max_nb_channels()
get_max_nb_channels Gets maximum number of channels supported
channel_params_t * get_phy_channels()
get_phy_channels Gets PHY channels
int8_t get_next_lower_tx_datarate(int8_t datarate)
get_next_lower_tx_datarate Gets the next lower datarate
int8_t get_next_lower_dr(int8_t dr, int8_t min_dr)
Get next lower data rate.
Data structures relating to PHY layer.
bool verify_nb_join_trials(uint8_t nb_join_trials)
verify_nb_join_trials Verifies that given number of trials is valid
int lookup_band_for_frequency(uint32_t freq) const
Looks up corresponding band for a frequency.
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset)
Computes new data rate according to the given offset.
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t *params)
Accept or rejects RxParamSetupReq MAC command.
void handle_receive(void)
Puts radio in receive mode.
This structure contains parameters for ADR request coming from network server.
Definition: lora_phy_ds.h:306
void set_radio_instance(LoRaRadio &radio)
Stores a reference to Radio object.
uint32_t get_radio_rng()
Provides a random number from radio.
virtual bool accept_tx_param_setup_req(uint8_t ul_dwell_time, uint8_t dl_dwell_time)
accept_tx_param_setup_req Makes decision whether to accept or reject TxParamSetupReq MAC command...
bool verify_rx_datarate(uint8_t datarate)
verify_rx_datarate Verifies that given RX datarate is valid
void put_radio_to_standby(void)
Puts radio in standby mode.
Interface for the radios, containing the main functions that a radio needs, and five callback functio...
Definition: LoRaRadio.h:440
DO NOT MODIFY, WILL BREAK THE API!
bool mask_bit_test(const uint16_t *mask, unsigned bit)
Tests if a channel is on or off in the channel mask.
uint8_t get_bandwidth(uint8_t dr_index)
Get channel bandwidth depending upon data rate table index.
Default user application maximum data size for transmission.
lorawan_time_t update_band_timeoff(bool joined, bool dutyCycle, band_t *bands, uint8_t nb_bands)
Updates the time-offs of the bands.
virtual void compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols, uint32_t rx_error, rx_config_params_t *rx_conf_params)
Computing Receive Windows.
uint16_t get_maximum_frame_counter_gap()
get_maximum_frame_counter_gap Gets maximum frame counter gap
void reset_to_default_values(loramac_protocol_params *params, bool init=false)
reset_to_default_values resets some parameters to default values
bool verify_duty_cycle(bool cycle)
verify_duty_cycle Verifies that given cycle is valid
uint8_t get_default_tx_power()
get_default_tx_power Gets the default TX power
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.