DESERT 3.5.1
Loading...
Searching...
No Matches
uwranging_tdoa.h
Go to the documentation of this file.
1//
2// Copyright (c) 2022 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
39#ifndef UWRANGINGTDOA_H
40#define UWRANGINGTDOA_H
41
42#include "uwranging_tdoa_hdr.h"
43#include <module.h>
44#include <limits>
45#include <vector>
46
47class UwRangingTDOA;
48
52class UwRangeTimer : public TimerHandler
53{
54public:
56 : TimerHandler()
57 {
58 module = m;
59 }
60
61protected:
62 virtual void expire(Event *e);
63 UwRangingTDOA *module;
64};
65
69class UwRangingTDOA : public Module
70{
71
72 friend class UwRangeTimer;
73
74public:
79
83 virtual ~UwRangingTDOA() = default;
84
90 virtual void recv(Packet *) override;
91
98 virtual void recv(Packet *p, Handler *h) override;
99
104 virtual int recvSyncClMsg(ClMessage *m) override;
105
113 virtual int command(int argc, const char *const *argv) override;
114
118 virtual void start();
119
123 virtual void stop();
124
125protected:
131 virtual bool isValid(double value) const;
132
138 virtual bool isValid(const tdoa_entry &entry) const;
139
143 virtual void rangeTX();
144
145 /* Performs the reception of a ranging message.
146 * @param Packet* Pointer to the packet received.
147 */
148 virtual void rangeRX(const Packet * p);
149
154 virtual void updateHoldoverTime(Packet *p, double tx_duration);
155
160 virtual int calcOptEntries(std::vector<int> *sorted_entries = nullptr) const;
161
167 virtual double entryWeight(int entry, int pkt_size, int mode) const;
168
170 virtual void throttleTX();
171
185 int phy_id;
189 double max_tt;
190 double max_age;
192 double delay_start;
194 double soundspeed;
196 std::vector<std::vector<int>> tof_map; /*< Map between couples of nodes to a distance. */
197 std::vector<std::vector<std::vector<tdoa_entry>>> entries_mat; /*< Matrix containing the entries for each packet. */
198 std::vector<std::vector<double>> times_mat; /*< Matrix containing the tx/rx times of each packet. */
199 std::vector<int> last_ids; /*< Vector of ids of the last rx/tx packet. */
200 std::vector<double> time_of_flights; /*< Vector of one way travel times between each nodes in the network. */
201 std::vector<double> entries_timestamps; /*< Vector of the times at which each one way travel time is computed. */
202 std::vector<double> entry_last_tx;
203 std::vector<uwrange_time_t> tx_timestamp;
204 std::vector<double> ber; /*< Vector fo the BER of each channel (symmetry assumption). */
205
206 const size_t PKTIDMAX = std::numeric_limits<uwrange_pkt_t>::max();
207};
208
209#endif
UwRangeTimer class is used to schedule the transmission of ranging packets.
virtual void expire(Event *e)
UwRangeTimer(UwRangingTDOA *m)
Class that represents a UwRangingTDOA Node.
double delay_start
Starting delay in seconds.
int dist_num
Number of distances each node computes.
virtual void updateHoldoverTime(Packet *p, double tx_duration)
Update the holdover time with the actual time of transmission.
double full_pkt_tx_dur
TX duration for a full range packet.
virtual void recv(Packet *) override
Performs the reception of packets from upper and lower layers.
virtual int calcOptEntries(std::vector< int > *sorted_entries=nullptr) const
Compute the optimal number of entries for the ranging message.
std::vector< double > entries_timestamps
int phy_id
Id of the PHY module.
virtual void rangeRX(const Packet *p)
int range_pkts_recv
Counter of received ranging packets.
double max_tt
Floating numbers within this value won't be discarded by NNLS.
virtual void stop()
Stop to send packets.
virtual int recvSyncClMsg(ClMessage *m) override
Retrieve packets from other modules.
int range_entries
Number of entries per ranging packet, if <= 0 enable adaptive payload size.
int n_nodes
Number of nodes.
virtual void rangeTX()
Send a ranging message down to the MAC layer.
UwRangingTDOA()
Constructor of the UwRangingTDOA class.
UwRangeTimer send_timer
Timer that schedules ranging packet transmissions.
int range_pkts_sent
Counter of sent ranging packets.
int packet_id
id of the last ranging packet sent (= node_id + k*n_nodes)
const size_t PKTIDMAX
Max number of ranging packets that can be saved.
std::vector< double > entry_last_tx
Vector of the last (actual) TX times of each entry.
std::vector< std::vector< int > > tof_map
std::vector< double > time_of_flights
bool scheduler_active
True if the ranging scheduler is been activated with Tcl "start" command.
int saved_entries
Total number of entries not sent in the ranging packets.
int range_bytes_sent
Counter of sent ranging bytes.
virtual ~UwRangingTDOA()=default
Destructor of the UwRangingTDOA class.
double max_age
Max age of a ranging packet in seconds.
virtual int command(int argc, const char *const *argv) override
TCL command interpreter.
std::vector< int > last_ids
int range_pkts_err
Counter of lost ranging packets.
double range_period
Ranging period in seconds.
std::vector< std::vector< double > > times_mat
virtual double entryWeight(int entry, int pkt_size, int mode) const
Compute the weight of the entry given the packet size in bits.
virtual bool isValid(double value) const
Check if value is not negative.
int poisson_traffic
If true the ranging packets are sent according to a poisson process with rate range_period.
std::vector< std::vector< std::vector< tdoa_entry > > > entries_mat
virtual void start()
Start to send packets.
int node_id
Id of the current node.
std::vector< uwrange_time_t > tx_timestamp
Vector of the TX timestamp for each packet to be sent.
double soundspeed
Speed of sound in m/s.
virtual void throttleTX()
Schedule the transmission of a rangig message.
int queue_size
Counts the packet sent to the MAC waiting to be transmitted.
std::vector< double > ber
Define the struct of a single tdoa payload entry.
Common structures and variables in the protocol.