Skip to content

Commit

Permalink
Fix sample rate change crash.
Browse files Browse the repository at this point in the history
Display Temperature and PA current for Hermes Lite 2.
  • Loading branch information
g0orx committed Mar 19, 2020
1 parent 9e9bfcd commit eae3eea
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 31 deletions.
2 changes: 2 additions & 0 deletions new_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ extern long response_sequence;
// DL1YCF: "response" is global (used in new_protocol_programmer.c)
extern int response;

/*
extern unsigned int exciter_power;
extern unsigned int alex_forward_power;
extern unsigned int alex_reverse_power;
*/

/*
extern int send_high_priority;
Expand Down
1 change: 1 addition & 0 deletions old_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ fprintf(stderr,"discover_receive_thread\n");
} else {
strcpy(discovered[devices].name,"HermesLite V2");
discovered[devices].device = DEVICE_HERMES_LITE2;
g_print("discovered HL2: Gateware Major Version=%d Minor Version=%d\n",buffer[9],buffer[15]);
}
discovered[devices].frequency_min=0.0;
discovered[devices].frequency_max=30720000.0;
Expand Down
27 changes: 23 additions & 4 deletions old_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,6 @@ static void process_ozy_input_buffer(unsigned char *buffer) {
g_idle_add(ext_mox_update,(gpointer)(long)(local_ptt));
}


switch((control_in[0]>>3)&0x1F) {
case 0:
adc_overload=control_in[1]&0x01;
Expand Down Expand Up @@ -869,18 +868,38 @@ static void process_ozy_input_buffer(unsigned char *buffer) {
// HL2 uses C1/C2 for measuring the temperature
//
exciter_power=((control_in[1]&0xFF)<<8)|(control_in[2]&0xFF); // from Penelope or Hermes
temperature=0;
} else {
exciter_power=0;
temperature+=((control_in[1]&0xFF)<<8)|(control_in[2]&0xFF); // HL2
n_temperature++;
if(n_temperature==10) {
average_temperature=temperature/10;
temperature=0;
n_temperature=0;
}
}
alex_forward_power=((control_in[3]&0xFF)<<8)|(control_in[4]&0xFF); // from Alex or Apollo
break;
case 2:
alex_reverse_power=((control_in[1]&0xFF)<<8)|(control_in[2]&0xFF); // from Alex or Apollo
AIN3=(control_in[3]<<8)+control_in[4]; // from Pennelope or Hermes
if (device != DEVICE_HERMES_LITE2) {
AIN3=((control_in[3]&0xFF)<<8)|(control_in[4]&0xFF); // For Penelope or Hermes
current=0;
} else {
AIN3=0;
current+=((control_in[3]&0xFF)<<8)|(control_in[4]&0xFF); // HL2
n_current++;
if(n_current==10) {
average_current=current/10;
current=0;
n_current=0;
}
}
break;
case 3:
AIN4=(control_in[1]<<8)+control_in[2]; // from Pennelope or Hermes
AIN6=(control_in[3]<<8)+control_in[4]; // from Pennelope or Hermes
AIN4=((control_in[1]&0xFF)<<8)|(control_in[2]&0xFF); // For Penelope or Hermes
AIN6=((control_in[3]&0xFF)<<8)|(control_in[4]&0xFF); // For Penelope or Hermes
break;
}

Expand Down
13 changes: 13 additions & 0 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ int dash;
int adc_overload;
int pll_locked;
unsigned int exciter_power;
unsigned int temperature;
unsigned int average_temperature;
unsigned int n_temperature;
unsigned int current;
unsigned int average_current;
unsigned int n_current;
unsigned int alex_forward_power;
unsigned int alex_reverse_power;
unsigned int AIN3;
Expand Down Expand Up @@ -928,6 +934,13 @@ void start_radio() {
display_toolbar=1;
#endif

temperature=0;
average_temperature=0;
n_temperature=0;
current=0;
average_current=0;
n_current=0;

radioRestoreState();

//
Expand Down
6 changes: 6 additions & 0 deletions radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ extern int full_tune;
extern int adc_overload;
extern int pll_locked;
extern unsigned int exciter_power;
extern unsigned int temperature;
extern unsigned int average_temperature;
extern unsigned int n_temperature;
extern unsigned int current;
extern unsigned int average_current;
extern unsigned int n_current;
extern unsigned int alex_forward_power;
extern unsigned int alex_reverse_power;
extern unsigned int IO1;
Expand Down
12 changes: 6 additions & 6 deletions receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ void set_displaying(RECEIVER *rx,int state) {
rx->displaying=state;
if(state) {
if(rx->update_timer_id>=0) g_source_remove(rx->update_timer_id);
rx->update_timer_id=g_timeout_add_full(G_PRIORITY_HIGH_IDLE,1000/rx->fps, update_display, rx, NULL);
rx->update_timer_id=gdk_threads_add_timeout_full(G_PRIORITY_HIGH_IDLE,1000/rx->fps, update_display, rx, NULL);
} else {
rx->update_timer_id=-1;
}
Expand Down Expand Up @@ -879,7 +879,6 @@ fprintf(stderr,"create_receiver: id=%d buffer_size=%d fft_size=%d pixels=%d fps=
rx->id=id;
g_mutex_init(&rx->mutex);
g_mutex_init(&rx->display_mutex);
fprintf(stderr,"create_receiver: g_mutex_init: %p\n",&rx->mutex);
switch(id) {
case 0:
rx->adc=0;
Expand Down Expand Up @@ -1117,7 +1116,6 @@ void receiver_change_sample_rate(RECEIVER *rx,int sample_rate) {
//

g_mutex_lock(&rx->mutex);
fprintf(stderr,"receiver_change_sample_rate: g_mutex_lock: %p\n",&rx->mutex);

rx->sample_rate=sample_rate;
int scale=rx->sample_rate/48000;
Expand All @@ -1139,7 +1137,6 @@ g_print("receiver_change_sample_rate: id=%d rate=%d scale=%d buffer_size=%d outp
init_analyzer(rx);
fprintf(stderr,"PS FEEDBACK change sample rate:id=%d rate=%d buffer_size=%d output_samples=%d\n",
rx->id, rx->sample_rate, rx->buffer_size, rx->output_samples);
fprintf(stderr,"receiver_change_sample_rate: g_mutex_unlock: %p\n",&rx->mutex);
g_mutex_unlock(&rx->mutex);
return;
}
Expand All @@ -1163,7 +1160,6 @@ fprintf(stderr,"receiver_change_sample_rate: g_mutex_unlock: %p\n",&rx->mutex);

SetChannelState(rx->id,1,0);

fprintf(stderr,"receiver_change_sample_rate: g_mutex_unlock: %p\n",&rx->mutex);
g_mutex_unlock(&rx->mutex);

fprintf(stderr,"receiver_change_sample_rate: id=%d rate=%d buffer_size=%d output_samples=%d\n",rx->id, rx->sample_rate, rx->buffer_size, rx->output_samples);
Expand Down Expand Up @@ -1337,6 +1333,8 @@ static void process_rx_buffer(RECEIVER *rx) {
void full_rx_buffer(RECEIVER *rx) {
int error;

g_mutex_lock(&rx->mutex);

// noise blanker works on original IQ samples
if(rx->nb) {
xanbEXT (rx->id, rx->iq_input_buffer, rx->iq_input_buffer);
Expand All @@ -1359,6 +1357,7 @@ void full_rx_buffer(RECEIVER *rx) {

//g_print("full_rx_buffer: rx=%d buffer_size=%d samples=%d\n",rx->id,rx->buffer_size,rx->samples);
process_rx_buffer(rx);
g_mutex_unlock(&rx->mutex);
}

static int rx_buffer_seen=0;
Expand Down Expand Up @@ -1395,7 +1394,7 @@ void receiver_change_zoom(RECEIVER *rx,double zoom) {
rx->pixel_samples=g_new(float,rx->pixels);
rx->hz_per_pixel=(double)rx->sample_rate/(double)rx->pixels;
rx->zoom=(int)zoom;
if(rx->zoom==1) {
if(zoom==1) {
rx->pan=0;
} else {
if(vfo[rx->id].ctun) {
Expand All @@ -1407,6 +1406,7 @@ void receiver_change_zoom(RECEIVER *rx,double zoom) {
rx->pan=(rx->pixels/2)-(rx->width/2);
}
}
rx->zoom=(int)zoom;
init_analyzer(rx);
}

Expand Down
38 changes: 20 additions & 18 deletions rx_panadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void rx_panadapter_update(RECEIVER *rx) {
int i;
int x1,x2;
float *samples;
char text[64];
cairo_text_extents_t extents;

gboolean active=active_receiver==rx;
Expand Down Expand Up @@ -528,55 +529,56 @@ void rx_panadapter_update(RECEIVER *rx) {
cairo_stroke(cr);

#ifdef GPIO
if(active && controller==CONTROLLER1) {
char text[64];
if(rx->id==0 && controller==CONTROLLER1) {

cairo_set_source_rgb(cr,1.0,1.0,0.0);
cairo_set_font_size(cr,16);
if(ENABLE_E2_ENCODER) {
cairo_move_to(cr, display_width-200,30);
cairo_move_to(cr, display_width-200,70);
sprintf(text,"%s (%s)",encoder_string[e2_encoder_action],sw_string[e2_sw_action]);
cairo_show_text(cr, text);
}

if(ENABLE_E3_ENCODER) {
cairo_move_to(cr, display_width-200,50);
cairo_move_to(cr, display_width-200,90);
sprintf(text,"%s (%s)",encoder_string[e3_encoder_action],sw_string[e3_sw_action]);
cairo_show_text(cr, text);
}

if(ENABLE_E4_ENCODER) {
cairo_move_to(cr, display_width-200,70);
cairo_move_to(cr, display_width-200,110);
sprintf(text,"%s (%s)",encoder_string[e4_encoder_action],sw_string[e4_sw_action]);
cairo_show_text(cr, text);
}
}
#endif

if(sequence_errors!=0) {
cairo_move_to(cr,100,20);
cairo_move_to(cr,100.0,50.0);
cairo_set_source_rgb(cr,1.0,0.0,0.0);
cairo_set_font_size(cr,12);
cairo_show_text(cr, "Sequence Error");
sequence_error_count++;
// show for 1 second
// show for 2 second
if(sequence_error_count==2*rx->fps) {
sequence_errors=0;
sequence_error_count=0;
}
}

if(rx->fexchange_errors!=0) {
cairo_move_to(cr,100,30);
cairo_set_source_rgb(cr,1.0,0.0,0.0);
cairo_set_font_size(cr,12);
cairo_show_text(cr, "fexchange Error");
fexchange_error_count++;
// show for 1 second
if(fexchange_error_count==2*rx->fps) {
rx->fexchange_errors=0;
fexchange_error_count=0;
}
if(rx->id==0 && protocol==ORIGINAL_PROTOCOL && device==DEVICE_HERMES_LITE2) {
cairo_set_source_rgb(cr,1.0,1.0,0.0);
cairo_set_font_size(cr,16);

double t = (3.26 * ((double)average_temperature / 4096.0) - 0.5) / 0.01;
sprintf(text,"%0.1fC",t);
cairo_move_to(cr, 100.0, 30.0);
cairo_show_text(cr, text);

double c = (((3.26 * ((double)average_current / 4096.0)) / 50.0) / 0.04 * 1000 * 1270 / 1000);
sprintf(text,"%0.0fmA",c);
cairo_move_to(cr, 160.0, 30.0);
cairo_show_text(cr, text);
}

cairo_destroy (cr);
Expand Down
22 changes: 19 additions & 3 deletions tx_panadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,19 +357,19 @@ void tx_panadapter_update(TRANSMITTER *tx) {
cairo_set_source_rgb(cr,1.0,1.0,0.0);
cairo_set_font_size(cr,16);
if(ENABLE_E2_ENCODER) {
cairo_move_to(cr, display_width-200,30);
cairo_move_to(cr, display_width-200,70);
sprintf(text,"%s (%s)",encoder_string[e2_encoder_action],sw_string[e2_sw_action]);
cairo_show_text(cr, text);
}

if(ENABLE_E3_ENCODER) {
cairo_move_to(cr, display_width-200,50);
cairo_move_to(cr, display_width-200,90);
sprintf(text,"%s (%s)",encoder_string[e3_encoder_action],sw_string[e3_sw_action]);
cairo_show_text(cr, text);
}

if(ENABLE_E4_ENCODER) {
cairo_move_to(cr, display_width-200,70);
cairo_move_to(cr, display_width-200,110);
sprintf(text,"%s (%s)",encoder_string[e4_encoder_action],sw_string[e4_sw_action]);
cairo_show_text(cr, text);
}
Expand Down Expand Up @@ -427,6 +427,22 @@ void tx_panadapter_update(TRANSMITTER *tx) {
*/
}

if(tx->dialog==NULL && protocol==ORIGINAL_PROTOCOL && device==DEVICE_HERMES_LITE2) {
char text[64];
cairo_set_source_rgb(cr,1.0,1.0,0.0);
cairo_set_font_size(cr,16);

double t = (3.26 * ((double)average_temperature / 4096.0) - 0.5) / 0.01;
sprintf(text,"%0.1fC",t);
cairo_move_to(cr, 100.0, 30.0);
cairo_show_text(cr, text);

double c = (((3.26 * ((double)average_current / 4096.0)) / 50.0) / 0.04 * 1000 * 1270 / 1000);
sprintf(text,"%0.0fmA",c);
cairo_move_to(cr, 160.0, 30.0);
cairo_show_text(cr, text);
}

cairo_destroy (cr);
gtk_widget_queue_draw (tx->panadapter);

Expand Down

0 comments on commit eae3eea

Please sign in to comment.