2 * Program to control ICOM radios
4 * This is a ripoff of the utility routines in the ICOM software
5 * distribution. The only function provided is to load the radio
6 * frequency. All other parameters must be manually set before use.
19 #undef write /* ports/winnt/include/config.h: #define write _write */
20 extern int async_write(int, const void *, unsigned int);
21 #define write(fd, data, octets) async_write(fd, data, octets)
27 * These routines send a packet and receive the response. If an error
28 * (collision) occurs on transmit, the packet is resent. If an error
29 * occurs on receive (timeout), all input to the terminating FI is
30 * discarded and the packet is resent. If the maximum number of retries
31 * is not exceeded, the program returns the number of octets in the user
32 * buffer; otherwise, it returns zero.
36 * Frames begin with a two-octet preamble PR-PR followyd by the
37 * transceiver address RE, controller address TX, control code CN, zero
38 * or more data octets DA (depending on command), and terminator FI.
39 * Since the bus is bidirectional, every octet output is echoed on
40 * input. Every valid frame sent is answered with a frame in the same
41 * format, but with the RE and TX fields interchanged. The CN field is
42 * set to NAK if an error has occurred. Otherwise, the data are returned
43 * in this and following DA octets. If no data are returned, the CN
44 * octet is set to ACK.
46 * +------+------+------+------+------+--//--+------+
47 * | PR | PR | RE | TX | CN | DA | FI |
48 * +------+------+------+------+------+--//--+------+
53 #define DICOM /dev/icom/ /* ICOM port link */
56 * Local function prototypes
58 static void doublefreq (double, u_char *, int);
62 * icom_freq(fd, ident, freq) - load radio frequency
65 icom_freq( /* returns 0 (ok), EIO (error) */
66 int fd, /* file descriptor */
67 int ident, /* ICOM radio identifier */
68 double freq /* frequency (MHz) */
71 u_char cmd[] = {PAD, PR, PR, 0, TX, V_SFREQ, 0, 0, 0, 0, FI,
80 doublefreq(freq * 1e6, &cmd[6], temp);
81 temp = write(fd, cmd, temp + 7);
88 * doublefreq(freq, y, len) - double to ICOM frequency with padding
91 doublefreq( /* returns void */
92 double freq, /* frequency */
93 u_char *x, /* radio frequency */
94 int len /* length (octets) */
101 snprintf(s1, sizeof(s1), " %10.0f", freq);
106 x[i] = x[i] | ((*y-- & 0x0f) << 4);
109 for ( ; i < len; i++)
115 * icom_init() - open and initialize serial interface
117 * This routine opens the serial interface for raw transmission; that
118 * is, character-at-a-time, no stripping, checking or monkeying with the
119 * bits. For Unix, an input operation ends either with the receipt of a
120 * character or a 0.5-s timeout.
124 const char *device, /* device name/link */
125 int speed, /* line speed */
126 int trace /* trace flags */ )
133 fd = tty_open(device, O_RDWR, 0777);
137 rc = tcgetattr(fd, &ttyb);
144 ttyb.c_iflag = 0; /* input modes */
145 ttyb.c_oflag = 0; /* output modes */
146 ttyb.c_cflag = IBAUD|CS8|CLOCAL; /* control modes (no read) */
147 ttyb.c_lflag = 0; /* local modes */
148 ttyb.c_cc[VMIN] = 0; /* min chars */
149 ttyb.c_cc[VTIME] = 5; /* receive timeout */
150 cfsetispeed(&ttyb, (u_int)speed);
151 cfsetospeed(&ttyb, (u_int)speed);
152 rc = tcsetattr(fd, TCSANOW, &ttyb);