From 5e4ecf5081d5e2302c6981f62bac4f3d6ea1a869 Mon Sep 17 00:00:00 2001 From: John Melton - G0ORX Date: Fri, 1 Dec 2017 09:14:57 +0000 Subject: [PATCH] Fixed CW TX problem at hiigher speeds. Changed Attenuation to be for the ADC. --- Makefile | 2 +- freqent_menu.c | 2 +- gpio.c | 2 +- meter.c | 7 ++++--- meter.h | 2 +- new_protocol.c | 6 ++---- old_protocol.c | 38 ++++++++++---------------------------- radio.c | 16 ++++++++++++---- radio.h | 2 +- receiver.c | 8 -------- receiver.h | 2 +- rigctl.c | 13 ++++++------- rx_panadapter.c | 8 ++++---- sliders.c | 30 +++++++++++++++++++----------- vfo_menu.c | 2 +- waterfall.c | 2 +- 16 files changed, 65 insertions(+), 77 deletions(-) diff --git a/Makefile b/Makefile index 93917ec..d0b4fcd 100644 --- a/Makefile +++ b/Makefile @@ -422,5 +422,5 @@ install: $(PROGRAM) release: $(PROGRAM) cp $(PROGRAM) release/pihpsdr cd release; tar cvf pihpsdr.tar pihpsdr - cd release; tar cvf pihpsdr-v1.2.tar pihpsdr + cd release; tar cvf pihpsdr-$(GIT_VERSION).tar pihpsdr diff --git a/freqent_menu.c b/freqent_menu.c index 004d984..d47578a 100644 --- a/freqent_menu.c +++ b/freqent_menu.c @@ -41,7 +41,7 @@ static GtkWidget *label; static char *btn_labels[] = {"1","2","3","4", "5","6","7","8", "9","0",".","BS", - "HZ","KZ","MZ","CR" + "Hz","kHz","MHz","CR" }; static void cleanup() { diff --git a/gpio.c b/gpio.c index ffed31e..640f61b 100644 --- a/gpio.c +++ b/gpio.c @@ -921,7 +921,7 @@ static encoder_changed(int action,int pos) { set_agc_gain(value); break; case ENCODER_ATTENUATION: - value=active_receiver->attenuation; + value=adc_attenuation[active_receiver->adc]; value+=pos; if(value<0) { value=0; diff --git a/meter.c b/meter.c index cd6c9cb..358c851 100644 --- a/meter.c +++ b/meter.c @@ -24,6 +24,7 @@ #include #include +#include "receiver.h" #include "meter.h" #include "wdsp.h" #include "radio.h" @@ -212,7 +213,7 @@ fprintf(stderr,"meter_init: width=%d height=%d\n",width,height); } -void meter_update(int meter_type,double value,double reverse,double exciter,double alc) { +void meter_update(RECEIVER *rx,int meter_type,double value,double reverse,double exciter,double alc) { char text[128]; char sf[32]; @@ -230,7 +231,7 @@ if(analog_meter) { switch(meter_type) { case SMETER: { - double level=value+(double)get_attenuation(); + double level=value+(double)adc_attenuation[rx->adc]; offset=210.0; int i; @@ -527,7 +528,7 @@ if(analog_meter) { // value is dBm text_location=10; offset=5.0; - double level=value+(double)get_attenuation(); + double level=value+(double)adc_attenuation[rx->adc]; if(meter_width>=114) { //int db=meter_width/114; // S9+60 (9*6)+60 //if(db>2) db=2; diff --git a/meter.h b/meter.h index aa98deb..720a49a 100644 --- a/meter.h +++ b/meter.h @@ -30,6 +30,6 @@ extern GtkWidget* meter_init(int width,int height,GtkWidget *parent); -extern void meter_update(int meter_type,double value,double reverse,double exciter,double alc); +extern void meter_update(RECEIVER *rx,int meter_type,double value,double reverse,double exciter,double alc); #endif diff --git a/new_protocol.c b/new_protocol.c index e573ae0..33e45d4 100644 --- a/new_protocol.c +++ b/new_protocol.c @@ -854,10 +854,8 @@ static void new_protocol_high_priority() { if(isTransmitting()) { high_priority_buffer_to_radio[1443]=transmitter->attenuation; } else { - for(r=0;rattenuation; - } + high_priority_buffer_to_radio[1443]=adc_attenuation[0]; + high_priority_buffer_to_radio[1442]=adc_attenuation[1]; } int rc; diff --git a/old_protocol.c b/old_protocol.c index 4dbbb36..80bd469 100644 --- a/old_protocol.c +++ b/old_protocol.c @@ -144,6 +144,8 @@ static int psk_samples=0; static int psk_divisor=6; #endif +static int local_ptt=0; + static double micinputbuffer[MAX_BUFFER_SIZE*2]; static int left_rx_sample; @@ -489,43 +491,23 @@ static void process_ozy_input_buffer(char *buffer) { control_in[3]=buffer[b++]; control_in[4]=buffer[b++]; - previous_ptt=ptt; + previous_ptt=local_ptt; + //previous_ptt=ptt; previous_dot=dot; previous_dash=dash; ptt=(control_in[0]&0x01)==0x01; dash=(control_in[0]&0x02)==0x02; dot=(control_in[0]&0x04)==0x04; -/* -if(ptt!=previous_ptt) { - fprintf(stderr,"ptt=%d\n",ptt); -} -if(dot!=previous_dot) { - fprintf(stderr,"dot=%d\n",dot); -} -if(dash!=previous_dash) { - fprintf(stderr,"dash=%d\n",dash); -} - if(previous_ptt!=ptt && vfo[tx_vfo].mode!=modeCWU && vfo[tx_vfo].mode!=modeCWL) { - g_idle_add(ext_ptt_update,(gpointer)(long)(ptt)); - } else if(previous_dot!=dot && (vfo[tx_vfo].mode==modeCWU || vfo[tx_vfo].mode==modeCWL)) { - g_idle_add(ext_ptt_update,(gpointer)(long)(dot)); - } else if(previous_dash!=dash && (vfo[tx_vfo].mode==modeCWU || vfo[tx_vfo].mode==modeCWL)) { - g_idle_add(ext_ptt_update,(gpointer)(long)(dash)); - } -*/ - + local_ptt=dot; if(vfo[tx_vfo].mode==modeCWL || vfo[tx_vfo].mode==modeCWU) { - if(dot==0 && dash==0) { - ptt=0; - } + local_ptt=ptt|dot|dash; } - - if(previous_ptt!=ptt) { -//fprintf(stderr,"ptt=%d previous_ptt=%d dot=%d dash=%d vfo=%d mode=%d\n",ptt,previous_ptt,dot,dash,tx_vfo,vfo[tx_vfo].mode); + if(previous_ptt!=local_ptt) { g_idle_add(ext_ptt_update,(gpointer)(long)(ptt)); } + switch((control_in[0]>>3)&0x1F) { case 0: adc_overload=control_in[1]&0x01; @@ -1038,7 +1020,7 @@ void ozy_send_buffer() { output_buffer[C3]=0x00; if(radio->device==DEVICE_HERMES || radio->device==DEVICE_ANGELIA || radio->device==DEVICE_ORION || radio->device==DEVICE_ORION2) { - output_buffer[C4]=0x20|receiver[0]->attenuation; + output_buffer[C4]=0x20|adc_attenuation[receiver[0]->adc]; } else { output_buffer[C4]=0x00; } @@ -1049,7 +1031,7 @@ void ozy_send_buffer() { output_buffer[C1]=0x00; if(receivers==2) { if(radio->device==DEVICE_HERMES || radio->device==DEVICE_ANGELIA || radio->device==DEVICE_ORION || radio->device==DEVICE_ORION2) { - output_buffer[C1]=0x20|receiver[1]->attenuation; + output_buffer[C1]=0x20|adc_attenuation[receiver[1]->adc]; } } output_buffer[C2]=0x00; diff --git a/radio.c b/radio.c index 18f7fcb..35f4bed 100644 --- a/radio.c +++ b/radio.c @@ -466,6 +466,9 @@ fprintf(stderr,"title: length=%d\n", (int)strlen(text)); } + adc_attenuation[0]=0; + adc_attenuation[1]=0; + //fprintf(stderr,"meter_calibration=%f display_calibration=%f\n", meter_calibration, display_calibration); radioRestoreState(); @@ -1035,10 +1038,6 @@ void set_attenuation(int value) { } } -int get_attenuation() { - return active_receiver->attenuation; -} - void set_alex_rx_antenna(int v) { if(active_receiver->id==0) { active_receiver->alex_antenna=v; @@ -1265,6 +1264,11 @@ fprintf(stderr,"radioRestoreState: %s\n",property_path); value=getProperty("rigctl_port_base"); if(value) rigctl_port_base=atoi(value); + value=getProperty("adc_0_attenuation"); + if(value) adc_attenuation[0]=atoi(value); + value=getProperty("adc_1_attenuation"); + if(value) adc_attenuation[1]=atoi(value); + sem_post(&property_sem); } @@ -1427,6 +1431,10 @@ void radioSaveState() { setProperty("e3_encoder_action",value); #endif + sprintf(value,"%d",adc_attenuation[0]); + setProperty("adc_0_attenuation",value); + sprintf(value,"%d",adc_attenuation[1]); + setProperty("adc_1_attenuation",value); vfo_save_state(); sprintf(value,"%d",receivers); diff --git a/radio.h b/radio.h index 5ca4ca0..9130f0e 100644 --- a/radio.h +++ b/radio.h @@ -142,6 +142,7 @@ extern int mic_ptt_tip_bias_ring; int receivers; int adc[2]; +int adc_attenuation[2]; int locked; @@ -268,7 +269,6 @@ extern void calcTuneDriveLevel(); extern void setSquelch(RECEIVER *rx); extern void set_attenuation(int value); -extern int get_attenuation(); extern void set_alex_rx_antenna(int v); extern void set_alex_tx_antenna(int v); extern void set_alex_attenuation(int v); diff --git a/receiver.c b/receiver.c index 197252c..af09dd2 100644 --- a/receiver.c +++ b/receiver.c @@ -221,9 +221,6 @@ void receiver_save_state(RECEIVER *rx) { sprintf(name,"receiver.%d.agc_hang_threshold",rx->id); sprintf(value,"%f",rx->agc_hang_threshold); setProperty(name,value); - sprintf(name,"receiver.%d.attenuation",rx->id); - sprintf(value,"%d",rx->attenuation); - setProperty(name,value); sprintf(name,"receiver.%d.dither",rx->id); sprintf(value,"%d",rx->dither); @@ -380,9 +377,6 @@ fprintf(stderr,"receiver_restore_state: id=%d\n",rx->id); sprintf(name,"receiver.%d.agc_hang_threshold",rx->id); value=getProperty(name); if(value) rx->agc_hang_threshold=atof(value); - sprintf(name,"receiver.%d.attenuation",rx->id); - value=getProperty(name); - if(value) rx->attenuation=atoi(value); sprintf(name,"receiver.%d.dither",rx->id); value=getProperty(name); @@ -775,7 +769,6 @@ fprintf(stderr,"create_pure_signal_receiver: id=%d buffer_size=%d\n",id,buffer_s rx->panadapter_low=-140; rx->volume=0.0; - rx->attenuation=0; rx->dither=0; rx->random=0; @@ -911,7 +904,6 @@ fprintf(stderr,"create_receiver: id=%d default ddc=%d adc=%d\n",rx->id, rx->ddc, rx->waterfall_automatic=1; rx->volume=0.1; - rx->attenuation=0; rx->dither=0; rx->random=0; diff --git a/receiver.h b/receiver.h index 58546af..90e6f7d 100644 --- a/receiver.h +++ b/receiver.h @@ -82,7 +82,7 @@ typedef struct _receiver { int nr2_ae; - int attenuation; + //int attenuation; int alex_antenna; int alex_attenuation; diff --git a/rigctl.c b/rigctl.c index adb52a4..7ff3703 100644 --- a/rigctl.c +++ b/rigctl.c @@ -2800,7 +2800,7 @@ void parse_cmd ( char * cmd_input,int len,int client_sock) { float calc_atten; if(len <=2) { //send_resp(client_sock,"RA0000;"); - calc_atten = round((float)active_receiver->attenuation*99.0/30.0); + calc_atten = round((float)adc_attenuation[active_receiver->adc]*99.0/30.0); if(calc_atten > 99.0) { calc_atten = 99.0; } @@ -3064,20 +3064,19 @@ void parse_cmd ( char * cmd_input,int len,int client_sock) { // PowerSDR returns S9=0015 code. // Let's make S9 half scale or a value of 70. double level=0.0; + int r=0; if(cmd_input[2] == '0') { - level = GetRXAMeter(receiver[0]->id, smeter); + r=0; } else if(cmd_input[2] == '1') { - if(receivers==2) { - level = GetRXAMeter(receiver[1]->id, smeter); - } + r=1; } + level = GetRXAMeter(receiver[r]->id, smeter); - level = GetRXAMeter(active_receiver->id, smeter); // Determine how high above 127 we are..making a range of 114 from S0 to S9+60db // 5 is a fugdge factor that shouldn't be there - but seems to get us to S9=SM015 - level = abs(127+(level + (double) get_attenuation()))+5; + level = abs(127+(level + (double)adc_attenuation[receiver[r]->adc]))+5; // Clip the value just in case if(cmd_input[2] == '0') { diff --git a/rx_panadapter.c b/rx_panadapter.c index 4e82d19..7b91d92 100644 --- a/rx_panadapter.c +++ b/rx_panadapter.c @@ -293,12 +293,12 @@ void rx_panadapter_update(RECEIVER *rx) { GetRXAAGCHangLevel(rx->id, &hang); GetRXAAGCThresh(rx->id, &thresh, 4096.0, (double)rx->sample_rate); - double knee_y=thresh+(double)get_attenuation(); + double knee_y=thresh+(double)adc_attenuation[rx->adc]; knee_y = floor((rx->panadapter_high - knee_y) * (double) display_height / (rx->panadapter_high - rx->panadapter_low)); - double hang_y=hang+(double)get_attenuation(); + double hang_y=hang+(double)adc_attenuation[rx->adc]; hang_y = floor((rx->panadapter_high - hang_y) * (double) display_height / (rx->panadapter_high - rx->panadapter_low)); @@ -352,13 +352,13 @@ void rx_panadapter_update(RECEIVER *rx) { samples[0]=-200.0; samples[display_width-1]=-200.0; - s1=(double)samples[0]+(double)get_attenuation(); + s1=(double)samples[0]+(double)adc_attenuation[rx->adc]; s1 = floor((rx->panadapter_high - s1) * (double) display_height / (rx->panadapter_high - rx->panadapter_low)); cairo_move_to(cr, 0.0, s1); for(i=1;iadc]; s2 = floor((rx->panadapter_high - s2) * (double) display_height / (rx->panadapter_high - rx->panadapter_low)); diff --git a/sliders.c b/sliders.c index b91cb49..7588a36 100644 --- a/sliders.c +++ b/sliders.c @@ -100,7 +100,11 @@ int sliders_active_receiver_changed(void *data) { if(display_sliders) { gtk_range_set_value(GTK_RANGE(af_gain_scale),active_receiver->volume*100.0); gtk_range_set_value (GTK_RANGE(agc_scale),active_receiver->agc_gain); - gtk_range_set_value (GTK_RANGE(attenuation_scale),active_receiver->attenuation); + gtk_range_set_value (GTK_RANGE(attenuation_scale),adc_attenuation[active_receiver->adc]); + + char title[64]; + sprintf(title,"ATT (dB)"/*,active_receiver->adc*/); + gtk_label_set_text(GTK_LABEL(attenuation_label),title); sliders_update(); } return FALSE; @@ -113,14 +117,14 @@ int scale_timeout_cb(gpointer data) { } static void attenuation_value_changed_cb(GtkWidget *widget, gpointer data) { - active_receiver->attenuation=(int)gtk_range_get_value(GTK_RANGE(attenuation_scale)); - set_attenuation(active_receiver->attenuation); + adc_attenuation[active_receiver->adc]=(int)gtk_range_get_value(GTK_RANGE(attenuation_scale)); + set_attenuation(adc_attenuation[active_receiver->adc]); } void set_attenuation_value(double value) { - active_receiver->attenuation=(int)value; + adc_attenuation[active_receiver->adc]=(int)value; if(display_sliders) { - gtk_range_set_value (GTK_RANGE(attenuation_scale),active_receiver->attenuation); + gtk_range_set_value (GTK_RANGE(attenuation_scale),adc_attenuation[active_receiver->adc]); } else { if(scale_status!=ATTENUATION) { if(scale_status!=NONE) { @@ -130,12 +134,14 @@ void set_attenuation_value(double value) { } } if(scale_status==NONE) { + char title[64]; + sprintf(title,"Attenuation - ADC-%d (dB)",active_receiver->adc); scale_status=ATTENUATION; - scale_dialog=gtk_dialog_new_with_buttons("Attenuation (dB)",GTK_WINDOW(top_window),GTK_DIALOG_DESTROY_WITH_PARENT,NULL,NULL); + scale_dialog=gtk_dialog_new_with_buttons(title,GTK_WINDOW(top_window),GTK_DIALOG_DESTROY_WITH_PARENT,NULL,NULL); GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(scale_dialog)); attenuation_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0, 31.0, 1.00); gtk_widget_set_size_request (attenuation_scale, 400, 30); - gtk_range_set_value (GTK_RANGE(attenuation_scale),active_receiver->attenuation); + gtk_range_set_value (GTK_RANGE(attenuation_scale),adc_attenuation[active_receiver->adc]); gtk_widget_show(attenuation_scale); gtk_container_add(GTK_CONTAINER(content),attenuation_scale); scale_timer=g_timeout_add(2000,scale_timeout_cb,NULL); @@ -143,11 +149,11 @@ void set_attenuation_value(double value) { int result=gtk_dialog_run(GTK_DIALOG(scale_dialog)); } else { g_source_remove(scale_timer); - gtk_range_set_value (GTK_RANGE(attenuation_scale),active_receiver->attenuation); + gtk_range_set_value (GTK_RANGE(attenuation_scale),adc_attenuation[active_receiver->adc]); scale_timer=g_timeout_add(2000,scale_timeout_cb,NULL); } } - set_attenuation(active_receiver->attenuation); + set_attenuation(adc_attenuation[active_receiver->adc]); } static void agcgain_value_changed_cb(GtkWidget *widget, gpointer data) { @@ -481,12 +487,14 @@ fprintf(stderr,"sliders_init: width=%d height=%d\n", width,height); gtk_grid_attach(GTK_GRID(sliders),agc_scale,4,0,2,1); g_signal_connect(G_OBJECT(agc_scale),"value_changed",G_CALLBACK(agcgain_value_changed_cb),NULL); - attenuation_label=gtk_label_new("ATT (dB):"); + char title[64]; + sprintf(title,"ATT (dB)"/*,active_receiver->adc*/); + attenuation_label=gtk_label_new(title); gtk_widget_show(attenuation_label); gtk_grid_attach(GTK_GRID(sliders),attenuation_label,6,0,1,1); attenuation_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0, 31.0, 1.0); - gtk_range_set_value (GTK_RANGE(attenuation_scale),active_receiver->attenuation); + gtk_range_set_value (GTK_RANGE(attenuation_scale),adc_attenuation[active_receiver->adc]); gtk_widget_show(attenuation_scale); gtk_grid_attach(GTK_GRID(sliders),attenuation_scale,7,0,2,1); g_signal_connect(G_OBJECT(attenuation_scale),"value_changed",G_CALLBACK(attenuation_value_changed_cb),NULL); diff --git a/vfo_menu.c b/vfo_menu.c index 5afcdc5..ad20013 100644 --- a/vfo_menu.c +++ b/vfo_menu.c @@ -48,7 +48,7 @@ static char *btn_labels[] = {"1","2","3", "4","5","6", "7","8","9", ".","0","BS", - "HZ","KZ","MZ" + "Hz","kHz","MHz" ,"CL" }; diff --git a/waterfall.c b/waterfall.c index 4f75027..b673f80 100644 --- a/waterfall.c +++ b/waterfall.c @@ -173,7 +173,7 @@ void waterfall_update(RECEIVER *rx) { p=pixels; samples=rx->pixel_samples; for(i=0;iadc]; average+=(int)sample; if(sample<(float)rx->waterfall_low) { *p++=colorLowR; -- 2.45.2