4 * Program to control ICOM radios
6 * This is a ripoff of the utility routines in the ICOM software
7 * distribution. The only function provided is to load the radio
8 * frequency. All other parameters must be manually set before use.
22 * These routines send a packet and receive the response. If an error
23 * (collision) occurs on transmit, the packet is resent. If an error
24 * occurs on receive (timeout), all input to the terminating FI is
25 * discarded and the packet is resent. If the maximum number of retries
26 * is not exceeded, the program returns the number of octets in the user
27 * buffer; otherwise, it returns zero.
31 * Frames begin with a two-octet preamble PR-PR followyd by the
32 * transceiver address RE, controller address TX, control code CN, zero
33 * or more data octets DA (depending on command), and terminator FI.
34 * Since the bus is bidirectional, every octet output is echoed on
35 * input. Every valid frame sent is answered with a frame in the same
36 * format, but with the RE and TX fields interchanged. The CN field is
37 * set to NAK if an error has occurred. Otherwise, the data are returned
38 * in this and following DA octets. If no data are returned, the CN
39 * octet is set to ACK.
41 * +------+------+------+------+------+--//--+------+
42 * | PR | PR | RE | TX | CN | DA | FI |
43 * +------+------+------+------+------+--//--+------+
48 #define DICOM /dev/icom/ /* ICOM port link */
51 * Local function prototypes
53 static void doublefreq (double, u_char
*, int);
57 * icom_freq(fd, ident, freq) - load radio frequency
60 icom_freq( /* returns 0 (ok), EIO (error) */
61 int fd
, /* file descriptor */
62 int ident
, /* ICOM radio identifier */
63 double freq
/* frequency (MHz) */
66 u_char cmd
[] = {PAD
, PR
, PR
, 0, TX
, V_SFREQ
, 0, 0, 0, 0, FI
,
74 doublefreq(freq
* 1e6
, &cmd
[6], temp
);
75 temp
= write(fd
, cmd
, temp
+ 7);
81 * doublefreq(freq, y, len) - double to ICOM frequency with padding
84 doublefreq( /* returns void */
85 double freq
, /* frequency */
86 u_char
*x
, /* radio frequency */
87 int len
/* length (octets) */
94 sprintf(s1
, " %10.0f", freq
);
99 x
[i
] = x
[i
] | ((*y
-- & 0x0f) << 4);
108 * icom_open() - open and initialize serial interface
110 * This routine opens the serial interface for raw transmission; that
111 * is, character-at-a-time, no stripping, checking or monkeying with the
112 * bits. For Unix, an input operation ends either with the receipt of a
113 * character or a 0.5-s timeout.
117 char *device
, /* device name/link */
118 int speed
, /* line speed */
119 int trace
/* trace flags */ )
125 fd
= open(device
, O_RDWR
, 0777);
129 tcgetattr(fd
, &ttyb
);
130 ttyb
.c_iflag
= 0; /* input modes */
131 ttyb
.c_oflag
= 0; /* output modes */
132 ttyb
.c_cflag
= IBAUD
|CS8
|CLOCAL
; /* control modes (no read) */
133 ttyb
.c_lflag
= 0; /* local modes */
134 ttyb
.c_cc
[VMIN
] = 0; /* min chars */
135 ttyb
.c_cc
[VTIME
] = 5; /* receive timeout */
136 cfsetispeed(&ttyb
, (u_int
)speed
);
137 cfsetospeed(&ttyb
, (u_int
)speed
);
138 tcsetattr(fd
, TCSANOW
, &ttyb
);