aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Krysik <ptrkrysik@gmail.com>2018-04-06 15:22:51 +0200
committerPiotr Krysik <ptrkrysik@gmail.com>2018-04-06 15:22:51 +0200
commite24860f9c018b761d3380d9ceaea0dff46ead6f4 (patch)
tree9291f887e55cb89e94602f63af3a3feb5f4ee902
parentbb7d94a712ff5f18730bd984f2fbfd20682e9edc (diff)
Reformatting control_channels_decoder
-rw-r--r--lib/decoding/control_channels_decoder_impl.cc114
1 files changed, 55 insertions, 59 deletions
diff --git a/lib/decoding/control_channels_decoder_impl.cc b/lib/decoding/control_channels_decoder_impl.cc
index bf0d976..81ce161 100644
--- a/lib/decoding/control_channels_decoder_impl.cc
+++ b/lib/decoding/control_channels_decoder_impl.cc
@@ -35,21 +35,21 @@ namespace gr {
static int ubits2sbits(ubit_t *ubits, sbit_t *sbits, int count)
{
- int i;
+ int i;
- for (i = 0; i < count; i++) {
- if (*ubits == 0x23) {
- ubits++;
- sbits++;
- continue;
- }
- if ((*ubits++) & 1)
- *sbits++ = -127;
- else
- *sbits++ = 127;
- }
+ for (i = 0; i < count; i++) {
+ if (*ubits == 0x23) {
+ ubits++;
+ sbits++;
+ continue;
+ }
+ if ((*ubits++) & 1)
+ *sbits++ = -127;
+ else
+ *sbits++ = 127;
+ }
- return count;
+ return count;
}
control_channels_decoder::sptr
@@ -68,10 +68,10 @@ namespace gr {
gr::io_signature::make(0, 0, 0)),
d_collected_bursts_num(0)
{
- //setup input/output ports
- message_port_register_in(pmt::mp("bursts"));
- set_msg_handler(pmt::mp("bursts"), boost::bind(&control_channels_decoder_impl::decode, this, _1));
- message_port_register_out(pmt::mp("msgs"));
+ //setup input/output ports
+ message_port_register_in(pmt::mp("bursts"));
+ set_msg_handler(pmt::mp("bursts"), boost::bind(&control_channels_decoder_impl::decode, this, _1));
+ message_port_register_out(pmt::mp("msgs"));
}
control_channels_decoder_impl::~control_channels_decoder_impl()
@@ -80,51 +80,47 @@ namespace gr {
void control_channels_decoder_impl::decode(pmt::pmt_t msg)
{
- ubit_t bursts_u[116 * 4];
- sbit_t bursts_s[116 * 4];
- uint8_t result[23];
- int n_errors, n_bits_total;
- int8_t header_plus_data[sizeof(gsmtap_hdr)+DATA_BYTES];
-
- d_bursts[d_collected_bursts_num] = msg;
- d_collected_bursts_num++;
-
- //get convecutive bursts
- if(d_collected_bursts_num==4)
+ ubit_t bursts_u[116 * 4];
+ sbit_t bursts_s[116 * 4];
+ uint8_t result[23];
+ int n_errors, n_bits_total;
+ int8_t header_plus_data[sizeof(gsmtap_hdr)+DATA_BYTES];
+
+ d_bursts[d_collected_bursts_num] = msg;
+ d_collected_bursts_num++;
+
+ //get convecutive bursts
+ if(d_collected_bursts_num==4)
+ {
+ d_collected_bursts_num=0;
+ //reorganize data from input bursts
+ for(int ii = 0; ii < 4; ii++)
{
- d_collected_bursts_num=0;
- //reorganize data from input bursts
- for(int ii = 0; ii < 4; ii++)
- {
- pmt::pmt_t header_plus_burst = pmt::cdr(d_bursts[ii]);
- int8_t * burst_bits = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr);
+ pmt::pmt_t header_plus_burst = pmt::cdr(d_bursts[ii]);
+ int8_t * burst_bits = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr);
- memcpy(&bursts_u[ii*116], &burst_bits[3],58);
- memcpy(&bursts_u[ii*116+58], &burst_bits[3+57+1+26],58);
- }
- //convert to soft bits
- ubits2sbits(bursts_u, bursts_s, 116 * 4);
- //decode
- if (-1 == gsm0503_xcch_decode(result, bursts_s, &n_errors, &n_bits_total))
- {
- //Possibly an encrypted message
- return;
- }
-
- //extract header of the first burst of the four bursts
- pmt::pmt_t first_header_plus_burst = pmt::cdr(d_bursts[0]);
- gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(first_header_plus_burst);
- //copy header and data
- memcpy(header_plus_data, header, sizeof(gsmtap_hdr));
- memcpy(header_plus_data+sizeof(gsmtap_hdr), result, DATA_BYTES);
- //set data type in the header
- ((gsmtap_hdr*)header_plus_data)->type = GSMTAP_TYPE_UM;
- //prepare message
- pmt::pmt_t msg_out = pmt::cons(pmt::PMT_NIL, pmt::make_blob(header_plus_data,DATA_BYTES+sizeof(gsmtap_hdr)));
- //send message to the output
- message_port_pub(pmt::mp("msgs"), msg_out);
+ memcpy(&bursts_u[ii*116], &burst_bits[3],58);
+ memcpy(&bursts_u[ii*116+58], &burst_bits[3+57+1+26],58);
+ }
+ //convert to soft bits
+ ubits2sbits(bursts_u, bursts_s, 116 * 4);
+ //decode
+ if (gsm0503_xcch_decode(result, bursts_s, &n_errors, &n_bits_total) != -1)
+ {
+ //extract header of the first burst of the four bursts
+ pmt::pmt_t first_header_plus_burst = pmt::cdr(d_bursts[0]);
+ gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(first_header_plus_burst);
+ //copy header and data
+ memcpy(header_plus_data, header, sizeof(gsmtap_hdr));
+ memcpy(header_plus_data+sizeof(gsmtap_hdr), result, DATA_BYTES);
+ //set data type in the header
+ ((gsmtap_hdr*)header_plus_data)->type = GSMTAP_TYPE_UM;
+ //prepare message
+ pmt::pmt_t msg_out = pmt::cons(pmt::PMT_NIL, pmt::make_blob(header_plus_data,DATA_BYTES+sizeof(gsmtap_hdr)));
+ //send message to the output
+ message_port_pub(pmt::mp("msgs"), msg_out);
}
- return;
+ }
}
} /* namespace gsm */
} /* namespace gr */