COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
ic9100.cpp File Reference
Include dependency graph for ic9100.cpp:

Functions

int main (int argc, char *argv[])
 

Variables

static ic9100_handle ic9100
 
static usrp_handle usrp
 
static Agentagent
 
static std::string nodename =""
 
static std::string radioname
 
static size_t deviceindex
 
static size_t radioindex = 9999
 
static std::string radiodevice
 
static uint16_t radioaddr
 
static string port
 
static uint16_t model
 
static uint16_t radiotype = static_cast<uint16_t>(DeviceType::NONE)
 
static float freq
 
static float band
 
static uint8_t opmode = static_cast<uint8_t>(DEVICE_RADIO_MODE_UNDEF)
 
double value1 = 0.
 
double value2 = 0.
 
string command = ""
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)
32 {
33  int32_t iretn;
34 
35  switch (argc)
36  {
37  case 9:
38  if (static_cast<string>("ic9100") == argv[3])
39  {
40  model = static_cast<uint16_t>(DEVICE_MODEL_IC9100);
41  radiodevice = argv[8];
42  radioaddr = stoi(radiodevice.substr(radiodevice.find(':')+1));
43  radiodevice = radiodevice.substr(0, radiodevice.find(':'));
44  }
45  else if (static_cast<string>("astrodev") == argv[3])
46  {
47  model = static_cast<uint16_t>(DEVICE_MODEL_ASTRODEV);
48  radiodevice = argv[8];
49  }
50  else if (static_cast<string>("usrp") == argv[3])
51  {
52  model = static_cast<uint16_t>(DEVICE_MODEL_USRP);
53  radiodevice = argv[8];
54  radioaddr = stoi(radiodevice.substr(radiodevice.find(':')+1));
55  radiodevice = radiodevice.substr(0, radiodevice.find(':'));
56  }
57  if (static_cast<string>("txr") == argv[4])
58  {
59  radiotype = static_cast<uint16_t>(DeviceType::TXR);
60  }
61  else if (static_cast<string>("rxr") == argv[4])
62  {
63  radiotype = static_cast<uint16_t>(DeviceType::RXR);
64  }
65  else if (static_cast<string>("tcv") == argv[4])
66  {
67  radiotype = static_cast<uint16_t>(DeviceType::TCV);
68  }
69  freq = atof(argv[5]);
70  band = atof(argv[6]);
71  if (static_cast<string>("am") == argv[7])
72  {
73  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_AM);
74  }
75  else if (static_cast<string>("amd") == argv[7])
76  {
77  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_AMD);
78  }
79  else if (static_cast<string>("fm") == argv[7])
80  {
81  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_FM);
82  }
83  else if (static_cast<string>("fmd") == argv[7])
84  {
85  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_FMD);
86  }
87  else if (static_cast<string>("lsb") == argv[7])
88  {
89  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_LSB);
90  }
91  else if (static_cast<string>("lsbd") == argv[7])
92  {
93  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_LSBD);
94  }
95  else if (static_cast<string>("usb") == argv[7])
96  {
97  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_USB);
98  }
99  else if (static_cast<string>("usbd") == argv[7])
100  {
101  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_USBD);
102  }
103  else if (static_cast<string>("dv") == argv[7])
104  {
105  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_DV);
106  }
107  else if (static_cast<string>("dvd") == argv[7])
108  {
109  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_DVD);
110  }
111  else if (static_cast<string>("cw") == argv[7])
112  {
113  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_CW);
114  }
115  else if (static_cast<string>("cwr") == argv[7])
116  {
117  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_CWR);
118  }
119  else if (static_cast<string>("rtty") == argv[7])
120  {
121  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_RTTY);
122  }
123  else if (static_cast<string>("rttyr") == argv[7])
124  {
125  opmode = static_cast<uint16_t>(DEVICE_RADIO_MODE_RTTYR);
126  }
127  nodename = argv[2];
128  radioname = argv[1];
129  break;
130  case 6:
131  nodename = argv[5];
132  case 5:
133  value2 = atof(argv[4]);
134  case 4:
135  value1 = atof(argv[3]);
136  case 3:
137  command = argv[2];
138  radioname = argv[1];
139  break;
140  default:
141  printf("Usage: agent->radio radioname [nodename [ic9100/astrodev txr/rxr/tcv frequency bandwidth mode device:addr]]\n");
142  exit (1);
143  break;
144  }
145 
146  // Establish the command channel and heartbeat
147  agent = new Agent(nodename);
148 
149  if ((iretn = agent->wait()) < 0)
150  {
151  fprintf(agent->get_debug_fd(), "%16.10f %s Failed to start Agent %s on Node %s Dated %s : %s\n",currentmjd(), mjd2iso8601(currentmjd()).c_str(), agent->getAgent().c_str(), agent->getNode().c_str(), utc2iso8601(data_ctime(argv[0])).c_str(), cosmos_error_string(iretn).c_str());
152  exit(iretn);
153  }
154 
155  if (argc > 6)
156  {
157  switch (radiotype)
158  {
159  case static_cast<uint16_t>(DeviceType::TXR):
161  deviceindex = agent->cinfo->pieces[static_cast <uint16_t>(iretn)].cidx;
163  break;
164  case static_cast<uint16_t>(DeviceType::RXR):
166  deviceindex = agent->cinfo->pieces[static_cast <uint16_t>(iretn)].cidx;
168  break;
169  case static_cast<uint16_t>(DeviceType::TCV):
171  deviceindex = agent->cinfo->pieces[static_cast <uint16_t>(iretn)].cidx;
173  break;
174  }
175  agent->cinfo->device[deviceindex].model = model;
177  agent->cinfo->device[deviceindex].tcv.freq = freq;
178  agent->cinfo->device[deviceindex].tcv.band = band;
179  agent->cinfo->device[deviceindex].tcv.opmode = opmode;
180  if (model == static_cast<uint16_t>(DEVICE_MODEL_IC9100))
181  {
184  if (iretn >= 0)
185  {
186  agent->cinfo->device[deviceindex].portidx = iretn;
187  }
188  }
189  else if (model == static_cast<uint16_t>(DEVICE_MODEL_TS2000))
190  {
192  if (iretn >= 0)
193  {
194  agent->cinfo->device[deviceindex].portidx = iretn;
195  }
196  }
197  else if (model == static_cast<uint16_t>(DEVICE_MODEL_USRP))
198  {
201  if (iretn >= 0)
202  {
203  agent->cinfo->device[deviceindex].portidx = iretn;
204  }
205  }
206  iretn = json_dump_node(agent->cinfo);
207  }
208 
209  // Look for named radio so we can use the right one
210  if (radiotype == static_cast<uint16_t>(DeviceType::NONE))
211  {
212  for (size_t i=0; i<agent->cinfo->devspec.rxr_cnt; ++i)
213  {
214  if (!strcmp(radioname.c_str(), agent->cinfo->pieces[agent->cinfo->device[agent->cinfo->devspec.rxr[i]].pidx].name))
215  {
217  radioindex = i;
218  radiotype = static_cast<uint16_t>(DeviceType::RXR);
219  break;
220  }
221  }
222  }
223 
224  if (radiotype == static_cast<uint16_t>(DeviceType::NONE))
225  {
226  for (size_t i=0; i<agent->cinfo->devspec.txr_cnt; ++i)
227  {
228  if (!strcmp(radioname.c_str(), agent->cinfo->pieces[agent->cinfo->device[agent->cinfo->devspec.txr[i]].pidx].name))
229  {
231  radioindex = i;
232  radiotype = static_cast<uint16_t>(DeviceType::TXR);
233  break;
234  }
235  }
236  }
237 
238  if (radiotype == static_cast<uint16_t>(DeviceType::NONE))
239  {
240  for (size_t i=0; i<agent->cinfo->devspec.tcv_cnt; ++i)
241  {
242  if (!strcmp(radioname.c_str(), agent->cinfo->pieces[agent->cinfo->device[agent->cinfo->devspec.tcv[i]].pidx].name))
243  {
245  radioindex = i;
246  radiotype = static_cast<uint16_t>(DeviceType::TCV);
247  break;
248  }
249  }
250  }
251 
252  if (radiotype == static_cast<uint16_t>(DeviceType::NONE))
253  {
254  std::cout<<"Exiting " << radioname << " for Node: " << nodename << " no radio found." << std::endl;
255  agent->shutdown();
256  exit (1);
257  }
258 
260  {
262  if (iretn < 0)
263  {
264  printf("Unable to connect to IC9100: %s\n", cosmos_error_string(iretn).c_str());
265  exit(iretn);
266  }
267 
268  iretn = ic9100_set_channel(ic9100, 0);
269  if (iretn < 0)
270  {
271  printf("Unable to set IC9100 to Main: %s\n", cosmos_error_string(iretn).c_str());
272  exit(iretn);
273  }
274  iretn = ic9100_get_frequency(ic9100);
275 
276  if (command == "freq")
277  {
278  if (argc == 3)
279  {
280  iretn = ic9100_get_frequency(ic9100);
281  if (iretn < 0)
282  {
283  printf("Unable to get IC9100 Frequency: %s\n", cosmos_error_string(iretn).c_str());
284  }
285  else {
286  printf("Frequency: %.0f Hz\n", ic9100.frequency);
287  }
288  }
289  else {
291  if (iretn < 0)
292  {
293  printf("Unable to set IC9100 Frequency: %s\n", cosmos_error_string(iretn).c_str());
294  }
295  else {
296  iretn = ic9100_get_frequency(ic9100);
297  printf("Frequency: %.0f Hz\n", ic9100.frequency);
298  }
299  }
300  }
301  else if (command == "rfpower")
302  {
303  iretn = ic9100_get_rfpower(ic9100);
304  if (iretn < 0)
305  {
306  printf("Unable to get IC9100 RFPower: %s\n", cosmos_error_string(iretn).c_str());
307  }
308  else {
309  printf("RFPower: %hhu\n", ic9100.rfpower);
310  }
311  }
312  }
313  else if (agent->cinfo->device[deviceindex].model == DEVICE_MODEL_USRP)
314  {
315  iretn = usrp_connect(agent->cinfo->port[agent->cinfo->device[deviceindex].portidx].name, agent->cinfo->device[deviceindex].addr, usrp);
316  if (command == "freq")
317  {
318  if (argc == 3)
319  {
320  iretn = usrp_get_frequency(usrp);
321  if (iretn < 0)
322  {
323  printf("Unable to get USRP Frequency: %s\n", cosmos_error_string(iretn).c_str());
324  }
325  else {
326  printf("Frequency: %.0f Hz\n", usrp.frequency);
327  }
328  }
329  else {
330  iretn = usrp_set_frequency(usrp, value1);
331  if (iretn < 0)
332  {
333  printf("Unable to set USRP Frequency: %s\n", cosmos_error_string(iretn).c_str());
334  }
335  else {
336  iretn = usrp_get_frequency(usrp);
337  printf("Frequency: %.0f Hz\n", usrp.frequency);
338  }
339  }
340  }
341  }
342 
343 }
Radio Receiver.
Definition: jsondef.h:508
Definition: jsondef.h:575
Definition: jsondef.h:561
vector< portstruc > port
Vector of all ports known to node.
Definition: jsondef.h:4244
string command
Definition: ic9100.cpp:28
uint8_t rfpower
Definition: ic9100_lib.h:80
FILE * get_debug_fd(double mjd=0.)
Definition: agentclass.cpp:2645
Definition: jsondef.h:585
static uint16_t radioaddr
Definition: ic9100.cpp:14
int32_t ic9100_set_frequency(ic9100_handle &handle, double frequency)
Definition: ic9100_lib.cpp:868
int32_t ic9100_set_channel(ic9100_handle &handle, uint8_t channelnum)
Definition: ic9100_lib.cpp:1089
Definition: jsondef.h:584
static std::string radiodevice
Definition: ic9100.cpp:13
vector< uint16_t > rxr
Definition: jsondef.h:3914
static float freq
Definition: ic9100.cpp:22
static size_t radioindex
Definition: ic9100.cpp:12
int i
Definition: rw_test.cpp:37
string getNode()
Listen for heartbeat.
Definition: agentclass.cpp:2607
Definition: jsondef.h:581
static usrp_handle usrp
Definition: ic9100.cpp:7
int32_t usrp_set_frequency(usrp_handle &handle, double frequency)
Definition: usrp_lib.cpp:226
double value1
Definition: ic9100.cpp:26
Not a Component.
Definition: jsondef.h:556
Definition: jsondef.h:574
int iretn
Definition: rw_test.cpp:37
Definition: jsondef.h:576
int32_t wait(State state=State::RUN, double waitsec=10.)
Definition: agentclass.cpp:398
uint16_t tcv_cnt
Definition: jsondef.h:3888
Definition: jsondef.h:567
Definition: jsondef.h:579
int32_t json_dump_node(cosmosstruc *cinfo)
Save Node entries to disk.
Definition: jsonlib.cpp:7233
vector< uint16_t > txr
Definition: jsondef.h:3925
vector< devicestruc > device
Vector of all general (common) information for devices (components) in node.
Definition: jsondef.h:4238
string cosmos_error_string(int32_t cosmos_errno)
Definition: cosmos-errno.cpp:45
int32_t ic9100_get_frequency(ic9100_handle &handle)
Definition: ic9100_lib.cpp:778
Definition: jsondef.h:651
Definition: jsondef.h:572
int32_t ic9100_connect(string device, uint8_t address, ic9100_handle &handle)
Definition: ic9100_lib.cpp:33
static std::string radioname
Definition: ic9100.cpp:10
Radio Transceiver.
Definition: jsondef.h:512
Definition: jsondef.h:583
uint16_t txr_cnt
Definition: jsondef.h:3893
static size_t deviceindex
Definition: ic9100.cpp:11
string getAgent()
Definition: agentclass.cpp:2609
vector< uint16_t > tcv
Definition: jsondef.h:3920
Definition: agentclass.h:139
int32_t usrp_get_frequency(usrp_handle &handle)
Definition: usrp_lib.cpp:148
Definition: jsondef.h:580
int32_t shutdown()
Shutdown agent gracefully.
Definition: agentclass.cpp:366
static ic9100_handle ic9100
Definition: ic9100.cpp:6
double data_ctime(string path)
Definition: datalib.cpp:1910
double frequency
Definition: usrp_lib.h:93
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
Definition: jsondef.h:582
static uint16_t radiotype
Definition: ic9100.cpp:21
int32_t usrp_connect(string device, uint16_t port, usrp_handle &handle)
Definition: usrp_lib.cpp:33
static Agent * agent
Definition: ic9100.cpp:8
string utc2iso8601(double utc)
ISO 8601 version of time.
Definition: timelib.cpp:1286
static uint8_t opmode
Definition: ic9100.cpp:24
Definition: jsondef.h:573
int32_t ic9100_get_rfpower(ic9100_handle &handle)
Definition: ic9100_lib.cpp:1162
static std::string nodename
Definition: ic9100.cpp:9
vector< piecestruc > pieces
Vector of all pieces in node.
Definition: jsondef.h:4232
uint16_t rxr_cnt
Definition: jsondef.h:3881
Definition: jsondef.h:645
int32_t json_createpiece(cosmosstruc *cinfo, string name, DeviceType ctype, double emi, double abs, double hcap, double hcon, double density)
Create new piece.
Definition: jsonlib.cpp:722
cosmosstruc * cinfo
Definition: agentclass.h:346
double value2
Definition: ic9100.cpp:27
static float band
Definition: ic9100.cpp:23
devspecstruc devspec
Structure for devices (components) special data in node, by type.
Definition: jsondef.h:4241
double frequency
Definition: ic9100_lib.h:92
Definition: jsondef.h:560
string mjd2iso8601(double mjd)
Definition: timelib.cpp:1316
Radio Transmitter.
Definition: jsondef.h:510
Definition: jsondef.h:578
Definition: jsondef.h:562
static uint16_t model
Definition: ic9100.cpp:20
Definition: jsondef.h:577
int32_t json_createport(cosmosstruc *cinfo, string name, PORT_TYPE type)
Definition: jsonlib.cpp:1086

Variable Documentation

ic9100_handle ic9100
static
usrp_handle usrp
static
Agent* agent
static
std::string nodename =""
static
std::string radioname
static
size_t deviceindex
static
size_t radioindex = 9999
static
std::string radiodevice
static
uint16_t radioaddr
static
string port
static
uint16_t model
static
uint16_t radiotype = static_cast<uint16_t>(DeviceType::NONE)
static
float freq
static
float band
static
uint8_t opmode = static_cast<uint8_t>(DEVICE_RADIO_MODE_UNDEF)
static
double value1 = 0.
double value2 = 0.
string command = ""