From 87df11967c7bb40af41c4e4ea141a336ffdbea8e Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Sun, 3 Dec 2023 21:33:39 +0530 Subject: [PATCH] convert a bunch of files to use the logging api --- discovery.c | 7 ++-- exit_menu.c | 1 - gpio.c | 57 +++++++++++------------------ meter.c | 12 +++---- old_discovery.c | 4 +-- old_protocol.c | 39 +++++++++----------- pulseaudio.c | 48 ++++++++++++------------- rigctl.c | 96 ++++++++++++++++++++----------------------------- rigctl_menu.c | 11 +++--- 9 files changed, 115 insertions(+), 160 deletions(-) diff --git a/discovery.c b/discovery.c index ec8d632..b3b6155 100644 --- a/discovery.c +++ b/discovery.c @@ -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;rowprotocol,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); diff --git a/exit_menu.c b/exit_menu.c index 9496cf0..d05ca68 100644 --- a/exit_menu.c +++ b/exit_menu.c @@ -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 fef0f2a..2164e28 100644 --- 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;iaction=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= 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); } } diff --git a/pulseaudio.c b/pulseaudio.c index 3cbde32..28867a8 100644 --- a/pulseaudio.c +++ b/pulseaudio.c @@ -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, diff --git a/rigctl.c b/rigctl.c index 3203d81..e36303e 100644 --- a/rigctl.c +++ b/rigctl.c @@ -62,6 +62,7 @@ #include "iambic.h" // declare keyer_update() #endif #include +#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; } diff --git a/rigctl_menu.c b/rigctl_menu.c index b4f0370..469e679 100644 --- a/rigctl_menu.c +++ b/rigctl_menu.c @@ -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(); } } -- 2.45.2