From e72cea45d39444c4f5b406ad52e0c71a5e141ff7 Mon Sep 17 00:00:00 2001
From: c vw <chwu@macintosh.speedport.ip>
Date: Sat, 10 Aug 2019 14:38:31 +0200
Subject: [PATCH] finalized antenna routing

---
 ant_menu.c     | 21 +++++++++++++++++++++
 hpsdrsim.c     | 10 +++++-----
 new_protocol.c | 46 ++++++++++++++++++++++++++++------------------
 old_protocol.c | 22 +++++++++++++++++++---
 radio_menu.c   | 22 ----------------------
 5 files changed, 73 insertions(+), 48 deletions(-)

diff --git a/ant_menu.c b/ant_menu.c
index 5641e52..3ea8d9b 100644
--- a/ant_menu.c
+++ b/ant_menu.c
@@ -241,6 +241,13 @@ static void xvtr_rb_cb(GtkWidget *widget,GdkEventButton *event, gpointer data) {
   show_xvtr();
 }
 
+static void newpa_cb(GtkWidget *widget, gpointer data) {
+  if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
+    new_pa_board=1;
+  } else {
+    new_pa_board=0;
+  }
+}
 
 void ant_menu(GtkWidget *parent) {
   parent_window=parent;
@@ -279,6 +286,20 @@ void ant_menu(GtkWidget *parent) {
   g_signal_connect(xvtr_rb,"toggled",G_CALLBACK(xvtr_rb_cb),NULL);
   gtk_grid_attach(GTK_GRID(grid),xvtr_rb,2,0,1,1);
 
+  if ((protocol == NEW_PROTOCOL      && (device == NEW_DEVICE_HERMES || device == NEW_DEVICE_ANGELIA || device == NEW_DEVICE_ORION)) ||
+      (protocol == ORIGINAL_PROTOCOL && (device == DEVICE_HERMES     || device == DEVICE_ANGELIA     || device == DEVICE_ORION))) {
+
+      //
+      // ANAN-100/200: There is an "old" (Rev. 15/16) and "new" (Rev. 24) PA board
+      //               around which differs in relay settings for using EXT1,2 and
+      //               differs in how to do PS feedback.
+      //
+      GtkWidget *new_pa_b = gtk_check_button_new_with_label("ANAN 100/200 new PA board");
+      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(new_pa_b), new_pa_board);
+      gtk_grid_attach(GTK_GRID(grid), new_pa_b, 3, 0, 1, 1);
+      g_signal_connect(new_pa_b, "toggled", G_CALLBACK(newpa_cb), NULL);
+  }
+
 
   if(protocol==ORIGINAL_PROTOCOL || protocol==NEW_PROTOCOL) {
     GtkWidget *rx_ant_label=gtk_label_new("Receive");
diff --git a/hpsdrsim.c b/hpsdrsim.c
index 0352032..4535a15 100644
--- a/hpsdrsim.c
+++ b/hpsdrsim.c
@@ -930,12 +930,12 @@ void process_ep2(uint8_t *frame)
 	case 19:
 	   chk_data(frame[1],txdrive,"TX DRIVE");
 	   chk_data(frame[2] & 0x3F,hermes_config,"HERMES CONFIG");
-	   chk_data(frame[2] & 0x40, alex_manual,"ALEX manual HPF/LPF");
-	   chk_data(frame[2] & 0x80, vna     ,"VNA mode");
+	   chk_data((frame[2] >> 6) & 0x01, alex_manual,"ALEX manual HPF/LPF");
+	   chk_data((frame[2] >> 7) & 0x01, vna     ,"VNA mode");
 	   chk_data(frame[3] & 0x1F,alex_hpf,"ALEX HPF");
-	   chk_data(frame[3] & 0x20,alex_bypass,"ALEX Bypass HPFs");
-	   chk_data(frame[3] & 0x40,lna6m,"ALEX 6m LNA");
-	   chk_data(frame[3] & 0x80,alexTRdisable,"ALEX T/R disable");
+	   chk_data((frame[3] >> 5) & 0x01,alex_bypass,"ALEX Bypass HPFs");
+	   chk_data((frame[3] >> 6) & 0x01,lna6m,"ALEX 6m LNA");
+	   chk_data((frame[3] >> 7) & 0x01,alexTRdisable,"ALEX T/R disable");
 	   chk_data(frame[4],alex_lpf,"ALEX LPF");
            // reset TX level. Leve a little head-room for noise
 	   txdrv_dbl=(double) txdrive * 0.00390625;  // div. by. 256
diff --git a/new_protocol.c b/new_protocol.c
index abf0c8c..0b06eb7 100644
--- a/new_protocol.c
+++ b/new_protocol.c
@@ -888,8 +888,7 @@ static void new_protocol_high_priority() {
 	i=0;  // flag used here for "filter bypass"
 	if (rxFrequency<1800000L) i=1;
 #ifdef PURESIGNAL
-	// Bypass HPFs (only) if using EXT1 for PURESIGNAL feedback!
-	// "relay chatter" is not necessary if using bypass input
+	// Bypass HPFs if using EXT1 for PURESIGNAL feedback!
 	if (isTransmitting() && transmitter->puresignal && receiver[PS_RX_FEEDBACK]->alex_antenna == 6) i=1;
 #endif
         if (i) {
@@ -970,43 +969,54 @@ static void new_protocol_high_priority() {
 	i=receiver[PS_RX_FEEDBACK]->alex_antenna;   	// 0, 6, or 7
     }
 #endif
-    if (device == NEW_DEVICE_ORION2) i +=100;
-    if (new_pa_board) i += 1000;
+    if (device == DEVICE_ORION2) {
+      i +=100;
+    } else if (new_pa_board) {
+      // New-PA setting invalid on ANAN-7000,8000
+      i +=1000;
+    }
     //
-    // There are combinations which the user may have selected but do not work,
-    // for example, using EXT1 for PS input on "new PA" or ANAN-7000 (i==106, 1006)
-    // and here we do not set any bit.
+    // There are several combination which do not exist (no jacket present)
+    // or which do not work (using EXT1-on-TX with ANAN-7000).
+    // In these cases, fall back to a "reasonable" case (e.g. use EXT1 if
+    // there is no EXT2).
+    // As a result, the "New PA board" setting is overriden for PURESIGNAL
+    // feedback: EXT1 assumes old PA board and ByPass assumes new PA board.
     //
     switch(i) {
-        case 3:		// EXT1 with old pa board
-	case 6:		// EXT1-on-TX with old pa board
+      case 3:           // EXT1 with old pa board
+      case 6:           // EXT1-on-TX with old pa board
+      case 1006:        // EXT1-on-TX with new pa board: impossible, *assume* old pa board present
           alex0 |= ALEX_RX_ANTENNA_EXT1 | ALEX_RX_ANTENNA_BYPASS;
           break;
-        case 4:		// EXT with old pa board
+      case 4:           // EXT2 with old pa board
           alex0 |= ALEX_RX_ANTENNA_EXT2 | ALEX_RX_ANTENNA_BYPASS;
           break;
-        case 5:		// XVTR with old pa board
+      case 5:           // XVTR with old pa board
             alex0 |= ALEX_RX_ANTENNA_XVTR | ALEX_RX_ANTENNA_BYPASS;
           break;
-	case 103:	// EXT1 with ANAN-7000
+      case 104:         // EXT2 with ANAN-7000: does not exit, use EXT2
+      case 103:         // EXT1 with ANAN-7000
           alex0 |= ALEX_RX_ANTENNA_EXT1 | ANAN7000_RX_SELECT;
 	  break;
-	case 105:	// XVTR with ANAN-7000
+      case 105:         // XVTR with ANAN-7000
 	  alex0 |= ALEX_RX_ANTENNA_XVTR | ANAN7000_RX_SELECT;
 	  break;
-	case 107:	// ByPass-on-TX with ANAN-7000
+      case 106:         // EXT1-on-TX with ANAN-7000: does not exist, use ByPass
+      case 107:         // Bypass-on-TX with ANAN-7000
           alex0 |= ALEX_RX_ANTENNA_BYPASS;
           break;
-        case 1003:	// EXT1 with new pa board
+      case 1003:        // EXT1 with new PA board
           alex0 |= ALEX_RX_ANTENNA_EXT1;
           break;
-        case 1004:	// EXT 2 with new pa board
+      case 1004:        // EXT2 with new PA board
           alex0 |= ALEX_RX_ANTENNA_EXT2;
           break;
-        case 1005:	// XVTR with new pa board
+      case 1005:        // XVRT with new PA board
             alex0 |= ALEX_RX_ANTENNA_XVTR;
 	    break;
-	case 1007:	// ByPass-on-TX with new pa board
+      case 7:           // Bypass-on-TX with old PA board: does not exist, *assume* new pa board present
+      case 1007:        // Bypass-on-TX with new PA board
           alex0 |= ALEX_RX_ANTENNA_BYPASS;
           break;
     }
diff --git a/old_protocol.c b/old_protocol.c
index ac92510..f63e35c 100644
--- a/old_protocol.c
+++ b/old_protocol.c
@@ -1134,11 +1134,24 @@ void ozy_send_buffer() {
 #ifdef PURESIGNAL
     if (isTransmitting() && transmitter->puresignal) i=receiver[PS_RX_FEEDBACK]->alex_antenna;
 #endif
-    if (device == DEVICE_ORION2) i +=100;
-    if (new_pa_board) i +=1000;
+    if (device == DEVICE_ORION2) {
+      i +=100;
+    } else if (new_pa_board) {
+      // New-PA setting invalid on ANAN-7000,8000
+      i +=1000;
+    }
+    //
+    // There are several combination which do not exist (no jacket present)
+    // or which do not work (using EXT1-on-TX with ANAN-7000).
+    // In these cases, fall back to a "reasonable" case (e.g. use EXT1 if
+    // there is no EXT2).
+    // As a result, the "New PA board" setting is overriden for PURESIGNAL
+    // feedback: EXT1 assumes old PA board and ByPass assumes new PA board.
+    //
     switch(i) {
       case 3: 		// EXT1 with old pa board
       case 6: 		// EXT1-on-TX with old pa board
+      case 1006:	// EXT1-on-TX with new pa board: impossible, *assume* old pa board present
         output_buffer[C3] |= 0xC0;
         break;
       case 4:		// EXT2 with old pa board
@@ -1147,12 +1160,14 @@ void ozy_send_buffer() {
       case 5:		// XVTR with old pa board
         output_buffer[C3] |= 0xE0;
         break;
+      case 104:		// EXT2 with ANAN-7000: does not exit, use EXT2
       case 103:		// EXT1 with ANAN-7000
         output_buffer[C3]|= 0x40;
         break;
       case 105:		// XVTR with ANAN-7000
         output_buffer[C3]|= 0x60;
         break;
+      case 106:		// EXT1-on-TX with ANAN-7000: does not exist, use ByPass
       case 107:		// Bypass-on-TX with ANAN-7000
         output_buffer[C3]|= 0x20;
 	break;
@@ -1165,6 +1180,7 @@ void ozy_send_buffer() {
       case 1005:	// XVRT with new PA board
         output_buffer[C3] |= 0x60;
 	break;
+      case 7:		// Bypass-on-TX with old PA board: does not exist, *assume* new pa board present
       case 1007:	// Bypass-on-TX with new PA board
         output_buffer[C3] |= 0x80;
 	break;
@@ -1300,7 +1316,7 @@ void ozy_send_buffer() {
         if (isTransmitting() && transmitter->puresignal && receiver[PS_RX_FEEDBACK]->alex_antenna == 6) {
           output_buffer[C2] |= 0x40;  // enable manual filter selection
           output_buffer[C3] &= 0x80;  // preserve ONLY "PA enable" bit and clear all filters including "6m LNA"
-          output_buffer[C3] |= 0x40;  // bypass all filters
+          output_buffer[C3] |= 0x20;  // bypass all filters
         }
 #endif
         }
diff --git a/radio_menu.c b/radio_menu.c
index 97e8719..9d40fdb 100644
--- a/radio_menu.c
+++ b/radio_menu.c
@@ -125,14 +125,6 @@ static void none_cb(GtkWidget *widget, gpointer data) {
   }
 }
 
-static void newpa_cb(GtkWidget *widget, gpointer data) {
-  if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
-    new_pa_board=1;
-  } else {
-    new_pa_board=0;
-  }
-}
-
 static void alex_cb(GtkWidget *widget, gpointer data) {
   if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
     filter_board = ALEX;
@@ -364,20 +356,6 @@ void radio_menu(GtkWidget *parent) {
     g_signal_connect(apollo_b, "toggled", G_CALLBACK(apollo_cb), NULL);
     g_signal_connect(charly25_b, "toggled", G_CALLBACK(charly25_cb), NULL);
 
-    if ((protocol == NEW_PROTOCOL      && (device == NEW_DEVICE_HERMES || device == NEW_DEVICE_ANGELIA || device == NEW_DEVICE_ORION)) ||
-        (protocol == ORIGINAL_PROTOCOL && (device == DEVICE_HERMES     || device == DEVICE_ANGELIA     || device == DEVICE_ORION))) {
-
-      //
-      // ANAN-100/200: There is an "old" (Rev. 15/16) and "new" (Rev. 24) PA board
-      //               around which differs in relay settings for using EXT1,2 and
-      //               differs in how to do PS feedback.
-      //
-      GtkWidget *new_pa_b = gtk_check_button_new_with_label("ANAN 100/200 new PA board");
-      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(new_pa_b), new_pa_board);
-      gtk_grid_attach(GTK_GRID(grid), new_pa_b, x, 6, 1, 1);
-      g_signal_connect(new_pa_b, "toggled", G_CALLBACK(newpa_cb), NULL);
-    }
-
     x++;
   }
 
-- 
2.45.2