Commit bb57d635 authored by Manolis Surligas's avatar Manolis Surligas

Continue with the FSK decoder for the UPSAT

parent 6ae7614a
<?xml version="1.0"?>
<block>
<name>upsat_fsk_frame_acquisition</name>
<name>UPSAT FSK Frame Acquisition</name>
<key>satnogs_upsat_fsk_frame_acquisition</key>
<category>satnogs</category>
<import>import satnogs</import>
<make>satnogs.upsat_fsk_frame_acquisition($&preamble, $&sync_word, $whitening, $manchester)</make>
<!-- Make one 'param' node for every Parameter you want settable from the GUI.
Sub-nodes:
* name
* key (makes the value accessible as $keyname, e.g. in the make node)
* type -->
<make>satnogs.upsat_fsk_frame_acquisition($preamble, $sync_word, $whitening, $manchester)</make>
<param>
<name>...</name>
<key>...</key>
<type>...</type>
<name>Frame Preamble</name>
<key>preamble</key>
<type>raw</type>
</param>
<!-- Make one 'sink' node per input. Sub-nodes:
* name (an identifier for the GUI)
* type
* vlen
* optional (set to 1 for optional inputs) -->
<param>
<name>Synchronization Word</name>
<key>sync_word</key>
<type>raw</type>
</param>
<param>
<name>Whitening</name>
<key>whitening</key>
<type>enum</type>
<option>
<name>No</name>
<key>False</key>
</option>
<option>
<name>Yes</name>
<key>True</key>
</option>
</param>
<param>
<name>Use Manchester Coding</name>
<key>manchester</key>
<type>enum</type>
<option>
<name>No</name>
<key>False</key>
</option>
<option>
<name>Yes</name>
<key>True</key>
</option>
</param>
<sink>
<name>in</name>
<type><!-- e.g. int, float, complex, byte, short, xxx_vector, ...--></type>
<type>float</type>
</sink>
<!-- Make one 'source' node per output. Sub-nodes:
* name (an identifier for the GUI)
* type
* vlen
* optional (set to 1 for optional inputs) -->
<source>
<name>out</name>
<type><!-- e.g. int, float, complex, byte, short, xxx_vector, ...--></type>
<name>pdu</name>
<type>message</type>
</source>
</block>
......@@ -31,6 +31,9 @@
*/
#define CW_DEBUG 1
/*!
* The maximum allowed frame length of the UPSAT satellite
*/
#define UPSAT_MAX_FRAME_LEN 255
#endif /* INCLUDE_SATNOGS_CONFIG_H_ */
......@@ -24,6 +24,7 @@
#include <gnuradio/io_signature.h>
#include "upsat_fsk_frame_acquisition_impl.h"
#include <satnogs/log.h>
namespace gr
{
......@@ -48,8 +49,27 @@ namespace gr
const std::vector<uint8_t> &sync_word, bool whitening, bool manchester) :
gr::sync_block ("upsat_fsk_frame_acquisition",
gr::io_signature::make (1, 1, sizeof(float)),
gr::io_signature::make (0, 0, 0))
gr::io_signature::make (0, 0, 0)),
d_preamble (preamble),
d_preamble_len (preamble.size ()),
d_sync_word (sync_word),
d_sync_word_len (sync_word.size ()),
d_state (SEARCHING),
d_shifting_byte (0x0),
d_decoded_bytes (0),
d_frame_len (0)
{
message_port_register_out (pmt::mp ("pdu"));
if (d_preamble_len < 2) {
throw std::invalid_argument ("Preamble must be at least 2 bytes long");
}
if (d_sync_word_len < 1) {
throw std::invalid_argument (
"Synchronization word must be at least 1 byte long");
}
d_pdu = new uint8_t[UPSAT_MAX_FRAME_LEN];
}
/*
......@@ -57,6 +77,50 @@ namespace gr
*/
upsat_fsk_frame_acquisition_impl::~upsat_fsk_frame_acquisition_impl ()
{
delete[] d_pdu;
}
inline void
upsat_fsk_frame_acquisition_impl::slice_and_shift (float in)
{
uint8_t tmp;
/* Slice the input into 0 and 1 bits */
tmp = in > 0 ? 1 : 0;
d_shifting_byte = d_shifting_byte << 1;
d_shifting_byte |= tmp;
}
inline void
upsat_fsk_frame_acquisition_impl::reset_state ()
{
d_state = SEARCHING;
d_decoded_bytes = 0;
d_shifting_byte = 0;
}
inline void
upsat_fsk_frame_acquisition_impl::have_preamble ()
{
d_state = HAVE_PREAMBLE;
d_decoded_bytes = 1;
}
inline void
upsat_fsk_frame_acquisition_impl::have_sync ()
{
d_state = HAVE_SYNC_WORD;
}
inline void
upsat_fsk_frame_acquisition_impl::have_frame_len ()
{
d_state = HAVE_FRAME_LEN;
}
inline void
upsat_fsk_frame_acquisition_impl::have_payload ()
{
d_state = HAVE_PAYLOAD;
}
int
......@@ -64,11 +128,32 @@ namespace gr
int noutput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
int i;
const float *in = (const float *) input_items[0];
for (i = 0; i < noutput_items; i++) {
slice_and_shift (in[i]);
switch (d_state)
{
case SEARCHING:
if (d_shifting_byte == d_preamble[0]) {
have_preamble ();
}
break;
case HAVE_PREAMBLE:
break;
case HAVE_SYNC_WORD:
break;
case HAVE_PAYLOAD:
if (d_decoded_bytes == d_frame_len) {
message_port_pub (pmt::mp ("pdu"),
pmt::make_blob (d_pdu, d_frame_len));
}
break;
default:
LOG_WARN("Unknown decoding state");
}
}
// Do <+signal processing+>
// Tell runtime system how many output items we produced.
return noutput_items;
}
......
......@@ -21,6 +21,7 @@
#ifndef INCLUDED_SATNOGS_UPSAT_FSK_FRAME_ACQUISITION_IMPL_H
#define INCLUDED_SATNOGS_UPSAT_FSK_FRAME_ACQUISITION_IMPL_H
#include <satnogs/config.h>
#include <satnogs/upsat_fsk_frame_acquisition.h>
namespace gr
......@@ -31,7 +32,42 @@ namespace gr
class upsat_fsk_frame_acquisition_impl : public upsat_fsk_frame_acquisition
{
private:
// Nothing to declare in this block.
/**
* Decoding FSM
*/
typedef enum
{
SEARCHING, //!< SEARCHING when searching for the start of the preamble
HAVE_PREAMBLE, //!< HAVE_PREAMBLE when the decoder is inside the preamble
HAVE_SYNC_WORD, //!< HAVE_SYNC_WORD when the decoder is inside the sync word
HAVE_FRAME_LEN, //!< HAVE_FRAME_LEN when the decoder is inside the frame length field
HAVE_PAYLOAD //!< HAVE_PAYLOAD when the decoder process the palyload of the frame
} decoding_state_t;
const std::vector<uint8_t> d_preamble;
const size_t d_preamble_len;
const std::vector<uint8_t> d_sync_word;
const size_t d_sync_word_len;
decoding_state_t d_state;
uint8_t d_shifting_byte;
size_t d_decoded_bytes;
size_t d_frame_len;
uint8_t *d_pdu;
inline void
slice_and_shift (float in);
inline void
reset_state ();
inline void
have_preamble ();
inline void
have_sync ();
inline void
have_frame_len ();
inline void
have_payload ();
public:
upsat_fsk_frame_acquisition_impl (const std::vector<uint8_t> &preamble,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment