From 976cd61d2e9dddc3a038ef7abf599a29a9a3436b Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Sat, 22 Jan 2022 22:39:00 -0600 Subject: [PATCH] Change snprintf to SNPRINTF in simulators https://github.com/Hamlib/Hamlib/issues/857 --- simulators/simelecraft.c | 12 ++++++------ simulators/simft991.c | 6 +++--- simulators/simicom.c | 30 ++++++++++++++++++++++++++++++ simulators/simkenwood.c | 4 ++-- simulators/simyaesu.c | 6 +++--- 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/simulators/simelecraft.c b/simulators/simelecraft.c index bd1ee8b2a..e5e1c28bf 100644 --- a/simulators/simelecraft.c +++ b/simulators/simelecraft.c @@ -143,7 +143,7 @@ int main(int argc, char *argv[]) printf("%s\n", buf); usleep(50 * 1000); int id = 24; - snprintf(buf, sizeof(buf), "ID%03d;", id); + SNPRINTF(buf, sizeof(buf), "ID%03d;", id); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); @@ -181,7 +181,7 @@ int main(int argc, char *argv[]) ant = (ant + 1) % 3; printf("%s\n", buf); usleep(50 * 1000); - snprintf(buf, sizeof(buf), "EX032%1d;", ant); + SNPRINTF(buf, sizeof(buf), "EX032%1d;", ant); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); @@ -189,9 +189,9 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "OM;") == 0) { - // KPA3 snprintf(buf, sizeof(buf), "OM AP----L-----;"); + // KPA3 SNPRINTF(buf, sizeof(buf), "OM AP----L-----;"); // K4+KPA3 - snprintf(buf, sizeof(buf), "OM AP-S----4---;"); + SNPRINTF(buf, sizeof(buf), "OM AP-S----4---;"); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); @@ -215,12 +215,12 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "MD;") == 0) { - snprintf(buf, sizeof(buf), "MD%d;", modea); + SNPRINTF(buf, sizeof(buf), "MD%d;", modea); write(fd, buf, strlen(buf)); } else if (strcmp(buf, "MD$;") == 0) { - snprintf(buf, sizeof(buf), "MD$%d;", modeb); + SNPRINTF(buf, sizeof(buf), "MD$%d;", modeb); write(fd, buf, strlen(buf)); } else if (strncmp(buf, "MD", 2) == 0) diff --git a/simulators/simft991.c b/simulators/simft991.c index 0417247cb..6b5133c2a 100644 --- a/simulators/simft991.c +++ b/simulators/simft991.c @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) printf("%s\n", buf); usleep(50 * 1000); int id = NC_RIGID_FTDX3000; - snprintf(buf, sizeof(buf), "ID%03d;", id); + SNPRINTF(buf, sizeof(buf), "ID%03d;", id); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); @@ -151,7 +151,7 @@ int main(int argc, char *argv[]) { printf("%s\n", buf); usleep(50 * 1000); - snprintf(buf, sizeof(buf), "AI0;"); + SNPRINTF(buf, sizeof(buf), "AI0;"); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); @@ -189,7 +189,7 @@ int main(int argc, char *argv[]) ant = (ant + 1) % 3; printf("%s\n", buf); usleep(50 * 1000); - snprintf(buf, sizeof(buf), "EX032%1d;", ant); + SNPRINTF(buf, sizeof(buf), "EX032%1d;", ant); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); diff --git a/simulators/simicom.c b/simulators/simicom.c index 49cc2546c..e06177fe5 100644 --- a/simulators/simicom.c +++ b/simulators/simicom.c @@ -184,6 +184,36 @@ void frameParse(int fd, unsigned char *frame, int len) write(fd, frame, 8); break; + case 0x14: + switch(frame[5]) + { + static int power_level = 0; + case 0x0a: + printf("Using power level %d\n", power_level); + power_level += 10; + if (power_level > 250) power_level = 0; + to_bcd(&frame[6], (long long)power_level, 2); + frame[8] = 0xfd; + write(fd, frame, 9); + break; + } + break; + + case 0x15: + switch(frame[5]) + { + static int meter_level = 0; + case 0x11: + printf("Using meter level %d\n", meter_level); + meter_level += 10; + if (meter_level > 250) meter_level = 0; + to_bcd(&frame[6], (long long)meter_level, 2); + frame[8] = 0xfd; + write(fd, frame, 9); + break; + } + break; + case 0x1a: // miscellaneous things switch (frame[5]) { diff --git a/simulators/simkenwood.c b/simulators/simkenwood.c index f7dbc03e1..620429d54 100644 --- a/simulators/simkenwood.c +++ b/simulators/simkenwood.c @@ -145,7 +145,7 @@ int main(int argc, char *argv[]) printf("%s\n", buf); usleep(50 * 1000); int id = 24; - snprintf(buf, sizeof(buf), "ID%03d;", id); + SNPRINTF(buf, sizeof(buf), "ID%03d;", id); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); @@ -183,7 +183,7 @@ int main(int argc, char *argv[]) ant = (ant + 1) % 3; printf("%s\n", buf); usleep(50 * 1000); - snprintf(buf, sizeof(buf), "EX032%1d;", ant); + SNPRINTF(buf, sizeof(buf), "EX032%1d;", ant); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); diff --git a/simulators/simyaesu.c b/simulators/simyaesu.c index c4ca47f99..eb63df681 100644 --- a/simulators/simyaesu.c +++ b/simulators/simyaesu.c @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) printf("%s\n", buf); usleep(50 * 1000); int id = NC_RIGID_FTDX3000; - snprintf(buf, sizeof(buf), "ID%03d;", id); + SNPRINTF(buf, sizeof(buf), "ID%03d;", id); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); @@ -174,7 +174,7 @@ int main(int argc, char *argv[]) { printf("%s\n", buf); usleep(50 * 1000); - snprintf(buf, sizeof(buf), "AI0;"); + SNPRINTF(buf, sizeof(buf), "AI0;"); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n); @@ -234,7 +234,7 @@ int main(int argc, char *argv[]) ant = (ant + 1) % 3; printf("%s\n", buf); usleep(50 * 1000); - snprintf(buf, sizeof(buf), "EX032%1d;", ant); + SNPRINTF(buf, sizeof(buf), "EX032%1d;", ant); n = write(fd, buf, strlen(buf)); printf("n=%d\n", n);