diff --git a/DSP_API/SmartSDR_Interface/sched_waveform.c b/DSP_API/SmartSDR_Interface/sched_waveform.c index 4ddadf1..1a9c3a3 100644 --- a/DSP_API/SmartSDR_Interface/sched_waveform.c +++ b/DSP_API/SmartSDR_Interface/sched_waveform.c @@ -44,6 +44,8 @@ #include "sched_waveform.h" #include "vita_output.h" #include "thumbDV.h" +#include "bit_pattern_matcher.h" + //static Queue sched_fft_queue; static pthread_rwlock_t _list_lock; @@ -201,6 +203,7 @@ static int _dv_serial_fd = 0; static GMSK_DEMOD _gmsk_demod = NULL; static GMSK_MOD _gmsk_mod = NULL; +static BIT_PM _syn_pm = NULL; static void* _sched_waveform_thread(void* param) { @@ -348,11 +351,30 @@ static void* _sched_waveform_thread(void* param) // Convert to shorts and move to RX2_cb. if(cfbContains(RX1_cb) >= DV_PACKET_SAMPLES * DECIMATION_FACTOR) { + enum DEMOD_STATE state = DEMOD_UNKNOWN; for(i=0 ; i< DV_PACKET_SAMPLES * DECIMATION_FACTOR ; i++) { float_in_24k[i + MEM_24] = cbReadFloat(RX1_cb); + state = gmsk_decode(_gmsk_demod, float_in_24k[i+MEM_24]); + BOOL found_syn_bits = FALSE; + if ( state == DEMOD_TRUE ) { + found_syn_bits = bitPM_addBit(_syn_pm, TRUE); + //output("%d ", 1); + } else if ( state == DEMOD_FALSE ) { + found_syn_bits = bitPM_addBit(_syn_pm, FALSE); + //output("%d ", 0); + } else { + //output("UNKNOWN DEMOD STATE"); + //bits[bit] = 0x00; + } + + if ( found_syn_bits ) { + output("FOUND SYN BITS"); + bitPM_reset(_syn_pm); + } } + fdmdv_24_to_8(float_out_8k, &float_in_24k[MEM_24], DV_PACKET_SAMPLES); for(i=0 ; i< DV_PACKET_SAMPLES ; i++) @@ -386,13 +408,13 @@ static void* _sched_waveform_thread(void* param) // nout = thumbDV_decode(_dv_serial_fd, packet_out, speech_out, nout); // if (nout == 0 ) output("y"); // } - nout = thumbDV_decode(_dv_serial_fd, NULL, speech_out, nout); + //nout = thumbDV_decode(_dv_serial_fd, NULL, speech_out, nout); for( i=0 ; i < nout ; i++) { - cbWriteShort(RX3_cb, speech_out[i]); - //cbWriteShort(RX3_cb, demod_in[i]); + //cbWriteShort(RX3_cb, speech_out[i]); + cbWriteShort(RX3_cb, demod_in[i]); } } @@ -589,6 +611,7 @@ static void* _sched_waveform_thread(void* param) gmsk_destroyDemodulator(_gmsk_demod); gmsk_destroyModulator(_gmsk_mod); + bitPM_destroy(_syn_pm); return NULL; } @@ -598,6 +621,24 @@ void sched_waveform_Init(void) _gmsk_demod = gmsk_createDemodulator(); _gmsk_mod = gmsk_createModulator(); + BOOL syn_bits[64 + 15] = {0}; + uint32 i = 0; + uint32 j = 0; + for ( i = 0 ; i < 64 -1 ; i += 2 ) { + syn_bits[i] = TRUE; + syn_bits[i+1] = FALSE; + } + + BOOL frame_bits[] = {TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, + TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE}; + + for ( i = 64, j = 0 ; i < 64 + 15 ; i++,j++ ) { + syn_bits[i] = frame_bits[j]; + } + + _syn_pm = bitPM_create( syn_bits, 64+15); + + pthread_rwlock_init(&_list_lock, NULL); @@ -616,8 +657,8 @@ void sched_waveform_Init(void) fifo_param.sched_priority = 30; pthread_setschedparam(_waveform_thread, SCHED_FIFO, &fifo_param); - gmsk_testBitsAndEncodeDecode(); - exit(0); +// gmsk_testBitsAndEncodeDecode(); + //exit(0); } diff --git a/DSP_API/ThumbDV/bit_pattern_matcher.c b/DSP_API/ThumbDV/bit_pattern_matcher.c index 11458ba..5f7282a 100644 --- a/DSP_API/ThumbDV/bit_pattern_matcher.c +++ b/DSP_API/ThumbDV/bit_pattern_matcher.c @@ -55,6 +55,14 @@ BIT_PM bitPM_create(BOOL * to_match, uint32 length) for ( i = 0 ; i < length; i++ ) { bpm->pattern[n--] = to_match[i]; } + output("Creating pattern matcher !!!!!\n"); + for ( i = 0 ; i < length ; i++ ) { + output("%d", bpm->pattern[i]); + } output("\n"); + for ( i = 0 ; i < length ; i++ ) { + output("%d", to_match[i]); + } output("\n"); + memset(bpm->data, 0, length * sizeof(BOOL)); @@ -99,12 +107,12 @@ BOOL bitPM_addBit(BIT_PM bpm, BOOL bit) } } -#ifdef DEBUG_BIT_PM +//#ifdef DEBUG_BIT_PM output(ANSI_GREEN "Match Found\n"); for ( i = 0; i < bpm->length ; i++ ) { output("Pat: %d Data %d\n", bpm->pattern[i], bpm->data[i]); } -#endif +//#endif /* If we make it here all checks have passed */ return TRUE; diff --git a/DSP_API/ThumbDV/bit_pattern_matcher.h b/DSP_API/ThumbDV/bit_pattern_matcher.h index 57d6d92..8883190 100644 --- a/DSP_API/ThumbDV/bit_pattern_matcher.h +++ b/DSP_API/ThumbDV/bit_pattern_matcher.h @@ -32,6 +32,10 @@ * * ************************************************************************** */ + +#ifndef THUMBDV_BIT_PATTERN_MATCHER_H_ +#define THUMBDV_BIT_PATTERN_MATCHER_H_ + #include "datatypes.h" typedef struct _bit_pattern_matcher @@ -47,3 +51,5 @@ BIT_PM bitPM_create(BOOL * to_match, uint32 length); BOOL bitPM_addBit(BIT_PM bpm, BOOL bit); void bitPM_reset(BIT_PM bpm); + +#endif /* THUMBDV_BIT_PATTERN_MATCHER_H_ */ diff --git a/DSP_API/ThumbDV/thumbDV.c b/DSP_API/ThumbDV/thumbDV.c index 480dacb..79c13e5 100644 --- a/DSP_API/ThumbDV/thumbDV.c +++ b/DSP_API/ThumbDV/thumbDV.c @@ -631,7 +631,4 @@ void thumbDV_init(const char * serial_device_name, int * serial_fd) thumbDV_writeSerial(*serial_fd, test_coded, 15); - - - }