]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
corrected new protocol tx buffer size and drive setting
authorJohn Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Tue, 23 Aug 2016 10:24:17 +0000 (10:24 +0000)
committerJohn Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Tue, 23 Aug 2016 10:24:17 +0000 (10:24 +0000)
12 files changed:
lime_protocol.c
main.c
menu.c
new_protocol.c
old_protocol.c
pihpsdr
radio.c
radio.h
release/pihpsdr.tar
release/pihpsdr/pihpsdr
vfo.c
wdsp_init.c

index 47bfbcc7c577380ffbf1ca02c0a424ca21663a81..56e2cf4eebbf5928eaf2823d1487ed24b945dde9 100644 (file)
@@ -19,7 +19,6 @@
 
 static double bandwidth=3000000.0;
 
-static DISCOVERED *d;
 static size_t receiver;
 static SoapySDRDevice *lime_device;
 static SoapySDRStream *stream;
@@ -59,7 +58,6 @@ void lime_protocol_init(int rx,int pixels) {
 
 fprintf(stderr,"lime_protocol_init: receiver=%d pixels=%d\n",rx,pixels);
 
-  d=&discovered[selected_device];
   receiver=(size_t)rx;
   display_width=pixels;
 
@@ -94,7 +92,7 @@ fprintf(stderr,"lime_protocol_init: receiver=%d pixels=%d\n",rx,pixels);
 
   // initialize the radio
 fprintf(stderr,"lime_protocol: receive_thread: SoapySDRDevice_make\n");
-  lime_device=SoapySDRDevice_make(d->info.soapy.args);
+  lime_device=SoapySDRDevice_make(discovered->info.soapy.args);
   if(lime_device==NULL) {
     fprintf(stderr,"lime_protocol: SoapySDRDevice_make failed: %s\n",SoapySDRDevice_lastError());
     _exit(-1);
diff --git a/main.c b/main.c
index ac0427c969b308ff264f3c6ff4f664f7ca6db526..df10b25b9e9a99b189b71a9c5e600cfed50ca1f6 100644 (file)
--- a/main.c
+++ b/main.c
@@ -484,20 +484,22 @@ fprintf(stderr,"protocol=%d name=%s\n",d->protocol,d->name);
 
   splash_status("Initializing wdsp ...");
 
-  d=&discovered[selected_device];
-  protocol=d->protocol;
-  device=d->device;
+  radio=&d[selected_device];
+  protocol=radio->protocol;
+  device=radio->device;
 
-  switch(d->protocol) {
+fprintf(stderr,"radio: %p\n",radio);
+
+  switch(radio->protocol) {
     case ORIGINAL_PROTOCOL:
     case NEW_PROTOCOL:
       sprintf(property_path,"%02X-%02X-%02X-%02X-%02X-%02X.props",
-                        d->info.network.mac_address[0],
-                        d->info.network.mac_address[1],
-                        d->info.network.mac_address[2],
-                        d->info.network.mac_address[3],
-                        d->info.network.mac_address[4],
-                        d->info.network.mac_address[5]);
+                        radio->info.network.mac_address[0],
+                        radio->info.network.mac_address[1],
+                        radio->info.network.mac_address[2],
+                        radio->info.network.mac_address[3],
+                        radio->info.network.mac_address[4],
+                        radio->info.network.mac_address[5]);
       break;
 #ifdef LIMESDR
     case LIMESDR_PROTOCOL:
@@ -508,7 +510,7 @@ fprintf(stderr,"protocol=%d name=%s\n",d->protocol,d->name);
 
   radioRestoreState();
 
-  if(protocol==NEW_PROTOCOL) {
+  if(radio->protocol==NEW_PROTOCOL) {
     samples=malloc(display_width*sizeof(float)*2*4); // 192 -> 48
   } else {
     samples=malloc(display_width*sizeof(float)*2);
@@ -517,7 +519,7 @@ fprintf(stderr,"protocol=%d name=%s\n",d->protocol,d->name);
   //splash_status("Initializing wdsp ...");
   wdsp_init(0,display_width,d->protocol);
 
-  switch(d->protocol) {
+  switch(radio->protocol) {
     case ORIGINAL_PROTOCOL:
       splash_status("Initializing old protocol ...");
       old_protocol_init(0,display_width);
diff --git a/menu.c b/menu.c
index 91d1c606a36b0d1b4145812299781218ee84c6cb..46dd57fcde1f8812414ec40ebdf43f71c5bd1db5 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -728,7 +728,13 @@ static gboolean menu_pressed_event_cb (GtkWidget *widget,
       gtk_widget_show(sample_rate_1536);
         gtk_grid_attach(GTK_GRID(general_grid),sample_rate_1536,0,10,1,1);
       g_signal_connect(sample_rate_1536,"pressed",G_CALLBACK(sample_rate_cb),(gpointer *)1536000);
+
+#ifdef raspberrypi
+      gtk_widget_set_sensitive(sample_rate_768,FALSE);
+      gtk_widget_set_sensitive(sample_rate_1536,FALSE);
+#endif
     }
+
   }
   
 #ifdef LIMESDR
index 537b64d2288c2701880b43f16df5fe82ad17724a..9a200029bbf180c1214e49f224645c129f0b1a95 100644 (file)
@@ -61,8 +61,6 @@
 
 int data_socket;
 
-static DISCOVERED *d;
-
 static int receiver;
 static int running;
 
@@ -110,11 +108,12 @@ static int micOutputRate=192000;
 static int micoutputsamples=BUFFER_SIZE*4;  // 48000 in, 192000 out
 
 static double micinputbuffer[BUFFER_SIZE*2]; // 48000
-static double micoutputbuffer[BUFFER_SIZE*4*2]; //192000
+static double iqoutputbuffer[BUFFER_SIZE*4*2]; //192000
 
 static long tx_iq_sequence;
 static unsigned char iqbuffer[1444];
 static int iqindex;
+static int micsamples;
 
 static int spectrumWIDTH=800;
 static int SPECTRUM_UPDATES_PER_SECOND=10;
@@ -150,9 +149,13 @@ static int psk_samples=0;
 static int psk_resample=6;  // convert from 48000 to 8000
 #endif
 
-static void new_protocol_high_priority(int run,int tx,int drive);
+static void new_protocol_high_priority(int run,int tx,double drive);
 static void* new_protocol_thread(void* arg);
 static void* new_protocol_timer_thread(void* arg);
+static void  process_iq_data(unsigned char *buffer);
+static void  process_command_response(unsigned char *buffer);
+static void  process_high_priority(unsigned char *buffer);
+static void  process_mic_data(unsigned char *buffer);
 static void full_rx_buffer();
 static void full_tx_buffer();
 
@@ -180,7 +183,7 @@ static void new_protocol_calc_buffers() {
 }
 
 void schedule_high_priority(int source) {
-fprintf(stderr,"new_protocol: schedule_high_priority: source=%d\n",source);
+//fprintf(stderr,"new_protocol: schedule_high_priority: source=%d\n",source);
     sem_wait(&send_high_priority_sem);
     send_high_priority=1;
     sem_post(&send_high_priority_sem);
@@ -278,11 +281,11 @@ fprintf(stderr,"new_protocol_general: receiver=%d\n", receiver);
     general_sequence++;
 }
 
-static void new_protocol_high_priority(int run,int tx,int drive) {
+static void new_protocol_high_priority(int run,int tx,double drive) {
     unsigned char buffer[1444];
     BAND *band=band_get_current_band();
 
-fprintf(stderr,"new_protocol_high_priority: run=%d tx=%d drive=%d\n", run, tx, drive);
+//fprintf(stderr,"new_protocol_high_priority: run=%d tx=%d drive=%f\n", run, tx, drive);
     memset(buffer, 0, sizeof(buffer));
 
     buffer[0]=high_priority_sequence>>24;
@@ -316,10 +319,8 @@ fprintf(stderr,"new_protocol_high_priority: run=%d tx=%d drive=%d\n", run, tx, d
     buffer[332]=phase;
 
 
-    float d=(float)drive;
-    d=d*((float)band->pa_calibration/100.0F);
+    double d=drive*((double)band->pa_calibration/100.0);
     int power=(int)(d*255.0);
-
     buffer[345]=power&0xFF;
 
 
@@ -628,7 +629,6 @@ double calibrate(int v) {
 
 void* new_protocol_thread(void* arg) {
 
-    d=&discovered[selected_device];
 
     struct sockaddr_in addr;
     int length;
@@ -636,28 +636,6 @@ void* new_protocol_thread(void* arg) {
     int bytesread;
     short sourceport;
 
-    long sequence;
-    long long timestamp;
-    int bitspersample;
-    int samplesperframe;
-
-    int b;
-    int leftsample;
-    int rightsample;
-    double leftsampledouble;
-    double rightsampledouble;
-
-    int previous_ptt;
-    int previous_dot;
-    int previous_dash;
-
-
-    int micsample;
-    double micsampledouble;
-
-    int micsamples;
-
-    int i, j;
 fprintf(stderr,"new_protocol_thread: receiver=%d\n", receiver);
 
     micsamples=0;
@@ -675,37 +653,37 @@ fprintf(stderr,"outputsamples=%d\n", outputsamples);
     setsockopt(data_socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
 
     // bind to the interface
-    if(bind(data_socket,(struct sockaddr*)&d->info.network.interface_address,d->info.network.interface_length)<0) {
+    if(bind(data_socket,(struct sockaddr*)&radio->info.network.interface_address,radio->info.network.interface_length)<0) {
         fprintf(stderr,"metis: bind socket failed for data_socket: receiver=%d\n",receiver);
         exit(-1);
     }
 
-    memcpy(&base_addr,&d->info.network.address,d->info.network.address_length);
-    base_addr_length=d->info.network.address_length;
+    memcpy(&base_addr,&radio->info.network.address,radio->info.network.address_length);
+    base_addr_length=radio->info.network.address_length;
     base_addr.sin_port=htons(GENERAL_REGISTERS_FROM_HOST_PORT);
 
-    memcpy(&receiver_addr,&d->info.network.address,d->info.network.address_length);
-    receiver_addr_length=d->info.network.address_length;
+    memcpy(&receiver_addr,&radio->info.network.address,radio->info.network.address_length);
+    receiver_addr_length=radio->info.network.address_length;
     receiver_addr.sin_port=htons(RECEIVER_SPECIFIC_REGISTERS_FROM_HOST_PORT);
 
-    memcpy(&transmitter_addr,&d->info.network.address,d->info.network.address_length);
-    transmitter_addr_length=d->info.network.address_length;
+    memcpy(&transmitter_addr,&radio->info.network.address,radio->info.network.address_length);
+    transmitter_addr_length=radio->info.network.address_length;
     transmitter_addr.sin_port=htons(TRANSMITTER_SPECIFIC_REGISTERS_FROM_HOST_PORT);
 
-    memcpy(&high_priority_addr,&d->info.network.address,d->info.network.address_length);
-    high_priority_addr_length=d->info.network.address_length;
+    memcpy(&high_priority_addr,&radio->info.network.address,radio->info.network.address_length);
+    high_priority_addr_length=radio->info.network.address_length;
     high_priority_addr.sin_port=htons(HIGH_PRIORITY_FROM_HOST_PORT);
 
-    memcpy(&audio_addr,&d->info.network.address,d->info.network.address_length);
-    audio_addr_length=d->info.network.address_length;
+    memcpy(&audio_addr,&radio->info.network.address,radio->info.network.address_length);
+    audio_addr_length=radio->info.network.address_length;
     audio_addr.sin_port=htons(AUDIO_FROM_HOST_PORT);
 
-    memcpy(&iq_addr,&d->info.network.address,d->info.network.address_length);
-    iq_addr_length=d->info.network.address_length;
+    memcpy(&iq_addr,&radio->info.network.address,radio->info.network.address_length);
+    iq_addr_length=radio->info.network.address_length;
     iq_addr.sin_port=htons(TX_IQ_FROM_HOST_PORT);
 
-    memcpy(&data_addr,&d->info.network.address,d->info.network.address_length);
-    data_addr_length=d->info.network.address_length;
+    memcpy(&data_addr,&radio->info.network.address,radio->info.network.address_length);
+    data_addr_length=radio->info.network.address_length;
     data_addr.sin_port=htons(RX_IQ_TO_HOST_PORT+receiver);
 
     samples=0;
@@ -727,58 +705,111 @@ fprintf(stderr,"outputsamples=%d\n", outputsamples);
 
 //fprintf(stderr,"received packet length %d from port %d\n",bytesread,sourceport);
 
-        if(sourceport==RX_IQ_TO_HOST_PORT) {
+        switch(sourceport) {
+            case RX_IQ_TO_HOST_PORT:
+              process_iq_data(buffer);
+              break;
+            case COMMAND_RESPONCE_TO_HOST_PORT:
+              process_command_response(buffer);
+              break;
+            case HIGH_PRIORITY_TO_HOST_PORT:
+              process_high_priority(buffer);
+              break;
+            case MIC_LINE_TO_HOST_PORT:
+              process_mic_data(buffer);
+              break;
+            default:
+              break;
+        }
+
+        if(running) {
+           sem_wait(&send_general_sem);
+           if(send_general==1) {
+               new_protocol_general();
+               send_general=0;
+           }
+           sem_post(&send_general_sem);
+
+           sem_wait(&send_high_priority_sem);
+           if(send_high_priority==1) {
+               new_protocol_high_priority(1,isTransmitting(),tune==0?drive:tune_drive);
+               send_high_priority=0;
+           }
+           sem_post(&send_high_priority_sem);
+       }
+        
+    }
 
-          sequence=((buffer[0]&0xFF)<<24)+((buffer[1]&0xFF)<<16)+((buffer[2]&0xFF)<<8)+(buffer[3]&0xFF);
-          timestamp=((long long)(buffer[4]&0xFF)<<56)+((long long)(buffer[5]&0xFF)<<48)+((long long)(buffer[6]&0xFF)<<40)+((long long)(buffer[7]&0xFF)<<32);
-                    ((long long)(buffer[8]&0xFF)<<24)+((long long)(buffer[9]&0xFF)<<16)+((long long)(buffer[10]&0xFF)<<8)+(long long)(buffer[11]&0xFF);
-          bitspersample=((buffer[12]&0xFF)<<8)+(buffer[13]&0xFF);
-          samplesperframe=((buffer[14]&0xFF)<<8)+(buffer[15]&0xFF);
+    close(data_socket);
+}
+
+static void process_iq_data(unsigned char *buffer) {
+    long sequence;
+    long long timestamp;
+    int bitspersample;
+    int samplesperframe;
+    int b;
+    int leftsample;
+    int rightsample;
+    double leftsampledouble;
+    double rightsampledouble;
+
+    sequence=((buffer[0]&0xFF)<<24)+((buffer[1]&0xFF)<<16)+((buffer[2]&0xFF)<<8)+(buffer[3]&0xFF);
+    timestamp=((long long)(buffer[4]&0xFF)<<56)+((long long)(buffer[5]&0xFF)<<48)+((long long)(buffer[6]&0xFF)<<40)+((long long)(buffer[7]&0xFF)<<32);
+    ((long long)(buffer[8]&0xFF)<<24)+((long long)(buffer[9]&0xFF)<<16)+((long long)(buffer[10]&0xFF)<<8)+(long long)(buffer[11]&0xFF);
+    bitspersample=((buffer[12]&0xFF)<<8)+(buffer[13]&0xFF);
+    samplesperframe=((buffer[14]&0xFF)<<8)+(buffer[15]&0xFF);
 
 //fprintf(stderr,"samples per frame %d\n",samplesperframe);
 
-          if(!isTransmitting()) {
-              b=16;
-              for(i=0;i<samplesperframe;i++) {
-                  leftsample   = (int)((signed char) buffer[b++]) << 16;
-                  leftsample  += (int)((unsigned char)buffer[b++]) << 8;
-                  leftsample  += (int)((unsigned char)buffer[b++]);
-                  rightsample  = (int)((signed char) buffer[b++]) << 16;
-                  rightsample += (int)((unsigned char)buffer[b++]) << 8;
-                  rightsample += (int)((unsigned char)buffer[b++]);
-
-                  leftsampledouble=(double)leftsample/8388607.0; // for 24 bits
-                  rightsampledouble=(double)rightsample/8388607.0; // for 24 bits
-            
-                  iqinputbuffer[samples*2]=leftsampledouble;
-                  iqinputbuffer[(samples*2)+1]=rightsampledouble;
-
-                  samples++;
-                  if(samples==BUFFER_SIZE) {
-                      full_rx_buffer();
-                      samples=0;
-                  }
-              }
-          }
+    if(!isTransmitting()) {
+        b=16;
+        int i;
+        for(i=0;i<samplesperframe;i++) {
+            leftsample   = (int)((signed char) buffer[b++]) << 16;
+            leftsample  += (int)((unsigned char)buffer[b++]) << 8;
+            leftsample  += (int)((unsigned char)buffer[b++]);
+            rightsample  = (int)((signed char) buffer[b++]) << 16;
+            rightsample += (int)((unsigned char)buffer[b++]) << 8;
+            rightsample += (int)((unsigned char)buffer[b++]);
+
+            leftsampledouble=(double)leftsample/8388607.0; // for 24 bits
+            rightsampledouble=(double)rightsample/8388607.0; // for 24 bits
+
+            iqinputbuffer[samples*2]=leftsampledouble;
+            iqinputbuffer[(samples*2)+1]=rightsampledouble;
+
+            samples++;
+            if(samples==BUFFER_SIZE) {
+                full_rx_buffer();
+                samples=0;
+            }
+       }
+   }
+}
+
+static void process_command_response(unsigned char *buffer) {
+    response_sequence=((buffer[0]&0xFF)<<24)+((buffer[1]&0xFF)<<16)+((buffer[2]&0xFF)<<8)+(buffer[3]&0xFF);
+    response=buffer[4]&0xFF;
+    fprintf(stderr,"response_sequence=%ld response=%d\n",response_sequence,response);
+    sem_post(&response_sem);
+}
 
-       } else if(sourceport==COMMAND_RESPONCE_TO_HOST_PORT) {
-          // command/response
-          response_sequence=((buffer[0]&0xFF)<<24)+((buffer[1]&0xFF)<<16)+((buffer[2]&0xFF)<<8)+(buffer[3]&0xFF);
-          response=buffer[4]&0xFF;
-          fprintf(stderr,"response_sequence=%ld response=%d\n",response_sequence,response);
-          sem_post(&response_sem);
+static void process_high_priority(unsigned char *buffer) {
+    long sequence;
+    int previous_ptt;
+    int previous_dot;
+    int previous_dash;
 
-       } else if(sourceport==HIGH_PRIORITY_TO_HOST_PORT) {
-          // high priority
-          sequence=((buffer[0]&0xFF)<<24)+((buffer[1]&0xFF)<<16)+((buffer[2]&0xFF)<<8)+(buffer[3]&0xFF);
+    sequence=((buffer[0]&0xFF)<<24)+((buffer[1]&0xFF)<<16)+((buffer[2]&0xFF)<<8)+(buffer[3]&0xFF);
 
-          previous_ptt=ptt;
-          previous_dot=dot;
-          previous_dash=dash;
+    previous_ptt=ptt;
+    previous_dot=dot;
+    previous_dash=dash;
 
-          ptt=buffer[4]&0x01;
-          dot=(buffer[4]>>1)&0x01;
-          dash=(buffer[4]>>2)&0x01;
+    ptt=buffer[4]&0x01;
+    dot=(buffer[4]>>1)&0x01;
+    dash=(buffer[4]>>2)&0x01;
 
 if(ptt!=previous_ptt) {
   fprintf(stderr,"ptt=%d\n",ptt);
@@ -789,94 +820,82 @@ if(dot!=previous_dot) {
 if(dash!=previous_dash) {
   fprintf(stderr,"dash=%d\n",dash);
 }
-          pll_locked=(buffer[4]>>3)&0x01;
-          adc_overload=buffer[5]&0x01;
-          exciter_power=((buffer[6]&0xFF)<<8)|(buffer[7]&0xFF);
-          alex_forward_power=((buffer[14]&0xFF)<<8)|(buffer[15]&0xFF);
-          alex_reverse_power=((buffer[22]&0xFF)<<8)|(buffer[23]&0xFF);
-          supply_volts=((buffer[49]&0xFF)<<8)|(buffer[50]&0xFF);
-
-          if(previous_ptt!=ptt) {
-              //send_high_priority=1;
-              previous_ptt=ptt;
-              g_idle_add(ptt_update,(gpointer)ptt);
-          }
+    pll_locked=(buffer[4]>>3)&0x01;
+    adc_overload=buffer[5]&0x01;
+    exciter_power=((buffer[6]&0xFF)<<8)|(buffer[7]&0xFF);
+    alex_forward_power=((buffer[14]&0xFF)<<8)|(buffer[15]&0xFF);
+    alex_reverse_power=((buffer[22]&0xFF)<<8)|(buffer[23]&0xFF);
+    supply_volts=((buffer[49]&0xFF)<<8)|(buffer[50]&0xFF);
+
+    if(previous_ptt!=ptt) {
+        //send_high_priority=1;
+        previous_ptt=ptt;
+        g_idle_add(ptt_update,(gpointer)ptt);
+    }
 
-       } else if(sourceport==MIC_LINE_TO_HOST_PORT) {
-          // Mic/Line data
-          sequence=((buffer[0]&0xFF)<<24)+((buffer[1]&0xFF)<<16)+((buffer[2]&0xFF)<<8)+(buffer[3]&0xFF);
-          if(isTransmitting()) {
-              b=4;
+}
 
-              for(i=0;i<720;i++) {
-                  micsample  = (int)((signed char) buffer[b++]) << 8;
-                  micsample  |= (int)((unsigned char)buffer[b++] & 0xFF);
+static void process_mic_data(unsigned char *buffer) {
+    long sequence;
+    int b;
+    int micsample;
+    double micsampledouble;
 
+    sequence=((buffer[0]&0xFF)<<24)+((buffer[1]&0xFF)<<16)+((buffer[2]&0xFF)<<8)+(buffer[3]&0xFF);
+    if(isTransmitting()) {
+        b=4;
+        int i,j,s;
+        for(i=0;i<720;i++) {
+            micsample  = (int)((signed char) buffer[b++]) << 8;
+            micsample  |= (int)((unsigned char)buffer[b++] & 0xFF);
 #ifdef FREEDV
-                  if(mode==modeFREEDV) {
-                    if(freedv_samples==0) { // 48K to 8K
-                      int modem_samples=mod_sample_freedv(micsample);
-                      if(modem_samples!=0) {
-                        int s;
-                        for(s=0;s<modem_samples;s++) {
-                          for(j=0;j<freedv_resample;j++) {  // 8K to 48K
-                            micsample=mod_out[s];
-                            micsampledouble=(double)micsample/32767.0; // 16 bit sample 2^16-1
-                            micinputbuffer[micsamples*2]=micsampledouble*mic_gain;
-                            micinputbuffer[(micsamples*2)+1]=micsampledouble*mic_gain;
-                            micsamples++;
-                            if(micsamples==buffer_size) {
-                              full_tx_buffer();
-                              micsamples=0;
-                            }
+            if(mode==modeFREEDV) {
+                if(freedv_samples==0) { // 48K to 8K
+                    int modem_samples=mod_sample_freedv(micsample);
+                    if(modem_samples!=0) {
+                      for(s=0;s<modem_samples;s++) {
+                        for(j=0;j<freedv_resample;j++) {  // 8K to 48K
+                          micsample=mod_out[s];
+                          micsampledouble=(double)micsample/32767.0; // 16 bit sample 2^16-1
+                          micinputbuffer[micsamples*2]=micsampledouble*mic_gain;
+                          micinputbuffer[(micsamples*2)+1]=micsampledouble*mic_gain;
+                          micsamples++;
+                          if(micsamples==BUFFER_SIZE) {
+                            full_tx_buffer();
+                            micsamples=0;
                           }
                         }
                       }
                     }
-                    freedv_samples++;
-                    if(freedv_samples==freedv_resample) {
-                      freedv_samples=0;
-                    }
-                  } else {
+               }
+               freedv_samples++;
+               if(freedv_samples==freedv_resample) {
+                   freedv_samples=0;
+               }
+            } else {
 #endif
-                    micsampledouble = (double)micsample/32767.0; // 16 bit sample
-                    micinputbuffer[micsamples*2]=micsampledouble*mic_gain;
-                    micinputbuffer[(micsamples*2)+1]=micsampledouble*mic_gain;
-
-                    micsamples++;
-
-                    if(micsamples==BUFFER_SIZE) {
-                      full_tx_buffer();
-                      micsamples=0;
-                    }
+               micsampledouble = (double)micsample/32767.0; // 16 bit sample
+               if(mode==modeCWL || mode==modeCWU || tune) {
+                   micinputbuffer[micsamples*2]=0.0;
+                   micinputbuffer[(micsamples*2)+1]=0.0;
+               } else {
+                   micinputbuffer[micsamples*2]=micsampledouble*mic_gain;
+                   micinputbuffer[(micsamples*2)+1]=micsampledouble*mic_gain;
+               }
+
+               micsamples++;
+
+               if(micsamples==BUFFER_SIZE) {
+                   full_tx_buffer();
+                   micsamples=0;
+               }
 #ifdef FREEDV
-                 }
-#endif
-
-              }
-          }
-       } else {
-       }
-
-       if(running) {
-           sem_wait(&send_general_sem);
-           if(send_general==1) {
-               new_protocol_general();
-               send_general=0;
            }
-           sem_post(&send_general_sem);
+#endif
 
-           sem_wait(&send_high_priority_sem);
-           if(send_high_priority==1) {
-               new_protocol_high_priority(1,isTransmitting(),tune==0?drive:tune_drive);
-               send_high_priority=0;
-           }
-           sem_post(&send_high_priority_sem);
-       }
-        
+        }
     }
 
-    close(data_socket);
 }
 
 #ifdef FREEDV
@@ -997,16 +1016,16 @@ static void full_tx_buffer() {
   int j;
   int error;
 
-  fexchange0(CHANNEL_TX, micinputbuffer, micoutputbuffer, &error);
-  Spectrum0(1, CHANNEL_TX, 0, 0, micoutputbuffer);
+  fexchange0(CHANNEL_TX, micinputbuffer, iqoutputbuffer, &error);
+  Spectrum0(1, CHANNEL_TX, 0, 0, iqoutputbuffer);
 
 #ifdef FREEDV
   if(mode==modeFREEDV) {
-    gain=32767.0*freedv_scale;
+    gain=8388607.0*freedv_scale;
   }
 #endif
 
-  if(d->device==DEVICE_METIS && atlas_penelope) {
+  if(radio->device==DEVICE_METIS && atlas_penelope) {
     if(tune) {
       gain=8388607.0*(double)tune_drive;
     } else {
@@ -1015,8 +1034,8 @@ static void full_tx_buffer() {
   }
 
   for(j=0;j<micoutputsamples;j++) {
-    isample=(long)(micoutputbuffer[j*2]*gain);
-    qsample=(long)(micoutputbuffer[(j*2)+1]*gain);
+    isample=(long)(iqoutputbuffer[j*2]*gain);
+    qsample=(long)(iqoutputbuffer[(j*2)+1]*gain);
 
     iqbuffer[iqindex++]=isample>>16;
     iqbuffer[iqindex++]=isample>>8;
index b56940b209f89eecf80885ab2c093802645e21ab..a4c6189ee64d03aa1ae912a7c17ac5db046ba4e1 100644 (file)
 #define LT2208_RANDOM_OFF         0x00
 #define LT2208_RANDOM_ON          0x10
 
-static DISCOVERED *d;
-
 static int buffer_size=BUFFER_SIZE;
 
 static int receiver;
@@ -232,8 +230,6 @@ void old_protocol_init(int rx,int pixels) {
 
   fprintf(stderr,"old_protocol_init\n");
 
-  d=&discovered[selected_device];
-
   //int result=sem_init(&frequency_changed_sem, 0, 1);
 
   if(local_audio) {
@@ -276,13 +272,13 @@ static void start_receive_thread() {
   setsockopt(data_socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
 
   // bind to the interface
-  if(bind(data_socket,(struct sockaddr*)&d->info.network.interface_address,d->info.network.interface_length)<0) {
+  if(bind(data_socket,(struct sockaddr*)&radio->info.network.interface_address,radio->info.network.interface_length)<0) {
     perror("old_protocol: bind socket failed for data_socket\n");
     exit(-1);
   }
 
-  memcpy(&data_addr,&d->info.network.address,d->info.network.address_length);
-  data_addr_length=d->info.network.address_length;
+  memcpy(&data_addr,&radio->info.network.address,radio->info.network.address_length);
+  data_addr_length=radio->info.network.address_length;
   data_addr.sin_port=htons(DATA_PORT);
 
   rc=pthread_create(&receive_thread_id,NULL,receive_thread,NULL);
@@ -649,7 +645,7 @@ static void full_tx_buffer() {
   }
 #endif
 
-  if(d->device==DEVICE_METIS && atlas_penelope) {
+  if(radio->device==DEVICE_METIS && atlas_penelope) {
     if(tune) {
       gain=32767.0*tune_drive;
     } else {
@@ -732,7 +728,7 @@ void ozy_send_buffer() {
           output_buffer[C1]|=SPEED_384K;
           break;
       }
-      if(d->device==DEVICE_METIS) {
+      if(radio->device==DEVICE_METIS) {
       }
 
       output_buffer[C2]=0x00;
@@ -906,7 +902,7 @@ void ozy_send_buffer() {
       output_buffer[C2]=0x00;
       output_buffer[C3]=0x00;
 
-      if(d->device==DEVICE_HERMES || d->device==DEVICE_ANGELIA || d->device==DEVICE_ORION) {
+      if(radio->device==DEVICE_HERMES || radio->device==DEVICE_ANGELIA || radio->device==DEVICE_ORION) {
         output_buffer[C4]=0x20|attenuation;
       } else {
         output_buffer[C4]=0x00;
diff --git a/pihpsdr b/pihpsdr
index c79522e7b18b99f0eaf2af492e9a340c38954859..82b5b8eb1d31d30b579359b474832656f38803e7 100755 (executable)
Binary files a/pihpsdr and b/pihpsdr differ
diff --git a/radio.c b/radio.c
index d1cd9f611ab64ad1eaec2d619754f14298a98d29..48d783c564ef1c5ab12359c0bf9490adf781e3b8 100644 (file)
--- a/radio.c
+++ b/radio.c
 #include <semaphore.h>
 #include <math.h>
 
+#include "discovered.h"
+//#include "discovery.h"
 #include "mode.h"
 #include "radio.h"
 #include "channel.h"
 #include "agc.h"
 #include "band.h"
-#include "discovered.h"
 #include "property.h"
 #include "new_protocol.h"
 #ifdef LIMESDR
@@ -42,6 +43,8 @@
 #define min(x,y) (x<y?x:y)
 #define max(x,y) (x<y?y:x)
 
+DISCOVERED *radio;
+
 char property_path[128];
 sem_t property_sem;
 
diff --git a/radio.h b/radio.h
index 5712282f92d4fd05e1db712491dd980f54393fc2..4d30174f44f1dd1e2ad3d690420c7cf7c65e10c0 100644 (file)
--- a/radio.h
+++ b/radio.h
@@ -38,6 +38,8 @@
 #define OLD_ORION_MIC_BIAS_DISABLED 0x00
 #define OLD_ORION_MIC_BIAS_ENABLED 0x20
 
+extern DISCOVERED *radio;
+
 extern char property_path[];
 
 extern double scale;
index 48867ae7b812ae26e76546f5447ad18d48805e86..a8eb7ba2e432bf551e0499fcd670f298e3999e40 100644 (file)
Binary files a/release/pihpsdr.tar and b/release/pihpsdr.tar differ
index c79522e7b18b99f0eaf2af492e9a340c38954859..82b5b8eb1d31d30b579359b474832656f38803e7 100755 (executable)
Binary files a/release/pihpsdr/pihpsdr and b/release/pihpsdr/pihpsdr differ
diff --git a/vfo.c b/vfo.c
index c08f030af1f16f779b88be6101a582bc621f29af..c461a616f57af019204688aaf260455583fce3a4 100644 (file)
--- a/vfo.c
+++ b/vfo.c
@@ -32,6 +32,7 @@
 #include <net/if.h>
 #include <ifaddrs.h>
 
+#include "discovered.h"
 #include "main.h"
 #include "agc.h"
 #include "mode.h"
@@ -46,7 +47,6 @@
 #include "toolbar.h"
 #include "wdsp.h"
 #include "wdsp_init.h"
-#include "discovered.h"
 
 static GtkWidget *parent_window;
 static int my_width;
@@ -180,7 +180,6 @@ static gboolean vfo_draw_cb (GtkWidget *widget,
 }
 
 int vfo_update(void *data) {
-    DISCOVERED *d=&discovered[selected_device];
     BANDSTACK_ENTRY* entry=bandstack_entry_get_current();
     FILTER* band_filters=filters[entry->mode];
     FILTER* band_filter=&band_filters[entry->filter];
@@ -195,20 +194,20 @@ int vfo_update(void *data) {
             CAIRO_FONT_WEIGHT_BOLD);
 
         char text[128];
-        switch(d->protocol) {
+        switch(discovered->protocol) {
             case ORIGINAL_PROTOCOL:
             case NEW_PROTOCOL:
               sprintf(text,"%s (%s %d.%d) %s",
-                    d->name,
-                    d->protocol==ORIGINAL_PROTOCOL?"old":"new",
-                    d->software_version/10,
-                    d->software_version%10,
-                    inet_ntoa(d->info.network.address.sin_addr));
+                    discovered->name,
+                    discovered->protocol==ORIGINAL_PROTOCOL?"old":"new",
+                    discovered->software_version/10,
+                    discovered->software_version%10,
+                    inet_ntoa(discovered->info.network.address.sin_addr));
               break;
 #ifdef LIMESDR
             case LIMESDR_PROTOCOL:
               sprintf(text,"%s\n",
-                    d->name);
+                    discovered->name);
               break;
 #endif
         }
index 92325a6219018a46cf679cca9006a7204e622c04..9fb853bcee74679060c025761babd61550e71425 100644 (file)
@@ -96,8 +96,7 @@ static void calc_tx_buffer_size() {
         break;
     }
   } else {
-    tx_buffer_size=BUFFER_SIZE*4;
-    // input always 48K -- output always 192K
+    tx_buffer_size=BUFFER_SIZE; // input always 192K
   }
 }
 
@@ -312,8 +311,10 @@ void wdsp_init(int rx,int pixels,int protocol) {
     fprintf(stderr,"wdsp_init: %d\n",rx);
    
     if(protocol==ORIGINAL_PROTOCOL) {
+        micSampleRate=sample_rate;
         micOutputRate=48000;
     } else {
+        micSampleRate=48000;
         micOutputRate=192000;
     }
 
@@ -346,16 +347,16 @@ void wdsp_init(int rx,int pixels,int protocol) {
 
     fprintf(stderr,"OpenChannel %d buffer_size=%d fft_size=%d sample_rate=%d dspRate=%d outputRate=%d\n",
                 CHANNEL_TX,
-                buffer_size,
+                tx_buffer_size,
                 fft_size,
-                sample_rate, //micSampleRate,
+                micSampleRate,
                 micDspRate,
                 micOutputRate);
 
     OpenChannel(CHANNEL_TX,
-                buffer_size,
+                tx_buffer_size,
                 fft_size,
-                sample_rate, //micSampleRate,
+                micSampleRate,
                 micDspRate,
                 micOutputRate,
                 1, // transmit
@@ -453,6 +454,7 @@ static void initAnalyzer(int channel,int buffer_size) {
     }
 #endif
     if(channel==CHANNEL_TX && protocol==NEW_PROTOCOL) {
+      buffer_size=buffer_size*4;
       pixels=spectrumWIDTH*4; // allows 192 -> 48 easy
     }
     SetAnalyzer(channel,