SoDaRadio-5.0.3-master:8901fb5
N200Control.cxx
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015, Matthew H. Reilly (kb1vc)
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 are
7  met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #include "N200Control.hxx"
30 #include <boost/format.hpp>
31 #include <boost/asio.hpp>
32 #include <math.h>
33 #include <stdexcept>
34 
35 
36 #include <stdio.h>
37 #include <unistd.h>
38 #include <fcntl.h>
39 #include <errno.h>
40 #include <termios.h>
41 #include <time.h>
42 
43 #include <strings.h>
44 
45 
46 namespace SoDa
47 {
48  N200Control::N200Control(uhd::usrp::multi_usrp::sptr _usrp,
49  int _mboard,
50  std::string ip_addr_str,
51  unsigned int portnum) : TRControl() {
52 
53  mboard = _mboard;
54  usrp = _usrp;
55 
56 
57  skt = new IP::ClientSocket(ip_addr_str.c_str(), portnum, IP::UDP);
58 
59  skt->setBlocking();
60 
61  // now check to see if it is for real.
62  try {
63  setTXOff();
64  }
65  catch (IP::ReadTimeoutExc & ex) {
66  // if we get here, then the device is not connected!
67  std::cerr << "No Serial TR switch control device found." << std::endl;
68  delete skt;
69  skt = NULL;
70  }
71  }
72 
74  {
75  if(skt == NULL) return false;
76  else {
77  try {
78  const char * cmd = "ON00NO\r";
79  skt->putRaw((const void*) cmd, 7);
80  char buf[20];
81  skt->getRaw((void *) buf, 13, 100000);
82  std::cerr << boost::format("\n\nON sent [%s]\n\n\t got [%s]\n\n")
83  % cmd % buf;
84  }
85  catch (IP::ReadTimeoutExc & ex) {
86  // if we get here, then the device is not connected!
87  std::cerr << "No Serial Controlled TR switch is connected to this N2xx....." << std::endl;
88  delete skt;
89  skt = NULL;
90  return false;
91  }
92  }
93 
94  return true;
95  }
96 
98  {
99  if(skt == NULL) { return false; }
100  else {
101  try {
102  const char * cmd = "ST00TS\r";
103  skt->putRaw((const void *) cmd, 7);
104  char buf[20];
105  bzero(buf, 20);
106  skt->getRaw((void *) buf, 13, 100000);
107  std::cerr << boost::format("\n\nOFF sent [%s]\n\n\t got [%s]\n\n")
108  % cmd % buf;
109  }
110  catch (IP::ReadTimeoutExc & ex) {
111  // if we get here, then the device is not connected!
112  std::cerr << "No Serial Controlled TR switch is connected to this N2xx....." << std::endl;
113  delete skt;
114  skt = NULL;
115  return false;
116  }
117  }
118  return true;
119  }
120 
122  {
123  return true;
124  }
125 
126  bool N200Control::setBand(unsigned int band, bool state)
127  { (void) band; (void) state; return false; }
128  bool N200Control::getBand(unsigned int band)
129  { (void) band; return false; }
130 
131 }
uhd::usrp::multi_usrp::sptr usrp
int putRaw(const void *ptr, unsigned int size)
Definition: IPSockets.cxx:239
bool setTXOff()
activate external controls to disable transmit mode.
Definition: N200Control.cxx:97
Generic Control class to activate T/R switching, band switching, and other control functions...
Definition: TRControl.hxx:51
bool setTXOn()
activate external controls to enable transmit mode.
Definition: N200Control.cxx:73
IP::ClientSocket * skt
int getRaw(const void *ptr, unsigned int size, unsigned int usec_timeout=0)
get a raw string of <size> bytes...
Definition: IPSockets.cxx:245
bool getBand(unsigned int band)
query state of signal path for selected band
N200Control(uhd::usrp::multi_usrp::sptr usrp, int mboard, std::string ip_addr_str, unsigned int portnum=49172)
constructor
Definition: N200Control.cxx:48
bool getTX()
report state of transmit-enable.
bool setBand(unsigned int band, bool state)
turn on/off signal path for selected band note that multiple bands can be enabled at one time(!) ...