~jan-ellenbeck/openwns-rise/LTEantennaAndSpeedUp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*******************************************************************************
 * This file is part of openWNS (open Wireless Network Simulator)
 * _____________________________________________________________________________
 *
 * Copyright (C) 2004-2007
 * Chair of Communication Networks (ComNets)
 * Kopernikusstr. 5, D-52074 Aachen, Germany
 * phone: ++49-241-80-27910,
 * fax: ++49-241-80-22242
 * email: info@openwns.org
 * www: http://www.openwns.org
 * _____________________________________________________________________________
 *
 * openWNS is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License version 2 as published by the
 * Free Software Foundation;
 *
 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/
#include <RISE/receiver/PowerMeasurement.hpp>

using namespace rise::receiver;

PowerMeasurement::PowerMeasurement()
    : wns::service::phy::power::PowerMeasurementInterface(),
	  rxPower(),
	  interference(),
	  omniAttenuation(),
	  noise(),
	  txPower(),
	  phyModePtr(NULL),
	  //distance(0),
	  subChannel(0),
	  transmitterStation(NULL)
	  //sourceNode(NULL),
	  //systemManager(NULL)
{
}

// same interface values as OFDMAPhy::Station::receiveData()
PowerMeasurement::PowerMeasurement(wns::Power rxPower, wns::Power interference, wns::Ratio omniAttenuation)
    : wns::service::phy::power::PowerMeasurementInterface(),
	  rxPower(rxPower),
	  interference(interference),
	  omniAttenuation(omniAttenuation),
	  noise(), // todo
	  txPower(), // todo
	  phyModePtr(), // todo
	  //distance(0), // todo
	  subChannel(0), // todo
	  transmissionObjectPtr(NULL),
	  transmitterStation(NULL)
	  //sourceNode(NULL), // todo
	  //systemManager(NULL)
{
}

// same interface values as OFDMAPhy::Station::receiveData()
PowerMeasurement::PowerMeasurement(rise::TransmissionObjectPtr t, wns::node::Interface* _sourceNode, wns::Power _rxPower, wns::Power _interference, wns::Ratio _omniAttenuation, int _subChannel)
    : wns::service::phy::power::PowerMeasurementInterface(), // inherited
	  rxPower(_rxPower),
	  interference(_interference),
	  omniAttenuation(_omniAttenuation),
	  noise(), // todo
	  //txPower(t->getTxPower()),
	  //phyModePtr(),
	  //distance(0), // todo
	  subChannel(_subChannel),
	  transmissionObjectPtr(t),
	  transmitterStation(NULL),
	  sourceNode(_sourceNode) // we need a node provider to get that ourself (rise:no, ofdmaphy:yes)
	  //systemManager(NULL)
{
	// these are the useful things we can get from the TransmissionObjectPtr t:
	assure(t,"transmissionObjectPtr==NULL");
	assure(transmissionObjectPtr,"transmissionObjectPtr==NULL");
	// TODO: replace t by member transmissionObjectPtr
	txPower = t->getTxPower();
	wns::service::phy::phymode::PhyModeInterfacePtr t_phyModePtr = t->getPhyModePtr(); // SmartPtr
	if (t_phyModePtr) { // !=NULL
		assure(t_phyModePtr,"phyModePtr==NULL");
		//phyModePtr = wns::service::phy::phymode::PhyModeInterfacePtr(t->getPhyModePtr());
		phyModePtr = t_phyModePtr;
	} else { // phyModePtr == NULL (happens in ofdmaphy::tests::OFDMATest::testGetRxPower)
		//phyModePtr = wns::service::phy::phymode::PhyModeInterfacePtr(&wns::service::phy::phymode::emptyPhyMode());
		phyModePtr = wns::service::phy::phymode::PhyModeInterfacePtr(); // empty
	}
	rise::Transmitter* transmitter = t->getTransmitter();
	assure(transmitter != NULL,"transmitter==NULL");
	// int32_t transmitterId = transmitter->getTransmitterId();
	// int32_t stationId = transmitter->getStation()->getStationId();
	// antenna::Antenna* antennaTx = transmitter->getAntenna();
	// antenna::Antenna* antennaRx = rise::receiver->getAntenna();
	//medium::PhysicalResource* physicalResource = t->getPhysicalResource();
	//assure(physicalResource != NULL,"physicalResource==NULL");
	// double f=physicalResource->getFrequency(); // Returns the mid-frequency
	// double b=physicalResource->getBandwidth();
	//rise::Station*
	transmitterStation = transmitter->getStation(); // static_cast<rise::Station*>(transmitter->getStation())
	assure(transmitterStation != NULL,"transmitterStation==NULL");
	//ofdmaphy::Station* transmitterStation = transmitter->getStation(); // static_cast<rise::Station*>(transmitter->getStation())
	//ofdmaphy::Station* OFDMAStation = dynamic_cast<ofdmaphy::Station*>(t->getTransmitter()->getStation());
	//std::string userName = OFDMAStation->getNode()->getName();
	//int32_t transmitterStationId = transmitterStation->getStationId();
	//wns::node::Interface* peerNode = transmitterStation->getNode(); // returns component->getNode()
	//wns::node::Interface* peerNode = ofdmaStation->getNode(); // returns component->getNode()
	// rise::SystemManager* systemManager = Station::getSystemManager()
	//ofdmaStation->systemManager->getStation(peerNode); // opposite way
	//Station* recipient = ofdmaStation->systemManager->getStation(wns::node::Interface* _recipient)
	//wns::osi::PDUPtr payload = t->getPayload();
	// /*rise::TransmissionObject::linkmode*/ uint32_t linkmode = t->getLinkMode(); // DL=0, UL=1, direct=2
	//txPower = t->getTxPower();
	//phyModePtr = t->getPhyModePtr();
}

