mirror of
https://github.com/n5ac/smartsdr-dsp.git
synced 2026-02-01 12:54:16 +01:00
Add bit pattern match files and functions
This commit is contained in:
parent
81bb26dc15
commit
a5609ca279
|
|
@ -587,6 +587,9 @@ static void* _sched_waveform_thread(void* param)
|
|||
}
|
||||
_waveform_thread_abort = TRUE;
|
||||
|
||||
gmsk_destroyDemodulator(_gmsk_demod);
|
||||
gmsk_destroyModulator(_gmsk_mod);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -613,7 +616,8 @@ void sched_waveform_Init(void)
|
|||
fifo_param.sched_priority = 30;
|
||||
pthread_setschedparam(_waveform_thread, SCHED_FIFO, &fifo_param);
|
||||
|
||||
//gmsk_testBitsAndEncodeDecode();
|
||||
gmsk_testBitsAndEncodeDecode();
|
||||
exit(0);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
111
DSP_API/ThumbDV/bit_pattern_matcher.c
Normal file
111
DSP_API/ThumbDV/bit_pattern_matcher.c
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
///*! \file bit_pattern_matcher.c
|
||||
// * \brief Allows matching of a pattern in an array ob gits.
|
||||
// *
|
||||
// * \copyright Copyright 2012-2014 FlexRadio Systems. All Rights Reserved.
|
||||
// * Unauthorized use, duplication or distribution of this software is
|
||||
// * strictly prohibited by law.
|
||||
// *
|
||||
// * \date 26-MAY-2015
|
||||
// * \author Ed Gonzalez
|
||||
// *
|
||||
// *
|
||||
// */
|
||||
|
||||
/* *****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 FlexRadio Systems.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact Information:
|
||||
* email: gpl<at>flexradiosystems.com
|
||||
* Mail: FlexRadio Systems, Suite 1-150, 4616 W. Howard LN, Austin, TX 78728
|
||||
*
|
||||
* ************************************************************************** */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "bit_pattern_matcher.h"
|
||||
|
||||
BIT_PM bitPM_create(BOOL * to_match, uint32 length)
|
||||
{
|
||||
BIT_PM bpm = (BIT_PM) safe_malloc(sizeof(bit_pm));
|
||||
|
||||
bpm->pattern = (BOOL *) safe_malloc(sizeof(BOOL) * length);
|
||||
bpm->data = (BOOL *) safe_malloc(sizeof(BOOL) * length);
|
||||
bpm->length = length;
|
||||
bpm->data_length = 0;
|
||||
|
||||
/* We have to put the pattern in reverse since
|
||||
* the samples are fed left to right
|
||||
*/
|
||||
uint32 i = 0;
|
||||
uint32 n = length - 1;
|
||||
for ( i = 0 ; i < length; i++ ) {
|
||||
bpm->pattern[n--] = to_match[i];
|
||||
}
|
||||
|
||||
memset(bpm->data, 0, length * sizeof(BOOL));
|
||||
|
||||
return bpm;
|
||||
}
|
||||
|
||||
void bitPM_destroy(BIT_PM bpm)
|
||||
{
|
||||
safe_free(bpm->data);
|
||||
safe_free(bpm->pattern);
|
||||
safe_free(bpm);
|
||||
}
|
||||
|
||||
void bitPM_reset(BIT_PM bpm)
|
||||
{
|
||||
bpm->data_length = 0;
|
||||
memset(bpm->data, 0, bpm->length * sizeof(BOOL));
|
||||
}
|
||||
|
||||
BOOL bitPM_addBit(BIT_PM bpm, BOOL bit)
|
||||
{
|
||||
uint32 i = 0;
|
||||
/* Shift the existing buffer to make space for new bit */
|
||||
for ( i = bpm->length - 1; i >= 1 ; i-- ) {
|
||||
bpm->data[i] = bpm->data[i-1];
|
||||
}
|
||||
|
||||
bpm->data[0] = bit;
|
||||
|
||||
if ( bpm->data_length < bpm->length ) {
|
||||
bpm->data_length++;
|
||||
}
|
||||
|
||||
if ( bpm->data_length != bpm->length ) {
|
||||
/* If not enough data has accumulated then simply return FALSE */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for ( i = 0; i < bpm->length ; i++ ) {
|
||||
if ( bpm->pattern[i] != bpm->data[i]) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
/* If we make it here all checks have passed */
|
||||
return TRUE;
|
||||
}
|
||||
49
DSP_API/ThumbDV/bit_pattern_matcher.h
Normal file
49
DSP_API/ThumbDV/bit_pattern_matcher.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
///*! \file bit_pattern_matcher.h
|
||||
// * \brief Allows matching of a pattern in an array ob gits.
|
||||
// *
|
||||
// * \copyright Copyright 2012-2014 FlexRadio Systems. All Rights Reserved.
|
||||
// * Unauthorized use, duplication or distribution of this software is
|
||||
// * strictly prohibited by law.
|
||||
// *
|
||||
// * \date 26-MAY-2015
|
||||
// * \author Ed Gonzalez
|
||||
// *
|
||||
// *
|
||||
// */
|
||||
|
||||
/* *****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 FlexRadio Systems.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact Information:
|
||||
* email: gpl<at>flexradiosystems.com
|
||||
* Mail: FlexRadio Systems, Suite 1-150, 4616 W. Howard LN, Austin, TX 78728
|
||||
*
|
||||
* ************************************************************************** */
|
||||
|
||||
#include "datatypes.h"
|
||||
|
||||
typedef struct _bit_pattern_matcher
|
||||
{
|
||||
BOOL * pattern;
|
||||
BOOL * data;
|
||||
uint32 length;
|
||||
uint32 data_length;
|
||||
} bit_pm, * BIT_PM;
|
||||
|
||||
void bitPM_destroy(BIT_PM bpm);
|
||||
BIT_PM bitPM_create(BOOL * to_match, uint32 length);
|
||||
|
||||
BOOL bitPM_addBit(BIT_PM bpm, BOOL bit);
|
||||
void bitPM_reset(BIT_PM bpm);
|
||||
|
|
@ -28,9 +28,11 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "DStarDefines.h"
|
||||
#include "gmsk_modem.h"
|
||||
#include "common.h"
|
||||
#include "bit_pattern_matcher.h"
|
||||
|
||||
|
||||
/* Filters */
|
||||
|
||||
|
|
@ -402,17 +404,22 @@ void gmsk_destroyModulator(GMSK_MOD mod )
|
|||
|
||||
void gmsk_testBitsAndEncodeDecode(void)
|
||||
{
|
||||
|
||||
GMSK_DEMOD _gmsk_demod = gmsk_createDemodulator();
|
||||
GMSK_MOD _gmsk_mod = gmsk_createModulator();
|
||||
|
||||
unsigned char pattern = 0xAA;
|
||||
BOOL pattern_bits[8] = {0};
|
||||
gmsk_bytesToBits(&pattern, pattern_bits, 8);
|
||||
|
||||
BIT_PM _bit_pm = bitPM_create(pattern_bits, 8);
|
||||
|
||||
float test_buffer[160*2];
|
||||
unsigned char test_coded[8] = {0xAA,0xAA,0xFF,0x00,0xFF,0x00,0xFF,0x00};
|
||||
unsigned char output_bytes[8] = {0};
|
||||
uint32 i = 0;
|
||||
|
||||
|
||||
BOOL bits[32] = {0};
|
||||
BOOL bits[64] = {0};
|
||||
gmsk_bytesToBits(test_coded, bits, 32);
|
||||
gmsk_byteToBits(0xF0, bits, 8);
|
||||
output("0xF0 = ");
|
||||
|
|
@ -428,7 +435,7 @@ void gmsk_testBitsAndEncodeDecode(void)
|
|||
gmsk_bitsToByte(&bits[i*8], &output_bytes[i]);
|
||||
output("Byte = 0x%02X\n", output_bytes[i]);
|
||||
}
|
||||
//
|
||||
|
||||
gmsk_encodeBuffer(_gmsk_mod, test_coded, 32*2, test_buffer, 160*2);
|
||||
FILE * dat = fopen("gmsk.dat", "w");
|
||||
for ( i = 0 ; i < 160*2 ; i++ ) {
|
||||
|
|
@ -439,6 +446,18 @@ void gmsk_testBitsAndEncodeDecode(void)
|
|||
|
||||
gmsk_decodeBuffer(_gmsk_demod, test_buffer, 160*2, output_bytes, 32*2);
|
||||
|
||||
gmsk_bytesToBits(output_bytes, bits, 32*2);
|
||||
output("STARTING PATTERN MATCH TEST \n");
|
||||
for ( i = 0 ; i < 32*2; i++ ) {
|
||||
output("%d ", bits[i]);
|
||||
if ( bitPM_addBit(_bit_pm, bits[i]) ) {
|
||||
output("MATCH!\n");
|
||||
bitPM_reset(_bit_pm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bitPM_destroy(_bit_pm);
|
||||
gmsk_destroyDemodulator(_gmsk_demod);
|
||||
gmsk_destroyModulator(_gmsk_mod);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
* Mail: FlexRadio Systems, Suite 1-150, 4616 W. Howard LN, Austin, TX 78728
|
||||
*
|
||||
* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
Loading…
Reference in a new issue