diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 6a38c6744..33e36a905 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2569,7 +2569,7 @@ struct multicast_s pthread_mutex_t mutex; int mutex_initialized; //#ifdef HAVE_ARPA_INET_H - struct ip_mreq mreq; // = {0}; + //struct ip_mreq mreq; // = {0}; struct sockaddr_in dest_addr; // = {0}; int port; //#endif diff --git a/simulators/simatd578.c b/simulators/simatd578.c index 0e33c3feb..02bfb6f0a 100644 --- a/simulators/simatd578.c +++ b/simulators/simatd578.c @@ -2,10 +2,12 @@ // gcc -o simatd578 simatd578.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq { int dummy; }; +#endif #include #include @@ -40,10 +42,12 @@ getmyline(int fd, unsigned char *buf) do { int bytes = read(fd, &c, 1); + if (bytes > 0) { buf[i++] = c; } + n++; } while (c != 0x0a); @@ -171,8 +175,7 @@ again: buf2[15] = 0x00; buf2[16] = 0x06; - if (buf[4] == 0x20) { n = write(fd, buf2, 17); } - else { n = 0; } + n = write(fd, buf2, 17); } break; diff --git a/simulators/simelecraft.c b/simulators/simelecraft.c index 70c8f2e38..0d8faafb5 100644 --- a/simulators/simelecraft.c +++ b/simulators/simelecraft.c @@ -2,10 +2,12 @@ // gcc -o simyaesu simyaesu.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include @@ -124,7 +126,7 @@ int main(int argc, char *argv[]) { buf[0] = 0; - if ((n=getmyline(fd, buf)) > 0) { printf("Cmd:%s, len=%d\n", buf, n); } + if ((n = getmyline(fd, buf)) > 0) { printf("Cmd:%s, len=%d\n", buf, n); } else {continue; } if (strcmp(buf, "RM5;") == 0) @@ -139,13 +141,13 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "AI;") == 0) { - SNPRINTF(buf,sizeof(buf),"AI%d;", ai); + SNPRINTF(buf, sizeof(buf), "AI%d;", ai); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); } else if (strncmp(buf, "AI", 2) == 0) { - sscanf(buf,"AI%d", &ai); + sscanf(buf, "AI%d", &ai); } else if (strcmp(buf, "AN0;") == 0) @@ -187,7 +189,7 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "BW$;") == 0) { - fprintf(stderr,"***** %d\n", __LINE__); + fprintf(stderr, "***** %d\n", __LINE__); SNPRINTF(buf, sizeof(buf), "BW$%04d;", bandwidthB); n = write(fd, buf, strlen(buf)); } @@ -333,10 +335,6 @@ int main(int argc, char *argv[]) { n = write(fd, "RV02.37;", 8); } - else if (strcmp(buf, "AI;") == 0) - { - n = write(fd, "AI0;", 4); - } else if (strcmp(buf, "MD;") == 0) { SNPRINTF(buf, sizeof(buf), "MD%d;", modea); @@ -390,9 +388,9 @@ int main(int argc, char *argv[]) SNPRINTF(buf, sizeof(buf), "KS%03d;", keyspd); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"KS",2) == 0) + else if (strncmp(buf, "KS", 2) == 0) { - sscanf(buf,"KS%d", &keyspd); + sscanf(buf, "KS%d", &keyspd); } else if (strncmp(buf, "TQ;", 3) == 0) { @@ -440,14 +438,14 @@ int main(int argc, char *argv[]) { sscanf(buf, "RA$%d;", &rxattenuatorB); } - else if (strncmp(buf, "KY;", 3)==0) + else if (strncmp(buf, "KY;", 3) == 0) { int status = 0; printf("KY query\n"); SNPRINTF(buf, sizeof(buf), "KY%d;", status); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf, "KY",2)==0) + else if (strncmp(buf, "KY", 2) == 0) { printf("Morse: %s\n", buf); } @@ -456,6 +454,11 @@ int main(int argc, char *argv[]) fprintf(stderr, "Unknown command: %s\n", buf); } + if (n == 0) + { + fprintf(stderr, "Write error? n==0\n"); + } + } return 0; diff --git a/simulators/simft736.c b/simulators/simft736.c index 49df48660..a535ecbf1 100644 --- a/simulators/simft736.c +++ b/simulators/simft736.c @@ -2,10 +2,12 @@ // gcc -o simft897 simft897.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include diff --git a/simulators/simft747gx.c b/simulators/simft747gx.c index dd9ef2902..98814692f 100644 --- a/simulators/simft747gx.c +++ b/simulators/simft747gx.c @@ -2,10 +2,12 @@ // gcc -o simft747gx simft747gx.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include diff --git a/simulators/simft817.c b/simulators/simft817.c index 3688abe56..00adb9c3a 100644 --- a/simulators/simft817.c +++ b/simulators/simft817.c @@ -2,10 +2,12 @@ // gcc -o simft897 simft897.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include diff --git a/simulators/simft818.c b/simulators/simft818.c index bf331d372..a189ba995 100644 --- a/simulators/simft818.c +++ b/simulators/simft818.c @@ -2,10 +2,12 @@ // gcc -o simyaesu simyaesu.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include @@ -162,9 +164,9 @@ int main(int argc, char *argv[]) SNPRINTF(resp, sizeof(resp), "FB%08.0f;", freqB); n = write(fd, resp, strlen(resp)); } - else if (strncmp(buf, "FA", 2) == 0) + else if (strncmp(buf, "FB", 2) == 0) { - sscanf(buf, "FA%f", &freqA); + sscanf(buf, "FB%f", &freqA); } else if (strcmp(buf, "FB;") == 0) { @@ -241,12 +243,13 @@ int main(int argc, char *argv[]) { printf("%s\n", buf); hl_usleep(50 * 1000); - pbuf = "VS0;"; + pbuf = strdup("VS0;"); if (curr_vfo == RIG_VFO_B || curr_vfo == RIG_VFO_SUB) { pbuf[2] = '1'; } n = write(fd, pbuf, strlen(pbuf)); printf("%s\n", pbuf); + free(pbuf); if (n < 0) { perror("VS"); } } @@ -345,6 +348,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "Unknown command: %s\n", buf); } + if (n == 0) { fprintf(stderr, "Write error? n==0\n"); } + } return 0; diff --git a/simulators/simft847.c b/simulators/simft847.c index 577b76ef6..f473f96d9 100644 --- a/simulators/simft847.c +++ b/simulators/simft847.c @@ -2,10 +2,12 @@ // gcc -o simft897 simft897.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include diff --git a/simulators/simft897.c b/simulators/simft897.c index 577b76ef6..f473f96d9 100644 --- a/simulators/simft897.c +++ b/simulators/simft897.c @@ -2,10 +2,12 @@ // gcc -o simft897 simft897.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include diff --git a/simulators/simft990.c b/simulators/simft990.c index 49341a0f3..c0c38898e 100644 --- a/simulators/simft990.c +++ b/simulators/simft990.c @@ -3,10 +3,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 @@ -48,7 +50,7 @@ typedef enum nc_rigid_e NC_RIGID_FTDX101MP = 682 } nc_rigid_t; -void load_dat(char *filename, unsigned char buf[1492]) +void load_dat(const char *filename, unsigned char buf[1492]) { FILE *fp = fopen(filename, "r"); char line[4096]; diff --git a/simulators/simft991.c b/simulators/simft991.c index 380928f59..0a9066f3c 100644 --- a/simulators/simft991.c +++ b/simulators/simft991.c @@ -2,10 +2,12 @@ // gcc -o simyaesu simyaesu.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include @@ -289,35 +291,35 @@ int main(int argc, char *argv[]) } else if (strncmp(buf, "KS;", 3) == 0) { - sprintf(buf,"KS%d;", keyspd); + sprintf(buf, "KS%d;", keyspd); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"KS",2) == 0) + else if (strncmp(buf, "KS", 2) == 0) { - sscanf(buf,"KS%03d", &keyspd); + sscanf(buf, "KS%03d", &keyspd); } else if (strncmp(buf, "BS;", 3) == 0) // cannot query BS { - sprintf(buf,"BS%02d;", bandselect); + sprintf(buf, "BS%02d;", bandselect); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf, "SH0;", 4)==0) + else if (strncmp(buf, "SH0;", 4) == 0) { - sprintf(buf,"SH0%02d;", width); + sprintf(buf, "SH0%02d;", width); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf, "SH0", 3)==0) + else if (strncmp(buf, "SH0", 3) == 0) { - sscanf(buf,"SH0%02d", &width); + sscanf(buf, "SH0%02d", &width); } - else if (strncmp(buf, "NA0;", 4)==0) + else if (strncmp(buf, "NA0;", 4) == 0) { - sprintf(buf,"NA0%d;", narrow); + sprintf(buf, "NA0%d;", narrow); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf, "NA0", 3)==0) + else if (strncmp(buf, "NA0", 3) == 0) { - sscanf(buf,"NA0%d", &narrow); + sscanf(buf, "NA0%d", &narrow); } else if (strlen(buf) > 0) diff --git a/simulators/simftdx101.c b/simulators/simftdx101.c index ad3c60542..ba49b8621 100644 --- a/simulators/simftdx101.c +++ b/simulators/simftdx101.c @@ -2,10 +2,12 @@ // gcc -o simyaesu simyaesu.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include @@ -213,11 +215,6 @@ int main(int argc, char *argv[]) { sscanf(buf, "FB%f", &freqB); } - else if (strcmp(buf, "VS;") == 0) - { - SNPRINTF(buf, sizeof(buf), "VS%c;", vfo == 0 ? '0' : '1'); - n = write(fd, buf, strlen(buf)); - } else if (strcmp(buf, "FT;") == 0) { SNPRINTF(buf, sizeof(buf), "FT%d;", ft); @@ -230,7 +227,7 @@ int main(int argc, char *argv[]) } else if (strncmp(buf, "MD0", 3) == 0) { - sscanf(buf,"MD0%d", &modeA); + sscanf(buf, "MD0%d", &modeA); } else if (strcmp(buf, "MD1;") == 0) { @@ -239,7 +236,7 @@ int main(int argc, char *argv[]) } else if (strncmp(buf, "MD1", 3) == 0) { - sscanf(buf,"MD1%d", &modeB); + sscanf(buf, "MD1%d", &modeB); } else if (strcmp(buf, "VS;") == 0) { @@ -302,21 +299,21 @@ int main(int argc, char *argv[]) } else if (strncmp(buf, "KS;", 3) == 0) { - sprintf(buf,"KS%d;", keyspd); + sprintf(buf, "KS%d;", keyspd); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"KS",2) == 0) + else if (strncmp(buf, "KS", 2) == 0) { - sscanf(buf,"KS%03d", &keyspd); + sscanf(buf, "KS%03d", &keyspd); } else if (strncmp(buf, "ST;", 3) == 0) { - sprintf(buf,"ST%d;", split); + sprintf(buf, "ST%d;", split); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"ST",2) == 0) + else if (strncmp(buf, "ST", 2) == 0) { - sscanf(buf,"ST%d", &split); + sscanf(buf, "ST%d", &split); } else if (strlen(buf) > 0) diff --git a/simulators/simftdx1200.c b/simulators/simftdx1200.c index 2255f55be..c67ea8a15 100644 --- a/simulators/simftdx1200.c +++ b/simulators/simftdx1200.c @@ -3,9 +3,9 @@ #define _XOPEN_SOURCE 700 // since we are POSIX here we need this struct ip_mreq - { +{ int dummy; - }; +}; #include #include @@ -287,12 +287,12 @@ int main(int argc, char *argv[]) } else if (strncmp(buf, "KS;", 3) == 0) { - sprintf(buf,"KS%d;", keyspd); + sprintf(buf, "KS%d;", keyspd); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"KS",2) == 0) + else if (strncmp(buf, "KS", 2) == 0) { - sscanf(buf,"KS%03d", &keyspd); + sscanf(buf, "KS%03d", &keyspd); } else if (strlen(buf) > 0) diff --git a/simulators/simftdx3000.c b/simulators/simftdx3000.c index 937e1a990..d48476de6 100644 --- a/simulators/simftdx3000.c +++ b/simulators/simftdx3000.c @@ -2,10 +2,12 @@ // gcc -o simyaesu simyaesu.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include @@ -195,11 +197,6 @@ int main(int argc, char *argv[]) { sscanf(buf, "FB%f", &freqB); } - else if (strcmp(buf, "VS;") == 0) - { - SNPRINTF(buf, sizeof(buf), "VS%c;", vfo == 0 ? '0' : '1'); - n = write(fd, buf, strlen(buf)); - } else if (strcmp(buf, "FT;") == 0) { int val = ft; diff --git a/simulators/simftdx5000.c b/simulators/simftdx5000.c index 04334e90c..c28ad049e 100644 --- a/simulators/simftdx5000.c +++ b/simulators/simftdx5000.c @@ -2,10 +2,12 @@ // gcc -o simyaesu simyaesu.c #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq - { +{ int dummy; - }; +}; +#endif #include #include @@ -196,11 +198,6 @@ int main(int argc, char *argv[]) { sscanf(buf, "FB%f", &freqB); } - else if (strcmp(buf, "VS;") == 0) - { - SNPRINTF(buf, sizeof(buf), "VS%c;", vfo == 0 ? '0' : '1'); - n = write(fd, buf, strlen(buf)); - } else if (strcmp(buf, "FT;") == 0) { SNPRINTF(buf, sizeof(buf), "FT%d;", ft); diff --git a/simulators/simic7000.c b/simulators/simic7000.c index d0c224d0b..388ddd2f7 100644 --- a/simulators/simic7000.c +++ b/simulators/simic7000.c @@ -6,10 +6,12 @@ // gcc -static -I../include -g -Wall -o simicom simicom.c -L../../build/src/.libs -lhamlib -lwsock32 -lws2_32 #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq { int dummy; }; +#endif #include #include @@ -51,7 +53,7 @@ int transceive = 0; int keyspd = 20; int rigtime = 1230; -void dumphex(unsigned char *buf, int n) +void dumphex(const unsigned char *buf, int n) { for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } diff --git a/simulators/simic705.c b/simulators/simic705.c index 1c5b33ab1..5b270ed1a 100644 --- a/simulators/simic705.c +++ b/simulators/simic705.c @@ -6,10 +6,12 @@ // gcc -static -I../include -g -Wall -o simicom simicom.c -L../../build/src/.libs -lhamlib -lwsock32 -lws2_32 #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq { int dummy; }; +#endif #include #include @@ -49,7 +51,7 @@ int agc_time = 1; int ovf_status = 0; int powerstat = 1; -void dumphex(unsigned char *buf, int n) +void dumphex(const unsigned char *buf, int n) { for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } @@ -460,8 +462,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame2[9] = 0x00; frame2[10] = 0xfd; n = write(fd, frame2, 11); -#endif +#else n = write(fd, frame, 12); +#endif } else { diff --git a/simulators/simic7100.c b/simulators/simic7100.c index ab6143b57..a7494c9be 100644 --- a/simulators/simic7100.c +++ b/simulators/simic7100.c @@ -6,10 +6,12 @@ // gcc -static -I../include -g -Wall -o simicom simicom.c -L../../build/src/.libs -lhamlib -lwsock32 -lws2_32 #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq { int dummy; }; +#endif #include #include @@ -49,7 +51,7 @@ int ovf_status = 0; int powerstat = 1; int keyspd = 20; -void dumphex(unsigned char *buf, int n) +void dumphex(const unsigned char *buf, int n) { for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } @@ -284,6 +286,7 @@ void frameParse(int fd, unsigned char *frame, int len) frame[8] = 0xfd; n = write(fd, frame, 9); break; + case 0x0c: dumphex(frame, 10); printf("subcmd=0x0c #1\n"); diff --git a/simulators/simic7200.c b/simulators/simic7200.c index 8fcc33e4b..927df1f86 100644 --- a/simulators/simic7200.c +++ b/simulators/simic7200.c @@ -6,10 +6,12 @@ // gcc -static -I../include -g -Wall -o simicom simicom.c -L../../build/src/.libs -lhamlib -lwsock32 -lws2_32 #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq { int dummy; }; +#endif #include #include @@ -61,7 +63,7 @@ int speechcompressor = 0; int agc = 0; int vox = 0; -void dumphex(unsigned char *buf, int n) +void dumphex(const unsigned char *buf, int n) { for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } @@ -157,6 +159,8 @@ void frameParse(int fd, unsigned char *frame, int len) if (powerstat) { n = write(fd, frame, 11); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -177,6 +181,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x05: @@ -189,6 +196,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x06: @@ -198,6 +208,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x07: @@ -222,6 +235,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x0f: @@ -234,6 +250,8 @@ void frameParse(int fd, unsigned char *frame, int len) printf("get split %d\n", 1); frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -241,6 +259,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -251,6 +271,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = attenuator; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -258,6 +280,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -281,6 +305,9 @@ void frameParse(int fd, unsigned char *frame, int len) printf("write 8 bytes\n"); dump_hex(frame, 8); n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x14: @@ -294,6 +321,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = aflevel; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -301,6 +330,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -314,6 +345,9 @@ void frameParse(int fd, unsigned char *frame, int len) dumphex(frame, 6); hl_usleep(10 * 1000); n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + printf("ACK x14 x08\n"); } else @@ -322,6 +356,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[8] = 0xfd; dumphex(frame, 9); n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + printf("SEND x14 x08\n"); } @@ -337,6 +374,8 @@ void frameParse(int fd, unsigned char *frame, int len) keyspd = from_bcd(&frame[6], 2); frame[6] = 0xfb; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -344,6 +383,8 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], keyspd, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -357,6 +398,9 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)power_level, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -366,6 +410,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = mnf; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -373,6 +419,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -388,6 +436,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = ovf_status; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + ovf_status = ovf_status == 0 ? 1 : 0; break; @@ -400,6 +451,9 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)meter_level, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -412,6 +466,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = preamp; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -419,6 +475,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -429,6 +487,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = agc; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -436,6 +496,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -446,6 +508,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = noiseblanker; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -453,6 +517,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -463,6 +529,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = noisereduction; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -470,6 +538,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -480,6 +550,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = autonotch; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -487,6 +559,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -497,6 +571,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = speechcompressor; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -504,6 +580,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -514,6 +592,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = vox; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -521,6 +601,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -531,6 +613,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = manualnotch; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -538,6 +622,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -552,6 +638,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = satmode; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -563,6 +651,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[5] = 0x94; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x1a: // miscellaneous things @@ -574,6 +665,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x02: // filter width @@ -584,6 +678,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = filter_width; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -592,6 +688,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -604,6 +702,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = agc_time; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -612,6 +712,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -622,6 +724,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = datamodeA; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -629,6 +733,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -646,6 +752,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = ptt; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -653,6 +761,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -667,6 +777,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfa; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x26: @@ -674,6 +787,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfa; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; default: printf("cmd 0x%02x unknown\n", frame[4]); diff --git a/simulators/simic7300.c b/simulators/simic7300.c index 978f72a8f..c74ea71fb 100644 --- a/simulators/simic7300.c +++ b/simulators/simic7300.c @@ -6,10 +6,12 @@ // gcc -static -I../include -g -Wall -o simicom simicom.c -L../../build/src/.libs -lhamlib -lwsock32 -lws2_32 #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq { int dummy; }; +#endif #include #include @@ -51,7 +53,7 @@ int ovf_status = 0; int powerstat = 1; int keyertype = 0; -void dumphex(unsigned char *buf, int n) +void dumphex(const unsigned char *buf, int n) { for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } @@ -134,6 +136,8 @@ void frameParse(int fd, unsigned char *frame, int len) if (powerstat) { n = write(fd, frame, 11); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -154,6 +158,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x05: @@ -166,6 +173,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x06: @@ -175,6 +185,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x07: @@ -195,6 +208,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x0f: @@ -204,6 +220,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[5] = split; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -212,6 +230,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -235,6 +255,9 @@ void frameParse(int fd, unsigned char *frame, int len) printf("write 8 bytes\n"); dump_hex(frame, 8); n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x14: @@ -251,6 +274,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = 0xfb; dumphex(frame, 7); n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + printf("ACK x14 x08\n"); } else @@ -259,6 +285,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[8] = 0xfb; dumphex(frame, 9); n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + printf("SEND x14 x08\n"); } @@ -273,6 +302,9 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)power_level, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x0c: @@ -285,6 +317,8 @@ void frameParse(int fd, unsigned char *frame, int len) keyspd = from_bcd(&frame[6], 2); frame[6] = 0xfb; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -292,6 +326,8 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], keyspd, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -309,12 +345,18 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 00; frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x07: frame[6] = ovf_status; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + ovf_status = ovf_status == 0 ? 1 : 0; break; @@ -327,6 +369,9 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)meter_level, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -343,6 +388,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = satmode; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -354,12 +401,18 @@ void frameParse(int fd, unsigned char *frame, int len) frame[5] = 1; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x19: // miscellaneous things frame[5] = 0x94; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x1a: // miscellaneous things @@ -371,6 +424,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = band; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -379,6 +434,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfe; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -389,6 +446,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x04: // AGC TIME @@ -399,6 +459,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = agc_time; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -407,6 +469,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -428,6 +492,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else // we're reading it { @@ -439,6 +505,8 @@ void frameParse(int fd, unsigned char *frame, int len) } n = write(fd, frame, 10); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; } @@ -452,6 +520,8 @@ case 0x1c: frame[6] = ptt; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -459,6 +529,8 @@ case 0x1c: frame[7] = 0xfb; frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -500,8 +572,15 @@ case 0x25: frame2[9] = 0x00; frame2[10] = 0xfd; n = write(fd, frame2, 11); -#endif + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + +#else n = write(fd, frame, 12); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + +#endif } else { @@ -514,6 +593,9 @@ case 0x25: frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + #if 0 // send async frame frame[2] = 0x00; // async freq @@ -526,6 +608,9 @@ case 0x25: frame[9] = 0x12; frame[10] = 0xfd; n = write(fd, frame, 11); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + #endif } @@ -542,6 +627,8 @@ case 0x26: frame[7] = frame[5] == 0 ? datamodeA : datamodeB; frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -561,6 +648,8 @@ case 0x26: frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } printf("\n"); @@ -572,6 +661,9 @@ case 0x25: frame[4] = 0xfa; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x26: @@ -579,6 +671,9 @@ case 0x26: frame[4] = 0xfa; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; #endif diff --git a/simulators/simic7600.c b/simulators/simic7600.c index da69aef26..2089e7085 100644 --- a/simulators/simic7600.c +++ b/simulators/simic7600.c @@ -6,10 +6,12 @@ // gcc -static -I../include -g -Wall -o simicom simicom.c -L../../build/src/.libs -lhamlib -lwsock32 -lws2_32 #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq { int dummy; }; +#endif #include #include @@ -49,7 +51,7 @@ int ovf_status = 0; int powerstat = 1; int datamode = 0; -void dumphex(unsigned char *buf, int n) +void dumphex(const unsigned char *buf, int n) { for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } @@ -132,6 +134,8 @@ void frameParse(int fd, unsigned char *frame, int len) if (powerstat) { n = write(fd, frame, 11); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -152,6 +156,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x05: @@ -164,6 +171,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x06: @@ -173,6 +183,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x07: @@ -193,6 +206,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x0f: @@ -205,6 +221,8 @@ void frameParse(int fd, unsigned char *frame, int len) printf("get split %d\n", 1); frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -212,6 +230,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -235,6 +255,9 @@ void frameParse(int fd, unsigned char *frame, int len) printf("write 8 bytes\n"); dump_hex(frame, 8); n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x14: @@ -249,6 +272,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = 0xfb; dumphex(frame, 7); n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + printf("ACK x14 x08\n"); } else @@ -257,6 +283,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[8] = 0xfb; dumphex(frame, 9); n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + printf("SEND x14 x08\n"); } @@ -271,6 +300,9 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)power_level, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -285,6 +317,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = ovf_status; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + ovf_status = ovf_status == 0 ? 1 : 0; break; @@ -297,6 +332,9 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)meter_level, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -313,6 +351,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = satmode; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -324,12 +364,18 @@ void frameParse(int fd, unsigned char *frame, int len) frame[5] = 1; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x19: // miscellaneous things frame[5] = 0x94; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x1a: // miscellaneous things @@ -341,6 +387,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x04: // AGC TIME @@ -351,6 +400,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = agc_time; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -359,6 +410,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -369,6 +422,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = datamode; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -376,6 +431,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfd; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -384,6 +441,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -399,6 +459,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = ptt; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -406,6 +468,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfb; frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -447,8 +511,15 @@ void frameParse(int fd, unsigned char *frame, int len) frame2[9] = 0x00; frame2[10] = 0xfd; n = write(fd, frame2, 11); -#endif + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + +#else n = write(fd, frame, 12); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + +#endif } else { @@ -461,6 +532,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + // send async frame frame[2] = 0x00; // async freq frame[3] = 0xa2; @@ -472,6 +546,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[9] = 0x12; frame[10] = 0xfd; n = write(fd, frame, 11); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -488,6 +564,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[8] = 0xfb; frame[9] = 0xfd; n = write(fd, frame, 10); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -507,6 +585,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } printf("\n"); @@ -518,6 +598,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfa; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x26: @@ -525,6 +608,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfa; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; #endif diff --git a/simulators/simic7610.c b/simulators/simic7610.c index 253306a51..d8dd118e0 100644 --- a/simulators/simic7610.c +++ b/simulators/simic7610.c @@ -5,10 +5,12 @@ // gcc -static -I../include -g -Wall -o simicom simicom.c -L../../build/src/.libs -lhamlib -lwsock32 -lws2_32 #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq { int dummy; }; +#endif #include #include @@ -49,7 +51,7 @@ int powerstat = 1; int datamode = 0; int keyspd = 130; // 130=20WPM -void dumphex(unsigned char *buf, int n) +void dumphex(const unsigned char *buf, int n) { for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } @@ -132,6 +134,8 @@ void frameParse(int fd, unsigned char *frame, int len) if (powerstat) { n = write(fd, frame, 11); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -152,6 +156,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x05: @@ -164,6 +171,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x06: @@ -173,6 +183,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x07: @@ -193,6 +206,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x0f: @@ -205,6 +221,8 @@ void frameParse(int fd, unsigned char *frame, int len) printf("get split %d\n", 1); frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -212,6 +230,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -235,6 +255,9 @@ void frameParse(int fd, unsigned char *frame, int len) printf("write 8 bytes\n"); dump_hex(frame, 8); n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x14: @@ -251,6 +274,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = 0xfb; dumphex(frame, 7); n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + printf("ACK x14 x08\n"); } else @@ -259,6 +285,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[8] = 0xfb; dumphex(frame, 9); n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + printf("SEND x14 x08\n"); } @@ -273,6 +302,9 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)power_level, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x0c: @@ -285,6 +317,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = keyspd; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -294,6 +328,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[5] = 0xfa; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -308,6 +345,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = ovf_status; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + ovf_status = ovf_status == 0 ? 1 : 0; break; @@ -320,12 +360,18 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)meter_level, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; default: frame[5] = 0xfa; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -343,6 +389,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = satmode; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -354,12 +402,18 @@ void frameParse(int fd, unsigned char *frame, int len) frame[5] = 1; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x19: // miscellaneous things frame[5] = 0x94; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x1a: // miscellaneous things @@ -371,6 +425,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x04: // AGC TIME @@ -381,6 +438,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = agc_time; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -389,6 +448,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -399,6 +460,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = datamode; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -406,6 +469,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfd; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -414,6 +479,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -429,6 +497,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = ptt; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -436,6 +506,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfb; frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -477,8 +549,16 @@ void frameParse(int fd, unsigned char *frame, int len) frame2[9] = 0x00; frame2[10] = 0xfd; n = write(fd, frame2, 11); -#endif + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + +#else n = write(fd, frame, 12); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + +#endif + } else { @@ -491,6 +571,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + // send async frame frame[2] = 0x00; // async freq frame[3] = 0xa2; @@ -502,6 +585,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[9] = 0x12; frame[10] = 0xfd; n = write(fd, frame, 11); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -518,6 +603,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[8] = 0xfb; frame[9] = 0xfd; n = write(fd, frame, 10); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -537,6 +624,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } printf("\n"); @@ -548,6 +637,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfa; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x26: @@ -555,6 +647,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfa; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; #endif diff --git a/simulators/simic7851.c b/simulators/simic7851.c index 14509c7a1..0986741fe 100644 --- a/simulators/simic7851.c +++ b/simulators/simic7851.c @@ -5,10 +5,12 @@ // gcc -static -I../include -g -Wall -o simicom simicom.c -L../../build/src/.libs -lhamlib -lwsock32 -lws2_32 #define _XOPEN_SOURCE 700 // since we are POSIX here we need this +#if 0 struct ip_mreq { int dummy; }; +#endif #include #include @@ -55,7 +57,7 @@ int notch = 0; int speechcompressor = 0; int vox = 0; -void dumphex(unsigned char *buf, int n) +void dumphex(const unsigned char *buf, int n) { for (int i = 0; i < n; ++i) { printf("%02x ", buf[i]); } @@ -120,9 +122,12 @@ void frameParse(int fd, unsigned char *frame, int len) int echo = 0; +// cppcheck-suppress knownConditionTrueFalse if (echo) { n = write(fd, frame, len); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } frame[3] = frame[2]; @@ -149,6 +154,8 @@ void frameParse(int fd, unsigned char *frame, int len) if (powerstat) { n = write(fd, frame, 11); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -169,10 +176,14 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x05: freq = from_bcd(&frame[5], (civ_731_mode ? 4 : 5) * 2); + //printf("set_freq to %.0f\n", freq); if (current_vfo == RIG_VFO_A || current_vfo == RIG_VFO_MAIN) { freqA = freq; } @@ -181,6 +192,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x06: @@ -190,6 +204,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x07: @@ -199,6 +216,7 @@ void frameParse(int fd, unsigned char *frame, int len) switch (frame[5]) { case 0xd2: + //printf("******* [6] = 0x07\n"); switch (frame[6]) @@ -216,6 +234,9 @@ void frameParse(int fd, unsigned char *frame, int len) //printf("0x07 0xd2 answer: \n"); dump_hex(frame, 6); n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x0f: @@ -228,6 +249,8 @@ void frameParse(int fd, unsigned char *frame, int len) //printf("get split %d\n", 1); frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -235,6 +258,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -246,12 +271,16 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { frame[5] = attenuator; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -275,9 +304,13 @@ void frameParse(int fd, unsigned char *frame, int len) //printf("write 8 bytes\n"); dump_hex(frame, 8); n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x14: + //printf("******** 0x14 received frame[5]=0x%02x\n", frame[5]); switch (frame[5]) @@ -293,6 +326,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[5] = 0xfd; dumphex(frame, 6); n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + //printf("ACK x14 x08\n"); } else @@ -303,6 +339,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[9] = 0xfd; dumphex(frame, 10); n = write(fd, frame, 10); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + //printf("SEND x14 x08\n"); } @@ -317,6 +356,9 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)power_level, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x0c: @@ -329,6 +371,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = keyspd; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -338,6 +382,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[5] = 0xfa; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -352,6 +399,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = ovf_status; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + ovf_status = ovf_status == 0 ? 1 : 0; break; @@ -364,12 +414,18 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)meter_level, 2); frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; default: frame[5] = 0xfa; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -383,6 +439,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = speechcompressor; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -390,14 +448,20 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } + break; + case 0x46: if (frame[6] == 0xfe) { frame[6] = vox; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -405,14 +469,20 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } + break; + case 0x48: if (frame[6] == 0xfe) { frame[6] = notch; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -420,8 +490,12 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } + break; + case 0x5a: if (frame[6] == 0xfe) { @@ -432,6 +506,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = satmode; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -443,12 +519,18 @@ void frameParse(int fd, unsigned char *frame, int len) frame[5] = 1; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x19: // miscellaneous things frame[5] = 0x94; frame[6] = 0xfd; n = write(fd, frame, 7); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x1a: // miscellaneous things @@ -460,9 +542,13 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x04: // AGC TIME + //printf("frame[6]==x%02x, frame[7]=0%02x\n", frame[6], frame[7]); if (frame[6] == 0xfd) // the we are reading @@ -470,6 +556,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = agc_time; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -478,6 +566,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -488,6 +578,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = datamode; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -495,6 +587,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfd; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -503,6 +597,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; } @@ -518,6 +615,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = ptt; frame[7] = 0xfd; n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { @@ -525,6 +624,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = 0xfb; frame[8] = 0xfd; n = write(fd, frame, 9); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -566,12 +667,20 @@ void frameParse(int fd, unsigned char *frame, int len) frame2[9] = 0x00; frame2[10] = 0xfd; n = write(fd, frame2, 11); -#endif + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + +#else n = write(fd, frame, 12); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + +#endif } else { freq = from_bcd(&frame[6], (civ_731_mode ? 4 : 5) * 2); + //printf("set_freq to %.0f\n", freq); if (frame[5] == 0x00) { freqA = freq; } @@ -580,6 +689,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + // send async frame frame[2] = 0x00; // async freq frame[3] = 0xa2; @@ -591,6 +703,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[9] = 0x12; frame[10] = 0xfd; n = write(fd, frame, 11); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; @@ -600,7 +714,7 @@ void frameParse(int fd, unsigned char *frame, int len) if (frame[6] == 0xfd) // then a query { - printf("GET MODE XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); + printf("GET MODE XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); // fe fe e0 8e 26 00 01 00 01 fd // 0 1 2 3 4 5 6 7 8 // AB MD DM FF @@ -611,10 +725,13 @@ void frameParse(int fd, unsigned char *frame, int len) printf("x26 response: "); dumphex(frame, 10); n = write(fd, frame, 10); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } else { - printf("SET MODE YYYYYYYYYYYYYYYYYYYYYYYYYYYYY\n"); + printf("SET MODE YYYYYYYYYYYYYYYYYYYYYYYYYYYYY\n"); + for (int i = 0; i < 12; ++i) { printf("%02x:", frame[i]); } if (frame[5] == 0) @@ -633,6 +750,8 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } printf("\n"); @@ -644,6 +763,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfa; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; case 0x26: @@ -651,6 +773,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfa; frame[5] = 0xfd; n = write(fd, frame, 6); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + break; #endif diff --git a/simulators/simic905.c b/simulators/simic905.c index 4f6476a2d..1c41e7a79 100644 --- a/simulators/simic905.c +++ b/simulators/simic905.c @@ -53,10 +53,22 @@ int keyspd = 25; int datamode = 0; int filter = 0; -int WRITE(int fd, unsigned char* buf, int buflen) +#define write(f,b,l) write_sim(f,b,l,__func__,__LINE__) + +int write_sim(int fd, const unsigned char *buf, int buflen, const char *func, + int linenum) { - dump_hex(buf,buflen); - return write(fd,buf,buflen); + int n; + dump_hex(buf, buflen); + n = write(fd, buf, buflen); + + if (n <= 0) + { + fprintf(stderr, "%s(%d) write error %d: %s\n", func, linenum, n, + strerror(errno)); + } + + return n; } void dumphex(unsigned char *buf, int n) @@ -127,24 +139,27 @@ void frameParse(int fd, unsigned char *frame, int len) //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) { - if (freqA > 5.85e9) freq_len = 6; + if (freqA > 5.85e9) { freq_len = 6; } + printf("get_freqA len=%d\n", freq_len); to_bcd(&frame[5], (long long)freqA, freq_len * 2); } else { - if (freqB > 5.85e9) freq_len = 6; + if (freqB > 5.85e9) { freq_len = 6; } + printf("get_freqB len=%d\n", freq_len); to_bcd(&frame[5], (long long)freqB, freq_len * 2); } - frame[5+freq_len] = 0xfd; + frame[5 + freq_len] = 0xfd; if (powerstat) { - n = WRITE(fd, frame, 11); + write(fd, frame, 11); } break; @@ -164,7 +179,7 @@ void frameParse(int fd, unsigned char *frame, int len) } frame[7] = 0xfd; - n = WRITE(fd, frame, 8); + write(fd, frame, 8); break; case 0x05: @@ -176,7 +191,7 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); break; case 0x06: @@ -185,7 +200,7 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); break; case 0x07: @@ -196,16 +211,16 @@ void frameParse(int fd, unsigned char *frame, int len) case 0x01: current_vfo = RIG_VFO_B; break; - case 0xa0: freqB = freqA;modeB = modeA; break; + case 0xa0: freqB = freqA; modeB = modeA; break; - case 0xb0: current_vfo = RIG_VFO_SUB; exit(1);break; + case 0xb0: current_vfo = RIG_VFO_SUB; exit(1); break; } printf("set_vfo to %s\n", rig_strvfo(current_vfo)); frame[4] = 0xfb; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); break; case 0x0f: @@ -214,7 +229,7 @@ void frameParse(int fd, unsigned char *frame, int len) printf("get split %d\n", split); frame[5] = split; frame[6] = 0xfd; - n = WRITE(fd, frame, 7); + write(fd, frame, 7); } else { @@ -222,7 +237,7 @@ void frameParse(int fd, unsigned char *frame, int len) split = frame[5]; frame[4] = 0xfb; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); } break; @@ -243,9 +258,9 @@ void frameParse(int fd, unsigned char *frame, int len) frame[5] = ant_curr; frame[6] = ant_option; frame[7] = 0xfd; - printf("WRITE 8 bytes\n"); + printf("write 8 bytes\n"); dump_hex(frame, 8); - n = WRITE(fd, frame, 8); + write(fd, frame, 8); break; case 0x14: @@ -259,7 +274,7 @@ void frameParse(int fd, unsigned char *frame, int len) { frame[6] = 0xfb; dumphex(frame, 7); - n = WRITE(fd, frame, 7); + write(fd, frame, 7); printf("ACK x14 x08\n"); } else @@ -267,7 +282,7 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)128, 2); frame[8] = 0xfb; dumphex(frame, 9); - n = WRITE(fd, frame, 9); + write(fd, frame, 9); printf("SEND x14 x08\n"); } @@ -281,7 +296,7 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)power_level, 2); frame[8] = 0xfd; - n = WRITE(fd, frame, 9); + write(fd, frame, 9); break; case 0x0c: @@ -293,14 +308,14 @@ void frameParse(int fd, unsigned char *frame, int len) printf("subcmd=0x0c #1\n"); keyspd = from_bcd(&frame[6], 2); frame[6] = 0xfb; - n = WRITE(fd, frame, 7); + write(fd, frame, 7); } else { printf("subcmd=0x0c #1\n"); to_bcd(&frame[6], keyspd, 2); frame[8] = 0xfd; - n = WRITE(fd, frame, 9); + write(fd, frame, 9); } break; @@ -317,7 +332,7 @@ void frameParse(int fd, unsigned char *frame, int len) case 0x07: frame[6] = ovf_status; frame[7] = 0xfd; - n = WRITE(fd, frame, 8); + write(fd, frame, 8); ovf_status = ovf_status == 0 ? 1 : 0; break; @@ -329,7 +344,7 @@ void frameParse(int fd, unsigned char *frame, int len) to_bcd(&frame[6], (long long)meter_level, 2); frame[8] = 0xfd; - n = WRITE(fd, frame, 9); + write(fd, frame, 9); break; } @@ -345,7 +360,7 @@ void frameParse(int fd, unsigned char *frame, int len) { frame[6] = satmode; frame[7] = 0xfd; - n = WRITE(fd, frame, 8); + write(fd, frame, 8); } break; @@ -356,13 +371,13 @@ void frameParse(int fd, unsigned char *frame, int len) case 0x18: // miscellaneous things frame[5] = 1; frame[6] = 0xfd; - n = WRITE(fd, frame, 7); + write(fd, frame, 7); break; case 0x19: // miscellaneous things frame[5] = 0x94; frame[6] = 0xfd; - n = WRITE(fd, frame, 7); + write(fd, frame, 7); break; case 0x1a: // miscellaneous things @@ -373,7 +388,7 @@ void frameParse(int fd, unsigned char *frame, int len) else { frame[6] = widthB; } frame[7] = 0xfd; - n = WRITE(fd, frame, 8); + write(fd, frame, 8); break; case 0x04: // AGC TIME @@ -383,7 +398,7 @@ void frameParse(int fd, unsigned char *frame, int len) { frame[6] = agc_time; frame[7] = 0xfd; - n = WRITE(fd, frame, 8); + write(fd, frame, 8); } else { @@ -391,17 +406,18 @@ void frameParse(int fd, unsigned char *frame, int len) agc_time = frame[6]; frame[4] = 0xfb; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); } break; + case 0x06: // datamode if (frame[5] == 0xfd) { frame[6] = datamode; frame[7] = filter; frame[8] = 0xfd; - n = WRITE(fd, frame, 9); + write(fd, frame, 9); } else { @@ -409,13 +425,13 @@ void frameParse(int fd, unsigned char *frame, int len) filter = frame[7]; frame[4] = 0xfb; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); } case 0x07: // satmode frame[4] = 0; frame[7] = 0xfd; - n = WRITE(fd, frame, 8); + write(fd, frame, 8); break; } @@ -433,7 +449,7 @@ void frameParse(int fd, unsigned char *frame, int len) frame[3] = tmp; frame[6] = ptt; frame[7] = 0xfd; - n = WRITE(fd, frame, 8); + write(fd, frame, 8); } else { @@ -443,7 +459,7 @@ void frameParse(int fd, unsigned char *frame, int len) frame[3] = tmp; frame[4] = 0xfb; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); } break; @@ -458,22 +474,25 @@ void frameParse(int fd, unsigned char *frame, int len) case 0x25: if (frame[6] == 0xfd) { - int freq_len = 5; + freq_len = 5; + if (frame[5] == 0x00) { - if (freqA > 5.85e9) freq_len = 6; + if (freqA > 5.85e9) { freq_len = 6; } + to_bcd(&frame[6], (long long)freqA, freq_len * 2); printf("X25 get_freqA=%.0f\n", freqA); - frame[6+freq_len] = 0xfd; - n = WRITE(fd, frame, 7+freq_len); + frame[6 + freq_len] = 0xfd; + write(fd, frame, 7 + freq_len); } else { - if (freqB > 5.85e9) freq_len = 6; + if (freqB > 5.85e9) { freq_len = 6; } + to_bcd(&frame[6], (long long)freqB, freq_len * 2); printf("X25 get_freqB=%.0f\n", freqB); - frame[6+freq_len] = 0xfd; - n = WRITE(fd, frame, 7+freq_len); + frame[6 + freq_len] = 0xfd; + write(fd, frame, 7 + freq_len); } //unsigned char frame2[12]; @@ -491,13 +510,15 @@ void frameParse(int fd, unsigned char *frame, int len) frame2[9] = 0x00; frame2[10] = 0x00; frame2[11] = 0xfd; - n = WRITE(fd, frame2, 12); + write(fd, frame2, 12); #endif } else { - int freq_len = 5; - if (frame[11] != 0xfd) freq_len = 6; + freq_len = 5; + + if (frame[11] != 0xfd) { freq_len = 6; } + freq = from_bcd(&frame[6], freq_len * 2); printf("set_freq to %.0f\n", freq); @@ -509,7 +530,7 @@ void frameParse(int fd, unsigned char *frame, int len) frame[3] = tmp; frame[4] = 0xfb; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); #if 0 // send async frame frame[2] = 0x00; // async freq @@ -521,7 +542,7 @@ void frameParse(int fd, unsigned char *frame, int len) frame[8] = 0x96; frame[9] = 0x12; frame[10] = 0xfd; - n = WRITE(fd, frame, 11); + write(fd, frame, 11); #endif } @@ -538,7 +559,7 @@ void frameParse(int fd, unsigned char *frame, int len) frame[7] = frame[5] == 0 ? datamodeA : datamodeB; frame[8] = frame[5] == 0 ? filterA : filterB; frame[9] = 0xfd; - n = WRITE(fd, frame, 10); + write(fd, frame, 10); } else { @@ -557,7 +578,7 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfb; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); } printf("\n"); @@ -568,14 +589,14 @@ void frameParse(int fd, unsigned char *frame, int len) printf("x25 send nak\n"); frame[4] = 0xfa; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); break; case 0x26: printf("x26 send nak\n"); frame[4] = 0xfa; frame[5] = 0xfd; - n = WRITE(fd, frame, 6); + write(fd, frame, 6); break; #endif diff --git a/simulators/simid5100.c b/simulators/simid5100.c index dcaf9d1a2..76171a569 100644 --- a/simulators/simid5100.c +++ b/simulators/simid5100.c @@ -7,9 +7,9 @@ #define _XOPEN_SOURCE 700 // since we are POSIX here we need this struct ip_mreq - { +{ int dummy; - }; +}; #include #include diff --git a/simulators/simjupiter.c b/simulators/simjupiter.c index f4db185ac..a37e8aea9 100644 --- a/simulators/simjupiter.c +++ b/simulators/simjupiter.c @@ -3,9 +3,9 @@ #define _XOPEN_SOURCE 700 // since we are POSIX here we need this struct ip_mreq - { +{ int dummy; - }; +}; #include #include diff --git a/simulators/simkenwood.c b/simulators/simkenwood.c index b141e0ec9..10ec81876 100644 --- a/simulators/simkenwood.c +++ b/simulators/simkenwood.c @@ -3,9 +3,9 @@ #define _XOPEN_SOURCE 700 // since we are POSIX here we need this struct ip_mreq - { +{ int dummy; - }; +}; #include #include diff --git a/simulators/simpowersdr.c b/simulators/simpowersdr.c index fb035ac09..4b0b38939 100644 --- a/simulators/simpowersdr.c +++ b/simulators/simpowersdr.c @@ -3,9 +3,9 @@ #define _XOPEN_SOURCE 700 // since we are POSIX here we need this struct ip_mreq - { +{ int dummy; - }; +}; #include #include @@ -454,12 +454,14 @@ int main(int argc, char *argv[]) else if (strncmp(buf, "ZZTX", 4) == 0) { printf("******** ZZTX[%c]\n", buf[4]); + switch (buf[4]) { case '1': ptt = 1; - break; + break; + case '0': ptt = 0; - break; + break; } continue; @@ -469,16 +471,17 @@ int main(int argc, char *argv[]) SNPRINTF(buf, sizeof(buf), "KS%03d;", keyspd); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"KS",2) == 0) + else if (strncmp(buf, "KS", 2) == 0) { - sscanf(buf,"KS%d", &keyspd); + sscanf(buf, "KS%d", &keyspd); } - else if (strncmp(buf,"ZZRM4",5)==0) + else if (strncmp(buf, "ZZRM4", 5) == 0) { SNPRINTF(buf, sizeof(buf), "ZZRM4%2.0f dB;", alc); n = write(fd, buf, strlen(buf)); alc += 1; - if (alc > 40) alc = -20; + + if (alc > 40) { alc = -20; } } else if (strlen(buf) > 0) { diff --git a/simulators/simqrplabs.c b/simulators/simqrplabs.c index 4c1c282ea..484813c58 100644 --- a/simulators/simqrplabs.c +++ b/simulators/simqrplabs.c @@ -314,19 +314,21 @@ int main(int argc, char *argv[]) SNPRINTF(buf, sizeof(buf), "SA0;"); n = write(fd, buf, strlen(buf)); } - else if (buf[3] == ';' && strncmp(buf, "SF", 2)==0) + else if (buf[3] == ';' && strncmp(buf, "SF", 2) == 0) { - SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], buf[2] == '0' ? freqA : freqB, + SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], + buf[2] == '0' ? freqA : freqB, buf[2] == '0' ? modeA + '0' : modeB + '0'); n = write(fd, buf, strlen(buf)); continue; } else if (strncmp(buf, "SF", 2) == 0) { - mode_t tmpmode= buf[14]; + mode_t tmpmode = buf[14]; if (buf[2] == '0') { modeA = tmpmode - '0'; } else { modeB = tmpmode - '0'; } + printf("modeA=%c, modeB=%c\n", modeA, modeB); continue; diff --git a/simulators/simrotorez.c b/simulators/simrotorez.c index 5d4f57cab..1b3b62977 100644 --- a/simulators/simrotorez.c +++ b/simulators/simrotorez.c @@ -3,9 +3,9 @@ #define _XOPEN_SOURCE 700 // since we are POSIX here we need this struct ip_mreq - { +{ int dummy; - }; +}; #include #include diff --git a/simulators/simspid.c b/simulators/simspid.c index 7a6baec2f..9166c50a8 100644 --- a/simulators/simspid.c +++ b/simulators/simspid.c @@ -3,9 +3,9 @@ #define _XOPEN_SOURCE 700 // since we are POSIX here we need this struct ip_mreq - { +{ int dummy; - }; +}; #include #include diff --git a/simulators/simtmd700.c b/simulators/simtmd700.c index dcba5cbcf..bd972fbbc 100644 --- a/simulators/simtmd700.c +++ b/simulators/simtmd700.c @@ -3,9 +3,9 @@ #define _XOPEN_SOURCE 700 // since we are POSIX here we need this struct ip_mreq - { +{ int dummy; - }; +}; #include #include diff --git a/simulators/simts450.c b/simulators/simts450.c index a7902f051..a37bba089 100644 --- a/simulators/simts450.c +++ b/simulators/simts450.c @@ -313,19 +313,21 @@ int main(int argc, char *argv[]) SNPRINTF(buf, sizeof(buf), "SA0;"); n = write(fd, buf, strlen(buf)); } - else if (buf[3] == ';' && strncmp(buf, "SF", 2)==0) + else if (buf[3] == ';' && strncmp(buf, "SF", 2) == 0) { - SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], buf[2] == '0' ? freqA : freqB, + SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], + buf[2] == '0' ? freqA : freqB, buf[2] == '0' ? modeA + '0' : modeB + '0'); n = write(fd, buf, strlen(buf)); continue; } else if (strncmp(buf, "SF", 2) == 0) { - mode_t tmpmode= buf[14]; + mode_t tmpmode = buf[14]; if (buf[2] == '0') { modeA = tmpmode - '0'; } else { modeB = tmpmode - '0'; } + printf("modeA=%c, modeB=%c\n", modeA, modeB); continue; diff --git a/simulators/simts590.c b/simulators/simts590.c index 4b083a2a4..011f264f3 100644 --- a/simulators/simts590.c +++ b/simulators/simts590.c @@ -314,19 +314,21 @@ int main(int argc, char *argv[]) SNPRINTF(buf, sizeof(buf), "SA0;"); n = write(fd, buf, strlen(buf)); } - else if (buf[3] == ';' && strncmp(buf, "SF", 2)==0) + else if (buf[3] == ';' && strncmp(buf, "SF", 2) == 0) { - SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], buf[2] == '0' ? freqA : freqB, + SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], + buf[2] == '0' ? freqA : freqB, buf[2] == '0' ? modeA + '0' : modeB + '0'); n = write(fd, buf, strlen(buf)); continue; } else if (strncmp(buf, "SF", 2) == 0) { - mode_t tmpmode= buf[14]; + mode_t tmpmode = buf[14]; if (buf[2] == '0') { modeA = tmpmode - '0'; } else { modeB = tmpmode - '0'; } + printf("modeA=%c, modeB=%c\n", modeA, modeB); continue; diff --git a/simulators/simts950.c b/simulators/simts950.c index 54847ea02..9ad331861 100644 --- a/simulators/simts950.c +++ b/simulators/simts950.c @@ -315,19 +315,21 @@ int main(int argc, char *argv[]) SNPRINTF(buf, sizeof(buf), "SA0;"); n = write(fd, buf, strlen(buf)); } - else if (buf[3] == ';' && strncmp(buf, "SF", 2)==0) + else if (buf[3] == ';' && strncmp(buf, "SF", 2) == 0) { - SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], buf[2] == '0' ? freqA : freqB, + SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], + buf[2] == '0' ? freqA : freqB, buf[2] == '0' ? modeA + '0' : modeB + '0'); n = write(fd, buf, strlen(buf)); continue; } else if (strncmp(buf, "SF", 2) == 0) { - mode_t tmpmode= buf[14]; + mode_t tmpmode = buf[14]; if (buf[2] == '0') { modeA = tmpmode - '0'; } else { modeB = tmpmode - '0'; } + printf("modeA=%c, modeB=%c\n", modeA, modeB); continue; diff --git a/simulators/simts990.c b/simulators/simts990.c old mode 100755 new mode 100644 index d9e51a183..7149ae3ec --- a/simulators/simts990.c +++ b/simulators/simts990.c @@ -320,19 +320,21 @@ int main(int argc, char *argv[]) SNPRINTF(buf, sizeof(buf), "SA0;"); n = write(fd, buf, strlen(buf)); } - else if (buf[3] == ';' && strncmp(buf, "SF", 2)==0) + else if (buf[3] == ';' && strncmp(buf, "SF", 2) == 0) { - SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], buf[2] == '0' ? freqA : freqB, + SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], + buf[2] == '0' ? freqA : freqB, buf[2] == '0' ? modeA + '0' : modeB + '0'); n = write(fd, buf, strlen(buf)); continue; } else if (strncmp(buf, "SF", 2) == 0) { - mode_t tmpmode= buf[14]; + mode_t tmpmode = buf[14]; if (buf[2] == '0') { modeA = tmpmode - '0'; } else { modeB = tmpmode - '0'; } + printf("modeA=%c, modeB=%c\n", modeA, modeB); continue; @@ -420,48 +422,48 @@ int main(int argc, char *argv[]) } else if (strncmp(buf, "CB;", 3) == 0) { - sprintf(buf,"CB%d;", operatingband); + sprintf(buf, "CB%d;", operatingband); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"CB",2) == 0) + else if (strncmp(buf, "CB", 2) == 0) { - sscanf(buf,"CB%d", &operatingband); + sscanf(buf, "CB%d", &operatingband); } else if (strncmp(buf, "TB;", 3) == 0) { - sprintf(buf,"TB%d;", split); + sprintf(buf, "TB%d;", split); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"TB",2) == 0) + else if (strncmp(buf, "TB", 2) == 0) { - sscanf(buf,"TB%d", &split); + sscanf(buf, "TB%d", &split); } else if (strncmp(buf, "KS;", 3) == 0) { - sprintf(buf,"KS%d;", keyspd); + sprintf(buf, "KS%d;", keyspd); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"KS",2) == 0) + else if (strncmp(buf, "KS", 2) == 0) { - sscanf(buf,"KS%03d", &keyspd); + sscanf(buf, "KS%03d", &keyspd); } else if (strncmp(buf, "OM0;", 4) == 0) { - sprintf(buf,"OM0%d;", modeMain); + sprintf(buf, "OM0%d;", modeMain); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"OM0",3) == 0) + else if (strncmp(buf, "OM0", 3) == 0) { - sscanf(buf,"OM0%d", &modeMain); + sscanf(buf, "OM0%d", &modeMain); } else if (strncmp(buf, "OM1;", 4) == 0) { - sprintf(buf,"OM1%d;", modeSub); + sprintf(buf, "OM1%d;", modeSub); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf,"OM1",3) == 0) + else if (strncmp(buf, "OM1", 3) == 0) { - sscanf(buf,"OM1%d", &modeSub); + sscanf(buf, "OM1%d", &modeSub); } else if (strlen(buf) > 0) { diff --git a/simulators/simxiegug90.c b/simulators/simxiegug90.c index 9d8a807f4..d20dd81ed 100644 --- a/simulators/simxiegug90.c +++ b/simulators/simxiegug90.c @@ -155,7 +155,7 @@ void frameParse(int fd, unsigned char *frame, int len) case 0x00: current_vfo = RIG_VFO_A; break; case 0x01: current_vfo = RIG_VFO_B; break; - + case 0xb0: freq = freqA; freqA = freqB; freqB = freq; break; } @@ -178,6 +178,7 @@ void frameParse(int fd, unsigned char *frame, int len) break; #if 0 + case 0x12: // we're simulating the 3-byte version -- not the 2-byte if (frame[5] != 0xfd) { @@ -270,6 +271,7 @@ void frameParse(int fd, unsigned char *frame, int len) break; #if 0 + case 0x18: // miscellaneous things frame[5] = 1; frame[6] = 0xfd; @@ -290,6 +292,7 @@ void frameParse(int fd, unsigned char *frame, int len) } break; + case 0x1c: switch (frame[5]) { diff --git a/simulators/simyaesu.c b/simulators/simyaesu.c index eb72b06bc..9bcb795b8 100644 --- a/simulators/simyaesu.c +++ b/simulators/simyaesu.c @@ -3,9 +3,9 @@ #define _XOPEN_SOURCE 700 // since we are POSIX here we need this struct ip_mreq - { +{ int dummy; - }; +}; #include #include