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

Functions

int32_t ic9100_connect (string device, uint8_t address, ic9100_handle &handle)
 
int32_t ic9100_disconnect (ic9100_handle &handle)
 
int32_t ic9100_write_header (ic9100_handle &handle)
 
int32_t ic9100_write (ic9100_handle &handle, uint8_t command)
 
int32_t ic9100_write (ic9100_handle &handle, uint8_t command, uint8_t subcommand)
 
int32_t ic9100_write (ic9100_handle &handle, uint8_t command, vector< uint8_t > message)
 
int32_t ic9100_write (ic9100_handle &handle, uint8_t command, uint8_t subcommand, vector< uint8_t > message)
 
uint8_t ic9100_byte (vector< uint8_t > response)
 
uint8_t ic9100_freq2band (double frequency)
 
int32_t ic9100_set_bandpass (ic9100_handle &handle, double bandpass)
 
int32_t ic9100_get_bandpass (ic9100_handle &handle)
 
int32_t ic9100_set_rfgain (ic9100_handle &handle, uint8_t rfgain)
 
int32_t ic9100_set_squelch (ic9100_handle &handle, uint8_t squelch)
 
int32_t ic9100_set_rfpower (ic9100_handle &handle, float power)
 
int32_t ic9100_check_address (ic9100_handle &handle)
 
int32_t ic9100_get_frequency (ic9100_handle &handle)
 
int32_t ic9100_get_mode (ic9100_handle &handle)
 
int32_t ic9100_set_frequency (ic9100_handle &handle, double frequency)
 
int32_t ic9100_set_mode (ic9100_handle &handle, uint8_t opmode)
 
int32_t ic9100_set_mode (ic9100_handle &handle, uint8_t opmode, uint8_t filtband, uint16_t modulation)
 
int32_t ic9100_set_channel (ic9100_handle &handle, uint8_t channelnum)
 
int32_t ic9100_get_rfgain (ic9100_handle &handle)
 
int32_t ic9100_get_squelch (ic9100_handle &handle)
 
int32_t ic9100_get_rfpower (ic9100_handle &handle)
 
int32_t ic9100_get_smeter (ic9100_handle &handle)
 
int32_t ic9100_get_rfmeter (ic9100_handle &handle)
 
int32_t ic9100_get_swrmeter (ic9100_handle &handle)
 
int32_t ic9100_get_alcmeter (ic9100_handle &handle)
 
int32_t ic9100_get_compmeter (ic9100_handle &handle)
 
int32_t ic9100_set_freqband (ic9100_handle &handle, uint8_t band)
 
int32_t ic9100_get_freqband (ic9100_handle &handle)
 
int32_t ic9100_set_bps9600mode (ic9100_handle &handle, uint8_t mode)
 
int32_t ic9100_get_bps9600mode (ic9100_handle &handle)
 
int32_t ic9100_set_datamode (ic9100_handle &handle, uint8_t mode)
 
int32_t ic9100_get_datamode (ic9100_handle &handle)
 
int32_t ic9100_set_repeater_squelch (ic9100_handle &handle, float frequency)
 
int32_t ic9100_get_repeater_squelch (ic9100_handle &handle)
 

Function Documentation

