1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
// can run this using rigctl/rigctld and socat pty devices
#define _XOPEN_SOURCE 700
// since we are POSIX here we need this
#if 0
struct ip_mreq
{
int dummy;
};
#endif
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include "../include/hamlib/rig.h"
#define BUFSIZE 256
double freqA = 147000000;
double freqB = 148000000;
char tx_vfo = '0';
char rx_vfo = '0';
char modeA = '0';
char modeB = '0';
int band = 0;
int control = 1;
// ID 0310 == 310, Must drop leading zero
typedef enum nc_rigid_e
{
NC_RIGID_NONE = 0,
NC_RIGID_FT450 = 241,
NC_RIGID_FT450D = 244,
NC_RIGID_FT950 = 310,
NC_RIGID_FT891 = 135,
NC_RIGID_FT991 = 135,
NC_RIGID_FT2000 = 251,
NC_RIGID_FT2000D = 252,
NC_RIGID_FTDX1200 = 583,
NC_RIGID_FTDX9000D = 101,
NC_RIGID_FTDX9000Contest = 102,
NC_RIGID_FTDX9000MP = 103,
NC_RIGID_FTDX5000 = 362,
NC_RIGID_FTDX3000 = 460,
NC_RIGID_FTDX101D = 681,
NC_RIGID_FTDX101MP = 682
} nc_rigid_t;
int
getmyline(int fd, char *buf)
{
char c;
int i = 0;
memset(buf, 0, BUFSIZE);
while (read(fd, &c, 1) > 0)
{
if (c == 0x0d) { return strlen(buf); }
buf[i++] = c;
}
if (strlen(buf) == 0) { hl_usleep(10 * 1000); }
return strlen(buf);
}
#if defined(WIN32) || defined(_WIN32)
int openPort(char *comport) // doesn't matter for using pts devices
{
int fd;
fd = open(comport, O_RDWR);
if (fd < 0)
{
perror(comport);
}
return fd;
}
#else
int openPort(char *comport) // doesn't matter for using pts devices
{
int fd = posix_openpt(O_RDWR);
char *name = ptsname(fd);
if (name == NULL)
{
perror("ptsname");
return -1;
}
printf("name=%s\n", name);
if (fd == -1 || grantpt(fd) == -1 || unlockpt(fd) == -1)
{
perror("posix_openpt");
return -1;
}
return fd;
}
#endif
int main(int argc, char *argv[])
{
char buf[256];
int n;
int fd = openPort(argv[1]);
while (1)
{
if (getmyline(fd, buf))
{
printf("Cmd:%s\n", buf);
}
else { continue; }
if (strcmp(buf, "ID") == 0)
{
printf("%s\n", buf);
hl_usleep(50 * 1000);
SNPRINTF(buf, sizeof(buf), "ID TM-D700\r");
n = write(fd, buf, strlen(buf));
printf("n=%d\n", n);
if (n <= 0) { perror("ID"); }
}
else if (strcmp(buf, "BC") == 0)
{
SNPRINTF(buf, sizeof(buf), "BC %d,%d\r", band, control);
n = write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "BC ", 3) == 0)
{
sscanf(buf, "BC %d,%d", &band, &control);
SNPRINTF(buf, sizeof(buf), "BC %d,%d\r", band, control);
n = write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "VMC ", 4) == 0)
{
SNPRINTF(buf, sizeof(buf), "VMC 0,0\r");
n = write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "AI", 2) == 0)
{
SNPRINTF(buf, sizeof(buf), "AI 0\r");
n = write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "FQ", 2) == 0)
{
SNPRINTF(buf, sizeof(buf), "FQ %011.0f,0\r", freqA);
n = write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "FQ ", 3) == 0)
{
sscanf(buf, "FQ %lf,0", &freqA);
SNPRINTF(buf, sizeof(buf), "FQ %011.0f,0\r", freqA);
n = write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "MD", 2) == 0)
{
SNPRINTF(buf, sizeof(buf), "MD 0\r");
n = write(fd, buf, strlen(buf));
}
else if (strlen(buf) > 0)
{
fprintf(stderr, "Unknown command: %s\n", buf);
}
}
return 0;
}
|