kopia lustrzana https://github.com/Hamlib/Hamlib
Replace raw write() calls with macro
So they can be aggregated for multiple commands in one messagepull/1614/head
rodzic
c37fb872cd
commit
c4f7cf35f9
|
@ -20,6 +20,12 @@ struct ip_mreq
|
|||
|
||||
#define BUFSIZE 256
|
||||
|
||||
/* Define a macro for sending response back to the app
|
||||
* This will allow us to reroute output to a buffering routine
|
||||
* Needed to handle multiple commands in a single message
|
||||
*/
|
||||
#define OUTPUT(s) write(fd, s, strlen(s))
|
||||
|
||||
int mysleep = 20;
|
||||
|
||||
int filternum1 = 7;
|
||||
|
@ -177,7 +183,7 @@ int main(int argc, char *argv[])
|
|||
/* Clean up from last continue - pass along any errors found */
|
||||
if (cmd_err != 0)
|
||||
{
|
||||
write(fd, err_txt[cmd_err - 1], strlen(err_txt[cmd_err - 1]));
|
||||
OUTPUT(err_txt[cmd_err - 1]);
|
||||
cmd_err = 0;
|
||||
}
|
||||
|
||||
|
@ -195,19 +201,19 @@ int main(int argc, char *argv[])
|
|||
hl_usleep(mysleep * 1000);
|
||||
sprintf(ifbuf, IFformat, freqa,
|
||||
(ptt + ptt_mic + ptt_data + ptt_tune) > 0 ? 1 : 0, modeA);
|
||||
write(fd, ifbuf, strlen(ifbuf));
|
||||
OUTPUT(ifbuf);
|
||||
}
|
||||
#if 0
|
||||
else if (strncmp(buf, "RM2", 3) == 0)
|
||||
{
|
||||
pbuf = "RM20020;";
|
||||
write(fd, pbuf, strlen(pbuf));
|
||||
OUTPUT(pbuf);
|
||||
}
|
||||
else if (strcmp(buf, "RM5;") == 0)
|
||||
{
|
||||
hl_usleep(mysleep * 1000);
|
||||
pbuf = "RM5100000;";
|
||||
write(fd, pbuf, strlen(pbuf));
|
||||
OUTPUT(pbuf);
|
||||
}
|
||||
#endif
|
||||
else if (strncmp(buf, "AN", 2) == 0)
|
||||
|
@ -220,7 +226,8 @@ int main(int argc, char *argv[])
|
|||
buf[4] = driveout;
|
||||
buf[5] = antout;
|
||||
buf[6] = ';';
|
||||
write(fd, buf, 7);
|
||||
buf[7] = '\0';
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -234,7 +241,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
hl_usleep(mysleep * 20);
|
||||
sprintf(buf,"NB1%d;", nb1);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "NB1",3) == 0)
|
||||
{
|
||||
|
@ -245,7 +252,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
hl_usleep(mysleep * 20);
|
||||
sprintf(buf,"NB2%d;", nb2);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "NB2",3) == 0)
|
||||
{
|
||||
|
@ -256,7 +263,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
hl_usleep(mysleep * 200);
|
||||
sprintf(buf,"RA%d;", ra);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "RA", 2) == 0)
|
||||
{
|
||||
|
@ -266,30 +273,30 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
hl_usleep(mysleep * 000);
|
||||
pbuf = "RG255;";
|
||||
write(fd, pbuf, strlen(pbuf));
|
||||
OUTPUT(pbuf);
|
||||
}
|
||||
else if (strcmp(buf, "MG;") == 0)
|
||||
{
|
||||
hl_usleep(mysleep * 1000);
|
||||
pbuf = "MG050;";
|
||||
write(fd, pbuf, strlen(pbuf));
|
||||
OUTPUT(pbuf);
|
||||
}
|
||||
else if (strcmp(buf, "AG;") == 0)
|
||||
{
|
||||
hl_usleep(mysleep * 1000);
|
||||
pbuf = "AG100;";
|
||||
write(fd, pbuf, strlen(pbuf));
|
||||
OUTPUT(pbuf);
|
||||
}
|
||||
else if (strcmp(buf, "FV;") == 0)
|
||||
{
|
||||
hl_usleep(mysleep * 1000);
|
||||
pbuf = "FV1.04;";
|
||||
write(fd, pbuf, strlen(pbuf));
|
||||
OUTPUT(pbuf);
|
||||
}
|
||||
else if (strncmp(buf, "IS;", 3) == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "IS+0000;");
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "IS", 2) == 0)
|
||||
{
|
||||
|
@ -298,34 +305,36 @@ int main(int argc, char *argv[])
|
|||
else if (strncmp(buf, "SM;", 3) == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "SM0035;");
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "PC;", 3) == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "PC%03d;", pc);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "PC", 2) == 0)
|
||||
{
|
||||
sscanf(buf,"PC%d", &pc);
|
||||
}
|
||||
#if 0
|
||||
else if (strcmp(buf, "FW1;") == 0)
|
||||
{
|
||||
//usleep(mysleep * 1000);
|
||||
pbuf = "FW10;";
|
||||
write(fd, pbuf, strlen(pbuf));
|
||||
OUTPUT(pbuf);
|
||||
hl_usleep(20 * 1000);
|
||||
}
|
||||
else if (strncmp(buf, "FW", 2) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
else if (strcmp(buf, "ID;") == 0)
|
||||
{
|
||||
hl_usleep(mysleep * 1000);
|
||||
int id = 24;
|
||||
SNPRINTF(buf, sizeof(buf), "ID%03d;", id);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -342,7 +351,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "EX00011;") == 0)
|
||||
{
|
||||
pbuf = "EX00011 001;";
|
||||
write(fd, pbuf, strlen(pbuf));
|
||||
OUTPUT(pbuf);
|
||||
}
|
||||
else if (strncmp(buf, "EX", 2) == 0)
|
||||
{
|
||||
|
@ -351,12 +360,12 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "FA;") == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "FA%011d;", freqa);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strcmp(buf, "FB;") == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "FB%011d;", freqb);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "FA", 2) == 0)
|
||||
{
|
||||
|
@ -369,13 +378,13 @@ int main(int argc, char *argv[])
|
|||
else if (strncmp(buf, "AI;", 3) == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "AI0;");
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
|
||||
else if (strncmp(buf, "PS;", 3) == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "PS1;");
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (buf[3] == ';' && strncmp(buf, "SF", 2) == 0)
|
||||
{
|
||||
|
@ -383,8 +392,8 @@ int main(int argc, char *argv[])
|
|||
SNPRINTF(buf, sizeof(buf), SFformat, tmpvfo,
|
||||
tmpvfo == 0 ? freqa : freqb,
|
||||
tmpvfo == 0 ? modeA : modeB);
|
||||
printf("SF buf=%s\n", buf);
|
||||
write(fd, buf, strlen(buf));
|
||||
//printf("SF buf=%s\n", buf);
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "SF", 2) == 0)
|
||||
{
|
||||
|
@ -416,7 +425,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
SNPRINTF(buf, sizeof(buf), "MD%d;",
|
||||
modeA); // not worried about modeB yet for simulator
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "MD", 2) == 0)
|
||||
{
|
||||
|
@ -425,7 +434,7 @@ int main(int argc, char *argv[])
|
|||
else if (strncmp(buf, "FL;", 3) == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "FL%03d%03d;", filternum1, filternum2);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "FL", 2) == 0)
|
||||
{
|
||||
|
@ -434,7 +443,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "FR;") == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "FR%d;", vfo);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "FR", 2) == 0)
|
||||
{
|
||||
|
@ -443,7 +452,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "FT;") == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "FR%d;", vfo_tx);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "FT", 2) == 0)
|
||||
{
|
||||
|
@ -452,7 +461,7 @@ int main(int argc, char *argv[])
|
|||
else if (strncmp(buf, "DA;", 3) == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "DA%d;", datamode);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "DA", 2) == 0)
|
||||
{
|
||||
|
@ -491,7 +500,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
printf("No CB command!\n");
|
||||
sprintf(buf, "CB%d;", operatingband);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "CB", 2) == 0)
|
||||
{
|
||||
|
@ -501,7 +510,7 @@ int main(int argc, char *argv[])
|
|||
else if (strncmp(buf, "TB;", 3) == 0)
|
||||
{
|
||||
sprintf(buf, "TB%d;", split);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "TB", 2) == 0)
|
||||
{
|
||||
|
@ -510,7 +519,7 @@ int main(int argc, char *argv[])
|
|||
else if (strncmp(buf, "KS;", 3) == 0)
|
||||
{
|
||||
sprintf(buf, "KS%03d;", keyspd);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "KS", 2) == 0)
|
||||
{
|
||||
|
@ -519,7 +528,7 @@ int main(int argc, char *argv[])
|
|||
else if (strncmp(buf, "OM0;", 4) == 0)
|
||||
{
|
||||
sprintf(buf, "OM0%d;", modeMain);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "OM0", 3) == 0)
|
||||
{
|
||||
|
@ -528,7 +537,7 @@ int main(int argc, char *argv[])
|
|||
else if (strncmp(buf, "OM1;", 4) == 0)
|
||||
{
|
||||
sprintf(buf, "OM1%d;", modeSub);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "OM1", 3) == 0)
|
||||
{
|
||||
|
@ -550,7 +559,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
if (buf[0] != '\0')
|
||||
{
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -569,13 +578,13 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
sprintf(buf,"SL0%02d;", sl);
|
||||
printf("R: %s\n", buf);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strcmp(buf, "SH0;") == 0)
|
||||
{
|
||||
sprintf(buf,"SH0%03d;", sh);
|
||||
printf("R: %s\n", buf);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "SL0", 3) == 0)
|
||||
{
|
||||
|
@ -590,7 +599,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "NR;") == 0)
|
||||
{
|
||||
sprintf(buf,"NR%d;", nr);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "NR", 2) == 0)
|
||||
{
|
||||
|
@ -600,7 +609,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "PA;") == 0)
|
||||
{
|
||||
sprintf(buf,"PA%d;", pa);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "PA", 2) == 0)
|
||||
{
|
||||
|
@ -609,17 +618,17 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "SM;") == 0)
|
||||
{
|
||||
sprintf(buf,"SM%04d;", sm);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strcmp(buf, "PC;") == 0)
|
||||
{
|
||||
sprintf(buf,"PC%03d;", sm);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strcmp(buf, "NT;") == 0)
|
||||
{
|
||||
sprintf(buf,"NT%d;", nt);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "NT", 2) == 0)
|
||||
{
|
||||
|
@ -628,7 +637,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "AG;") == 0)
|
||||
{
|
||||
sprintf(buf,"AG%03d;", ag);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "AG", 2) == 0)
|
||||
{
|
||||
|
@ -637,7 +646,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "AC;") == 0)
|
||||
{
|
||||
sprintf(buf,"AC%03d;", ac);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "AC", 2) == 0)
|
||||
{
|
||||
|
@ -646,7 +655,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "SQ;") == 0)
|
||||
{
|
||||
sprintf(buf,"SQ%03d;", sq);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "SQ", 2) == 0)
|
||||
{
|
||||
|
@ -655,7 +664,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "RG;") == 0)
|
||||
{
|
||||
sprintf(buf,"RG%03d;", rg);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "RG", 2) == 0)
|
||||
{
|
||||
|
@ -664,7 +673,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "MG;") == 0)
|
||||
{
|
||||
sprintf(buf,"MG%03d;", mg);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "MG", 2) == 0)
|
||||
{
|
||||
|
@ -673,7 +682,7 @@ int main(int argc, char *argv[])
|
|||
else if (strncmp(buf, "RL1;", 3) == 0)
|
||||
{
|
||||
SNPRINTF(buf, sizeof(buf), "RL%02d;", rl);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "RL1", 2) == 0)
|
||||
{
|
||||
|
@ -683,7 +692,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(buf, "SP;") == 0)
|
||||
{
|
||||
sprintf(buf,"SP%d;", sp);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else if (strncmp(buf, "SP", 2) == 0)
|
||||
{
|
||||
|
@ -734,7 +743,7 @@ int main(int argc, char *argv[])
|
|||
t = time(NULL);
|
||||
localtm = localtime(&t);
|
||||
strftime(&buf[3], BUFSIZ - 3, "%y%m%d%H%M%S;", localtm);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -745,7 +754,8 @@ int main(int argc, char *argv[])
|
|||
case '1': // Setting status
|
||||
buf[3] = '1';
|
||||
buf[4] = ';';
|
||||
write(fd, buf, 5);
|
||||
buf[5] = '\0';
|
||||
OUTPUT(buf);
|
||||
break;
|
||||
case '2': // Local clock time zone
|
||||
case '3': // Auxiliary clock time zone
|
||||
|
@ -754,7 +764,7 @@ int main(int argc, char *argv[])
|
|||
if (buf[3] == ';')
|
||||
{
|
||||
sprintf(&buf[3], "%03d;", tzs[idx]);
|
||||
write(fd, buf, strlen(buf));
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -767,7 +777,8 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
buf[3] = auxtzc;
|
||||
buf[4] = ';';
|
||||
write(fd, buf, 5);
|
||||
buf[5] = '\0';
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -782,7 +793,8 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
buf[3] = autoset + '0';
|
||||
buf[4] = ';';
|
||||
write(fd, buf, 5);
|
||||
buf[5] = '\0';
|
||||
OUTPUT(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Ładowanie…
Reference in New Issue