mirror of
https://github.com/Hamlib/Hamlib.git
synced 2024-09-21 10:27:18 +00:00
Add simtmd710
This commit is contained in:
parent
a6951c8e14
commit
79c496800e
149
simulators/simtmd710.c
Normal file
149
simulators/simtmd710.c
Normal file
@ -0,0 +1,149 @@
|
||||
// can run this using rigctl/rigctld and socat pty devices
|
||||
// gcc -o simyaesu simyaesu.c
|
||||
#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 <hamlib/rig.h>
|
||||
|
||||
#define BUFSIZE 256
|
||||
|
||||
int mysleep = 20;
|
||||
|
||||
float freqA = 14074000;
|
||||
float freqB = 14074500;
|
||||
int filternum = 7;
|
||||
int datamode = 0;
|
||||
int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune;
|
||||
|
||||
// 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)
|
||||
{
|
||||
buf[i++] = c;
|
||||
|
||||
if (c == 0x0d) { return strlen(buf); }
|
||||
}
|
||||
|
||||
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("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[])
|
||||
{
|
||||
char buf[256];
|
||||
char *pbuf;
|
||||
int fd = openPort(argv[1]);
|
||||
int freqa = 14074000, freqb = 140735000;
|
||||
int modeA = 0; // , modeB = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
buf[0] = 0;
|
||||
|
||||
if (getmyline(fd, buf) > 0) { printf("Cmd:%s\n", buf); }
|
||||
|
||||
if (strncmp(buf, "BC", 2) == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "BC %d %d%c", vfo, vfo_tx, 0x0d);
|
||||
printf("R:%s\n", buf);
|
||||
write(fd, buf, strlen(buf));
|
||||
continue;
|
||||
}
|
||||
else if (strncmp(buf, "FO", 2) == 0)
|
||||
{
|
||||
if (buf[3]=='0') {
|
||||
SNPRINTF(buf, sizeof(buf), "FO 0 %d%c", freqA, 0x0d);
|
||||
}
|
||||
else {
|
||||
SNPRINTF(buf, sizeof(buf), "FO 1 %d%c", freqB, 0x0d);
|
||||
}
|
||||
printf("R:%s\n", buf);
|
||||
write(fd, buf, strlen(buf));
|
||||
continue;
|
||||
}
|
||||
else if (strlen(buf) > 0)
|
||||
{
|
||||
fprintf(stderr, "Unknown command: %s\n", buf);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user