SoDaRadio-5.0.3-master:8901fb5
Command.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 
29 #include "Command.hxx"
30 #include <string>
31 #include <sstream>
32 #include <map>
33 
36 std::map<std::string, SoDa::Command::CmdTarget> SoDa::Command::target_map_s2v;
37 std::map<SoDa::Command::CmdTarget, std::string> SoDa::Command::target_map_v2s;
38 
40 {
41  table_needs_init = true;
42  // created from the buildmap file produced by enum_body2map.sh
43  target_map_s2v[std::string("RX_TUNE_FREQ")] = RX_TUNE_FREQ;
44  target_map_s2v[std::string("TX_TUNE_FREQ")] = TX_TUNE_FREQ;
45  target_map_s2v[std::string("RX_RETUNE_FREQ")] = RX_RETUNE_FREQ;
46  target_map_s2v[std::string("TX_RETUNE_FREQ")] = TX_RETUNE_FREQ;
47  target_map_s2v[std::string("RX_FE_FREQ")] = RX_FE_FREQ;
48  target_map_s2v[std::string("TX_FE_FREQ")] = TX_FE_FREQ;
49  target_map_s2v[std::string("RX_LO3_FREQ")] = RX_LO3_FREQ;
50  target_map_s2v[std::string("RX_SAMP_RATE")] = RX_SAMP_RATE;
51  target_map_s2v[std::string("TX_SAMP_RATE")] = TX_SAMP_RATE;
52  target_map_s2v[std::string("RX_ANT")] = RX_ANT;
53  target_map_s2v[std::string("TX_ANT")] = TX_ANT;
54  target_map_s2v[std::string("RX_RF_GAIN")] = RX_RF_GAIN;
55  target_map_s2v[std::string("TX_RF_GAIN")] = TX_RF_GAIN;
56  target_map_s2v[std::string("RX_AF_GAIN")] = RX_AF_GAIN;
57  target_map_s2v[std::string("RX_AF_SIDETONE_GAIN")] = RX_AF_SIDETONE_GAIN;
58  target_map_s2v[std::string("TX_AF_GAIN")] = TX_AF_GAIN;
59  target_map_s2v[std::string("TX_STATE")] = TX_STATE;
60  target_map_s2v[std::string("RX_STATE")] = RX_STATE;
61  target_map_s2v[std::string("RX_MODE")] = RX_MODE;
62  target_map_s2v[std::string("TX_MODE")] = TX_MODE;
63  target_map_s2v[std::string("RX_BW")] = RX_BW;
64  target_map_s2v[std::string("RBW")] = RBW;
65  target_map_s2v[std::string("CLOCK_SOURCE")] = CLOCK_SOURCE;
66  target_map_s2v[std::string("LO_CHECK")] = LO_CHECK;
67  target_map_s2v[std::string("LO_OFFSET")] = LO_OFFSET;
68  target_map_s2v[std::string("RX_AF_FILTER")] = RX_AF_FILTER;
69  target_map_s2v[std::string("RX_AF_FILTER_SHAPE")] = RX_AF_FILTER_SHAPE;
70  target_map_s2v[std::string("TX_BEACON")] = TX_BEACON;
71  target_map_s2v[std::string("TX_CW_SPEED")] = TX_CW_SPEED;
72  target_map_s2v[std::string("TX_CW_TEXT")] = TX_CW_TEXT;
73  target_map_s2v[std::string("TX_CW_FLUSHTEXT")] = TX_CW_FLUSHTEXT;
74 
75  target_map_s2v[std::string("SPEC_CENTER_FREQ")] = SPEC_CENTER_FREQ;
76  target_map_s2v[std::string("SPEC_RANGE_LOW")] = SPEC_RANGE_LOW;
77  target_map_s2v[std::string("SPEC_RANGE_HI")] = SPEC_RANGE_HI;
78  target_map_s2v[std::string("SPEC_STEP")] = SPEC_STEP;
79  target_map_s2v[std::string("SPEC_BUF_LEN")] = SPEC_BUF_LEN;
80  target_map_s2v[std::string("SPEC_DIMS")] = SPEC_DIMS;
81  target_map_s2v[std::string("SPEC_AVG_WINDOW")] = SPEC_AVG_WINDOW;
82  target_map_s2v[std::string("SPEC_UPDATE_RATE")] = SPEC_UPDATE_RATE;
83  target_map_s2v[std::string("SDR_VERSION")] = SDR_VERSION;
84  target_map_s2v[std::string("DBG_REP")] = DBG_REP;
85 
86  target_map_s2v[std::string("HWMB_REP")] = HWMB_REP;
87  target_map_s2v[std::string("INIT_SETUP_COMPLETE")] = INIT_SETUP_COMPLETE;
88  target_map_s2v[std::string("TVRT_LO_ENABLE")] = TVRT_LO_ENABLE;
89  target_map_s2v[std::string("TVRT_LO_DISABLE")] = TVRT_LO_DISABLE;
90  target_map_s2v[std::string("TVRT_LO_CONFIG")] = TVRT_LO_CONFIG;
91 
92  target_map_s2v[std::string("STOP")] = STOP;
93  target_map_s2v[std::string("STATUS_MESSAGE")] = STATUS_MESSAGE;
94 
95  target_map_s2v[std::string("TX_AUDIO_IN")] = TX_AUDIO_IN;
96  target_map_s2v[std::string("TX_AUDIO_FILT_ENA")] = TX_AUDIO_FILT_ENA;
97 
98  target_map_s2v[std::string("RX_GAIN_RANGE")] = RX_GAIN_RANGE;
99  target_map_s2v[std::string("TX_GAIN_RANGE")] = TX_GAIN_RANGE;
100  target_map_s2v[std::string("RX_ANT_NAME")] = RX_ANT_NAME;
101  target_map_s2v[std::string("TX_ANT_NAME")] = TX_ANT_NAME;
102  target_map_s2v[std::string("MOD_SEL_ENTRY")] = MOD_SEL_ENTRY;
103  target_map_s2v[std::string("AF_FILT_ENTRY")] = AF_FILT_ENTRY;
104  target_map_s2v[std::string("CW_CHAR_SENT")] = CW_CHAR_SENT;
105 
106  target_map_v2s[RX_TUNE_FREQ] = std::string("RX_TUNE_FREQ");
107  target_map_v2s[TX_TUNE_FREQ] = std::string("TX_TUNE_FREQ");
108  target_map_v2s[RX_RETUNE_FREQ] = std::string("RX_RETUNE_FREQ");
109  target_map_v2s[TX_RETUNE_FREQ] = std::string("TX_RETUNE_FREQ");
110  target_map_v2s[RX_FE_FREQ] = std::string("RX_FE_FREQ");
111  target_map_v2s[TX_FE_FREQ] = std::string("TX_FE_FREQ");
112  target_map_v2s[RX_LO3_FREQ] = std::string("RX_LO3_FREQ");
113  target_map_v2s[RX_SAMP_RATE] = std::string("RX_SAMP_RATE");
114  target_map_v2s[TX_SAMP_RATE] = std::string("TX_SAMP_RATE");
115  target_map_v2s[RX_ANT] = std::string("RX_ANT");
116  target_map_v2s[TX_ANT] = std::string("TX_ANT");
117  target_map_v2s[RX_RF_GAIN] = std::string("RX_RF_GAIN");
118  target_map_v2s[TX_RF_GAIN] = std::string("TX_RF_GAIN");
119  target_map_v2s[RX_AF_GAIN] = std::string("RX_AF_GAIN");
120  target_map_v2s[RX_AF_SIDETONE_GAIN] = std::string("RX_AF_SIDETONE_GAIN");
121  target_map_v2s[TX_AF_GAIN] = std::string("TX_AF_GAIN");
122  target_map_v2s[TX_STATE] = std::string("TX_STATE");
123  target_map_v2s[RX_STATE] = std::string("RX_STATE");
124  target_map_v2s[RX_MODE] = std::string("RX_MODE");
125  target_map_v2s[TX_MODE] = std::string("TX_MODE");
126  target_map_v2s[RX_BW] = std::string("RX_BW");
127  target_map_v2s[RBW] = std::string("RBW");
128  target_map_v2s[CLOCK_SOURCE] = std::string("CLOCK_SOURCE");
129  target_map_v2s[LO_CHECK] = std::string("LO_CHECK");
130  target_map_v2s[LO_OFFSET] = std::string("LO_OFFSET");
131  target_map_v2s[RX_AF_FILTER] = std::string("RX_AF_FILTER");
132  target_map_v2s[RX_AF_FILTER_SHAPE] = std::string("RX_AF_FILTER_SHAPE");
133  target_map_v2s[TX_BEACON] = std::string("TX_BEACON");
134  target_map_v2s[TX_CW_SPEED] = std::string("TX_CW_SPEED");
135  target_map_v2s[TX_CW_TEXT] = std::string("TX_CW_TEXT");
136  target_map_v2s[TX_CW_FLUSHTEXT] = std::string("TX_CW_FLUSHTEXT");
137 
138  target_map_v2s[SPEC_CENTER_FREQ] = std::string("SPEC_CENTER_FREQ");
139  target_map_v2s[SPEC_RANGE_LOW] = std::string("SPEC_RANGE_LOW");
140  target_map_v2s[SPEC_RANGE_HI] = std::string("SPEC_RANGE_HI");
141  target_map_v2s[SPEC_STEP] = std::string("SPEC_STEP");
142  target_map_v2s[SPEC_BUF_LEN] = std::string("SPEC_BUF_LEN");
143  target_map_v2s[SPEC_DIMS] = std::string("SPEC_DIMS");
144  target_map_v2s[SPEC_AVG_WINDOW] = std::string("SPEC_AVG_WINDOW");
145  target_map_v2s[SPEC_UPDATE_RATE] = std::string("SPEC_UPDATE_RATE");
146 
147  target_map_v2s[SDR_VERSION] = std::string("SDR_VERSION");
148  target_map_v2s[HWMB_REP] = std::string("HWMB_REP");
149  target_map_v2s[INIT_SETUP_COMPLETE] = std::string("INIT_SETUP_COMPLETE");
150 
151  target_map_v2s[DBG_REP] = std::string("DBG_REP");
152  target_map_v2s[TVRT_LO_ENABLE] = std::string("TVRT_LO_ENABLE");
153  target_map_v2s[TVRT_LO_DISABLE] = std::string("TVRT_LO_DISABLE");
154  target_map_v2s[TVRT_LO_CONFIG] = std::string("TVRT_LO_CONFIG");
155  target_map_v2s[STOP] = std::string("STOP");
156  target_map_v2s[STATUS_MESSAGE] = std::string("STATUS_MESSAGE");
157 
158  target_map_v2s[TX_AUDIO_IN] = std::string("TX_AUDIO_IN");
159  target_map_v2s[TX_AUDIO_FILT_ENA] = std::string("TX_AUDIO_FILT_ENA");
160 
161  target_map_v2s[RX_GAIN_RANGE] = std::string("RX_GAIN_RANGE");
162  target_map_v2s[TX_GAIN_RANGE] = std::string("TX_GAIN_RANGE");
163  target_map_v2s[RX_ANT_NAME] = std::string("RX_ANT_NAME");
164  target_map_v2s[TX_ANT_NAME] = std::string("TX_ANT_NAME");
165  target_map_v2s[MOD_SEL_ENTRY] = std::string("MOD_SEL_ENTRY");
166  target_map_v2s[AF_FILT_ENTRY] = std::string("AF_FILT_ENTRY");
167  target_map_v2s[CW_CHAR_SENT] = std::string("CW_CHAR_SENT");
168 
169 }
170 
172 {
173  if(table_needs_init) {
174  initTables();
175  }
176  // tokenize the string
177  // [GET|REP] TARGET
178  // or
179  // SET TARGET [I|D|S] DATA
180  std::istringstream iss(str);
181 
182  std::string cmd_str, targ_str, typ_str, val_s;
183  double val_d;
184  int val_i;
185 
188 
189  cmd_str = ""; targ_str = "";
190  iss >> cmd_str >> targ_str;
191 
192  if(cmd_str == "SET") {
193  ct = Command::SET;
194  if(target_map_s2v.find(targ_str) == target_map_s2v.end()) {
195  std::cerr << "Command target was [" << targ_str << "] can't parse that." << std::endl;
196  return NULL;
197  }
198  targ = target_map_s2v[targ_str];
199  iss >> typ_str;
200  switch (typ_str[0]) {
201  case 'I':
202  iss >> val_i;
203  return new Command(ct, targ, val_i);
204  break;
205  case 'D':
206  iss >> val_d;
207  return new Command(ct, targ, val_d);
208  break;
209  case 'S':
210  iss >> val_s;
211  return new Command(ct, targ, val_s);
212  break;
213  default:
214  std::cerr << "Can't parse dtype string [" << typ_str << "]" << std::endl;
215  break;
216  }
217  }
218  else if(cmd_str == "GET") {
219  }
220  else if(cmd_str == "REP") {
221  }
222  else {
223  std::cerr << "Can't parse [" << str << "] first token was [" << cmd_str << "]" << std::endl;
224  return NULL;
225  }
226 
227  return NULL;
228 }
229 
230 std::string SoDa::Command::toString() const
231 {
232  if(table_needs_init) {
233  initTables();
234  }
235  std::string sp("");
236  std::ostringstream oss;
237  switch(cmd) {
238  case SET: oss << "SET ";
239  break;
240  case GET: oss << "GET ";
241  break;
242  case REP: oss << "REP ";
243  break;
244  default:
245  break;
246  }
247 
248  if(target_map_v2s.find(target) != target_map_v2s.end()) {
249  oss << target_map_v2s[target];
250  }
251  else {
252  oss << " [?" << target << "?] ";
253  }
254 
255 
256 
257  switch(parm_type) {
258  case 'I':
259  oss << " I " << iparms[0];
260  break;
261  case 'D':
262  oss << " D " << dparms[0];
263  break;
264  case 'S':
265  oss << " S \"" << sparm << "\"";
266  break;
267  }
268  sp += oss.str();
269 
270  return sp;
271 }
tweak the waterfall display parameters like resolution bandwidth
Definition: Command.hxx:270
On receipt of a TVRT_LO_DISABLE command, turn the LO output on TX2 off.
Definition: Command.hxx:391
Not many choices for TX ant, just TX.
Definition: Command.hxx:154
Enable the TX audio bandpass filter (limit to 2.5 kHz) for SSB/AM/FM.
Definition: Command.hxx:424
low spectrum frequency range
Definition: Command.hxx:274
turn transmitter on and off.
Definition: Command.hxx:197
Sample rate for RX is typically 600 KHz or better to allow a reasonable span for the waterfall and pe...
Definition: Command.hxx:132
RX audio gain setting.
Definition: Command.hxx:175
Command()
Constructor – create an empty command.
Definition: Command.hxx:632
Sample rate for TX needs to be fast enough for reasonable FM We set it to 625000 just because there d...
Definition: Command.hxx:141
Set the TX final amplifier.
Definition: Command.hxx:167
Set the RX front end attenuator/amp.
Definition: Command.hxx:161
Set the modulation mode for the receive chain.
Definition: Command.hxx:251
This is an LO check command - use it for finding the actual microwave LO frequency.
Definition: Command.hxx:299
int iparms[4]
integer parameters
Definition: Command.hxx:668
Report min max TX Gain setting (dparm[0,1] = min, max)
Definition: Command.hxx:434
Set the RX front end (1st LO, the 2nd IF LO), and the 3rd LO in a more-or-less optimal way to positio...
Definition: Command.hxx:68
Set the modulation mode for the transmit chain.
Definition: Command.hxx:259
Report the motherboard name (the model name of the USRP)
Definition: Command.hxx:362
all spec info in one call, cf, span, and buflen
Definition: Command.hxx:279
CmdType
Commands are of the form, SET, GET, or REPort some parameter.
Definition: Command.hxx:53
CmdTarget target
the thing we&#39;re touching
Definition: Command.hxx:673
TX Carrier Control – send a dead carrier.
Definition: Command.hxx:208
Ignored for now.
Definition: Command.hxx:201
Initiate a debug dump.
Definition: Command.hxx:353
Report a string/name pair for modulation mode.
Definition: Command.hxx:450
freqency step
Definition: Command.hxx:276
indicate to GUI that we&#39;ve sent all the initial configuration information
Definition: Command.hxx:460
Report min max RX Gain setting (dparm[0,1] = min, max)
Definition: Command.hxx:429
static int command_sequence_number
sequential ID applied to each command
Definition: Command.hxx:678
Flush outstanding CW text strings from pending buffer.
Definition: Command.hxx:228
On receipt of a STOP command, all threads should exit their run loop.
Definition: Command.hxx:371
static std::map< CmdTarget, std::string > target_map_v2s
mapping for toString
Definition: Command.hxx:682
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
how many FFT samples contribute to a spectrum report
Definition: Command.hxx:281
Same effect as TX_TUNE_FREQ.
Definition: Command.hxx:115
char sparm[64]
a buffer holding the string
Definition: Command.hxx:670
the center frequency (command from GUI)
Definition: Command.hxx:273
The STATUS_MESSAGE carries a payload of up to 64 characters.
Definition: Command.hxx:414
Set the RX front end 1st LO and the 2nd IF LO.
Definition: Command.hxx:79
Report TX antenna choice (asciiz string, uint tag)
Definition: Command.hxx:444
char parm_type
is this a double, int, string?
Definition: Command.hxx:676
TX CW text control – a buffer of up to 8 characters.
Definition: Command.hxx:215
RX ant choices are TX/RX, and RX2.
Definition: Command.hxx:148
CmdTarget
Each command has a "target" state that it is meant to modify, query, or report.
Definition: Command.hxx:58
static bool table_needs_init
if true, we need to call initTables()
Definition: Command.hxx:680
CmdType cmd
the command type (SET, GET, REP)
Definition: Command.hxx:672
double dparms[4]
double float parameters
Definition: Command.hxx:669
static std::map< std::string, CmdTarget > target_map_s2v
mapping for parseCommandString
Definition: Command.hxx:681
how many FFT samples between spectrum reports
Definition: Command.hxx:282
The master clock oscillator source Reference oscilator selector set to 1 for external, 0 for internal rep = 1 for internal lock, 0 for unlock 3 for external lock, 2 for external unlocked.
Definition: Command.hxx:291
send character count from start-of-time each time we send a character.
Definition: Command.hxx:466
Tune the 3rd LO, if the current FE frequency is such that the desired frequency is between RX_FE_FREQ...
Definition: Command.hxx:89
Set speed of CW generator.
Definition: Command.hxx:221
Report the SDR (SoDa server program) version info.
Definition: Command.hxx:344
tweak the AF chain – filter settings
Definition: Command.hxx:264
Tune the 3rd LO (in SoDa::USRPRX).
Definition: Command.hxx:96
Set the TX front end (1st LO, the 2nd IF LO), and the 3rd LO in a more-or-less optimal way to positio...
Definition: Command.hxx:108
static Command * parseCommandString(std::string str)
convert a string to a command
Definition: Command.cxx:171
RX audio gain for sidetone (CW) monitor.
Definition: Command.hxx:182
number of samples in the buffer.
Definition: Command.hxx:277
Report a string/name pair for AF filter bandwidth.
Definition: Command.hxx:455
Report RX antenna choice (asciiz string, uint tag)
Definition: Command.hxx:439
high spectrum frequency range
Definition: Command.hxx:275
On receipt of a TVRT_LO_ENABLE command dump a perpetual constant IF stream of (1.0, 0.0) into the tx2 channel to get a steady output.
Definition: Command.hxx:381
static void initTables()
setup maps to support parseCommandString and toString
Definition: Command.cxx:39
On receipt of a TVRT_LO_CONFIG command , set the TX2 channel frequency to dparam[0] and the TX2 outpu...
Definition: Command.hxx:404
Same effect as TX_TUNE_FREQ.
Definition: Command.hxx:122
std::string toString() const
return a string that displays the command
Definition: Command.cxx:230
this is a GET/REP command – BaseBandRX takes FFT centered around 0 and reports largest peak within 5...
Definition: Command.hxx:305
Select the transmit chain audio input (for SSB, AM, and FM)
Definition: Command.hxx:419