kopia lustrzana https://github.com/proto17/dji_droneid
Moved the XOR_BIT_VEC to a constant static member variable
This was being created for every burst which was just wasteful. It was done that way because I was in a hurry =\gr-droneid-update
rodzic
4aa81eb2b9
commit
0729e4620e
|
@ -221,7 +221,79 @@ namespace gr {
|
|||
/// QPSK to bits
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
auto bits = utils::qpsk_to_bits(all_data_carriers);
|
||||
std::array<uint8_t, 7200> XOR_BIT_VEC = {
|
||||
|
||||
for (int idx = 0; idx < 7200; idx++) {
|
||||
if (bits[idx] == 1 && XOR_BIT_VEC[idx] == 1) {
|
||||
bits[idx] = 0;
|
||||
} else if (bits[idx] == 0 && XOR_BIT_VEC[idx] == 0) {
|
||||
bits[idx] = 0;
|
||||
} else {
|
||||
bits[idx] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Setup and run the Turbo decoder
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const size_t input_file_bit_count = 7200;
|
||||
|
||||
const int turbo_iterations = 4;
|
||||
const int turbo_decoder_bit_count = 1412; // Number of bits that the Turbo decoder will take in
|
||||
const int expected_payload_bytes = 176; // Number of bytes that the Turbo decoder will output
|
||||
const int expected_payload_bits = expected_payload_bytes * 8;
|
||||
|
||||
// Allocate buffers for the Turbo decoder
|
||||
std::vector<int8_t> d1(turbo_decoder_bit_count);
|
||||
std::vector<int8_t> d2(turbo_decoder_bit_count);
|
||||
std::vector<int8_t> d3(turbo_decoder_bit_count);
|
||||
std::vector<uint8_t> decoded_bytes(expected_payload_bytes);
|
||||
|
||||
// Create the required structures to run the Turbo decoder
|
||||
struct lte_rate_matcher * rate_matcher = lte_rate_matcher_alloc();
|
||||
struct tdecoder * turbo_decoder = alloc_tdec();
|
||||
struct lte_rate_matcher_io rate_matcher_io = {
|
||||
.D = turbo_decoder_bit_count,
|
||||
.E = input_file_bit_count,
|
||||
.d = {&d1[0], &d2[0], &d3[0]},
|
||||
.e = &bits[0]
|
||||
};
|
||||
|
||||
// Setup the rate matching logic
|
||||
lte_rate_match_rv(rate_matcher, &rate_matcher_io, 0);
|
||||
|
||||
// Run the turbo decoder (will do rate matching as well)
|
||||
const int decode_status = lte_turbo_decode(turbo_decoder, expected_payload_bits, turbo_iterations,
|
||||
&decoded_bytes[0], &d1[0], &d2[0], &d3[0]);
|
||||
|
||||
if (decode_status != 0) {
|
||||
std::cerr << "Failed to decode\n";
|
||||
} else {
|
||||
for (const auto & b : decoded_bytes) {
|
||||
fprintf(stdout, "%02x", b);
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
const auto crc_out = CRC::Calculate(&decoded_bytes[0], decoded_bytes.size(), CRC::CRC_24_LTEA());
|
||||
if (crc_out != 0) {
|
||||
std::cerr << "CRC Check Failed!\n";
|
||||
}
|
||||
}
|
||||
|
||||
free_tdec(turbo_decoder);
|
||||
lte_rate_matcher_free(rate_matcher);
|
||||
}
|
||||
|
||||
int
|
||||
demodulation_impl::work(int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items) {
|
||||
// Do <+signal processing+>
|
||||
|
||||
// Tell runtime system how many output items we produced.
|
||||
return noutput_items;
|
||||
}
|
||||
|
||||
const uint8_t demodulation_impl::XOR_BIT_VEC[7200] = {
|
||||
1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1
|
||||
, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0
|
||||
, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0
|
||||
|
@ -402,80 +474,8 @@ namespace gr {
|
|||
, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1
|
||||
, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1
|
||||
, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1
|
||||
|
||||
};
|
||||
|
||||
for (int idx = 0; idx < 7200; idx++) {
|
||||
if (bits[idx] == 1 && XOR_BIT_VEC[idx] == 1) {
|
||||
bits[idx] = 0;
|
||||
} else if (bits[idx] == 0 && XOR_BIT_VEC[idx] == 0) {
|
||||
bits[idx] = 0;
|
||||
} else {
|
||||
bits[idx] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Setup and run the Turbo decoder
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const size_t input_file_bit_count = 7200;
|
||||
|
||||
const int turbo_iterations = 4;
|
||||
const int turbo_decoder_bit_count = 1412; // Number of bits that the Turbo decoder will take in
|
||||
const int expected_payload_bytes = 176; // Number of bytes that the Turbo decoder will output
|
||||
const int expected_payload_bits = expected_payload_bytes * 8;
|
||||
|
||||
// Allocate buffers for the Turbo decoder
|
||||
std::vector<int8_t> d1(turbo_decoder_bit_count);
|
||||
std::vector<int8_t> d2(turbo_decoder_bit_count);
|
||||
std::vector<int8_t> d3(turbo_decoder_bit_count);
|
||||
std::vector<uint8_t> decoded_bytes(expected_payload_bytes);
|
||||
|
||||
// Create the required structures to run the Turbo decoder
|
||||
struct lte_rate_matcher * rate_matcher = lte_rate_matcher_alloc();
|
||||
struct tdecoder * turbo_decoder = alloc_tdec();
|
||||
struct lte_rate_matcher_io rate_matcher_io = {
|
||||
.D = turbo_decoder_bit_count,
|
||||
.E = input_file_bit_count,
|
||||
.d = {&d1[0], &d2[0], &d3[0]},
|
||||
.e = &bits[0]
|
||||
};
|
||||
|
||||
// Setup the rate matching logic
|
||||
lte_rate_match_rv(rate_matcher, &rate_matcher_io, 0);
|
||||
|
||||
// Run the turbo decoder (will do rate matching as well)
|
||||
const int decode_status = lte_turbo_decode(turbo_decoder, expected_payload_bits, turbo_iterations,
|
||||
&decoded_bytes[0], &d1[0], &d2[0], &d3[0]);
|
||||
|
||||
if (decode_status != 0) {
|
||||
std::cerr << "Failed to decode\n";
|
||||
} else {
|
||||
for (const auto & b : decoded_bytes) {
|
||||
fprintf(stdout, "%02x", b);
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
const auto crc_out = CRC::Calculate(&decoded_bytes[0], decoded_bytes.size(), CRC::CRC_24_LTEA());
|
||||
if (crc_out != 0) {
|
||||
std::cerr << "CRC Check Failed!\n";
|
||||
}
|
||||
}
|
||||
|
||||
free_tdec(turbo_decoder);
|
||||
lte_rate_matcher_free(rate_matcher);
|
||||
}
|
||||
|
||||
int
|
||||
demodulation_impl::work(int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items) {
|
||||
// Do <+signal processing+>
|
||||
|
||||
// Tell runtime system how many output items we produced.
|
||||
return noutput_items;
|
||||
}
|
||||
|
||||
} /* namespace droneid */
|
||||
} /* namespace gr */
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace gr {
|
|||
const uint32_t short_cp_len_;
|
||||
const std::string debug_path_;
|
||||
|
||||
const static uint8_t XOR_BIT_VEC [7200];
|
||||
|
||||
std::unique_ptr<gr::fft::fft_complex> fft_;
|
||||
std::unique_ptr<gr::fft::fft_shift<std::complex<float>>> fft_shift_;
|
||||
size_t sample_count_;
|
||||
|
|
Ładowanie…
Reference in New Issue