From: John Melton - G0ORX/N6LYT Date: Sat, 18 Feb 2017 10:09:42 +0000 (+0000) Subject: updated LimeSDR protocol. Changes calls to setVox to use g_idel_add. Some code cleanup X-Git-Url: https://git.rkrishnan.org/pf/$top_link?a=commitdiff_plain;h=87c44209fc971716dae360a954290ecebbe7d1e2;p=pihpsdr.git updated LimeSDR protocol. Changes calls to setVox to use g_idel_add. Some code cleanup --- diff --git a/Makefile b/Makefile index 736b0a4..bb20ced 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ USBOZY_INCLUDE=USBOZY #UNAME_N=odroid #UNAME_N=up #UNAME_N=pine64 -UNAME_N=x86 +UNAME_N=jetsen CC=gcc LINK=gcc diff --git a/audio.c b/audio.c index 39f1359..70a346d 100644 --- a/audio.c +++ b/audio.c @@ -439,8 +439,8 @@ fprintf(stderr,"output_device: %s\n",device_id); if(strncmp("dmix:", name, 5)==0/* || strncmp("pulse", name, 5)==0*/) { fprintf(stderr,"name=%s descr=%s io=%s\n",name, descr, io); - device_id=malloc(64); + snprintf(device_id, 64, "%s", name); output_devices[n_output_devices++]=device_id; fprintf(stderr,"output_device: %s\n",device_id); diff --git a/lime_protocol.c b/lime_protocol.c index 07ae695..c7e1d92 100644 --- a/lime_protocol.c +++ b/lime_protocol.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -14,19 +13,20 @@ #include "discovered.h" #include "lime_protocol.h" #include "radio.h" +#include "receiver.h" #include "SoapySDR/Constants.h" #include "SoapySDR/Device.h" static double bandwidth=3000000.0; -static int lime_sample_rate= -static size_t receiver; +static size_t lime_receiver; static SoapySDRDevice *lime_device; static SoapySDRStream *stream; +static int lime_sample_rate; static int display_width; -static int buffer_size=BUFFER_SIZE; +static int lime_buffer_size=BUFFER_SIZE; static int outputsamples; -static int fft_size=4096; +static int lime_fft_size=4096; static int dspRate=48000; static int outputRate=48000; static float *buffer; @@ -35,17 +35,19 @@ static int max_samples; static long long saved_frequency=0LL; static int saved_antenna=-1; -static double iqinputbuffer[BUFFER_SIZE*2]; +//static double iqinputbuffer[BUFFER_SIZE*2]; static double audiooutputbuffer[BUFFER_SIZE*2]; static int samples=0; -static pthread_t receive_thread_id; -static void *receive_thread(void* arg); +static GThread *receive_thread_id; +static gpointer receive_thread(gpointer data); -static void *resampler; static int actual_rate; +#ifdef RESAMPLE +static void *resampler; static double resamples[1024*2]; static double resampled[1024*2]; +#endif #ifdef TIMING static int rate_samples; @@ -53,13 +55,16 @@ static int rate_samples; static int running; +void lime_protocol_change_sample_rate(int rate) { +} + void lime_protocol_init(int rx,int pixels,int sample_rate) { SoapySDRKwargs args; int rc; -fprintf(stderr,"lime_protocol_init: receiver=%d pixels=%d sample_rate=%d\n",rx,pixels,sample_rate); +fprintf(stderr,"lime_protocol_init: lime_receiver=%d pixels=%d sample_rate=%d\n",rx,pixels,sample_rate); - receiver=(size_t)rx; + lime_receiver=(size_t)rx; display_width=pixels; lime_sample_rate=sample_rate; @@ -94,7 +99,7 @@ fprintf(stderr,"lime_protocol_init: receiver=%d pixels=%d sample_rate=%d\n",rx,p // initialize the radio fprintf(stderr,"lime_protocol: receive_thread: SoapySDRDevice_make\n"); - lime_device=SoapySDRDevice_make(discovered->info.soapy.args); + lime_device=SoapySDRDevice_make(radio->info.soapy.args); if(lime_device==NULL) { fprintf(stderr,"lime_protocol: SoapySDRDevice_make failed: %s\n",SoapySDRDevice_lastError()); _exit(-1); @@ -104,23 +109,22 @@ fprintf(stderr,"lime_protocol: set antenna to NONE\n"); lime_protocol_set_antenna(0); fprintf(stderr,"lime_protocol: setting samplerate=%f\n",(double)sample_rate); - rc=SoapySDRDevice_setSampleRate(lime_device,SOAPY_SDR_RX,receiver,(double)sample_rate); + rc=SoapySDRDevice_setSampleRate(lime_device,SOAPY_SDR_RX,lime_receiver,(double)sample_rate); if(rc!=0) { fprintf(stderr,"lime_protocol: SoapySDRDevice_setSampleRate(%f) failed: %s\n",(double)sample_rate,SoapySDRDevice_lastError()); } - actual_rate=(int)SoapySDRDevice_getSampleRate(lime_device, SOAPY_SDR_RX, receiver); + actual_rate=(int)SoapySDRDevice_getSampleRate(lime_device, SOAPY_SDR_RX, lime_receiver); fprintf(stderr,"lime_protocol: actual samplerate= %d\n",actual_rate); +#ifdef RESAMPLE if(sample_rate==768000 && actual_rate==767999) { actual_rate=768000; fprintf(stderr,"lime_protocol: forced actual_rate\n"); } - -void lime_protocol_change_sample_rate(int rate) { -} +#endif fprintf(stderr,"lime_protocol: setting bandwidth =%f\n",bandwidth); - rc=SoapySDRDevice_setBandwidth(lime_device,SOAPY_SDR_RX,receiver,bandwidth); + rc=SoapySDRDevice_setBandwidth(lime_device,SOAPY_SDR_RX,lime_receiver,bandwidth); if(rc!=0) { fprintf(stderr,"lime_protocol: SoapySDRDevice_setBandwidth(%f) failed: %s\n",bandwidth,SoapySDRDevice_lastError()); } @@ -132,7 +136,7 @@ fprintf(stderr,"lime_protocol: setting save_frequency: %lld\n",saved_frequency); /* fprintf(stderr,"lime_protocol: set baseband frequency\n"); - rc=SoapySDRDevice_setFrequencyComponent(lime_device,SOAPY_SDR_RX,receiver,"BB",0.0,&args); + rc=SoapySDRDevice_setFrequencyComponent(lime_device,SOAPY_SDR_RX,lime_receiver,"BB",0.0,&args); if(rc!=0) { fprintf(stderr,"lime_protocol: SoapySDRDevice_setFrequencyComponent(BB) failed: %s\n",SoapySDRDevice_lastError()); } @@ -142,23 +146,23 @@ fprintf(stderr,"setting antennal to LNAL\n"); lime_protocol_set_antenna(2); fprintf(stderr,"setting Gain LNA=30.0\n"); - rc=SoapySDRDevice_setGainElement(lime_device,SOAPY_SDR_RX,receiver,"LNA",30.0); + rc=SoapySDRDevice_setGainElement(lime_device,SOAPY_SDR_RX,lime_receiver,"LNA",30.0); if(rc!=0) { fprintf(stderr,"lime_protocol: SoapySDRDevice_setGain LNA failed: %s\n",SoapySDRDevice_lastError()); } fprintf(stderr,"setting Gain PGA=19.0\n"); - rc=SoapySDRDevice_setGainElement(lime_device,SOAPY_SDR_RX,receiver,"PGA",19.0); + rc=SoapySDRDevice_setGainElement(lime_device,SOAPY_SDR_RX,lime_receiver,"PGA",19.0); if(rc!=0) { fprintf(stderr,"lime_protocol: SoapySDRDevice_setGain PGA failed: %s\n",SoapySDRDevice_lastError()); } fprintf(stderr,"setting Gain TIA=12.0\n"); - rc=SoapySDRDevice_setGainElement(lime_device,SOAPY_SDR_RX,receiver,"TIA",12.0); + rc=SoapySDRDevice_setGainElement(lime_device,SOAPY_SDR_RX,lime_receiver,"TIA",12.0); if(rc!=0) { fprintf(stderr,"lime_protocol: SoapySDRDevice_setGain TIA failed: %s\n",SoapySDRDevice_lastError()); } fprintf(stderr,"lime_protocol: receive_thread: SoapySDRDevice_setupStream\n"); - size_t channels=(size_t)receiver; + size_t channels=(size_t)lime_receiver; rc=SoapySDRDevice_setupStream(lime_device,&stream,SOAPY_SDR_RX,"CF32",&channels,1,&args); if(rc!=0) { fprintf(stderr,"lime_protocol: SoapySDRDevice_setupStream failed: %s\n",SoapySDRDevice_lastError()); @@ -170,10 +174,12 @@ fprintf(stderr,"max_samples=%d\n",max_samples); buffer=(float *)malloc(max_samples*sizeof(float)*2); +#ifdef RESAMPLE if(actual_rate!=sample_rate) { fprintf(stderr,"lime_protocol: creating resampler from %d to %d\n",actual_rate,sample_rate); resampler=create_resample (1, max_samples, resamples, resampled, actual_rate, sample_rate, 0.0, 0, 1.0); } +#endif rc=SoapySDRDevice_activateStream(lime_device, stream, 0, 0LL, 0); if(rc!=0) { @@ -193,20 +199,19 @@ fprintf(stderr,"lime_protocol: setting save_frequency: %lld\n",saved_frequency); } fprintf(stderr,"lime_protocol_init: audio_open_output\n"); - if(audio_open_output()!=0) { - local_audio=false; + if(audio_open_output(receiver[0])!=0) { + receiver[0]->local_audio=false; fprintf(stderr,"audio_open_output failed\n"); } fprintf(stderr,"lime_protocol_init: create receive_thread\n"); - rc=pthread_create(&receive_thread_id,NULL,receive_thread,NULL); - if(rc != 0) { - fprintf(stderr,"lime_protocol: pthread_create failed on receive_thread: rc=%d\n", rc); - _exit(-1); + receive_thread_id = g_thread_new( "lime protocol", receive_thread, NULL); + if( ! receive_thread_id ) + { + fprintf(stderr,"g_thread_new failed for receive_thread\n"); + exit( -1 ); } - - - + fprintf(stderr, "receive_thread: id=%p\n",receive_thread_id); } static void *receive_thread(void *arg) { @@ -229,7 +234,8 @@ fprintf(stderr,"lime_protocol: receive_thread\n"); while(running) { elements=SoapySDRDevice_readStream(lime_device,stream,(void *)&buffer,max_samples,&flags,&timeNs,timeoutUs); //fprintf(stderr,"read %d elements\n",elements); - if(actual_rate!=sample_rate) { +#ifdef RESAMPLE + if(actual_rate!=lime_sample_rate) { for(i=0;iid,rx_height,y); break; #ifdef LIMESDR case LIMESDR_PROTOCOL: - lime_protocol_init(0,display_width); + lime_protocol_init(0,display_width,receiver[0]->sample_rate); break; #endif } @@ -560,6 +560,8 @@ static void rxtx(int state) { int i; int y=VFO_HEIGHT; +fprintf(stderr,"rxtx: state=%d\n",state); + if(state) { // switch to tx for(i=0;ifrequency-(long long)(active_receiver->sample_rate/2); - long long maxf=entry->frequency+(long long)(active_receiver->sample_rate/2); +fprintf(stderr,"setFrequency: %lld\n",f); + long long minf=vfo[v].frequency-(long long)(active_receiver->sample_rate/2); + long long maxf=vfo[v].frequency+(long long)(active_receiver->sample_rate/2); if(fmaxf) f=maxf; - ddsOffset=f-entry->frequency; - wdsp_set_offset(ddsOffset); + vfo[v].offset=f-vfo[v].frequency; + set_offset(active_receiver,vfo[v].offset); return; } break; @@ -774,8 +784,8 @@ void setFrequency(long long f) { #ifdef LIMESDR case LIMESDR_PROTOCOL: lime_protocol_set_frequency(f); - ddsOffset=0; - wdsp_set_offset(ddsOffset); + vfo[v].offset=0; + set_offset(active_receiver,vfo[v].offset); break; #endif } diff --git a/radio.h b/radio.h index 0c41d56..c457030 100644 --- a/radio.h +++ b/radio.h @@ -253,6 +253,8 @@ extern void setMox(int state); extern int getMox(); extern void setTune(int state); extern int getTune(); +extern void setVox(int state); +extern int vox_changed(void *data); extern double getDrive(); extern void setDrive(double d); extern void calcDriveLevel(); diff --git a/receiver.c b/receiver.c index 221572c..40fa39e 100644 --- a/receiver.c +++ b/receiver.c @@ -34,6 +34,9 @@ #include "mode.h" #include "new_protocol.h" #include "old_protocol.h" +#ifdef LIME_PROTOOCL +#include "lime_protocol.h" +#endif #include "property.h" #include "radio.h" #include "receiver.h" @@ -248,6 +251,9 @@ void receiver_save_state(RECEIVER *rx) { sprintf(name,"receiver.%d.local_audio",rx->id); sprintf(value,"%d",rx->local_audio); setProperty(name,value); + sprintf(name,"receiver.%d.mute_when_not_active",rx->id); + sprintf(value,"%d",rx->mute_when_not_active); + setProperty(name,value); sprintf(name,"receiver.%d.audio_device",rx->id); sprintf(value,"%d",rx->audio_device); setProperty(name,value); @@ -375,6 +381,9 @@ fprintf(stderr,"receiver_restore_state: id=%d\n",rx->id); sprintf(name,"receiver.%d.local_audio",rx->id); value=getProperty(name); if(value) rx->local_audio=atoi(value); + sprintf(name,"receiver.%d.mute_when_not_active",rx->id); + value=getProperty(name); + if(value) rx->mute_when_not_active=atoi(value); sprintf(name,"receiver.%d.audio_device",rx->id); value=getProperty(name); if(value) rx->audio_device=atoi(value); @@ -742,6 +751,7 @@ fprintf(stderr,"create_receiver: id=%d default adc=%d\n",rx->id, rx->adc); rx->playback_handle=NULL; rx->local_audio=0; + rx->mute_when_not_active=0; rx->audio_channel=STEREO; rx->audio_device=-1; @@ -960,16 +970,20 @@ static void process_rx_buffer(RECEIVER *rx) { } if(rx->local_audio) { - switch(rx->audio_channel) { - case STEREO: - audio_write(rx,left_audio_sample,right_audio_sample); - break; - case LEFT: - audio_write(rx,left_audio_sample,0); - break; - case RIGHT: - audio_write(rx,0,right_audio_sample); - break; + if(rx!=active_receiver && rx->mute_when_not_active) { + audio_write(rx,0,0); + } else { + switch(rx->audio_channel) { + case STEREO: + audio_write(rx,left_audio_sample,right_audio_sample); + break; + case LEFT: + audio_write(rx,left_audio_sample,0); + break; + case RIGHT: + audio_write(rx,0,right_audio_sample); + break; + } } } diff --git a/receiver.h b/receiver.h index 75e36a7..56c2a2b 100644 --- a/receiver.h +++ b/receiver.h @@ -110,6 +110,7 @@ typedef struct _receiver { GdkPixbuf *pixbuf; int local_audio; + int mute_when_not_active; int audio_device; snd_pcm_t *playback_handle; int playback_offset; diff --git a/rx_menu.c b/rx_menu.c index 3d1318d..4c4ed23 100644 --- a/rx_menu.c +++ b/rx_menu.c @@ -82,6 +82,10 @@ static void local_audio_cb(GtkWidget *widget, gpointer data) { } } +static void mute_audio_cb(GtkWidget *widget, gpointer data) { + active_receiver->mute_when_not_active=gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); +} + static void local_output_changed_cb(GtkWidget *widget, gpointer data) { active_receiver->audio_device=(int)(long)data; if(active_receiver->local_audio) { @@ -322,6 +326,12 @@ void rx_menu(GtkWidget *parent) { gtk_grid_attach(GTK_GRID(grid),right_b,x,++row,1,1); g_signal_connect(right_b,"toggled",G_CALLBACK(audio_channel_cb),(gpointer)RIGHT); } + + GtkWidget *mute_audio_b=gtk_check_button_new_with_label("Mute when not active"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_audio_b), active_receiver->mute_when_not_active); + gtk_widget_show(mute_audio_b); + gtk_grid_attach(GTK_GRID(grid),mute_audio_b,x,++row,1,1); + g_signal_connect(mute_audio_b,"toggled",G_CALLBACK(mute_audio_cb),NULL); gtk_container_add(GTK_CONTAINER(content),grid); diff --git a/store_menu.c b/store_menu.c index a91cada..71e79ae 100644 --- a/store_menu.c +++ b/store_menu.c @@ -39,6 +39,8 @@ static GtkWidget *parent_window=NULL; static GtkWidget *dialog=NULL; +GtkWidget *store_button[NUM_OF_MEMORYS]; + static gboolean store_close_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { if(dialog!=NULL) { gtk_widget_destroy(dialog); @@ -51,7 +53,7 @@ static gboolean store_close_cb (GtkWidget *widget, GdkEventButton *event, gpoint static gboolean store_select_cb (GtkWidget *widget, gpointer data) { int index = (int) data; fprintf(stderr,"STORE BUTTON PUSHED=%d\n",index); - char workstr[16]; + char workstr[40]; /* Update mem[data] with current info */ @@ -64,6 +66,9 @@ static gboolean store_select_cb (GtkWidget *widget, gpointer data) { fprintf(stderr,"store_select_cb: mode=%d\n",mem[index].mode); fprintf(stderr,"store_select_cb: filter=%d\n",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); + // Save in the file now.. memSaveState(); } @@ -85,14 +90,18 @@ static gboolean recall_select_cb (GtkWidget *widget, gpointer data) { vfo[active_receiver->id].band = get_band_from_frequency(new_freq); vfo[active_receiver->id].mode = mem[index].mode; vfo[active_receiver->id].filter = mem[index].filter; - vfo_band_changed(vfo[active_receiver->id].band); + //vfo_band_changed(vfo[active_receiver->id].band); + vfo_filter_changed(mem[index].filter); + vfo_mode_changed(mem[index].mode); + g_idle_add(vfo_update,NULL); + } void store_menu(GtkWidget *parent) { GtkWidget *b; int i; BAND *band; - char label_str[20]; + char label_str[50]; parent_window=parent; @@ -126,8 +135,9 @@ void store_menu(GtkWidget *parent) { g_signal_connect(b,"pressed",G_CALLBACK(store_select_cb),(gpointer *) i); gtk_grid_attach(GTK_GRID(grid),b,2,i,1,1); - sprintf(label_str,"Recall M%d",i); + sprintf(label_str,"M%d=%8.6f MHz",i,((double) mem[i].frequency)/1000000.0); b=gtk_button_new_with_label(label_str); + store_button[i]= b; g_signal_connect(b,"pressed",G_CALLBACK(recall_select_cb),(gpointer *) i); gtk_grid_attach(GTK_GRID(grid),b,3,i,1,1); } diff --git a/vfo.c b/vfo.c index 58533fa..dff1464 100644 --- a/vfo.c +++ b/vfo.c @@ -418,6 +418,7 @@ void vfo_move(long long hz) { switch(protocol) { #ifdef LIMESDR case LIMESDR_PROTOCOL: + vfo[id].ctun_frequency=((vfo[id].ctun_frequency-hz)/step)*step; break; #endif default: @@ -439,6 +440,7 @@ void vfo_move_to(long long hz) { switch(protocol) { #ifdef LIMESDR case LIMESDR_PROTOCOL: + vfo[id].ctun_frequency=(vfo[id].frequency+hz)/step*step; break; #endif default: @@ -642,7 +644,7 @@ int vfo_update(void *data) { } else { cairo_set_source_rgb(cr, 1, 1, 0); } - sprintf(temp_text,"RIT: %d Hz",vfo[id].rit); + sprintf(temp_text,"RIT: %lld Hz",vfo[id].rit); cairo_move_to(cr, 5, 50); cairo_set_font_size(cr, 12); cairo_show_text(cr, temp_text); diff --git a/vox.c b/vox.c index cfd78b5..7b99e55 100644 --- a/vox.c +++ b/vox.c @@ -29,7 +29,8 @@ static guint vox_timeout; static double peak=0.0; static int vox_timeout_cb(gpointer data) { - setVox(0); + //setVox(0); + g_idle_add(vox_changed,(gpointer)0); g_idle_add(vfo_update,NULL); return FALSE; } @@ -62,7 +63,8 @@ void update_vox(TRANSMITTER *tx) { if(previous_vox) { g_source_remove(vox_timeout); } else { - setVox(1); + //setVox(1); + g_idle_add(vox_changed,(gpointer)1); } vox_timeout=g_timeout_add((int)vox_hang,vox_timeout_cb,NULL); } @@ -75,6 +77,8 @@ void update_vox(TRANSMITTER *tx) { void vox_cancel() { if(vox) { g_source_remove(vox_timeout); - setVox(0); + //setVox(0); + g_idle_add(vox_changed,(gpointer)0); + g_idle_add(vfo_update,NULL); } } diff --git a/vox_menu.c b/vox_menu.c index 27ac113..8b710f7 100644 --- a/vox_menu.c +++ b/vox_menu.c @@ -96,7 +96,7 @@ static gboolean close_cb (GtkWidget *widget, GdkEventButton *event, gpointer dat static gboolean enable_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { vox_enabled=vox_enabled==1?0:1; - gtk_button_set_label(GTK_BUTTON(widget),vox_enabled==0?"VOX On":"VOX Off"); + gtk_button_set_label(GTK_BUTTON(widget),vox_enabled==0?"VOX Enable":"VOX Disable"); vfo_update(NULL); return TRUE; } @@ -155,7 +155,7 @@ void vox_menu(GtkWidget *parent) { led=create_led(10,10); gtk_grid_attach(GTK_GRID(grid),led,2,0,1,1); - GtkWidget *enable_b=gtk_button_new_with_label(vox_enabled==0?"VOX On":"VOX Off"); + GtkWidget *enable_b=gtk_button_new_with_label(vox_enabled==0?"VOX Enable":"VOX Disable"); g_signal_connect (enable_b, "pressed", G_CALLBACK(enable_cb), NULL); gtk_grid_attach(GTK_GRID(grid),enable_b,3,0,1,1);