rx gain: experimenting with rounding
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 14 Jan 2022 08:22:01 +0000 (13:52 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 14 Jan 2022 08:22:01 +0000 (13:52 +0530)
rigctl.c

index 74d23e27ff115507995242e0ac5db8ef282c2bf6..f8297fe9eb0912aaa3c1973f58c49be38e03c351 100644 (file)
--- a/rigctl.c
+++ b/rigctl.c
@@ -3464,20 +3464,20 @@ int parse_cmd(void *data) {
         int att = 0;
         if (have_rx_gain) {
           att = (int)(adc[active_receiver->adc].attenuation + 12);
-          att = (int)(((double)att / 60.0) * 99.0);
+          att = (int)round((att * 99.0) / 60.0);
         } else {
           att = (int)(adc[active_receiver->adc].attenuation);
-          att = (int)(((double)att / 31.0) * 99.0);
+          att = (int)round((att * 99.0) / 31.0);
         }
         sprintf(reply, "RA%02d00;", att);
         send_resp(client->fd, reply);
       } else if (command[4] == ';') {
           command[4] = '\0';
-          int att = atoi(&command[2]);
+          int att = strtol(&command[2], NULL, 10);
           if (have_rx_gain) {
-              att = (int)((((double)att / 99.0) * 60.0) - 12.0);
+              att = (int)round(((att * 60.0) / 99.0)) - 12;
           } else {
-              att = (int)(((double)att / 99.0) * 31.0);
+              att = (int)round((att * 31.0) / 99.0);
           }
           set_attenuation_value((double)att);
       }