From: Ramakrishnan Muthukrishnan Date: Sat, 2 Dec 2023 16:48:36 +0000 (+0530) Subject: use logging API from log.h/log.c X-Git-Url: https://git.rkrishnan.org/vdrive/%22file:/listings//%22%22.?a=commitdiff_plain;h=032272da260f852aeeac568fbc5d05b0d0b22614;p=pihpsdr.git use logging API from log.h/log.c --- diff --git a/discovery.c b/discovery.c index c0dd5cd..ec8d632 100644 --- a/discovery.c +++ b/discovery.c @@ -55,6 +55,7 @@ #include "client_server.h" #endif #include "property.h" +#include "log.h" static GtkWidget *discovery_dialog; static DISCOVERED *d; @@ -236,7 +237,7 @@ static gboolean connect_cb (GtkWidget *widget, GdkEventButton *event, gpointer d // connect to remote host running piHPSDR strncpy(host_addr, gtk_entry_get_text(GTK_ENTRY(host_addr_entry)), 30); host_port=gtk_spin_button_get_value(GTK_SPIN_BUTTON(host_port_spinner)); -g_print("connect_cb: %s:%d\n",host_addr,host_port); + log_trace("connect_cb: %s:%d",host_addr,host_port); setProperty("host",host_addr); char temp[16]; sprintf(temp,"%d",host_port); @@ -495,7 +496,7 @@ fprintf(stderr,"%p Protocol=%d name=%s\n",d,d->protocol,d->name); fprintf(stderr,"showing device dialog\n"); // autostart if one device and autostart enabled - g_print("%s: devices=%d autostart=%d\n",__FUNCTION__,devices,autostart); + log_trace("%s: devices=%d autostart=%d",__FUNCTION__,devices,autostart); // if(devices==1 && autostart) { if(autostart) { diff --git a/main.c b/main.c index c9282ba..68ebbbd 100644 --- a/main.c +++ b/main.c @@ -20,13 +20,10 @@ // Define maximum window size. // Standard values 800 and 480: suitable for RaspberryBi 7-inch screen -#define G_LOG_USE_STRUCTURED 1 - #define MAX_DISPLAY_WIDTH 1024 // edit #define MAX_DISPLAY_HEIGHT 600 // edit #include -#include #include #include #include @@ -64,6 +61,8 @@ #include "ext.h" #include "vfo.h" +#include "log.h" + struct utsname unameData; gint display_width; @@ -210,7 +209,7 @@ static void activate_pihpsdr(GtkApplication *app, gpointer data) { display_width = gdk_screen_get_width(screen); display_height = gdk_screen_get_height(screen); - g_debug("width=%d height=%d\n", display_width, display_height); + log_debug("width=%d height=%d", display_width, display_height); // Go to "window" mode if there is enough space on the screen. // Do not forget extra space needed for window top bars, screen bars etc. @@ -235,8 +234,8 @@ static void activate_pihpsdr(GtkApplication *app, gpointer data) { full_screen = 1; } - g_debug("display_width=%d display_height=%d\n", display_width, - display_height); + log_debug("display_width=%d display_height=%d", display_width, + display_height); top_window = gtk_application_window_new(app); if (full_screen) { @@ -249,11 +248,9 @@ static void activate_pihpsdr(GtkApplication *app, gpointer data) { GError *error; if (!gtk_window_set_icon_from_file(GTK_WINDOW(top_window), "hpsdr.png", &error)) { - g_log_structured(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, - "MESSAGE", "failed to set icon for top_window\n"); + log_warn("failed to set icon for top_window"); if (error != NULL) { - g_log_structured(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, - "MESSAGE", "%s\n", error->message); + log_warn("%s", error->message); } } g_signal_connect(top_window, "delete-event", G_CALLBACK(main_delete), NULL); diff --git a/memory.c b/memory.c index e9f8ff1..5196719 100644 --- a/memory.c +++ b/memory.c @@ -19,9 +19,10 @@ #include #include +#include "log.h" void show_memory(char *title) { struct rusage r_usage; getrusage(RUSAGE_SELF,&r_usage); - fprintf(stderr, "%s: Memory usage: %ld bytes\n",title,r_usage.ru_maxrss); + log_trace("%s: Memory usage: %ld bytes",title,r_usage.ru_maxrss); } diff --git a/new_menu.c b/new_menu.c index edb14cb..38be1ae 100644 --- a/new_menu.c +++ b/new_menu.c @@ -49,7 +49,6 @@ #include "filter_menu.h" #include "noise_menu.h" #include "agc_menu.h" -#include "test_menu.h" #include "vox_menu.h" #include "diversity_menu.h" #include "tx_menu.h" diff --git a/old_discovery.c b/old_discovery.c index 0ab712b..2a59f73 100644 --- a/old_discovery.c +++ b/old_discovery.c @@ -37,6 +37,7 @@ #include "discovered.h" #include "discovery.h" #include "old_discovery.h" +#include "log.h" static char interface_name[64]; static struct sockaddr_in interface_addr={0}; @@ -69,11 +70,11 @@ static void discover(struct ifaddrs* iface) { // Therefore we try to send a METIS detection packet via TCP // to a "fixed" ip address. // - fprintf(stderr,"Trying to detect at TCP addr %s\n", ipaddr_tcp); + log_trace("Trying to detect at TCP addr %s", ipaddr_tcp); memset(&to_addr, 0, sizeof(to_addr)); to_addr.sin_family = AF_INET; if (inet_aton(ipaddr_tcp, &to_addr.sin_addr) == 0) { - fprintf(stderr,"discover: TCP addr %s is invalid!\n",ipaddr_tcp); + log_error("discover: TCP addr %s is invalid!",ipaddr_tcp); return; } to_addr.sin_port=htons(DISCOVERY_PORT); @@ -116,7 +117,7 @@ static void discover(struct ifaddrs* iface) { // If no connection occured, return if (rc == 0) { // select timed out - fprintf(stderr,"discover: select() timed out on TCP discovery socket\n"); + log_error("discover: select() timed out on TCP discovery socket"); close(discovery_socket); return; } @@ -131,7 +132,7 @@ static void discover(struct ifaddrs* iface) { } if (optval != 0) { // connect did not succeed - fprintf(stderr,"discover: connect() on TCP socket did not succeed\n"); + log_error("discover: connect() on TCP socket did not succeed"); close(discovery_socket); return; } @@ -140,7 +141,7 @@ static void discover(struct ifaddrs* iface) { } else { strcpy(interface_name,iface->ifa_name); - fprintf(stderr,"discover: looking for HPSDR devices on %s\n", interface_name); + log_trace("discover: looking for HPSDR devices on %s", interface_name); // send a broadcast to locate hpsdr boards on the network discovery_socket=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP); @@ -163,13 +164,13 @@ static void discover(struct ifaddrs* iface) { return; } - fprintf(stderr,"discover: bound to %s\n",interface_name); + log_trace("discover: bound to %s",interface_name); // allow broadcast on the socket int on=1; rc=setsockopt(discovery_socket, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); if(rc != 0) { - fprintf(stderr,"discover: cannot set SO_BROADCAST: rc=%d\n", rc); + log_error("discover: cannot set SO_BROADCAST: rc=%d", rc); exit(-1); } @@ -187,8 +188,8 @@ static void discover(struct ifaddrs* iface) { discover_thread_id = g_thread_new( "old discover receive", discover_receive_thread, NULL); if( ! discover_thread_id ) { - fprintf(stderr,"g_thread_new failed on discover_receive_thread\n"); - exit( -1 ); + log_error("g_thread_new failed on discover_receive_thread"); + exit(-1); } @@ -215,23 +216,23 @@ static void discover(struct ifaddrs* iface) { close(discovery_socket); if (iface == NULL) { - fprintf(stderr,"discover: exiting TCP discover for %s\n",ipaddr_tcp); - if (devices == rc+1) { - // - // We have exactly found one TCP device - // and have to patch the TCP addr into the device field - // and set the "use TCP" flag. - // - memcpy((void*)&discovered[rc].info.network.address,(void*)&to_addr,sizeof(to_addr)); - discovered[rc].info.network.address_length=sizeof(to_addr); - memcpy((void*)&discovered[rc].info.network.interface_address,(void*)&to_addr,sizeof(to_addr)); - memcpy((void*)&discovered[rc].info.network.interface_netmask,(void*)&to_addr,sizeof(to_addr)); - discovered[rc].info.network.interface_length=sizeof(to_addr); - strcpy(discovered[rc].info.network.interface_name,"TCP"); - discovered[rc].use_tcp=1; - } + log_trace("discover: exiting TCP discover for %s",ipaddr_tcp); + if (devices == rc+1) { + // + // We have exactly found one TCP device + // and have to patch the TCP addr into the device field + // and set the "use TCP" flag. + // + memcpy((void*)&discovered[rc].info.network.address,(void*)&to_addr,sizeof(to_addr)); + discovered[rc].info.network.address_length=sizeof(to_addr); + memcpy((void*)&discovered[rc].info.network.interface_address,(void*)&to_addr,sizeof(to_addr)); + memcpy((void*)&discovered[rc].info.network.interface_netmask,(void*)&to_addr,sizeof(to_addr)); + discovered[rc].info.network.interface_length=sizeof(to_addr); + strcpy(discovered[rc].info.network.interface_name,"TCP"); + discovered[rc].use_tcp=1; + } } else { - fprintf(stderr,"discover: exiting discover for %s\n",iface->ifa_name); + log_trace("discover: exiting discover for %s",iface->ifa_name); } } @@ -246,8 +247,6 @@ static gpointer discover_receive_thread(gpointer data) { struct timeval tv; int i; - fprintf(stderr,"discover_receive_thread\n"); - tv.tv_sec = 2; tv.tv_usec = 0; setsockopt(discovery_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval)); @@ -256,12 +255,12 @@ static gpointer discover_receive_thread(gpointer data) { while(1) { bytes_read=recvfrom(discovery_socket,buffer,sizeof(buffer),1032,(struct sockaddr*)&addr,&len); if(bytes_read<0) { - fprintf(stderr,"discovery: bytes read %d\n", bytes_read); - perror("old_discovery: recvfrom socket failed for discover_receive_thread"); + log_debug("discovery: bytes read %d", bytes_read); + log_error("old_discovery: recvfrom socket failed for discover_receive_thread: %s", strerror(errno)); break; } if (bytes_read == 0) break; - fprintf(stderr,"old_discovery: received %d bytes\n",bytes_read); + log_trace("old_discovery: received %d bytes",bytes_read); if ((buffer[0] & 0xFF) == 0xEF && (buffer[1] & 0xFF) == 0xFE) { int status = buffer[2] & 0xFF; if (status == 2 || status == 3) { @@ -341,7 +340,7 @@ g_print("discovered HL2: Gateware Major Version=%d Minor Version=%d\n",buffer[9] strcpy(discovered[devices].info.network.interface_name,interface_name); discovered[devices].use_tcp=0; discovered[devices].supported_receivers=2; - fprintf(stderr,"old_discovery: found device=%d software_version=%d status=%d address=%s (%02X:%02X:%02X:%02X:%02X:%02X) on %s min=%f max=%f\n", + log_trace("old_discovery: found device=%d software_version=%d status=%d address=%s (%02X:%02X:%02X:%02X:%02X:%02X) on %s min=%f max=%f", discovered[devices].device, discovered[devices].software_version, discovered[devices].status, @@ -361,7 +360,7 @@ g_print("discovered HL2: Gateware Major Version=%d Minor Version=%d\n",buffer[9] } } - fprintf(stderr,"discovery: exiting discover_receive_thread\n"); + log_trace("discovery: exiting discover_receive_thread"); g_thread_exit(NULL); return NULL; } @@ -369,7 +368,6 @@ g_print("discovered HL2: Gateware Major Version=%d Minor Version=%d\n",buffer[9] void old_discovery() { struct ifaddrs *addrs,*ifa; -fprintf(stderr,"old_discovery\n"); getifaddrs(&addrs); ifa = addrs; while (ifa) { @@ -388,21 +386,21 @@ fprintf(stderr,"old_discovery\n"); // Do one additional "discover" for a fixed TCP address discover(NULL); - fprintf(stderr, "discovery found %d devices\n",devices); + log_trace("discovery found %d devices",devices); for(size_t i = 0; i < devices; i++) { - fprintf(stderr,"discovery: found device=%d software_version=%d status=%d address=%s (%02X:%02X:%02X:%02X:%02X:%02X) on %s\n", - discovered[i].device, - discovered[i].software_version, - discovered[i].status, - inet_ntoa(discovered[i].info.network.address.sin_addr), - discovered[i].info.network.mac_address[0], - discovered[i].info.network.mac_address[1], - discovered[i].info.network.mac_address[2], - discovered[i].info.network.mac_address[3], - discovered[i].info.network.mac_address[4], - discovered[i].info.network.mac_address[5], - discovered[i].info.network.interface_name); + log_trace("discovery: found device=%d software_version=%d status=%d address=%s (%02X:%02X:%02X:%02X:%02X:%02X) on %s", + discovered[i].device, + discovered[i].software_version, + discovered[i].status, + inet_ntoa(discovered[i].info.network.address.sin_addr), + discovered[i].info.network.mac_address[0], + discovered[i].info.network.mac_address[1], + discovered[i].info.network.mac_address[2], + discovered[i].info.network.mac_address[3], + discovered[i].info.network.mac_address[4], + discovered[i].info.network.mac_address[5], + discovered[i].info.network.interface_name); } } diff --git a/old_protocol.c b/old_protocol.c index 85a3ba7..fcc290c 100644 --- a/old_protocol.c +++ b/old_protocol.c @@ -54,6 +54,7 @@ #include "ext.h" #include "iambic.h" #include "error_handler.h" +#include "log.h" #define min(x,y) (xlocal_microphone) { if(audio_open_input()!=0) { - g_print("audio_open_input failed\n"); + log_error("audio_open_input failed"); transmitter->local_microphone=0; } } @@ -294,28 +270,25 @@ void old_protocol_init(int rx,int pixels,int rate) { // if we have a USB interfaced Ozy device: // if (device == DEVICE_OZY) { - g_print("old_protocol_init: initialise ozy on USB\n"); - ozy_initialise(); - start_usb_receive_threads(); + log_trace("old_protocol_init: initialise ozy on USB"); + ozy_initialise(); + start_usb_receive_threads(); } else #endif { - g_print("old_protocol starting receive thread: buffer_size=%d output_buffer_size=%d\n",buffer_size,output_buffer_size); - if (radio->use_tcp) { - open_tcp_socket(); - } else { - open_udp_socket(); - } + log_trace("old_protocol starting receive thread: buffer_size=%d output_buffer_size=%d",buffer_size,output_buffer_size); + if (radio->use_tcp) { + open_tcp_socket(); + } else { + open_udp_socket(); + } receive_thread_id = g_thread_new( "old protocol", receive_thread, NULL); if( ! receive_thread_id ) { - g_print("g_thread_new failed on receive_thread\n"); - exit( -1 ); + log_error("g_thread_new failed on receive_thread"); + exit(-1); } - g_print( "receive_thread: id=%p\n",receive_thread_id); - - g_print("old_protocol_init: prime radio\n"); for(i=8;iinfo.network.interface_address.sin_addr),ntohs(radio->info.network.interface_address.sin_port)); + log_trace("binding UDP socket to %s:%d\n",inet_ntoa(radio->info.network.interface_address.sin_addr),ntohs(radio->info.network.interface_address.sin_port)); if(bind(tmp,(struct sockaddr*)&radio->info.network.interface_address,radio->info.network.interface_length)<0) { - perror("old_protocol: bind socket failed for data_socket\n"); - exit(-1); + log_error("old_protocol: bind socket failed for data_socket: %s", strerror(errno)); + exit(-1); } memcpy(&data_addr,&radio->info.network.address,radio->info.network.address_length); data_addr.sin_port=htons(DATA_PORT); data_socket=tmp; - g_print("%s: UDP socket established: %d for %s:%d\n",__FUNCTION__,data_socket,inet_ntoa(data_addr.sin_addr),ntohs(data_addr.sin_port)); + log_trace("%s: UDP socket established: %d for %s:%d",__FUNCTION__,data_socket,inet_ntoa(data_addr.sin_addr),ntohs(data_addr.sin_port)); } static void open_tcp_socket() { @@ -462,7 +428,7 @@ static void open_tcp_socket() { memcpy(&data_addr,&radio->info.network.address,radio->info.network.address_length); data_addr.sin_port=htons(DATA_PORT); data_addr.sin_family = AF_INET; - g_print("Trying to open TCP connection to %s\n", inet_ntoa(radio->info.network.address.sin_addr)); + log_trace("Trying to open TCP connection to %s", inet_ntoa(radio->info.network.address.sin_addr)); tmp=socket(AF_INET, SOCK_STREAM, 0); if (tmp < 0) { @@ -487,7 +453,7 @@ static void open_tcp_socket() { perror("tcp_socket: SO_RCVBUF"); } tcp_socket=tmp; - g_print("TCP socket established: %d\n", tcp_socket); + log_trace("TCP socket established: %d", tcp_socket); } static gpointer receive_thread(gpointer arg) { diff --git a/property.c b/property.c index 860bf91..e520961 100644 --- a/property.c +++ b/property.c @@ -23,22 +23,22 @@ #include #include #include "property.h" +#include "log.h" PROPERTY* properties=NULL; static double version=0.0; void clearProperties() { -g_print("clearProperties\n"); - if(properties!=NULL) { - // free all the properties - PROPERTY *next; - while(properties!=NULL) { - next=properties->next_property; - free(properties); - properties=next; + if(properties!=NULL) { + // free all the properties + PROPERTY *next; + while(properties!=NULL) { + next=properties->next_property; + free(properties); + properties=next; + } } - } } /* --------------------------------------------------------------------------*/ @@ -54,7 +54,6 @@ void loadProperties(char* filename) { FILE* f=fopen(filename,"r"); PROPERTY* property; - fprintf(stderr,"loadProperties: %s\n",filename); clearProperties(); if(f) { while(fgets(string,sizeof(string),f)) { @@ -81,7 +80,7 @@ void loadProperties(char* filename) { if(version!=PROPERTY_VERSION) { properties=NULL; - fprintf(stderr,"loadProperties: version=%f expected version=%f ignoring\n",version,PROPERTY_VERSION); + log_error("loadProperties: version=%f expected version=%f ignoring",version,PROPERTY_VERSION); } } @@ -96,10 +95,8 @@ void saveProperties(char* filename) { FILE* f=fopen(filename,"w+"); char line[512]; - fprintf(stderr,"saveProperties: %s\n",filename); - if(!f) { - fprintf(stderr,"can't open %s\n",filename); + log_error("can't open %s",filename); return; } diff --git a/pulseaudio.c b/pulseaudio.c index d915ad1..3cbde32 100644 --- a/pulseaudio.c +++ b/pulseaudio.c @@ -11,6 +11,7 @@ #include "radio.h" #include "receiver.h" #include "transmitter.h" +#include "log.h" int n_input_devices; AUDIO_DEVICE input_devices[MAX_AUDIO_DEVICES]; @@ -364,7 +365,7 @@ int cw_audio_write(RECEIVER *rx, float sample) { rx->local_audio_buffer_size * sizeof(float) * 2, &err); if (rc != 0) { - fprintf(stderr, "audio_write failed err=%d\n", err); + log_error("audio_write failed err=%d", err); } rx->local_audio_buffer_offset = 0; } @@ -393,7 +394,7 @@ int audio_write(RECEIVER *rx, float left_sample, float right_sample) { rx->local_audio_buffer_size * sizeof(float) * 2, &err); if (rc != 0) { - fprintf(stderr, "audio_write failed err=%d\n", err); + log_error("audio_write failed err=%d", err); } rx->local_audio_buffer_offset = 0; } diff --git a/radio.c b/radio.c index 9baad7a..5eceae4 100644 --- a/radio.c +++ b/radio.c @@ -66,6 +66,7 @@ #include "vox.h" #include "waterfall.h" #include "zoompan.h" +#include "log.h" #ifdef LOCALCW #include "iambic.h" @@ -355,21 +356,21 @@ gint rx_height; void radio_stop() { if (can_transmit) { - g_print("radio_stop: TX: CloseChannel: %d\n", transmitter->id); + log_trace("radio_stop: TX: CloseChannel: %d", transmitter->id); CloseChannel(transmitter->id); } set_displaying(receiver[0], 0); - g_print("radio_stop: RX0: CloseChannel: %d\n", receiver[0]->id); + log_trace("radio_stop: RX0: CloseChannel: %d", receiver[0]->id); CloseChannel(receiver[0]->id); set_displaying(receiver[1], 0); - g_print("radio_stop: RX1: CloseChannel: %d\n", receiver[1]->id); + log_trace("radio_stop: RX1: CloseChannel: %d", receiver[1]->id); CloseChannel(receiver[1]->id); } void reconfigure_radio() { int i; int y; - g_print("reconfigure_radio: receivers=%d\n", receivers); + log_trace("reconfigure_radio: receivers=%d", receivers); rx_height = display_height - VFO_HEIGHT; if (display_zoompan) { rx_height -= ZOOMPAN_HEIGHT; @@ -471,11 +472,9 @@ static void create_visual() { gtk_container_remove(GTK_CONTAINER(top_window), grid); gtk_container_add(GTK_CONTAINER(top_window), fixed); - // g_print("radio: vfo_init\n"); vfo_panel = vfo_init(VFO_WIDTH, VFO_HEIGHT, top_window); gtk_fixed_put(GTK_FIXED(fixed), vfo_panel, 0, y); - // g_print("radio: meter_init\n"); meter = meter_init(METER_WIDTH, METER_HEIGHT, top_window); gtk_fixed_put(GTK_FIXED(fixed), meter, VFO_WIDTH, y); @@ -564,7 +563,6 @@ static void create_visual() { #ifdef CLIENT_SERVER if (!radio_is_remote) { #endif - // g_print("Create transmitter\n"); if (can_transmit) { if (duplex) { transmitter = create_transmitter( @@ -644,7 +642,7 @@ static void create_visual() { if (init_gpio) { #ifdef GPIO if (gpio_init() < 0) { - g_print("GPIO failed to initialize\n"); + log_error("GPIO failed to initialize"); } #endif } @@ -652,7 +650,7 @@ static void create_visual() { #ifdef LOCALCW // init local keyer if enabled if (cw_keyer_internal == 0) { - g_print("Initialize keyer.....\n"); + log_trace("Initialize keyer....."); keyer_update(); } @@ -685,7 +683,6 @@ static void create_visual() { } if (display_sliders) { - // g_print("create sliders\n"); sliders = sliders_init(display_width, SLIDERS_HEIGHT); gtk_fixed_put(GTK_FIXED(fixed), sliders, 0, y); y += SLIDERS_HEIGHT; @@ -697,12 +694,12 @@ static void create_visual() { y += TOOLBAR_HEIGHT; } - g_print("create_visual: receivers=%d RECEIVERS=%d\n", receivers, RECEIVERS); + log_trace("create_visual: receivers=%d RECEIVERS=%d", receivers, RECEIVERS); if (receivers != RECEIVERS) { int r = receivers; receivers = RECEIVERS; - g_print("create_visual: calling radio_change_receivers: receivers=%d " - "r=%d\n", + log_trace("create_visual: calling radio_change_receivers: receivers=%d " + "r=%d", receivers, r); radio_change_receivers(r); } @@ -713,8 +710,6 @@ static void create_visual() { void start_radio() { int i; - // g_print("start_radio: selected radio=%p - // device=%d\n",radio,radio->device); gdk_window_set_cursor(gtk_widget_get_window(top_window), gdk_cursor_new(GDK_WATCH)); @@ -1091,8 +1086,6 @@ void start_radio() { adc[1].attenuation = 0; } - // g_print("meter_calibration=%f display_calibration=%f\n", - // meter_calibration, display_calibration); #ifdef GPIO switch (controller) { @@ -1123,10 +1116,10 @@ void start_radio() { display_sequence_errors = TRUE; - g_print("%s: setup RECEIVERS protocol=%d\n", __FUNCTION__, protocol); + log_trace("%s: setup RECEIVERS protocol=%d", __FUNCTION__, protocol); switch (protocol) { default: - g_print("%s: setup RECEIVERS default\n", __FUNCTION__); + log_trace("%s: setup RECEIVERS default", __FUNCTION__); RECEIVERS = 2; #ifdef PURESIGNAL MAX_RECEIVERS = (RECEIVERS + 2); @@ -1203,7 +1196,7 @@ void start_radio() { // radio. // #ifdef MIDI - g_print("%s: midi_enabled=%d midi_device_name=%s\n", __FUNCTION__, + log_trace("%s: midi_enabled=%d midi_device_name=%s", __FUNCTION__, midi_enabled, midi_device_name); if (midi_enabled && (midi_device_name != NULL)) { if (register_midi_device(midi_device_name) < 0) { @@ -1225,12 +1218,12 @@ void start_radio() { } void disable_rigctl() { - g_print("RIGCTL: disable_rigctl()\n"); + log_trace("RIGCTL: disable_rigctl()"); close_rigctl_ports(); } void radio_change_receivers(int r) { - g_print("radio_change_receivers: from %d to %d\n", receivers, r); + log_trace("radio_change_receivers: from %d to %d", receivers, r); // The button in the radio menu will call this function even if the // number of receivers has not changed. if (receivers == r) @@ -1412,9 +1405,6 @@ void vox_changed(int state) { } void frequency_changed(RECEIVER *rx) { - // g_print("frequency_changed: channel=%d frequency=%ld lo=%ld error=%ld - // ctun=%d - // offset=%ld\n",rx->channel,rx->frequency_a,rx->lo_a,rx->error_a,rx->ctun,rx->offset); if (vfo[0].ctun) { SetRXAShiftFreq(rx->id, (double)vfo[0].offset); RXANBPSetShiftFrequency(rx->id, (double)vfo[0].offset); @@ -1640,8 +1630,6 @@ void calcDriveLevel() { if (isTransmitting() && protocol == NEW_PROTOCOL) { schedule_high_priority(); } - // g_print("calcDriveLevel: drive=%d - // drive_level=%d\n",transmitter->drive,transmitter->drive_level); } void setDrive(double value) { @@ -1715,7 +1703,7 @@ void radioRestoreState() { char *value; int i; - g_print("radioRestoreState: %s\n", property_path); + log_trace("radioRestoreState: %s", property_path); g_mutex_lock(&property_mutex); loadProperties(property_path); @@ -2173,7 +2161,7 @@ void radioSaveState() { char value[80]; char name[32]; - g_print("radioSaveState: %s\n", property_path); + log_trace("radioSaveState: %s", property_path); g_mutex_lock(&property_mutex); clearProperties(); @@ -2514,7 +2502,6 @@ void calculate_display_average(RECEIVER *rx) { void set_filter_type(int filter_type) { int i; - // g_print("set_filter_type: %d\n",filter_type); for (i = 0; i < RECEIVERS; i++) { receiver[i]->low_latency = filter_type; RXASetMP(receiver[i]->id, filter_type); @@ -2526,7 +2513,6 @@ void set_filter_type(int filter_type) { void set_filter_size(int filter_size) { int i; - // g_print("set_filter_size: %d\n",filter_size); for (i = 0; i < RECEIVERS; i++) { receiver[i]->fft_size = filter_size; RXASetNC(receiver[i]->id, filter_size); diff --git a/receiver.c b/receiver.c index fda9c0f..c5b6b65 100644 --- a/receiver.c +++ b/receiver.c @@ -51,6 +51,7 @@ #ifdef CLIENT_SERVER #include "client_server.h" #endif +#include "log.h" #define min(x, y) (x < y ? x : y) #define max(x, y) (x < y ? y : x) @@ -62,7 +63,7 @@ static gboolean making_active = FALSE; void receiver_weak_notify(gpointer data, GObject *obj) { RECEIVER *rx = (RECEIVER *)data; - g_print("%s: id=%d obj=%p\n", __FUNCTION__, rx->id, obj); + log_trace("%s: id=%d obj=%p", __FUNCTION__, rx->id, obj); } gboolean receiver_button_press_event(GtkWidget *widget, GdkEventButton *event, @@ -171,7 +172,7 @@ void receiver_save_state(RECEIVER *rx) { char name[128]; char value[128]; - g_print("%s: %d\n", __FUNCTION__, rx->id); + log_trace("%s: %d", __FUNCTION__, rx->id); sprintf(name, "receiver.%d.audio_channel", rx->id); sprintf(value, "%d", rx->audio_channel); setProperty(name, value); @@ -391,7 +392,7 @@ void receiver_restore_state(RECEIVER *rx) { char name[128]; char *value; - g_print("%s: id=%d\n", __FUNCTION__, rx->id); + log_trace("%s: id=%d", __FUNCTION__, rx->id); sprintf(name, "receiver.%d.audio_channel", rx->id); value = getProperty(name); @@ -706,7 +707,7 @@ void reconfigure_receiver(RECEIVER *rx, int height) { if (rx->display_panadapter) { if (rx->panadapter == NULL) { - g_print("%s: panadapter_init: width:%d height:%d\n", __FUNCTION__, + log_trace("%s: panadapter_init: width:%d height:%d", __FUNCTION__, rx->width, myheight); rx_panadapter_init(rx, rx->width, myheight); gtk_fixed_put(GTK_FIXED(rx->panel), rx->panadapter, 0, @@ -728,14 +729,14 @@ void reconfigure_receiver(RECEIVER *rx, int height) { if (rx->display_waterfall) { if (rx->waterfall == NULL) { - g_print("%s: waterfall_init: width:%d height:%d\n", __FUNCTION__, + log_trace("%s: waterfall_init: width:%d height:%d", __FUNCTION__, rx->width, myheight); waterfall_init(rx, rx->width, myheight); gtk_fixed_put(GTK_FIXED(rx->panel), rx->waterfall, 0, y); // y=0 if ONLY waterfall is present } else { // set the size - g_print("%s: waterfall set_size_request: width:%d height:%d\n", + log_trace("%s: waterfall set_size_request: width:%d height:%d", __FUNCTION__, rx->width, myheight); gtk_widget_set_size_request(rx->waterfall, rx->width, myheight); // move the current one @@ -913,9 +914,6 @@ static void init_analyzer(RECEIVER *rx) { overlap = (int)fmax( 0.0, ceil(fft_size - (double)rx->sample_rate / (double)rx->fps)); - // g_print("%s: id=%d buffer_size=%d - // overlap=%d\n",_FUNCTION__,rx->id,rx->buffer_size,overlap); - SetAnalyzer( rx->id, n_pixout, spur_elimination_ffts, // number of LO frequencies = number of ffts used @@ -950,7 +948,7 @@ static void create_visual(RECEIVER *rx) { int y = 0; rx->panel = gtk_fixed_new(); - g_print("%s: id=%d width=%d height=%d %p\n", __FUNCTION__, rx->id, + log_debug("%s: id=%d width=%d height=%d %p", __FUNCTION__, rx->id, rx->width, rx->height, rx->panel); g_object_weak_ref(G_OBJECT(rx->panel), receiver_weak_notify, (gpointer)rx); gtk_widget_set_size_request(rx->panel, rx->width, rx->height); @@ -964,7 +962,7 @@ static void create_visual(RECEIVER *rx) { } rx_panadapter_init(rx, rx->width, height); - g_print("%s: panadapter height=%d y=%d %p\n", __FUNCTION__, height, y, + log_debug("%s: panadapter height=%d y=%d %p", __FUNCTION__, height, y, rx->panadapter); g_object_weak_ref(G_OBJECT(rx->panadapter), receiver_weak_notify, (gpointer)rx); @@ -973,8 +971,8 @@ static void create_visual(RECEIVER *rx) { if (rx->display_waterfall) { waterfall_init(rx, rx->width, height); - g_print("%ss: waterfall height=%d y=%d %p\n", __FUNCTION__, height, y, - rx->waterfall); + log_debug("%ss: waterfall height=%d y=%d %p", __FUNCTION__, height, y, + rx->waterfall); g_object_weak_ref(G_OBJECT(rx->waterfall), receiver_weak_notify, (gpointer)rx); gtk_fixed_put(GTK_FIXED(rx->panel), rx->waterfall, 0, y); @@ -986,7 +984,7 @@ static void create_visual(RECEIVER *rx) { #ifdef PURESIGNAL RECEIVER *create_pure_signal_receiver(int id, int buffer_size, int sample_rate, int width) { - g_print("%s: id=%d buffer_size=%d\n", __FUNCTION__, id, buffer_size); + log_trace("%s: id=%d buffer_size=%d", __FUNCTION__, id, buffer_size); RECEIVER *rx = malloc(sizeof(RECEIVER)); rx->id = id; @@ -1104,8 +1102,8 @@ RECEIVER *create_pure_signal_receiver(int id, int buffer_size, int sample_rate, int result; XCreateAnalyzer(rx->id, &result, 262144, 1, 1, ""); if (result != 0) { - g_print("%s: XCreateAnalyzer id=%d failed: %d\n", __FUNCTION__, rx->id, - result); + log_error("%s: XCreateAnalyzer id=%d failed: %d", __FUNCTION__, rx->id, + result); } else { init_analyzer(rx); } @@ -1123,8 +1121,8 @@ RECEIVER *create_pure_signal_receiver(int id, int buffer_size, int sample_rate, RECEIVER *create_receiver(int id, int buffer_size, int fft_size, int pixels, int fps, int width, int height) { - g_print("%s: id=%d buffer_size=%d fft_size=%d pixels=%d fps=%d\n", - __FUNCTION__, id, buffer_size, fft_size, pixels, fps); + log_trace("%s: id=%d buffer_size=%d fft_size=%d pixels=%d fps=%d", + __FUNCTION__, id, buffer_size, fft_size, pixels, fps); RECEIVER *rx = malloc(sizeof(RECEIVER)); rx->id = id; g_mutex_init(&rx->mutex); @@ -1161,7 +1159,7 @@ RECEIVER *create_receiver(int id, int buffer_size, int fft_size, int pixels, break; } } - g_print("%s: id=%d default adc=%d\n", __FUNCTION__, rx->id, rx->adc); + log_trace("%s: id=%d default adc=%d", __FUNCTION__, rx->id, rx->adc); rx->sample_rate = 48000; rx->buffer_size = buffer_size; rx->fft_size = fft_size; @@ -1262,23 +1260,23 @@ RECEIVER *create_receiver(int id, int buffer_size, int fft_size, int pixels, rx->pixels = pixels * rx->zoom; rx->pixel_samples = g_new(float, rx->pixels); - g_print( - "%s (after restore): rx=%p id=%d audio_buffer_size=%d local_audio=%d\n", + log_trace( + "%s (after restore): rx=%p id=%d audio_buffer_size=%d local_audio=%d", __FUNCTION__, rx, rx->id, rx->audio_buffer_size, rx->local_audio); int scale = rx->sample_rate / 48000; rx->output_samples = rx->buffer_size / scale; rx->audio_output_buffer = g_new(gdouble, 2 * rx->output_samples); - g_print("%s: id=%d output_samples=%d audio_output_buffer=%p\n", + log_trace("%s: id=%d output_samples=%d audio_output_buffer=%p", __FUNCTION__, rx->id, rx->output_samples, rx->audio_output_buffer); rx->hz_per_pixel = (double)rx->sample_rate / (double)rx->pixels; // setup wdsp for this receiver - g_print("%s: id=%d after restore adc=%d\n", __FUNCTION__, rx->id, rx->adc); + log_trace("%s: id=%d after restore adc=%d", __FUNCTION__, rx->id, rx->adc); - g_print("%s: OpenChannel id=%d buffer_size=%d fft_size=%d sample_rate=%d\n", + log_trace("%s: OpenChannel id=%d buffer_size=%d fft_size=%d sample_rate=%d", __FUNCTION__, rx->id, rx->buffer_size, rx->fft_size, rx->sample_rate); OpenChannel(rx->id, rx->buffer_size, rx->fft_size, rx->sample_rate, @@ -1348,8 +1346,8 @@ RECEIVER *create_receiver(int id, int buffer_size, int fft_size, int pixels, int result; XCreateAnalyzer(rx->id, &result, 262144, 1, 1, ""); if (result != 0) { - g_print("%s: XCreateAnalyzer id=%d failed: %d\n", __FUNCTION__, rx->id, - result); + log_error("%s: XCreateAnalyzer id=%d failed: %d", __FUNCTION__, rx->id, + result); } else { init_analyzer(rx); } @@ -1361,7 +1359,7 @@ RECEIVER *create_receiver(int id, int buffer_size, int fft_size, int pixels, create_visual(rx); - g_print("%s: rx=%p id=%d local_audio=%d\n", __FUNCTION__, rx, rx->id, + log_trace("%s: rx=%p id=%d local_audio=%d", __FUNCTION__, rx, rx->id, rx->local_audio); if (rx->local_audio) { if (audio_open_output(rx) < 0) { @@ -1390,7 +1388,7 @@ void receiver_change_sample_rate(RECEIVER *rx, int sample_rate) { rx->output_samples = rx->buffer_size / scale; rx->hz_per_pixel = (double)rx->sample_rate / (double)rx->width; - g_print("%s: id=%d rate=%d scale=%d buffer_size=%d output_samples=%d\n", + log_trace("%s: id=%d rate=%d scale=%d buffer_size=%d output_samples=%d", __FUNCTION__, rx->id, sample_rate, scale, rx->buffer_size, rx->output_samples); #ifdef PURESIGNAL @@ -1406,8 +1404,8 @@ void receiver_change_sample_rate(RECEIVER *rx, int sample_rate) { g_free(rx->pixel_samples); rx->pixel_samples = g_new(float, rx->pixels); init_analyzer(rx); - g_print("%s: PS FEEDBACK: id=%d rate=%d buffer_size=%d " - "output_samples=%d\n", + log_trace("%s: PS FEEDBACK: id=%d rate=%d buffer_size=%d " + "output_samples=%d", __FUNCTION__, rx->id, rx->sample_rate, rx->buffer_size, rx->output_samples); g_mutex_unlock(&rx->mutex); @@ -1430,9 +1428,9 @@ void receiver_change_sample_rate(RECEIVER *rx, int sample_rate) { g_mutex_unlock(&rx->mutex); - g_print("%s: id=%d rate=%d buffer_size=%d output_samples=%d\n", - __FUNCTION__, rx->id, rx->sample_rate, rx->buffer_size, - rx->output_samples); + log_trace("%s: id=%d rate=%d buffer_size=%d output_samples=%d", + __FUNCTION__, rx->id, rx->sample_rate, rx->buffer_size, + rx->output_samples); } void receiver_frequency_changed(RECEIVER *rx) { @@ -1523,9 +1521,6 @@ static void process_rx_buffer(RECEIVER *rx) { short left_audio_sample, right_audio_sample; int i; - // g_print("%s: rx=%p id=%d output_samples=%d - // audio_output_buffer=%p\n",__FUNCTION__,rx,rx->id,rx->output_samples,rx->audio_output_buffer); - for (i = 0; i < rx->output_samples; i++) { if (isTransmitting() && (!duplex || mute_rx_while_transmitting)) { left_sample = 0.0; @@ -1611,7 +1606,6 @@ static void process_rx_buffer(RECEIVER *rx) { void full_rx_buffer(RECEIVER *rx) { int error; - // g_print("%s: rx=%p\n",__FUNCTION__,rx); g_mutex_lock(&rx->mutex); // noise blanker works on original IQ samples diff --git a/rigctl_menu.c b/rigctl_menu.c index d036fb4..b4f0370 100644 --- a/rigctl_menu.c +++ b/rigctl_menu.c @@ -31,6 +31,7 @@ #include "band.h" #include "radio.h" #include "vfo.h" +#include "log.h" gboolean serial_enable = TRUE; // edit (enable serial at startup) char ser_port[64]="/dev/ttyACM0"; @@ -93,7 +94,7 @@ static void serial_enable_cb(GtkWidget *widget, gpointer data) { // Set Baud Rate static void baud_rate_cb(GtkWidget *widget, gpointer data) { serial_baud_rate = GPOINTER_TO_INT(data); - fprintf(stderr,"RIGCTL_MENU: Baud rate changed: %d\n",serial_baud_rate); + log_trace("RIGCTL_MENU: Baud rate changed: %d",serial_baud_rate); } void rigctl_menu(GtkWidget *parent) { diff --git a/rx_menu.c b/rx_menu.c index b53e846..fb15bf1 100644 --- a/rx_menu.c +++ b/rx_menu.c @@ -34,6 +34,7 @@ #include "receiver.h" #include "rx_menu.h" #include "sliders.h" +#include "log.h" static GtkWidget *parent_window = NULL; static GtkWidget *dialog = NULL; @@ -101,7 +102,7 @@ static void adc_cb(GtkToggleButton *widget, gpointer data) { } static void local_audio_cb(GtkWidget *widget, gpointer data) { - fprintf(stderr, "local_audio_cb: rx=%d\n", active_receiver->id); + log_trace("local_audio_cb: rx=%d", active_receiver->id); if (active_receiver->audio_name != NULL) { g_free(active_receiver->audio_name); @@ -117,7 +118,7 @@ static void local_audio_cb(GtkWidget *widget, gpointer data) { if (audio_open_output(active_receiver) == 0) { active_receiver->local_audio = 1; } else { - fprintf(stderr, "local_audio_cb: audio_open_output failed\n"); + log_error("local_audio_cb: audio_open_output failed"); active_receiver->local_audio = 0; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE); } @@ -127,7 +128,7 @@ static void local_audio_cb(GtkWidget *widget, gpointer data) { audio_close_output(active_receiver); } } - fprintf(stderr, "local_audio_cb: local_audio=%d\n", + log_trace("local_audio_cb: local_audio=%d", active_receiver->local_audio); } @@ -147,7 +148,7 @@ static void mute_radio_cb(GtkWidget *widget, gpointer data) { // static void local_output_changed_cb(GtkWidget *widget, gpointer data) { int i = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); - fprintf(stderr, "local_output_changed rx=%d %s\n", active_receiver->id, + log_trace("local_output_changed rx=%d %s", active_receiver->id, output_devices[i].name); if (active_receiver->local_audio) { audio_close_output(active_receiver); // audio_close with OLD device @@ -174,7 +175,7 @@ static void local_output_changed_cb(GtkWidget *widget, gpointer data) { FALSE); } } - fprintf(stderr, "local_output_changed rx=%d local_audio=%d\n", + log_trace("local_output_changed rx=%d local_audio=%d", active_receiver->id, active_receiver->local_audio); } @@ -214,7 +215,7 @@ void toggle_audio_output_device(void) { // set the other device as active if (audio_open_output(active_receiver) < 0) { - g_print("unable to open the audio output device: %s", active_receiver->audio_name); + log_error("unable to open the audio output device: %s", active_receiver->audio_name); } } diff --git a/sliders.c b/sliders.c index 8194f17..9b71c40 100644 --- a/sliders.c +++ b/sliders.c @@ -58,6 +58,7 @@ #include "client_server.h" #endif #include "actions.h" +#include "log.h" static int width; static int height; @@ -783,7 +784,7 @@ GtkWidget *sliders_init(int my_width, int my_height) { width=my_width; height=my_height; -fprintf(stderr,"sliders_init: width=%d height=%d\n", width,height); + log_trace("sliders_init: width=%d height=%d", width,height); sliders=gtk_grid_new(); gtk_widget_set_size_request (sliders, width, height); diff --git a/soundio.c b/soundio.c index c6c8b36..4b2e93d 100644 --- a/soundio.c +++ b/soundio.c @@ -36,6 +36,7 @@ #include "radio.h" #include "receiver.h" #include "audio.h" +#include "log.h" int audio = 0; int audio_buffer_size = 256; // samples (both left and right) @@ -88,7 +89,6 @@ static int remove_index=0; static int frames=0; static void write_callback(struct SoundIoOutStream *outstream, int frame_count_min, int frame_count_max) { -//fprintf(stderr,"write_callback: min=%d max=%d frames=%d insert_index=%d remove_index=%d\n",frame_count_min, frame_count_max, frames, insert_index, remove_index); double float_sample_rate = outstream->sample_rate; double seconds_per_frame = 1.0 / float_sample_rate; struct SoundIoChannelArea *areas; @@ -102,7 +102,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m frames_left=frame_count_max; } if ((err = soundio_outstream_begin_write(outstream, &areas, &frames_left))) { - fprintf(stderr, "unrecoverable stream error: %s\n", soundio_strerror(err)); + log_error("unrecoverable stream error: %s", soundio_strerror(err)); exit(1); } @@ -129,7 +129,7 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m if ((err = soundio_outstream_end_write(outstream))) { if (err == SoundIoErrorUnderflow) return; - fprintf(stderr, "unrecoverable stream error: %s\n", soundio_strerror(err)); + log_error("unrecoverable stream error: %s", soundio_strerror(err)); exit(1); } } else { @@ -143,14 +143,13 @@ static void underflow_callback(struct SoundIoOutStream *outstream) { } int audio_open_output(RECEIVER *rx) { - int err; -fprintf(stderr,"audio_open_output: id=%d device=%d\n", rx->id,rx->audio_device); + log_trace("audio_open_output: id=%d device=%d", rx->id,rx->audio_device); soundio = soundio_create(); if (!soundio) { - fprintf(stderr, "audio_open_output: soundio_create failed\n"); - return -1; + log_error("audio_open_output: soundio_create failed"); + return -1; } soundio_connect(soundio); @@ -159,13 +158,13 @@ fprintf(stderr,"audio_open_output: id=%d device=%d\n", rx->id,rx->audio_device); audio_device = soundio_get_output_device(soundio, rx->audio_device); if(!audio_device) { - fprintf(stderr, "audio_open_output: soundio_get_output_device failed\n"); + log_error("audio_open_output: soundio_get_output_device failed"); return -1; } if (audio_device->probe_error) { - fprintf(stderr, "audio_open_output: Cannot probe audio_device: %s\n", soundio_strerror(audio_device->probe_error)); - return -1; + log_error("audio_open_output: Cannot probe audio_device: %s", soundio_strerror(audio_device->probe_error)); + return -1; } outstream = soundio_outstream_create(audio_device); @@ -178,22 +177,22 @@ fprintf(stderr,"audio_open_output: id=%d device=%d\n", rx->id,rx->audio_device); if (soundio_device_supports_format(audio_device, SoundIoFormatS16LE)) { outstream->format = SoundIoFormatS16LE; } else { - fprintf(stderr,"audio_open_output: audio_device does not support S16LE\n"); + log_error("audio_open_output: audio_device does not support S16LE"); return -1; } if ((err = soundio_outstream_open(outstream))) { - fprintf(stderr, "audio_open_output: unable to open audio_device: %s", soundio_strerror(err)); + log_error("audio_open_output: unable to open audio_device: %s", soundio_strerror(err)); return -1; } - fprintf(stderr, "audio_open_output: Software latency: %f\n", outstream->software_latency); + log_trace("audio_open_output: Software latency: %f", outstream->software_latency); if (outstream->layout_error) { - fprintf(stderr, "audio_open_output: unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error)); + log_error("audio_open_output: unable to set channel layout: %s", soundio_strerror(outstream->layout_error)); } if ((err = soundio_outstream_start(outstream))) { - fprintf(stderr, "audio_open_output: unable to start audio_device: %s\n", soundio_strerror(err)); + log_error("audio_open_output: unable to start audio_device: %s", soundio_strerror(err)); return -1; } @@ -207,7 +206,7 @@ int audio_open_input() { int rate=48000; int dir=0; -fprintf(stderr,"audio_open_input: %d\n",n_selected_input_device); + fprintf(stderr,"audio_open_input: %d\n",n_selected_input_device); if(n_selected_input_device<0 || n_selected_input_device>=n_input_devices) { n_selected_input_device=-1; return -1; @@ -334,7 +333,6 @@ void audio_close_input() { } int audio_write(RECEIVER *rx,short left_sample,short right_sample) { -//fprintf(stderr,"audio_write: id=%d frames=%d insert_index=%d remove_index=%d\n",rx->id, frames, insert_index,remove_index); if(frames<(BUFFER_SIZE-2)) { output_left_buffer[insert_index]=left_sample; output_right_buffer[insert_index]=right_sample; @@ -344,7 +342,7 @@ int audio_write(RECEIVER *rx,short left_sample,short right_sample) { } frames++; } else { - fprintf(stderr,"audio_write: buffer_full: frames=%d insert_index-%d remove_index=%d\n",frames,insert_index,remove_index); + log_debug("audio_write: buffer_full: frames=%d insert_index-%d remove_index=%d",frames,insert_index,remove_index); } /* @@ -440,7 +438,7 @@ void audio_get_cards() { struct SoundIo *soundio = soundio_create(); if (!soundio) { - fprintf(stderr, "audio_get_cards: soundio_create failed\n"); + log_error("audio_get_cards: soundio_create failed"); return; } @@ -456,7 +454,7 @@ void audio_get_cards() { for(i=0;iid,device->name); + log_trace("output: %d: id=%s name=%s",i,device->id,device->name); char *device_id=malloc(64); strncpy(device_id,device->id,64); output_devices[i]=device_id; @@ -465,7 +463,7 @@ fprintf(stderr,"output: %d: id=%s name=%s\n",i,device->id,device->name); for(i=0;iid,device->name); + log_trace("input: %d: id=%s name=%s",i,device->id,device->name); char *device_id=malloc(64); strncpy(device_id,device->id,64); input_devices[i]=device_id; diff --git a/store.c b/store.c index a2bbc35..49f653b 100644 --- a/store.c +++ b/store.c @@ -31,7 +31,7 @@ #include "property.h" #include "store.h" #include "store_menu.h" - +#include "log.h" /* struct MEM { @@ -104,35 +104,35 @@ void memRestoreState() { mem[b].filter = filterF0; } - fprintf(stderr,"memRestoreState: restore memory\n"); + log_trace("memRestoreState: restore memory"); for(b=0;bid].mode; mem[index].filter=vfo[active_receiver->id].filter; - fprintf(stderr,"store_select_cb: Index=%d\n",index); - fprintf(stderr,"store_select_cb: freqA=%11lld\n",mem[index].frequency); - fprintf(stderr,"store_select_cb: mode=%d\n",mem[index].mode); - fprintf(stderr,"store_select_cb: filter=%d\n",mem[index].filter); + log_debug("store_select_cb: Index=%d",index); + log_debug("store_select_cb: freqA=%11lld",mem[index].frequency); + log_debug("store_select_cb: mode=%d",mem[index].mode); + log_debug("store_select_cb: filter=%d",mem[index].filter); sprintf(workstr,"M%d=%8.6f MHz", index,((double) mem[index].frequency)/1000000.0); gtk_button_set_label(GTK_BUTTON(store_button[index]),workstr); @@ -94,10 +95,10 @@ static gboolean recall_select_cb (GtkWidget *widget, gpointer data) { //new_freq = mem[index].frequency; strcpy(mem[index].title,"Active"); new_freq = mem[index].frequency; - fprintf(stderr,"recall_select_cb: Index=%d\n",index); - fprintf(stderr,"recall_select_cb: freqA=%11lld\n",new_freq); - fprintf(stderr,"recall_select_cb: mode=%d\n",mem[index].mode); - fprintf(stderr,"recall_select_cb: filter=%d\n",mem[index].filter); + log_debug("recall_select_cb: Index=%d",index); + log_debug("recall_select_cb: freqA=%11lld",new_freq); + log_debug("recall_select_cb: mode=%d",mem[index].mode); + log_debug("recall_select_cb: filter=%d",mem[index].filter); vfo[active_receiver->id].frequency = new_freq; vfo[active_receiver->id].band = get_band_from_frequency(new_freq); diff --git a/test_menu.c b/test_menu.c deleted file mode 100644 index cacf756..0000000 --- a/test_menu.c +++ /dev/null @@ -1,102 +0,0 @@ -/* Copyright (C) -* 2016 - John Melton, G0ORX/N6LYT -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* -*/ - -#include -#include -#include - -#include "new_menu.h" -#include "update.h" - -static GtkWidget *parent_window=NULL; - -static GtkWidget *dialog=NULL; - -static void cleanup() { - if(dialog!=NULL) { - gtk_widget_destroy(dialog); - dialog=NULL; - sub_menu=NULL; - } -} - -static gboolean close_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { - cleanup(); - return TRUE; -} - -static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) { - cleanup(); - return FALSE; -} - -static gboolean test_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { - - int result=check_update(); - fprintf(stderr,"check_update returned %d\n",result); - - if(result>0) { - result=load_update(); - fprintf(stderr,"load_update returned %d\n",result); - } - - return TRUE; -} - -void test_menu(GtkWidget *parent) { - - parent_window=parent; - - dialog=gtk_dialog_new(); - gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parent_window)); - //gtk_window_set_decorated(GTK_WINDOW(dialog),FALSE); - gtk_window_set_title(GTK_WINDOW(dialog),"piHPSDR - Test"); - g_signal_connect (dialog, "delete_event", G_CALLBACK (delete_event), NULL); - - GdkRGBA color; - color.red = 1.0; - color.green = 1.0; - color.blue = 1.0; - color.alpha = 1.0; - gtk_widget_override_background_color(dialog,GTK_STATE_FLAG_NORMAL,&color); - - GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - - GtkWidget *grid=gtk_grid_new(); - - gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE); - gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE); - gtk_grid_set_column_spacing (GTK_GRID(grid),5); - gtk_grid_set_row_spacing (GTK_GRID(grid),5); - - GtkWidget *close_b=gtk_button_new_with_label("Close"); - g_signal_connect (close_b, "pressed", G_CALLBACK(close_cb), NULL); - gtk_grid_attach(GTK_GRID(grid),close_b,0,0,1,1); - - GtkWidget *test_b=gtk_button_new_with_label("Test"); - g_signal_connect (test_b, "pressed", G_CALLBACK(test_cb), NULL); - gtk_grid_attach(GTK_GRID(grid),test_b,0,1,1,1); - - gtk_container_add(GTK_CONTAINER(content),grid); - - sub_menu=dialog; - - gtk_widget_show_all(dialog); - -} diff --git a/test_menu.h b/test_menu.h deleted file mode 100644 index 1a24455..0000000 --- a/test_menu.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) -* 2016 - John Melton, G0ORX/N6LYT -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* -*/ - -void test_menu(GtkWidget *parent); diff --git a/toolbar.c b/toolbar.c index 80ad892..9c01366 100644 --- a/toolbar.c +++ b/toolbar.c @@ -50,6 +50,7 @@ #ifdef CLIENT_SERVER #include "client_server.h" #endif +#include "log.h" int function=0; @@ -158,7 +159,6 @@ void mox_cb(GtkWidget *widget, gpointer data) { } void mox_update(int state) { -//fprintf(stderr,"mox_update: state=%d\n",state); if(getTune()==1) { setTune(0); } @@ -228,7 +228,7 @@ GtkWidget *toolbar_init(int my_width, int my_height, GtkWidget* parent) { int button_width=width/8; - fprintf(stderr,"toolbar_init: width=%d height=%d button_width=%d\n", width,height,button_width); + log_trace("toolbar_init: width=%d height=%d button_width=%d", width,height,button_width); white.red=1.0; white.green=1.0; diff --git a/transmitter.c b/transmitter.c index c573a52..eb74d51 100644 --- a/transmitter.c +++ b/transmitter.c @@ -1,73 +1,73 @@ /* Copyright (C) -* 2017 - John Melton, G0ORX/N6LYT -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* -*/ + * 2017 - John Melton, G0ORX/N6LYT + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include +#include #include #include -#include #include #include "alex.h" +#include "audio.h" #include "band.h" #include "bandstack.h" #include "channel.h" +#include "ext.h" +#include "filter.h" +#include "log.h" #include "main.h" -#include "receiver.h" #include "meter.h" -#include "filter.h" #include "mode.h" +#include "new_protocol.h" +#include "old_protocol.h" #include "property.h" #include "radio.h" -#include "vfo.h" -#include "vox.h" -#include "meter.h" +#include "receiver.h" #include "toolbar.h" +#include "transmitter.h" #include "tx_panadapter.h" +#include "vfo.h" +#include "vox.h" #include "waterfall.h" -#include "receiver.h" -#include "transmitter.h" -#include "new_protocol.h" -#include "old_protocol.h" -#include "audio.h" -#include "ext.h" double getNextSideToneSample(); double getNextInternalSideToneSample(); -#define min(x,y) (xout_of_band=0; - g_idle_add(ext_vfo_update,NULL); - return FALSE; + TRANSMITTER *tx = (TRANSMITTER *)data; + tx->out_of_band = 0; + g_idle_add(ext_vfo_update, NULL); + return FALSE; } void transmitter_set_out_of_band(TRANSMITTER *tx) { - tx->out_of_band=1; - g_idle_add(ext_vfo_update,NULL); - tx->out_of_band_timer_id=gdk_threads_add_timeout_full(G_PRIORITY_HIGH_IDLE,1000,update_out_of_band, tx, NULL); + tx->out_of_band = 1; + g_idle_add(ext_vfo_update, NULL); + tx->out_of_band_timer_id = gdk_threads_add_timeout_full( + G_PRIORITY_HIGH_IDLE, 1000, update_out_of_band, tx, NULL); } void transmitter_set_deviation(TRANSMITTER *tx) { - SetTXAFMDeviation(tx->id, (double)tx->deviation); + SetTXAFMDeviation(tx->id, (double)tx->deviation); } void transmitter_set_am_carrier_level(TRANSMITTER *tx) { - SetTXAAMCarrierLevel(tx->id, tx->am_carrier_level); + SetTXAAMCarrierLevel(tx->id, tx->am_carrier_level); } -void transmitter_set_ctcss(TRANSMITTER *tx,int state,int i) { -g_print("transmitter_set_ctcss: state=%d i=%d frequency=%0.1f\n",state,i,ctcss_frequencies[i]); - tx->ctcss_enabled=state; - tx->ctcss=i; - SetTXACTCSSFreq(tx->id, ctcss_frequencies[tx->ctcss]); - SetTXACTCSSRun(tx->id, tx->ctcss_enabled); +void transmitter_set_ctcss(TRANSMITTER *tx, int state, int i) { + log_trace("transmitter_set_ctcss: state=%d i=%d frequency=%0.1f", state, i, + ctcss_frequencies[i]); + tx->ctcss_enabled = state; + tx->ctcss = i; + SetTXACTCSSFreq(tx->id, ctcss_frequencies[tx->ctcss]); + SetTXACTCSSRun(tx->id, tx->ctcss_enabled); } -void transmitter_set_compressor_level(TRANSMITTER *tx,double level) { - tx->compressor_level=level; - SetTXACompressorGain(tx->id, tx->compressor_level); +void transmitter_set_compressor_level(TRANSMITTER *tx, double level) { + tx->compressor_level = level; + SetTXACompressorGain(tx->id, tx->compressor_level); } -void transmitter_set_compressor(TRANSMITTER *tx,int state) { - tx->compressor=state; - SetTXACompressorRun(tx->id, tx->compressor); +void transmitter_set_compressor(TRANSMITTER *tx, int state) { + tx->compressor = state; + SetTXACompressorRun(tx->id, tx->compressor); } -void reconfigure_transmitter(TRANSMITTER *tx,int width,int height) { -g_print("reconfigure_transmitter: width=%d height=%d\n",width,height); - if(width!=tx->width) { - tx->width=width; - tx->height=height; - int ratio=tx->iq_output_rate/tx->mic_sample_rate; - tx->pixels=display_width*ratio*2; - g_free(tx->pixel_samples); - tx->pixel_samples=g_new(float,tx->pixels); - init_analyzer(tx); - } - gtk_widget_set_size_request(tx->panadapter, width, height); +void reconfigure_transmitter(TRANSMITTER *tx, int width, int height) { + log_trace("reconfigure_transmitter: width=%d height=%d", width, height); + if (width != tx->width) { + tx->width = width; + tx->height = height; + int ratio = tx->iq_output_rate / tx->mic_sample_rate; + tx->pixels = display_width * ratio * 2; + g_free(tx->pixel_samples); + tx->pixel_samples = g_new(float, tx->pixels); + init_analyzer(tx); + } + gtk_widget_set_size_request(tx->panadapter, width, height); } void transmitter_save_state(TRANSMITTER *tx) { - char name[128]; - char value[128]; - - sprintf(name,"transmitter.%d.fps",tx->id); - sprintf(value,"%d",tx->fps); - setProperty(name,value); - sprintf(name,"transmitter.%d.filter_low",tx->id); - sprintf(value,"%d",tx->filter_low); - setProperty(name,value); - sprintf(name,"transmitter.%d.filter_high",tx->id); - sprintf(value,"%d",tx->filter_high); - setProperty(name,value); - sprintf(name,"transmitter.%d.use_rx_filter",tx->id); - sprintf(value,"%d",tx->use_rx_filter); - setProperty(name,value); - sprintf(name,"transmitter.%d.alex_antenna",tx->id); - sprintf(value,"%d",tx->alex_antenna); - setProperty(name,value); - - sprintf(name,"transmitter.%d.panadapter_low",tx->id); - sprintf(value,"%d",tx->panadapter_low); - setProperty(name,value); - sprintf(name,"transmitter.%d.panadapter_high",tx->id); - sprintf(value,"%d",tx->panadapter_high); - setProperty(name,value); - - sprintf(name,"transmitter.%d.local_microphone",tx->id); - sprintf(value,"%d",tx->local_microphone); - setProperty(name,value); - if(tx->microphone_name!=NULL) { - sprintf(name,"transmitter.%d.microphone_name",tx->id); - sprintf(value,"%s",tx->microphone_name); - setProperty(name,value); - } - sprintf(name,"transmitter.%d.low_latency",tx->id); - sprintf(value,"%d",tx->low_latency); - setProperty(name,value); + char name[128]; + char value[128]; + + sprintf(name, "transmitter.%d.fps", tx->id); + sprintf(value, "%d", tx->fps); + setProperty(name, value); + sprintf(name, "transmitter.%d.filter_low", tx->id); + sprintf(value, "%d", tx->filter_low); + setProperty(name, value); + sprintf(name, "transmitter.%d.filter_high", tx->id); + sprintf(value, "%d", tx->filter_high); + setProperty(name, value); + sprintf(name, "transmitter.%d.use_rx_filter", tx->id); + sprintf(value, "%d", tx->use_rx_filter); + setProperty(name, value); + sprintf(name, "transmitter.%d.alex_antenna", tx->id); + sprintf(value, "%d", tx->alex_antenna); + setProperty(name, value); + + sprintf(name, "transmitter.%d.panadapter_low", tx->id); + sprintf(value, "%d", tx->panadapter_low); + setProperty(name, value); + sprintf(name, "transmitter.%d.panadapter_high", tx->id); + sprintf(value, "%d", tx->panadapter_high); + setProperty(name, value); + + sprintf(name, "transmitter.%d.local_microphone", tx->id); + sprintf(value, "%d", tx->local_microphone); + setProperty(name, value); + if (tx->microphone_name != NULL) { + sprintf(name, "transmitter.%d.microphone_name", tx->id); + sprintf(value, "%s", tx->microphone_name); + setProperty(name, value); + } + sprintf(name, "transmitter.%d.low_latency", tx->id); + sprintf(value, "%d", tx->low_latency); + setProperty(name, value); #ifdef PURESIGNAL - sprintf(name,"transmitter.%d.puresignal",tx->id); - sprintf(value,"%d",tx->puresignal); - setProperty(name,value); - sprintf(name,"transmitter.%d.auto_on",tx->id); - sprintf(value,"%d",tx->auto_on); - setProperty(name,value); - sprintf(name,"transmitter.%d.single_on",tx->id); - sprintf(value,"%d",tx->single_on); - setProperty(name,value); - sprintf(name,"transmitter.%d.feedback",tx->id); - sprintf(value,"%d",tx->feedback); - setProperty(name,value); - sprintf(name,"transmitter.%d.attenuation",tx->id); - sprintf(value,"%d",tx->attenuation); - setProperty(name,value); + sprintf(name, "transmitter.%d.puresignal", tx->id); + sprintf(value, "%d", tx->puresignal); + setProperty(name, value); + sprintf(name, "transmitter.%d.auto_on", tx->id); + sprintf(value, "%d", tx->auto_on); + setProperty(name, value); + sprintf(name, "transmitter.%d.single_on", tx->id); + sprintf(value, "%d", tx->single_on); + setProperty(name, value); + sprintf(name, "transmitter.%d.feedback", tx->id); + sprintf(value, "%d", tx->feedback); + setProperty(name, value); + sprintf(name, "transmitter.%d.attenuation", tx->id); + sprintf(value, "%d", tx->attenuation); + setProperty(name, value); #endif - sprintf(name,"transmitter.%d.ctcss_enabled",tx->id); - sprintf(value,"%d",tx->ctcss_enabled); - setProperty(name,value); - sprintf(name,"transmitter.%d.ctcss",tx->id); - sprintf(value,"%d",tx->ctcss); - setProperty(name,value); - sprintf(name,"transmitter.%d.deviation",tx->id); - sprintf(value,"%d",tx->deviation); - setProperty(name,value); - sprintf(name,"transmitter.%d.am_carrier_level",tx->id); - sprintf(value,"%f",tx->am_carrier_level); - setProperty(name,value); - sprintf(name,"transmitter.%d.drive",tx->id); - sprintf(value,"%d",tx->drive); - setProperty(name,value); - sprintf(name,"transmitter.%d.tune_percent",tx->id); - sprintf(value,"%d",tx->tune_percent); - setProperty(name,value); - sprintf(name,"transmitter.%d.tune_use_drive",tx->id); - sprintf(value,"%d",tx->tune_use_drive); - setProperty(name,value); - sprintf(name,"transmitter.%d.drive_level",tx->id); - sprintf(value,"%d",tx->drive_level); - setProperty(name,value); - sprintf(name,"transmitter.%d.compressor",tx->id); - sprintf(value,"%d",tx->compressor); - setProperty(name,value); - sprintf(name,"transmitter.%d.compressor_level",tx->id); - sprintf(value,"%f",tx->compressor_level); - setProperty(name,value); - sprintf(name,"transmitter.%d.xit_enabled",tx->id); - sprintf(value,"%d",tx->xit_enabled); - setProperty(name,value); - sprintf(name,"transmitter.%d.xit",tx->id); - sprintf(value,"%lld",tx->xit); - setProperty(name,value); - - sprintf(name,"transmitter.%d.dialog_x",tx->id); - sprintf(value,"%d",tx->dialog_x); - setProperty(name,value); - sprintf(name,"transmitter.%d.dialog_y",tx->id); - sprintf(value,"%d",tx->dialog_y); - setProperty(name,value); + sprintf(name, "transmitter.%d.ctcss_enabled", tx->id); + sprintf(value, "%d", tx->ctcss_enabled); + setProperty(name, value); + sprintf(name, "transmitter.%d.ctcss", tx->id); + sprintf(value, "%d", tx->ctcss); + setProperty(name, value); + sprintf(name, "transmitter.%d.deviation", tx->id); + sprintf(value, "%d", tx->deviation); + setProperty(name, value); + sprintf(name, "transmitter.%d.am_carrier_level", tx->id); + sprintf(value, "%f", tx->am_carrier_level); + setProperty(name, value); + sprintf(name, "transmitter.%d.drive", tx->id); + sprintf(value, "%d", tx->drive); + setProperty(name, value); + sprintf(name, "transmitter.%d.tune_percent", tx->id); + sprintf(value, "%d", tx->tune_percent); + setProperty(name, value); + sprintf(name, "transmitter.%d.tune_use_drive", tx->id); + sprintf(value, "%d", tx->tune_use_drive); + setProperty(name, value); + sprintf(name, "transmitter.%d.drive_level", tx->id); + sprintf(value, "%d", tx->drive_level); + setProperty(name, value); + sprintf(name, "transmitter.%d.compressor", tx->id); + sprintf(value, "%d", tx->compressor); + setProperty(name, value); + sprintf(name, "transmitter.%d.compressor_level", tx->id); + sprintf(value, "%f", tx->compressor_level); + setProperty(name, value); + sprintf(name, "transmitter.%d.xit_enabled", tx->id); + sprintf(value, "%d", tx->xit_enabled); + setProperty(name, value); + sprintf(name, "transmitter.%d.xit", tx->id); + sprintf(value, "%lld", tx->xit); + setProperty(name, value); + + sprintf(name, "transmitter.%d.dialog_x", tx->id); + sprintf(value, "%d", tx->dialog_x); + setProperty(name, value); + sprintf(name, "transmitter.%d.dialog_y", tx->id); + sprintf(value, "%d", tx->dialog_y); + setProperty(name, value); } void transmitter_restore_state(TRANSMITTER *tx) { - char name[128]; - char *value; - - sprintf(name,"transmitter.%d.fps",tx->id); - value=getProperty(name); - if(value) tx->fps=atoi(value); - sprintf(name,"transmitter.%d.filter_low",tx->id); - value=getProperty(name); - if(value) tx->filter_low=atoi(value); - sprintf(name,"transmitter.%d.filter_high",tx->id); - value=getProperty(name); - if(value) tx->filter_high=atoi(value); - sprintf(name,"transmitter.%d.use_rx_filter",tx->id); - value=getProperty(name); - if(value) tx->use_rx_filter=atoi(value); - sprintf(name,"transmitter.%d.alex_antenna",tx->id); - value=getProperty(name); - if(value) tx->alex_antenna=atoi(value); - - sprintf(name,"transmitter.%d.panadapter_low",tx->id); - value=getProperty(name); - if(value) tx->panadapter_low=atoi(value); - sprintf(name,"transmitter.%d.panadapter_high",tx->id); - value=getProperty(name); - if(value) tx->panadapter_high=atoi(value); - - sprintf(name,"transmitter.%d.local_microphone",tx->id); - value=getProperty(name); - if(value) tx->local_microphone=atoi(value); - sprintf(name,"transmitter.%d.microphone_name",tx->id); - value=getProperty(name); - if(value) { - tx->microphone_name=g_new(gchar,strlen(value)+1); - strcpy(tx->microphone_name,value); - } - sprintf(name,"transmitter.%d.low_latency",tx->id); - value=getProperty(name); - if(value) tx->low_latency=atoi(value); + char name[128]; + char *value; + + sprintf(name, "transmitter.%d.fps", tx->id); + value = getProperty(name); + if (value) + tx->fps = atoi(value); + sprintf(name, "transmitter.%d.filter_low", tx->id); + value = getProperty(name); + if (value) + tx->filter_low = atoi(value); + sprintf(name, "transmitter.%d.filter_high", tx->id); + value = getProperty(name); + if (value) + tx->filter_high = atoi(value); + sprintf(name, "transmitter.%d.use_rx_filter", tx->id); + value = getProperty(name); + if (value) + tx->use_rx_filter = atoi(value); + sprintf(name, "transmitter.%d.alex_antenna", tx->id); + value = getProperty(name); + if (value) + tx->alex_antenna = atoi(value); + + sprintf(name, "transmitter.%d.panadapter_low", tx->id); + value = getProperty(name); + if (value) + tx->panadapter_low = atoi(value); + sprintf(name, "transmitter.%d.panadapter_high", tx->id); + value = getProperty(name); + if (value) + tx->panadapter_high = atoi(value); + + sprintf(name, "transmitter.%d.local_microphone", tx->id); + value = getProperty(name); + if (value) + tx->local_microphone = atoi(value); + sprintf(name, "transmitter.%d.microphone_name", tx->id); + value = getProperty(name); + if (value) { + tx->microphone_name = g_new(gchar, strlen(value) + 1); + strcpy(tx->microphone_name, value); + } + sprintf(name, "transmitter.%d.low_latency", tx->id); + value = getProperty(name); + if (value) + tx->low_latency = atoi(value); #ifdef PURESIGNAL - sprintf(name,"transmitter.%d.puresignal",tx->id); - value=getProperty(name); - if(value) tx->puresignal=atoi(value); - sprintf(name,"transmitter.%d.auto_on",tx->id); - value=getProperty(name); - if(value) tx->auto_on=atoi(value); - sprintf(name,"transmitter.%d.single_on",tx->id); - value=getProperty(name); - if(value) tx->single_on=atoi(value); - sprintf(name,"transmitter.%d.feedback",tx->id); - value=getProperty(name); - if(value) tx->feedback=atoi(value); - sprintf(name,"transmitter.%d.attenuation",tx->id); - value=getProperty(name); - if(value) tx->attenuation=atoi(value); + sprintf(name, "transmitter.%d.puresignal", tx->id); + value = getProperty(name); + if (value) + tx->puresignal = atoi(value); + sprintf(name, "transmitter.%d.auto_on", tx->id); + value = getProperty(name); + if (value) + tx->auto_on = atoi(value); + sprintf(name, "transmitter.%d.single_on", tx->id); + value = getProperty(name); + if (value) + tx->single_on = atoi(value); + sprintf(name, "transmitter.%d.feedback", tx->id); + value = getProperty(name); + if (value) + tx->feedback = atoi(value); + sprintf(name, "transmitter.%d.attenuation", tx->id); + value = getProperty(name); + if (value) + tx->attenuation = atoi(value); #endif - sprintf(name,"transmitter.%d.ctcss_enabled",tx->id); - value=getProperty(name); - if(value) tx->ctcss_enabled=atoi(value); - sprintf(name,"transmitter.%d.ctcss",tx->id); - value=getProperty(name); - if(value) tx->ctcss=atoi(value); - sprintf(name,"transmitter.%d.deviation",tx->id); - value=getProperty(name); - if(value) tx->deviation=atoi(value); - sprintf(name,"transmitter.%d.am_carrier_level",tx->id); - value=getProperty(name); - if(value) tx->am_carrier_level=atof(value); - sprintf(name,"transmitter.%d.drive",tx->id); - value=getProperty(name); - if(value) tx->drive=atoi(value); - sprintf(name,"transmitter.%d.tune_percent",tx->id); - value=getProperty(name); - if(value) tx->tune_percent=atoi(value); - sprintf(name,"transmitter.%d.tune_use_drive",tx->id); - value=getProperty(name); - if(value) tx->tune_use_drive=atoi(value); - sprintf(name,"transmitter.%d.drive_level",tx->id); - value=getProperty(name); - if(value) tx->drive_level=atoi(value); - sprintf(name,"transmitter.%d.compressor",tx->id); - value=getProperty(name); - if(value) tx->compressor=atoi(value); - sprintf(name,"transmitter.%d.compressor_level",tx->id); - value=getProperty(name); - if(value) tx->compressor_level=atof(value); - sprintf(name,"transmitter.%d.xit_enabled",tx->id); - value=getProperty(name); - if(value) tx->xit_enabled=atoi(value); - sprintf(name,"transmitter.%d.xit",tx->id); - value=getProperty(name); - if(value) tx->xit=atoll(value); - sprintf(name,"transmitter.%d.dialog_x",tx->id); - value=getProperty(name); - if(value) tx->dialog_x=atoi(value); - sprintf(name,"transmitter.%d.dialog_y",tx->id); - value=getProperty(name); - if(value) tx->dialog_y=atoi(value); + sprintf(name, "transmitter.%d.ctcss_enabled", tx->id); + value = getProperty(name); + if (value) + tx->ctcss_enabled = atoi(value); + sprintf(name, "transmitter.%d.ctcss", tx->id); + value = getProperty(name); + if (value) + tx->ctcss = atoi(value); + sprintf(name, "transmitter.%d.deviation", tx->id); + value = getProperty(name); + if (value) + tx->deviation = atoi(value); + sprintf(name, "transmitter.%d.am_carrier_level", tx->id); + value = getProperty(name); + if (value) + tx->am_carrier_level = atof(value); + sprintf(name, "transmitter.%d.drive", tx->id); + value = getProperty(name); + if (value) + tx->drive = atoi(value); + sprintf(name, "transmitter.%d.tune_percent", tx->id); + value = getProperty(name); + if (value) + tx->tune_percent = atoi(value); + sprintf(name, "transmitter.%d.tune_use_drive", tx->id); + value = getProperty(name); + if (value) + tx->tune_use_drive = atoi(value); + sprintf(name, "transmitter.%d.drive_level", tx->id); + value = getProperty(name); + if (value) + tx->drive_level = atoi(value); + sprintf(name, "transmitter.%d.compressor", tx->id); + value = getProperty(name); + if (value) + tx->compressor = atoi(value); + sprintf(name, "transmitter.%d.compressor_level", tx->id); + value = getProperty(name); + if (value) + tx->compressor_level = atof(value); + sprintf(name, "transmitter.%d.xit_enabled", tx->id); + value = getProperty(name); + if (value) + tx->xit_enabled = atoi(value); + sprintf(name, "transmitter.%d.xit", tx->id); + value = getProperty(name); + if (value) + tx->xit = atoll(value); + sprintf(name, "transmitter.%d.dialog_x", tx->id); + value = getProperty(name); + if (value) + tx->dialog_x = atoi(value); + sprintf(name, "transmitter.%d.dialog_y", tx->id); + value = getProperty(name); + if (value) + tx->dialog_y = atoi(value); } static double compute_power(double p) { - double interval=10.0; - switch(pa_power) { + double interval = 10.0; + switch (pa_power) { case PA_1W: - interval=100.0; // mW - break; + interval = 100.0; // mW + break; case PA_10W: - interval=1.0; // W - break; + interval = 1.0; // W + break; case PA_30W: - interval=3.0; // W - break; + interval = 3.0; // W + break; case PA_50W: - interval=5.0; // W - break; + interval = 5.0; // W + break; case PA_100W: - interval=10.0; // W - break; + interval = 10.0; // W + break; case PA_200W: - interval=20.0; // W - break; + interval = 20.0; // W + break; case PA_500W: - interval=50.0; // W - break; - } - int i=0; - if(p>(double)pa_trim[10]) { - i=9; - } else { - while(p>(double)pa_trim[i]) { - i++; + interval = 50.0; // W + break; + } + int i = 0; + if (p > (double)pa_trim[10]) { + i = 9; + } else { + while (p > (double)pa_trim[i]) { + i++; + } + if (i > 0) + i--; } - if(i>0) i--; - } - double frac = (p - (double)pa_trim[i]) / ((double)pa_trim[i + 1] - (double)pa_trim[i]); - return interval * ((1.0 - frac) * (double)i + frac * (double)(i + 1)); + double frac = (p - (double)pa_trim[i]) / + ((double)pa_trim[i + 1] - (double)pa_trim[i]); + return interval * ((1.0 - frac) * (double)i + frac * (double)(i + 1)); } static gboolean update_display(gpointer data) { - TRANSMITTER *tx=(TRANSMITTER *)data; - int rc; - -//fprintf(stderr,"update_display: tx id=%d\n",tx->id); - if(tx->displaying) { - // if "MON" button is active (tx->feedback is TRUE), - // then obtain spectrum pixels from PS_RX_FEEDBACK, - // that is, display the (attenuated) TX signal from the "antenna" - // - // POSSIBLE MISMATCH OF SAMPLE RATES IN ORIGINAL PROTOCOL: - // TX sample rate is fixed 48 kHz, but RX sample rate can be - // 2*, 4*, or even 8* larger. The analyzer has been set up to use - // more pixels in this case, so we just need to copy the - // inner part of the spectrum. - // If both spectra have the same number of pixels, this code - // just copies all of them - // + TRANSMITTER *tx = (TRANSMITTER *)data; + int rc; + + if (tx->displaying) { + // if "MON" button is active (tx->feedback is TRUE), + // then obtain spectrum pixels from PS_RX_FEEDBACK, + // that is, display the (attenuated) TX signal from the "antenna" + // + // POSSIBLE MISMATCH OF SAMPLE RATES IN ORIGINAL PROTOCOL: + // TX sample rate is fixed 48 kHz, but RX sample rate can be + // 2*, 4*, or even 8* larger. The analyzer has been set up to use + // more pixels in this case, so we just need to copy the + // inner part of the spectrum. + // If both spectra have the same number of pixels, this code + // just copies all of them + // #ifdef PURESIGNAL - if(tx->puresignal && tx->feedback) { - RECEIVER *rx_feedback=receiver[PS_RX_FEEDBACK]; - g_mutex_lock(&rx_feedback->mutex); - GetPixels(rx_feedback->id,0,rx_feedback->pixel_samples,&rc); - int full = rx_feedback->pixels; // number of pixels in the feedback spectrum - int width = tx->pixels; // number of pixels to copy from the feedback spectrum - int start = (full-width) /2; // Copy from start ... (end-1) - float *tfp=tx->pixel_samples; - float *rfp=rx_feedback->pixel_samples+start; - int i; - // - // The TX panadapter shows a RELATIVE signal strength. A CW or single-tone signal at - // full drive appears at 0dBm, the two peaks of a full-drive two-tone signal appear - // at -6 dBm each. THIS DOES NOT DEPEND ON THE POSITION OF THE DRIVE LEVEL SLIDER. - // The strength of the feedback signal, however, depends on the drive, on the PA and - // on the attenuation effective in the feedback path. - // We try to normalize the feeback signal such that is looks like a "normal" TX - // panadapter if the feedback is optimal for PURESIGNAL (that is, if the attenuation - // is optimal). The correction depends on the protocol (different peak levels in the TX - // feedback channel, old=0.407, new=0.2899, difference is 3 dB). - switch (protocol) { - case ORIGINAL_PROTOCOL: - for (i=0; imutex); - } else { + if (tx->puresignal && tx->feedback) { + RECEIVER *rx_feedback = receiver[PS_RX_FEEDBACK]; + g_mutex_lock(&rx_feedback->mutex); + GetPixels(rx_feedback->id, 0, rx_feedback->pixel_samples, &rc); + int full = + rx_feedback + ->pixels; // number of pixels in the feedback spectrum + int width = tx->pixels; // number of pixels to copy from the + // feedback spectrum + int start = (full - width) / 2; // Copy from start ... (end-1) + float *tfp = tx->pixel_samples; + float *rfp = rx_feedback->pixel_samples + start; + int i; + // + // The TX panadapter shows a RELATIVE signal strength. A CW or + // single-tone signal at full drive appears at 0dBm, the two peaks + // of a full-drive two-tone signal appear at -6 dBm each. THIS DOES + // NOT DEPEND ON THE POSITION OF THE DRIVE LEVEL SLIDER. The + // strength of the feedback signal, however, depends on the drive, + // on the PA and on the attenuation effective in the feedback path. + // We try to normalize the feeback signal such that is looks like a + // "normal" TX panadapter if the feedback is optimal for PURESIGNAL + // (that is, if the attenuation is optimal). The correction depends + // on the protocol (different peak levels in the TX feedback + // channel, old=0.407, new=0.2899, difference is 3 dB). + switch (protocol) { + case ORIGINAL_PROTOCOL: + for (i = 0; i < width; i++) { + *tfp++ = *rfp++ + 12.0; + } + break; + case NEW_PROTOCOL: + for (i = 0; i < width; i++) { + *tfp++ = *rfp++ + 15.0; + } + break; + default: + memcpy(tfp, rfp, width * sizeof(float)); + break; + } + g_mutex_unlock(&rx_feedback->mutex); + } else { #endif - GetPixels(tx->id,0,tx->pixel_samples,&rc); + GetPixels(tx->id, 0, tx->pixel_samples, &rc); #ifdef PURESIGNAL - } + } #endif - if(rc) { - tx_panadapter_update(tx); - } + if (rc) { + tx_panadapter_update(tx); + } - transmitter->alc=GetTXAMeter(tx->id, alc); - double constant1=3.3; - double constant2=0.095; - int fwd_cal_offset=6; + transmitter->alc = GetTXAMeter(tx->id, alc); + double constant1 = 3.3; + double constant2 = 0.095; + int fwd_cal_offset = 6; - int fwd_power; - int rev_power; - int ex_power; - double v1; + int fwd_power; + int rev_power; + int ex_power; + double v1; - fwd_power=alex_forward_power; - rev_power=alex_reverse_power; - if(device==DEVICE_HERMES_LITE || device==DEVICE_HERMES_LITE2) { - ex_power=0; - } else { - ex_power=exciter_power; - } - switch(protocol) { - case ORIGINAL_PROTOCOL: - switch(device) { - case DEVICE_METIS: - constant1=3.3; - constant2=0.09; - break; - case DEVICE_HERMES: - case DEVICE_ANGELIA: - constant1=3.3; - constant2=0.095; - break; - case DEVICE_ORION: - constant1=5.0; - constant2=0.108; - fwd_cal_offset=4; - break; - case DEVICE_ORION2: - constant1=5.0; - constant2=0.08; - fwd_cal_offset=18; - break; - case DEVICE_HERMES_LITE: - case DEVICE_HERMES_LITE2: - // possible reversed depending polarity of current sense transformer - if(rev_power>fwd_power) { - fwd_power=alex_reverse_power; - rev_power=alex_forward_power; - } - constant1=3.3; - constant2=1.4; - fwd_cal_offset=6; - break; + fwd_power = alex_forward_power; + rev_power = alex_reverse_power; + if (device == DEVICE_HERMES_LITE || device == DEVICE_HERMES_LITE2) { + ex_power = 0; + } else { + ex_power = exciter_power; } + switch (protocol) { + case ORIGINAL_PROTOCOL: + switch (device) { + case DEVICE_METIS: + constant1 = 3.3; + constant2 = 0.09; + break; + case DEVICE_HERMES: + case DEVICE_ANGELIA: + constant1 = 3.3; + constant2 = 0.095; + break; + case DEVICE_ORION: + constant1 = 5.0; + constant2 = 0.108; + fwd_cal_offset = 4; + break; + case DEVICE_ORION2: + constant1 = 5.0; + constant2 = 0.08; + fwd_cal_offset = 18; + break; + case DEVICE_HERMES_LITE: + case DEVICE_HERMES_LITE2: + // possible reversed depending polarity of current sense + // transformer + if (rev_power > fwd_power) { + fwd_power = alex_reverse_power; + rev_power = alex_forward_power; + } + constant1 = 3.3; + constant2 = 1.4; + fwd_cal_offset = 6; + break; + } - if(fwd_power==0) { - fwd_power=ex_power; - } - fwd_power=fwd_power-fwd_cal_offset; - v1=((double)fwd_power/4095.0)*constant1; - transmitter->fwd=(v1*v1)/constant2; + if (fwd_power == 0) { + fwd_power = ex_power; + } + fwd_power = fwd_power - fwd_cal_offset; + v1 = ((double)fwd_power / 4095.0) * constant1; + transmitter->fwd = (v1 * v1) / constant2; - if(device==DEVICE_HERMES_LITE || device==DEVICE_HERMES_LITE2) { - transmitter->exciter=0.0; - } else { - ex_power=ex_power-fwd_cal_offset; - v1=((double)ex_power/4095.0)*constant1; - transmitter->exciter=(v1*v1)/constant2; - } + if (device == DEVICE_HERMES_LITE || device == DEVICE_HERMES_LITE2) { + transmitter->exciter = 0.0; + } else { + ex_power = ex_power - fwd_cal_offset; + v1 = ((double)ex_power / 4095.0) * constant1; + transmitter->exciter = (v1 * v1) / constant2; + } - transmitter->rev=0.0; - if(fwd_power!=0) { - v1=((double)rev_power/4095.0)*constant1; - transmitter->rev=(v1*v1)/constant2; - } - break; - case NEW_PROTOCOL: - switch(device) { - case NEW_DEVICE_ATLAS: - constant1=3.3; - constant2=0.09; - break; - case NEW_DEVICE_HERMES: - constant1=3.3; - constant2=0.09; - break; - case NEW_DEVICE_HERMES2: - constant1=3.3; - constant2=0.095; - break; - case NEW_DEVICE_ANGELIA: - constant1=3.3; - constant2=0.095; - break; - case NEW_DEVICE_ORION: - constant1=5.0; - constant2=0.108; - fwd_cal_offset=4; - break; - case NEW_DEVICE_ORION2: - constant1=5.0; - constant2=0.08; - fwd_cal_offset=18; - break; - case NEW_DEVICE_HERMES_LITE: - case NEW_DEVICE_HERMES_LITE2: - constant1=3.3; - constant2=0.09; + transmitter->rev = 0.0; + if (fwd_power != 0) { + v1 = ((double)rev_power / 4095.0) * constant1; + transmitter->rev = (v1 * v1) / constant2; + } break; - } + case NEW_PROTOCOL: + switch (device) { + case NEW_DEVICE_ATLAS: + constant1 = 3.3; + constant2 = 0.09; + break; + case NEW_DEVICE_HERMES: + constant1 = 3.3; + constant2 = 0.09; + break; + case NEW_DEVICE_HERMES2: + constant1 = 3.3; + constant2 = 0.095; + break; + case NEW_DEVICE_ANGELIA: + constant1 = 3.3; + constant2 = 0.095; + break; + case NEW_DEVICE_ORION: + constant1 = 5.0; + constant2 = 0.108; + fwd_cal_offset = 4; + break; + case NEW_DEVICE_ORION2: + constant1 = 5.0; + constant2 = 0.08; + fwd_cal_offset = 18; + break; + case NEW_DEVICE_HERMES_LITE: + case NEW_DEVICE_HERMES_LITE2: + constant1 = 3.3; + constant2 = 0.09; + break; + } - fwd_power=alex_forward_power; - if(fwd_power==0) { - fwd_power=exciter_power; - } - fwd_power=fwd_power-fwd_cal_offset; - v1=((double)fwd_power/4095.0)*constant1; - transmitter->fwd=(v1*v1)/constant2; - - ex_power=exciter_power; - ex_power=ex_power-fwd_cal_offset; - v1=((double)ex_power/4095.0)*constant1; - transmitter->exciter=(v1*v1)/constant2; - - transmitter->rev=0.0; - if(alex_forward_power!=0) { - rev_power=alex_reverse_power; - v1=((double)rev_power/4095.0)*constant1; - transmitter->rev=(v1*v1)/constant2; + fwd_power = alex_forward_power; + if (fwd_power == 0) { + fwd_power = exciter_power; + } + fwd_power = fwd_power - fwd_cal_offset; + v1 = ((double)fwd_power / 4095.0) * constant1; + transmitter->fwd = (v1 * v1) / constant2; + + ex_power = exciter_power; + ex_power = ex_power - fwd_cal_offset; + v1 = ((double)ex_power / 4095.0) * constant1; + transmitter->exciter = (v1 * v1) / constant2; + + transmitter->rev = 0.0; + if (alex_forward_power != 0) { + rev_power = alex_reverse_power; + v1 = ((double)rev_power / 4095.0) * constant1; + transmitter->rev = (v1 * v1) / constant2; + } + break; } - break; - } + double fwd = compute_power(transmitter->fwd); + double rev = compute_power(transmitter->rev); - double fwd=compute_power(transmitter->fwd); - double rev=compute_power(transmitter->rev); - -//g_print("transmitter: meter_update: fwd:%f->%f rev:%f->%f ex_fwd=%d alex_fwd=%d alex_rev=%d\n",transmitter->fwd,fwd,transmitter->rev,rev,exciter_power,alex_forward_power,alex_reverse_power); + if (!duplex) { + meter_update(active_receiver, POWER, /*transmitter->*/ fwd, + /*transmitter->*/ rev, transmitter->exciter, + transmitter->alc); + } - if(!duplex) { - meter_update(active_receiver,POWER,/*transmitter->*/fwd,/*transmitter->*/rev,transmitter->exciter,transmitter->alc); + return TRUE; // keep going } - - return TRUE; // keep going - } - return FALSE; // no more timer events + return FALSE; // no more timer events } - static void init_analyzer(TRANSMITTER *tx) { int flp[] = {0}; double keep_time = 0.1; - int n_pixout=1; + int n_pixout = 1; int spur_elimination_ffts = 1; int data_type = 1; int fft_size = 8192; @@ -617,783 +652,831 @@ static void init_analyzer(TRANSMITTER *tx) { int clip = 0; int span_clip_l = 0; int span_clip_h = 0; - int pixels=tx->pixels; + int pixels = tx->pixels; int stitches = 1; int calibration_data_set = 0; double span_min_freq = 0.0; double span_max_freq = 0.0; - int max_w = fft_size + (int) min(keep_time * (double) tx->fps, keep_time * (double) fft_size * (double) tx->fps); - - overlap = (int)max(0.0, ceil(fft_size - (double)tx->mic_sample_rate / (double)tx->fps)); - - fprintf(stderr,"SetAnalyzer id=%d buffer_size=%d overlap=%d pixels=%d\n",tx->id,tx->output_samples,overlap,tx->pixels); - - - SetAnalyzer(tx->id, - n_pixout, - spur_elimination_ffts, //number of LO frequencies = number of ffts used in elimination - data_type, //0 for real input data (I only); 1 for complex input data (I & Q) - flp, //vector with one elt for each LO frequency, 1 if high-side LO, 0 otherwise - fft_size, //size of the fft, i.e., number of input samples - tx->output_samples, //number of samples transferred for each OpenBuffer()/CloseBuffer() - window_type, //integer specifying which window function to use - kaiser_pi, //PiAlpha parameter for Kaiser window - overlap, //number of samples each fft (other than the first) is to re-use from the previous - clip, //number of fft output bins to be clipped from EACH side of each sub-span - span_clip_l, //number of bins to clip from low end of entire span - span_clip_h, //number of bins to clip from high end of entire span - pixels, //number of pixel values to return. may be either <= or > number of bins - stitches, //number of sub-spans to concatenate to form a complete span - calibration_data_set, //identifier of which set of calibration data to use - span_min_freq, //frequency at first pixel value8192 - span_max_freq, //frequency at last pixel value - max_w //max samples to hold in input ring buffers + int max_w = + fft_size + (int)min(keep_time * (double)tx->fps, + keep_time * (double)fft_size * (double)tx->fps); + + overlap = (int)max( + 0.0, ceil(fft_size - (double)tx->mic_sample_rate / (double)tx->fps)); + + log_trace("SetAnalyzer id=%d buffer_size=%d overlap=%d pixels=%d", tx->id, + tx->output_samples, overlap, tx->pixels); + + SetAnalyzer( + tx->id, n_pixout, + spur_elimination_ffts, // number of LO frequencies = number of ffts used + // in elimination + data_type, // 0 for real input data (I only); 1 for complex input data + // (I & Q) + flp, // vector with one elt for each LO frequency, 1 if high-side LO, 0 + // otherwise + fft_size, // size of the fft, i.e., number of input samples + tx->output_samples, // number of samples transferred for each + // OpenBuffer()/CloseBuffer() + window_type, // integer specifying which window function to use + kaiser_pi, // PiAlpha parameter for Kaiser window + overlap, // number of samples each fft (other than the first) is to + // re-use from the previous + clip, // number of fft output bins to be clipped from EACH side of each + // sub-span + span_clip_l, // number of bins to clip from low end of entire span + span_clip_h, // number of bins to clip from high end of entire span + pixels, // number of pixel values to return. may be either <= or > + // number of bins + stitches, // number of sub-spans to concatenate to form a complete span + calibration_data_set, // identifier of which set of calibration data to + // use + span_min_freq, // frequency at first pixel value8192 + span_max_freq, // frequency at last pixel value + max_w // max samples to hold in input ring buffers ); - // - // This cannot be changed for the TX panel, - // use peak mode - // - SetDisplayDetectorMode(tx->id, 0, DETECTOR_MODE_PEAK); - SetDisplayAverageMode(tx->id, 0, AVERAGE_MODE_NONE); - + // + // This cannot be changed for the TX panel, + // use peak mode + // + SetDisplayDetectorMode(tx->id, 0, DETECTOR_MODE_PEAK); + SetDisplayAverageMode(tx->id, 0, AVERAGE_MODE_NONE); } void create_dialog(TRANSMITTER *tx) { -g_print("create_dialog\n"); - tx->dialog=gtk_dialog_new(); - gtk_window_set_transient_for(GTK_WINDOW(tx->dialog),GTK_WINDOW(top_window)); - gtk_window_set_title(GTK_WINDOW(tx->dialog),"TX"); - g_signal_connect (tx->dialog, "delete_event", G_CALLBACK (delete_event), NULL); - GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(tx->dialog)); -g_print("create_dialog: add tx->panel\n"); - gtk_widget_set_size_request (tx->panel, display_width/4, display_height/2); - gtk_container_add(GTK_CONTAINER(content),tx->panel); - - gtk_widget_add_events(tx->dialog, GDK_KEY_PRESS_MASK); - g_signal_connect(tx->dialog, "key_press_event", G_CALLBACK(keypress_cb), NULL); + tx->dialog = gtk_dialog_new(); + gtk_window_set_transient_for(GTK_WINDOW(tx->dialog), + GTK_WINDOW(top_window)); + gtk_window_set_title(GTK_WINDOW(tx->dialog), "TX"); + g_signal_connect(tx->dialog, "delete_event", G_CALLBACK(delete_event), + NULL); + GtkWidget *content = gtk_dialog_get_content_area(GTK_DIALOG(tx->dialog)); + gtk_widget_set_size_request(tx->panel, display_width / 4, + display_height / 2); + gtk_container_add(GTK_CONTAINER(content), tx->panel); + + gtk_widget_add_events(tx->dialog, GDK_KEY_PRESS_MASK); + g_signal_connect(tx->dialog, "key_press_event", G_CALLBACK(keypress_cb), + NULL); } static void create_visual(TRANSMITTER *tx) { - - fprintf(stderr,"transmitter: create_visual: id=%d width=%d height=%d\n",tx->id, tx->width,tx->height); - - tx->dialog=NULL; + log_trace("transmitter: create_visual: id=%d width=%d height=%d", tx->id, + tx->width, tx->height); - tx->panel=gtk_fixed_new(); - gtk_widget_set_size_request (tx->panel, tx->width, tx->height); + tx->dialog = NULL; - if(tx->display_panadapter) { - tx_panadapter_init(tx,tx->width,tx->height); - gtk_fixed_put(GTK_FIXED(tx->panel),tx->panadapter,0,0); - } + tx->panel = gtk_fixed_new(); + gtk_widget_set_size_request(tx->panel, tx->width, tx->height); - gtk_widget_show_all(tx->panel); - g_object_ref((gpointer)tx->panel); + if (tx->display_panadapter) { + tx_panadapter_init(tx, tx->width, tx->height); + gtk_fixed_put(GTK_FIXED(tx->panel), tx->panadapter, 0, 0); + } - if(duplex) { - create_dialog(tx); - } + gtk_widget_show_all(tx->panel); + g_object_ref((gpointer)tx->panel); + if (duplex) { + create_dialog(tx); + } } -TRANSMITTER *create_transmitter(int id, int buffer_size, int fft_size, int fps, int width, int height) { - int rc; +TRANSMITTER *create_transmitter(int id, int buffer_size, int fft_size, int fps, + int width, int height) { + int rc; - TRANSMITTER *tx=g_new(TRANSMITTER,1); - tx->id=id; - tx->dac=0; - tx->buffer_size=buffer_size; - tx->fft_size=fft_size; - tx->fps=fps; + TRANSMITTER *tx = g_new(TRANSMITTER, 1); + tx->id = id; + tx->dac = 0; + tx->buffer_size = buffer_size; + tx->fft_size = fft_size; + tx->fps = fps; - switch(protocol) { + switch (protocol) { case ORIGINAL_PROTOCOL: - tx->mic_sample_rate=48000; - tx->mic_dsp_rate=48000; - tx->iq_output_rate=48000; - break; + tx->mic_sample_rate = 48000; + tx->mic_dsp_rate = 48000; + tx->iq_output_rate = 48000; + break; case NEW_PROTOCOL: - tx->mic_sample_rate=48000; - tx->mic_dsp_rate=96000; - tx->iq_output_rate=192000; - break; - - } - int ratio=tx->iq_output_rate/tx->mic_sample_rate; - tx->output_samples=tx->buffer_size*ratio; - //tx->pixels=width*ratio*4; - tx->pixels=display_width*ratio*2; - - tx->width=width; - tx->height=height; - tx->display_panadapter=1; - tx->display_waterfall=0; - - tx->panadapter_high=0; - tx->panadapter_low=-70; - tx->panadapter_step=10; - - tx->displaying=0; - - tx->alex_antenna=ALEX_TX_ANTENNA_1; - -fprintf(stderr,"create_transmitter: id=%d buffer_size=%d mic_sample_rate=%d mic_dsp_rate=%d iq_output_rate=%d output_samples=%d fps=%d width=%d height=%d\n",tx->id, tx->buffer_size, tx->mic_sample_rate, tx->mic_dsp_rate, tx->iq_output_rate, tx->output_samples,tx->fps,tx->width,tx->height); - - tx->filter_low=tx_filter_low; - tx->filter_high=tx_filter_high; - tx->use_rx_filter=FALSE; - - tx->out_of_band=0; - - tx->low_latency=0; - - tx->twotone=0; - tx->puresignal=0; - tx->feedback=0; - tx->auto_on=0; - tx->single_on=0; - - tx->attenuation=0; - tx->ctcss=11; - tx->ctcss_enabled=FALSE; - - tx->deviation=2500; - tx->am_carrier_level=0.5; - - tx->drive=50; - tx->tune_percent=10; - tx->tune_use_drive=0; - - tx->compressor=0; - tx->compressor_level=0.0; - - tx->local_microphone=0; - tx->microphone_name=NULL; - - tx->xit_enabled=FALSE; - tx->xit=0LL; - - tx->dialog_x=-1; - tx->dialog_y=-1; - - transmitter_restore_state(tx); - - - // allocate buffers -fprintf(stderr,"transmitter: allocate buffers: mic_input_buffer=%d iq_output_buffer=%d pixels=%d\n",tx->buffer_size,tx->output_samples,tx->pixels); - tx->mic_input_buffer=g_new(double,2*tx->buffer_size); - tx->iq_output_buffer=g_new(double,2*tx->output_samples); - tx->samples=0; - tx->pixel_samples=g_new(float,tx->pixels); - if (cw_shape_buffer48) g_free(cw_shape_buffer48); - if (cw_shape_buffer192) g_free(cw_shape_buffer192); - // - // We need this one both for old and new protocol, since - // is is also used to shape the audio samples - cw_shape_buffer48=g_new(double,tx->buffer_size); - if (protocol == NEW_PROTOCOL) { - // We need this buffer for the new protocol only, where it is only - // used to shape the TX envelope - cw_shape_buffer192=g_new(double,tx->output_samples); - } -fprintf(stderr,"transmitter: allocate buffers: mic_input_buffer=%p iq_output_buffer=%p pixels=%p\n",tx->mic_input_buffer,tx->iq_output_buffer,tx->pixel_samples); - - fprintf(stderr,"create_transmitter: OpenChannel id=%d buffer_size=%d fft_size=%d sample_rate=%d dspRate=%d outputRate=%d\n", - tx->id, - tx->buffer_size, - 2048, // tx->fft_size, - tx->mic_sample_rate, - tx->mic_dsp_rate, - tx->iq_output_rate); + tx->mic_sample_rate = 48000; + tx->mic_dsp_rate = 96000; + tx->iq_output_rate = 192000; + break; + } + int ratio = tx->iq_output_rate / tx->mic_sample_rate; + tx->output_samples = tx->buffer_size * ratio; + // tx->pixels=width*ratio*4; + tx->pixels = display_width * ratio * 2; + + tx->width = width; + tx->height = height; + tx->display_panadapter = 1; + tx->display_waterfall = 0; + + tx->panadapter_high = 0; + tx->panadapter_low = -70; + tx->panadapter_step = 10; + + tx->displaying = 0; + + tx->alex_antenna = ALEX_TX_ANTENNA_1; + + log_trace("create_transmitter: id=%d buffer_size=%d mic_sample_rate=%d " + "mic_dsp_rate=%d iq_output_rate=%d output_samples=%d fps=%d " + "width=%d height=%d", + tx->id, tx->buffer_size, tx->mic_sample_rate, tx->mic_dsp_rate, + tx->iq_output_rate, tx->output_samples, tx->fps, tx->width, + tx->height); + + tx->filter_low = tx_filter_low; + tx->filter_high = tx_filter_high; + tx->use_rx_filter = FALSE; + + tx->out_of_band = 0; + + tx->low_latency = 0; + + tx->twotone = 0; + tx->puresignal = 0; + tx->feedback = 0; + tx->auto_on = 0; + tx->single_on = 0; + + tx->attenuation = 0; + tx->ctcss = 11; + tx->ctcss_enabled = FALSE; + + tx->deviation = 2500; + tx->am_carrier_level = 0.5; + + tx->drive = 50; + tx->tune_percent = 10; + tx->tune_use_drive = 0; + + tx->compressor = 0; + tx->compressor_level = 0.0; + + tx->local_microphone = 0; + tx->microphone_name = NULL; + + tx->xit_enabled = FALSE; + tx->xit = 0LL; + + tx->dialog_x = -1; + tx->dialog_y = -1; + + transmitter_restore_state(tx); + + // allocate buffers + log_trace("transmitter: allocate buffers: mic_input_buffer=%d " + "iq_output_buffer=%d pixels=%d", + tx->buffer_size, tx->output_samples, tx->pixels); + tx->mic_input_buffer = g_new(double, 2 * tx->buffer_size); + tx->iq_output_buffer = g_new(double, 2 * tx->output_samples); + tx->samples = 0; + tx->pixel_samples = g_new(float, tx->pixels); + if (cw_shape_buffer48) + g_free(cw_shape_buffer48); + if (cw_shape_buffer192) + g_free(cw_shape_buffer192); + // + // We need this one both for old and new protocol, since + // is is also used to shape the audio samples + cw_shape_buffer48 = g_new(double, tx->buffer_size); + if (protocol == NEW_PROTOCOL) { + // We need this buffer for the new protocol only, where it is only + // used to shape the TX envelope + cw_shape_buffer192 = g_new(double, tx->output_samples); + } + log_trace("transmitter: allocate buffers: mic_input_buffer=%p " + "iq_output_buffer=%p pixels=%p", + tx->mic_input_buffer, tx->iq_output_buffer, tx->pixel_samples); - OpenChannel(tx->id, - tx->buffer_size, + log_trace("create_transmitter: OpenChannel id=%d buffer_size=%d " + "fft_size=%d sample_rate=%d dspRate=%d outputRate=%d", + tx->id, tx->buffer_size, 2048, // tx->fft_size, - tx->mic_sample_rate, - tx->mic_dsp_rate, - tx->iq_output_rate, - 1, // transmit - 0, // run - 0.010, 0.025, 0.0, 0.010, 0); + tx->mic_sample_rate, tx->mic_dsp_rate, tx->iq_output_rate); - TXASetNC(tx->id, tx->fft_size); - TXASetMP(tx->id, tx->low_latency); + OpenChannel(tx->id, tx->buffer_size, + 2048, // tx->fft_size, + tx->mic_sample_rate, tx->mic_dsp_rate, tx->iq_output_rate, + 1, // transmit + 0, // run + 0.010, 0.025, 0.0, 0.010, 0); + TXASetNC(tx->id, tx->fft_size); + TXASetMP(tx->id, tx->low_latency); - SetTXABandpassWindow(tx->id, 1); - SetTXABandpassRun(tx->id, 1); + SetTXABandpassWindow(tx->id, 1); + SetTXABandpassRun(tx->id, 1); - SetTXAFMEmphPosition(tx->id,pre_emphasize); + SetTXAFMEmphPosition(tx->id, pre_emphasize); - SetTXACFIRRun(tx->id, protocol==NEW_PROTOCOL?1:0); // turned on if new protocol - if(enable_tx_equalizer) { - SetTXAGrphEQ(tx->id, tx_equalizer); - SetTXAEQRun(tx->id, 1); - } else { - SetTXAEQRun(tx->id, 0); - } + SetTXACFIRRun( + tx->id, protocol == NEW_PROTOCOL ? 1 : 0); // turned on if new protocol + if (enable_tx_equalizer) { + SetTXAGrphEQ(tx->id, tx_equalizer); + SetTXAEQRun(tx->id, 1); + } else { + SetTXAEQRun(tx->id, 0); + } - transmitter_set_ctcss(tx,tx->ctcss_enabled,tx->ctcss); - SetTXAAMSQRun(tx->id, 0); - SetTXAosctrlRun(tx->id, 0); + transmitter_set_ctcss(tx, tx->ctcss_enabled, tx->ctcss); + SetTXAAMSQRun(tx->id, 0); + SetTXAosctrlRun(tx->id, 0); - SetTXAALCAttack(tx->id, 1); - SetTXAALCDecay(tx->id, 10); - SetTXAALCSt(tx->id, 1); // turn it on (always on) + SetTXAALCAttack(tx->id, 1); + SetTXAALCDecay(tx->id, 10); + SetTXAALCSt(tx->id, 1); // turn it on (always on) - SetTXALevelerAttack(tx->id, 1); - SetTXALevelerDecay(tx->id, 500); - SetTXALevelerTop(tx->id, 5.0); - SetTXALevelerSt(tx->id, tx_leveler); + SetTXALevelerAttack(tx->id, 1); + SetTXALevelerDecay(tx->id, 500); + SetTXALevelerTop(tx->id, 5.0); + SetTXALevelerSt(tx->id, tx_leveler); - SetTXAPreGenMode(tx->id, 0); - SetTXAPreGenToneMag(tx->id, 0.0); - SetTXAPreGenToneFreq(tx->id, 0.0); - SetTXAPreGenRun(tx->id, 0); + SetTXAPreGenMode(tx->id, 0); + SetTXAPreGenToneMag(tx->id, 0.0); + SetTXAPreGenToneFreq(tx->id, 0.0); + SetTXAPreGenRun(tx->id, 0); - SetTXAPostGenMode(tx->id, 0); - SetTXAPostGenToneMag(tx->id, tone_level); - SetTXAPostGenTTMag(tx->id, tone_level,tone_level); - SetTXAPostGenToneFreq(tx->id, 0.0); - SetTXAPostGenRun(tx->id, 0); + SetTXAPostGenMode(tx->id, 0); + SetTXAPostGenToneMag(tx->id, tone_level); + SetTXAPostGenTTMag(tx->id, tone_level, tone_level); + SetTXAPostGenToneFreq(tx->id, 0.0); + SetTXAPostGenRun(tx->id, 0); - SetTXAPanelGain1(tx->id,pow(10.0, mic_gain/20.0)); - SetTXAPanelRun(tx->id, 1); + SetTXAPanelGain1(tx->id, pow(10.0, mic_gain / 20.0)); + SetTXAPanelRun(tx->id, 1); - SetTXAFMDeviation(tx->id, (double)tx->deviation); - SetTXAAMCarrierLevel(tx->id, tx->am_carrier_level); + SetTXAFMDeviation(tx->id, (double)tx->deviation); + SetTXAAMCarrierLevel(tx->id, tx->am_carrier_level); - SetTXACompressorGain(tx->id, tx->compressor_level); - SetTXACompressorRun(tx->id, tx->compressor); + SetTXACompressorGain(tx->id, tx->compressor_level); + SetTXACompressorRun(tx->id, tx->compressor); - tx_set_mode(tx,get_tx_mode()); + tx_set_mode(tx, get_tx_mode()); - XCreateAnalyzer(tx->id, &rc, 262144, 1, 1, ""); - if (rc != 0) { - fprintf(stderr, "XCreateAnalyzer id=%d failed: %d\n",tx->id,rc); - } else { - init_analyzer(tx); - } + XCreateAnalyzer(tx->id, &rc, 262144, 1, 1, ""); + if (rc != 0) { + log_warn("XCreateAnalyzer id=%d failed: %d", tx->id, rc); + } else { + init_analyzer(tx); + } - create_visual(tx); + create_visual(tx); - return tx; + return tx; } -void tx_set_mode(TRANSMITTER* tx,int mode) { - if(tx!=NULL) { - int filter_low, filter_high; - tx->mode=mode; - SetTXAMode(tx->id, tx->mode); - if(tx->use_rx_filter) { - int m=vfo[active_receiver->id].mode; - if(m==modeFMN) { - if(active_receiver->deviation==2500) { - filter_low=-4000; - filter_high=4000; +void tx_set_mode(TRANSMITTER *tx, int mode) { + if (tx != NULL) { + int filter_low, filter_high; + tx->mode = mode; + SetTXAMode(tx->id, tx->mode); + if (tx->use_rx_filter) { + int m = vfo[active_receiver->id].mode; + if (m == modeFMN) { + if (active_receiver->deviation == 2500) { + filter_low = -4000; + filter_high = 4000; + } else { + filter_low = -8000; + filter_high = 8000; + } + } else { + FILTER *mode_filters = filters[m]; + FILTER *filter = &mode_filters[vfo[active_receiver->id].filter]; + filter_low = filter->low; + filter_high = filter->high; + } } else { - filter_low=-8000; - filter_high=8000; + filter_low = tx_filter_low; + filter_high = tx_filter_high; } - } else { - FILTER *mode_filters=filters[m]; - FILTER *filter=&mode_filters[vfo[active_receiver->id].filter]; - filter_low=filter->low; - filter_high=filter->high; - } - } else { - filter_low=tx_filter_low; - filter_high=tx_filter_high; + tx_set_filter(tx, filter_low, filter_high); } - tx_set_filter(tx,filter_low,filter_high); - } } -void tx_set_filter(TRANSMITTER *tx,int low,int high) { - int txmode=get_tx_mode(); +void tx_set_filter(TRANSMITTER *tx, int low, int high) { + int txmode = get_tx_mode(); - switch(txmode) { + switch (txmode) { case modeLSB: case modeCWL: case modeDIGL: - tx->filter_low=-high; - tx->filter_high=-low; - break; + tx->filter_low = -high; + tx->filter_high = -low; + break; case modeUSB: case modeCWU: case modeDIGU: - tx->filter_low=low; - tx->filter_high=high; - break; + tx->filter_low = low; + tx->filter_high = high; + break; case modeDSB: case modeAM: case modeSAM: - tx->filter_low=-high; - tx->filter_high=high; - break; + tx->filter_low = -high; + tx->filter_high = high; + break; case modeFMN: - if(tx->deviation==2500) { - tx->filter_low=-4000; - tx->filter_high=4000; - } else { - tx->filter_low=-8000; - tx->filter_high=8000; - } - break; + if (tx->deviation == 2500) { + tx->filter_low = -4000; + tx->filter_high = 4000; + } else { + tx->filter_low = -8000; + tx->filter_high = 8000; + } + break; case modeDRM: - tx->filter_low=7000; - tx->filter_high=17000; - break; - } + tx->filter_low = 7000; + tx->filter_high = 17000; + break; + } - double fl=tx->filter_low; - double fh=tx->filter_high; + double fl = tx->filter_low; + double fh = tx->filter_high; - SetTXABandpassFreqs(tx->id,fl,fh); + SetTXABandpassFreqs(tx->id, fl, fh); } -void tx_set_pre_emphasize(TRANSMITTER *tx,int state) { - SetTXAFMEmphPosition(tx->id,state); +void tx_set_pre_emphasize(TRANSMITTER *tx, int state) { + SetTXAFMEmphPosition(tx->id, state); } static void full_tx_buffer(TRANSMITTER *tx) { - long isample; - long qsample; - double gain, sidevol, ramp; - double *dp; - int j; - int error; - int cwmode; - int sidetone=0; - static int txflag=0; - - // It is important to query tx->mode and tune only *once* within this function, to assure that - // the two "if (cwmode)" clauses give the same result. - // cwmode only valid in the old protocol, in the new protocol we use a different mechanism - - cwmode = (tx->mode == modeCWL || tx->mode == modeCWU) && !tune && !tx->twotone; - - switch(protocol) { + long isample; + long qsample; + double gain, sidevol, ramp; + double *dp; + int j; + int error; + int cwmode; + int sidetone = 0; + static int txflag = 0; + + // It is important to query tx->mode and tune only *once* within this + // function, to assure that the two "if (cwmode)" clauses give the same + // result. cwmode only valid in the old protocol, in the new protocol we use + // a different mechanism + + cwmode = + (tx->mode == modeCWL || tx->mode == modeCWU) && !tune && !tx->twotone; + + switch (protocol) { case ORIGINAL_PROTOCOL: - gain=32767.0; // 16 bit - break; + gain = 32767.0; // 16 bit + break; case NEW_PROTOCOL: - gain=8388607.0; // 24 bit - break; + gain = 8388607.0; // 24 bit + break; default: - gain=32767.0; + gain = 32767.0; break; - } + } - if (cwmode) { - // - // do not update VOX in CW mode in case we have just switched to CW - // and tx->mic_input_buffer is non-empty. WDSP (fexchange0) is not - // needed because we directly produce the I/Q samples (see below). - // What we do, however, is to create the iq_output_buffer for the - // sole purpose to display the spectrum of our CW signal. Then, - // the difference between poorly-shaped and well-shaped CW pulses - // also becomes visible on *our* TX spectrum display. - // - dp=tx->iq_output_buffer; - // These are the I/Q samples that describe our CW signal - // The only use we make of it is displaying the spectrum. - switch (protocol) { - case ORIGINAL_PROTOCOL: - for (j = 0; j < tx->output_samples; j++) { - *dp++ = 0.0; - *dp++ = cw_shape_buffer48[j]; + if (cwmode) { + // + // do not update VOX in CW mode in case we have just switched to CW + // and tx->mic_input_buffer is non-empty. WDSP (fexchange0) is not + // needed because we directly produce the I/Q samples (see below). + // What we do, however, is to create the iq_output_buffer for the + // sole purpose to display the spectrum of our CW signal. Then, + // the difference between poorly-shaped and well-shaped CW pulses + // also becomes visible on *our* TX spectrum display. + // + dp = tx->iq_output_buffer; + // These are the I/Q samples that describe our CW signal + // The only use we make of it is displaying the spectrum. + switch (protocol) { + case ORIGINAL_PROTOCOL: + for (j = 0; j < tx->output_samples; j++) { + *dp++ = 0.0; + *dp++ = cw_shape_buffer48[j]; + } + break; + case NEW_PROTOCOL: + for (j = 0; j < tx->output_samples; j++) { + *dp++ = 0.0; + *dp++ = cw_shape_buffer192[j]; + } + break; } - break; - case NEW_PROTOCOL: - for (j = 0; j < tx->output_samples; j++) { - *dp++ = 0.0; - *dp++ = cw_shape_buffer192[j]; + } else { + update_vox(tx); + + fexchange0(tx->id, tx->mic_input_buffer, tx->iq_output_buffer, &error); + if (error != 0) { + log_error("full_tx_buffer: id=%d fexchange0: error=%d", tx->id, + error); } - break; } - } else { - update_vox(tx); - fexchange0(tx->id, tx->mic_input_buffer, tx->iq_output_buffer, &error); - if(error!=0) { - fprintf(stderr,"full_tx_buffer: id=%d fexchange0: error=%d\n",tx->id,error); + if (tx->displaying && !(tx->puresignal && tx->feedback)) { + Spectrum0(1, tx->id, 0, 0, tx->iq_output_buffer); } - } - if(tx->displaying && !(tx->puresignal && tx->feedback)) { - Spectrum0(1, tx->id, 0, 0, tx->iq_output_buffer); - } - - if (isTransmitting()) { + if (isTransmitting()) { #ifdef SW_LEVEL_CTRL - if((radio->device==NEW_DEVICE_ATLAS && atlas_penelope) || - (radio->device == DEVICE_HERMES_LITE2)) { + if ((radio->device == NEW_DEVICE_ATLAS && atlas_penelope) || + (radio->device == DEVICE_HERMES_LITE2)) { #else - if(radio->device==NEW_DEVICE_ATLAS && atlas_penelope) { + if (radio->device == NEW_DEVICE_ATLAS && atlas_penelope) { #endif - // - // On these boards, drive level changes are performed by - // scaling the TX IQ samples. In the other cases, DriveLevel - // as sent in the C&C frames becomes effective and the IQ - // samples are sent with full amplitude. - // DL1YCF: include factor 0.00392 since DriveLevel == 255 means full amplitude - // - if(tune && !transmitter->tune_use_drive) { - double fac=sqrt((double)transmitter->tune_percent * 0.01); - gain=gain*(double)transmitter->drive_level*fac*0.00392; - } else { - gain=gain*(double)transmitter->drive_level*0.00392; - } - } - - if (txflag == 0 && protocol == NEW_PROTOCOL) { - // - // this is the first time (after a pause) that we send TX samples - // so send some "silence" to prevent FIFO underflows - // - for (j=0; j< 480; j++) { - new_protocol_iq_samples(0,0); - } - } - txflag=1; -// -// When doing CW, we do not need WDSP since Q(t) = cw_shape_buffer(t) and I(t)=0 -// For the old protocol where the IQ and audio samples are tied together, we can -// easily generate a synchronous side tone (and use the function -// old_protocol_iq_samples_with_sidetone for this purpose). -// -// Note that the CW shape buffer is tied to the mic sample rate (48 kHz). -// - if (cwmode) { - // - // "pulse shape case": - // directly produce the I/Q samples. For a continuous zero-frequency - // carrier (as needed for CW) I(t)=1 and Q(t)=0 everywhere. We shape I(t) - // with the pulse envelope. We also produce a side tone with same shape. - // Note that tx->iq_output_buffer is not used. Therefore, all the - // SetTXAPostGen functions are not needed for CW! - // - // In the new protocol, we just put "silence" into the TX IQ buffer - // - switch (protocol) { - case ORIGINAL_PROTOCOL: - // - // tx->output_samples equals tx->buffer_size - // Take TX envelope from the 48kHz shape buffer - // - sidevol= 64.0 * cw_keyer_sidetone_volume; // between 0.0 and 8128.0 - isample=0; // will be constantly zero - for(j=0;joutput_samples;j++) { - ramp=cw_shape_buffer48[j]; // between 0.0 and 1.0 - qsample=floor(gain*ramp+0.5); // always non-negative, isample is just the pulse envelope - sidetone=sidevol * ramp * getNextInternalSideToneSample(); - - isample = isample >= 0.0 ? (long)floor(isample * gain + 0.5) : (long)ceil(isample * gain - 0.5); - qsample = qsample >= 0.0 ? (long)floor(qsample * gain + 0.5) : (long)ceil(qsample * gain - 0.5); - - old_protocol_iq_samples_with_sidetone(isample,qsample,sidetone); - } - break; - case NEW_PROTOCOL: - // - // tx->output_samples if four times tx->buffer_size - // Take TX envelope from the 192kHz shape buffer - // - isample=0; - for(j=0;joutput_samples;j++) { - ramp=cw_shape_buffer192[j]; // between 0.0 and 1.0 - qsample=floor(gain*ramp+0.5); // always non-negative, isample is just the pulse envelope - - isample = isample >= 0.0 ? (long)floor(isample * gain + 0.5) : (long)ceil(isample * gain - 0.5); - qsample = qsample >= 0.0 ? (long)floor(qsample * gain + 0.5) : (long)ceil(qsample * gain - 0.5); - - new_protocol_iq_samples(isample,qsample); - } - break; - } - } else { - // - // Original code without pulse shaping and without side tone - // - for(j=0;joutput_samples;j++) { - double is,qs; - if(iqswap) { - qs=tx->iq_output_buffer[j*2]; - is=tx->iq_output_buffer[(j*2)+1]; + // + // On these boards, drive level changes are performed by + // scaling the TX IQ samples. In the other cases, DriveLevel + // as sent in the C&C frames becomes effective and the IQ + // samples are sent with full amplitude. + // DL1YCF: include factor 0.00392 since DriveLevel == 255 means full + // amplitude + // + if (tune && !transmitter->tune_use_drive) { + double fac = sqrt((double)transmitter->tune_percent * 0.01); + gain = gain * (double)transmitter->drive_level * fac * 0.00392; } else { - is=tx->iq_output_buffer[j*2]; - qs=tx->iq_output_buffer[(j*2)+1]; + gain = gain * (double)transmitter->drive_level * 0.00392; + } + } + + if (txflag == 0 && protocol == NEW_PROTOCOL) { + // + // this is the first time (after a pause) that we send TX samples + // so send some "silence" to prevent FIFO underflows + // + for (j = 0; j < 480; j++) { + new_protocol_iq_samples(0, 0); + } + } + txflag = 1; + // + // When doing CW, we do not need WDSP since Q(t) = cw_shape_buffer(t) + // and I(t)=0 For the old protocol where the IQ and audio samples are + // tied together, we can easily generate a synchronous side tone (and + // use the function old_protocol_iq_samples_with_sidetone for this + // purpose). + // + // Note that the CW shape buffer is tied to the mic sample rate (48 + // kHz). + // + if (cwmode) { + // + // "pulse shape case": + // directly produce the I/Q samples. For a continuous zero-frequency + // carrier (as needed for CW) I(t)=1 and Q(t)=0 everywhere. We shape + // I(t) with the pulse envelope. We also produce a side tone with + // same shape. Note that tx->iq_output_buffer is not used. + // Therefore, all the SetTXAPostGen functions are not needed for CW! + // + // In the new protocol, we just put "silence" into the TX IQ buffer + // + switch (protocol) { + case ORIGINAL_PROTOCOL: + // + // tx->output_samples equals tx->buffer_size + // Take TX envelope from the 48kHz shape buffer + // + sidevol = + 64.0 * cw_keyer_sidetone_volume; // between 0.0 and 8128.0 + isample = 0; // will be constantly zero + for (j = 0; j < tx->output_samples; j++) { + ramp = cw_shape_buffer48[j]; // between 0.0 and 1.0 + qsample = floor(gain * ramp + + 0.5); // always non-negative, isample is + // just the pulse envelope + sidetone = sidevol * ramp * getNextInternalSideToneSample(); + + isample = isample >= 0.0 ? (long)floor(isample * gain + 0.5) + : (long)ceil(isample * gain - 0.5); + qsample = qsample >= 0.0 ? (long)floor(qsample * gain + 0.5) + : (long)ceil(qsample * gain - 0.5); + + old_protocol_iq_samples_with_sidetone(isample, qsample, + sidetone); + } + break; + case NEW_PROTOCOL: + // + // tx->output_samples if four times tx->buffer_size + // Take TX envelope from the 192kHz shape buffer + // + isample = 0; + for (j = 0; j < tx->output_samples; j++) { + ramp = cw_shape_buffer192[j]; // between 0.0 and 1.0 + qsample = floor(gain * ramp + + 0.5); // always non-negative, isample is + // just the pulse envelope + + isample = isample >= 0.0 ? (long)floor(isample * gain + 0.5) + : (long)ceil(isample * gain - 0.5); + qsample = qsample >= 0.0 ? (long)floor(qsample * gain + 0.5) + : (long)ceil(qsample * gain - 0.5); + + new_protocol_iq_samples(isample, qsample); + } + break; + } + } else { + // + // Original code without pulse shaping and without side tone + // + for (j = 0; j < tx->output_samples; j++) { + double is, qs; + if (iqswap) { + qs = tx->iq_output_buffer[j * 2]; + is = tx->iq_output_buffer[(j * 2) + 1]; + } else { + is = tx->iq_output_buffer[j * 2]; + qs = tx->iq_output_buffer[(j * 2) + 1]; + } + isample = is >= 0.0 ? (long)floor(is * gain + 0.5) + : (long)ceil(is * gain - 0.5); + qsample = qs >= 0.0 ? (long)floor(qs * gain + 0.5) + : (long)ceil(qs * gain - 0.5); + switch (protocol) { + case ORIGINAL_PROTOCOL: + old_protocol_iq_samples(isample, qsample); + break; + case NEW_PROTOCOL: + new_protocol_iq_samples(isample, qsample); + break; + } } - isample = is >= 0.0 ? (long)floor(is * gain + 0.5) : (long)ceil(is * gain - 0.5); - qsample = qs >= 0.0 ? (long)floor(qs * gain + 0.5) : (long)ceil(qs * gain - 0.5); - switch(protocol) { - case ORIGINAL_PROTOCOL: - old_protocol_iq_samples(isample,qsample); - break; - case NEW_PROTOCOL: - new_protocol_iq_samples(isample,qsample); - break; - } - } + } + } else { + // + // When the buffer has not been sent because MOX has gone, + // instead flush the current TX IQ buffer + // + if (txflag == 1 && protocol == NEW_PROTOCOL) + new_protocol_flush_iq_samples(); + txflag = 0; } - } else { - // - // When the buffer has not been sent because MOX has gone, - // instead flush the current TX IQ buffer - // - if (txflag == 1 && protocol == NEW_PROTOCOL) new_protocol_flush_iq_samples(); - txflag=0; - } } -void add_mic_sample(TRANSMITTER *tx,float mic_sample) { - int mode=tx->mode; - float cwsample; - double mic_sample_double, ramp; - int i,s; - int updown; +void add_mic_sample(TRANSMITTER *tx, float mic_sample) { + int mode = tx->mode; + float cwsample; + double mic_sample_double, ramp; + int i, s; + int updown; -// -// silence TX audio if tuning, or when doing CW. -// (in order not to fire VOX) -// + // + // silence TX audio if tuning, or when doing CW. + // (in order not to fire VOX) + // - if (tune || mode==modeCWL || mode==modeCWU) { - mic_sample_double=0.0; - } else { - mic_sample_double=(double)mic_sample; - } + if (tune || mode == modeCWL || mode == modeCWU) { + mic_sample_double = 0.0; + } else { + mic_sample_double = (double)mic_sample; + } -// -// shape CW pulses when doing CW and transmitting, else nullify them -// - if((mode==modeCWL || mode==modeCWU) && isTransmitting()) { -// -// RigCtl CW sets the variables cw_key_up and cw_key_down -// to the number of samples for the next down/up sequence. -// cw_key_down can be zero, for inserting some space -// -// We HAVE TO shape the signal to avoid hard clicks to be -// heard way beside our frequency. The envelope (ramp function) -// is stored in cwramp48[0::RAMPLEN], so we "move" cw_shape between these -// values. The ramp width is RAMPLEN/48000 seconds. -// -// In the new protocol, we use this ramp for the side tone, but -// must use values from cwramp192 for the TX iq signal. -// -// Note that usually, the pulse is much broader than the ramp, -// that is, cw_key_down and cw_key_up are much larger than RAMPLEN. -// - cw_not_ready=0; - if (cw_key_down > 0 ) { - if (cw_shape < RAMPLEN) cw_shape++; // walk up the ramp - cw_key_down--; // decrement key-up counter - updown=1; - } else { - // dig into this even if cw_key_up is already zero, to ensure - // that we reach the bottom of the ramp for very small pauses - if (cw_shape > 0) cw_shape--; // walk down the ramp - if (cw_key_up > 0) cw_key_up--; // decrement key-down counter - updown=0; - } - // - // store the ramp value in cw_shape_buffer, but also use it for shaping the "local" - // side tone - ramp=cwramp48[cw_shape]; - cwsample=0.00197 * getNextSideToneSample() * cw_keyer_sidetone_volume * ramp; - if(active_receiver->local_audio) cw_audio_write(active_receiver,cwsample); - cw_shape_buffer48[tx->samples]=ramp; - // - // In the new protocol, we MUST maintain a constant flow of audio samples to the radio - // (at least for ANAN-200D and ANAN-7000 internal side tone generation) - // So we ship out audio: silence if CW is internal, side tone if CW is local. - // - // Furthermore, for each audio sample we have to create four TX samples. If we are at - // the beginning of the ramp, these are four zero samples, if we are at the, it is - // four unit samples, and in-between, we use the values from cwramp192. - // Note that this ramp has been extended a little, such that it begins with four zeros - // and ends with four times 1.0. - // + // + // shape CW pulses when doing CW and transmitting, else nullify them + // + if ((mode == modeCWL || mode == modeCWU) && isTransmitting()) { + // + // RigCtl CW sets the variables cw_key_up and cw_key_down + // to the number of samples for the next down/up sequence. + // cw_key_down can be zero, for inserting some space + // + // We HAVE TO shape the signal to avoid hard clicks to be + // heard way beside our frequency. The envelope (ramp function) + // is stored in cwramp48[0::RAMPLEN], so we "move" cw_shape between + // these values. The ramp width is RAMPLEN/48000 seconds. + // + // In the new protocol, we use this ramp for the side tone, but + // must use values from cwramp192 for the TX iq signal. + // + // Note that usually, the pulse is much broader than the ramp, + // that is, cw_key_down and cw_key_up are much larger than RAMPLEN. + // + cw_not_ready = 0; + if (cw_key_down > 0) { + if (cw_shape < RAMPLEN) + cw_shape++; // walk up the ramp + cw_key_down--; // decrement key-up counter + updown = 1; + } else { + // dig into this even if cw_key_up is already zero, to ensure + // that we reach the bottom of the ramp for very small pauses + if (cw_shape > 0) + cw_shape--; // walk down the ramp + if (cw_key_up > 0) + cw_key_up--; // decrement key-down counter + updown = 0; + } + // + // store the ramp value in cw_shape_buffer, but also use it for shaping + // the "local" side tone + ramp = cwramp48[cw_shape]; + cwsample = + 0.00197 * getNextSideToneSample() * cw_keyer_sidetone_volume * ramp; + if (active_receiver->local_audio) + cw_audio_write(active_receiver, cwsample); + cw_shape_buffer48[tx->samples] = ramp; + // + // In the new protocol, we MUST maintain a constant flow of audio + // samples to the radio (at least for ANAN-200D and ANAN-7000 internal + // side tone generation) So we ship out audio: silence if CW is + // internal, side tone if CW is local. + // + // Furthermore, for each audio sample we have to create four TX samples. + // If we are at the beginning of the ramp, these are four zero samples, + // if we are at the, it is four unit samples, and in-between, we use the + // values from cwramp192. Note that this ramp has been extended a + // little, such that it begins with four zeros and ends with four + // times 1.0. + // if (protocol == NEW_PROTOCOL) { - s=0; - if (!cw_keyer_internal || CAT_cw_is_active) s=(int) (cwsample * 32767.0); - new_protocol_cw_audio_samples(s, s); - s=4*cw_shape; - i=4*tx->samples; - // The 192kHz-ramp is constructed such that for cw_shape==0 or cw_shape==RAMPLEN, - // the two following cases create the same shape. - if (updown) { - // climbing up... - cw_shape_buffer192[i+0]=cwramp192[s+0]; - cw_shape_buffer192[i+1]=cwramp192[s+1]; - cw_shape_buffer192[i+2]=cwramp192[s+2]; - cw_shape_buffer192[i+3]=cwramp192[s+3]; - } else { - // descending... - cw_shape_buffer192[i+0]=cwramp192[s+3]; - cw_shape_buffer192[i+1]=cwramp192[s+2]; - cw_shape_buffer192[i+2]=cwramp192[s+1]; - cw_shape_buffer192[i+3]=cwramp192[s+0]; - } - } - } else { -// -// If no longer transmitting, or no longer doing CW: reset pulse shaper. -// This will also swallow any pending CW in rigtl CAT CW and wipe out -// cw_shape_buffer very quickly. In order to tell rigctl etc. that CW should be -// aborted, we also use the cw_not_ready flag. -// - cw_not_ready=1; - cw_key_up=0; - cw_key_down=0; - cw_shape=0; - cw_shape_buffer48[tx->samples]=0.0; - if (protocol == NEW_PROTOCOL) { - cw_shape_buffer192[4*tx->samples+0]=0.0; - cw_shape_buffer192[4*tx->samples+1]=0.0; - cw_shape_buffer192[4*tx->samples+2]=0.0; - cw_shape_buffer192[4*tx->samples+3]=0.0; - } - } - tx->mic_input_buffer[tx->samples*2]=mic_sample_double; - tx->mic_input_buffer[(tx->samples*2)+1]=0.0; //mic_sample_double; - tx->samples++; - if(tx->samples==tx->buffer_size) { - full_tx_buffer(tx); - tx->samples=0; - } - + s = 0; + if (!cw_keyer_internal || CAT_cw_is_active) + s = (int)(cwsample * 32767.0); + new_protocol_cw_audio_samples(s, s); + s = 4 * cw_shape; + i = 4 * tx->samples; + // The 192kHz-ramp is constructed such that for cw_shape==0 or + // cw_shape==RAMPLEN, the two following cases create the same shape. + if (updown) { + // climbing up... + cw_shape_buffer192[i + 0] = cwramp192[s + 0]; + cw_shape_buffer192[i + 1] = cwramp192[s + 1]; + cw_shape_buffer192[i + 2] = cwramp192[s + 2]; + cw_shape_buffer192[i + 3] = cwramp192[s + 3]; + } else { + // descending... + cw_shape_buffer192[i + 0] = cwramp192[s + 3]; + cw_shape_buffer192[i + 1] = cwramp192[s + 2]; + cw_shape_buffer192[i + 2] = cwramp192[s + 1]; + cw_shape_buffer192[i + 3] = cwramp192[s + 0]; + } + } + } else { + // + // If no longer transmitting, or no longer doing CW: reset pulse + //shaper. This will also swallow any pending CW in rigtl CAT CW and wipe + //out + // cw_shape_buffer very quickly. In order to tell rigctl etc. that + // CW should be + // aborted, we also use the cw_not_ready flag. + // + cw_not_ready = 1; + cw_key_up = 0; + cw_key_down = 0; + cw_shape = 0; + cw_shape_buffer48[tx->samples] = 0.0; + if (protocol == NEW_PROTOCOL) { + cw_shape_buffer192[4 * tx->samples + 0] = 0.0; + cw_shape_buffer192[4 * tx->samples + 1] = 0.0; + cw_shape_buffer192[4 * tx->samples + 2] = 0.0; + cw_shape_buffer192[4 * tx->samples + 3] = 0.0; + } + } + tx->mic_input_buffer[tx->samples * 2] = mic_sample_double; + tx->mic_input_buffer[(tx->samples * 2) + 1] = 0.0; // mic_sample_double; + tx->samples++; + if (tx->samples == tx->buffer_size) { + full_tx_buffer(tx); + tx->samples = 0; + } + #ifdef AUDIO_WATERFALL - if(audio_samples!=NULL && isTransmitting()) { - if(waterfall_samples==0) { - audio_samples[audio_samples_index]=(float)mic_sample; - audio_samples_index++; - if(audio_samples_index>=AUDIO_WATERFALL_SAMPLES) { - //Spectrum(CHANNEL_AUDIO,0,0,audio_samples,audio_samples); - audio_samples_index=0; - } - } - waterfall_samples++; - if(waterfall_samples==waterfall_resample) { - waterfall_samples=0; - } - } + if (audio_samples != NULL && isTransmitting()) { + if (waterfall_samples == 0) { + audio_samples[audio_samples_index] = (float)mic_sample; + audio_samples_index++; + if (audio_samples_index >= AUDIO_WATERFALL_SAMPLES) { + // Spectrum(CHANNEL_AUDIO,0,0,audio_samples,audio_samples); + audio_samples_index = 0; + } + } + waterfall_samples++; + if (waterfall_samples == waterfall_resample) { + waterfall_samples = 0; + } + } #endif } -void add_ps_iq_samples(TRANSMITTER *tx, double i_sample_tx,double q_sample_tx, double i_sample_rx, double q_sample_rx) { +void add_ps_iq_samples(TRANSMITTER *tx, double i_sample_tx, double q_sample_tx, + double i_sample_rx, double q_sample_rx) { // // If not compiled for PURESIGNAL, make this a dummy function // #ifdef PURESIGNAL - RECEIVER *tx_feedback=receiver[PS_TX_FEEDBACK]; - RECEIVER *rx_feedback=receiver[PS_RX_FEEDBACK]; - -//fprintf(stderr,"add_ps_iq_samples: samples=%d i_rx=%f q_rx=%f i_tx=%f q_tx=%f\n",rx_feedback->samples, i_sample_rx,q_sample_rx,i_sample_tx,q_sample_tx); - - tx_feedback->iq_input_buffer[tx_feedback->samples*2]=i_sample_tx; - tx_feedback->iq_input_buffer[(tx_feedback->samples*2)+1]=q_sample_tx; - rx_feedback->iq_input_buffer[rx_feedback->samples*2]=i_sample_rx; - rx_feedback->iq_input_buffer[(rx_feedback->samples*2)+1]=q_sample_rx; - - tx_feedback->samples=tx_feedback->samples+1; - rx_feedback->samples=rx_feedback->samples+1; - - if(rx_feedback->samples>=rx_feedback->buffer_size) { - if(isTransmitting()) { - pscc(transmitter->id, rx_feedback->buffer_size, tx_feedback->iq_input_buffer, rx_feedback->iq_input_buffer); - if(transmitter->displaying && transmitter->feedback) { - Spectrum0(1, rx_feedback->id, 0, 0, rx_feedback->iq_input_buffer); - } + RECEIVER *tx_feedback = receiver[PS_TX_FEEDBACK]; + RECEIVER *rx_feedback = receiver[PS_RX_FEEDBACK]; + + tx_feedback->iq_input_buffer[tx_feedback->samples * 2] = i_sample_tx; + tx_feedback->iq_input_buffer[(tx_feedback->samples * 2) + 1] = q_sample_tx; + rx_feedback->iq_input_buffer[rx_feedback->samples * 2] = i_sample_rx; + rx_feedback->iq_input_buffer[(rx_feedback->samples * 2) + 1] = q_sample_rx; + + tx_feedback->samples = tx_feedback->samples + 1; + rx_feedback->samples = rx_feedback->samples + 1; + + if (rx_feedback->samples >= rx_feedback->buffer_size) { + if (isTransmitting()) { + pscc(transmitter->id, rx_feedback->buffer_size, + tx_feedback->iq_input_buffer, rx_feedback->iq_input_buffer); + if (transmitter->displaying && transmitter->feedback) { + Spectrum0(1, rx_feedback->id, 0, 0, + rx_feedback->iq_input_buffer); + } + } + rx_feedback->samples = 0; + tx_feedback->samples = 0; } - rx_feedback->samples=0; - tx_feedback->samples=0; - } #endif } -void tx_set_displaying(TRANSMITTER *tx,int state) { - tx->displaying=state; - if(state) { - tx->update_timer_id=gdk_threads_add_timeout_full(G_PRIORITY_HIGH_IDLE,1000/tx->fps, update_display, (gpointer)tx, NULL); - } +void tx_set_displaying(TRANSMITTER *tx, int state) { + tx->displaying = state; + if (state) { + tx->update_timer_id = + gdk_threads_add_timeout_full(G_PRIORITY_HIGH_IDLE, 1000 / tx->fps, + update_display, (gpointer)tx, NULL); + } } -void tx_set_ps(TRANSMITTER *tx,int state) { +void tx_set_ps(TRANSMITTER *tx, int state) { #ifdef PURESIGNAL - // - // Switch PURESIGNAL on (state !=0) or off (state==0) - // - // The following rules must be obeyed: - // - // a.) do not call SetPSControl unless you know the feedback - // data streams are flowing. Otherwise, these calls may - // be have no effect (experimental observation) - // - // b. in the old protocol, do not change the value of - // tx->puresignal unless the protocol is stopped. - // (to have a safe re-configuration of the number of - // RX streams) - // - if (!state) { - // if switching off, stop PS engine first, keep feedback - // streams flowing for a while to be sure SetPSControl works. - SetPSControl(tx->id, 1, 0, 0, 0); - usleep(100000); - } - switch (protocol) { + // + // Switch PURESIGNAL on (state !=0) or off (state==0) + // + // The following rules must be obeyed: + // + // a.) do not call SetPSControl unless you know the feedback + // data streams are flowing. Otherwise, these calls may + // be have no effect (experimental observation) + // + // b. in the old protocol, do not change the value of + // tx->puresignal unless the protocol is stopped. + // (to have a safe re-configuration of the number of + // RX streams) + // + if (!state) { + // if switching off, stop PS engine first, keep feedback + // streams flowing for a while to be sure SetPSControl works. + SetPSControl(tx->id, 1, 0, 0, 0); + usleep(100000); + } + switch (protocol) { case ORIGINAL_PROTOCOL: - // stop protocol, change PS state, restart protocol - old_protocol_stop(); - usleep(100000); - tx->puresignal = state ? 1 : 0; - old_protocol_run(); - break; + // stop protocol, change PS state, restart protocol + old_protocol_stop(); + usleep(100000); + tx->puresignal = state ? 1 : 0; + old_protocol_run(); + break; case NEW_PROTOCOL: - // change PS state and tell radio about it - tx->puresignal = state ? 1 : 0; - schedule_high_priority(); - schedule_receive_specific(); - } - if(state) { - // if switching on: wait a while to get the feedback - // streams flowing, then start PS engine - usleep(100000); - SetPSControl(tx->id, 0, 0, 1, 0); - } - // update screen - g_idle_add(ext_vfo_update,NULL); + // change PS state and tell radio about it + tx->puresignal = state ? 1 : 0; + schedule_high_priority(); + schedule_receive_specific(); + } + if (state) { + // if switching on: wait a while to get the feedback + // streams flowing, then start PS engine + usleep(100000); + SetPSControl(tx->id, 0, 0, 1, 0); + } + // update screen + g_idle_add(ext_vfo_update, NULL); #endif } -void tx_set_twotone(TRANSMITTER *tx,int state) { - transmitter->twotone=state; - if(state) { - // set frequencies and levels - switch(tx->mode) { - case modeCWL: - case modeLSB: - case modeDIGL: - SetTXAPostGenTTFreq(transmitter->id, -900.0, -1700.0); - break; - default: - SetTXAPostGenTTFreq(transmitter->id, 900.0, 1700.0); - break; +void tx_set_twotone(TRANSMITTER *tx, int state) { + transmitter->twotone = state; + if (state) { + // set frequencies and levels + switch (tx->mode) { + case modeCWL: + case modeLSB: + case modeDIGL: + SetTXAPostGenTTFreq(transmitter->id, -900.0, -1700.0); + break; + default: + SetTXAPostGenTTFreq(transmitter->id, 900.0, 1700.0); + break; + } + SetTXAPostGenTTMag(transmitter->id, 0.49, 0.49); + SetTXAPostGenMode(transmitter->id, 1); + SetTXAPostGenRun(transmitter->id, 1); + } else { + SetTXAPostGenRun(transmitter->id, 0); } - SetTXAPostGenTTMag (transmitter->id, 0.49, 0.49); - SetTXAPostGenMode(transmitter->id, 1); - SetTXAPostGenRun(transmitter->id, 1); - } else { - SetTXAPostGenRun(transmitter->id, 0); - } - g_idle_add(ext_mox_update,GINT_TO_POINTER(state)); + g_idle_add(ext_mox_update, GINT_TO_POINTER(state)); } -void tx_set_ps_sample_rate(TRANSMITTER *tx,int rate) { +void tx_set_ps_sample_rate(TRANSMITTER *tx, int rate) { #ifdef PURESIGNAL - SetPSFeedbackRate (tx->id,rate); + SetPSFeedbackRate(tx->id, rate); #endif } @@ -1402,11 +1485,11 @@ void tx_set_ps_sample_rate(TRANSMITTER *tx,int rate) { // but now it also smoothes (cw_shape) the signal // void cw_hold_key(int state) { - if (state) { - cw_key_down = 960000; // up to 20 sec - } else { - cw_key_down = 0; - } + if (state) { + cw_key_down = 960000; // up to 20 sec + } else { + cw_key_down = 0; + } } // Sine tone generator: @@ -1414,19 +1497,21 @@ void cw_hold_key(int state) { // for generating side tones simultaneously on the // HPSDR board and local audio. -#define TWOPIOVERSAMPLERATE 0.0001308996938995747; // 2 Pi / 48000 +#define TWOPIOVERSAMPLERATE 0.0001308996938995747; // 2 Pi / 48000 static long asteps = 0; static long bsteps = 0; double getNextSideToneSample() { - double angle = (asteps*cw_keyer_sidetone_frequency)*TWOPIOVERSAMPLERATE; - if (++asteps == 48000) asteps = 0; - return sin(angle); + double angle = (asteps * cw_keyer_sidetone_frequency) * TWOPIOVERSAMPLERATE; + if (++asteps == 48000) + asteps = 0; + return sin(angle); } double getNextInternalSideToneSample() { - double angle = (bsteps*cw_keyer_sidetone_frequency)*TWOPIOVERSAMPLERATE; - if (++bsteps == 48000) bsteps = 0; - return sin(angle); + double angle = (bsteps * cw_keyer_sidetone_frequency) * TWOPIOVERSAMPLERATE; + if (++bsteps == 48000) + bsteps = 0; + return sin(angle); } diff --git a/tx_panadapter.c b/tx_panadapter.c index 2859e8f..58068c0 100644 --- a/tx_panadapter.c +++ b/tx_panadapter.c @@ -43,6 +43,7 @@ #endif #include "ext.h" #include "new_menu.h" +#include "log.h" static gint last_x; static gboolean has_moved=FALSE; @@ -317,7 +318,6 @@ void tx_panadapter_update(TRANSMITTER *tx) { // cursor cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); cairo_set_line_width(cr, 1.0); -//fprintf(stderr,"cursor: x=%f\n",(double)(display_width/2.0)+(vfo[tx->id].offset/hz_per_pixel)); //cairo_move_to(cr,vfofreq+(vfo[id].offset/hz_per_pixel),0.0); //cairo_line_to(cr,vfofreq+(vfo[id].offset/hz_per_pixel),(double)display_height); cairo_move_to(cr,vfofreq,0.0); @@ -455,7 +455,7 @@ void tx_panadapter_update(TRANSMITTER *tx) { void tx_panadapter_init(TRANSMITTER *tx, int width,int height) { -fprintf(stderr,"tx_panadapter_init: %d x %d\n",width,height); + log_trace("tx_panadapter_init: %d x %d",width,height); tx->panadapter_surface=NULL; tx->panadapter=gtk_drawing_area_new (); diff --git a/vfo.c b/vfo.c index bdbbaad..5626274 100644 --- a/vfo.c +++ b/vfo.c @@ -54,6 +54,7 @@ #endif #include "ext.h" #include "screen.h" +#include "log.h" static GtkWidget *parent_window; static int my_width; @@ -230,7 +231,7 @@ void vfo_restore_state() { char *value; for (i = 0; i < MAX_VFOS; i++) { - g_print("vfo_restore_state: %d\n", i); + log_trace("vfo_restore_state: %d", i); vfo[i].band = band20; vfo[i].bandstack = 0; @@ -243,7 +244,7 @@ void vfo_restore_state() { vfo[i].rit = 0; vfo[i].ctun = 0; - g_print("vfo_restore_state: band=%d frequency=%lld\n", vfo[i].band, + log_trace("vfo_restore_state: band=%d frequency=%lld", vfo[i].band, vfo[i].frequency); sprintf(name, "vfo.%d.band", i); @@ -1262,7 +1263,7 @@ void vfo_update(void) { // some space int which_nb = get_nb(active_receiver); if (which_nb < 0) { - g_print("RIGCTL: ERROR in NR determination used for display\n"); + log_trace("RIGCTL: ERROR in NR determination used for display"); which_nb = 0; } draw_item(cr, SCR_NB, which_nb); @@ -1271,7 +1272,7 @@ void vfo_update(void) { // NR, NR2, NR3 and NR4 are mutually exclusive int which_nr = get_nr(active_receiver); if (which_nr < 0) { - g_print("RIGCTL: ERROR in NR determination used for display\n"); + log_trace("RIGCTL: ERROR in NR determination used for display"); which_nr = 0; } draw_item(cr, SCR_NR, which_nr); @@ -1308,7 +1309,7 @@ void vfo_update(void) { cairo_destroy(cr); gtk_widget_queue_draw(vfo_panel); } else { - fprintf(stderr, "vfo_update: no surface!\n"); + log_debug("vfo_update: no surface!"); } } @@ -1334,7 +1335,7 @@ static gboolean vfo_press_event_cb(GtkWidget *widget, GdkEventButton *event, GtkWidget *vfo_init(int width, int height, GtkWidget *parent) { - fprintf(stderr, "vfo_init: width=%d height=%d\n", width, height); + log_trace("vfo_init: width=%d height=%d", width, height); parent_window = parent; my_width = width; diff --git a/vox_menu.c b/vox_menu.c index 580464e..bd8fa30 100644 --- a/vox_menu.c +++ b/vox_menu.c @@ -32,6 +32,7 @@ #include "vox_menu.h" #include "vox.h" #include "ext.h" +#include "log.h" static GtkWidget *parent_window=NULL; @@ -124,9 +125,9 @@ static void start_level_thread() { run_level=1; level_thread_id = g_thread_new( "VOX level", level_thread, NULL); if(!level_thread_id ) { - fprintf(stderr,"g_thread_new failed on level_thread\n"); + log_debug("g_thread_new failed on level_thread"); } - fprintf(stderr, "level_thread: id=%p\n",level_thread_id); + log_debug("level_thread: id=%p",level_thread_id); } static void destroy_cb(GtkWidget *widget, gpointer data) { diff --git a/waterfall.c b/waterfall.c index fd85804..a117f4b 100644 --- a/waterfall.c +++ b/waterfall.c @@ -138,17 +138,12 @@ void waterfall_update(RECEIVER *rx) { if (rx->waterfall_frequency < (vfo_freq - half) || rx->waterfall_frequency > (vfo_freq + half)) { // outside of the range - blank waterfall - // fprintf(stderr,"waterfall_update: clear waterfall from - // %lld to - // %lld\n",rx->waterfall_frequency,vfo[rx->id].frequency); memset(pixels, 0, display_width * display_height * 3); } else { // rotate waterfall int rotate_pixels = (int)((double)(rx->waterfall_frequency - vfo_freq) / hz_per_pixel); - // fprintf(stderr,"waterfall_update: rotate waterfall from - // %lld to %lld // pixels=%d\n",rx->waterfall_frequency,vfo[rx->id].frequency,rotate_pixels); if (rotate_pixels < 0) { for (size_t h = 0; h < display_height; h++) { diff --git a/zoompan.c b/zoompan.c index ec92a87..106f26d 100644 --- a/zoompan.c +++ b/zoompan.c @@ -34,6 +34,7 @@ #include "client_server.h" #endif #include "actions.h" +#include "log.h" static int width; static int height; @@ -231,7 +232,7 @@ GtkWidget *zoompan_init(int my_width, int my_height) { width=my_width; height=my_height; -fprintf(stderr,"zoompan_init: width=%d height=%d\n", width,height); + log_trace("zoompan_init: width=%d height=%d", width,height); zoompan=gtk_grid_new(); gtk_widget_set_size_request (zoompan, width, height);