diff options
author | Thomas Habets <thomas@habets.se> | 2021-02-28 22:57:23 +0000 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-03-01 07:52:44 -0500 |
commit | 2f0e690baeda709e0e76be93ebb60edc1d3e1695 (patch) | |
tree | a21d1768cab24ad4bf93aceda0d9fae199cfdeed /gr-digital/lib | |
parent | 0231d9746b41c3980f30390557b7a08e538f25c6 (diff) |
digital/simple_correlator: Remove manual memory management
Signed-off-by: Thomas Habets <thomas@habets.se>
Diffstat (limited to 'gr-digital/lib')
-rw-r--r-- | gr-digital/lib/simple_correlator_impl.cc | 20 | ||||
-rw-r--r-- | gr-digital/lib/simple_correlator_impl.h | 22 |
2 files changed, 15 insertions, 27 deletions
diff --git a/gr-digital/lib/simple_correlator_impl.cc b/gr-digital/lib/simple_correlator_impl.cc index babec8bb37..d062f24726 100644 --- a/gr-digital/lib/simple_correlator_impl.cc +++ b/gr-digital/lib/simple_correlator_impl.cc @@ -34,18 +34,10 @@ simple_correlator_impl::simple_correlator_impl(int payload_bytesize) io_signature::make(1, 1, sizeof(float)), io_signature::make(1, 1, sizeof(unsigned char))), d_payload_bytesize(payload_bytesize), - d_state(ST_LOOKING), - d_osi(0), - d_transition_osi(0), - d_center_osi(0), d_bblen((payload_bytesize + GRSF_PAYLOAD_OVERHEAD) * GRSF_BITS_PER_BYTE), - d_bitbuf(new unsigned char[d_bblen]), - d_pktbuf(new unsigned char[d_bblen / GRSF_BITS_PER_BYTE]), - d_bbi(0) + d_bitbuf(d_bblen), + d_pktbuf(d_bblen / GRSF_BITS_PER_BYTE) { - d_avbi = 0; - d_accum = 0.0; - d_avg = 0.0; for (int i = 0; i < AVG_PERIOD; i++) { d_avgbuf[i] = 0.0; } @@ -53,11 +45,7 @@ simple_correlator_impl::simple_correlator_impl(int payload_bytesize) enter_looking(); } -simple_correlator_impl::~simple_correlator_impl() -{ - delete[] d_bitbuf; - delete[] d_pktbuf; -} +simple_correlator_impl::~simple_correlator_impl() {} void simple_correlator_impl::enter_looking() { @@ -162,7 +150,7 @@ int simple_correlator_impl::general_work(int noutput_items, d_bbi++; if (d_bbi >= d_bblen) { // printf("got whole packet\n"); - packit(d_pktbuf, d_bitbuf, d_bbi); + packit(d_pktbuf.data(), d_bitbuf.data(), d_bbi); // printf("seqno %3d\n", d_pktbuf[0]); memcpy(out, &d_pktbuf[GRSF_PAYLOAD_OVERHEAD], d_payload_bytesize); enter_looking(); diff --git a/gr-digital/lib/simple_correlator_impl.h b/gr-digital/lib/simple_correlator_impl.h index 59188363c8..3a5514dcc9 100644 --- a/gr-digital/lib/simple_correlator_impl.h +++ b/gr-digital/lib/simple_correlator_impl.h @@ -26,21 +26,21 @@ private: enum state_t { ST_LOOKING, ST_UNDER_THRESHOLD, ST_LOCKED }; int d_payload_bytesize; - state_t d_state; - unsigned int d_osi; // over sample index [0,OVERSAMPLE-1] - unsigned int d_transition_osi; // first index where Hamming dist < thresh - unsigned int d_center_osi; // center of bit + state_t d_state = ST_LOOKING; + unsigned int d_osi = 0; // over sample index [0,OVERSAMPLE-1] + unsigned int d_transition_osi = 0; // first index where Hamming dist < thresh + unsigned int d_center_osi = 0; // center of bit unsigned long long int d_shift_reg[OVERSAMPLE]; - int d_bblen; // length of bitbuf - unsigned char* d_bitbuf; // demodulated bits - unsigned char* d_pktbuf; // temp packet buf - int d_bbi; // bitbuf index + int d_bblen; // length of bitbuf + std::vector<unsigned char> d_bitbuf; // demodulated bits + std::vector<unsigned char> d_pktbuf; // temp packet buf + int d_bbi = 0; // bitbuf index static const int AVG_PERIOD = 512; // must be power of 2 (for freq offset correction) - int d_avbi; + int d_avbi = 0; float d_avgbuf[AVG_PERIOD]; - float d_avg; - float d_accum; + float d_avg = 0.0; + float d_accum = 0.0; inline int slice(float x) { return x >= d_avg ? 1 : 0; } |