31 unsigned _rate,
unsigned _bandwidth, boost::uint8_t _linkTypeId, std::string
const & _info)
32 : coding(_coding), minRssi(_minRssi), rate(_rate), bandwidth(_bandwidth), linkTypeId(_linkTypeId), info(_info)
37 parameter.
id = boost::uint32_t(parameter.
linkTypeId) << 24 | boost::uint32_t(parameter.v_modulationId());
38 if (modulations_.count(parameter.
id) == 0)
39 modulations_.insert(parameter.
id, parameter.v_clone());
46 Modulations::const_iterator it (modulations_.find(
id));
47 if (it == modulations_.end())
59 os <<
" id: " <<
id << std::endl
60 <<
" coding: " <<
coding << std::endl
61 <<
" rate: " <<
rate << std::endl
62 <<
"bandwidth: " <<
bandwidth << std::endl
63 <<
"min. RSSI: " <<
minRssi << std::endl;
70 boost::format fmt (
"%10d%1.1s %11.11s %7d %9d %8d ");
71 os << fmt %
"id" %
"" %
"coding" %
"rate" %
"bandwidth" %
"min.RSSI";
72 v_dumpTableHeader(os);
79 boost::format fmt (
"%10d%1.1s %11.11s %7d %9d %8d ");
93 namespace fty = console::factory;
96 fty::Command(&WirelessInterface::listModulations,
this)
97 .doc(
"List wireless parameter configurations.") );
99 fty::Command(&WirelessInterface::listFrequencies,
this)
100 .doc(
"List wireless frequencies and bandwidths") );
103 .arg(
"frequency",
"frequency of new channel")
104 .doc(
"Change to new channel given by frequency. The bandwidth is not changed.\n" 105 "For valid frequencies and bandwidths, see 'frequencies'") );
108 .arg(
"frequency",
"frequency of new channel")
109 .arg(
"bandwidth",
"new channel bandwidth")
110 .doc(
"Change to new channel given by frequency and bandwidth. For valid frequencies and\n" 111 "bandwidths, see 'frequencies'") );
114 .arg(
"frequencyLower",
"frequency interval lower bound")
115 .arg(
"frequencyUpper",
"frequency interval upper bound")
116 .doc(
"add a whitelisted frequency range") );
119 .arg(
"center frequency",
"center frequency of the whitelisted channel in kHz")
120 .arg(
"bandwidth",
"bandwidth in kHz")
121 .doc(
"add a whitelisted channel") );
122 consoleDir().add(
"clearWhitelistedFrequencies",
124 .doc(
"clear all configured whitelisted frequencies") );
127 .arg(
"distance",
"distance in meters")
128 .doc(
"set coverage range") );
131 prefix_ void senf::emu::WirelessInterface::listModulations(std::ostream & os)
134 ModulationParameterIds
const & modIds (modulationParameterIds());
135 if (modIds.empty()) {
136 os <<
"no modulations configured" << std::endl;
142 cmid = transmitter().modulation();
143 os <<
"Current modulation: " << std::endl;
153 prefix_ void senf::emu::WirelessInterface::listFrequencies(std::ostream & os)
157 unsigned freq (frequency());
158 os <<
"Frequency: " << freq
159 <<
"\nBandwidth: " << bw <<
"\n\n";
160 boost::format fmt (
"%3d%1.1s %10d%1.1s%-10d %10d%1.1s%-10d\n");
162 %
"#" %
"" %
"FREQ" %
"U" %
"ENCY" %
"BAND" %
"W" %
"IDTH";
164 for (
Frequency const & f : frequencies()) {
167 % (f.bandwidthLower <= bw && f.bandwidthUpper >= bw &&
168 f.frequencyLower <= freq && f.frequencyUpper >= freq ?
"*" :
"")
170 % (f.frequencyLower == f.frequencyUpper ?
"" :
"-")
171 % (f.frequencyLower == f.frequencyUpper ?
"" : senf::str(f.frequencyUpper))
173 % (f.bandwidthLower == f.bandwidthUpper ?
"" :
"-")
174 % (f.bandwidthLower == f.bandwidthUpper ?
"" : senf::str(f.bandwidthUpper));
176 os <<
"Whitelisted Frequency Ranges:\n";
177 for (FrequencyInterval
const & f : whitelistedFrequencies_) {
178 os << f.first <<
" - " << f.second << std::endl;
182 prefix_ void senf::emu::WirelessInterface::lookupFrequency(
unsigned freq,
unsigned bw)
185 if (! frequency_is_whitelisted(whitelistedFrequencies_)(
freq-bw/2,
freq+bw/2))
191 if (dynamic_cast<senf::emu::HardwareWLANInterface const *>(
this) != NULL)
194 Frequencies::const_iterator i (
195 frequencies_.project<ByLower>(
196 frequencies_.get<ByUpper>().lower_bound(boost::make_tuple(bw,
freq))));
197 Frequencies::const_iterator i_end (
198 frequencies_.get<ByLower>().upper_bound(boost::make_tuple(bw,
freq)));
200 for (; i != i_end; ++i)
201 if (bw >= i->bandwidthLower && bw <= i->bandwidthUpper &&
202 ((
freq == i->frequencyLower &&
freq == i->frequencyUpper) ||
203 (
freq >= i->frequencyLower+bw/2 && freq <= i->frequencyUpper-bw/2)))
209 prefix_ senf::emu::WirelessInterface::frequency_is_whitelisted::frequency_is_whitelisted(FrequencyIntervals
const & whitelistedFrequencies)
210 : whitelistedFrequencies_(whitelistedFrequencies)
213 prefix_ bool senf::emu::WirelessInterface::frequency_is_whitelisted::operator()(
unsigned frequencyLower,
unsigned frequencyUpper)
215 if (whitelistedFrequencies_.empty())
217 for (FrequencyInterval
const & freqInterval : whitelistedFrequencies_) {
218 if (freqInterval.first <= frequencyLower && freqInterval.second >= frequencyUpper)
224 prefix_ bool senf::emu::WirelessInterface::frequency_is_whitelisted::operator()(
Frequency const & frequency)
227 "complex frequency ranges are not supported for whitelisting. Sorry.");
229 "complex frequency ranges are not supported for whitelisting. Sorry.");
236 if (frequencyUpper <= frequencyLower)
237 throw InvalidArgumentException(
"frequencyUpper (") << frequencyUpper <<
") <= frequencyLower (" << frequencyLower <<
")";
238 whitelistedFrequencies_.insert( std::make_pair(frequencyLower, frequencyUpper));
243 if (frequency < bandwidth/2)
245 whitelistedFrequencies_.insert( std::make_pair(frequency-bandwidth/2, frequency+bandwidth/2));
250 whitelistedFrequencies_.clear();
260 namespace fty = console::factory;
262 interface().consoleDir()
264 .arg(
"power",
"new transmit power")
265 .doc(
"Set current transmit power. Use 'txpowers' to list valid values or\n" 266 "get the current txpower value.") );
267 interface().consoleDir()
268 .add(
"txpowers", fty::Command(&WirelessTransmitter::listTxpowers,
this)
269 .doc(
"List valid transmit power values for current parameter configuration.\n" 270 "This lists depends on the selected parameter configuration !\n" 272 "The unit of the value listed in the POWER column is wireless interface type and\n" 273 "driver dependent.") );
276 prefix_ void senf::emu::WirelessTransmitter::listTxpowers(std::ostream & os)
280 os <<
"txPower: " << txp <<
"\n\n";
281 boost::format fmt (
"%3d%1.1s %9d%1.1s%-9d\n");
282 os << fmt %
"#" %
"" %
"PO" %
"W" %
"ER";
285 for (TxPowersRange::iterator i (p.begin()); i != p.end(); ++i, ++n)
288 % (i->lower <= txp && i->upper >= txp ?
"*" :
"")
290 % (i->lower == i->upper ?
"" :
"-")
291 % (i->lower == i->upper ?
"" : senf::str(i->upper));
297 return v_modulationId();
302 if (! senf::contains(interface().modulationParameterIds(),
id))
309 txPowers_.insert(
TxPower(power, power));
314 if (powerLower >= powerUpper)
316 << powerLower <<
" >= " << powerUpper;
317 txPowers_.insert(
TxPower(powerLower, powerUpper));
WirelessInterfaceAPI public header.
unsigned registerModulation(ModulationParameter ¶meter)
void registerTxPower(int power)
#define SENF_MEMBINDFNP(ret, cls, fn, args)
void clearWhitelistedFrequencies()
unsigned bandwidth
Bandwidth in KHz.
ModulationParameter const & findModulationById(ModulationParameter::id_t id) const
short minRssi
Minimum RSSI value.
Wireless modulation parameter.
Interface API base class specialization for wireless interfaces.
Transmit power table entry.
void whitelistedChannel(unsigned frequency, unsigned bandwidth)
unsigned rate
Bitrate in kbit/s.
void init()
Initialize interface.
console::ScopedDirectory & consoleDir()
void dump(std::ostream &os) const
void coverageRange(unsigned distance)
set the coverage range of the interface in meters
boost::iterator_range< TxPowers::const_iterator > TxPowersRange
unsigned bandwidthLower
Bandwidth interval lower bound.
boost::uint8_t linkTypeId
void dumpTableHeader(std::ostream &os) const
#define SENF_ASSERT(x, comment)
void whitelistedFrequencyRange(unsigned frequencyLower, unsigned frequencyUpper)
static ModulationParameterRegistry & instance()
void dumpTableRow(std::ostream &os, bool is_current_modulation) const
Transmit capable wireless interface base class.
unsigned frequencyLower
Frequency interval lower bound.
ModulationParameter(std::string const &_coding, short _minRssi, unsigned _rate, unsigned _bandwidth, boost::uint8_t _linkTypeId, std::string const &_info="")
unsigned bandwidthUpper
Bandwidth interval upper bound.
ModulationParameter::id_t modulation() const
Get current modulation parameter configuration id.
HardwareWLANInterface public header.
unsigned frequencyUpper
Frequency interval upper bound.