PowerMeasurement::~PowerMeasurement()
{
}

const wns::Power
PowerMeasurement::getRxPower() const
{
	return rxPower;
}

const wns::Power
PowerMeasurement::getInterferencePower() const
{
	return interference;
}

const wns::Power
PowerMeasurement::getOmniInterferencePower() const
{
	return wns::Power::from_mW(interference.get_mW() / omniAttenuation.get_factor());
	// ^ same as this:
	//return interference - omniAttenuation;
}

const wns::Power
PowerMeasurement::getNoisePower() const
{
	assure(false,"not yet implemented");
	return noise;
}

const wns::Ratio
PowerMeasurement::getSINR() const
{
	return rxPower / interference; // interference contains noise
}

const double
PowerMeasurement::getMI() const
{
	assure(phyModePtr, "invalid phyModePtr");
	return phyModePtr->getSINR2MI(getSINR());
}

const double
PowerMeasurement::getMIB() const
{
	assure(phyModePtr, "invalid phyModePtr");
	return phyModePtr->getSINR2MIB(getSINR());
}

const wns::Power
PowerMeasurement::getTxPower() const
{
	return txPower;
}

const wns::Ratio
PowerMeasurement::getPathLoss() const
{
	return txPower/rxPower;
}

const wns::Power
PowerMeasurement::getRSS() const // received signal strength (S+I)
{
	return rxPower+interference;
}

const wns::service::phy::phymode::PhyModeInterfacePtr
PowerMeasurement::getPhyMode() const
{
	assure(phyModePtr,"phyModePtr==NULL");
	return phyModePtr;
}

/*
// meters between sender and receiver [m]
const double PowerMeasurement::getDistance() const
{
	assure(false,"not yet implemented");
	//double Station::getDistance(PositionableInterface* p)
	// rise::Transmitter* transmitter    = transmissionObjectPtr->getTransmitter();
	// rise::Station* transmitterStation = transmitter->getStation();
	assure(transmitterStation != NULL,"transmitterStation==NULL");
	double distance = transmitterStation->getDistance(receiverStation);
	return distance;
}
*/

// OFDMA subchannel used
const int PowerMeasurement::getSubChannel() const
{
	// assure(false,"not yet implemented");
	// it seems to work for us...
	return subChannel;
}

const rise::Station* PowerMeasurement::getSourceStation() const
{
	// rise::Transmitter* transmitter    = transmissionObjectPtr->getTransmitter();
	// rise::Station* transmitterStation = transmitter->getStation();
	assure(transmitterStation != NULL,"transmitterStation==NULL");
	return transmitterStation;
}

//const
wns::node::Interface* PowerMeasurement::getSourceNode() const
{
	// rise::Transmitter* transmitter    = transmissionObjectPtr->getTransmitter();
	// rise::Station* transmitterStation = transmitter->getStation();
	//wns::node::Interface* sourceNode = transmitterStation->getNode(); // only possible for OFDMAPhy
	// only OFDMAPhy::Station knows its node.
	assure(sourceNode != NULL,"sourceNode==NULL");
	return sourceNode;
}

/*
void PowerMeasurement::setSystemManager(rise::SystemManager* _systemManager) {
	systemManager=_systemManager;
}
*/

std::string PowerMeasurement::getString() const
{
	std::stringstream line;
	line << "[RxP="<<getRxPower()<<", I="<<getInterferencePower()<<", SINR="<<getSINR()<<"]";
	return line.str();
}