everything's a smart pointer

pull/1/head
Tom Early 5 years ago
parent 62e0b18c82
commit acfb479770

@ -1,5 +1,6 @@
/*
* Copyright (C) 2009-2016 by Jonathan Naylor G4KLX
* Copyright (C) 2030 Thomas A. Early N7TAE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -35,34 +36,12 @@ const unsigned int NUM_OF_STATES = 16U;
const uint32_t M = 2U;
const unsigned int K = 5U;
CYSFConvolution::CYSFConvolution() :
m_metrics1(nullptr),
m_metrics2(nullptr),
m_oldMetrics(nullptr),
m_newMetrics(nullptr),
m_decisions(nullptr),
m_dp(nullptr)
{
m_metrics1 = new uint16_t[16U];
m_metrics2 = new uint16_t[16U];
m_decisions = new uint64_t[180U];
}
CYSFConvolution::~CYSFConvolution()
{
delete[] m_metrics1;
delete[] m_metrics2;
delete[] m_decisions;
}
CYSFConvolution::CYSFConvolution() : m_oldMetrics(m_metrics1), m_newMetrics(m_metrics2), m_dp(m_decisions) {}
void CYSFConvolution::start()
{
::memset(m_metrics1, 0x00U, NUM_OF_STATES * sizeof(uint16_t));
::memset(m_metrics2, 0x00U, NUM_OF_STATES * sizeof(uint16_t));
m_oldMetrics = m_metrics1;
m_newMetrics = m_metrics2;
m_dp = m_decisions;
for (int i=0; i<16; i++)
m_metrics1[i] = m_metrics2[i] = 0U;
}
void CYSFConvolution::decode(uint8_t s0, uint8_t s1)

@ -27,7 +27,6 @@ class CYSFConvolution
{
public:
CYSFConvolution();
~CYSFConvolution();
void start();
void decode(uint8_t s0, uint8_t s1);
@ -36,13 +35,12 @@ public:
void encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const;
private:
uint16_t* m_metrics1;
uint16_t* m_metrics2;
uint16_t m_metrics1[16];
uint16_t m_metrics2[16];
uint16_t* m_oldMetrics;
uint16_t* m_newMetrics;
uint64_t* m_decisions;
uint64_t m_decisions[180];
uint64_t* m_dp;
};
#endif

@ -57,18 +57,11 @@ const unsigned int INTERLEAVE_TABLE[] =
38U, 78U, 118U, 158U, 198U
};
CYSFFICH::CYSFFICH() :
m_fich(nullptr)
CYSFFICH::CYSFFICH()
{
m_fich = new unsigned char[6U];
::memset(m_fich, 0U, 6U);
}
CYSFFICH::~CYSFFICH()
{
delete[] m_fich;
}
bool CYSFFICH::decode(const unsigned char* bytes)
{
assert(bytes != nullptr);

@ -24,7 +24,6 @@ class CYSFFICH
{
public:
CYSFFICH();
~CYSFFICH();
bool decode(const unsigned char* bytes);
@ -60,7 +59,7 @@ public:
void load(const unsigned char* fich);
private:
unsigned char* m_fich;
unsigned char m_fich[6];
};
#endif

@ -73,31 +73,15 @@ const unsigned int INTERLEAVE_TABLE_5_20[] =
};
// This one differs from the others in that it interleaves bits and not dibits
const unsigned char WHITENING_DATA[] = {0x93U, 0xD7U, 0x51U, 0x21U, 0x9CU, 0x2FU, 0x6CU, 0xD0U, 0xEFU, 0x0FU,
0xF8U, 0x3DU, 0xF1U, 0x73U, 0x20U, 0x94U, 0xEDU, 0x1EU, 0x7CU, 0xD8U
};
const unsigned char WHITENING_DATA[] = {
0x93U, 0xD7U, 0x51U, 0x21U, 0x9CU, 0x2FU, 0x6CU, 0xD0U, 0xEFU, 0x0FU, 0xF8U, 0x3DU, 0xF1U, 0x73U, 0x20U, 0x94U, 0xEDU, 0x1EU, 0x7CU, 0xD8U
};
const unsigned char BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U};
const unsigned char BIT_MASK_TABLE[] = { 0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U };
#define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
#define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])
CYSFPayload::CYSFPayload() :
m_uplink(nullptr),
m_downlink(nullptr),
m_source(nullptr),
m_dest(nullptr)
{
}
CYSFPayload::~CYSFPayload()
{
delete[] m_uplink;
delete[] m_downlink;
delete[] m_source;
delete[] m_dest;
}
bool CYSFPayload::processHeaderData(unsigned char* data)
{
assert(data != nullptr);
@ -140,14 +124,14 @@ bool CYSFPayload::processHeaderData(unsigned char* data)
if (m_dest == nullptr)
{
m_dest = new unsigned char[YSF_CALLSIGN_LENGTH];
::memcpy(m_dest, output + 0U, YSF_CALLSIGN_LENGTH);
m_dest = std::unique_ptr<unsigned char[]>(new unsigned char[YSF_CALLSIGN_LENGTH]);
::memcpy(m_dest.get(), output, YSF_CALLSIGN_LENGTH);
}
if (m_source == nullptr)
{
m_source = new unsigned char[YSF_CALLSIGN_LENGTH];
::memcpy(m_source, output + YSF_CALLSIGN_LENGTH, YSF_CALLSIGN_LENGTH);
m_source = std::unique_ptr<unsigned char[]>(new unsigned char[YSF_CALLSIGN_LENGTH]);
::memcpy(m_source.get(), output + YSF_CALLSIGN_LENGTH, YSF_CALLSIGN_LENGTH);
}
for (unsigned int i = 0U; i < 20U; i++)
@ -217,11 +201,11 @@ bool CYSFPayload::processHeaderData(unsigned char* data)
for (unsigned int i = 0U; i < 20U; i++)
output[i] ^= WHITENING_DATA[i];
if (m_downlink != nullptr)
::memcpy(output + 0U, m_downlink, YSF_CALLSIGN_LENGTH);
if (m_downlink)
::memcpy(output + 0U, m_downlink.get(), YSF_CALLSIGN_LENGTH);
if (m_uplink != nullptr)
::memcpy(output + YSF_CALLSIGN_LENGTH, m_uplink, YSF_CALLSIGN_LENGTH);
if (m_uplink)
::memcpy(output + YSF_CALLSIGN_LENGTH, m_uplink.get(), YSF_CALLSIGN_LENGTH);
for (unsigned int i = 0U; i < 20U; i++)
output[i] ^= WHITENING_DATA[i];
@ -618,7 +602,7 @@ void CYSFPayload::writeDataFRModeData2(const unsigned char* dt, unsigned char* d
void CYSFPayload::setUplink(const std::string& callsign)
{
m_uplink = new unsigned char[YSF_CALLSIGN_LENGTH];
m_uplink = std::unique_ptr<unsigned char[]>(new unsigned char[YSF_CALLSIGN_LENGTH]);
std::string uplink = callsign;
uplink.resize(YSF_CALLSIGN_LENGTH, ' ');
@ -629,7 +613,7 @@ void CYSFPayload::setUplink(const std::string& callsign)
void CYSFPayload::setDownlink(const std::string& callsign)
{
m_downlink = new unsigned char[YSF_CALLSIGN_LENGTH];
m_downlink = std::unique_ptr<unsigned char[]>(new unsigned char[YSF_CALLSIGN_LENGTH]);
std::string downlink = callsign;
downlink.resize(YSF_CALLSIGN_LENGTH, ' ');
@ -643,7 +627,7 @@ std::string CYSFPayload::getSource()
std::string tmp;
if (m_dest)
tmp.assign((const char *)m_source, YSF_CALLSIGN_LENGTH);
tmp.assign((const char *)m_source.get(), YSF_CALLSIGN_LENGTH);
else
tmp = "";
@ -655,7 +639,7 @@ std::string CYSFPayload::getDest()
std::string tmp;
if (m_dest)
tmp.assign((const char *)m_dest, YSF_CALLSIGN_LENGTH);
tmp.assign((const char *)m_dest.get(), YSF_CALLSIGN_LENGTH);
else
tmp = "";
@ -664,9 +648,6 @@ std::string CYSFPayload::getDest()
void CYSFPayload::reset()
{
delete[] m_source;
delete[] m_dest;
m_source = nullptr;
m_dest = nullptr;
m_source.reset();
m_dest.reset();
}

@ -1,5 +1,6 @@
/*
* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
* Copyright (C) 2020 Thomas A. Early
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,13 +21,11 @@
#define YSFPayload_H
#include <string>
#include <memory>
class CYSFPayload
{
public:
CYSFPayload();
~CYSFPayload();
bool processHeaderData(unsigned char* bytes);
void writeVDMode2Data(unsigned char* data, const unsigned char* dt);
@ -49,10 +48,10 @@ public:
void reset();
private:
unsigned char* m_uplink;
unsigned char* m_downlink;
unsigned char* m_source;
unsigned char* m_dest;
std::unique_ptr<unsigned char[]> m_uplink;
std::unique_ptr<unsigned char[]> m_downlink;
std::unique_ptr<unsigned char[]> m_source;
std::unique_ptr<unsigned char[]> m_dest;
};
#endif

Loading…
Cancel
Save

Powered by TurnKey Linux.