Add sync and decoding states

Match both control symbols at the beginning
This commit is contained in:
Thanos Gkiolias 2018-01-25 19:23:22 +02:00 committed by Manolis Surligas
parent c2d20fbead
commit 9eedf70d5f
2 changed files with 56 additions and 10 deletions

View File

@ -51,7 +51,14 @@ namespace gr
d_comp_type (comp_type),
d_control_symbol_pos (0),
d_control_symbol_neg (0),
d_data_reg (0)
d_data_reg (0),
d_wrong_bits (0),
d_wrong_bits_neg (0),
d_nwrong (0),
d_nwrong_neg (0),
d_10b_cnt (0),
d_word (0),
d_state (IN_SYNC)
{
message_port_register_out (pmt::mp ("pdu"));
if (!set_access_code (control_symbol)) {
@ -81,7 +88,7 @@ namespace gr
d_control_symbol_pos = (d_control_symbol_pos << 1)
| (control_symbol[i] & 0x1);
}
d_control_symbol_neg = ~d_control_symbol_pos;
d_control_symbol_neg = (~d_control_symbol_pos) & 0x3FF;
return true;
}
@ -96,17 +103,45 @@ namespace gr
d_data_reg = (d_data_reg << 1) | (in[i] & 0x1);
unsigned long long wrong_bits = (d_data_reg ^ d_control_symbol_pos)
& 0x3FF;
unsigned int nwrong = gr::blocks::count_bits64 (wrong_bits);
switch (d_state)
{
case IN_SYNC:
if (nwrong <= 1) {
d_data_reg = 0;
printf ("Packet found \n");
}
d_wrong_bits = (d_data_reg ^ d_control_symbol_pos) & 0x3FF;
d_wrong_bits_neg = (d_data_reg ^ d_control_symbol_neg) & 0x3FF;
d_nwrong = gr::blocks::count_bits64 (d_wrong_bits);
d_nwrong_neg = gr::blocks::count_bits64 (d_wrong_bits_neg);
//GR_LOG_DEBUG(d_logger, boost::format ("Wrong number: %u") % wrong_bits);
/* we found the controls symbol */
if ((d_nwrong == 0) || (d_nwrong_neg == 0)) {
d_state = DECODING;
d_word = 0;
printf ("Packet start found! Begin decoding! \n");
}
//GR_LOG_DEBUG(d_logger, boost::format ("Wrong number: %u") % wrong_bits);
break;
case DECODING:
if (d_10b_cnt < 10) {
d_word = (d_word << 1) | (d_data_reg & 0x1);
d_10b_cnt++;
if(d_10b_cnt == 10){
d_state = IN_SYNC;
d_10b_cnt = 0;
printf("DECODING FINISHED! BEGIN SYNC!!\n");
}
}
break;
default:
GR_LOG_ERROR(d_logger, "Invalid state");
}
}
// Tell runtime system how many output items we produced.

View File

@ -36,6 +36,17 @@ namespace gr
uint16_t d_control_symbol_pos;
uint16_t d_control_symbol_neg;
uint16_t d_data_reg;
unsigned long long d_wrong_bits, d_wrong_bits_neg;
unsigned int d_nwrong, d_nwrong_neg;
uint d_10b_cnt;
uint16_t d_word;
typedef enum
{
IN_SYNC, DECODING
} d_state_t;
d_state_t d_state;
public:
decoder_8b10b_impl (const std::string& control_symbol,