47 : TclClass(
"Module/UW/ElectroMagnetic/PHY")
59 , lut_token_separator_(
',')
60 , rxPowerThreshold_(-200)
62 if (!MPhy_Bpsk::initialized) {
65 MPhy_Bpsk::initialized =
true;
75 if (strcasecmp(argv[1],
"useLUT") == 0) {
79 }
else if (argc == 3) {
80 if (strcasecmp(argv[1],
"setLUTFileName") == 0) {
81 string tmp_ = ((
char *) argv[2]);
82 if (tmp_.size() == 0) {
83 fprintf(stderr,
"Empty string for the file name");
88 }
else if (strcasecmp(argv[1],
"setLUTSeparator") == 0) {
89 string tmp_ = ((
char *) argv[2]);
90 if (tmp_.size() == 0) {
91 fprintf(stderr,
"Empty char for the file name");
98 return MPhy_Bpsk::command(argc, argv);
104 hdr_MPhy *ph = HDR_MPHY(p);
105 if ((PktRx == 0) && (txPending ==
false)) {
108 if (ph->modulationType == MPhy_Bpsk::modid) {
114 std::cout <<
"UwElectroMagneticPhy::Drop Packet::Wrong modulation"
119 cout << NOW <<
" UwElectroMagneticPhy: Drop Packet::Below Threshold : received power = "
127 std::cout <<
"UwElectroMagneticPhy::Drop Packet::Synced onto another packet "
129 << PktRx <<
", pending = " << txPending << std::endl;
138 hdr_cmn *ch = HDR_CMN(p);
143 std::cout << NOW <<
" UwElectroMagneticPhy: RSSI= " << rx_power << std::endl;
145 double PER =
getPER(rx_power);
147 std::cout << NOW <<
" UwElectroMagneticPhy: interpolated PER = " << PER << std::endl;
150 double x = RNG::defaultrng()->uniform_double();
179 hdr_MPhy *ph = HDR_MPHY(p);
182 std::cout <<
" UwElectroMagneticPhy: TxAntenna= " << ph->srcAntenna->getGain(p) << std::endl;
183 std::cout <<
" UwElectroMagneticPhy: RxAntenna= " << ph->dstAntenna->getGain(p) << std::endl;
186 double tot_attenuation =propagation_->getGain(p);
189 double rx_power = TxPower_ + ph->srcAntenna->getGain(p) + ph->dstAntenna->getGain(p) - tot_attenuation;
191 rx_power = pow(10,(rx_power/10));
201 RSSIMap::iterator it =
lut_map.lower_bound(rx_power);
203 if (it !=
lut_map.end() && it->first == rx_power) {
205 std::cout << rx_power <<
" " << it->first <<
" " << it->second
211 if (it ==
lut_map.end() && it->first != rx_power) {
214 if (it ==
lut_map.begin() && it->first != rx_power) {
219 RSSIMap::iterator u_it = it;
221 return linearInterpolator(rx_power, it->first, it->second, u_it->first, u_it->second)/100;
226 double x,
double x1,
double y1,
double x2,
double y2)
229 double m = (y1 - y2) / (x1 - x2);
230 double q = y1 - m * x1;
237 ifstream input_file_;
240 if (input_file_.is_open()) {
243 while (std::getline(input_file_, line_)) {
244 ::std::stringstream line_stream(line_);
UwElectroMagneticPhyClass()
TclObject * create(int, const char *const *)
UwElectroMagneticPhy()
Constructor of UwElectroMagneticPhy class.
virtual double linearInterpolator(double x, double x1, double y1, double x2, double y2)
virtual void initializeLUT()
Inizialize LUT of c_variable values.
char lut_token_separator_
RSSIMap lut_map
Lookup table map of the RSSI versus PER.
double getPER(double rx_power)
double getRxPower(Packet *p)
virtual int command(int, const char *const *)
TCL command interpreter.
UwElectroMagneticPhyClass class_UwElectroMagneticPhyClass
Definition of UwEm class.
#define ELECTROMAGNETIC_MODULATION_TYPE