2008-05-31 22:26:53 +00:00
|
|
|
/* -*- C++ -*- */
|
2008-11-09 22:41:29 +00:00
|
|
|
|
2008-05-31 22:26:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Steve Glass
|
|
|
|
*
|
|
|
|
* This file is part of OP25.
|
|
|
|
*
|
|
|
|
* OP25 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.
|
|
|
|
*
|
|
|
|
* OP25 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 OP25; 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
|
|
|
|
|
2008-09-09 09:03:37 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <op25_decoder_ff.h>
|
2008-05-31 22:26:53 +00:00
|
|
|
#include <gr_io_signature.h>
|
2008-11-02 11:34:28 +00:00
|
|
|
#include <gr_message.h>
|
2008-05-31 22:26:53 +00:00
|
|
|
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff_sptr
|
|
|
|
op25_make_decoder_ff(gr_msg_queue_sptr msgq)
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
2008-09-09 09:03:37 +00:00
|
|
|
return op25_decoder_ff_sptr(new op25_decoder_ff(msgq));
|
2008-05-31 22:26:53 +00:00
|
|
|
}
|
|
|
|
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff::~op25_decoder_ff()
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-09-09 09:03:37 +00:00
|
|
|
void
|
|
|
|
op25_decoder_ff::forecast(int nof_output_items, gr_vector_int &nof_input_items_reqd)
|
|
|
|
{
|
2008-11-07 10:14:00 +00:00
|
|
|
#if 0
|
2008-09-09 09:03:37 +00:00
|
|
|
const int nof_symbols_per_LDU = 864;
|
|
|
|
const size_t nof_inputs = nof_input_items_reqd.size();
|
|
|
|
std::fill(&nof_input_items_reqd[0], &nof_input_items_reqd[nof_inputs], nof_symbols_per_LDU);
|
2008-11-07 10:14:00 +00:00
|
|
|
#else
|
|
|
|
const size_t nof_inputs = nof_input_items_reqd.size();
|
|
|
|
std::fill(&nof_input_items_reqd[0], &nof_input_items_reqd[nof_inputs], nof_output_items);
|
|
|
|
#endif
|
2008-09-09 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
2008-05-31 22:26:53 +00:00
|
|
|
int
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff::general_work(int nof_output_items, gr_vector_int& nof_input_items, gr_vector_const_void_star& input_items, gr_vector_void_star& output_items)
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
|
|
|
const float *in = reinterpret_cast<const float*>(input_items[0]);
|
|
|
|
for(int i = 0; i < nof_output_items; ++i) {
|
|
|
|
dibit d;
|
|
|
|
if(in[i] < -2.0) {
|
|
|
|
d = 3;
|
|
|
|
} else if(in[i] < 0.0) {
|
|
|
|
d = 2;
|
|
|
|
} else if(in[i] < 2.0) {
|
|
|
|
d = 0;
|
|
|
|
} else {
|
|
|
|
d = 1;
|
|
|
|
}
|
|
|
|
receive_symbol(d);
|
|
|
|
}
|
2008-11-07 10:14:00 +00:00
|
|
|
consume_each(nof_input_items[0]);
|
|
|
|
|
|
|
|
// for now audio silence is output
|
|
|
|
float *out = reinterpret_cast<float*>(output_items[0]);
|
|
|
|
std::fill(&out[0], &out[nof_output_items], 0.0);
|
|
|
|
return nof_output_items;
|
2008-05-31 22:26:53 +00:00
|
|
|
}
|
|
|
|
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff::op25_decoder_ff(gr_msg_queue_sptr msgq) :
|
|
|
|
gr_block("decoder_ff", gr_make_io_signature(1, 1, sizeof(float)), gr_make_io_signature(1, 1, sizeof(float))),
|
2008-05-31 22:26:53 +00:00
|
|
|
d_msgq(msgq),
|
|
|
|
d_state(SYNCHRONIZING),
|
|
|
|
d_substate(IDENTIFYING),
|
|
|
|
d_data_unit(),
|
|
|
|
d_data_units(0),
|
2008-11-09 22:41:29 +00:00
|
|
|
d_frame_sync(0),
|
|
|
|
d_network_ID(0),
|
|
|
|
d_symbol(0),
|
2008-05-31 22:26:53 +00:00
|
|
|
d_unrecognized(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff::correlates(dibit d)
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
|
|
|
size_t errs = 0;
|
2008-06-09 20:58:52 +00:00
|
|
|
const size_t ERR_THRESHOLD = 4;
|
2008-05-31 22:26:53 +00:00
|
|
|
const size_t NOF_FS_BITS = 48;
|
2008-10-29 11:41:41 +00:00
|
|
|
const uint64_t FS = 0x5575f5ff77ffLL;
|
|
|
|
const uint64_t FS_MASK = 0xffffffffffffLL;
|
2008-09-06 21:25:58 +00:00
|
|
|
d_frame_sync = (d_frame_sync << 2) | d;
|
2008-05-31 22:26:53 +00:00
|
|
|
d_frame_sync &= FS_MASK;
|
|
|
|
size_t diff = FS ^ d_frame_sync;
|
|
|
|
for(size_t i = 0; i < NOF_FS_BITS; ++i) {
|
|
|
|
if(diff & 0x1) {
|
|
|
|
++errs;
|
|
|
|
}
|
|
|
|
diff >>= 1;
|
|
|
|
}
|
2008-06-09 20:58:52 +00:00
|
|
|
return errs < ERR_THRESHOLD;
|
2008-05-31 22:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff::identifies(dibit d)
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
|
|
|
bool identified = false;
|
|
|
|
d_network_ID <<= 2;
|
|
|
|
d_network_ID |= d;
|
|
|
|
const size_t LAST_NETWORK_ID_SYMBOL = 56;
|
|
|
|
if(LAST_NETWORK_ID_SYMBOL == d_symbol) {
|
|
|
|
identified = true;
|
|
|
|
}
|
|
|
|
return identified;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff::receive_symbol(dibit d)
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
|
|
|
switch(d_state) {
|
|
|
|
case SYNCHRONIZING:
|
|
|
|
if(correlates(d)) {
|
|
|
|
d_symbol = 24;
|
|
|
|
d_state = SYNCHRONIZED;
|
|
|
|
d_substate = IDENTIFYING;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SYNCHRONIZED:
|
2008-09-06 21:25:58 +00:00
|
|
|
sync_receive_symbol(d);
|
2008-05-31 22:26:53 +00:00
|
|
|
++d_symbol;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff::sync_receive_symbol(dibit d)
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
|
|
|
switch(d_substate) {
|
|
|
|
case IDENTIFYING:
|
|
|
|
if(identifies(d)) {
|
|
|
|
d_data_unit = data_unit::make_data_unit(d_frame_sync, d_network_ID);
|
|
|
|
if(d_data_unit) {
|
|
|
|
d_substate = READING;
|
|
|
|
} else {
|
|
|
|
++d_unrecognized;
|
|
|
|
d_state = SYNCHRONIZING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case READING:
|
|
|
|
if(d_data_unit->complete(d)) {
|
2008-11-02 11:34:28 +00:00
|
|
|
size_t msg_sz = d_data_unit->size();
|
|
|
|
gr_message_sptr msg = gr_make_message(/*type*/0, /*arg1*/++d_data_units, /*arg2*/0, msg_sz);
|
|
|
|
uint8_t *msg_data = static_cast<uint8_t*>(msg->msg());
|
2008-11-09 22:41:29 +00:00
|
|
|
if((msg_sz = d_data_unit->decode(msg_sz, msg_data))) {
|
2008-11-02 11:34:28 +00:00
|
|
|
d_msgq->handle(msg);
|
2008-05-31 22:26:53 +00:00
|
|
|
}
|
|
|
|
data_unit_sptr null;
|
|
|
|
d_data_unit = null;
|
|
|
|
d_state = SYNCHRONIZING;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|