SoDaRadio-5.0.3-master:8901fb5
TestServer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, 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 #include <uhd/usrp/multi_usrp.hpp>
29 
30 #include "SoDaBase.hxx"
31 #include "MultiMBox.hxx"
32 
33 // the radio parts.
34 #include "Params.hxx"
35 #include "UI.hxx"
36 
37 namespace SoDa {
38  class TestServer : public SoDaThread {
39  public:
40  TestServer(CmdMBox * _cwtxt_stream, CmdMBox * _cmd_stream) : SoDa::SoDaThread("TestServer"){
41  cwtxt_stream = _cwtxt_stream;
42  cmd_stream = _cmd_stream;
43 
46 
47  }
48 
49  void run() {
50  bool exitflag = false;
51  Command * cmd;
52  while(!exitflag) {
53  if((cmd = cmd_stream->get(cmd_subs)) != NULL) {
54  std::cerr << "CMD STREAM: [" << cmd->toString() << "]" << std::endl;
55  exitflag |= (cmd->target == Command::STOP);
56  cmd_stream->free(cmd);
57  }
58  if((cmd = cwtxt_stream->get(cwtxt_subs)) != NULL) {
59  std::cerr << "CW TXT STREAM: [" << cmd->toString() << "]" << std::endl;
60  exitflag |= (cmd->target == Command::STOP);
61  cmd_stream->free(cmd);
62  }
63  usleep(10000);
64  }
65  }
66 
67  private:
70  };
71 }
72 
73 
74 #include "Command.hxx"
75 
76 int doWork(int argc, char * argv[])
77 {
78  // create the components of a fake radio
79  // that can sink commands from the IP socket
80  // interface.
81 
82  SoDa::Params params(argc, argv);
83 
84  // These are the mailboxes that connect
85  // the various widgets
86  // the rx and tx streams are vectors of complex floats.
87  // we don't declare the extent here, as it will be set
88  // by a negotiation.
89  SoDa::DatMBox rx_stream, tx_stream, cw_env_stream, if_stream;
92  SoDa::CmdMBox gps_stream(false);
93 
94  // The UI
95  SoDa::UI ui(&params, &cwtxt_stream, &rx_stream, &if_stream,
96  &cmd_stream, &gps_stream);
97 
98  // The test unit
99  SoDa::TestServer test_server(&cmd_stream, &cwtxt_stream);
100 
101  // start the UI -- configure stuff and all that.
102  ui.start();
103 
104  // start command consumers first.
105  test_server.start();
106 
107  ui.join();
108  test_server.join();
109  // while(1) {
110  // usleep(1000000);
111  // }
112 
113  // when we get here, we are done... (UI should not return until it gets an "exit/quit" command.)
114  return 0;
115 }
116 
117 int main(int argc, char * argv[])
118 {
119  try {
120  return doWork(argc, argv);
121  }
122  catch (SoDa::SoDaException * exc) {
123  std::cerr << "Exception caught at SoDa main: " << std::endl;
124  std::cerr << "\t" << exc->toString() << std::endl;
125  }
126 }
The Baseclass for all SoDa objects, and useful commonly used classes.
The Thread baseclass for all SoDa thread objects.
Definition: SoDaBase.hxx:284
T * get(unsigned int subscriber_id)
Definition: MultiMBox.hxx:110
Definition: UI.hxx:40
TestServer(CmdMBox *_cwtxt_stream, CmdMBox *_cmd_stream)
Definition: TestServer.cxx:40
This class handles command line parameters and built-ins.
Definition: Params.hxx:42
The SoDa Exception class.
Definition: SoDaBase.hxx:217
CmdTarget target
the thing we&#39;re touching
Definition: Command.hxx:673
void start()
Execute the threads run loop.
Definition: SoDaBase.hxx:292
void run()
Each thread object must define its "run" loop.
Definition: TestServer.cxx:49
std::string toString()
Create a string that explains this exception.
Definition: SoDaBase.hxx:246
void join()
more properly "Wait for this thread to exit its run loop".
Definition: SoDaBase.hxx:301
On receipt of a STOP command, all threads should exit their run loop.
Definition: Command.hxx:371
This is a list of all the commands that can "do something" to one or more components in the SoDa radi...
Definition: Command.hxx:47
int doWork(int argc, char *argv[])
Definition: TestServer.cxx:76
int main(int argc, char *argv[])
Definition: TestServer.cxx:117
void free(T *m)
Definition: MultiMBox.hxx:118
CmdMBox * cmd_stream
Definition: TestServer.cxx:68
CmdMBox * cwtxt_stream
Definition: TestServer.cxx:68
std::string toString() const
return a string that displays the command
Definition: Command.cxx:230