From 105c6b8d3942646d35a7af09d52e1cb73a5a8c8b Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Tue, 30 Apr 2024 17:28:03 -0500 Subject: [PATCH] Add simmicom.c --- simulators/Makefile.am | 2 +- simulators/simmicom.c | 130 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 simulators/simmicom.c diff --git a/simulators/Makefile.am b/simulators/Makefile.am index 12c290686..74fb40224 100644 --- a/simulators/Makefile.am +++ b/simulators/Makefile.am @@ -8,7 +8,7 @@ DISTCLEANFILES = bin_PROGRAMS = -check_PROGRAMS = simelecraft simicgeneric simkenwood simyaesu simic9100 simic9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simic7300 simic7000 simic7100 simic7200 simatd578 simic905 simts450 simic7600 simic7610 simic705 simts950 simts990 simic7851 simftdx101 simxiegug90 simqrplabs simft818 simic275 simtrusdx simft1000 simtmd710 simts890 simxiegux108g simxiegux6100 simic910 simft450 simelecraftk4 +check_PROGRAMS = simelecraft simicgeneric simkenwood simyaesu simic9100 simic9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simic7300 simic7000 simic7100 simic7200 simatd578 simic905 simts450 simic7600 simic7610 simic705 simts950 simts990 simic7851 simftdx101 simxiegug90 simqrplabs simft818 simic275 simtrusdx simft1000 simtmd710 simts890 simxiegux108g simxiegux6100 simic910 simft450 simelecraftk4 simmicom simelecraft_SOURCES = simelecraft.c simkenwood_SOURCES = simkenwood.c diff --git a/simulators/simmicom.c b/simulators/simmicom.c new file mode 100644 index 000000000..70f5b0019 --- /dev/null +++ b/simulators/simmicom.c @@ -0,0 +1,130 @@ +// can run this using rigctl/rigctld and socat pty devices +// gcc -o simspid simspid.c +#define _XOPEN_SOURCE 700 +// since we are POSIX here we need this +#if 0 +struct ip_mreq +{ + int dummy; +}; +#endif + +#include +#include +#include +#include +#include +#include "../include/hamlib/rig.h" + +#define BUFSIZE 256 + +float freqA = 14074000; +float freqB = 14074500; +char tx_vfo = '0'; +char rx_vfo = '0'; +char modeA = '1'; +char modeB = '1'; +int width_main = 500; +int width_sub = 700; + + +int +getmyline(int fd, unsigned char *buf) +{ + int i = 0; + int n = 0; + memset(buf, 0, BUFSIZE); + + n = read(fd, buf, 4); + + if (n <= 0) { sleep(1); return 0;} + + int bytesToRead = buf[1] + 2; //; len does not include cksum, or eom + n += read(fd, &buf[4], bytesToRead); + printf("n=%d:", n); + + for (i = 0; i < n; ++i) + { + printf(" %02x", buf[i]); + } + + printf("\n"); + return n; +} + +#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[]) +{ + unsigned char buf[256]; + + +again: + int fd = openPort(argv[1]); + + while (1) + { + int bytes = getmyline(fd, buf); + + if (bytes == 0) + { + close(fd); + goto again; + } + + switch (buf[3]) + { + case 0x06: + printf("Report receiver freq\n"); + break; + case 0x13: + printf("PTT On\n"); + break; + case 0x14: + printf("PTT Off\n"); + break; + + default: printf("Unknown cmd=%02x\n", buf[3]); + } + } + + return 0; +}