git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@372 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2018-12-16 07:48:58 +00:00
parent 7b23044599
commit a87d2f154e
72 changed files with 19380 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
# Copyright 2011,2012,2016 Free Software Foundation, Inc.
#
# This file was generated by gr_modtool, a tool from the GNU Radio framework
# This file is a part of gr-jay
#
# GNU Radio 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, or (at your option)
# any later version.
#
# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
########################################################################
# Setup library
########################################################################
include(GrPlatform) #define LIB_SUFFIX
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
list(APPEND jay_sources
square_ff_impl.cc
square2_ff_impl.cc
garage_impl.cc
)
set(jay_sources "${jay_sources}" PARENT_SCOPE)
if(NOT jay_sources)
MESSAGE(STATUS "No C++ sources... skipping lib/")
return()
endif(NOT jay_sources)
add_library(gnuradio-jay SHARED ${jay_sources})
target_link_libraries(gnuradio-jay ${Boost_LIBRARIES} ${GNURADIO_ALL_LIBRARIES})
set_target_properties(gnuradio-jay PROPERTIES DEFINE_SYMBOL "gnuradio_jay_EXPORTS")
if(APPLE)
set_target_properties(gnuradio-jay PROPERTIES
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
)
endif(APPLE)
########################################################################
# Install built library files
########################################################################
include(GrMiscUtils)
GR_LIBRARY_FOO(gnuradio-jay RUNTIME_COMPONENT "jay_runtime" DEVEL_COMPONENT "jay_devel")
########################################################################
# Build and register unit test
########################################################################
include(GrTest)
include_directories(${CPPUNIT_INCLUDE_DIRS})
list(APPEND test_jay_sources
${CMAKE_CURRENT_SOURCE_DIR}/test_jay.cc
${CMAKE_CURRENT_SOURCE_DIR}/qa_jay.cc
)
add_executable(test-jay ${test_jay_sources})
target_link_libraries(
test-jay
${GNURADIO_RUNTIME_LIBRARIES}
${Boost_LIBRARIES}
${CPPUNIT_LIBRARIES}
gnuradio-jay
)
GR_ADD_TEST(test_jay test-jay)
########################################################################
# Print summary
########################################################################
message(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Building for version: ${VERSION} / ${LIBVER}")
+280
View File
@@ -0,0 +1,280 @@
/* -*- c++ -*- */
/*
* Copyright 2018 Jay Arrowfield.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "garage_impl.h"
#define WITH_DEBUG_MESSAGES 0
#define WITH_DEBUG_FILE 0
namespace gr
{
namespace jay
{
garage::sptr garage::make(int sampleRate, int samplesPerSym, float kLoopFilter, float kThreshold)
{
return gnuradio::get_initial_sptr(new garage_impl(sampleRate, samplesPerSym, kLoopFilter, kThreshold));
}
/*
* The private constructor
*/
garage_impl::garage_impl(int sampleRate, int samplesPerSym, float kLoopFilter, float kThreshold)
: gr::block("garage", gr::io_signature::make(1, 1, sizeof(float)),
gr::io_signature::make(1, 1, sizeof(float)))
, m_sampleRate(sampleRate)
, m_samplesPerSym(samplesPerSym)
, m_count(samplesPerSym)
, m_baudRate((float)m_sampleRate/m_samplesPerSym)
, m_kLoopFilter(kLoopFilter)
, m_kThreshold(kThreshold)
, m_vmin(0)
, m_vmax(0)
, m_v_thr(0)
, m_lag_accu(0)
, m_bit(0)
, m_i(0)
, m_gapDistance(8*m_samplesPerSym)
, m_gapCounter(0)
, m_gapCounterEnable(0)
, m_packetCounter(0)
, m_bitCounter(0)
, m_sampleCounter(0)
, m_pFile_y(nullptr)
, m_pFile_bits(nullptr)
{
}
/*
* Our virtual destructor.
*/
garage_impl::~garage_impl()
{
}
bool garage_impl::start()
{
fprintf(stderr, "Opening garage\n");
#if WITH_DEBUG_FILE
m_pFile_y = fopen("/home/jens/garage_y.dat", "w");
m_pFile_bits = fopen("/home/jens/garage_bits.dat", "w");
#endif
return true;
}
bool garage_impl::stop()
{
fprintf(stderr, "Closing garage\n");
if (m_pFile_y)
{
fclose(m_pFile_y);
}
if (m_pFile_bits)
{
fclose(m_pFile_bits);
}
return true;
}
void garage_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
ninput_items_required[0] = m_samplesPerSym*noutput_items;
}
int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
{
float rho = 1e-5;
const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0];
int outCount = 0;
int inCount = 0;
// Do <+signal processing+>
int countReload = m_samplesPerSym-1;
float alpha_thr = 0.5f;
float hyst_thr = 0.5f;
float k_leadLag = m_kLoopFilter;
float loopThreshold = m_kThreshold;
float k_lead = 1.0e-1f;
float k_lag = 1.0e-4f;
float k_leak = 0;
float err = 0;
int i_i = 0;
while ((i_i+1) < ninput_items[0])
{
// Get next interpolated sample
float i_f = m_i - (float)i_i;
float y = (1.f-i_f)*in[i_i] + i_f*in[i_i+1];
// Calculate threshold
m_v_thr = (fabs(m_vmax) - fabs(m_vmin))/2;
if (y < m_vmin)
{
m_vmin = (1-alpha_thr)*m_vmin + alpha_thr*y;
}
else if (y > m_vmax)
{
m_vmax = (1-alpha_thr)*m_vmax + alpha_thr*y;
}
m_vmin = m_vmin + rho*(m_v_thr - m_vmin);
m_vmax = m_vmax + rho*(m_v_thr - m_vmax);
// Detect bit change
int bitChg = 0;
if (m_bit == 1)
{
if (y < (hyst_thr*m_v_thr))
{
m_bit = 0;
bitChg = 1;
}
}
else
{
if (y > (hyst_thr*m_v_thr))
{
m_bit = 1;
bitChg = 1;
}
}
bitProcessGap(bitChg);
// Calc error
err = 0;
if (bitChg and (m_v_thr >= loopThreshold))
{
err = -(m_count - (int)(m_samplesPerSym/2));
}
float vcorr = k_leadLag*k_lead*err + m_lag_accu;
// Lag part of loop filter
m_lag_accu += k_leadLag*k_lag*err;
m_lag_accu *= (1.f - k_leak);
m_baudRate = (float)m_sampleRate/((1+vcorr)*m_samplesPerSym);
// Sample bit at baud rate = fs/numSamplesPerSym
if (m_count == 0)
{
out[outCount++] = (float)m_bit;
m_count = countReload;
bitRecord(m_bit);
if (m_pFile_bits)
{
fprintf(m_pFile_bits, "%f %f\n", (float)m_sampleCounter/m_sampleRate, y);
}
}
else
{
m_count--;
}
if (m_pFile_y)
{
fprintf(m_pFile_y, "%f %f %f %f\n", (float)m_sampleCounter/m_sampleRate, y, m_v_thr, vcorr);
}
m_sampleCounter++;
m_i += (1+vcorr);
i_i = (int)m_i;
inCount++;
if (inCount >= ninput_items[0])
{
break;
}
if (i_i >= (float)ninput_items[0])
{
break;
}
}
#if WITH_DEBUG_MESSAGES
fprintf(stderr, "ninput_items[0] = %d\n", ninput_items[0]);
fprintf(stderr, "m_i = %f\n", m_i);
fprintf(stderr, "inCount = %d\n", inCount);
fprintf(stderr, "outCount = %d\n", outCount);
#endif
// Tell runtime system how many input items we consumed on
// each input stream.
m_i -= i_i;
consume_each (i_i);
// Tell runtime system how many output items we produced.
return outCount;
}
void garage_impl::bitsPrint()
{
for (int k=0; k < m_bitCounter; k++)
{
printf("%d", m_bits[k]);
}
printf("\n");
printf("Recorded %d bits\n", m_bitCounter);
}
void garage_impl::bitRecord(int bit)
{
if (m_bitCounter < sizeof(m_bits)/sizeof(*m_bits))
{
m_bits[m_bitCounter++] = bit;
}
}
void garage_impl::bitProcessGap(int bitChg)
{
if (bitChg)
{
if (!m_gapCounterEnable)
{
m_bitCounter = 0;
}
m_gapCounterEnable = 1;
m_gapCounter = 0;
}
else
{
m_gapCounter += m_gapCounterEnable;
if (m_gapCounter >= m_gapDistance)
{
m_gapCounter = 0;
m_gapCounterEnable = 0;
printf("------------------------\n");
printf("Packet: %03d\n", m_packetCounter++);
bitsPrint();
fprintf(stderr, "baudrate = %d\n", (int)m_baudRate);
}
}
}
} /* namespace jay */
} /* namespace gr */
+80
View File
@@ -0,0 +1,80 @@
/* -*- c++ -*- */
/*
* Copyright 2018 Jay Arrowfield.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_JAY_GARAGE_IMPL_H
#define INCLUDED_JAY_GARAGE_IMPL_H
#include <jay/garage.h>
namespace gr
{
namespace jay
{
class garage_impl : public garage
{
private:
int m_sampleRate;
int m_samplesPerSym;
int m_count;
float m_baudRate;
float m_kLoopFilter;
float m_kThreshold;
float m_vmin;
float m_vmax;
float m_v_thr;
float m_lag_accu;
int m_bit;
float m_i;
int m_gapDistance;
int m_gapCounter;
int m_gapCounterEnable;
int m_packetCounter;
int m_bitCounter;
uint64_t m_sampleCounter;
int m_bits[4096];
FILE *m_pFile_y;
FILE *m_pFile_bits;
void bitProcessGap(int bitChg);
void bitRecord(int bit);
void bitsPrint();
bool start() override;
bool stop() override;
public:
garage_impl(int sampleRate, int samplesPerSym, float kLoopFilter, float kThreshold);
~garage_impl();
// Where all the action really happens
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
} // namespace jay
} // namespace gr
#endif /* INCLUDED_JAY_GARAGE_IMPL_H */
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright 2012 Free Software Foundation, Inc.
*
* This file was generated by gr_modtool, a tool from the GNU Radio framework
* This file is a part of gr-jay
*
* GNU Radio 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, or (at your option)
* any later version.
*
* GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/*
* This class gathers together all the test cases for the gr-filter
* directory into a single test suite. As you create new test cases,
* add them here.
*/
#include "qa_jay.h"
CppUnit::TestSuite *
qa_jay::suite()
{
CppUnit::TestSuite *s = new CppUnit::TestSuite("jay");
return s;
}
+39
View File
@@ -0,0 +1,39 @@
/* -*- c++ -*- */
/*
* Copyright 2012 Free Software Foundation, Inc.
*
* This file was generated by gr_modtool, a tool from the GNU Radio framework
* This file is a part of gr-jay
*
* GNU Radio 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, or (at your option)
* any later version.
*
* GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef _QA_JAY_H_
#define _QA_JAY_H_
#include <gnuradio/attributes.h>
#include <cppunit/TestSuite.h>
//! collect all the tests for the gr-filter directory
class __GR_ATTR_EXPORT qa_jay
{
public:
//! return suite of tests for all of gr-filter directory
static CppUnit::TestSuite *suite();
};
#endif /* _QA_JAY_H_ */
+75
View File
@@ -0,0 +1,75 @@
/* -*- c++ -*- */
/*
* Copyright 2018 gr-jay author.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "square2_ff_impl.h"
namespace gr {
namespace jay {
square2_ff::sptr
square2_ff::make()
{
return gnuradio::get_initial_sptr
(new square2_ff_impl());
}
/*
* The private constructor
*/
square2_ff_impl::square2_ff_impl()
: gr::sync_block("square2_ff",
gr::io_signature::make(1, 1, sizeof (float)),
gr::io_signature::make(1, 1, sizeof (float)))
{}
/*
* Our virtual destructor.
*/
square2_ff_impl::~square2_ff_impl()
{
}
int
square2_ff_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0];
// Do <+signal processing+>
for(int i = 0; i < noutput_items; i++)
{
out[i] = in[i] * in[i];
}
// Tell runtime system how many output items we produced.
return noutput_items;
}
} /* namespace jay */
} /* namespace gr */
+48
View File
@@ -0,0 +1,48 @@
/* -*- c++ -*- */
/*
* Copyright 2018 gr-jay author.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_JAY_SQUARE2_FF_IMPL_H
#define INCLUDED_JAY_SQUARE2_FF_IMPL_H
#include <jay/square2_ff.h>
namespace gr {
namespace jay {
class square2_ff_impl : public square2_ff
{
private:
// Nothing to declare in this block.
public:
square2_ff_impl();
~square2_ff_impl();
// Where all the action really happens
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
} // namespace jay
} // namespace gr
#endif /* INCLUDED_JAY_SQUARE2_FF_IMPL_H */
+93
View File
@@ -0,0 +1,93 @@
/* -*- c++ -*- */
/*
* Copyright 2018 gr-jay author.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "square_ff_impl.h"
namespace gr {
namespace jay {
square_ff::sptr square_ff::make()
{
return gnuradio::get_initial_sptr(new square_ff_impl());
}
/*
* The private constructor
*/
square_ff_impl::square_ff_impl()
: gr::block("square_ff",
gr::io_signature::make(1, 1, sizeof(float)),
gr::io_signature::make(1, 1, sizeof(float)))
{
fprintf(stderr, "Halloooooooooooooooooooo\n");
}
/*
* Our virtual destructor.
*/
square_ff_impl::~square_ff_impl()
{
}
long min_output_buffer(size_t i)
{
fprintf(stderr, "min_output_buffer\n");
return 1;
}
void
square_ff_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
printf("noutput_items = %u\n", noutput_items);
ninput_items_required[0] = noutput_items;
}
int
square_ff_impl::general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0];
// Do <+signal processing+>
for (int i=0; i < noutput_items; i++)
{
out[i] = in[i] * in[i];
}
// Tell runtime system how many input items we consumed on
// each input stream.
consume_each (noutput_items);
// Tell runtime system how many output items we produced.
return noutput_items;
}
} /* namespace jay */
} /* namespace gr */
+51
View File
@@ -0,0 +1,51 @@
/* -*- c++ -*- */
/*
* Copyright 2018 gr-jay author.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_JAY_SQUARE_FF_IMPL_H
#define INCLUDED_JAY_SQUARE_FF_IMPL_H
#include <jay/square_ff.h>
namespace gr {
namespace jay {
class square_ff_impl : public square_ff
{
private:
// Nothing to declare in this block.
public:
square_ff_impl();
~square_ff_impl();
// Where all the action really happens
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
} // namespace jay
} // namespace gr
#endif /* INCLUDED_JAY_SQUARE_FF_IMPL_H */
+49
View File
@@ -0,0 +1,49 @@
/* -*- c++ -*- */
/*
* Copyright 2012 Free Software Foundation, Inc.
*
* This file was generated by gr_modtool, a tool from the GNU Radio framework
* This file is a part of gr-jay
*
* GNU Radio 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, or (at your option)
* any later version.
*
* GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <cppunit/TextTestRunner.h>
#include <cppunit/XmlOutputter.h>
#include <gnuradio/unittests.h>
#include "qa_jay.h"
#include <iostream>
#include <fstream>
int
main (int argc, char **argv)
{
CppUnit::TextTestRunner runner;
std::ofstream xmlfile(get_unittest_path("jay.xml").c_str());
CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile);
runner.addTest(qa_jay::suite());
runner.setOutputter(xmlout);
bool was_successful = runner.run("", false);
return was_successful ? 0 : 1;
}