1 #include "LibCyberRadio/NDR651/RadioController.h" 8 RadioController::RadioController(
const std::string& radioHostname,
unsigned short radioPort,
bool debug):
9 Debuggable(debug,
"RadioController"),
10 radioHostname(radioHostname),
14 this->clientSocket =
new ClientSocket(radioHostname, radioPort);
17 RadioController::~RadioController()
19 if (this->clientSocket != NULL)
21 delete this->clientSocket;
26 void RadioController::dumpRspVec()
28 for (
int i = 0; i < this->rspVec.size(); i++)
30 std::cout <<
"Val: " << this->rspVec.at(i) <<
" Ind: " << i << std::endl;
34 bool RadioController::sendCmd(
const std::string& cmd,
bool splitResponse)
37 if (!this->clientSocket->connectToServer())
39 throw std::runtime_error(
"ClientSocket could not connect to radio");
42 if (this->clientSocket != NULL && this->clientSocket->isConnected())
44 bool cmdError =
false;
48 cmdError = this->clientSocket->sendCmdAndGetRsp(cmd, this->rspVec, CMD_TIMEOUT);
53 boost::split(this->rspVec, this->rspVec.at(0), boost::algorithm::is_any_of(
" ,"));
57 this->clientSocket->disconnect();
61 this->debug(
"clientSocket is NULL or not connected\n");
65 bool RadioController::sendCmdAndQry(
const std::string& cmd,
const std::string& qry,
bool splitResponse)
68 if (!this->clientSocket->connectToServer())
70 throw std::runtime_error(
"ClientSocket could not connect to radio");
73 if (this->clientSocket != NULL && this->clientSocket->isConnected())
75 bool cmdError =
false;
79 cmdError = this->clientSocket->sendCmdAndGetRsp(cmd, this->rspVec, CMD_TIMEOUT);
85 cmdError |= this->clientSocket->sendCmdAndGetRsp(qry, this->rspVec, CMD_TIMEOUT);
90 boost::split(this->rspVec, this->rspVec.at(0), boost::algorithm::is_any_of(
" ,"));
94 this->clientSocket->disconnect();
98 this->debug(
"clientSocket is NULL or not connected\n");
103 std::string RadioController::getRadioMac(
unsigned int tenGbeIndex)
105 std::string cmd = (boost::format(
"#MAC? %d\n") % tenGbeIndex).str();
106 return this->sendCmd(cmd) ? this->rspVec.at(1) :
"";
109 std::string RadioController::getRadioIP(
unsigned int tenGbeIndex)
111 std::string cmd = (boost::format(
"SIP? %d\n") % tenGbeIndex).str();
112 return this->sendCmd(cmd) ? this->rspVec.at(3) :
"";
115 bool RadioController::setTXF(
unsigned int rfTxChannel,
double freq)
122 if (rfTxChannel==3) {
126 rv[i] = this->setTXF(++i, freq);
130 std::string cmd, qry;
131 double epsilon = 0.000001;
134 qry = (boost::format(
"SHF? %d, 1\n") % rfTxChannel).str();
135 if (!this->sendCmd(qry))
return false;
136 unsigned int currentShf = atoi(this->rspVec.at(5).c_str());
139 qry = (boost::format(
"TXF? %d\n") % rfTxChannel).str();
140 if (!this->sendCmd(qry))
return false;
141 double setFreq = atof(this->rspVec.at(3).c_str());
144 if ((currentShf == 1) && (setFreq <= 200) && (freq > 200))
147 this->setSHF(rfTxChannel, 0);
149 else if ((currentShf == 0) && ((setFreq > 200) || (setFreq < epsilon)) && (freq <= 200))
152 this->setSHF(rfTxChannel, 1);
156 cmd = (boost::format(
"TXF %d, %f\n") % rfTxChannel % freq).str();
157 qry = (boost::format(
"TXF? %d\n") % rfTxChannel).str();
158 if (this->sendCmdAndQry(cmd, qry))
160 setFreq = atof(this->rspVec.at(3).c_str());
161 return (std::abs(setFreq - freq) < epsilon);
167 double RadioController::getTXA(
unsigned int channel)
170 std::string qry = (boost::format(
"TXA? %d\n") % channel).str();
171 if (this->sendCmd(qry))
173 ret = atof(this->rspVec.at(3).c_str());
178 bool RadioController::setTXA(
unsigned int channel,
double attenuation)
184 rv[i] = this->setTXA(++i, attenuation);
188 std::string cmd = (boost::format(
"TXA %d, %f\n") % channel % attenuation).str();
189 std::string qry = (boost::format(
"TXA? %d\n") % channel).str();
190 if (this->sendCmdAndQry(cmd, qry))
192 double setAttenuation = atof(this->rspVec.at(3).c_str());
193 double epsilon = 1.0;
194 return (std::fabs(setAttenuation - attenuation) < epsilon);
201 bool RadioController::setTXP(
unsigned int channel,
bool enable)
207 rv[i] = this->setTXP(++i, enable);
211 std::string cmd = (boost::format(
"TXP %d, %d\n") % channel % (int)(enable)).str();
212 std::string qry = (boost::format(
"TXP? %d\n") % channel).str();
215 if (!this->sendCmd(qry))
return false;
216 bool setEnable = atof(this->rspVec.at(3).c_str());
217 if (setEnable == enable)
return false;
219 if (this->sendCmdAndQry(cmd, qry))
221 setEnable = (bool)(atoi(this->rspVec.at(3).c_str()));
222 return setEnable == enable;
228 bool RadioController::setTXINV(
unsigned int ducChannel,
bool invert)
230 std::string cmd = (boost::format(
"TXINV %d, %d\n") % ducChannel % (int)(invert)).str();
231 std::string qry = (boost::format(
"TXINV? %d\n") % ducChannel).str();
232 if (this->sendCmdAndQry(cmd, qry))
234 bool setInvert = (bool)(atoi(this->rspVec.at(3).c_str()));
235 return setInvert == invert;
240 bool RadioController::setDUCP(
unsigned int ducChannel,
bool pause)
242 std::string cmd = (boost::format(
"DUCP %d, %d\n") % ducChannel % (int)(pause)).str();
243 std::string qry = (boost::format(
"DUCP? %d\n") % ducChannel).str();
244 if (this->sendCmdAndQry(cmd, qry))
246 bool setPause = (bool)(atoi(this->rspVec.at(3).c_str()));
247 return setPause == pause;
252 bool RadioController::setDUCA(
unsigned int ducChannel,
double attenuation)
254 std::string cmd = (boost::format(
"DUCA %d, %f\n") % ducChannel % attenuation).str();
255 std::string qry = (boost::format(
"DUCA? %d\n") % ducChannel).str();
256 if (this->sendCmdAndQry(cmd, qry))
258 double setAttenuation = atof(this->rspVec.at(3).c_str());
259 double epsilon = 0.2;
260 return (std::fabs(setAttenuation - attenuation) <= epsilon);
265 bool RadioController::setDUCF(
unsigned int ducChannel,
double freq)
267 std::string cmd = (boost::format(
"DUCF %d, %f\n") % ducChannel % freq).str();
268 std::string qry = (boost::format(
"DUCF? %d\n") % ducChannel).str();
269 if (this->sendCmdAndQry(cmd, qry))
271 double setFreq = atof(this->rspVec.at(3).c_str());
272 return setFreq == freq;
277 bool RadioController::clearDUCG(
unsigned int ducGroup)
279 std::string cmd, qry;
281 for (
int i = 1; i <= 8; i++)
283 cmd = (boost::format(
"DUCG %d, %d, 0\n") % ducGroup % i).str();
284 qry = (boost::format(
"DUCG? %d, %d\n") % ducGroup % i).str();
285 if (this->sendCmdAndQry(cmd, qry))
287 unsigned int setEnable = (
unsigned int)(atoi(this->rspVec.at(5).c_str()));
288 success &= (setEnable == 0);
294 bool RadioController::setDUCG(
unsigned int ducGroup,
unsigned int ducChannel,
bool enable)
296 std::string cmd = (boost::format(
"DUCG %d, %d, %d\n") % ducGroup % ducChannel % enable).str();
297 std::string qry = (boost::format(
"DUCG? %d, %d\n") % ducGroup % ducChannel).str();
298 if (this->sendCmdAndQry(cmd, qry))
300 bool setEnable = (bool)(atoi(this->rspVec.at(5).c_str()));
301 return (setEnable == enable);
307 bool RadioController::setDUCGE(
unsigned ducGroup,
bool enable)
309 std::string cmd = (boost::format(
"DUCGE %d, %d\n") % ducGroup % enable).str();
310 std::string qry = (boost::format(
"DUCGE? %d\n") % ducGroup).str();
311 if (this->sendCmdAndQry(cmd, qry))
313 bool setEnable = (bool)(atoi(this->rspVec.at(3).c_str()));
314 return (setEnable == enable);
320 bool RadioController::setSHF(
unsigned int rfTxChannel,
bool enable)
322 std::string cmd = (boost::format(
"SHF %d, 1, %d\n") % rfTxChannel % (int)(enable)).str();
323 std::string qry = (boost::format(
"SHF? %d, 1\n") % rfTxChannel).str();
324 if (this->sendCmdAndQry(cmd, qry))
326 bool shfEnable = (bool)(atoi(this->rspVec.at(5).c_str()));
327 return shfEnable == enable;
332 bool RadioController::setSIP(
unsigned int tenGbeIndex,
const std::string& sourceIP)
334 std::string cmd = (boost::format(
"SIP %d, %s\n") % tenGbeIndex % sourceIP).str();
335 std::string qry = (boost::format(
"SIP? %d\n") % tenGbeIndex).str();
336 if (this->sendCmdAndQry(cmd, qry))
338 std::string setSIP = this->rspVec.at(3);
339 return setSIP == sourceIP;
344 bool RadioController::setDIP(
345 unsigned int ducChannel,
346 unsigned int tenGbeIndex,
347 const std::string& destIP,
348 const std::string& destMAC,
349 unsigned short ducStatusPort
353 unsigned int ducDipIndex = 32 - ducChannel;
354 std::string cmd = (boost::format(
"DIP %d, %d, %s, %s, %d, %d\n") % tenGbeIndex % ducDipIndex % destIP % destMAC % ducStatusPort % ducStatusPort ).str();
355 std::string qry = (boost::format(
"DIP? %d, %d\n") % tenGbeIndex % ducDipIndex ).str();
356 if (this->sendCmdAndQry(cmd, qry))
360 success &= (this->rspVec.at(11) == destIP);
361 success &= (this->rspVec.at(13) == destMAC);
362 success &= (atoi(this->rspVec.at(15).c_str()) == ducStatusPort);
363 success &= (atoi(this->rspVec.at(17).c_str()) == ducStatusPort);
369 bool RadioController::setDUC(
371 unsigned int tenGbeIndex,
374 unsigned int ducRateIndex,
375 unsigned int rfTxChannel,
377 unsigned int streamID
380 std::string cmd = (boost::format(
"DUC %d, %d, %d, %f, %d, %d, %d, %d\n") % ducChannel % tenGbeIndex % ducFreq % attenuation % ducRateIndex % rfTxChannel % mode % streamID ).str();
381 std::string qry = (boost::format(
"DUC? %d\n") % ducChannel ).str();
382 if (this->sendCmdAndQry(cmd, qry))
385 success &= (atoi(this->rspVec.at(3).c_str()) == tenGbeIndex);
386 success &= (atof(this->rspVec.at(5).c_str()) == ducFreq);
388 double setAttenuation = atof(this->rspVec.at(7).c_str());
389 double epsilon = 0.1;
390 success &= (std::abs(setAttenuation - attenuation) < epsilon);
392 success &= (atoi(this->rspVec.at(9).c_str()) == ducRateIndex);
393 success &= (atoi(this->rspVec.at(11).c_str()) == rfTxChannel);
394 success &= (atoi(this->rspVec.at(13).c_str()) == mode);
395 success &= (atoi(this->rspVec.at(15).c_str()) == streamID);
401 bool RadioController::setDUCHS(
402 unsigned int ducChannel,
403 unsigned int tenGbeIndex,
404 unsigned int fullThresh,
405 unsigned int emptyThresh,
406 unsigned int duchsPeriod,
407 unsigned int ducStreamID
410 unsigned int ducDipIndex = 32 - ducChannel;
411 std::string cmd = (boost::format(
"DUCHS %d, %d, %d, %d, %d, %d, 0, %d\n") % ducChannel % tenGbeIndex % fullThresh % emptyThresh % duchsPeriod % ducDipIndex % ducStreamID ).str();
412 std::string qry = (boost::format(
"DUCHS? %d\n") % ducChannel ).str();
413 if (this->sendCmdAndQry(cmd, qry))
416 success &= (atoi(this->rspVec.at(3).c_str()) == tenGbeIndex);
417 success &= (atoi(this->rspVec.at(5).c_str()) == fullThresh);
418 success &= (atoi(this->rspVec.at(7).c_str()) == emptyThresh);
419 success &= (atoi(this->rspVec.at(9).c_str()) == duchsPeriod);
420 success &= (atoi(this->rspVec.at(11).c_str()) == ducDipIndex);
421 success &= (atoi(this->rspVec.at(15).c_str()) == ducStreamID);
431 bool RadioController::setDUCHSPercent(
432 unsigned int ducChannel,
433 unsigned int tenGbeIndex,
434 double fullThreshPercent,
435 double emptyThreshPercent,
436 unsigned int updatesPerSecond,
437 unsigned int ducStreamID
440 unsigned int ducDipIndex = 32 - ducChannel;
441 unsigned int fullThresh, emptyThresh, duchsPeriod;
443 fullThresh = ((
unsigned int )(fullThreshPercent * 67108860)) - ((
unsigned int )(fullThreshPercent * 67108860)%4);
444 emptyThresh = ((
unsigned int )(emptyThreshPercent * 67108860)) - ((
unsigned int )(emptyThreshPercent * 67108860)%4);
445 if ((updatesPerSecond > 0) && (updatesPerSecond <= 200))
447 duchsPeriod = 1000/5/updatesPerSecond;
455 std::string cmd = (boost::format(
"DUCHS %d, %d, %d, %d, %d, %d, 0, %d\n") % ducChannel % tenGbeIndex % fullThresh % emptyThresh % duchsPeriod % ducDipIndex % ducStreamID ).str();
456 std::string qry = (boost::format(
"DUCHS? %d\n") % ducChannel ).str();
457 if (this->sendCmdAndQry(cmd, qry))
460 success &= (atoi(this->rspVec.at(3).c_str()) == tenGbeIndex);
461 success &= (atoi(this->rspVec.at(5).c_str()) == fullThresh);
462 success &= (atoi(this->rspVec.at(7).c_str()) == emptyThresh);
463 success &= (atoi(this->rspVec.at(9).c_str()) == duchsPeriod);
464 success &= (atoi(this->rspVec.at(11).c_str()) == ducDipIndex);
465 success &= (atoi(this->rspVec.at(15).c_str()) == ducStreamID);
471 bool RadioController::clearDUC(
unsigned int ducChannel)
473 std::string cmd = (boost::format(
"DUC %d, 0, 0, 0, 0, 0, 0, 0\n") % ducChannel).str();
474 std::string qry = (boost::format(
"DUC? %d\n") % ducChannel).str();
475 if (this->sendCmdAndQry(cmd, qry))
478 success &= (atoi(this->rspVec.at(3).c_str()) == 0);
479 success &= (atoi(this->rspVec.at(5).c_str()) == 0);
480 success &= (atoi(this->rspVec.at(7).c_str()) == 0);
481 success &= (atoi(this->rspVec.at(9).c_str()) == 0);
482 success &= (atoi(this->rspVec.at(11).c_str()) == 0);
483 success &= (atoi(this->rspVec.at(13).c_str()) == 0);
484 success &= (atoi(this->rspVec.at(15).c_str()) == 0);
490 bool RadioController::clearDUCHS(
unsigned int ducChannel)
492 std::string cmd = (boost::format(
"DUCHS %d, 0, 0, 0, 0, 0, 0, 0\n") % ducChannel).str();
493 std::string qry = (boost::format(
"DUCHS? %d\n") % ducChannel).str();
494 if (this->sendCmdAndQry(cmd, qry))
497 success &= (atoi(this->rspVec.at(3).c_str()) == 0);
498 success &= (atoi(this->rspVec.at(5).c_str()) == 0);
499 success &= (atoi(this->rspVec.at(7).c_str()) == 0);
500 success &= (atoi(this->rspVec.at(9).c_str()) == 0);
501 success &= (atoi(this->rspVec.at(11).c_str()) == 0);
502 success &= (atoi(this->rspVec.at(13).c_str()) == 0);
503 success &= (atoi(this->rspVec.at(15).c_str()) == 0);
509 bool RadioController::querySTAT(
bool verbose)
511 std::string cmd = (boost::format(
"STAT?%s\n") % (verbose?
" v":
"") ).str();
512 this->sendCmd(cmd,
true);
516 bool RadioController::queryTSTAT(
bool verbose)
518 std::string cmd = (boost::format(
"TSTAT?%s\n") % (verbose?
" v":
"") ).str();
519 this->sendCmd(cmd,
true);
Defines functionality for LibCyberRadio applications.