]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
convert a bunch of files to use the logging api logging-cleanup
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sun, 3 Dec 2023 16:03:39 +0000 (21:33 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sun, 3 Dec 2023 16:05:43 +0000 (21:35 +0530)
discovery.c
exit_menu.c
gpio.c
meter.c
old_discovery.c
old_protocol.c
pulseaudio.c
rigctl.c
rigctl_menu.c

index ec8d632e7b33299c7c207cd96a1a34d002b642d2..b3b61552c422450af99fc2428e6753250cf5c6c0 100644 (file)
@@ -285,7 +285,7 @@ void discovery() {
 //
 // first: look on USB for an Ozy
 //
-  fprintf(stderr,"looking for USB based OZY devices\n");
+  log_trace("looking for USB based OZY devices");
 
   if (ozy_discover() != 0)
   {
@@ -312,7 +312,7 @@ void discovery() {
 
   status_text("Discovery");
   
-    fprintf(stderr,"discovery: found %d devices\n", devices);
+    log_info("discovery: found %d devices", devices);
     gdk_window_set_cursor(gtk_widget_get_window(top_window),gdk_cursor_new(GDK_ARROW));
 
     discovery_dialog = gtk_dialog_new();
@@ -349,7 +349,7 @@ void discovery() {
       char text[256];
       for(row=0;row<devices;row++) {
         d=&discovered[row];
-fprintf(stderr,"%p Protocol=%d name=%s\n",d,d->protocol,d->name);
+       log_trace("%p Protocol=%d name=%s",d,d->protocol,d->name);
         sprintf(version,"v%d.%d",
                           d->software_version/10,
                           d->software_version%10);
@@ -493,7 +493,6 @@ fprintf(stderr,"%p Protocol=%d name=%s\n",d,d->protocol,d->name);
 
     gtk_container_add (GTK_CONTAINER (content), grid);
     gtk_widget_show_all(discovery_dialog);
-fprintf(stderr,"showing device dialog\n");
 
     // autostart if one device and autostart enabled
     log_trace("%s: devices=%d autostart=%d",__FUNCTION__,devices,autostart);
index 9496cf03a9e2c3b2065405b5f908546d454d1702..d05ca68c8b0adaf41e02e97b4e714d16aff345ab 100644 (file)
@@ -58,7 +58,6 @@ static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_d
 }
 
 static gboolean exit_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
-g_print("exit_cb\n");
 #ifdef GPIO
   gpio_close();
 #endif
diff --git a/gpio.c b/gpio.c
index fef0f2a008dc4ce02c9f6ea649780fad515da8ae..2164e281a4e1c8b5debfd8ffce225f47decbd8b1 100644 (file)
--- a/gpio.c
+++ b/gpio.c
@@ -65,6 +65,7 @@
 #include "zoompan.h"
 #ifdef LOCALCW
 #include "iambic.h"
+#include "log.h"
 
 //
 // Broadcom pins #9, 10, 11 are not used
@@ -367,7 +368,6 @@ static gpointer rotary_encoder_thread(gpointer data) {
   int i;
 
   usleep(250000);
-  g_print("%s\n",__FUNCTION__);
   while(TRUE) {
     g_mutex_lock(&encoder_mutex);
     for(i=0;i<MAX_ENCODERS;i++) {
@@ -590,7 +590,7 @@ static void process_edge(int offset,int value) {
         if(t<switches[i].switch_debounce) {
           return;
         }
-//g_print("%s: switches=%p function=%d (%s)\n",__FUNCTION__,switches,switches[i].switch_function,sw_string[switches[i].switch_function]);
+        //g_print("%s: switches=%p function=%d (%s)\n",__FUNCTION__,switches,switches[i].switch_function,sw_string[switches[i].switch_function]);
         switches[i].switch_debounce=t+settle_time;
         PROCESS_ACTION *a=g_new(PROCESS_ACTION,1);
         a->action=switches[i].switch_function;
@@ -603,7 +603,7 @@ static void process_edge(int offset,int value) {
 
 
   if(!found) {
-    g_print("%s: could not find %d\n",__FUNCTION__,offset);
+    log_trace("%s: could not find %d",__FUNCTION__,offset);
   }
 }
 
@@ -629,7 +629,6 @@ static int interrupt_cb(int event_type, unsigned int line, const struct timespec
 
 void gpio_set_defaults(int ctrlr) {
   int i;
-  g_print("%s: %d\n",__FUNCTION__,ctrlr);
   switch(ctrlr) {
     case NO_CONTROLLER:
       encoders=encoders_no_controller;
@@ -901,12 +900,6 @@ static gpointer monitor_thread(gpointer arg) {
   struct timespec t;
 
   // thread to monitor gpio events
-  g_print("%s: start event monitor lines=%d\n",__FUNCTION__,lines);
-  g_print("%s:",__FUNCTION__);
-  for(int i=0;i<lines;i++) {
-    g_print(" %d",monitor_lines[i]);
-  }
-  g_print("\n");
   t.tv_sec=60;
   t.tv_nsec=0;
 
@@ -915,10 +908,9 @@ static gpointer monitor_thread(gpointer arg) {
                        monitor_lines, lines, FALSE,
                        consumer, &t, NULL, interrupt_cb,NULL);
   if (ret<0) {
-    g_print("%s: ctxless event monitor failed: %s\n",__FUNCTION__,g_strerror(errno));
+    log_debug("%s: ctxless event monitor failed: %s",__FUNCTION__,g_strerror(errno));
   }
 
-  g_print("%s: exit\n",__FUNCTION__);
   return NULL;
 }
 
@@ -926,11 +918,10 @@ static int setup_line(struct gpiod_chip *chip, int offset, gboolean pullup) {
   int ret;
   struct gpiod_line_request_config config;
 
-  g_print("%s: %d\n",__FUNCTION__,offset);
   struct gpiod_line *line=gpiod_chip_get_line(chip, offset);
   if (!line) {
-    g_print("%s: get line %d failed: %s\n",__FUNCTION__,offset,g_strerror(errno));
-    return -1;
+      log_error("%s: get line %d failed: %s",__FUNCTION__,offset,g_strerror(errno));
+      return -1;
   }
 
   config.consumer=consumer;
@@ -942,8 +933,8 @@ static int setup_line(struct gpiod_chip *chip, int offset, gboolean pullup) {
 #endif
   ret=gpiod_line_request(line,&config,1);
   if (ret<0) {
-    g_print("%s: line %d gpiod_line_request failed: %s\n",__FUNCTION__,offset,g_strerror(errno));
-    return ret;
+      log_error("%s: line %d gpiod_line_request failed: %s",__FUNCTION__,offset,g_strerror(errno));
+      return ret;
   }
 
   gpiod_line_release(line);
@@ -957,18 +948,17 @@ static int setup_output_line(struct gpiod_chip *chip, int offset, int _initial_v
   int ret;
   struct gpiod_line_request_config config;
 
-  g_print("%s: %d\n",__FUNCTION__,offset);
   struct gpiod_line *line=gpiod_chip_get_line(chip, offset);
   if (!line) {
-    g_print("%s: get line %d failed: %s\n",__FUNCTION__,offset,g_strerror(errno));
-    return -1;
+      log_error("%s: get line %d failed: %s",__FUNCTION__,offset,g_strerror(errno));
+      return -1;
   }
 
   config.consumer=consumer;
   config.request_type=GPIOD_LINE_REQUEST_DIRECTION_OUTPUT;
   ret=gpiod_line_request(line,&config,1);
   if (ret<0) {
-    g_print("%s: line %d gpiod_line_request failed: %s\n",__FUNCTION__,offset,g_strerror(errno));
+    log_error("%s: line %d gpiod_line_request failed: %s",__FUNCTION__,offset,g_strerror(errno));
     return ret;
   }
 
@@ -982,7 +972,7 @@ static int setup_output_line(struct gpiod_chip *chip, int offset, int _initial_v
 #endif
 
 int gpio_init() {
-  int ret=0;
+    int ret=0;
 
 #ifdef GPIO
   initialiseEpoch();
@@ -993,12 +983,11 @@ int gpio_init() {
 
   chip=NULL;
 
-//g_print("%s: open gpio 0\n",__FUNCTION__);
   chip=gpiod_chip_open_by_number(0);
   if(chip==NULL) {
-    g_print("%s: open chip failed: %s\n",__FUNCTION__,g_strerror(errno));
-    ret=-1;
-    goto err;
+      log_error("%s: open chip failed: %s",__FUNCTION__,g_strerror(errno));
+      ret=-1;
+      goto err;
   }
   
 #ifdef LOCALCW  
@@ -1009,14 +998,13 @@ int gpio_init() {
                // for local CW the following pins are set.
                CWL_BUTTON=17;
                CWR_BUTTON=21;
-               g_print("LOCALCW is on ; NO controller selected; CW Buttons reconfigured\n");
+               log_debug("LOCALCW is on; NO controller selected; CW Buttons reconfigured");
        }
        // Radioberry device driver uses GPIO ports.
        if(controller != NO_CONTROLLER) {
 #endif
 
   // setup encoders
-  g_print("%s: setup encoders\n",__FUNCTION__);
   for(int i=0;i<MAX_ENCODERS;i++) {
     if(encoders[i].bottom_encoder_enabled) {
       if(setup_line(chip,encoders[i].bottom_encoder_address_a,encoders[i].bottom_encoder_pullup)<0) {
@@ -1044,7 +1032,6 @@ int gpio_init() {
   }
 
   // setup switches
-  g_print("%s: setup switches\n",__FUNCTION__);
   for(int i=0;i<MAX_SWITCHES;i++) {
     if(switches[i].switch_enabled) {
       if(setup_line(chip,switches[i].switch_address,switches[i].switch_pullup)<0) {
@@ -1058,14 +1045,13 @@ int gpio_init() {
 
   if(controller==CONTROLLER2_V1 || controller==CONTROLLER2_V2) {
     i2c_init();
-    g_print("%s: setup i2c interrupt %d\n",__FUNCTION__,I2C_INTERRUPT);
     if((ret=setup_line(chip,I2C_INTERRUPT,TRUE))<0) {
       goto err;
     }
   }
 
 #ifdef LOCALCW
-  g_print("%s: ENABLE_CW_BUTTONS=%d  CWL_BUTTON=%d CWR_BUTTON=%d\n", __FUNCTION__, ENABLE_CW_BUTTONS, CWL_BUTTON, CWR_BUTTON);
+  log_trace("%s: ENABLE_CW_BUTTONS=%d  CWL_BUTTON=%d CWR_BUTTON=%d", __FUNCTION__, ENABLE_CW_BUTTONS, CWL_BUTTON, CWR_BUTTON);
   if(ENABLE_CW_BUTTONS) {
     if((ret=setup_line(chip,CWL_BUTTON,CW_ACTIVE_LOW==1))<0) {
       goto err;
@@ -1092,16 +1078,16 @@ int gpio_init() {
     ) {
     monitor_thread_id = g_thread_new( "gpiod monitor", monitor_thread, NULL);
     if(!monitor_thread_id ) {
-      g_print("%s: g_thread_new failed for monitor_thread\n",__FUNCTION__);
+      log_trace("%s: g_thread_new failed for monitor_thread",__FUNCTION__);
     }
 
     if(controller!=NO_CONTROLLER) {
       rotary_encoder_thread_id = g_thread_new( "encoders", rotary_encoder_thread, NULL);
       if(!rotary_encoder_thread_id ) {
-        g_print("%s: g_thread_new failed on rotary_encoder_thread\n",__FUNCTION__);
+        log_trace("%s: g_thread_new failed on rotary_encoder_thread",__FUNCTION__);
         exit( -1 );
       }
-      g_print("%s: rotary_encoder_thread: id=%p\n",__FUNCTION__,rotary_encoder_thread_id);
+      log_trace("%s: rotary_encoder_thread: id=%p",__FUNCTION__,rotary_encoder_thread_id);
     }
   }
 
@@ -1109,7 +1095,6 @@ int gpio_init() {
   return 0;
 
 err:
-g_print("%s: err\n",__FUNCTION__);
 #ifdef GPIO
   if(chip!=NULL) {
     gpiod_chip_close(chip);
@@ -1136,7 +1121,7 @@ void gpio_cw_sidetone_set(int level) {
 #else
     if((rc=gpiod_ctxless_set_value_ext(gpio_device,SIDETONE_GPIO,level,FALSE,consumer,NULL,NULL,0))<0) {
 #endif
-      g_print("%s: err=%d\n",__FUNCTION__,rc);
+       log_trace("%s: err=%d",__FUNCTION__,rc);
     }
 #endif
   }
diff --git a/meter.c b/meter.c
index 667927ff0293f500d50fea3c72bb04e3e22999bd..67dd0661d05342f2736b9c0e2184e3b87b0689df 100644 (file)
--- a/meter.c
+++ b/meter.c
@@ -104,14 +104,12 @@ meter_press_event_cb (GtkWidget *widget,
 
 
 GtkWidget* meter_init(int width,int height,GtkWidget *parent) {
+    meter_width=width;
+    meter_height=height;
+    parent_window=parent;
 
-fprintf(stderr,"meter_init: width=%d height=%d\n",width,height);
-  meter_width=width;
-  meter_height=height;
-  parent_window=parent;
-
-  meter = gtk_drawing_area_new ();
-  gtk_widget_set_size_request (meter, width, height);
+    meter = gtk_drawing_area_new ();
+    gtk_widget_set_size_request (meter, width, height);
  
   /* Signals used to handle the backing surface */
   g_signal_connect (meter, "draw",
index 2a59f7315f76fd5cb52f1621d3534905a73c8186..8c8cfc045c909e07a0dab2feba613f37566299cc 100644 (file)
@@ -306,7 +306,7 @@ static gpointer discover_receive_thread(gpointer data) {
                            } else {
                               strcpy(discovered[devices].name,"HermesLite V2");                
                              discovered[devices].device = DEVICE_HERMES_LITE2;
-g_print("discovered HL2: Gateware Major Version=%d Minor Version=%d\n",buffer[9],buffer[15]);
+                             log_trace("discovered HL2: Gateware Major Version=%d Minor Version=%d",buffer[9],buffer[15]);
                            }
                             discovered[devices].frequency_min=0.0;
                             discovered[devices].frequency_max=30720000.0;
@@ -327,7 +327,7 @@ g_print("discovered HL2: Gateware Major Version=%d Minor Version=%d\n",buffer[9]
                             discovered[devices].frequency_max=61440000.0;
                             break;
                     }
-                   g_print("old_discovery: name=%s min=%f max=%f\n",discovered[devices].name, discovered[devices].frequency_min, discovered[devices].frequency_max);
+                   log_trace("old_discovery: name=%s min=%f max=%f",discovered[devices].name, discovered[devices].frequency_min, discovered[devices].frequency_max);
                     for(i=0;i<6;i++) {
                         discovered[devices].info.network.mac_address[i]=buffer[i+3];
                     }
index fcc290c9d031c3a153218a48fdc16ca0441e4672..f8f29f720280b716fa622881f34c719a4793a682 100644 (file)
@@ -465,7 +465,6 @@ static gpointer receive_thread(gpointer arg) {
   int ep;
   uint32_t sequence;
 
-  g_print( "old_protocol: receive_thread\n");
   running=1;
 
   //metis_restart();
@@ -501,7 +500,6 @@ static gpointer receive_thread(gpointer arg) {
          } else if (data_socket >= 0) {
             bytes_read=recvfrom(data_socket,buffer,sizeof(buffer),0,(struct sockaddr*)&addr,&length);
             if(bytes_read < 0 && errno != EAGAIN) perror("old_protocol recvfrom UDP:");
-           //g_print("%s: bytes_read=%d\n",__FUNCTION__,bytes_read);
           } else {
            // This could happen in METIS start/stop sequences
            usleep(100000);
@@ -525,8 +523,8 @@ static gpointer receive_thread(gpointer arg) {
              // A sequence error with a seqnum of zero usually indicates a METIS restart
              // and is no error condition
               if (sequence != 0 && sequence != last_seq_num+1) {
-               g_print("SEQ ERROR: last %ld, recvd %ld\n", (long) last_seq_num, (long) sequence);
-                sequence_errors++;
+                 log_error("SEQ ERROR: last %ld, recvd %ld", (long) last_seq_num, (long) sequence);
+                 sequence_errors++;
              }
              last_seq_num=sequence;
               switch(ep) {
@@ -551,19 +549,19 @@ static gpointer receive_thread(gpointer arg) {
 */
                   break;
                 default:
-                  g_print("unexpected EP %d length=%d\n",ep,bytes_read);
+                  log_error("unexpected EP %d length=%d",ep,bytes_read);
                   break;
               }
               break;
             case 2:  // response to a discovery packet
-              g_print("unexepected discovery response when not in discovery mode\n");
+              log_error("unexepected discovery response when not in discovery mode");
               break;
             default:
-              g_print("unexpected packet type: 0x%02X\n",buffer[2]);
+              log_error("unexpected packet type: 0x%02X",buffer[2]);
               break;
           }
         } else {
-          g_print("received bad header bytes on data port %02X,%02X\n",buffer[0],buffer[1]);
+          log_debug("received bad header bytes on data port %02X,%02X",buffer[0],buffer[1]);
         }
         break;
     }
@@ -979,7 +977,7 @@ static void process_ozy_input_buffer(unsigned char  *buffer) {
     time(&t);
     gmt=gmtime(&t);
 
-    g_print("%s: process_ozy_input_buffer: did not find sync: restarting\n",
+    log_debug("%s: process_ozy_input_buffer: did not find sync: restarting\n",
             asctime(gmt));
 
 
@@ -1053,16 +1051,16 @@ static void process_control_bytes() {
         IO3=(control_in[1]&0x08)?0:1;
         if(mercury_software_version!=control_in[2]) {
           mercury_software_version=control_in[2];
-          g_print("  Mercury Software version: %d (0x%0X)\n",mercury_software_version,mercury_software_version);
+          log_info("  Mercury Software version: %d (0x%0X)",mercury_software_version,mercury_software_version);
         }
         if(penelope_software_version!=control_in[3]) {
           penelope_software_version=control_in[3];
-          g_print("  Penelope Software version: %d (0x%0X)\n",penelope_software_version,penelope_software_version);
+          log_info("  Penelope Software version: %d (0x%0X)",penelope_software_version,penelope_software_version);
         }
       }
       if(ozy_software_version!=control_in[4]) {
         ozy_software_version=control_in[4];
-        g_print("FPGA firmware version: %d.%d\n",ozy_software_version/10,ozy_software_version%10);
+        log_info("FPGA firmware version: %d.%d",ozy_software_version/10,ozy_software_version%10);
       }
       break;
     case 1:
@@ -1526,7 +1524,7 @@ void ozy_send_buffer() {
       // Out of paranoia: print warning and choose ANT1
       //
       if (i<0 || i>2) {
-          g_print("WARNING: illegal TX antenna chosen, using ANT1\n");
+          log_warn("WARNING: illegal TX antenna chosen, using ANT1");
           transmitter->alex_antenna=0;
           i=0;
       }
@@ -1940,7 +1938,7 @@ void ozy_send_buffer() {
  * ship out line after each complete run
  */
   if (proto_mod && command == 1) {
-    g_print("DIS=%d DRIVE=%3d PTT=%d i1=%4d RXout=%d RXant=%d i2=%d TXrel=%d FB=%d BP=%d LNA=%d HPF=%02x LPF=%02x\n",
+    log_info("DIS=%d DRIVE=%3d PTT=%d i1=%4d RXout=%d RXant=%d i2=%d TXrel=%d FB=%d BP=%d LNA=%d HPF=%02x LPF=%02x",
      C3_TXDIS, C1_DRIVE, PC_PTT, CASE1, C3_RX1_OUT, C3_RX1_ANT, CASE2, C4_TX_REL,
      C2_FB, C3_BP, C3_LNA, C3_HPF, C4_LPF);
     proto_mod=0;
@@ -1969,9 +1967,9 @@ static void ozyusb_write(unsigned char* buffer,int length)
   i = ozy_write(EP2_OUT_ID,buffer,length);
   if(i!=length) {
     if(i==USB_TIMEOUT) {
-      g_print("%s: ozy_write timeout for %d bytes\n",__FUNCTION__,length);
+       log_trace("%s: ozy_write timeout for %d bytes",__FUNCTION__,length);
     } else {
-      g_print("%s: ozy_write for %d bytes returned %d\n",__FUNCTION__,length,i);
+       log_trace("%s: ozy_write for %d bytes returned %d",__FUNCTION__,length,i);
     }
   }
 
@@ -2066,7 +2064,6 @@ static int metis_write(unsigned char ep,unsigned char* buffer,int length) {
 static void metis_restart() {
   int i;
 
-  g_print("%s\n",__FUNCTION__);
   //
   // In TCP-ONLY mode, we possibly need to re-connect
   // since if we come from a METIS-stop, the server
@@ -2116,7 +2113,6 @@ static void metis_start_stop(int command) {
   int tmp;
   unsigned char buffer[1032];
     
-  g_print("%s: %d\n",__FUNCTION__,command);
 #ifdef USBOZY
   if(device!=DEVICE_OZY)
   {
@@ -2159,7 +2155,6 @@ static void metis_start_stop(int command) {
     tcp_socket=-1;
     usleep(100000);  // give some time to swallow incoming TCP packets
     close(tmp);
-    g_print("TCP socket closed\n");
   }
 
 #ifdef USBOZY
@@ -2178,7 +2173,7 @@ static void metis_send_buffer(unsigned char* buffer,int length) {
 
   if (tcp_socket >= 0) {
     if (length != 1032) {
-       g_print("PROGRAMMING ERROR: TCP LENGTH != 1032\n");
+       log_error("PROGRAMMING ERROR: TCP LENGTH != 1032");
        exit(-1);
     }
     if(sendto(tcp_socket,buffer,length,0,NULL, 0) != length) {
@@ -2188,12 +2183,12 @@ static void metis_send_buffer(unsigned char* buffer,int length) {
 //g_print("%s: sendto %d for %s:%d length=%d\n",__FUNCTION__,data_socket,inet_ntoa(data_addr.sin_addr),ntohs(data_addr.sin_port),length);
     bytes_sent=sendto(data_socket,buffer,length,0,(struct sockaddr*)&data_addr,sizeof(data_addr));
     if(bytes_sent!=length) {
-      g_print("%s: UDP sendto failed: %d: %s\n",__FUNCTION__,errno,strerror(errno));
+      log_error("%s: UDP sendto failed: %d: %s",__FUNCTION__,errno,strerror(errno));
       //perror("sendto socket failed for UDP metis_send_data\n");
     }
   } else {
     // This should not happen
-    g_print("METIS send: neither UDP nor TCP socket available!\n");
+    log_error("METIS send: neither UDP nor TCP socket available!");
     exit(-1);
   }
 }
index 3cbde325878c0dcfcc145a52e83bd4155c4e1fce..28867a8b817f6c2eb99225076152eb5ec690c263 100644 (file)
@@ -46,8 +46,8 @@ static void source_list_cb(pa_context *context, const pa_source_info *s,
     int i;
     if (eol > 0) {
         for (i = 0; i < n_input_devices; i++) {
-            g_print("Input: %d: %s (%s)\n", input_devices[i].index,
-                    input_devices[i].name, input_devices[i].description);
+            log_trace("Input: %d: %s (%s)", input_devices[i].index,
+                     input_devices[i].name, input_devices[i].description);
         }
         g_mutex_unlock(&audio_mutex);
     } else if (n_input_devices < MAX_AUDIO_DEVICES) {
@@ -67,8 +67,8 @@ static void sink_list_cb(pa_context *context, const pa_sink_info *s, int eol,
     int i;
     if (eol > 0) {
         for (i = 0; i < n_output_devices; i++) {
-            g_print("Output: %d: %s (%s)\n", output_devices[i].index,
-                    output_devices[i].name, output_devices[i].description);
+            log_trace("Output: %d: %s (%s)", output_devices[i].index,
+                     output_devices[i].name, output_devices[i].description);
         }
         op = pa_context_get_source_info_list(pa_ctx, source_list_cb, NULL);
     } else if (n_output_devices < MAX_AUDIO_DEVICES) {
@@ -90,38 +90,37 @@ static void state_cb(pa_context *c, void *userdata) {
 
     state = pa_context_get_state(c);
 
-    g_print("%s: %d\n", __FUNCTION__, state);
     switch (state) {
     // There are just here for reference
     case PA_CONTEXT_UNCONNECTED:
-        g_print("audio: state_cb: PA_CONTEXT_UNCONNECTED\n");
+        log_debug("audio: state_cb: PA_CONTEXT_UNCONNECTED");
         break;
     case PA_CONTEXT_CONNECTING:
-        g_print("audio: state_cb: PA_CONTEXT_CONNECTING\n");
+        log_debug("audio: state_cb: PA_CONTEXT_CONNECTING");
         break;
     case PA_CONTEXT_AUTHORIZING:
-        g_print("audio: state_cb: PA_CONTEXT_AUTHORIZING\n");
+        log_debug("audio: state_cb: PA_CONTEXT_AUTHORIZING");
         break;
     case PA_CONTEXT_SETTING_NAME:
-        g_print("audio: state_cb: PA_CONTEXT_SETTING_NAME\n");
+        log_debug("audio: state_cb: PA_CONTEXT_SETTING_NAME");
         break;
     case PA_CONTEXT_FAILED:
-        g_print("audio: state_cb: PA_CONTEXT_FAILED\n");
+        log_debug("audio: state_cb: PA_CONTEXT_FAILED");
         g_mutex_unlock(&audio_mutex);
         break;
     case PA_CONTEXT_TERMINATED:
-        g_print("audio: state_cb: PA_CONTEXT_TERMINATED\n");
+        log_debug("audio: state_cb: PA_CONTEXT_TERMINATED");
         g_mutex_unlock(&audio_mutex);
         break;
     case PA_CONTEXT_READY:
-        g_print("audio: state_cb: PA_CONTEXT_READY\n");
+        log_debug("audio: state_cb: PA_CONTEXT_READY");
         // get a list of the output devices
         n_input_devices = 0;
         n_output_devices = 0;
         op = pa_context_get_sink_info_list(pa_ctx, sink_list_cb, NULL);
         break;
     default:
-        g_print("audio: state_cb: unknown state %d\n", state);
+        log_debug("audio: state_cb: unknown state %d", state);
         break;
     }
 }
@@ -167,12 +166,12 @@ int audio_open_output(RECEIVER *rx) {
             rx->local_audio_buffer_offset = 0;
             rx->local_audio_buffer =
                 g_new0(float, 2 * rx->local_audio_buffer_size);
-            g_print("%s: allocated local_audio_buffer %p size %ld bytes\n",
-                    __FUNCTION__, rx->local_audio_buffer,
-                    2 * rx->local_audio_buffer_size * sizeof(float));
+            log_trace("allocated local_audio_buffer %p size %ld bytes",
+                     rx->local_audio_buffer,
+                     2 * rx->local_audio_buffer_size * sizeof(float));
         } else {
             result = -1;
-            g_print("%s: pa-simple_new failed: err=%d\n", __FUNCTION__, err);
+            log_trace("pa-simple_new failed: err=%d", err);
         }
         g_mutex_unlock(&rx->local_audio_mutex);
     }
@@ -184,7 +183,6 @@ static void *mic_read_thread(gpointer arg) {
     int rc;
     int err;
 
-    g_print("%s: running=%d\n", __FUNCTION__, running);
     while (running) {
         g_mutex_lock(&audio_mutex);
         if (local_microphone_buffer == NULL) {
@@ -195,8 +193,8 @@ static void *mic_read_thread(gpointer arg) {
                                 &err);
             if (rc < 0) {
                 running = 0;
-                g_print("%s: returned %d error=%d (%s)\n", __FUNCTION__, rc,
-                        err, pa_strerror(err));
+                log_error("%s: returned %d error=%d (%s)", __FUNCTION__, rc,
+                         err, pa_strerror(err));
             } else {
                 gint newpt;
                 for (gint i = 0; i < local_microphone_buffer_size; i++) {
@@ -229,7 +227,6 @@ static void *mic_read_thread(gpointer arg) {
         }
         g_mutex_unlock(&audio_mutex);
     }
-    g_print("%s: exit\n", __FUNCTION__);
     return NULL;
 }
 
@@ -270,7 +267,7 @@ int audio_open_input() {
         local_microphone_buffer_offset = 0;
         local_microphone_buffer = g_new0(float, local_microphone_buffer_size);
 
-        g_print("%s: allocating ring buffer\n", __FUNCTION__);
+        log_trace("%s: allocating ring buffer", __FUNCTION__);
         mic_ring_buffer = (float *)g_new(float, MICRINGLEN);
         mic_ring_read_pt = mic_ring_write_pt = 0;
         if (mic_ring_buffer == NULL) {
@@ -279,11 +276,11 @@ int audio_open_input() {
         }
 
         running = TRUE;
-        g_print("%s: PULSEAUDIO mic_read_thread\n", __FUNCTION__);
+        log_trace("%s: PULSEAUDIO mic_read_thread", __FUNCTION__);
         mic_read_thread_id = g_thread_new("mic_thread", mic_read_thread, NULL);
         if (!mic_read_thread_id) {
-            g_print("%s: g_thread_new failed on mic_read_thread\n",
-                    __FUNCTION__);
+            log_error("%s: g_thread_new failed on mic_read_thread",
+                     __FUNCTION__);
             g_free(local_microphone_buffer);
             local_microphone_buffer = NULL;
             running = FALSE;
@@ -331,7 +328,6 @@ float audio_get_next_mic_sample() {
 
     if ((mic_ring_buffer == NULL) || (mic_ring_read_pt == mic_ring_write_pt)) {
         // no buffer, or nothing in buffer: insert silence
-        // g_print("%s: no samples\n",__FUNCTION__);
         sample = 0.0;
     } else {
         // the "existence" of the ring buffer is now guaranteed for 1 msec,
index 3203d810b8f8d46ca6e1e4f6adb85464bde588be..e36303e74ea194be5dc47059b33bee0455bb87ce 100644 (file)
--- a/rigctl.c
+++ b/rigctl.c
@@ -62,6 +62,7 @@
 #include "iambic.h" // declare keyer_update()
 #endif
 #include <math.h>
+#include "log.h"
 
 #define NEW_PARSER
 
@@ -281,30 +282,24 @@ void close_rigctl_ports() {
     linger.l_onoff = 1;
     linger.l_linger = 0;
 
-    g_print("close_rigctl_ports: server_socket=%d\n", server_socket);
+    log_trace("close_rigctl_ports: server_socket=%d", server_socket);
     server_running = 0;
     for (i = 0; i < MAX_CLIENTS; i++) {
         if (client[i].fd != -1) {
-            g_print("setting SO_LINGER to 0 for client_socket: %d\n",
-                    client[i].fd);
             if (setsockopt(client[i].fd, SOL_SOCKET, SO_LINGER,
                            (const char *)&linger, sizeof(linger)) == -1) {
-                perror("setsockopt(...,SO_LINGER,...) failed for client");
+                log_debug("setsockopt(...,SO_LINGER,...) failed for client: %s", strerror(errno));
             }
-            g_print("closing client socket: %d\n", client[i].fd);
             close(client[i].fd);
             client[i].fd = -1;
         }
     }
 
     if (server_socket >= 0) {
-        g_print("setting SO_LINGER to 0 for server_socket: %d\n",
-                server_socket);
         if (setsockopt(server_socket, SOL_SOCKET, SO_LINGER,
                        (const char *)&linger, sizeof(linger)) == -1) {
-            perror("setsockopt(...,SO_LINGER,...) failed for server");
+            log_debug("setsockopt(...,SO_LINGER,...) failed for server: %s", strerror(errno));
         }
-        g_print("closing server_socket: %d\n", server_socket);
         close(server_socket);
         server_socket = -1;
     }
@@ -778,12 +773,13 @@ long long rigctl_getFrequency() {
 //
 void send_resp(int fd, char *msg) {
     if (fd == -1) {
-       g_print("RIGCTL: invalid file descriptor\n");
-       perror("send_resp");
+       log_error("RIGCTL: invalid file descriptor");
        return;
     }
-    if (rigctl_debug)
-        g_print("RIGCTL: RESP=%s\n", msg);
+
+    if (rigctl_debug) {
+        log_debug("RIGCTL: RESP=%s", msg);
+    }
 
     int length = strlen(msg);
     int written = 0;
@@ -791,7 +787,7 @@ void send_resp(int fd, char *msg) {
     while (written < length) {
        ssize_t n = write(fd, &msg[written], length - written);
        if (n < 0) {
-           perror("send_resp");
+           log_error("send_resp: %s", strerror(errno));
            break;
        }
         written += n;
@@ -809,11 +805,9 @@ static gpointer rigctl_server(gpointer data) {
     int on = 1;
     int i;
 
-    g_print("rigctl_server: starting server on port %d\n", port);
-
     server_socket = socket(AF_INET, SOCK_STREAM, 0);
     if (server_socket < 0) {
-        perror("rigctl_server: listen socket failed");
+        log_error("rigctl_server: listen socket failed: %s", strerror(errno));
         return NULL;
     }
 
@@ -851,35 +845,29 @@ static gpointer rigctl_server(gpointer data) {
            }
             return NULL;
         }
-       g_print("rigctl server: listen succeeded\n");
 
         // find a spare thread
         for (i = 0; i < MAX_CLIENTS; i++) {
             if (client[i].fd == -1) {
-                g_print("Using client: %d\n", i);
 
                 client[i].fd =
                     accept(server_socket, (struct sockaddr *)&client[i].address,
                            &client[i].address_length);
                 if (client[i].fd < 0) {
-                    perror("rigctl_server: client accept failed");
+                    log_error("rigctl_server: client accept failed: %s", strerror(errno));
                     continue;
                 }
 
                 client[i].thread_id = g_thread_new(
                     "rigctl client", rigctl_client, (gpointer)&client[i]);
                 if (client[i].thread_id == NULL) {
-                    g_print("g_thread_new failed (n rigctl_client\n");
-                    g_print("setting SO_LINGER to 0 for client_socket: %d\n",
-                            client[i].fd);
                     struct linger linger = {0};
                     linger.l_onoff = 1;
                     linger.l_linger = 0;
                     if (setsockopt(client[i].fd, SOL_SOCKET, SO_LINGER,
                                    (const char *)&linger,
                                    sizeof(linger)) == -1) {
-                        perror(
-                            "setsockopt(...,SO_LINGER,...) failed for client");
+                        log_error("setsockopt(...,SO_LINGER,...) failed for client: %s", strerror(errno));
                     }
                     close(client[i].fd);
                    client[i].fd = -1;
@@ -896,12 +884,10 @@ static gpointer rigctl_client(gpointer data) {
 
     CLIENT *client = (CLIENT *)data;
 
-    g_print("rigctl_client: starting rigctl_client: socket=%d\n", client->fd);
-
     g_mutex_lock(&mutex_a->m);
     cat_control++;
     if (rigctl_debug)
-        g_print("RIGCTL: CTLA INC cat_control=%d\n", cat_control);
+        log_debug("RIGCTL: CTLA INC cat_control=%d", cat_control);
     g_mutex_unlock(&mutex_a->m);
     g_idle_add(ext_vfo_update, NULL);
 
@@ -921,7 +907,7 @@ static gpointer rigctl_client(gpointer data) {
                if (cmd_input[i] == ';') {
                    command[command_index] = '\0';
                    if (rigctl_debug)
-                       g_print("RIGCTL: command=%s\n", command);
+                       log_debug("RIGCTL: command=%s", command);
                    COMMAND *info = g_new(COMMAND, 1);
                    info->client = client;
                    info->command = command;
@@ -942,23 +928,22 @@ static gpointer rigctl_client(gpointer data) {
        }
     }
 
-    g_print("RIGCTL: Leaving rigctl_client thread: numbytes = %d\n", numbytes);
     if (client->fd != -1) {
-        g_print("setting SO_LINGER to 0 for client_socket: %d\n", client->fd);
         struct linger linger = {0};
         linger.l_onoff = 1;
         linger.l_linger = 0;
         if (setsockopt(client->fd, SOL_SOCKET, SO_LINGER, (const char *)&linger,
                        sizeof(linger)) == -1) {
-            perror("setsockopt(...,SO_LINGER,...) failed for client");
+            log_error("setsockopt(...,SO_LINGER,...) failed for client: %s", strerror(errno));
         }
         close(client->fd);
         client->fd = -1;
         // Decrement CAT_CONTROL
         g_mutex_lock(&mutex_a->m);
         cat_control--;
-        if (rigctl_debug)
-            g_print("RIGCTL: CTLA DEC - cat_control=%d\n", cat_control);
+        if (rigctl_debug) {
+            log_debug("RIGCTL: CTLA DEC - cat_control=%d", cat_control);
+       }
         g_mutex_unlock(&mutex_a->m);
         g_idle_add(ext_vfo_update, NULL);
     }
@@ -4276,8 +4261,9 @@ int parse_cmd(void *data) {
     }
 
     if (!implemented) {
-        if (rigctl_debug)
-            g_print("RIGCTL: UNIMPLEMENTED COMMAND: %s\n", info->command);
+        if (rigctl_debug) {
+            log_debug("RIGCTL: UNIMPLEMENTED COMMAND: %s", info->command);
+       }
         send_resp(client->fd, "?;");
     }
 
@@ -4291,7 +4277,7 @@ int set_interface_attribs(int fd, int speed, int parity) {
     struct termios tty;
     memset(&tty, 0, sizeof tty);
     if (tcgetattr(fd, &tty) != 0) {
-        g_print("RIGCTL: Error %d from tcgetattr", errno);
+        log_error("tcgetattr: %s", strerror(errno));
         return -1;
     }
 
@@ -4319,7 +4305,7 @@ int set_interface_attribs(int fd, int speed, int parity) {
     tty.c_cflag &= ~CRTSCTS;
 
     if (tcsetattr(fd, TCSANOW, &tty) != 0) {
-        g_print("RIGCTL: Error %d from tcsetattr", errno);
+        log_error("tcsetattr: %s", strerror(errno));
         return -1;
     }
     return 0;
@@ -4339,15 +4325,15 @@ void set_blocking (int fd, int should_block) {
   fcntl(fd, F_SETFL, flags);
 
   if (tcgetattr (fd, &tty) != 0) {
-    g_print ("RIGCTL (tggetattr):");
-    return;
+      log_error("tggetattr error");
+      return;
   }
 
   tty.c_cc[VMIN]  = should_block > 0? 1: 0;
   tty.c_cc[VTIME] = 5;            // 0.5 seconds read timeout
 
   if (tcsetattr (fd, TCSANOW, &tty) != 0) {
-    g_print("RIGCTL (tcsetattr):");
+    log_error("tcsetattr error");
   }
 }
 
@@ -4361,6 +4347,7 @@ static gpointer serial_server(gpointer data) {
     int numbytes;
     int i;
     cat_control++;
+
     serial_running = TRUE;
     while (serial_running) {
         numbytes = read(fd, cmd_input, sizeof cmd_input);
@@ -4371,7 +4358,7 @@ static gpointer serial_server(gpointer data) {
                 if (cmd_input[i] == ';') {
                     command[command_index] = '\0';
                     if (rigctl_debug) {
-                        g_print("RIGCTL: command=%s\n", command);
+                        log_debug("RIGCTL: command=%s", command);
                    }
                     COMMAND *info = g_new(COMMAND, 1);
                     info->client = client;
@@ -4400,7 +4387,6 @@ static gpointer serial_server(gpointer data) {
 }
 
 int launch_serial() {
-    g_print("RIGCTL: Launch Serial port %s\n", ser_port);
     if (mutex_b_exists == 0) {
         mutex_b = g_new(GT_MUTEX, 1);
         g_mutex_init(&mutex_b->m);
@@ -4409,18 +4395,16 @@ int launch_serial() {
 
     if (mutex_busy == NULL) {
         mutex_busy = g_new(GT_MUTEX, 1);
-        g_print("launch_serial: mutex_busy=%p\n", mutex_busy);
+        log_trace("launch_serial: mutex_busy=%p", mutex_busy);
         g_mutex_init(&mutex_busy->m);
     }
 
     fd = open(ser_port, O_RDWR | O_NOCTTY | O_SYNC | O_NONBLOCK);
     if (fd < 0) {
-        g_print("RIGCTL: Error %d opening %s: %s\n", errno, ser_port,
-                strerror(errno));
-        return 0;
+        log_error("error opening %s: %s\n", ser_port, strerror(errno));
+        return -1;
     }
 
-    g_print("serial port fd=%d\n", fd);
     set_interface_attribs(fd, serial_baud_rate, serial_parity);
     set_blocking(fd, 1); // set no blocking
 
@@ -4431,16 +4415,16 @@ int launch_serial() {
         g_thread_new("Serial server", serial_server, serial_client);
     if (!serial_server_thread_id) {
         g_free(serial_client);
-        g_print("g_thread_new failed on serial_server\n");
-        return 0;
+        log_error("g_thread_new failed on serial_server");
+        return -1;
     }
 
-    return 1;
+    return 0;
 }
 
 // Serial Port close
 void disable_serial() {
-    g_print("RIGCTL: Disable Serial port %s\n", ser_port);
+    log_trace("RIGCTL: Disable Serial port %s", ser_port);
     serial_running = FALSE;
 }
 
@@ -4449,8 +4433,7 @@ void disable_serial() {
 //                   (Port numbers now const ints instead of defines..)
 //
 void launch_rigctl() {
-
-    g_print("LAUNCHING RIGCTL!!\n");
+    log_trace("LAUNCHING RIGCTL!!");
 
     rigctl_busy = 1;
     mutex_a = g_new(GT_MUTEX, 1);
@@ -4466,14 +4449,14 @@ void launch_rigctl() {
     g_mutex_init(&mutex_c->m);
 
     mutex_busy = g_new(GT_MUTEX, 1);
-    g_print("launch_rigctl: mutex_busy=%p\n", mutex_busy);
+    log_trace("launch_rigctl: mutex_busy=%p", mutex_busy);
     g_mutex_init(&mutex_busy->m);
 
     // This routine encapsulates the thread call
     rigctl_server_thread_id = g_thread_new("rigctl server", rigctl_server,
                                            (gpointer)(long)rigctl_port_base);
     if (!rigctl_server_thread_id) {
-        g_print("g_thread_new failed on rigctl_server\n");
+        log_error("g_thread_new failed on rigctl_server");
     }
 }
 
@@ -4509,7 +4492,6 @@ void set_freqB(long long new_freqB) {
 int set_alc(gpointer data) {
     int *lcl_ptr = (int *)data;
     alc = *lcl_ptr;
-    g_print("RIGCTL: set_alc=%d\n", alc);
     return 0;
 }
 
index b4f0370522e487bf27443b4d44848ac080944534..469e6790c0488a8b158855f1073b09169e8bd51a 100644 (file)
@@ -67,7 +67,7 @@ static void rigctl_value_changed_cb(GtkWidget *widget, gpointer data) {
 
 static void rigctl_debug_cb(GtkWidget *widget, gpointer data) {
   rigctl_debug=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-  g_print("---------- RIGCTL DEBUG %s ----------\n",rigctl_debug?"ON":"OFF");
+  log_trace("---------- RIGCTL DEBUG %s ----------",rigctl_debug?"ON":"OFF");
 }
 
 static void rigctl_enable_cb(GtkWidget *widget, gpointer data) {
@@ -83,11 +83,12 @@ static void serial_enable_cb(GtkWidget *widget, gpointer data) {
   strcpy(ser_port,gtk_entry_get_text(GTK_ENTRY(serial_port_entry)));
   serial_enable=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
   if(serial_enable) {
-     if(launch_serial() == 0) {
-        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(widget),FALSE)      ;
-     }       
+     if(launch_serial() == -1) {
+        log_debug("unable to enable serial port\n");
+        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(widget),FALSE);
+     }
   } else {
-     disable_serial();
+      disable_serial();
   }
 }