Skip to content

Commit

Permalink
add soapy_protocol_is_running function
Browse files Browse the repository at this point in the history
  • Loading branch information
g0orx committed Nov 6, 2020
1 parent bfa924d commit 1668438
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
43 changes: 16 additions & 27 deletions soapy_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
#include "SoapySDR/Formats.h"
#include "SoapySDR/Version.h"

//#define TIMING
#ifdef TIMING
#include <sys/time.h>
#endif

#include "band.h"
#include "channel.h"
#include "discovered.h"
Expand Down Expand Up @@ -69,10 +64,6 @@ static gpointer receive_thread(gpointer data);

static int actual_rate;

#ifdef TIMING
static int rate_samples;
#endif

static gboolean running;

static int mic_sample_divisor=1;
Expand Down Expand Up @@ -198,6 +189,13 @@ g_print("soapy_protocol_create_transmitter: SoapySDRDevice_setupStream: channel=
g_print("soapy_protocol_create_transmitter: max_tx_samples=%d\n",max_tx_samples);
output_buffer=(float *)malloc(max_tx_samples*sizeof(float)*2);

if(radio->local_microphone) {
if(audio_open_input(radio)!=0) {
fprintf(stderr,"audio_open_input failed\n");
radio->local_microphone=FALSE;
}
}

}

void soapy_protocol_start_transmitter(TRANSMITTER *tx) {
Expand Down Expand Up @@ -254,12 +252,6 @@ static void *receive_thread(void *arg) {
long long timeNs=0;
long timeoutUs=100000L;
int i;
#ifdef TIMING
struct timeval tv;
long start_time, end_time;
rate_samples=0;
gettimeofday(&tv, NULL); start_time=tv.tv_usec + 1000000 * tv.tv_sec;
#endif
RECEIVER *rx=(RECEIVER *)arg;
float *buffer=g_new(float,max_samples*2);
void *buffs[]={buffer};
Expand All @@ -269,6 +261,8 @@ g_print("%s: receive_thread\n",__FUNCTION__);
elements=SoapySDRDevice_readStream(soapy_device,rx_stream,buffs,max_samples,&flags,&timeNs,timeoutUs);
if(elements<0) {
g_print("%s: elements=%d max_samples=%d\n",__FUNCTION__,elements,max_samples);
running=FALSE;
break;
}
for(i=0;i<elements;i++) {
rx->buffer[i*2]=(double)buffer[i*2];
Expand Down Expand Up @@ -321,15 +315,6 @@ g_print("resampler: elements in=%d out=%d\n",elements,out_elements);
} else {
add_iq_samples(rx,isample,qsample);
}
#ifdef TIMING
rate_samples++;
if(rate_samples>=rx->sample_rate) {
gettimeofday(&tv, NULL); end_time=tv.tv_usec + 1000000 * tv.tv_sec;
g_print("%d samples in %ld usec\n",rx->sample_rate,end_time-start_time);
rate_samples=0;
start_time=end_time;
}
#endif
}
}
}
Expand All @@ -338,9 +323,9 @@ g_print("%s: receive_thread: SoapySDRDevice_deactivateStream\n",__FUNCTION__);
SoapySDRDevice_deactivateStream(soapy_device,rx_stream,0,0LL);
g_print("%s: receive_thread: SoapySDRDevice_closeStream\n",__FUNCTION__);
SoapySDRDevice_closeStream(soapy_device,rx_stream);
g_print("%s: receive_thread: SoapySDRDevice_unmake\n",__FUNCTION__);
SoapySDRDevice_unmake(soapy_device);
_exit(0);
//g_print("%s: receive_thread: SoapySDRDevice_unmake\n",__FUNCTION__);
// SoapySDRDevice_unmake(soapy_device);
//_exit(0);
}

void soapy_protocol_process_local_mic(RADIO *r) {
Expand Down Expand Up @@ -490,3 +475,7 @@ void soapy_protocol_set_automatic_gain(RECEIVER *rx,gboolean mode) {
char *soapy_protocol_read_sensor(char *name) {
return SoapySDRDevice_readSensor(soapy_device, name);
}

gboolean soapy_protocol_is_running() {
return running;
}
1 change: 1 addition & 0 deletions soapy_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ void soapy_protocol_process_local_mic(RADIO *r);
void soapy_protocol_iq_samples(float isample,float qsample);
void soapy_protocol_set_mic_sample_rate(int rate);
char *soapy_protocol_read_sensor(char *name);
gboolean soapy_protocol_is_running();
#endif

0 comments on commit 1668438

Please sign in to comment.