From a0b2cdb9f43bca220fd97fac6b328435bb04e361 Mon Sep 17 00:00:00 2001
From: c vw <dl1ycf@darc.de>
Date: Thu, 30 May 2019 14:28:14 +0200
Subject: [PATCH] Fixed CW pulse shaping (exchanging I and Q), my ANAN-7000
 needs this.

---
 rigctl.c      | 5 +++--
 transmitter.c | 9 ++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/rigctl.c b/rigctl.c
index 052218f..e21ad82 100644
--- a/rigctl.c
+++ b/rigctl.c
@@ -550,9 +550,10 @@ static gpointer rigctl_cw_thread(gpointer data)
         g_idle_add(ext_mox_update ,(gpointer)1);
 	// have to wait until it is really there
 	// Note that if out-of-band, we would wait
-	// forever here, so allow at most 100 msec
+	// forever here, so allow at most 200 msec
+	// We also have to wait for cw_not_ready becoming zero
 	i=100;
-        while (!mox && i-- > 0) usleep(1000L);
+        while ((!mox || cw_not_ready) && i-- > 0) usleep(1000L);
 	// still no MOX? --> silently discard CW character and give up
 	if (!mox) {
 	    CAT_cw_is_active=0;
diff --git a/transmitter.c b/transmitter.c
index 00d5e4e..805bd9b 100644
--- a/transmitter.c
+++ b/transmitter.c
@@ -842,8 +842,8 @@ static void full_tx_buffer(TRANSMITTER *tx) {
     // These are the I/Q samples that describe our CW signal
     // The only use we make of it is displaying the spectrum.
     for (j = 0; j < tx->output_samples; j++) {
-      *dp++ = cw_shape_buffer[j];
       *dp++ = 0.0;
+      *dp++ = cw_shape_buffer[j];
     }
   } else {
     update_vox(tx);
@@ -879,7 +879,7 @@ static void full_tx_buffer(TRANSMITTER *tx) {
     }
 
 //
-//  When doing CW, we do not need WDSP since I(t) = cw_shape_buffer(t) and Q(t)=0
+//  When doing CW, we do not need WDSP since Q(t) = cw_shape_buffer(t) and I(t)=0
 //  For the old protocol where the IQ and audio samples are tied together, we can
 //  easily generate a synchronous side tone (and use the function
 //  old_protocol_iq_samples_with_sidetone for this purpose).
@@ -895,10 +895,10 @@ static void full_tx_buffer(TRANSMITTER *tx) {
         // SetTXAPostGen functions are not needed for CW!
 	//
         sidevol= 258.0 * cw_keyer_sidetone_volume;  // between 0.0 and 32766.0
-	qsample=0;				    // will be constantly zero
+	isample=0;				    // will be constantly zero
         for(j=0;j<tx->output_samples;j++) {
 	    ramp=cw_shape_buffer[j];	    	    // between 0.0 and 1.0
-	    isample=floor(gain*ramp+0.5);           // always non-negative, isample is just the pulse envelope
+	    qsample=floor(gain*ramp+0.5);           // always non-negative, isample is just the pulse envelope
 	    switch(protocol) {
 		case ORIGINAL_PROTOCOL:
 		    //
@@ -1106,7 +1106,6 @@ void tx_set_ps(TRANSMITTER *tx,int state) {
 }
 
 void tx_set_twotone(TRANSMITTER *tx,int state) {
-  fprintf(stderr,"TX TWO TONE new state=%d\n", state);
   transmitter->twotone=state;
   if(state) {
     // set frequencies and levels
-- 
2.45.2