2018-11-29 01:41:36 +01:00
|
|
|
/* -*- c++ -*- */
|
|
|
|
/*
|
|
|
|
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018, Libre Space Foundation <http://librespacefoundation.org/>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gnuradio/io_signature.h>
|
2018-12-01 23:47:56 +01:00
|
|
|
|
2018-11-29 01:41:36 +01:00
|
|
|
#include "frame_acquisition_impl.h"
|
|
|
|
|
2018-12-01 23:47:56 +01:00
|
|
|
#include <satnogs/golay24.h>
|
2018-12-03 00:42:14 +01:00
|
|
|
#include <satnogs/log.h>
|
|
|
|
#include <satnogs/utils.h>
|
|
|
|
#include <arpa/inet.h>
|
2018-12-01 23:47:56 +01:00
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
namespace gr {
|
|
|
|
namespace satnogs {
|
2018-11-29 01:41:36 +01:00
|
|
|
|
|
|
|
frame_acquisition::sptr
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition::make(variant_t variant,
|
|
|
|
const std::vector<uint8_t> &preamble,
|
|
|
|
size_t preamble_threshold,
|
|
|
|
const std::vector<uint8_t> &sync,
|
|
|
|
size_t sync_threshold,
|
|
|
|
size_t frame_size_field_len,
|
|
|
|
size_t frame_len,
|
|
|
|
checksum_t crc,
|
|
|
|
whitening::whitening_sptr descrambler,
|
|
|
|
size_t max_frame_len)
|
2018-12-01 23:47:56 +01:00
|
|
|
{
|
2019-09-12 15:25:10 +02:00
|
|
|
return gnuradio::get_initial_sptr(
|
|
|
|
new frame_acquisition_impl(variant,
|
|
|
|
preamble,
|
|
|
|
preamble_threshold,
|
|
|
|
sync,
|
|
|
|
sync_threshold,
|
|
|
|
frame_size_field_len,
|
|
|
|
frame_len,
|
|
|
|
crc,
|
|
|
|
descrambler,
|
|
|
|
max_frame_len));
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition_impl::frame_acquisition_impl(variant_t variant,
|
|
|
|
const std::vector<uint8_t> &preamble,
|
|
|
|
size_t preamble_threshold,
|
|
|
|
const std::vector<uint8_t> &sync,
|
|
|
|
size_t sync_threshold,
|
|
|
|
size_t frame_size_field_len,
|
|
|
|
size_t frame_len,
|
|
|
|
checksum_t crc,
|
|
|
|
whitening::whitening_sptr descrambler,
|
|
|
|
size_t max_frame_len) :
|
|
|
|
gr::sync_block("frame_acquisition",
|
|
|
|
gr::io_signature::make(1, 1, sizeof(uint8_t)),
|
|
|
|
gr::io_signature::make(0, 0, 0)),
|
|
|
|
d_variant(variant),
|
|
|
|
d_preamble(preamble.size() * 8),
|
|
|
|
d_preamble_shift_reg(preamble.size() * 8),
|
|
|
|
d_preamble_len(preamble.size() * 8),
|
|
|
|
d_preamble_thrsh(preamble_threshold),
|
|
|
|
d_sync(sync.size() * 8),
|
|
|
|
d_sync_shift_reg(sync.size() * 8),
|
|
|
|
d_sync_len(sync.size() * 8),
|
|
|
|
d_sync_thrsh(sync_threshold),
|
|
|
|
d_state(SEARCHING),
|
|
|
|
d_cnt(0),
|
|
|
|
d_frame_size_field_len(frame_size_field_len),
|
|
|
|
d_frame_len(frame_len),
|
|
|
|
d_max_frame_len(max_frame_len),
|
|
|
|
d_crc(crc),
|
|
|
|
d_crc_len(0),
|
|
|
|
d_whitening(descrambler)
|
2018-11-29 01:41:36 +01:00
|
|
|
{
|
|
|
|
set_output_multiple(8);
|
2019-09-12 15:25:10 +02:00
|
|
|
for (uint8_t b : preamble) {
|
2018-11-29 01:41:36 +01:00
|
|
|
d_preamble <<= (b >> 7);
|
|
|
|
d_preamble <<= ((b >> 6) & 0x1);
|
|
|
|
d_preamble <<= ((b >> 5) & 0x1);
|
|
|
|
d_preamble <<= ((b >> 4) & 0x1);
|
|
|
|
d_preamble <<= ((b >> 3) & 0x1);
|
|
|
|
d_preamble <<= ((b >> 2) & 0x1);
|
|
|
|
d_preamble <<= ((b >> 1) & 0x1);
|
|
|
|
d_preamble <<= (b & 0x1);
|
|
|
|
}
|
2019-09-12 15:25:10 +02:00
|
|
|
for (uint8_t b : sync) {
|
2018-11-29 01:41:36 +01:00
|
|
|
d_sync <<= (b >> 7);
|
|
|
|
d_sync <<= ((b >> 6) & 0x1);
|
|
|
|
d_sync <<= ((b >> 5) & 0x1);
|
|
|
|
d_sync <<= ((b >> 4) & 0x1);
|
|
|
|
d_sync <<= ((b >> 3) & 0x1);
|
|
|
|
d_sync <<= ((b >> 2) & 0x1);
|
|
|
|
d_sync <<= ((b >> 1) & 0x1);
|
|
|
|
d_sync <<= (b & 0x1);
|
|
|
|
}
|
2018-12-01 23:47:56 +01:00
|
|
|
|
|
|
|
/* Parameters checking */
|
|
|
|
if (max_frame_len == 0) {
|
2019-09-12 15:25:10 +02:00
|
|
|
throw std::invalid_argument(
|
|
|
|
"The maximum frame size should be at least 1 byte");
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_sync_len < 8) {
|
2018-12-01 23:47:56 +01:00
|
|
|
throw std::invalid_argument("SYNC word should be at least 8 bits");
|
|
|
|
}
|
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_preamble_len < 8) {
|
2018-12-01 23:47:56 +01:00
|
|
|
throw std::invalid_argument("Preamble should be at least 8 bits");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d_preamble_len < 2 * d_preamble_thrsh) {
|
2019-09-12 15:25:10 +02:00
|
|
|
throw std::invalid_argument(
|
|
|
|
"Too many error bits are allowed for the preamble."
|
|
|
|
"Consider lowering the threshold");
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d_sync_len < 2 * d_sync_thrsh) {
|
2019-09-12 15:25:10 +02:00
|
|
|
throw std::invalid_argument(
|
|
|
|
"Too many error bits are allowed for the sync word. "
|
|
|
|
"Consider lowering the threshold");
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d_frame_size_field_len > 4) {
|
2019-09-12 15:25:10 +02:00
|
|
|
throw std::invalid_argument("Frame length field can be up to 4 bytes");
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
|
2018-12-03 00:42:14 +01:00
|
|
|
if (d_frame_size_field_len == 0 && d_variant != GENERIC_CONSTANT_FRAME_LEN) {
|
2019-09-12 15:25:10 +02:00
|
|
|
throw std::invalid_argument("Frame length field cannot be 0");
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_variant == GENERIC_CONSTANT_FRAME_LEN) {
|
2018-12-03 00:42:14 +01:00
|
|
|
d_frame_size_field_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the CRC length */
|
2019-09-12 15:25:10 +02:00
|
|
|
switch (d_crc) {
|
|
|
|
case CRC16_CCITT:
|
|
|
|
d_crc_len = 2;
|
|
|
|
break;
|
|
|
|
case CRC16_CCITT_REVERSED:
|
|
|
|
d_crc_len = 2;
|
|
|
|
break;
|
|
|
|
case CRC16_IBM:
|
|
|
|
d_crc_len = 2;
|
|
|
|
break;
|
|
|
|
case CRC32:
|
|
|
|
d_crc_len = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
d_crc_len = 0;
|
|
|
|
break;
|
2018-12-03 00:42:14 +01:00
|
|
|
}
|
|
|
|
|
2018-12-01 23:47:56 +01:00
|
|
|
d_pdu = new uint8_t[max_frame_len];
|
|
|
|
|
|
|
|
/* Register the PMT message queue */
|
|
|
|
message_port_register_out(pmt::mp("out"));
|
2018-11-29 01:41:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our virtual destructor.
|
|
|
|
*/
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition_impl::~frame_acquisition_impl()
|
2018-11-29 01:41:36 +01:00
|
|
|
{
|
2018-12-01 23:47:56 +01:00
|
|
|
delete [] d_pdu;
|
2018-11-29 01:41:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition_impl::work(int noutput_items,
|
|
|
|
gr_vector_const_void_star &input_items,
|
|
|
|
gr_vector_void_star &output_items)
|
2018-11-29 01:41:36 +01:00
|
|
|
{
|
|
|
|
const uint8_t *in = (const uint8_t *) input_items[0];
|
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
switch (d_state) {
|
|
|
|
case SEARCHING:
|
|
|
|
return searching_preamble(in, noutput_items);
|
|
|
|
case SEARCHING_SYNC:
|
|
|
|
return searching_sync(in, noutput_items);
|
|
|
|
case DECODING_GENERIC_FRAME_LEN:
|
|
|
|
return dec_generic_frame_len(in, noutput_items);
|
|
|
|
case DECODING_GOLAY24_FRAME_LEN:
|
|
|
|
return dec_golay24_frame_len(in, noutput_items);
|
|
|
|
case DECODING_PAYLOAD:
|
|
|
|
return decoding(in, noutput_items);
|
|
|
|
default:
|
|
|
|
return noutput_items;
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition_impl::searching_preamble(const uint8_t *in, int len)
|
2018-12-01 23:47:56 +01:00
|
|
|
{
|
2019-09-12 15:25:10 +02:00
|
|
|
for (int i = 0; i < len; i++) {
|
2018-12-01 23:47:56 +01:00
|
|
|
d_preamble_shift_reg <<= in[i];
|
|
|
|
shift_reg tmp = d_preamble_shift_reg ^ d_preamble;
|
2019-09-12 15:25:10 +02:00
|
|
|
if (tmp.count() <= d_preamble_thrsh) {
|
2018-12-03 00:42:14 +01:00
|
|
|
LOG_DEBUG("Found PREAMBLE");
|
2018-12-01 23:47:56 +01:00
|
|
|
d_state = SEARCHING_SYNC;
|
|
|
|
d_cnt = 0;
|
2019-09-12 15:25:10 +02:00
|
|
|
return i + 1;
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition_impl::searching_sync(const uint8_t *in, int len)
|
2018-12-01 23:47:56 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
d_sync_shift_reg <<= in[i];
|
|
|
|
shift_reg tmp = d_sync_shift_reg ^ d_sync;
|
|
|
|
d_cnt++;
|
2019-09-12 15:25:10 +02:00
|
|
|
if (tmp.count() <= d_sync_thrsh) {
|
2018-12-03 00:42:14 +01:00
|
|
|
LOG_DEBUG("Found SYNC");
|
2019-09-12 15:25:10 +02:00
|
|
|
switch (d_variant) {
|
|
|
|
case GENERIC_CONSTANT_FRAME_LEN:
|
|
|
|
d_state = DECODING_PAYLOAD;
|
|
|
|
break;
|
|
|
|
case GENERIC_VAR_FRAME_LEN:
|
|
|
|
d_state = DECODING_GENERIC_FRAME_LEN;
|
|
|
|
break;
|
|
|
|
case GOLAY24_CODED_FRAME_LEN:
|
|
|
|
LOG_WARN("Found!");
|
|
|
|
d_state = DECODING_GOLAY24_FRAME_LEN;
|
|
|
|
break;
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
d_cnt = 0;
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The sync word should be available by now */
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_cnt > d_preamble_len * 2 + d_sync_len) {
|
2018-12-01 23:47:56 +01:00
|
|
|
reset();
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition_impl::dec_generic_frame_len(const uint8_t *in, int len)
|
2018-12-01 23:47:56 +01:00
|
|
|
{
|
|
|
|
const int s = std::min(len / 8, (int) d_frame_size_field_len);
|
2019-09-12 15:25:10 +02:00
|
|
|
for (int i = 0; i < s; i++) {
|
2018-12-01 23:47:56 +01:00
|
|
|
uint8_t b = 0x0;
|
|
|
|
b |= in[i * 8] << 7;
|
|
|
|
b |= in[i * 8 + 1] << 6;
|
|
|
|
b |= in[i * 8 + 2] << 5;
|
|
|
|
b |= in[i * 8 + 3] << 4;
|
|
|
|
b |= in[i * 8 + 4] << 3;
|
|
|
|
b |= in[i * 8 + 5] << 2;
|
|
|
|
b |= in[i * 8 + 6] << 1;
|
|
|
|
b |= in[i * 8 + 7];
|
|
|
|
d_frame_len <<= 8;
|
|
|
|
d_frame_len |= b;
|
|
|
|
d_cnt++;
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_cnt == d_frame_size_field_len) {
|
2018-12-01 23:47:56 +01:00
|
|
|
/* Most of the available modems apply whitening on the frame length too */
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_whitening) {
|
2018-12-01 23:47:56 +01:00
|
|
|
uint32_t descrambled = 0x0;
|
|
|
|
d_whitening->descramble((uint8_t *)&descrambled,
|
|
|
|
(const uint8_t *)&d_frame_len,
|
2018-12-03 00:42:14 +01:00
|
|
|
d_frame_size_field_len, false);
|
2018-12-01 23:47:56 +01:00
|
|
|
d_frame_len = descrambled;
|
|
|
|
}
|
2018-12-03 00:42:14 +01:00
|
|
|
|
|
|
|
/* Mask the bits that are not used */
|
|
|
|
d_frame_len &= ~(0xFFFFFFFF << (d_frame_size_field_len * 8));
|
|
|
|
LOG_DEBUG("Found frame length: %u", d_frame_len);
|
|
|
|
|
|
|
|
/* Length field is needed for the CRC calculation */
|
2019-09-12 15:25:10 +02:00
|
|
|
for (uint32_t j = 0; j < d_frame_size_field_len; j++) {
|
2018-12-03 00:42:14 +01:00
|
|
|
d_pdu[j] = (d_frame_len >> ((d_frame_size_field_len - 1 - j) * 8)) & 0xFF;
|
|
|
|
}
|
|
|
|
d_frame_len += d_frame_size_field_len;
|
|
|
|
|
|
|
|
/* Append the CRC length if any */
|
|
|
|
d_frame_len += d_crc_len;
|
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_frame_len < d_max_frame_len) {
|
2018-12-01 23:47:56 +01:00
|
|
|
d_state = DECODING_PAYLOAD;
|
|
|
|
}
|
2019-09-12 15:25:10 +02:00
|
|
|
else {
|
2018-12-01 23:47:56 +01:00
|
|
|
reset();
|
|
|
|
return (i + 1) * 8;
|
|
|
|
}
|
2018-12-03 00:42:14 +01:00
|
|
|
d_cnt = d_frame_size_field_len;
|
2018-12-01 23:47:56 +01:00
|
|
|
return (i + 1) * 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s * 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition_impl::dec_golay24_frame_len(const uint8_t *in, int len)
|
2018-12-01 23:47:56 +01:00
|
|
|
{
|
|
|
|
/* Golay24 needs 3 bytes to decode */
|
|
|
|
const int s = std::min(len / 8, 3);
|
2019-07-19 23:50:12 +02:00
|
|
|
d_frame_len = 0;
|
2019-09-12 15:25:10 +02:00
|
|
|
for (int i = 0; i < s; i++) {
|
2018-12-01 23:47:56 +01:00
|
|
|
uint8_t b = 0x0;
|
|
|
|
b |= in[i * 8] << 7;
|
|
|
|
b |= in[i * 8 + 1] << 6;
|
|
|
|
b |= in[i * 8 + 2] << 5;
|
|
|
|
b |= in[i * 8 + 3] << 4;
|
|
|
|
b |= in[i * 8 + 4] << 3;
|
|
|
|
b |= in[i * 8 + 5] << 2;
|
|
|
|
b |= in[i * 8 + 6] << 1;
|
|
|
|
b |= in[i * 8 + 7];
|
|
|
|
d_frame_len <<= 8;
|
|
|
|
d_frame_len |= b;
|
|
|
|
d_cnt++;
|
|
|
|
|
|
|
|
/* Try to decode the frame length */
|
|
|
|
if (d_cnt == 3) {
|
2019-07-19 23:50:12 +02:00
|
|
|
LOG_WARN("Len coded %u", d_frame_len);
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_whitening) {
|
2018-12-01 23:47:56 +01:00
|
|
|
uint32_t descrambled = 0x0;
|
2019-07-19 23:50:12 +02:00
|
|
|
d_whitening->descramble((uint8_t *) &descrambled,
|
2018-12-03 00:42:14 +01:00
|
|
|
(const uint8_t *)&d_frame_len, 3, false);
|
2018-12-01 23:47:56 +01:00
|
|
|
d_frame_len = descrambled;
|
|
|
|
}
|
2019-07-19 23:50:12 +02:00
|
|
|
d_frame_len = ((d_frame_len & 0xFFF) << 12) | (d_frame_len >> 12);
|
2019-09-12 15:25:10 +02:00
|
|
|
golay24 g = golay24();
|
2019-07-19 23:50:12 +02:00
|
|
|
uint32_t tmp = 0;
|
2019-09-12 15:25:10 +02:00
|
|
|
if (g.decode24(&tmp, d_frame_len)) {
|
2019-07-19 23:50:12 +02:00
|
|
|
d_frame_len = tmp >> 12;
|
|
|
|
LOG_WARN("Len %u", d_frame_len);
|
2018-12-03 00:42:14 +01:00
|
|
|
|
|
|
|
/* Append the CRC length if any */
|
|
|
|
d_frame_len += d_crc_len;
|
|
|
|
|
2018-12-01 23:47:56 +01:00
|
|
|
/* Check if the payload can fit in the buffer */
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_frame_len > d_max_frame_len) {
|
2018-12-01 23:47:56 +01:00
|
|
|
reset();
|
|
|
|
return (i + 1) * 8;
|
|
|
|
}
|
2019-09-12 15:25:10 +02:00
|
|
|
else {
|
2018-12-01 23:47:56 +01:00
|
|
|
d_state = DECODING_PAYLOAD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2019-09-12 15:25:10 +02:00
|
|
|
reset();
|
2018-12-01 23:47:56 +01:00
|
|
|
return (i + 1) * 8;
|
|
|
|
}
|
|
|
|
d_cnt = 0;
|
|
|
|
return (i + 1) * 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s * 8;
|
|
|
|
}
|
2018-11-29 01:41:36 +01:00
|
|
|
|
2018-12-01 23:47:56 +01:00
|
|
|
int
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition_impl::decoding(const uint8_t *in, int len)
|
2018-12-01 23:47:56 +01:00
|
|
|
{
|
|
|
|
const int s = len / 8;
|
2019-09-12 15:25:10 +02:00
|
|
|
for (int i = 0; i < s; i++) {
|
2018-12-01 23:47:56 +01:00
|
|
|
uint8_t b = 0x0;
|
2018-12-03 00:42:14 +01:00
|
|
|
b = in[i * 8] << 7;
|
2018-12-01 23:47:56 +01:00
|
|
|
b |= in[i * 8 + 1] << 6;
|
|
|
|
b |= in[i * 8 + 2] << 5;
|
|
|
|
b |= in[i * 8 + 3] << 4;
|
|
|
|
b |= in[i * 8 + 4] << 3;
|
|
|
|
b |= in[i * 8 + 5] << 2;
|
|
|
|
b |= in[i * 8 + 6] << 1;
|
|
|
|
b |= in[i * 8 + 7];
|
|
|
|
d_pdu[d_cnt++] = b;
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_cnt == d_frame_len) {
|
|
|
|
if (d_whitening) {
|
2018-12-03 00:42:14 +01:00
|
|
|
d_whitening->descramble(d_pdu + d_frame_size_field_len,
|
|
|
|
d_pdu + d_frame_size_field_len,
|
|
|
|
d_frame_len - d_frame_size_field_len, false);
|
|
|
|
}
|
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
if (check_crc()) {
|
|
|
|
message_port_pub(
|
|
|
|
pmt::mp("out"),
|
|
|
|
pmt::make_blob(d_pdu + d_frame_size_field_len,
|
|
|
|
d_frame_len - d_crc_len - d_frame_size_field_len));
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
reset();
|
2019-09-12 15:25:10 +02:00
|
|
|
return (i + 1) * 8;
|
2018-12-01 23:47:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition_impl::reset()
|
2018-12-01 23:47:56 +01:00
|
|
|
{
|
2019-09-12 15:25:10 +02:00
|
|
|
if (d_whitening) {
|
2018-12-01 23:47:56 +01:00
|
|
|
d_whitening->reset();
|
|
|
|
}
|
|
|
|
d_cnt = 0;
|
|
|
|
d_state = SEARCHING;
|
|
|
|
d_preamble_shift_reg.reset();
|
|
|
|
d_sync_shift_reg.reset();
|
2018-11-29 01:41:36 +01:00
|
|
|
}
|
|
|
|
|
2018-12-03 00:42:14 +01:00
|
|
|
bool
|
2019-09-12 15:25:10 +02:00
|
|
|
frame_acquisition_impl::check_crc()
|
2018-12-03 00:42:14 +01:00
|
|
|
{
|
|
|
|
uint16_t crc16_c;
|
|
|
|
uint16_t crc16_received;
|
|
|
|
uint32_t crc32_c;
|
|
|
|
uint32_t crc32_received;
|
2019-09-12 15:25:10 +02:00
|
|
|
switch (d_crc) {
|
|
|
|
case CRC_NONE:
|
|
|
|
return true;
|
|
|
|
case CRC16_CCITT:
|
|
|
|
crc16_c = crc16_ccitt(d_pdu, d_frame_len - 2);
|
|
|
|
memcpy(&crc16_received, d_pdu + d_frame_len - 2, 2);
|
|
|
|
crc16_received = ntohs(crc16_received);
|
|
|
|
LOG_DEBUG("Received: 0x%02x Computed: 0x%02x", crc16_received, crc16_c);
|
|
|
|
if (crc16_c == crc16_received) {
|
2018-12-03 00:42:14 +01:00
|
|
|
return true;
|
2019-09-12 15:25:10 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case CRC16_CCITT_REVERSED:
|
|
|
|
crc16_c = crc16_ccitt_reversed(d_pdu, d_frame_len - 2);
|
|
|
|
memcpy(&crc16_received, d_pdu + d_frame_len - 2, 2);
|
|
|
|
crc16_received = ntohs(crc16_received);
|
|
|
|
LOG_DEBUG("Received: 0x%02x Computed: 0x%02x", crc16_received, crc16_c);
|
|
|
|
if (crc16_c == crc16_received) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case CRC16_IBM:
|
|
|
|
crc16_c = crc16_ibm(d_pdu, d_frame_len - 2);
|
|
|
|
memcpy(&crc16_received, d_pdu + d_frame_len - 2, 2);
|
|
|
|
crc16_received = ntohs(crc16_received);
|
|
|
|
LOG_WARN("Received: 0x%02x Computed: 0x%02x", crc16_received, crc16_c);
|
|
|
|
if (crc16_c == crc16_received) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case CRC32:
|
|
|
|
crc32_c = crc32(d_pdu, d_frame_len - 4);
|
|
|
|
memcpy(&crc32_received, d_pdu + d_frame_len - 4, 4);
|
|
|
|
crc32_received = ntohl(crc32_received);
|
|
|
|
if (crc32_c == crc32_received) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return false;
|
2018-12-03 00:42:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-29 01:41:36 +01:00
|
|
|
} /* namespace satnogs */
|
|
|
|
} /* namespace gr */
|
|
|
|
|