]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Fix sample rate change crash.
authorJohn Melton G0ORX <john.d.melton@googlemail.com>
Thu, 19 Mar 2020 12:25:09 +0000 (12:25 +0000)
committerJohn Melton G0ORX <john.d.melton@googlemail.com>
Thu, 19 Mar 2020 12:25:09 +0000 (12:25 +0000)
Display Temperature and PA current for Hermes Lite 2.

new_protocol.h
old_discovery.c
old_protocol.c
radio.c
radio.h
receiver.c
rx_panadapter.c
tx_panadapter.c

index bdc6ba2e0fb9d04a5379e7a0d33d8c8b0b96f299..2300386fcb90ccd62586b6582c74964648e6bfcb 100644 (file)
@@ -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;
index 9d53a32743aee0fc5a58e698ae0b181333c99050..cab68f4e7798641762b4f97152c1fb86353cbf54 100644 (file)
@@ -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;
index 2d9e6abed08769f271083900595a43d8a3272bdd..498ad7d7ea9c1dc628e39161135e7919d163fc21 100644 (file)
@@ -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;
@@ -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;
     }
 
diff --git a/radio.c b/radio.c
index e4536f7507ce1c3ceaf09291f7cd84a2602cecc8..d173d353514ddd577614947d46d98604fba5a886 100644 (file)
--- a/radio.c
+++ b/radio.c
@@ -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;
@@ -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();
 
 //
diff --git a/radio.h b/radio.h
index 53aa27aaf71fd2cfff6d197af2156e0889ccca3b..3b4127b11c3f4d30063b84f94d2a87ceb36fcf87 100644 (file)
--- a/radio.h
+++ b/radio.h
@@ -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;
index 5f9b518cf12bc09e4a25d703e69539c2763fd1de..4ebe1d2ff0319ab120b4c409911fa34337c77be8 100644 (file)
@@ -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;
   }
@@ -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;
@@ -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;
@@ -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;
   }
@@ -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);
@@ -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);
@@ -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;
@@ -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) {
@@ -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);
 }
 
index 682ac7789c36a8fb10e1557e1c00a879a45b7264..f6e41f31d189dae9c4c339fd776759d22f99d89c 100644 (file)
@@ -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;
@@ -528,25 +529,24 @@ 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);
     }
@@ -554,29 +554,31 @@ void rx_panadapter_update(RECEIVER *rx) {
 #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);
index fe2fa9f408153e388206bf42e35924bda028bb3c..f4b5a67338f5026d16719d1e51f28ba8877574b2 100644 (file)
@@ -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);
     }
@@ -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);