2021-02-22 05:38:21 +00:00
|
|
|
// can run this using rigctl/rigctld and socat pty devices
|
2021-05-04 19:34:51 +00:00
|
|
|
// gcc -o simyaesu simyaesu.c
|
|
|
|
#define _XOPEN_SOURCE 600
|
2021-02-22 05:36:57 +00:00
|
|
|
#include <stdio.h>
|
2021-05-04 19:34:51 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
2021-02-22 05:36:57 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define BUFSIZE 256
|
|
|
|
|
|
|
|
float freqA = 14074000;
|
|
|
|
float freqB = 14074500;
|
2021-11-15 13:16:17 +00:00
|
|
|
char tx_vfo = 0;
|
|
|
|
char rx_vfo = 0;
|
2021-02-22 05:36:57 +00:00
|
|
|
|
|
|
|
// 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
|
2021-05-04 19:34:51 +00:00
|
|
|
getmyline(int fd, char *buf)
|
2021-02-22 05:36:57 +00:00
|
|
|
{
|
2021-08-01 17:19:44 +00:00
|
|
|
char c;
|
2021-02-22 05:36:57 +00:00
|
|
|
int i = 0;
|
|
|
|
memset(buf, 0, BUFSIZE);
|
|
|
|
|
2021-05-04 19:34:51 +00:00
|
|
|
while (read(fd, &c, 1) > 0)
|
2021-02-22 05:36:57 +00:00
|
|
|
{
|
|
|
|
buf[i++] = c;
|
|
|
|
|
|
|
|
if (c == ';') { return strlen(buf); }
|
|
|
|
}
|
|
|
|
|
|
|
|
return strlen(buf);
|
|
|
|
}
|
2021-05-04 19:34:51 +00:00
|
|
|
|
|
|
|
#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("pstname");
|
|
|
|
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[])
|
2021-02-22 05:36:57 +00:00
|
|
|
{
|
|
|
|
char buf[256];
|
2021-05-04 19:34:51 +00:00
|
|
|
char *pbuf;
|
2021-02-22 05:36:57 +00:00
|
|
|
int n;
|
2021-05-04 19:34:51 +00:00
|
|
|
int fd = openPort(argv[1]);
|
2021-02-22 05:36:57 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2021-08-26 11:49:24 +00:00
|
|
|
if (getmyline(fd, buf))
|
|
|
|
{
|
|
|
|
printf("Cmd:%s\n", buf);
|
|
|
|
}
|
|
|
|
else { return 0; }
|
2021-02-22 05:36:57 +00:00
|
|
|
|
|
|
|
if (strcmp(buf, "RM5;") == 0)
|
|
|
|
{
|
|
|
|
printf("%s\n", buf);
|
|
|
|
usleep(50 * 1000);
|
2021-05-04 19:34:51 +00:00
|
|
|
pbuf = "RM5100000;";
|
|
|
|
n = write(fd, pbuf, strlen(pbuf));
|
2021-02-22 05:36:57 +00:00
|
|
|
printf("n=%d\n", n);
|
|
|
|
|
|
|
|
if (n <= 0) { perror("RM5"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(buf, "AN0;") == 0)
|
|
|
|
{
|
|
|
|
printf("%s\n", buf);
|
|
|
|
usleep(50 * 1000);
|
2021-05-04 19:34:51 +00:00
|
|
|
pbuf = "AN030;";
|
|
|
|
n = write(fd, pbuf, strlen(pbuf));
|
2021-02-22 05:36:57 +00:00
|
|
|
printf("n=%d\n", n);
|
|
|
|
|
|
|
|
if (n <= 0) { perror("AN"); }
|
|
|
|
}
|
2021-11-15 13:16:17 +00:00
|
|
|
else if (strcmp(buf, "FA;") == 0)
|
|
|
|
{
|
2021-11-28 18:41:10 +00:00
|
|
|
pbuf = strdup("FA3456789012;");
|
|
|
|
sprintf(pbuf, "FA%010.0f", freqA);
|
2021-11-15 13:16:17 +00:00
|
|
|
free(pbuf);
|
|
|
|
}
|
2021-11-28 18:41:10 +00:00
|
|
|
else if (strncmp(buf, "FA", 2) == 0)
|
2021-11-15 13:16:17 +00:00
|
|
|
{
|
2021-11-28 18:41:10 +00:00
|
|
|
sscanf(buf, "FA%f", &freqA);
|
2021-11-15 13:16:17 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(buf, "FB;") == 0)
|
|
|
|
{
|
2021-11-28 18:41:10 +00:00
|
|
|
pbuf = strdup("FB3456789012;");
|
|
|
|
sprintf(pbuf, "FB%010.0f", freqB);
|
2021-11-15 13:16:17 +00:00
|
|
|
free(pbuf);
|
|
|
|
}
|
2021-11-28 18:41:10 +00:00
|
|
|
else if (strncmp(buf, "FB", 2) == 0)
|
2021-11-15 13:16:17 +00:00
|
|
|
{
|
2021-11-28 18:41:10 +00:00
|
|
|
sscanf(buf, "FB%f", &freqB);
|
2021-11-15 13:16:17 +00:00
|
|
|
}
|
2021-02-22 05:36:57 +00:00
|
|
|
else if (strcmp(buf, "IF;") == 0)
|
|
|
|
{
|
|
|
|
printf("%s\n", buf);
|
|
|
|
usleep(50 * 1000);
|
2021-05-04 19:34:51 +00:00
|
|
|
pbuf = "IF059014200000+000000700000;";
|
|
|
|
n = write(fd, pbuf, strlen(pbuf));
|
2021-02-22 05:36:57 +00:00
|
|
|
printf("n=%d\n", n);
|
|
|
|
|
|
|
|
if (n <= 0) { perror("IF"); }
|
|
|
|
}
|
|
|
|
else if (strcmp(buf, "ID;") == 0)
|
|
|
|
{
|
|
|
|
printf("%s\n", buf);
|
|
|
|
usleep(50 * 1000);
|
2021-05-04 19:34:51 +00:00
|
|
|
int id = NC_RIGID_FTDX3000;
|
2021-08-26 11:49:24 +00:00
|
|
|
snprintf(buf, sizeof(buf), "ID%03d;", id);
|
2021-05-04 19:34:51 +00:00
|
|
|
n = write(fd, buf, strlen(buf));
|
2021-02-22 05:36:57 +00:00
|
|
|
printf("n=%d\n", n);
|
|
|
|
|
|
|
|
if (n <= 0) { perror("ID"); }
|
|
|
|
}
|
2021-11-08 16:28:28 +00:00
|
|
|
else if (strcmp(buf, "AI;") == 0)
|
|
|
|
{
|
|
|
|
printf("%s\n", buf);
|
|
|
|
usleep(50 * 1000);
|
|
|
|
snprintf(buf, sizeof(buf), "AI0;");
|
|
|
|
n = write(fd, buf, strlen(buf));
|
|
|
|
printf("n=%d\n", n);
|
|
|
|
|
|
|
|
if (n <= 0) { perror("ID"); }
|
|
|
|
}
|
2021-02-22 05:36:57 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
else if (strncmp(buf, "AI", 2) == 0)
|
|
|
|
{
|
|
|
|
if (strcmp(buf, "AI;"))
|
|
|
|
{
|
|
|
|
printf("%s\n", buf);
|
|
|
|
usleep(50 * 1000);
|
|
|
|
n = fprintf(fp, "%s", "AI0;");
|
|
|
|
printf("n=%d\n", n);
|
|
|
|
|
|
|
|
if (n <= 0) { perror("AI"); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
else if (strcmp(buf, "VS;") == 0)
|
|
|
|
{
|
|
|
|
printf("%s\n", buf);
|
|
|
|
usleep(50 * 1000);
|
2021-05-04 19:34:51 +00:00
|
|
|
pbuf = "VS0;";
|
|
|
|
n = write(fd, pbuf, strlen(pbuf));
|
2021-02-22 05:36:57 +00:00
|
|
|
printf("n=%d\n", n);
|
|
|
|
|
|
|
|
if (n < 0) { perror("VS"); }
|
|
|
|
}
|
2021-11-28 18:41:10 +00:00
|
|
|
else if (strcmp(buf, "FT;") == 0)
|
2021-11-15 13:16:17 +00:00
|
|
|
{
|
2021-11-28 18:41:10 +00:00
|
|
|
usleep(50 * 1000);
|
2021-11-15 13:16:17 +00:00
|
|
|
pbuf = strdup("FTx;");
|
|
|
|
pbuf[2] = tx_vfo;
|
|
|
|
n = write(fd, pbuf, strlen(pbuf));
|
|
|
|
free(pbuf);
|
2021-11-28 18:41:10 +00:00
|
|
|
|
2021-11-15 13:16:17 +00:00
|
|
|
if (n < 0) { perror("FT"); }
|
|
|
|
}
|
|
|
|
else if (strncmp(buf, "FT", 2) == 0)
|
|
|
|
{
|
|
|
|
tx_vfo = buf[2];
|
2021-11-28 18:41:10 +00:00
|
|
|
|
|
|
|
if (tx_vfo == '3') { tx_vfo = '1'; }
|
|
|
|
else if (tx_vfo == '2') { tx_vfo = '0'; }
|
2021-11-15 13:16:17 +00:00
|
|
|
else { perror("Expected 2 or 3"); }
|
|
|
|
}
|
2021-02-22 05:36:57 +00:00
|
|
|
else if (strcmp(buf, "EX032;") == 0)
|
|
|
|
{
|
|
|
|
static int ant = 0;
|
|
|
|
ant = (ant + 1) % 3;
|
|
|
|
printf("%s\n", buf);
|
|
|
|
usleep(50 * 1000);
|
2021-05-04 19:34:51 +00:00
|
|
|
snprintf(buf, sizeof(buf), "EX032%1d;", ant);
|
|
|
|
n = write(fd, buf, strlen(buf));
|
2021-02-22 05:36:57 +00:00
|
|
|
printf("n=%d\n", n);
|
|
|
|
|
|
|
|
if (n < 0) { perror("EX032"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (strlen(buf) > 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unknown command: %s\n", buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|