diff --git a/c++/.gitignore b/c++/.gitignore new file mode 100644 index 000000000..a84d07bb7 --- /dev/null +++ b/c++/.gitignore @@ -0,0 +1,4 @@ +test-suite.log +testcpp +testcpp.log +testcpp.trs diff --git a/simulators/.gitignore b/simulators/.gitignore new file mode 100644 index 000000000..58fab97e8 --- /dev/null +++ b/simulators/.gitignore @@ -0,0 +1,58 @@ +simatd578 +simeasycomm +simelecraft +simelecraftk4 +simflex +simft1000 +simft450 +simft710 +simft736 +simft817 +simft818 +simft847 +simft990 +simft991 +simftdx101 +simftdx1200 +simftdx3000 +simftdx5000 +simic2730 +simic275 +simic7000 +simic705 +simic7100 +simic7200 +simic7300 +simic7600 +simic7610 +simic7700 +simic7851 +simic905 +simic910 +simic9100 +simic9700 +simicgeneric +simicr8600 +simid5100 +simjupiter +simkenwood +simmicom +simorion +simpmr171 +simpowersdr +simpstrotator +simqrplabs +simrotorez +simspid +simtmd700 +simtmd710 +simtrusdx +simts450 +simts590 +simts890 +simts950 +simts990 +simxiegug90 +simxiegux108g +simxiegux6100 +simyaesu diff --git a/simulators/sim.h b/simulators/sim.h index fda16b2e7..206f45686 100644 --- a/simulators/sim.h +++ b/simulators/sim.h @@ -1,5 +1,41 @@ -#include "../src/misc.h" #include +#include +#include + +#include "../src/misc.h" + +/* 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 = 570, + NC_RIGID_FT991A = 670, + NC_RIGID_FT2000 = 251, + NC_RIGID_FT2000D = 252, + NC_RIGID_FTDX1200 = 583, + NC_RIGID_FTDX10 = 761, + NC_RIGID_FTDX9000D = 101, + NC_RIGID_FTDX9000Contest = 102, + NC_RIGID_FTDX9000MP = 103, + NC_RIGID_FTDX5000 = 362, + NC_RIGID_FTDX3000 = 460, + NC_RIGID_FTDX3000DM = 462, // an undocumented FT-DX3000DM 50W rig + NC_RIGID_FTDX101D = 681, + NC_RIGID_FTDX101MP = 682, + NC_RIGID_FT710 = 800, + NC_RIGID_FTX1 = 840, +} nc_rigid_t; + +void dumphex(const unsigned char *buf, int n) +{ + for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } + + printf("\n"); +} #define WRITE(f,b,l) write_sim(f,(const unsigned char*)b,l,__func__,__LINE__) @@ -18,3 +54,87 @@ int write_sim(int fd, const unsigned char *buf, int buflen, const char *func, 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("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 + +// Size of command buffer +#define BUFSIZE 256 + +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 == ';') { return i; } + } + + if (i == 0) { hl_usleep(10 * 1000); } + + return i; +} + +int +getmyline5(int fd, unsigned char *buf) +{ + unsigned char c; + int i = 0; + memset(buf, 0, BUFSIZE); + + while (i < 5 && read(fd, &c, 1) > 0) + { + buf[i++] = c; + } + + if (i > 0) { + printf("n=%d %02x %02x %02x %02x %02x\n", i, + buf[0], buf[1], buf[2], buf[3], buf[4]); + } + + if (i == 0) { + hl_usleep(10 * 1000); + } + + return i; +} diff --git a/simulators/simatd578.c b/simulators/simatd578.c index 5fe16fd0f..b6d5e43de 100644 --- a/simulators/simatd578.c +++ b/simulators/simatd578.c @@ -1,19 +1,11 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" + +#include "sim.h" #define BUFSIZE 256 @@ -30,7 +22,7 @@ int curr_vfo = 0; int -getmyline(int fd, unsigned char *buf) +_getmyline(int fd, unsigned char *buf) { unsigned char c; int i = 0; @@ -46,75 +38,31 @@ getmyline(int fd, unsigned char *buf) { buf[i++] = c; } - - n++; } while (c != 0x0a); - printf("n=%d \n", n); - - for (i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - + printf("n=%d", i); + for (n = 0; n < i; ++n) { printf(" %02x", buf[n]); } printf("\n"); - return n; + + return i; } -#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[]) { - unsigned char buf[256], buf2[256]; - int n; + unsigned char buf[BUFSIZE], buf2[256]; -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = _getmyline(fd, buf); + int n = 0; if (bytes == 0) { - close(fd); - goto again; + continue; } if (bytes != 8) diff --git a/simulators/simeasycomm.c b/simulators/simeasycomm.c index 2a92869ba..da5647650 100644 --- a/simulators/simeasycomm.c +++ b/simulators/simeasycomm.c @@ -1,26 +1,20 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" +#include + +#include "hamlib/rig.h" +#include "misc.h" #define BUFSIZE 256 static void *rotorez_thread(void *arg); int -getmyline(int fd, char *buf) +_getmyline(int fd, char *buf) { unsigned char c = 0; int i = 0; @@ -44,43 +38,7 @@ getmyline(int fd, char *buf) 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("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 +#include "sim.h" int thread_args[2]; @@ -103,8 +61,8 @@ int main(int argc, char *argv[]) while (1) { int bytes; - if (!flag) bytes = getmyline(fd, buf); - else bytes = getmyline(fd2, buf); + if (!flag) bytes = _getmyline(fd, buf); + else bytes = _getmyline(fd2, buf); flag = !flag; if (bytes == 0) @@ -149,23 +107,20 @@ int main(int argc, char *argv[]) static void *rotorez_thread(void *arg) { int n = 0; - char buf[256]; + char buf[BUFSIZE]; int fd = *(int *)arg; float az = 123; float el = 45; -again: while (1) { int bytes; - bytes = getmyline(fd, buf); + bytes = _getmyline(fd, buf); if (bytes == 0) { - //close(fd); hl_usleep(100 * 1000); - //printf("again\n"); - goto again; + continue; } printf("line[%d]=%s\n", fd, buf); diff --git a/simulators/simelecraft.c b/simulators/simelecraft.c index f52903254..acc931d09 100644 --- a/simulators/simelecraft.c +++ b/simulators/simelecraft.c @@ -1,22 +1,15 @@ // 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 #include -#include #include #include + #include "hamlib/rig.h" #include "sim.h" +#include "misc.h" -#define BUFSIZE 256 float freqA = 14074000; float freqB = 14074500; @@ -38,68 +31,12 @@ int modea = 2; int modeb = 2; int ptt = 0; -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 == ';') { 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("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]; + char buf[BUFSIZE]; char *pbuf; int n; int fd = openPort(argv[1]); diff --git a/simulators/simelecraftk4.c b/simulators/simelecraftk4.c index fae2f2cb7..edd31061b 100644 --- a/simulators/simelecraftk4.c +++ b/simulators/simelecraftk4.c @@ -1,22 +1,14 @@ // 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 -#include -#include #include #include + #include "hamlib/rig.h" #include "sim.h" +#include "misc.h" -#define BUFSIZE 256 int freqA = 14074000; int freqB = 14074500; @@ -39,68 +31,12 @@ int modeB = 2; int ptt = 0; // int freqa = 14074000, freqb = 14073500; -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 == ';') { 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("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]; + char buf[BUFSIZE]; char *pbuf; int n; int fd = openPort(argv[1]); diff --git a/simulators/simflex.c b/simulators/simflex.c index 3c0565568..0b127e26b 100644 --- a/simulators/simflex.c +++ b/simulators/simflex.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #if defined(WIN32) || defined(_WIN32) #include #include diff --git a/simulators/simft1000.c b/simulators/simft1000.c index 94f6d9c07..30e2429e3 100644 --- a/simulators/simft1000.c +++ b/simulators/simft1000.c @@ -1,21 +1,11 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "sim.h" float freqA = 14074000; float freqB = 14074500; @@ -27,80 +17,19 @@ int width_main = 500; int width_sub = 700; -int -getmyline(int fd, unsigned char *buf) -{ - unsigned char c; - int i = 0; - int n = 0; - memset(buf, 0, BUFSIZE); - - while (i < 5 && read(fd, &c, 1) > 0) - { - buf[i++] = c; - n++; - } - - printf("n=%d %02x %02x %02x %02x %02x\n", n, buf[0], buf[1], buf[2], buf[3], - buf[4]); - 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("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[]) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = getmyline5(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } if (bytes != 5) diff --git a/simulators/simft450.c b/simulators/simft450.c index abee8b1c9..f97c6631f 100644 --- a/simulators/simft450.c +++ b/simulators/simft450.c @@ -1,21 +1,13 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + float freqA = 14074000; float freqB = 14074500; @@ -52,89 +44,13 @@ int gt = 0; int ex016 = 0; int ex020 = 0; -// 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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int n; int fd = openPort(argv[1]); diff --git a/simulators/simft710.c b/simulators/simft710.c index eeb80727c..525f49bbb 100644 --- a/simulators/simft710.c +++ b/simulators/simft710.c @@ -1,21 +1,13 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + float freqA = 14074000; float freqB = 14074500; @@ -53,90 +45,13 @@ int ex016 = 0; int ex020 = 0; int st = 0; -// 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_FT710 = 800 -} 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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int n; int fd = openPort(argv[1]); diff --git a/simulators/simft736.c b/simulators/simft736.c index 1822bfc36..c10614dfc 100644 --- a/simulators/simft736.c +++ b/simulators/simft736.c @@ -1,21 +1,11 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "sim.h" float freqA = 14074000; float freqB = 14074500; @@ -27,80 +17,19 @@ int width_main = 500; int width_sub = 700; -int -getmyline(int fd, unsigned char *buf) -{ - unsigned char c; - int i = 0; - int n = 0; - memset(buf, 0, BUFSIZE); - - while (i < 5 && read(fd, &c, 1) > 0) - { - buf[i++] = c; - n++; - } - - printf("n=%d %02x %02x %02x %02x %02x\n", n, buf[0], buf[1], buf[2], buf[3], - buf[4]); - 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("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[]) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = getmyline5(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } if (bytes != 5) diff --git a/simulators/simft747gx.c b/simulators/simft747gx.c index b996c92bb..5fca30362 100644 --- a/simulators/simft747gx.c +++ b/simulators/simft747gx.c @@ -1,20 +1,13 @@ // 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 #include #include #include #include -#define BUFSIZE 256 +#include "sim.h" float freqA = 14074000; float freqB = 14074500; @@ -26,80 +19,19 @@ int width_main = 500; int width_sub = 700; -int -getmyline(int fd, unsigned char *buf) -{ - unsigned char c; - int i = 0; - int n = 0; - memset(buf, 0, BUFSIZE); - - while (i < 5 && read(fd, &c, 1) > 0) - { - buf[i++] = c; - n++; - } - - printf("n=%d %02x %02x %02x %02x %02x\n", n, buf[0], buf[1], buf[2], buf[3], - buf[4]); - 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("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[]) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = getmyline5(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } if (bytes != 5) diff --git a/simulators/simft817.c b/simulators/simft817.c index afc43c83d..cd9ebeaa2 100644 --- a/simulators/simft817.c +++ b/simulators/simft817.c @@ -1,21 +1,11 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "sim.h" int vfo = 0; // 0=A, !0=B float freqA = 14074000; @@ -28,80 +18,19 @@ int width_main = 500; int width_sub = 700; -int -getmyline(int fd, unsigned char *buf) -{ - unsigned char c; - int i = 0; - int n = 0; - memset(buf, 0, BUFSIZE); - - while (i < 5 && read(fd, &c, 1) > 0) - { - buf[i++] = c; - n++; - } - - printf("n=%d %02x %02x %02x %02x %02x\n", n, buf[0], buf[1], buf[2], buf[3], - buf[4]); - 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("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[]) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = getmyline5(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } if (bytes != 5) diff --git a/simulators/simft818.c b/simulators/simft818.c index 93fd37cc5..79813b509 100644 --- a/simulators/simft818.c +++ b/simulators/simft818.c @@ -1,21 +1,14 @@ // 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 #include -#include #include #include -#include "hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + float freqA = 14074000; float freqB = 14074500; @@ -27,90 +20,13 @@ char modeB = '1'; int width = 0; int ptt; -// 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_FTDX3000DM = 462, - 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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char resp[256]; char *pbuf; int n; diff --git a/simulators/simft847.c b/simulators/simft847.c index 91d031c12..a8800012a 100644 --- a/simulators/simft847.c +++ b/simulators/simft847.c @@ -1,21 +1,12 @@ // 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 -#include -#include #include #include -//#include "../include/hamlib/rig.h" +//#include "hamlib/rig.h" -#define BUFSIZE 256 +#include "sim.h" /* In hono(u)r of the 10Hz resolution of the FT-847, vfo frequencies * are stored in decaHertz(daHz) @@ -28,82 +19,20 @@ int width_sub = 700; int vfo; -int -getmyline(int fd, unsigned char *buf) -{ - unsigned char c; - int i = 0; - int n = 0; - memset(buf, 0, BUFSIZE); - - while (i < 5 && read(fd, &c, 1) > 0) - { - buf[i++] = c; - n++; - } - - printf("n=%d %02x %02x %02x %02x %02x\n", n, buf[0], buf[1], buf[2], buf[3], - buf[4]); - 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("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[]) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int freq, i, n; - -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = getmyline5(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } if (bytes != 5) diff --git a/simulators/simft897.c b/simulators/simft897.c index 8af0b36b9..0af8f83c8 100644 --- a/simulators/simft897.c +++ b/simulators/simft897.c @@ -1,21 +1,14 @@ // 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 #include #include #include #include -#include "../include/hamlib/rig.h" +#include "hamlib/rig.h" -#define BUFSIZE 256 +#include "sim.h" float freqA = 14074000; float freqB = 14074500; @@ -27,82 +20,20 @@ int width_main = 500; int width_sub = 700; -int -getmyline(int fd, unsigned char *buf) -{ - unsigned char c; - int i = 0; - int n = 0; - memset(buf, 0, BUFSIZE); - - while (i < 5 && read(fd, &c, 1) > 0) - { - buf[i++] = c; - n++; - } - - printf("n=%d %02x %02x %02x %02x %02x\n", n, buf[0], buf[1], buf[2], buf[3], - buf[4]); - 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("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[]) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int n; - -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = getmyline5(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } if (bytes != 5) diff --git a/simulators/simft990.c b/simulators/simft990.c index 5dbb569ea..0e22bea25 100644 --- a/simulators/simft990.c +++ b/simulators/simft990.c @@ -2,21 +2,12 @@ // emulates 1.2 ROM FT990 which can only read 1492 bytes #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 +#include "sim.h" float freqA = 14074000; float freqB = 14074500; @@ -27,29 +18,9 @@ char modeB = '1'; int width_main = 500; int width_sub = 700; +#define ALL_DATA_SIZE 1492 -// 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; - -static void load_dat(const char *filename, unsigned char buf[1492]) +static void load_dat(const char *filename, unsigned char buf[ALL_DATA_SIZE]) { FILE *fp = fopen(filename, "r"); char line[4096]; @@ -66,7 +37,7 @@ static void load_dat(const char *filename, unsigned char buf[1492]) sscanf(p, "%x", &val); buf[n++] = val; } - while (p = strtok(NULL, " \r\n")); + while ((p = strtok(NULL, " \r\n"))); strtok(s, "\r\n"); //printf("n=%d, %s\n",n,s); @@ -74,96 +45,35 @@ static void load_dat(const char *filename, unsigned char buf[1492]) } fclose(fp); - printf("%d bytes read\n", n); + printf("%d bytes read from file %s\n", n, filename); } -static unsigned char alldata[1492]; - -int -getmyline(int fd, char *buf) -{ - unsigned char c; - int i = 0; - int n = 0; - memset(buf, 0, BUFSIZE); - -#if 1 - - while (i < 5 && read(fd, &c, 1) > 0) - { - buf[i++] = c; - n++; - } - -#else - n = read(fd, buf, 5); -#endif - printf("n=%d %02x %02x %02x %02x %02x\n", n, buf[0], buf[1], buf[2], buf[3], - buf[4]); - 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("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 - - +static unsigned char alldata[ALL_DATA_SIZE]; int main(int argc, char *argv[]) { - char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); load_dat("simft990.dat", alldata); while (1) { - int bytes = getmyline(fd, buf); + int bytes = getmyline5(fd, buf); if (bytes == 0) { continue; } if (bytes != 5) { printf("Not 5 bytes? bytes=%d\n", bytes); + continue; } + // Protocol of rigs/yaesu/ft990v12.c + if (buf[4] == 0x10) { - write(fd, alldata, 1492); + write(fd, alldata, ALL_DATA_SIZE); } } diff --git a/simulators/simft991.c b/simulators/simft991.c index 6d420ae9b..fb1d9e829 100644 --- a/simulators/simft991.c +++ b/simulators/simft991.c @@ -1,21 +1,13 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + float freqA = 14074000; float freqB = 14074500; @@ -31,89 +23,13 @@ int vd = 0; int sm0 = 0; int sm1 = 0; -// 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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int n; int fd = openPort(argv[1]); diff --git a/simulators/simftdx101.c b/simulators/simftdx101.c index dc0b39532..eb240a300 100644 --- a/simulators/simftdx101.c +++ b/simulators/simftdx101.c @@ -1,21 +1,13 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + float freqA = 14074000; float freqB = 14074500; @@ -39,89 +31,13 @@ int rport_gain_psk = 50; int syncvfo = 0; int ant = 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) - { - buf[i++] = c; - - if (c == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int n; int fd = openPort(argv[1]); diff --git a/simulators/simftdx1200.c b/simulators/simftdx1200.c index dac4e51f5..f6b56820f 100644 --- a/simulators/simftdx1200.c +++ b/simulators/simftdx1200.c @@ -1,21 +1,13 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + float freqA = 14074000; float freqB = 14074500; @@ -30,89 +22,13 @@ int na = 0; int ex039 = 0; int keyspd = 20; -// 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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int n; int fd = openPort(argv[1]); diff --git a/simulators/simftdx3000.c b/simulators/simftdx3000.c index b81c88570..d4cd4f851 100644 --- a/simulators/simftdx3000.c +++ b/simulators/simftdx3000.c @@ -1,21 +1,13 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + float freqA = 14074000; float freqB = 14074500; @@ -29,89 +21,13 @@ int sh = 25; int na = 0; int ex039 = 0; -// 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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int n; int fd = openPort(argv[1]); diff --git a/simulators/simftdx5000.c b/simulators/simftdx5000.c index 4a843af01..121542f4c 100644 --- a/simulators/simftdx5000.c +++ b/simulators/simftdx5000.c @@ -1,21 +1,13 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + float freqA = 14074000; float freqB = 14074500; @@ -31,89 +23,13 @@ int na = 0; int ex039 = 0; int ex103 = 0; -// 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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int n; int fd = openPort(argv[1]); diff --git a/simulators/simic2730.c b/simulators/simic2730.c index 3d2dcbce1..a509ba01f 100644 --- a/simulators/simic2730.c +++ b/simulators/simic2730.c @@ -3,27 +3,17 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -50,13 +40,6 @@ int transceive = 0; int keyspd = 20; int rigtime = 1230; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -64,8 +47,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -96,7 +77,7 @@ again: } i = 0; - goto again; + continue; } } @@ -515,43 +496,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 void rigStatus() { @@ -569,7 +513,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic275.c b/simulators/simic275.c index 0a6883ee1..8d8b1e7ff 100644 --- a/simulators/simic275.c +++ b/simulators/simic275.c @@ -3,27 +3,17 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -50,13 +40,6 @@ int transceive = 0; int keyspd = 20; int rigtime = 1230; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -64,8 +47,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -96,7 +77,7 @@ again: } i = 0; - goto again; + continue; } } @@ -510,43 +491,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 void rigStatus() { @@ -564,7 +508,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic7000.c b/simulators/simic7000.c index 06673d9fa..fb3a76572 100644 --- a/simulators/simic7000.c +++ b/simulators/simic7000.c @@ -3,27 +3,16 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" - -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -50,13 +39,6 @@ int transceive = 0; int keyspd = 20; int rigtime = 1230; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -64,8 +46,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -95,7 +75,7 @@ again: } i = 0; - goto again; + continue; } } @@ -528,44 +508,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -582,7 +524,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic705.c b/simulators/simic705.c index dfb051758..1ab2cd567 100644 --- a/simulators/simic705.c +++ b/simulators/simic705.c @@ -3,25 +3,14 @@ // Needs a lot of improvement to work on all Icoms #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 -#include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "hamlib/rig.h" +#include "misc.h" +#include "sim.h" /* Simulators really shouldn't be using ANY of the definitions * from the Hamlib rig.h parameters, but only those of the * rig itself. This still won't be a clean room implementation, @@ -30,7 +19,6 @@ struct ip_mreq */ #include "../rigs/icom/icom_defs.h" -#define BUFSIZE 256 #define X25 #undef SATMODE @@ -59,13 +47,6 @@ int ovf_status = 0; int powerstat = 1; const char *vfonames[2] = {"VFOA", "VFOB"}; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -73,8 +54,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -98,7 +77,7 @@ again: } i = 0; - goto again; + continue; } } @@ -586,43 +565,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 void rigStatus() { @@ -640,7 +582,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic7100.c b/simulators/simic7100.c index 7556f359a..2dc1c3ddf 100644 --- a/simulators/simic7100.c +++ b/simulators/simic7100.c @@ -3,28 +3,18 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" #undef ECHO -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -49,13 +39,6 @@ int ovf_status = 0; int powerstat = 1; int keyspd = 20; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -63,8 +46,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -95,7 +76,7 @@ again: } i = 0; - goto again; + continue; } } @@ -474,44 +455,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -528,7 +471,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic7200.c b/simulators/simic7200.c index a23989d66..90ab1e47a 100644 --- a/simulators/simic7200.c +++ b/simulators/simic7200.c @@ -3,27 +3,17 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -60,13 +50,6 @@ int speechcompressor = 0; int agc = 0; int vox = 0; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -74,8 +57,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -108,7 +89,7 @@ again: } i = 0; - goto again; + continue; } } @@ -804,44 +785,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -858,7 +801,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic7300.c b/simulators/simic7300.c index 3760b76d5..2f9d6152f 100644 --- a/simulators/simic7300.c +++ b/simulators/simic7300.c @@ -3,27 +3,17 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -50,13 +40,6 @@ int ovf_status = 0; int powerstat = 1; int keyertype = 0; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -64,8 +47,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -95,7 +76,7 @@ again: } i = 0; - goto again; + continue; } } @@ -715,44 +696,6 @@ if (n == 0) { printf("Write failed=%s\n", strerror(errno)); } } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -769,7 +712,7 @@ printf("%cVFOB: mode=%d datamode=%d width=%ld freq=%.0f\n", vfob, modeB, int main(int argc, char **argv) { -unsigned char buf[256]; +unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic7600.c b/simulators/simic7600.c index 666922c5f..610c4524b 100644 --- a/simulators/simic7600.c +++ b/simulators/simic7600.c @@ -3,27 +3,17 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 //#define X25 int civ_731_mode = 0; @@ -48,13 +38,6 @@ int ovf_status = 0; int powerstat = 1; int datamode = 0; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -62,8 +45,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -87,7 +68,7 @@ again: } i = 0; - goto again; + continue; } } @@ -626,44 +607,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -680,7 +623,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic7610.c b/simulators/simic7610.c index 74fe39706..9bc14af39 100644 --- a/simulators/simic7610.c +++ b/simulators/simic7610.c @@ -2,27 +2,16 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" - -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -52,13 +41,6 @@ int tx_inhibit = 0; int dpp = 0; int dualwatch = 0; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -66,8 +48,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -91,7 +71,7 @@ again: } i = 0; - goto again; + continue; } } @@ -732,44 +712,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -786,7 +728,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic7700.c b/simulators/simic7700.c index ce3e57444..4f7b671c0 100644 --- a/simulators/simic7700.c +++ b/simulators/simic7700.c @@ -3,27 +3,17 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -51,13 +41,6 @@ int ovf_status = 0; int powerstat = 1; int keyertype = 0; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -65,8 +48,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -90,7 +71,7 @@ again: } i = 0; - goto again; + continue; } } @@ -693,43 +674,6 @@ if (n == 0) { printf("Write failed=%s\n", strerror(errno)); } } -#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 void rigStatus() { @@ -747,7 +691,7 @@ printf("%cVFOB: mode=%d datamode=%d width=%ld freq=%.0f\n", vfob, modeB, int main(int argc, char **argv) { -unsigned char buf[256]; +unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic7851.c b/simulators/simic7851.c index 5a7c333dc..07074c256 100644 --- a/simulators/simic7851.c +++ b/simulators/simic7851.c @@ -2,27 +2,17 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -54,13 +44,6 @@ int notch = 0; int speechcompressor = 0; int vox = 0; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -68,8 +51,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c = 0xff; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -94,7 +75,7 @@ again: } i = 0; - goto again; + continue; } } @@ -796,43 +777,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 void rigStatus() { @@ -850,7 +794,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic905.c b/simulators/simic905.c index 7b7de3ba5..962d6fc97 100644 --- a/simulators/simic905.c +++ b/simulators/simic905.c @@ -3,28 +3,17 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" #include "sim.h" - -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -53,13 +42,6 @@ int keyspd = 25; int datamode = 0; int filter = 0; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -67,8 +49,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -92,7 +72,7 @@ again: } i = 0; - goto again; + continue; } } @@ -104,6 +84,7 @@ again: void frameParse(int fd, unsigned char *frame, int len) { double freq; + int freq_len = 5; if (len == 0) { @@ -125,7 +106,6 @@ void frameParse(int fd, unsigned char *frame, int len) case 0x03: //from_bcd(frameackbuf[2], (civ_731_mode ? 4 : 5) * 2); - int freq_len = 5; if (current_vfo == RIG_VFO_A || current_vfo == RIG_VFO_MAIN) { @@ -593,44 +573,6 @@ void frameParse(int fd, unsigned char *frame, int len) // don't care about the rig type yet } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -647,7 +589,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic910.c b/simulators/simic910.c index ee5301663..2b6b3f255 100644 --- a/simulators/simic910.c +++ b/simulators/simic910.c @@ -3,28 +3,18 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" #include "sim.h" -#define BUFSIZE 256 //#define X25 int civ_731_mode = 0; @@ -53,13 +43,6 @@ int keyspd = 25; int datamode = 0; int filter = 0; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -67,8 +50,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -92,7 +73,7 @@ again: } i = 0; - goto again; + continue; } } @@ -104,6 +85,7 @@ again: void frameParse(int fd, unsigned char *frame, int len) { double freq; + int freq_len = 5; if (len == 0) { @@ -128,7 +110,6 @@ void frameParse(int fd, unsigned char *frame, int len) case 0x03: //from_bcd(frameackbuf[2], (civ_731_mode ? 4 : 5) * 2); - int freq_len = 5; if (current_vfo == RIG_VFO_A || current_vfo == RIG_VFO_MAIN) { @@ -596,44 +577,6 @@ void frameParse(int fd, unsigned char *frame, int len) // don't care about the rig type yet } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -650,7 +593,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic9100.c b/simulators/simic9100.c index 25a3bf0e7..82c9efd6d 100644 --- a/simulators/simic9100.c +++ b/simulators/simic9100.c @@ -3,27 +3,16 @@ // Needs a lot of improvement to work on all Icoms #define _XOPEN_SOURCE 700 // since we are POSIX here we need this -#if 0 -struct ip_mreq -{ - int dummy; -}; -#endif -#include "hamlib/rig.h" #include -#include #include #include #include -#include -#include "../src/misc.h" -#include -#include -#include #include -#include "sim.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "sim.h" +#include "misc.h" + //#define X25 int civ_731_mode = 0; @@ -48,13 +37,6 @@ int ovf_status = 0; int powerstat = 1; int subband = 1; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -62,8 +44,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -87,7 +67,7 @@ again: } i = 0; - goto again; + continue; } } @@ -529,44 +509,6 @@ printf("+++++++++++++++ SETTING VFO +++++++++++++++++\n"); // don't care about the rig type yet } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -583,7 +525,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simic9700.c b/simulators/simic9700.c index ee64eaf44..61d26aba2 100644 --- a/simulators/simic9700.c +++ b/simulators/simic9700.c @@ -3,28 +3,17 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" #include "sim.h" -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -50,13 +39,6 @@ int ovf_status = 0; int powerstat = 1; int keyspd = 90; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -64,8 +46,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -89,7 +69,7 @@ again: } i = 0; - goto again; + continue; } } @@ -558,44 +538,6 @@ void frameParse(int fd, unsigned char *frame, int len) // don't care about the rig type yet } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -612,7 +554,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simicgeneric.c b/simulators/simicgeneric.c index 4e26e284f..98996f6ea 100644 --- a/simulators/simicgeneric.c +++ b/simulators/simicgeneric.c @@ -3,24 +3,16 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" +#include "misc.h" #include "sim.h" -#define BUFSIZE 256 //#define X25 int civ_731_mode = 0; @@ -40,13 +32,6 @@ ant_t ant_curr = 0; int ant_option = 0; int ptt = 0; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -396,44 +381,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -450,7 +397,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simicr8600.c b/simulators/simicr8600.c index b5522e5ad..5ab35dbe1 100644 --- a/simulators/simicr8600.c +++ b/simulators/simicr8600.c @@ -3,24 +3,16 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" +#include "misc.h" #include "sim.h" -#define BUFSIZE 256 //#define X25 int civ_731_mode = 0; @@ -40,13 +32,6 @@ ant_t ant_curr = 0; int ant_option = 0; int ptt = 0; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -391,44 +376,6 @@ void frameParse(int fd, unsigned char *frame, int len) } } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -445,7 +392,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simid5100.c b/simulators/simid5100.c index 08e08f50d..b6d4b47d6 100644 --- a/simulators/simid5100.c +++ b/simulators/simid5100.c @@ -3,27 +3,17 @@ // Needs a lot of improvement to work on all Icoms #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 +#include + #include "hamlib/rig.h" -#include "../src/misc.h" -#include -#include +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 int civ_731_mode = 0; vfo_t current_vfo = RIG_VFO_A; @@ -45,13 +35,6 @@ int agc_time = 1; int ovf_status = 0; int powerstat = 1; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -59,8 +42,6 @@ frameGet(int fd, unsigned char *buf) memset(buf, 0, BUFSIZE); unsigned char c; -again: - while (read(fd, &c, 1) > 0) { buf[i++] = c; @@ -84,7 +65,7 @@ again: } i = 0; - goto again; + continue; } } @@ -387,44 +368,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 - void rigStatus() { char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; @@ -439,7 +382,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simjupiter.c b/simulators/simjupiter.c index f4a383ebc..9c96078d0 100644 --- a/simulators/simjupiter.c +++ b/simulators/simjupiter.c @@ -1,21 +1,11 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "sim.h" float freqA = 14074000; float freqB = 14074500; @@ -27,80 +17,19 @@ int width_main = 500; int width_sub = 700; -int -getmyline(int fd, unsigned char *buf) -{ - unsigned char c; - int i = 0; - int n = 0; - memset(buf, 0, BUFSIZE); - - while (i < 5 && read(fd, &c, 1) > 0) - { - buf[i++] = c; - n++; - } - - printf("n=%d %02x %02x %02x %02x %02x\n", n, buf[0], buf[1], buf[2], buf[3], - buf[4]); - 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("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[]) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = getmyline5(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } if (bytes != 5) diff --git a/simulators/simkenwood.c b/simulators/simkenwood.c index daa7575f1..fd9e6d4ba 100644 --- a/simulators/simkenwood.c +++ b/simulators/simkenwood.c @@ -1,21 +1,13 @@ // 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 -#include -#include #include #include -#include "hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + int mysleep = 20; @@ -25,68 +17,13 @@ int filternum = 7; int datamode = 0; int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; -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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int fd = openPort(argv[1]); int freqa = 14074000, freqb = 140735000; diff --git a/simulators/simmicom.c b/simulators/simmicom.c index 76aef1e0e..3b25b6c0b 100644 --- a/simulators/simmicom.c +++ b/simulators/simmicom.c @@ -1,20 +1,11 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#include "../src/misc.h" + +#include "misc.h" #define BUFSIZE 256 @@ -29,7 +20,7 @@ int width_sub = 700; int -getmyline(int fd, unsigned char *buf) +_getmyline(int fd, unsigned char *buf) { int i = 0; int n = 0; @@ -52,62 +43,22 @@ getmyline(int fd, unsigned char *buf) 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("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 - +#include "sim.h" int main(int argc, char *argv[]) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; - -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = _getmyline(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } switch (buf[3]) diff --git a/simulators/simorion.c b/simulators/simorion.c index cbb11edb7..642e40b1e 100644 --- a/simulators/simorion.c +++ b/simulators/simorion.c @@ -1,19 +1,9 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" #define BUFSIZE 256 @@ -25,7 +15,7 @@ int ptt = 0; int keyspd = 20; int -getmyline(int fd, char *buf) +_getmyline(int fd, char *buf) { unsigned char c; int i = 0; @@ -43,61 +33,22 @@ getmyline(int fd, char *buf) 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("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 - +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256], reply[256]; + char buf[BUFSIZE], reply[256]; -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = _getmyline(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } if (strncmp(buf, "?V", 2) == 0) diff --git a/simulators/simpmr171.c b/simulators/simpmr171.c index cc3c9cc4d..adf726425 100644 --- a/simulators/simpmr171.c +++ b/simulators/simpmr171.c @@ -1,19 +1,9 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" #define BUFSIZE 256 @@ -28,7 +18,7 @@ int width_sub = 700; int -getmyline(int fd, unsigned char *buf) +_getmyline(int fd, unsigned char *buf) { unsigned char c; int i = 0; @@ -59,61 +49,22 @@ getmyline(int fd, unsigned char *buf) 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("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 - +#include "sim.h" int main(int argc, char *argv[]) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = _getmyline(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } switch (buf[5]) diff --git a/simulators/simpowersdr.c b/simulators/simpowersdr.c index a3701831c..8c7d8ca38 100644 --- a/simulators/simpowersdr.c +++ b/simulators/simpowersdr.c @@ -1,21 +1,13 @@ // 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 -#include -#include #include #include -#include "hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + float freqA = 14074000; float freqB = 14074500; @@ -26,68 +18,13 @@ int keyspd = 20; double alc = 0; int tx; -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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int n; int fd = openPort(argv[1]); diff --git a/simulators/simpstrotator.c b/simulators/simpstrotator.c index 74e7cd01a..f63847aae 100644 --- a/simulators/simpstrotator.c +++ b/simulators/simpstrotator.c @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #define SERVER_PORT 12001 #define REPLY_PORT 12002 diff --git a/simulators/simqrplabs.c b/simulators/simqrplabs.c index c389ff2c8..f9f44e5a4 100644 --- a/simulators/simqrplabs.c +++ b/simulators/simqrplabs.c @@ -1,21 +1,14 @@ // 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 -#include -#include #include #include -#include "hamlib/rig.h" +#include + +#include "hamlib/rig.h" +#include "misc.h" -#define BUFSIZE 256 int mysleep = 20; @@ -26,68 +19,13 @@ int datamode = 0; int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; int tomode = 0; -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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int fd = openPort(argv[1]); int freqa = 14074000, freqb = 140735000; diff --git a/simulators/simrotorez.c b/simulators/simrotorez.c index d1688a9b3..7b4ba21d5 100644 --- a/simulators/simrotorez.c +++ b/simulators/simrotorez.c @@ -1,26 +1,20 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" +#include + +#include "hamlib/rig.h" +#include "misc.h" #define BUFSIZE 256 static void *rotorez_thread(void *arg); int -getmyline(int fd, char *buf) +_getmyline(int fd, char *buf) { unsigned char c = 0; int i = 0; @@ -44,43 +38,7 @@ getmyline(int fd, char *buf) 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("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 +#include "sim.h" int thread_args[2]; @@ -103,8 +61,8 @@ int main(int argc, char *argv[]) while (1) { int bytes; - if (!flag) bytes = getmyline(fd, buf); - else bytes = getmyline(fd2, buf); + if (!flag) bytes = _getmyline(fd, buf); + else bytes = _getmyline(fd2, buf); flag = !flag; if (bytes == 0) @@ -149,23 +107,20 @@ int main(int argc, char *argv[]) static void *rotorez_thread(void *arg) { int n = 0; - char buf[256]; + char buf[BUFSIZE]; int fd = *(int *)arg; float az = 123; float el = 45; -again: while (1) { int bytes; - bytes = getmyline(fd, buf); + bytes = _getmyline(fd, buf); if (bytes == 0) { - //close(fd); hl_usleep(100 * 1000); - //printf("again\n"); - goto again; + continue; } printf("line[%d]=%s\n", fd, buf); diff --git a/simulators/simspid.c b/simulators/simspid.c index b0783adf0..9c96078d0 100644 --- a/simulators/simspid.c +++ b/simulators/simspid.c @@ -1,21 +1,11 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" -#define BUFSIZE 256 +#include "sim.h" float freqA = 14074000; float freqB = 14074500; @@ -27,81 +17,19 @@ int width_main = 500; int width_sub = 700; -int -getmyline(int fd, unsigned char *buf) -{ - unsigned char c; - int i = 0; - int n = 0; - memset(buf, 0, BUFSIZE); - - while (i < 5 && read(fd, &c, 1) > 0) - { - buf[i++] = c; - n++; - } - - printf("n=%d %02x %02x %02x %02x %02x\n", n, buf[0], buf[1], buf[2], buf[3], - buf[4]); - 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("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[]) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; - -again: int fd = openPort(argv[1]); while (1) { - int bytes = getmyline(fd, buf); + int bytes = getmyline5(fd, buf); if (bytes == 0) { - close(fd); - goto again; + continue; } if (bytes != 5) diff --git a/simulators/simtmd700.c b/simulators/simtmd700.c index 5bb363533..2abf667cd 100644 --- a/simulators/simtmd700.c +++ b/simulators/simtmd700.c @@ -1,19 +1,12 @@ // 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 -#include -#include #include #include -#include "../include/hamlib/rig.h" + +#include "hamlib/rig.h" +#include "misc.h" #define BUFSIZE 256 double freqA = 147000000; @@ -26,7 +19,7 @@ int band = 0; int control = 1; int -getmyline(int fd, char *buf) +_getmyline(int fd, char *buf) { char c; int i = 0; @@ -44,55 +37,18 @@ getmyline(int fd, char *buf) 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 - +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; int n; int fd = openPort(argv[1]); while (1) { - if (getmyline(fd, buf)) + if (_getmyline(fd, buf)) { printf("Cmd:%s\n", buf); } diff --git a/simulators/simtmd710.c b/simulators/simtmd710.c index 9cd53ebc1..3e5a8b9e7 100644 --- a/simulators/simtmd710.c +++ b/simulators/simtmd710.c @@ -1,18 +1,10 @@ // 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 -#include -#include #include #include + #include "hamlib/rig.h" #define BUFSIZE 256 @@ -26,7 +18,7 @@ int datamode = 0; int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; int -getmyline(int fd, char *buf) +_getmyline(int fd, char *buf) { char c; int i = 0; @@ -44,74 +36,42 @@ getmyline(int fd, char *buf) 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 - +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; int fd = openPort(argv[1]); while (1) { buf[0] = 0; - if (getmyline(fd, buf) > 0) { printf("Cmd:%s\n", buf); } + 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); + 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); + char vfo = buf[3]; + int frequency; + char tone_frequency[] = "10"; // 94.8 + char ctcss_frequency[] = "05"; // 79,7 + char dcs_frequency[] = "016"; // 114 + + if (vfo == '0') { + frequency = (int)freqA; + } else { + frequency = (int)freqB; } + SNPRINTF(buf, sizeof(buf), "FO %c,%.10d,0,0,0,0,0,0,%.2s,%.2s,%.3s,00000000,0%c", + vfo, frequency, tone_frequency, ctcss_frequency, dcs_frequency, 0x0d); printf("R:%s\n", buf); write(fd, buf, strlen(buf)); diff --git a/simulators/simtrusdx.c b/simulators/simtrusdx.c index e12b5d22a..58241c19a 100644 --- a/simulators/simtrusdx.c +++ b/simulators/simtrusdx.c @@ -1,22 +1,14 @@ // 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 -#include -#include #include #include -#include "hamlib/rig.h" -#include "sim.h" +#include + +#include "hamlib/rig.h" +#include "misc.h" -#define BUFSIZE 256 int mysleep = 20; @@ -28,68 +20,13 @@ int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; int tomode = 0; int keyspd = 25; -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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int fd = openPort(argv[1]); int freqa = 14074000, freqb = 140735000; diff --git a/simulators/simts450.c b/simulators/simts450.c index 81f7d5615..be89a2398 100644 --- a/simulators/simts450.c +++ b/simulators/simts450.c @@ -1,22 +1,14 @@ // 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 -#include -#include #include #include -#include "hamlib/rig.h" -#include "sim.h" +#include + +#include "hamlib/rig.h" +#include "misc.h" -#define BUFSIZE 256 int mysleep = 20; @@ -28,68 +20,13 @@ int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; int tomode = 0; int keyspd = 25; -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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int fd = openPort(argv[1]); int freqa = 14074000, freqb = 140735000; diff --git a/simulators/simts590.c b/simulators/simts590.c index 6bad05597..5a51e309b 100644 --- a/simulators/simts590.c +++ b/simulators/simts590.c @@ -1,22 +1,15 @@ // 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 -#include -#include #include #include +#include + #include "hamlib/rig.h" #include "sim.h" +#include "misc.h" -#define BUFSIZE 256 int mysleep = 20; @@ -34,7 +27,7 @@ int usb_af_input = 9; int mic_gain = 50; int -getmyline(int fd, char *buf) +_getmyline(int fd, char *buf) { char c; int i = 0; @@ -54,49 +47,11 @@ getmyline(int fd, char *buf) 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]; + char buf[BUFSIZE]; char *pbuf; int fd = openPort(argv[1]); int freqa = 14074000, freqb = 140735000; @@ -106,7 +61,7 @@ int main(int argc, char *argv[]) { buf[0] = 0; - if (getmyline(fd, buf) > 0) { printf("Cmd:%s\n", buf); } + if (_getmyline(fd, buf) > 0) { printf("Cmd:%s\n", buf); } // else { return 0; } diff --git a/simulators/simts890.c b/simulators/simts890.c index 6e29a7f7f..32ea9e188 100644 --- a/simulators/simts890.c +++ b/simulators/simts890.c @@ -27,22 +27,14 @@ // 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 "config.h" #include #include -#include #include #include -#include #include #include + +#include "config.h" //#include "hamlib/rig.h" /* Definitions */ @@ -52,8 +44,6 @@ struct ip_mreq * app is only using the latest-and-greatest, comment out the next define. */ #define LEGACY -// Size of command buffer -#define BUFSIZE 256 // Number of selectable bands #define NBANDS 11 /* Type we're emulating - K=The Americas(default), E=Europe */ @@ -211,74 +201,12 @@ static void swapvfos(kvfop_t *vfoset[]); // Extracted from rig.h int hl_usleep(unsigned long usec); // Until it's replaced -#if defined(WIN32) || defined(_WIN32) -int openPort(char *comport) // doesn't matter for using pts devices -{ - int fd; - fd = open(comport, O_RDWR); +#include "sim.h" - 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 -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - int retval; - - while ((retval = read(fd, &c, 1)) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (retval != 0) - { - perror("read failed:"); - //close(fd); - //fd = openPort(""); - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int fd = openPort(argv[1]); int cmd_err = 0; diff --git a/simulators/simts950.c b/simulators/simts950.c index b7a1d6c08..70ace6062 100644 --- a/simulators/simts950.c +++ b/simulators/simts950.c @@ -1,21 +1,14 @@ // 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 -#include -#include #include #include -#include "hamlib/rig.h" +#include + +#include "hamlib/rig.h" +#include "misc.h" -#define BUFSIZE 256 int mysleep = 20; @@ -26,68 +19,13 @@ int filternum2 = 8; int datamode = 0; int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; -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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int fd = openPort(argv[1]); int freqa = 14074000, freqb = 140735000; diff --git a/simulators/simts990.c b/simulators/simts990.c index db5158c70..d2b96b5af 100644 --- a/simulators/simts990.c +++ b/simulators/simts990.c @@ -1,22 +1,14 @@ // 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 -#include -#include #include #include -#include -#include "hamlib/rig.h" +#include + +#include "hamlib/rig.h" +#include "misc.h" -#define BUFSIZE 256 int mysleep = 20; @@ -60,76 +52,14 @@ int mo1 = 0; int pc = 50; -#if defined(WIN32) || defined(_WIN32) -int openPort(char *comport) // doesn't matter for using pts devices -{ - int fd; - fd = open(comport, O_RDWR); +#include "sim.h" - 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 -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - int retval; - - while ((retval = read(fd, &c, 1)) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (retval != 0) - { - perror("read failed:"); - //close(fd); - //fd = openPort(""); - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char *pbuf; int fd = openPort(argv[1]); char modeA = '1', modeB = '2'; diff --git a/simulators/simxiegug90.c b/simulators/simxiegug90.c index 287f9536b..755ff2ebf 100644 --- a/simulators/simxiegug90.c +++ b/simulators/simxiegug90.c @@ -3,23 +3,15 @@ // Needs a lot of improvement to work on all Icoms #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" -#include "../src/misc.h" +#include + +#include "hamlib/rig.h" +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -40,13 +32,6 @@ int ant_option = 0; int ptt = 0; int keyspd = 20; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -411,43 +396,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 void rigStatus() { @@ -465,7 +413,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simxiegux108g.c b/simulators/simxiegux108g.c index 031113728..501e56b46 100644 --- a/simulators/simxiegux108g.c +++ b/simulators/simxiegux108g.c @@ -3,23 +3,15 @@ // Needs a lot of improvement to work on all Icoms #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" -#include "../src/misc.h" +#include + +#include "hamlib/rig.h" +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -40,13 +32,6 @@ int ant_option = 0; int ptt = 0; int keyspd = 20; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -403,43 +388,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 void rigStatus() { @@ -457,7 +405,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simxiegux6100.c b/simulators/simxiegux6100.c index f871d8399..9d0726d89 100644 --- a/simulators/simxiegux6100.c +++ b/simulators/simxiegux6100.c @@ -3,23 +3,15 @@ // Needs a lot of improvement to work on all Icoms #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" -#include "../src/misc.h" +#include + +#include "hamlib/rig.h" +#include "misc.h" +#include "sim.h" -#define BUFSIZE 256 #define X25 int civ_731_mode = 0; @@ -40,13 +32,6 @@ int ant_option = 0; int ptt = 0; int keyspd = 20; -void dumphex(const unsigned char *buf, int n) -{ - for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } - - printf("\n"); -} - int frameGet(int fd, unsigned char *buf) { @@ -416,43 +401,6 @@ void frameParse(int fd, unsigned char *frame, int len) } -#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 void rigStatus() { @@ -470,7 +418,7 @@ void rigStatus() int main(int argc, char **argv) { - unsigned char buf[256]; + unsigned char buf[BUFSIZE]; int fd = openPort(argv[1]); printf("%s: %s\n", argv[0], rig_version()); diff --git a/simulators/simyaesu.c b/simulators/simyaesu.c index cc57d818f..fd610c6b5 100644 --- a/simulators/simyaesu.c +++ b/simulators/simyaesu.c @@ -1,21 +1,13 @@ // 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 -#include -#include #include #include -#include "hamlib/rig.h" -#define BUFSIZE 256 +#include "hamlib/rig.h" +#include "misc.h" + float freqA = 14074000; float freqB = 14074500; @@ -33,90 +25,13 @@ int width_sub = 0; int ex039 = 0; int lk = 0; -// 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_FTDX3000DM = 462, - 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 == ';') { 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("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 +#include "sim.h" int main(int argc, char *argv[]) { - char buf[256]; + char buf[BUFSIZE]; char resp[256]; char *pbuf; int n; @@ -138,6 +53,9 @@ int main(int argc, char *argv[]) if (power == 0 && strcmp(buf, "PS1;") != 0) { continue; } + resp[0] = 0; + pbuf = NULL; + if (strcmp(buf, "PS;") == 0) { sprintf(resp, "PS%d;", power); @@ -151,7 +69,6 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "RM5;") == 0) { - printf("%s\n", buf); hl_usleep(50 * 1000); pbuf = "RM5100000;"; n = write(fd, pbuf, strlen(pbuf)); @@ -161,7 +78,6 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "RM8;") == 0) { - printf("%s\n", buf); hl_usleep(50 * 1000); pbuf = "RM8197000;"; n = write(fd, pbuf, strlen(pbuf)); @@ -171,7 +87,6 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "RM9;") == 0) { - printf("%s\n", buf); hl_usleep(50 * 1000); pbuf = "RM9089000;"; n = write(fd, pbuf, strlen(pbuf)); @@ -182,7 +97,6 @@ int main(int argc, char *argv[]) else if (strcmp(buf, "AN0;") == 0) { - printf("%s\n", buf); hl_usleep(50 * 1000); pbuf = "AN030;"; n = write(fd, pbuf, strlen(pbuf)); @@ -213,7 +127,6 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "IF;") == 0) { - printf("%s\n", buf); hl_usleep(50 * 1000); pbuf = "IF00107041000+000000200000;"; n = write(fd, pbuf, strlen(pbuf)); @@ -223,21 +136,19 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "ID;") == 0) { - printf("%s\n", buf); hl_usleep(50 * 1000); int id = NC_RIGID_FT991; - SNPRINTF(buf, sizeof(buf), "ID%03d;", id); - n = write(fd, buf, strlen(buf)); + SNPRINTF(resp, sizeof(resp), "ID%03d;", id); + n = write(fd, resp, strlen(resp)); //printf("n=%d\n", n); if (n <= 0) { perror("ID"); } } else if (strcmp(buf, "AI;") == 0) { - printf("%s\n", buf); hl_usleep(50 * 1000); - SNPRINTF(buf, sizeof(buf), "AI0;"); - n = write(fd, buf, strlen(buf)); + SNPRINTF(resp, sizeof(resp), "AI0;"); + n = write(fd, resp, strlen(resp)); //printf("n=%d\n", n); if (n <= 0) { perror("AI"); } @@ -257,8 +168,7 @@ int main(int argc, char *argv[]) { if (strcmp(buf, "AI;")) { - printf("%s\n", buf); - hl_usleep(50 * 1000); + hl_usleep(50 * 1000); n = fprintf(fp, "%s", "AI0;"); printf("n=%d\n", n); @@ -274,7 +184,6 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "VS;") == 0) { - printf("%s\n", buf); hl_usleep(50 * 1000); pbuf = "VS0;"; @@ -352,51 +261,50 @@ int main(int argc, char *argv[]) { static int ant = 0; ant = (ant + 1) % 3; - printf("%s\n", buf); hl_usleep(50 * 1000); - SNPRINTF(buf, sizeof(buf), "EX032%1d;", ant); - n = write(fd, buf, strlen(buf)); + SNPRINTF(resp, sizeof(resp), "EX032%1d;", ant); + n = write(fd, resp, strlen(resp)); //printf("n=%d\n", n); if (n < 0) { perror("EX032"); } } else if (strcmp(buf, "NA0;") == 0) { - SNPRINTF(buf, sizeof(buf), "NA00;"); + SNPRINTF(resp, sizeof(resp), "NA00;"); hl_usleep(50 * 1000); - n = write(fd, buf, strlen(buf)); - //printf("%s n=%d\n", buf, n); + n = write(fd, resp, strlen(resp)); + //printf("%s n=%d\n", resp, n); } else if (strcmp(buf, "RF0;") == 0) { - SNPRINTF(buf, sizeof(buf), "RF0%d;", roofing_filter_main); + SNPRINTF(resp, sizeof(resp), "RF0%d;", roofing_filter_main); hl_usleep(50 * 1000); - n = write(fd, buf, strlen(buf)); + n = write(fd, resp, strlen(resp)); } else if (strcmp(buf, "RF1;") == 0) { - SNPRINTF(buf, sizeof(buf), "RF1%d;", roofing_filter_sub); + SNPRINTF(resp, sizeof(resp), "RF1%d;", roofing_filter_sub); hl_usleep(50 * 1000); - n = write(fd, buf, strlen(buf)); + n = write(fd, resp, strlen(resp)); } else if (strncmp(buf, "RF", 2) == 0) { - SNPRINTF(buf, sizeof(buf), "RF%c%d;", buf[2], + SNPRINTF(resp, sizeof(resp), "RF%c%d;", buf[2], buf[2] == 0 ? roofing_filter_main : roofing_filter_sub); hl_usleep(50 * 1000); - n = write(fd, buf, strlen(buf)); + n = write(fd, resp, strlen(resp)); } else if (strcmp(buf, "SH0;") == 0) { - SNPRINTF(buf, sizeof(buf), "SH%c%02d;", buf[2], width_main); + SNPRINTF(resp, sizeof(resp), "SH%c%02d;", buf[2], width_main); hl_usleep(50 * 1000); - n = write(fd, buf, strlen(buf)); + n = write(fd, resp, strlen(resp)); } else if (strcmp(buf, "SH1;") == 0) { - SNPRINTF(buf, sizeof(buf), "SH%c%02d;", buf[2], width_sub); + SNPRINTF(resp, sizeof(resp), "SH%c%02d;", buf[2], width_sub); hl_usleep(50 * 1000); - n = write(fd, buf, strlen(buf)); + n = write(fd, resp, strlen(resp)); } else if (strncmp(buf, "SH", 2) == 0 && strlen(buf) > 4) { @@ -410,13 +318,13 @@ int main(int argc, char *argv[]) } else if (strncmp(buf, "SH", 2) == 0) { - SNPRINTF(buf, sizeof(buf), "SH%c%02d;", buf[2], + SNPRINTF(resp, sizeof(resp), "SH%c%02d;", buf[2], buf[2] == 0 ? width_main : width_sub); } else if (strcmp(buf, "EX039;") == 0) { - SNPRINTF(buf, sizeof(buf), "EX039%d;", ex039); - n = write(fd, buf, strlen(buf)); + SNPRINTF(resp, sizeof(resp), "EX039%d;", ex039); + n = write(fd, resp, strlen(resp)); } else if (strncmp(buf, "EX039", 5) == 0) { @@ -424,8 +332,8 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "LK;") == 0) { - SNPRINTF(buf, sizeof(buf), "LK%d;", lk); - n = write(fd, buf, strlen(buf)); + SNPRINTF(resp, sizeof(resp), "LK%d;", lk); + n = write(fd, resp, strlen(resp)); } else if (strncmp(buf, "LK", 3) == 0) { @@ -433,18 +341,18 @@ int main(int argc, char *argv[]) } else if (strncmp(buf, "DT0;", 4) == 0) { - SNPRINTF(buf, sizeof(buf), "DT020221022;"); - n = write(fd, buf, strlen(buf)); + SNPRINTF(resp, sizeof(resp), "DT020221022;"); + n = write(fd, resp, strlen(resp)); } else if (strncmp(buf, "DT1;", 4) == 0) { - SNPRINTF(buf, sizeof(buf), "DT1222100;"); - n = write(fd, buf, strlen(buf)); + SNPRINTF(resp, sizeof(resp), "DT1222100;"); + n = write(fd, resp, strlen(resp)); } else if (strncmp(buf, "DT2;", 4) == 0) { - SNPRINTF(buf, sizeof(buf), "DT2+0500;"); - n = write(fd, buf, strlen(buf)); + SNPRINTF(resp, sizeof(resp), "DT2+0500;"); + n = write(fd, resp, strlen(resp)); } @@ -453,6 +361,14 @@ int main(int argc, char *argv[]) fprintf(stderr, "Unknown command: '%s'\n", buf); } + if (pbuf) + { + printf("Resp:%s\n", pbuf); + } + else if (resp[0]) + { + printf("Resp:%s\n", resp); + } } return 0;