From: c vw Date: Fri, 31 May 2019 08:35:08 +0000 (+0200) Subject: some stream-lining to prepeare for a huge pull request X-Git-Url: https://git.rkrishnan.org/%5B/listings/flags/status?a=commitdiff_plain;h=db47735e37f927bf19f808d455aed4ec1865addf;p=pihpsdr.git some stream-lining to prepeare for a huge pull request --- diff --git a/hpsdrsim.c b/hpsdrsim.c index c267d14..0b73aef 100644 --- a/hpsdrsim.c +++ b/hpsdrsim.c @@ -20,26 +20,18 @@ * RF3 signal strength varies according to TX-drive and TX-ATT settings * RF4 signal strength is normalized to amplitude of 0.407 * - * RF1 and RF2 are associated with ADC1 and ADC2. - * RF3 also goes to ADC1 upon TX - * RF4 is the TX DAC signal. Upon TX, it goes to RX2 for Metis, RX4 for Hermes, and RX5 beyond. - * - * The SDR application has to make the proper ADC settings! - * - * Without PURESIGNAL, the standard association is: - * RX1=ADC1, RX2=ADC2 (ADC2 not present for METIS and ANAN-10/10E/100) - * - * When using PURESIGNAL, the standard association is: + * The connection with the ADCs are: + * first ADC: RF1 upon receive, RF3 upon transmit + * second ADC: RF2 * - * DEVICE=METIS: RX1=ADC1, RX2=TX-DAC - * DEVICE=HERMES: RX1=ADC1, RX2=ADC1, RX3=ADC2, RX4=TX-DAC - * DEVICE=ORION: RX1=ADC1, RX2=ADC1, RX3=ADC3, RX4=ADC1, RX5=TX-DAC (also for ANGELIA and ORION2) - * - * Note that for STEMlab (RedPitaya) based SDRs, there is usually a fixed association + * RF4 is the TX DAC signal. Upon TX, it goes to RX2 for Metis, RX4 for Hermes, and RX5 beyond. + * Since the feedback runs at the RX sample rate while the TX sample rate is fixed (48000 Hz), + * we have to re-sample and do this in a very stupid way (linear interpolation). * + * The SDR application has to make the proper ADC settings, except for STEMlab + * (RedPitaya based SDRs), where there is a fixed association * RX1=ADC1, RX2=ADC2, RX3=ADC2, RX4=TX-DAC - * - * And this setting is NOT AFFECTED by the ADC settings in the HPSDR protocol. + * and the PURESIGNAL feedback signal is connected to the second ADC. * * Audio sent to the "radio" is played via the first available output channel. * This works on MacOS (PORTAUDIO) and Linux (ALSA). @@ -172,8 +164,10 @@ int envptr=0; #ifdef MICSAMPLES // // Raw audio data (48000 16-bit int words) is read from a file and stored. -// As soon as the ALEX attenuators are engaged, these mic samples are -// sent to the SDR program ONCE. +// As soon as the attenuation of RX1 goes above 20dB, these samples are +// sent to the SDR (one shot), and when the attenuation goes below 10dB, this system +// is reset, so playing with the ALEX ATT buttons or with the ATT slider you can +// send mic samples to the SDR application and do some testing. // static int16_t micsamples[48000]; int micsamples_ptr=-2; @@ -318,8 +312,6 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - fprintf(stderr, "DEBUG_TCP: RP <--> PC: sock_TCP_Server: %d\n", sock_TCP_Server); - setsockopt(sock_TCP_Server, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes)); int tcpmaxseg = 1032; @@ -340,7 +332,7 @@ int main(int argc, char *argv[]) } listen(sock_TCP_Server, 1024); - fprintf(stderr, "DEBUG_TCP: RP <--> PC: Listening for TCP client connection request\n"); + fprintf(stderr, "Listening for TCP client connection request\n"); int flags = fcntl(sock_TCP_Server, F_GETFL, 0); fcntl(sock_TCP_Server, F_SETFL, flags | O_NONBLOCK); @@ -437,7 +429,7 @@ int main(int argc, char *argv[]) { if((sock_TCP_Client = accept(sock_TCP_Server, NULL, NULL)) > -1) { - fprintf(stderr, "DEBUG_TCP: RP <--> PC: sock_TCP_Client: %d connected to sock_TCP_Server: %d\n", sock_TCP_Client, sock_TCP_Server); + fprintf(stderr,"sock_TCP_Client: %d connected to sock_TCP_Server: %d\n", sock_TCP_Client, sock_TCP_Server); } // This avoids firing accept() too often if it constantly fails udp_retries=0; @@ -453,7 +445,7 @@ int main(int argc, char *argv[]) // processing an invalid packet is too dangerous -- skip it! if (bytes_read != 1032) { - fprintf(stderr,"DEBUG_PROT: RvcMsg Code=0x%08x Len=%d\n", code, (int)bytes_read); + fprintf(stderr,"InvalidLength: RvcMsg Code=0x%08x Len=%d\n", code, (int)bytes_read); break; } @@ -462,7 +454,7 @@ int main(int argc, char *argv[]) if (seqnum != last_seqnum + 1) { - fprintf(stderr,"DEBUG_SEQ: SEQ ERROR: last %ld, recvd %ld\n", (long)last_seqnum, (long)seqnum); + fprintf(stderr,"SEQ ERROR: last %ld, recvd %ld\n", (long)last_seqnum, (long)seqnum); } last_seqnum = seqnum; @@ -567,12 +559,12 @@ int main(int argc, char *argv[]) // respond to an incoming Metis detection request case 0x0002feef: - fprintf(stderr, "DEBUG_PROT: RP -> PC: respond to an incoming Metis detection request / code: 0x%08x\n", code); + fprintf(stderr, "Respond to an incoming Metis detection request / code: 0x%08x\n", code); // processing an invalid packet is too dangerous -- skip it! if (bytes_read != 63) { - fprintf(stderr,"DEBUG_PROT: RvcMsg Code=0x%08x Len=%d\n", code, (int)bytes_read); + fprintf(stderr,"InvalidLength: RvcMsg Code=0x%08x Len=%d\n", code, (int)bytes_read); break; } reply[2] = 2 + active_thread; @@ -588,7 +580,7 @@ int main(int argc, char *argv[]) { if (send(sock_TCP_Client, buffer, 60, 0) < 0) { - fprintf(stderr, "DEBUG_TCP: RP -> PC: TCP send error occurred when responding to an incoming Metis detection request!\n"); + fprintf(stderr, "TCP send error occurred when responding to an incoming Metis detection request!\n"); } // close the TCP socket which was only used for the detection close(sock_TCP_Client); @@ -605,12 +597,12 @@ int main(int argc, char *argv[]) // stop the Red Pitaya to PC transmission via handler_ep6 case 0x0004feef: - fprintf(stderr, "DEBUG_PROT: RP -> PC: stop the transmission via handler_ep6 / code: 0x%08x\n", code); + fprintf(stderr, "STOP the transmission via handler_ep6 / code: 0x%08x\n", code); // processing an invalid packet is too dangerous -- skip it! if (bytes_read != 64) { - fprintf(stderr,"DEBUG_PROT: RvcMsg Code=0x%08x Len=%d\n", code, bytes_read); + fprintf(stderr,"InvalidLength: RvcMsg Code=0x%08x Len=%d\n", code, bytes_read); break; } @@ -629,7 +621,7 @@ int main(int argc, char *argv[]) //// This special code 0x11 is no longer needed, is does exactly the same thing //// as the other start codes 0x01, 0x02, 0x03 - fprintf(stderr, "DEBUG_TCP: PC -> RP: TCP METIS-start message received / code: 0x%08x\n", code); + fprintf(stderr, "TCP METIS-start message received / code: 0x%08x\n", code); /* FALLTHROUGH */ @@ -637,12 +629,12 @@ int main(int argc, char *argv[]) case 0x0204feef: case 0x0304feef: - fprintf(stderr, "DEBUG_PROT: RP <--> PC: start the handler_ep6 thread / code: 0x%08x\n", code); + fprintf(stderr, "START the handler_ep6 thread / code: 0x%08x\n", code); // processing an invalid packet is too dangerous -- skip it! if (bytes_read != 64) { - fprintf(stderr,"DEBUG_PROT: RvcMsg Code=0x%08x Len=%d\n", code, bytes_read); + fprintf(stderr,"InvalidLength: RvcMsg Code=0x%08x Len=%d\n", code, bytes_read); break; } @@ -653,6 +645,11 @@ int main(int argc, char *argv[]) addr_ep6.sin_addr.s_addr = addr_from.sin_addr.s_addr; addr_ep6.sin_port = addr_from.sin_port; + // + // The initial value of txptr defines the delay between + // TX samples sent to the SDR and PURESIGNAL feedback + // samples arriving + // txptr=(25 << rate) * 126; // must be even multiple of 63 rxptr=0; memset(isample, 0, RTXLEN*sizeof(double)); @@ -672,11 +669,11 @@ int main(int argc, char *argv[]) // Possibly a discovery packet of the New protocol, otherwise a severe error if (bytes_read == 60 && code == 0 && buffer[4] == 0x02) { - fprintf(stderr,"DEBUG_PROT: PC -> RP: NewProtocol discovery packet received (no response)\n"); + fprintf(stderr,"NewProtocol discovery packet received (we won't respond)\n"); } else { - fprintf(stderr,"DEBUG_PROT: PC -> RP: invalid code: 0x%08x (Len=%d)\n", code, bytes_read); + fprintf(stderr,"PackedInvalidCode: 0x%08x (Len=%d)\n", code, bytes_read); } break; } @@ -921,10 +918,9 @@ void *handler_ep6(void *arg) 127, 127, 127, 24, 0, 0, 0, 0, 127, 127, 127, 32, 66, 66, 66, 66 }; - int32_t rf1isample,rf1qsample; - int32_t rf2isample,rf2qsample; - int32_t rf3isample,rf3qsample; - int32_t rf4isample,rf4qsample; + int32_t adc1isample,adc1qsample; + int32_t adc2isample,adc2qsample; + int32_t dacisample,dacqsample; int32_t myisample,myqsample; int16_t ssample; @@ -1024,40 +1020,49 @@ void *handler_ep6(void *arg) pointer += 8; memset(pointer, 0, 504); for (j=0; j> 16) & 0xFF; *pointer++ = (myisample >> 8) & 0xFF; @@ -1141,7 +1146,7 @@ void *handler_ep6(void *arg) { if (sendmsg(sock_TCP_Client, &msghdr, 0) < 0) { - fprintf(stderr, "DEBUG_TCP: RP -> PC: TCP sendmsg error occurred at sequence number: %u !\n", counter); + fprintf(stderr, "TCP sendmsg error occurred at sequence number: %u !\n", counter); } } else @@ -1314,7 +1319,7 @@ void audio_get_cards() { descr = snd_device_name_get_hint(*n, "DESC"); io = snd_device_name_get_hint(*n, "IOID"); - if(strncmp("dmix:", name, 5)==0/* || strncmp("pulse", name, 5)==0*/) { + if(strncmp("dmix:", name, 5)==0) { fprintf(stderr,"name=%s descr=%s io=%s\n",name, descr, io); device_id=malloc(64); diff --git a/iambic.c b/iambic.c index 56d11b2..3609ee3 100644 --- a/iambic.c +++ b/iambic.c @@ -357,8 +357,6 @@ static void* keyer_thread(void *arg) { int old_volume; struct sched_param param; - // In Linux, the new scheduling policy will be effective for the - // calling thread only. param.sched_priority = MY_PRIORITY; if(sched_setscheduler((pid_t)0, SCHED_FIFO, ¶m) == -1) { perror("sched_setscheduler failed"); @@ -381,9 +379,9 @@ static void* keyer_thread(void *arg) { // firing up the TX. This induces a small delay when hitting the key for // the first time, but excludes that the first dot is swallowed. // Note: if out-of-band, mox will never come, therefore - // give up after 100 msec. - i=100; - while (!mox && i-- > 0) usleep(1000); + // give up after 200 msec. + i=200; + while ((!mox || cw_not_ready) && i-- > 0) usleep(1000L); cwvox=(int) cw_keyer_hang_time; } diff --git a/old_protocol.c b/old_protocol.c index b4a65a3..579a878 100644 --- a/old_protocol.c +++ b/old_protocol.c @@ -953,11 +953,11 @@ void ozy_send_buffer() { #ifdef PURESIGNAL // // Upon TX, we might have to activate a different RX path for the - // attenuated feedback signal. Use feedback_antenna == 0, if + // attenuated feedback signal. Use alex_antenna == 0, if // the feedback signal is routed automatically/internally // If feedback is to the second ADC, leave RX1 ANT settings untouched // - if (isTransmitting() && transmitter->puresignal && receiver[PS_RX_FEEDBACK]->adc == 0) i=receiver[PS_RX_FEEDBACK]->feedback_antenna; + if (isTransmitting() && transmitter->puresignal && receiver[PS_RX_FEEDBACK]->adc == 0) i=receiver[PS_RX_FEEDBACK]->alex_antenna; #endif switch(i) { case 3: // Alex: RX2 IN, ANAN: EXT1, ANAN7000: still uses internal feedback diff --git a/ps_menu.c b/ps_menu.c index 5213ed3..4e13f03 100644 --- a/ps_menu.c +++ b/ps_menu.c @@ -267,11 +267,11 @@ static void ps_ant_cb(GtkWidget *widget, gpointer data) { case 0: // AUTO (Internal), feedback goes to first ADC case 3: // EXT1, feedback goes to first ADC case 4: // EXT2, feedback goes to first ADC - receiver[PS_RX_FEEDBACK]->feedback_antenna = (int) (uintptr_t) data; + receiver[PS_RX_FEEDBACK]->alex_antenna = (int) (uintptr_t) data; receiver[PS_RX_FEEDBACK]->adc = 0; break; case 99: // RX2, feedback goes to second ADC - receiver[PS_RX_FEEDBACK]->feedback_antenna = 0; + receiver[PS_RX_FEEDBACK]->alex_antenna = 0; receiver[PS_RX_FEEDBACK]->adc = 1; break; } @@ -428,7 +428,7 @@ void ps_menu(GtkWidget *parent) { GtkWidget *ps_ant_auto=gtk_radio_button_new_with_label(NULL,"AUTO"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ps_ant_auto), - (receiver[PS_RX_FEEDBACK]->feedback_antenna == 0) && (receiver[PS_RX_FEEDBACK]->adc == 0)); + (receiver[PS_RX_FEEDBACK]->alex_antenna == 0) && (receiver[PS_RX_FEEDBACK]->adc == 0)); gtk_widget_show(ps_ant_auto); gtk_grid_attach(GTK_GRID(grid), ps_ant_auto, col, row, 1, 1); g_signal_connect(ps_ant_auto,"toggled", G_CALLBACK(ps_ant_cb), (gpointer) (long) 0); @@ -436,7 +436,7 @@ void ps_menu(GtkWidget *parent) { GtkWidget *ps_ant_ext1=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(ps_ant_auto),"EXT1"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ps_ant_ext1), - (receiver[PS_RX_FEEDBACK]->feedback_antenna==3) && (receiver[PS_RX_FEEDBACK]->adc == 0)); + (receiver[PS_RX_FEEDBACK]->alex_antenna==3) && (receiver[PS_RX_FEEDBACK]->adc == 0)); gtk_widget_show(ps_ant_ext1); gtk_grid_attach(GTK_GRID(grid), ps_ant_ext1, col, row, 1, 1); g_signal_connect(ps_ant_ext1,"toggled", G_CALLBACK(ps_ant_cb), (gpointer) (long) 3); @@ -444,7 +444,7 @@ void ps_menu(GtkWidget *parent) { GtkWidget *ps_ant_ext2=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(ps_ant_auto),"EXT2"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ps_ant_ext2), - (receiver[PS_RX_FEEDBACK]->feedback_antenna==4) && (receiver[PS_RX_FEEDBACK]->adc == 0)); + (receiver[PS_RX_FEEDBACK]->alex_antenna==4) && (receiver[PS_RX_FEEDBACK]->adc == 0)); gtk_widget_show(ps_ant_ext2); gtk_grid_attach(GTK_GRID(grid), ps_ant_ext2, col, row, 1, 1); g_signal_connect(ps_ant_ext2,"toggled", G_CALLBACK(ps_ant_cb), (gpointer) (long) 4); diff --git a/radio.c b/radio.c index b646170..b52f5f8 100644 --- a/radio.c +++ b/radio.c @@ -1534,8 +1534,8 @@ void radioSaveState() { receiver_save_state(receiver[i]); } #ifdef PURESIGNAL - // There is little to save. - // An exception is the feedback_antenna stored in PS_RX_FEEDBACK + // The only variables of interest in this receiver are + // the alex_antenna an the adc receiver_save_state(receiver[PS_RX_FEEDBACK]); #endif transmitter_save_state(transmitter); diff --git a/receiver.c b/receiver.c index 9a1ed09..d2300e4 100644 --- a/receiver.c +++ b/receiver.c @@ -199,11 +199,6 @@ void receiver_save_state(RECEIVER *rx) { sprintf(value,"%d",rx->waterfall_automatic); setProperty(name,value); -#ifdef PURESIGNAL - sprintf(name,"receiver.%d.feedback_antenna",rx->id); - sprintf(value,"%d",rx->feedback_antenna); - setProperty(name,value); -#endif sprintf(name,"receiver.%d.alex_antenna",rx->id); sprintf(value,"%d",rx->alex_antenna); setProperty(name,value); @@ -360,11 +355,6 @@ fprintf(stderr,"receiver_restore_state: id=%d\n",rx->id); value=getProperty(name); if(value) rx->waterfall_automatic=atoi(value); -#ifdef PURESIGNAL - sprintf(name,"receiver.%d.feedback_antenna",rx->id); - value=getProperty(name); - if(value) rx->feedback_antenna=atoi(value); -#endif sprintf(name,"receiver.%d.alex_antenna",rx->id); value=getProperty(name); if(value) rx->alex_antenna=atoi(value); @@ -798,7 +788,6 @@ fprintf(stderr,"create_pure_signal_receiver: id=%d buffer_size=%d\n",id,buffer_s rx->nr2_npe_method=0; rx->nr2_ae=1; - rx->feedback_antenna=0; rx->alex_antenna=0; rx->alex_attenuation=0; @@ -817,7 +806,7 @@ fprintf(stderr,"create_pure_signal_receiver: id=%d buffer_size=%d\n",id,buffer_s rx->low_latency=0; - // not much to be restored, except feedback_antenna + // not much to be restored, except alex_antenna and adc if (id == PS_RX_FEEDBACK) receiver_restore_state(rx); int result; @@ -931,10 +920,6 @@ fprintf(stderr,"create_receiver: id=%d default ddc=%d adc=%d\n",rx->id, rx->ddc, rx->nr2_npe_method=0; rx->nr2_ae=1; -#ifdef PURESIGNAL - rx->feedback_antenna=0; -#endif - BAND *b=band_get_band(vfo[rx->id].band); rx->alex_antenna=b->alexRxAntenna; rx->alex_attenuation=b->alexAttenuation; diff --git a/receiver.h b/receiver.h index 52970ca..39bf084 100644 --- a/receiver.h +++ b/receiver.h @@ -89,13 +89,6 @@ typedef struct _receiver { int alex_antenna; int alex_attenuation; -#ifdef PURESIGNAL - // indicates to which ALEX RX antenna the attenuated feedback - // signal from the PA goes. The coding is the same as for alex_antenna, - // except that this connector is only used when transmitting. - int feedback_antenna; -#endif - int filter_low; int filter_high; diff --git a/rigctl.c b/rigctl.c index e21ad82..e1dcc8d 100644 --- a/rigctl.c +++ b/rigctl.c @@ -552,7 +552,7 @@ static gpointer rigctl_cw_thread(gpointer data) // Note that if out-of-band, we would wait // forever here, so allow at most 200 msec // We also have to wait for cw_not_ready becoming zero - i=100; + i=200; while ((!mox || cw_not_ready) && i-- > 0) usleep(1000L); // still no MOX? --> silently discard CW character and give up if (!mox) { diff --git a/transmitter.c b/transmitter.c index 805bd9b..18878b8 100644 --- a/transmitter.c +++ b/transmitter.c @@ -1139,7 +1139,7 @@ void tx_set_ps_sample_rate(TRANSMITTER *tx,int rate) { // void cw_hold_key(int state) { if (state) { - cw_key_down = 480000; // up to 10 sec + cw_key_down = 960000; // up to 20 sec } else { cw_key_down = 0; }