int32_t ic9100_connect ( string  device,
uint8_t  address,
ic9100_handle handle 
)
34 {
35  int32_t iretn;
36 
38 
39  if (!handle.serial->get_open())
40  {
41  return (SERIAL_ERROR_OPEN);
42  }
43 
44  handle.serial->set_timeout(.1);
45 
46  handle.address = address;
47  iretn = ic9100_check_address(handle);
48 
49  return iretn;
50 }
Definition: serialclass.h:43
int32_t ic9100_check_address(ic9100_handle &handle)
Definition: ic9100_lib.cpp:760
int iretn
Definition: rw_test.cpp:37
char address[]
Definition: netperf_listen.cpp:69
#define IC9100_PARITY
Definition: ic9100_lib.h:39
Serial * serial
Definition: ic9100_lib.h:70
uint8_t address
Definition: ic9100_lib.h:68
bool get_open()
Definition: serialclass.cpp:158
int32_t set_timeout(int, double timeout)
Definition: serialclass.cpp:515
#define IC9100_STOPBITS
Definition: ic9100_lib.h:40
#define SERIAL_ERROR_OPEN
Definition: cosmos-errno.h:177
#define IC9100_BAUD
Definition: ic9100_lib.h:37
static string device
Definition: ax25_recv.cpp:39
#define IC9100_BITS
Definition: ic9100_lib.h:38
int32_t ic9100_disconnect ( ic9100_handle handle)
53 {
54  if (!handle.serial->get_open()) return (SERIAL_ERROR_OPEN);
55 
56  handle.serial->close_device();
57  return 0;
58 }
int32_t close_device()
Definition: serialclass.cpp:126
Serial * serial
Definition: ic9100_lib.h:70
bool get_open()
Definition: serialclass.cpp:158
#define SERIAL_ERROR_OPEN
Definition: cosmos-errno.h:177
int32_t ic9100_write_header ( ic9100_handle handle)
61 {
62  int32_t iretn = 0;
63 
64  iretn = handle.serial->put_char(0xfe);
65  if (iretn < 0)
66  {
67  return iretn;
68  }
69  iretn = handle.serial->put_char(0xfe);
70  if (iretn < 0)
71  {
72  return iretn;
73  }
74  iretn = handle.serial->put_char(handle.address);
75  if (iretn < 0)
76  {
77  return iretn;
78  }
79  iretn = handle.serial->put_char(0xe0);
80  if (iretn < 0)
81  {
82  return iretn;
83  }
84 
85  return 0;
86 }
int iretn
Definition: rw_test.cpp:37
int32_t put_char(uint8_t c)
Definition: serialclass.cpp:609
Serial * serial
Definition: ic9100_lib.h:70
uint8_t address
Definition: ic9100_lib.h:68
int32_t ic9100_write ( ic9100_handle handle,
uint8_t  command 
)
89 {
90  int32_t iretn = 0;
91 
92  vector <uint8_t> data;
93  iretn = ic9100_write(handle, command, data);
94  return iretn;
95 }
int iretn
Definition: rw_test.cpp:37
string command
Definition: add_radio.cpp:27
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_write ( ic9100_handle handle,
uint8_t  command,
uint8_t  subcommand 
)
98 {
99  int32_t iretn = 0;
100 
101  vector <uint8_t> data;
102  iretn = ic9100_write(handle, command, subcommand, data);
103  return iretn;
104 }
int iretn
Definition: rw_test.cpp:37
string command
Definition: add_radio.cpp:27
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_write ( ic9100_handle handle,
uint8_t  command,
vector< uint8_t >  message 
)
107 {
108  int32_t iretn = 0;
109 
110  handle.mut.lock();
111 
112  iretn = ic9100_write_header(handle);
113  if (iretn < 0)
114  {
115  handle.mut.unlock();
116  return iretn;
117  }
118 
119  iretn = handle.serial->put_char(command);
120  if (iretn < 0)
121  {
122  handle.mut.unlock();
123  return iretn;
124  }
125 
126  if (message.size())
127  {
128  iretn = handle.serial->put_data(static_cast <uint8_t *>(message.data()), message.size());
129  if (iretn < 0)
130  {
131  handle.mut.unlock();
132  return iretn;
133  }
134  }
135 
136  iretn = handle.serial->put_char(0xfd);
137  if (iretn < 0)
138  {
139  handle.mut.unlock();
140  return iretn;
141  }
142 
143  uint8_t buffer[100];
144  iretn = handle.serial->get_data( buffer, 100);
145  if (iretn < 0)
146  {
147  handle.mut.unlock();
148  return iretn;
149  }
150  size_t base = message.size() + 6;
151 
152  if (static_cast <size_t>(iretn) < base)
153  {
154  handle.mut.unlock();
155  return IC9100_ERROR_WRITE;
156  }
157 
158  if (static_cast <size_t>(iretn) == base)
159  {
160  handle.mut.unlock();
161  return IC9100_ERROR_ADDR;
162  }
163 
164  if (buffer[base] != 0xfe || buffer[base+1] != 0xfe || buffer[base+2] != 0xe0 || buffer[base+3] != handle.address || buffer[static_cast <size_t>(iretn)-1] != 0xfd)
165  {
166  handle.mut.unlock();
167  return IC9100_ERROR_WRITE;
168  }
169 
170  if (buffer[base+4] == 0xfa)
171  {
172  handle.mut.unlock();
173  return IC9100_ERROR_NG;
174  }
175 
176  if (buffer[base+4] == 0xfb)
177  {
178  handle.response.resize(0);
179  handle.mut.unlock();
180  return 0;
181  }
182  else
183  {
184  base += 5;
185  handle.response.resize(static_cast <size_t>(iretn)-(base+1));
186  memcpy(static_cast<void *>(handle.response.data()), &buffer[base], static_cast <size_t>(iretn)-(base+1));
187  handle.mut.unlock();
188  return iretn - static_cast <int32_t>((base+1));
189  }
190 
191 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
int32_t put_data(vector< uint8_t > data)
Definition: serialclass.cpp:707
int iretn
Definition: rw_test.cpp:37
std::mutex mut
Definition: ic9100_lib.h:71
int32_t put_char(uint8_t c)
Definition: serialclass.cpp:609
static char buffer[255]
Definition: propagator_simple.cpp:60
uint8_t message[300]
Definition: kpc9612p_send.cpp:36
#define IC9100_ERROR_NG
Definition: cosmos-errno.h:184
Serial * serial
Definition: ic9100_lib.h:70
string command
Definition: add_radio.cpp:27
uint8_t address
Definition: ic9100_lib.h:68
int32_t ic9100_write_header(ic9100_handle &handle)
Definition: ic9100_lib.cpp:60
int32_t get_data(vector< uint8_t > &data, size_t size=SIZE_MAX)
Definition: serialclass.cpp:1202
#define IC9100_ERROR_ADDR
Definition: cosmos-errno.h:186
#define IC9100_ERROR_WRITE
Definition: cosmos-errno.h:183
int32_t ic9100_write ( ic9100_handle handle,
uint8_t  command,
uint8_t  subcommand,
vector< uint8_t >  message 
)
194 {
195  int32_t iretn = 0;
196 
197  handle.mut.lock();
198 
199  iretn = ic9100_write_header(handle);
200  if (iretn < 0)
201  {
202  handle.mut.unlock();
203  return iretn;
204  }
205 
206  iretn = handle.serial->put_char(command);
207  if (iretn < 0)
208  {
209  handle.mut.unlock();
210  return iretn;
211  }
212  iretn = handle.serial->put_char(subcommand);
213  if (iretn < 0)
214  {
215  handle.mut.unlock();
216  return iretn;
217  }
218  if (message.size())
219  {
220  iretn = handle.serial->put_data(message);
221  if (iretn < 0)
222  {
223  handle.mut.unlock();
224  return iretn;
225  }
226  }
227  iretn = handle.serial->put_char(0xfd);
228  if (iretn < 0)
229  {
230  handle.mut.unlock();
231  return iretn;
232  }
233 
234  vector <uint8_t> buffer;
235  iretn = handle.serial->get_data(buffer, 100);
236  if (iretn < 0)
237  {
238  handle.mut.unlock();
239  return iretn;
240  }
241 
242  size_t base = message.size() + 7;
243  if (static_cast <size_t>(iretn) < base)
244  {
245  handle.mut.unlock();
246  return IC9100_ERROR_WRITE;
247  }
248 
249  if (static_cast <size_t>(iretn) == base)
250  {
251  handle.mut.unlock();
252  return IC9100_ERROR_ADDR;
253  }
254 
255  if (buffer[base] != 0xfe || buffer[base+1] != 0xfe || buffer[base+2] != 0xe0 || buffer[base+3] != handle.address || buffer[static_cast <size_t>(iretn)-1] != 0xfd)
256  {
257  handle.mut.unlock();
258  return IC9100_ERROR_WRITE;
259  }
260 
261  if (buffer[base+4] == 0xfa)
262  {
263  handle.mut.unlock();
264  return IC9100_ERROR_NG;
265  }
266 
267  if (buffer[base+4] == 0xfb)
268  {
269  handle.response.resize(0);
270  handle.mut.unlock();
271  return 0;
272  }
273  else
274  {
275  base += 6;
276  handle.response.resize(static_cast <size_t>(iretn)-(base+1));
277  memcpy(static_cast <void *>(handle.response.data()), &buffer[base], static_cast <size_t>(iretn)-(base+1));
278  handle.mut.unlock();
279  return iretn - static_cast <int32_t>((base+1));
280  }
281 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
int32_t put_data(vector< uint8_t > data)
Definition: serialclass.cpp:707
int iretn
Definition: rw_test.cpp:37
std::mutex mut
Definition: ic9100_lib.h:71
int32_t put_char(uint8_t c)
Definition: serialclass.cpp:609
static char buffer[255]
Definition: propagator_simple.cpp:60
uint8_t message[300]
Definition: kpc9612p_send.cpp:36
#define IC9100_ERROR_NG
Definition: cosmos-errno.h:184
Serial * serial
Definition: ic9100_lib.h:70
string command
Definition: add_radio.cpp:27
uint8_t address
Definition: ic9100_lib.h:68
int32_t ic9100_write_header(ic9100_handle &handle)
Definition: ic9100_lib.cpp:60
int32_t get_data(vector< uint8_t > &data, size_t size=SIZE_MAX)
Definition: serialclass.cpp:1202
#define IC9100_ERROR_ADDR
Definition: cosmos-errno.h:186
#define IC9100_ERROR_WRITE
Definition: cosmos-errno.h:183
uint8_t ic9100_byte ( vector< uint8_t >  response)
284 {
285  uint8_t result = 0.;
286  for (size_t i=0; i<2; ++i)
287  {
288  result *= 100.;
289  result += 10. * (response[i] >> 4) + (response[i] % 16);
290  }
291 
292  return result;
293 }
int i
Definition: rw_test.cpp:37
uint8_t ic9100_freq2band ( double  frequency)
296 {
297  uint8_t freqband;
298 
299  if (frequency < 1.8e6)
300  {
301  freqband = 14;
302  }
303  else if (frequency < 2.0e6)
304  {
305  freqband = 1;
306  }
307  else if (frequency >= 3.4e6 && frequency < 4.1e6)
308  {
309  freqband = 2;
310  }
311  else if (frequency >= 6.9e6 && frequency < 7.5e6)
312  {
313  freqband = 3;
314  }
315  else if (frequency >= 9.9e6 && frequency < 10.5e6)
316  {
317  freqband = 4;
318  }
319  else if (frequency >= 13.9e6 && frequency < 14.5e6)
320  {
321  freqband = 5;
322  }
323  else if (frequency >= 17.9e6 && frequency < 18.5e6)
324  {
325  freqband = 6;
326  }
327  else if (frequency >= 20.9e6 && frequency < 21.5e6)
328  {
329  freqband = 7;
330  }
331  else if (frequency >= 24.4e6 && frequency < 25.1e6)
332  {
333  freqband = 8;
334  }
335  else if (frequency >= 28.0e6 && frequency < 30.0e6)
336  {
337  freqband = 9;
338  }
339  else if (frequency >= 50.0e6 && frequency <= 54.0e6)
340  {
341  freqband = 10;
342  }
343  else if (frequency >= 108.0e6 && frequency <= 174.0e6)
344  {
345  freqband = 11;
346  }
347  else if (frequency >= 420.0e6 && frequency <= 480.0e6)
348  {
349  freqband = 12;
350  }
351  else if (frequency >= 1240.0e6 && frequency <1320.0e6)
352  {
353  freqband = 13;
354  }
355  else
356  {
357  freqband = 14;
358  }
359  return freqband;
360 }
int32_t ic9100_set_bandpass ( ic9100_handle handle,
double  bandpass 
)
363 {
364  int32_t iretn = 0;
365 
366  iretn = ic9100_get_mode(handle);
367 
368  if (iretn < 0)
369  {
370  return iretn;
371  }
372 
373  uint8_t filtband = 1;
374 
375  switch (handle.mode)
376  {
377  case IC9100_MODE_AM:
378  if (bandpass < 200 || bandpass > 10000)
379  {
381  }
382  if (bandpass < 3333.)
383  {
384  filtband = 3;
385  }
386  else if (bandpass < 6666.)
387  {
388  filtband = 2;
389  }
390  else
391  {
392  filtband = 1;
393  }
394  break;
395  case IC9100_MODE_CW:
396  case IC9100_MODE_CWR:
397  if (bandpass < 50 || bandpass > 3600)
398  {
400  }
401  if (bandpass < 300.)
402  {
403  filtband = 3;
404  }
405  else if (bandpass < 600.)
406  {
407  filtband = 2;
408  }
409  else
410  {
411  filtband = 1;
412  }
413  break;
414  case IC9100_MODE_DV:
415  case IC9100_MODE_FM:
416  if (bandpass != 7000. && bandpass != 10000. && bandpass != 15000.)
417  {
419  }
420  if (bandpass == 7000.)
421  {
422  filtband = 3;
423  }
424  else if (bandpass == 10000.)
425  {
426  filtband = 2;
427  }
428  else
429  {
430  filtband = 1;
431  }
432  break;
433  case IC9100_MODE_LSB:
434  case IC9100_MODE_USB:
435  if (bandpass < 50 || bandpass > 3600)
436  {
438  }
439  if (!handle.datamode)
440  {
441  if (bandpass < 2100.)
442  {
443  filtband = 3;
444  }
445  else if (bandpass < 2700.)
446  {
447  filtband = 2;
448  }
449  else
450  {
451  filtband = 1;
452  }
453  }
454  else
455  {
456  if (bandpass < 300.)
457  {
458  filtband = 3;
459  }
460  else if (bandpass < 600.)
461  {
462  filtband = 2;
463  }
464  else
465  {
466  filtband = 1;
467  }
468  }
469  break;
470  case IC9100_MODE_RTTY:
471  case IC9100_MODE_RTTYR:
472  if (bandpass < 50 || bandpass > 2700)
473  {
475  }
476  if (bandpass < 300.)
477  {
478  filtband = 2;
479  }
480  else if (bandpass < 600.)
481  {
482  filtband = 2;
483  }
484  else
485  {
486  filtband = 1;
487  }
488  break;
489  default:
491  }
492 
493  if (bandpass >= 1e10 || bandpass < 0)
494  {
496  }
497 
498  iretn = ic9100_set_mode(handle, handle.opmode, filtband);
499  if (iretn < 0)
500  {
501  return iretn;
502  }
503 
504  handle.bandpass = static_cast <float>(bandpass);
505  handle.filtband = filtband;
506 
507  return 0;
508 }
#define IC9100_MODE_CWR
Definition: ic9100_lib.h:58
#define IC9100_MODE_USB
Definition: ic9100_lib.h:53
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int iretn
Definition: rw_test.cpp:37
#define IC9100_MODE_LSB
Definition: ic9100_lib.h:52
uint8_t datamode
Definition: ic9100_lib.h:76
uint8_t opmode
Definition: ic9100_lib.h:86
#define IC9100_MODE_DV
Definition: ic9100_lib.h:60
#define IC9100_MODE_CW
Definition: ic9100_lib.h:55
int32_t ic9100_set_mode(ic9100_handle &handle, uint8_t opmode)
Definition: ic9100_lib.cpp:974
#define IC9100_MODE_RTTY
Definition: ic9100_lib.h:56
float bandpass
Definition: ic9100_lib.h:87
int32_t ic9100_get_mode(ic9100_handle &handle)
Definition: ic9100_lib.cpp:810
#define IC9100_MODE_RTTYR
Definition: ic9100_lib.h:59
#define IC9100_MODE_FM
Definition: ic9100_lib.h:57
uint8_t mode
Definition: ic9100_lib.h:75
#define IC9100_MODE_AM
Definition: ic9100_lib.h:54
uint8_t filtband
Definition: ic9100_lib.h:74
int32_t ic9100_get_bandpass ( ic9100_handle handle)
511 {
512  int32_t iretn;
513 
514  iretn = ic9100_get_mode(handle);
515  if (iretn < 0)
516  {
517  return iretn;
518  }
519 
520  switch (handle.mode)
521  {
522  case IC9100_MODE_AM:
523  switch(handle.filtband)
524  {
525  case 3:
526  handle.bandpass = 3000.;
527  break;
528  case 2:
529  handle.bandpass = 6000.;
530  break;
531  case 1:
532  handle.bandpass = 9000.;
533  break;
534  }
535  break;
536  case IC9100_MODE_CW:
537  case IC9100_MODE_CWR:
538  switch(handle.filtband)
539  {
540  case 3:
541  handle.bandpass = 250.;
542  break;
543  case 2:
544  handle.bandpass = 500.;
545  break;
546  case 1:
547  handle.bandpass = 1200.;
548  break;
549  }
550  break;
551  case IC9100_MODE_DV:
552  case IC9100_MODE_FM:
553  switch(handle.filtband)
554  {
555  case 3:
556  handle.bandpass = 7000.;
557  break;
558  case 2:
559  handle.bandpass = 10000.;
560  break;
561  case 1:
562  handle.bandpass = 15000.;
563  break;
564  }
565  break;
566  case IC9100_MODE_LSB:
567  case IC9100_MODE_USB:
568  if (!handle.datamode)
569  {
570  switch(handle.filtband)
571  {
572  case 3:
573  handle.bandpass = 1800.;
574  break;
575  case 2:
576  handle.bandpass = 2400.;
577  break;
578  case 1:
579  handle.bandpass = 3000.;
580  break;
581  }
582  }
583  else
584  {
585  switch(handle.filtband)
586  {
587  case 3:
588  handle.bandpass = 350.;
589  break;
590  case 2:
591  handle.bandpass = 500.;
592  break;
593  case 1:
594  handle.bandpass = 1200.;
595  break;
596  }
597  }
598  break;
599  case IC9100_MODE_RTTY:
600  case IC9100_MODE_RTTYR:
601  switch(handle.filtband)
602  {
603  case 3:
604  handle.bandpass = 250.;
605  break;
606  case 2:
607  handle.bandpass = 500.;
608  break;
609  case 1:
610  handle.bandpass = 2400.;
611  break;
612  }
613  break;
614  }
615 
616  return 0;
617 }
#define IC9100_MODE_CWR
Definition: ic9100_lib.h:58
#define IC9100_MODE_USB
Definition: ic9100_lib.h:53
int iretn
Definition: rw_test.cpp:37
#define IC9100_MODE_LSB
Definition: ic9100_lib.h:52
uint8_t datamode
Definition: ic9100_lib.h:76
#define IC9100_MODE_DV
Definition: ic9100_lib.h:60
#define IC9100_MODE_CW
Definition: ic9100_lib.h:55
#define IC9100_MODE_RTTY
Definition: ic9100_lib.h:56
float bandpass
Definition: ic9100_lib.h:87
int32_t ic9100_get_mode(ic9100_handle &handle)
Definition: ic9100_lib.cpp:810
#define IC9100_MODE_RTTYR
Definition: ic9100_lib.h:59
#define IC9100_MODE_FM
Definition: ic9100_lib.h:57
uint8_t mode
Definition: ic9100_lib.h:75
#define IC9100_MODE_AM
Definition: ic9100_lib.h:54
uint8_t filtband
Definition: ic9100_lib.h:74
int32_t ic9100_set_rfgain ( ic9100_handle handle,
uint8_t  rfgain 
)
620 {
621  int32_t iretn = 0;
622 
623  if (iretn < 0)
624  {
625  return iretn;
626  }
627 
628  vector <uint8_t> data { 0x0,0x0 };
629 
630  for (size_t i=0; i<2; ++i)
631  {
632  data[1-i] = 0;
633  for (size_t j=0; j<2; ++j)
634  {
635  uint8_t digit = rfgain % 10;
636  switch (j)
637  {
638  case 0:
639  data[1-i] += digit;
640  break;
641  case 1:
642  data[1-i] += digit << 4;
643  break;
644  }
645  rfgain /= 10;
646  }
647  }
648 
649  iretn = ic9100_write(handle, 0x14, 0x2, data);
650  return iretn;
651 }
int i
Definition: rw_test.cpp:37
int iretn
Definition: rw_test.cpp:37
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_set_squelch ( ic9100_handle handle,
uint8_t  squelch 
)
654 {
655  int32_t iretn = 0;
656 
657  if (iretn < 0)
658  {
659  return iretn;
660  }
661 
662  vector <uint8_t> data { 0x0,0x0 };
663 
664  for (size_t i=0; i<2; ++i)
665  {
666  data[1-i] = 0;
667  for (size_t j=0; j<2; ++j)
668  {
669  uint8_t digit = squelch % 10;
670  switch (j)
671  {
672  case 0:
673  data[1-i] += digit;
674  break;
675  case 1:
676  data[1-i] += digit << 4;
677  break;
678  }
679  squelch /= 10;
680  }
681  }
682 
683  iretn = ic9100_write(handle, 0x14, 0x3, data);
684  return iretn;
685 }
int i
Definition: rw_test.cpp:37
int iretn
Definition: rw_test.cpp:37
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_set_rfpower ( ic9100_handle handle,
float  power 
)
688 {
689  uint8_t rfpower = 0;
690  int32_t iretn = 0;
691 
692  if (iretn < 0)
693  {
694  return iretn;
695  }
696 
697  if (handle.freqband < 11)
698  {
699  if (power < 2.f || power > (handle.mode==IC9100_MODE_AM?30.f:100.f))
700  {
702  }
703  rfpower = static_cast <uint8_t> (255 * (power - 2.f) / (handle.mode==IC9100_MODE_AM?28.f:98.f));
704  }
705  else if (handle.freqband < 12)
706  {
707  if (power < 2.f || power > (100.f))
708  {
710  }
711  rfpower = static_cast <uint8_t> (255 * (power - 2.f) / (98.f));
712  }
713  else if (handle.freqband < 13)
714  {
715  if (power < 2.f || power > 75.f)
716  {
718  }
719  rfpower = static_cast <uint8_t> (255 * (power - 2.f) / 73.f);
720  }
721  else if (handle.freqband < 14)
722  {
723  if (power < 2.f || power > 10.f)
724  {
726  }
727  rfpower = static_cast <uint8_t> (255 * (power - 2.f) / 8.f);
728  }
729  vector <uint8_t> data { 0x0,0x0 };
730 
731  for (size_t i=0; i<2; ++i)
732  {
733  data[1-i] = 0;
734  for (size_t j=0; j<2; ++j)
735  {
736  uint8_t digit = rfpower % 10;
737  switch (j)
738  {
739  case 0:
740  data[1-i] += digit;
741  break;
742  case 1:
743  data[1-i] += digit << 4;
744  break;
745  }
746  rfpower /= 10;
747  }
748  }
749 
750  iretn = ic9100_write(handle, 0x14, 0xa, data);
751  if (iretn < 0)
752  {
753  return iretn;
754  }
755 
756  handle.maxpower = power;
757  return 0;
758 }
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int i
Definition: rw_test.cpp:37
int iretn
Definition: rw_test.cpp:37
float maxpower
Definition: ic9100_lib.h:90
uint8_t freqband
Definition: ic9100_lib.h:73
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
uint8_t mode
Definition: ic9100_lib.h:75
#define IC9100_MODE_AM
Definition: ic9100_lib.h:54
int32_t ic9100_check_address ( ic9100_handle handle)
761 {
762  int32_t iretn = 0;
763 
764  iretn = ic9100_write(handle, 0x19, 0x0);
765  if (iretn < 0)
766  {
767  return iretn;
768  }
769 
770  // if (handle.address != handle.response[0])
771  // {
772  // return IC9100_ERROR_OUTOFRANGE;
773  // }
774 
775  return 0;
776 }
int iretn
Definition: rw_test.cpp:37
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_get_frequency ( ic9100_handle handle)
779 {
780  int32_t iretn = 0;
781 
782  if (iretn < 0)
783  {
784  return iretn;
785  }
786 
787  iretn = ic9100_write(handle, 0x3);
788  if (iretn < 0)
789  {
790  return iretn;
791  }
792 
793  if (iretn != 5)
794  {
796  }
797 
798  double frequency = 0.;
799  for (size_t i=0; i<5; ++i)
800  {
801  frequency *= 100.;
802  frequency += 10. * (handle.response[4-i] >> 4) + (handle.response[4-i] % 16);
803  }
804  handle.frequency = frequency;
805 
806  handle.freqband = ic9100_freq2band(frequency);
807  return iretn;
808 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int i
Definition: rw_test.cpp:37
int iretn
Definition: rw_test.cpp:37
uint8_t freqband
Definition: ic9100_lib.h:73
uint8_t ic9100_freq2band(double frequency)
Definition: ic9100_lib.cpp:295
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
double frequency
Definition: ic9100_lib.h:92
int32_t ic9100_get_mode ( ic9100_handle handle)
811 {
812  int32_t iretn = 0;
813 
814  if (iretn < 0)
815  {
816  return iretn;
817  }
818 
819  iretn = ic9100_write(handle, 0x4);
820  if (iretn < 0)
821  {
822  return iretn;
823  }
824 
825  if (iretn != 2)
826  {
828  }
829 
830  switch (handle.response[0])
831  {
832  case IC9100_MODE_AM:
833  handle.opmode = DEVICE_RADIO_MODE_AM;
834  break;
835  case IC9100_MODE_FM:
836  handle.opmode = DEVICE_RADIO_MODE_FM;
837  break;
838  case IC9100_MODE_LSB:
839  handle.opmode = DEVICE_RADIO_MODE_LSB;
840  break;
841  case IC9100_MODE_USB:
842  handle.opmode = DEVICE_RADIO_MODE_USB;
843  break;
844  case IC9100_MODE_CW:
845  case IC9100_MODE_CWR:
846  handle.opmode = DEVICE_RADIO_MODE_CW;
847  break;
848  case IC9100_MODE_RTTY:
849  case IC9100_MODE_RTTYR:
851  break;
852  case IC9100_MODE_DV:
853  handle.opmode = DEVICE_RADIO_MODE_DV;
854  break;
855  }
856  handle.mode = handle.response[0];
857  handle.filtband = handle.response[1];
858 
859  iretn = ic9100_get_datamode(handle);
860  if (iretn < 0)
861  {
862  return iretn;
863  }
864 
865  return iretn;
866 }
#define IC9100_MODE_CWR
Definition: ic9100_lib.h:58
vector< uint8_t > response
Definition: ic9100_lib.h:72
Definition: jsondef.h:584
#define IC9100_MODE_USB
Definition: ic9100_lib.h:53
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
Definition: jsondef.h:574
int iretn
Definition: rw_test.cpp:37
Definition: jsondef.h:576
#define IC9100_MODE_LSB
Definition: ic9100_lib.h:52
uint8_t opmode
Definition: ic9100_lib.h:86
Definition: jsondef.h:572
#define IC9100_MODE_DV
Definition: ic9100_lib.h:60
Definition: jsondef.h:580
#define IC9100_MODE_CW
Definition: ic9100_lib.h:55
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
Definition: jsondef.h:582
#define IC9100_MODE_RTTY
Definition: ic9100_lib.h:56
#define IC9100_MODE_RTTYR
Definition: ic9100_lib.h:59
#define IC9100_MODE_FM
Definition: ic9100_lib.h:57
Definition: jsondef.h:578
uint8_t mode
Definition: ic9100_lib.h:75
int32_t ic9100_get_datamode(ic9100_handle &handle)
Definition: ic9100_lib.cpp:1483
#define IC9100_MODE_AM
Definition: ic9100_lib.h:54
uint8_t filtband
Definition: ic9100_lib.h:74
int32_t ic9100_set_frequency ( ic9100_handle handle,
double  frequency 
)
869 {
870  int32_t iretn = 0;
871  if (iretn < 0)
872  {
873  return iretn;
874  }
875 
876  vector <uint8_t> data { 0x0,0x0,0x0,0x0,0x0 };
877 
878  if (frequency >= 1e10 || frequency < 0)
879  {
881  }
882 
883  frequency = trunc(frequency);
884  for (size_t i=0; i<5; ++i)
885  {
886  data[i] = 0;
887  for (size_t j=0; j<2; ++j)
888  {
889  uint8_t digit = static_cast <uint8_t>(fmod(frequency, 10.));
890  switch (j)
891  {
892  case 0:
893  data[i] += digit;
894  break;
895  case 1:
896  data[i] += digit << 4;
897  break;
898  }
899  frequency = trunc(frequency / 10.);
900  }
901  }
902 
903  iretn = ic9100_write(handle, 0x5, data);
904  if (iretn < 0)
905  {
906  return iretn;
907  }
908 
909  if (frequency < 1.8e6)
910  {
911  handle.freqband = 14;
912  }
913  else if (frequency < 2.0e6)
914  {
915  handle.freqband = 1;
916  }
917  else if (frequency >= 3.4e6 && frequency < 4.1e6)
918  {
919  handle.freqband = 2;
920  }
921  else if (frequency >= 6.9e6 && frequency < 7.5e6)
922  {
923  handle.freqband = 3;
924  }
925  else if (frequency >= 9.9e6 && frequency < 10.5e6)
926  {
927  handle.freqband = 4;
928  }
929  else if (frequency >= 13.9e6 && frequency < 14.5e6)
930  {
931  handle.freqband = 5;
932  }
933  else if (frequency >= 17.9e6 && frequency < 18.5e6)
934  {
935  handle.freqband = 6;
936  }
937  else if (frequency >= 20.9e6 && frequency < 21.5e6)
938  {
939  handle.freqband = 7;
940  }
941  else if (frequency >= 24.4e6 && frequency < 25.1e6)
942  {
943  handle.freqband = 8;
944  }
945  else if (frequency >= 28.0e6 && frequency < 30.0e6)
946  {
947  handle.freqband = 9;
948  }
949  else if (frequency >= 50.0e6 && frequency <= 54.0e6)
950  {
951  handle.freqband = 10;
952  }
953  else if (frequency >= 108.0e6 && frequency <= 174.0e6)
954  {
955  handle.freqband = 11;
956  }
957  else if (frequency >= 420.0e6 && frequency <= 480.0e6)
958  {
959  handle.freqband = 12;
960  }
961  else if (frequency >= 1240.0e6 && frequency <1320.0e6)
962  {
963  handle.freqband = 13;
964  }
965  else
966  {
967  handle.freqband = 14;
968  }
969  handle.frequency = frequency;
970 
971  return 0;
972 }
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int i
Definition: rw_test.cpp:37
int iretn
Definition: rw_test.cpp:37
uint8_t freqband
Definition: ic9100_lib.h:73
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
double frequency
Definition: ic9100_lib.h:92
int32_t ic9100_set_mode ( ic9100_handle handle,
uint8_t  opmode 
)
975 {
976  int32_t iretn;
977 
978  iretn = ic9100_set_mode(handle, opmode, handle.filtband);
979  if (iretn < 0)
980  {
981  return iretn;
982  }
983 
984  return 0;
985 
986 }
int iretn
Definition: rw_test.cpp:37
int32_t ic9100_set_mode(ic9100_handle &handle, uint8_t opmode)
Definition: ic9100_lib.cpp:974
static uint8_t opmode
Definition: add_radio.cpp:23
uint8_t filtband
Definition: ic9100_lib.h:74
int32_t ic9100_set_mode ( ic9100_handle handle,
uint8_t  opmode,
uint8_t  filtband,
uint16_t  modulation 
)
989 {
990  int32_t iretn = 0;
991  if (iretn < 0)
992  {
993  return iretn;
994  }
995 
996  uint8_t datamode = 0;
997  uint8_t mode;
998 
999  switch (opmode)
1000  {
1001  case DEVICE_RADIO_MODE_AMD:
1002  datamode = 1;
1003  mode = IC9100_MODE_AM;
1004  break;
1005  case DEVICE_RADIO_MODE_AM:
1006  mode = IC9100_MODE_AM;
1007  break;
1008  case DEVICE_RADIO_MODE_CW:
1009  mode = IC9100_MODE_CW;
1010  break;
1011  case DEVICE_RADIO_MODE_CWR:
1012  mode = IC9100_MODE_CWR;
1013  break;
1014  case DEVICE_RADIO_MODE_DVD:
1015  datamode = 1;
1016  mode = IC9100_MODE_DV;
1017  break;
1018  case DEVICE_RADIO_MODE_DV:
1019  mode = IC9100_MODE_DV;
1020  break;
1021  case DEVICE_RADIO_MODE_FMD:
1022  datamode = 1;
1023  mode = IC9100_MODE_FM;
1024  break;
1025  case DEVICE_RADIO_MODE_FM:
1026  mode = IC9100_MODE_FM;
1027  break;
1029  datamode = 1;
1030  mode = IC9100_MODE_LSB;
1031  break;
1032  case DEVICE_RADIO_MODE_LSB:
1033  mode = IC9100_MODE_LSB;
1034  break;
1036  mode = IC9100_MODE_RTTY;
1037  break;
1039  mode = IC9100_MODE_RTTYR;
1040  break;
1042  datamode = 1;
1043  mode = IC9100_MODE_USB;
1044  break;
1045  case DEVICE_RADIO_MODE_USB:
1046  mode = IC9100_MODE_USB;
1047  break;
1048  default:
1049  return IC9100_ERROR_OUTOFRANGE;
1050  }
1051 
1052  if (filtband)
1053  {
1054  vector <uint8_t> data { 0x0, 0x0 };
1055  data[0] = mode;
1056  data[1] = filtband;
1057  iretn = ic9100_write(handle, 0x6, data);
1058  }
1059  else
1060  {
1061  vector <uint8_t> data { 0x0 };
1062  data[0] = mode;
1063  iretn = ic9100_write(handle, 0x6, data);
1064  }
1065 
1066  if (iretn < 0)
1067  {
1068  return iretn;
1069  }
1070 
1071  handle.filtband = filtband;
1072 
1073  if (handle.datamode != datamode)
1074  {
1075  iretn = ic9100_set_datamode(handle, datamode);
1076  if (iretn < 0)
1077  {
1078  return iretn;
1079  }
1080  }
1081 
1082 
1083  handle.opmode = opmode;
1084  handle.mode = mode;
1085 
1086  return 0;
1087 }
#define IC9100_MODE_CWR
Definition: ic9100_lib.h:58
Definition: jsondef.h:575
Definition: jsondef.h:585
Definition: jsondef.h:584
#define IC9100_MODE_USB
Definition: ic9100_lib.h:53
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
Definition: jsondef.h:581
Definition: jsondef.h:574
int iretn
Definition: rw_test.cpp:37
Definition: jsondef.h:576
#define IC9100_MODE_LSB
Definition: ic9100_lib.h:52
Definition: jsondef.h:579
uint8_t datamode
Definition: ic9100_lib.h:76
uint8_t opmode
Definition: ic9100_lib.h:86
Definition: jsondef.h:572
#define IC9100_MODE_DV
Definition: ic9100_lib.h:60
Definition: jsondef.h:583
Definition: jsondef.h:580
#define IC9100_MODE_CW
Definition: ic9100_lib.h:55
static uint8_t opmode
Definition: add_radio.cpp:23
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
Definition: jsondef.h:582
Definition: jsondef.h:573
#define IC9100_MODE_RTTY
Definition: ic9100_lib.h:56
#define IC9100_MODE_RTTYR
Definition: ic9100_lib.h:59
#define IC9100_MODE_FM
Definition: ic9100_lib.h:57
Definition: jsondef.h:578
int32_t ic9100_set_datamode(ic9100_handle &handle, uint8_t mode)
Definition: ic9100_lib.cpp:1434
uint8_t mode
Definition: ic9100_lib.h:75
#define IC9100_MODE_AM
Definition: ic9100_lib.h:54
uint8_t filtband
Definition: ic9100_lib.h:74
Definition: jsondef.h:577
int32_t ic9100_set_channel ( ic9100_handle handle,
uint8_t  channelnum 
)
1090 {
1091  int32_t iretn = 0;
1092 
1093  switch (channelnum)
1094  {
1095  case IC9100_CHANNEL_A:
1096  case IC9100_CHANNEL_B:
1097  {
1098  iretn = ic9100_write(handle, 0x7, 0xd0+channelnum);
1099  }
1100  break;
1101  case IC9100_CHANNEL_SWAP:
1102  {
1103  iretn = ic9100_write(handle, 0x7, 0xb0);
1104  }
1105  break;
1106  default:
1107  return IC9100_ERROR_OUTOFRANGE;
1108  }
1109 
1110  if (iretn < 0)
1111  {
1112  return iretn;
1113  }
1114 
1115  if (channelnum != IC9100_CHANNEL_SWAP)
1116  {
1117  handle.channelnum = channelnum;
1118  }
1119 
1120  return 0;
1121 }
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int iretn
Definition: rw_test.cpp:37
#define IC9100_CHANNEL_B
Definition: ic9100_lib.h:43
#define IC9100_CHANNEL_SWAP
Definition: ic9100_lib.h:44
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
uint8_t channelnum
Definition: ic9100_lib.h:69
#define IC9100_CHANNEL_A
Definition: ic9100_lib.h:42
int32_t ic9100_get_rfgain ( ic9100_handle handle)
1124 {
1125  int32_t iretn = 0;
1126 
1127  if (iretn < 0)
1128  {
1129  return iretn;
1130  }
1131 
1132  iretn = ic9100_write(handle, 0x14, 0x2);
1133  if (iretn != 2)
1134  {
1135  return IC9100_ERROR_OUTOFRANGE;
1136  }
1137 
1138  handle.rfgain = ic9100_byte(handle.response);
1139 
1140  return iretn;
1141 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
uint8_t rfgain
Definition: ic9100_lib.h:78
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int iretn
Definition: rw_test.cpp:37
uint8_t ic9100_byte(vector< uint8_t > response)
Definition: ic9100_lib.cpp:283
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_get_squelch ( ic9100_handle handle)
1144 {
1145  int32_t iretn = 0;
1146 
1147  if (iretn < 0)
1148  {
1149  return iretn;
1150  }
1151 
1152  iretn = ic9100_write(handle, 0x14, 0x3);
1153  if (iretn != 2)
1154  {
1155  return IC9100_ERROR_OUTOFRANGE;
1156  }
1157  handle.squelch = ic9100_byte(handle.response);
1158 
1159  return 0;
1160 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int iretn
Definition: rw_test.cpp:37
uint8_t ic9100_byte(vector< uint8_t > response)
Definition: ic9100_lib.cpp:283
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
uint8_t squelch
Definition: ic9100_lib.h:79
int32_t ic9100_get_rfpower ( ic9100_handle handle)
1163 {
1164  int32_t iretn = 0;
1165 
1166  if (iretn < 0)
1167  {
1168  return iretn;
1169  }
1170 
1171  iretn = ic9100_write(handle, 0x14, 0xa);
1172  if (iretn != 2)
1173  {
1174  return IC9100_ERROR_OUTOFRANGE;
1175  }
1176 
1177  float power = ic9100_byte(handle.response);
1178 
1179  handle.rfpower = static_cast <uint8_t> (power);
1180  power /= 255.f;
1181 
1182  if (handle.freqband < 11)
1183  {
1184  power = 2.f + power * (handle.mode==IC9100_MODE_AM?28.f:98.f);
1185  }
1186  else if (handle.freqband < 12)
1187  {
1188  power = 2.f + power * 98.f;
1189  }
1190  else if (handle.freqband < 13)
1191  {
1192  power = 2.f + power * 73.f;
1193  }
1194  else if (handle.freqband < 14)
1195  {
1196  power = 2.f + power * 8.f;
1197  }
1198  handle.maxpower = power;
1199  return iretn;
1200 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
uint8_t rfpower
Definition: ic9100_lib.h:80
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int iretn
Definition: rw_test.cpp:37
float maxpower
Definition: ic9100_lib.h:90
uint8_t ic9100_byte(vector< uint8_t > response)
Definition: ic9100_lib.cpp:283
uint8_t freqband
Definition: ic9100_lib.h:73
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
uint8_t mode
Definition: ic9100_lib.h:75
#define IC9100_MODE_AM
Definition: ic9100_lib.h:54
int32_t ic9100_get_smeter ( ic9100_handle handle)
1203 {
1204  int32_t iretn = 0;
1205 
1206  iretn = ic9100_write(handle, 0x15, 0x2);
1207  if (iretn < 0)
1208  {
1209  return iretn;
1210  }
1211 
1212  float power = ic9100_byte(handle.response);
1213 
1214  handle.smeter = static_cast <uint8_t> (power);
1215  power /= 240.f;
1216 
1217  if (power > 1.f)
1218  {
1219  power = 1.;
1220  }
1221 
1222  if (handle.freqband < 11)
1223  {
1224  power = 2.f + power * (handle.mode==IC9100_MODE_AM?28.f:98.f);
1225  }
1226  else if (handle.freqband < 12)
1227  {
1228  power = 2.f + power * 98.f;
1229  }
1230  else if (handle.freqband < 13)
1231  {
1232  power = 2.f + power * 73.f;
1233  }
1234  else if (handle.freqband < 14)
1235  {
1236  power = 1.f + power * 8.f;
1237  }
1238  handle.powerin = power;
1239 
1240  return 0;
1241 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
int iretn
Definition: rw_test.cpp:37
uint8_t ic9100_byte(vector< uint8_t > response)
Definition: ic9100_lib.cpp:283
uint8_t freqband
Definition: ic9100_lib.h:73
float powerin
Definition: ic9100_lib.h:88
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
uint8_t mode
Definition: ic9100_lib.h:75
#define IC9100_MODE_AM
Definition: ic9100_lib.h:54
uint8_t smeter
Definition: ic9100_lib.h:81
int32_t ic9100_get_rfmeter ( ic9100_handle handle)
1244 {
1245  int32_t iretn = 0;
1246 
1247  iretn = ic9100_write(handle, 0x15, 0x11);
1248  if (iretn < 0)
1249  {
1250  return iretn;
1251  }
1252 
1253  float power = ic9100_byte(handle.response);
1254 
1255  handle.rfmeter = static_cast <uint8_t> (power);
1256  if (power <= 141)
1257  {
1258  power /= 282.f;
1259  }
1260  else
1261  {
1262  power /= 215.f;
1263  }
1264 
1265  if (power > 1.f)
1266  {
1267  power = 1.;
1268  }
1269 
1270  if (handle.freqband < 11)
1271  {
1272  power = 2.f + power * (handle.mode==IC9100_MODE_AM?28.f:98.f);
1273  }
1274  else if (handle.freqband < 12)
1275  {
1276  power = 2.f + power * 98.f;
1277  }
1278  else if (handle.freqband < 13)
1279  {
1280  power = 2.f + power * 73.f;
1281  }
1282  else if (handle.freqband < 14)
1283  {
1284  power = 1.f + power * 8.f;
1285  }
1286  handle.powerout = power;
1287 
1288  return 0;
1289 }
float powerout
Definition: ic9100_lib.h:89
vector< uint8_t > response
Definition: ic9100_lib.h:72
int iretn
Definition: rw_test.cpp:37
uint8_t ic9100_byte(vector< uint8_t > response)
Definition: ic9100_lib.cpp:283
uint8_t freqband
Definition: ic9100_lib.h:73
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
uint8_t rfmeter
Definition: ic9100_lib.h:82
uint8_t mode
Definition: ic9100_lib.h:75
#define IC9100_MODE_AM
Definition: ic9100_lib.h:54
int32_t ic9100_get_swrmeter ( ic9100_handle handle)
1292 {
1293  int32_t iretn = 0;
1294 
1295  iretn = ic9100_write(handle, 0x15, 0x12);
1296  if (iretn < 0)
1297  {
1298  return iretn;
1299  }
1300 
1301  handle.swrmeter = ic9100_byte(handle.response);
1302 
1303  return 0;
1304 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
int iretn
Definition: rw_test.cpp:37
uint8_t ic9100_byte(vector< uint8_t > response)
Definition: ic9100_lib.cpp:283
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
uint8_t swrmeter
Definition: ic9100_lib.h:83
int32_t ic9100_get_alcmeter ( ic9100_handle handle)
1307 {
1308  int32_t iretn = 0;
1309 
1310  iretn = ic9100_write(handle, 0x15, 0x13);
1311  if (iretn < 0)
1312  {
1313  return iretn;
1314  }
1315 
1316  handle.alcmeter = ic9100_byte(handle.response);
1317 
1318  return 0;
1319 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
int iretn
Definition: rw_test.cpp:37
uint8_t ic9100_byte(vector< uint8_t > response)
Definition: ic9100_lib.cpp:283
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
uint8_t alcmeter
Definition: ic9100_lib.h:84
int32_t ic9100_get_compmeter ( ic9100_handle handle)
1322 {
1323  int32_t iretn = 0;
1324 
1325  iretn = ic9100_write(handle, 0x15, 0x14);
1326  if (iretn < 0)
1327  {
1328  return iretn;
1329  }
1330 
1331  ic9100_byte(handle.response);
1332 
1333  return 0;
1334 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
int iretn
Definition: rw_test.cpp:37
uint8_t ic9100_byte(vector< uint8_t > response)
Definition: ic9100_lib.cpp:283
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_set_freqband ( ic9100_handle handle,
uint8_t  band 
)
1337 {
1338  int32_t iretn = 0;
1339 
1340  if (band > 0 && band < 15)
1341  {
1342  vector <uint8_t> data { 0x0, 0x1 };
1343  if (band < 10)
1344  {
1345  data[0] = band;
1346  }
1347  else
1348  {
1349  data[0] = band + 6;
1350  }
1351  iretn = ic9100_write(handle, 0x1a, 0x1, data);
1352  }
1353  else
1354  {
1355  return IC9100_ERROR_OUTOFRANGE;
1356  }
1357 
1358  if (iretn < 0)
1359  {
1360  return iretn;
1361  }
1362 
1363  handle.freqband = band;
1364 
1365  return 0;
1366 }
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
static float band
Definition: add_radio.cpp:22
int iretn
Definition: rw_test.cpp:37
uint8_t freqband
Definition: ic9100_lib.h:73
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_get_freqband ( ic9100_handle handle)
1369 {
1370  int32_t iretn = 0;
1371 
1372  iretn = ic9100_write(handle, 0x1a, 0x3);
1373  if (iretn < 0)
1374  {
1375  return iretn;
1376  }
1377 
1378  if (handle.response[0] < 10)
1379  {
1380  handle.bps9600mode = handle.response[0];
1381  }
1382  else
1383  {
1384  handle.bps9600mode = handle.response[0] - 6;
1385  }
1386 
1387  return 0;
1388 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
int iretn
Definition: rw_test.cpp:37
uint8_t bps9600mode
Definition: ic9100_lib.h:77
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_set_bps9600mode ( ic9100_handle handle,
uint8_t  mode 
)
1391 {
1392  int32_t iretn = 0;
1393 
1394  switch (mode)
1395  {
1396  case IC9100_9600MODE_OFF:
1397  case IC9100_9600MODE_ON:
1398  {
1399  vector <uint8_t> data { 0x0, 0x55, 0x0 };
1400  data[2] = mode;
1401  iretn = ic9100_write(handle, 0x1a, 0x5, data);
1402  }
1403  break;
1404  default:
1405  return IC9100_ERROR_OUTOFRANGE;
1406  }
1407 
1408  if (iretn < 0)
1409  {
1410  return iretn;
1411  }
1412 
1413  handle.bps9600mode = mode;
1414 
1415  return 0;
1416 }
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int iretn
Definition: rw_test.cpp:37
#define IC9100_9600MODE_OFF
Definition: ic9100_lib.h:49
#define IC9100_9600MODE_ON
Definition: ic9100_lib.h:50
uint8_t bps9600mode
Definition: ic9100_lib.h:77
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_get_bps9600mode ( ic9100_handle handle)
1419 {
1420  int32_t iretn = 0;
1421 
1422  vector <uint8_t> data { 0x0, 0x55 };
1423  iretn = ic9100_write(handle, 0x1a, 0x5, data);
1424  if (iretn < 0)
1425  {
1426  return iretn;
1427  }
1428 
1429  handle.bps9600mode = handle.response[2];
1430 
1431  return 0;
1432 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
int iretn
Definition: rw_test.cpp:37
uint8_t bps9600mode
Definition: ic9100_lib.h:77
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_set_datamode ( ic9100_handle handle,
uint8_t  mode 
)
1435 {
1436  int32_t iretn = 0;
1437 
1438  switch (mode)
1439  {
1440  case IC9100_DATAMODE_ON:
1441  {
1442  vector <uint8_t> data { 0x0, 0x0 };
1443  data[0] = mode;
1444  data[1] = handle.filtband;
1445  if (data[1] == 0 || data[1] > 3)
1446  {
1447  data[1] = 1;
1448  }
1449  iretn = ic9100_write(handle, 0x1a, 0x6, data);
1450  if (iretn < 0)
1451  {
1452  return iretn;
1453  }
1454 // iretn = ic9100_set_bps9600mode(handle, IC9100_9600MODE_ON);
1455  }
1456  break;
1457  case IC9100_DATAMODE_OFF:
1458  {
1459  vector <uint8_t> data { 0x0, 0x0 };
1460  data[0] = mode;
1461  if (iretn < 0)
1462  {
1463  return iretn;
1464  }
1466  }
1467  break;
1468  default:
1469  return IC9100_ERROR_OUTOFRANGE;
1470  }
1471 
1472  if (iretn < 0)
1473  {
1474  return iretn;
1475  }
1476 
1477  handle.datamode = mode;
1478  handle.opmode = static_cast <uint8_t>((handle.opmode >> 1) << 1) + mode;
1479 
1480  return 0;
1481 }
int32_t ic9100_set_bps9600mode(ic9100_handle &handle, uint8_t mode)
Definition: ic9100_lib.cpp:1390
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int iretn
Definition: rw_test.cpp:37
uint8_t datamode
Definition: ic9100_lib.h:76
uint8_t opmode
Definition: ic9100_lib.h:86
#define IC9100_9600MODE_OFF
Definition: ic9100_lib.h:49
#define IC9100_DATAMODE_OFF
Definition: ic9100_lib.h:46
#define IC9100_DATAMODE_ON
Definition: ic9100_lib.h:47
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
uint8_t filtband
Definition: ic9100_lib.h:74
int32_t ic9100_get_datamode ( ic9100_handle handle)
1484 {
1485  int32_t iretn = 0;
1486 
1487  iretn = ic9100_write(handle, 0x1a, 0x6);
1488  if (iretn < 0)
1489  {
1490  return iretn;
1491  }
1492 
1493  handle.datamode = handle.response[0];
1494  handle.opmode = static_cast <uint8_t>((handle.opmode >> 1) << 1) + handle.response[0];
1495 
1496  return 0;
1497 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
int iretn
Definition: rw_test.cpp:37
uint8_t datamode
Definition: ic9100_lib.h:76
uint8_t opmode
Definition: ic9100_lib.h:86
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_set_repeater_squelch ( ic9100_handle handle,
float  frequency 
)
1500 {
1501  int32_t iretn = 0;
1502 
1503  vector <uint8_t> data { 0x0 };
1504 
1505  if (frequency == 0.f)
1506  {
1507  iretn = ic9100_write(handle, 0x16, 0x42, data);
1508  if (iretn != 1)
1509  {
1510  return IC9100_ERROR_OUTOFRANGE;
1511  }
1512  return iretn;
1513  }
1514  else
1515  {
1516  data[0] = 1;
1517  iretn = ic9100_write(handle, 0x16, 0x42, data);
1518  if (iretn != 1)
1519  {
1520  return IC9100_ERROR_OUTOFRANGE;
1521  }
1522  }
1523 
1524  data.resize(3);
1525  frequency = truncf(frequency * 10.f);
1526  for (size_t i=0; i<3; ++i)
1527  {
1528  data[i] = 0;
1529  for (size_t j=0; j<2; ++j)
1530  {
1531  uint8_t digit = static_cast <uint8_t>(fmodf(frequency, 10.));
1532  switch (j)
1533  {
1534  case 0:
1535  data[2-i] += digit;
1536  break;
1537  case 1:
1538  data[2-i] += digit << 4;
1539  break;
1540  }
1541  frequency = truncf(frequency / 10.f);
1542  }
1543  }
1544 
1545 
1546  iretn = ic9100_write(handle, 0x1b, 0x00, data);
1547 
1548  return iretn;
1549 }
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int i
Definition: rw_test.cpp:37
int iretn
Definition: rw_test.cpp:37
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
int32_t ic9100_get_repeater_squelch ( ic9100_handle handle)
1552 {
1553  int32_t iretn = 0;
1554 
1555  iretn = ic9100_write(handle, 0x16, 0x42);
1556  if (iretn != 1)
1557  {
1558  return IC9100_ERROR_OUTOFRANGE;
1559  }
1560 
1561  if (handle.response[0] == 0)
1562  {
1563  handle.repeater_squelch = 0.;
1564  return 0;
1565  }
1566 
1567  iretn = ic9100_write(handle, 0x1b, 0x00);
1568  if (iretn != 3)
1569  {
1570  return IC9100_ERROR_OUTOFRANGE;
1571  }
1572 
1573  float frequency = 0.;
1574  for (size_t i=0; i<3; ++i)
1575  {
1576  frequency *= 100.f;
1577  frequency += 10.f * (handle.response[i] >> 4) + (handle.response[i] % 16);
1578  }
1579  handle.repeater_squelch = frequency / 10.f;
1580 
1581  return iretn;
1582 }
vector< uint8_t > response
Definition: ic9100_lib.h:72
#define IC9100_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:182
int i
Definition: rw_test.cpp:37
int iretn
Definition: rw_test.cpp:37
int32_t ic9100_write(ic9100_handle &handle, uint8_t command)
Definition: ic9100_lib.cpp:88
float repeater_squelch
Definition: ic9100_lib.h:91