2023-02-06 21:56:36 +00:00
|
|
|
// can run this using rigctl/rigctld and socat pty devices
|
2023-05-08 17:04:08 +00:00
|
|
|
#define _XOPEN_SOURCE 700
|
|
|
|
|
// since we are POSIX here we need this
|
2023-02-06 21:56:36 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
2025-08-02 20:59:29 +00:00
|
|
|
|
2025-08-03 14:07:30 +00:00
|
|
|
#include "hamlib/rig.h"
|
2025-08-02 20:59:29 +00:00
|
|
|
#include "misc.h"
|
2023-02-06 21:56:36 +00:00
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
|
|
int
|
2025-08-04 08:45:30 +00:00
|
|
|
_getmyline(int fd, char *buf)
|
2023-02-06 21:56:36 +00:00
|
|
|
{
|
|
|
|
|
char c;
|
|
|
|
|
int i = 0;
|
|
|
|
|
memset(buf, 0, BUFSIZE);
|
|
|
|
|
|
|
|
|
|
while (read(fd, &c, 1) > 0)
|
|
|
|
|
{
|
2023-05-08 12:37:13 +00:00
|
|
|
if (c == 0x0d) { return strlen(buf); }
|
|
|
|
|
|
2023-02-06 21:56:36 +00:00
|
|
|
buf[i++] = c;
|
|
|
|
|
}
|
2023-12-16 17:37:58 +00:00
|
|
|
|
|
|
|
|
if (strlen(buf) == 0) { hl_usleep(10 * 1000); }
|
2023-02-06 21:56:36 +00:00
|
|
|
|
|
|
|
|
return strlen(buf);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-02 16:13:31 +00:00
|
|
|
#include "sim.h"
|
2023-02-06 21:56:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2025-08-02 18:03:10 +00:00
|
|
|
char buf[BUFSIZE];
|
2023-02-06 21:56:36 +00:00
|
|
|
int n;
|
|
|
|
|
int fd = openPort(argv[1]);
|
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
2025-08-04 08:45:30 +00:00
|
|
|
if (_getmyline(fd, buf))
|
2023-02-06 21:56:36 +00:00
|
|
|
{
|
|
|
|
|
printf("Cmd:%s\n", buf);
|
|
|
|
|
}
|
|
|
|
|
else { continue; }
|
|
|
|
|
|
|
|
|
|
if (strcmp(buf, "ID") == 0)
|
|
|
|
|
{
|
|
|
|
|
printf("%s\n", buf);
|
2023-05-08 17:04:08 +00:00
|
|
|
hl_usleep(50 * 1000);
|
2023-02-06 21:56:36 +00:00
|
|
|
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)
|
|
|
|
|
{
|
2023-05-08 12:37:13 +00:00
|
|
|
sscanf(buf, "BC %d,%d", &band, &control);
|
2023-02-06 21:56:36 +00:00
|
|
|
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));
|
|
|
|
|
}
|
2023-05-08 12:37:13 +00:00
|
|
|
else if (strncmp(buf, "FQ ", 3) == 0)
|
2023-02-06 21:56:36 +00:00
|
|
|
{
|
2023-05-08 12:37:13 +00:00
|
|
|
sscanf(buf, "FQ %lf,0", &freqA);
|
2023-02-06 21:56:36 +00:00
|
|
|
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;
|
|
|
|
|
}
|