1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Edouard Griffiths, F4EXB. //
// //
// 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 //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef DSDCC_DSTAR_H_
#define DSDCC_DSTAR_H_
#include <string>
#include "viterbi3.h"
#include "crc.h"
#include "locator.h"
#include "export.h"
namespace DSDcc
{
class DSDDecoder;
class DSDCC_API DSDDstar
{
public:
explicit DSDDstar(DSDDecoder *dsdDecoder);
~DSDDstar();
void init(bool header = false);
void process();
void processHD();
const std::string& getRpt1() const { return m_header.m_rpt1; }
const std::string& getRpt2() const { return m_header.m_rpt2; }
const std::string& getYourSign() const { return m_header.m_yourSign; }
const std::string& getMySign() const { return m_header.m_mySign; }
const char *getInfoText() const { return m_slowData.text; }
const char *getLocator() const { return m_slowData.locator; }
int getBearing() const { return m_slowData.bearing; }
float getDistance() const { return m_slowData.distance; }
private:
typedef enum
{
DStarVoiceFrame,
DStarDataFrame,
DStarSyncFrame
} DStarFrameTYpe;
struct DStarHeader
{
void clear()
{
m_rpt1.clear();
m_rpt2.clear();
m_yourSign.clear();
m_mySign.clear();
m_rpt1FromHD = false;
m_rpt2FromHD = false;
m_yourSignFromHD = false;
m_mySignFromHD = false;
}
void setRpt1(const char *rpt1, bool fromHD)
{
if (!m_rpt1FromHD || fromHD)
{
m_rpt1 = std::string(rpt1, 8);
m_rpt1FromHD = fromHD;
}
}
void setRpt2(const char *rpt2, bool fromHD)
{
if (!m_rpt2FromHD || fromHD)
{
m_rpt2 = std::string(rpt2, 8);
m_rpt2FromHD = fromHD;
}
}
void setYourSign(const char *yourSign, bool fromHD)
{
if (!m_yourSignFromHD || fromHD)
{
m_yourSign = std::string(yourSign, 8);
m_yourSignFromHD = fromHD;
}
}
void setMySign(const char *mySign, const char *mySignInfo, bool fromHD)
{
if (!m_mySignFromHD || fromHD)
{
m_mySign = std::string(mySign, 8);
m_mySign += '/';
m_mySign += std::string(mySignInfo, 4);
m_mySignFromHD = fromHD;
}
}
std::string m_rpt1;
std::string m_rpt2;
std::string m_yourSign;
std::string m_mySign;
bool m_rpt1FromHD;
bool m_rpt2FromHD;
bool m_yourSignFromHD;
bool m_mySignFromHD;
};
typedef enum
{
DStarSlowData0,
DStarSlowData1,
DStarSlowData2,
DStarSlowDataGPS,
DStarSlowDataText,
DStarSlowDataHeader,
DStarSlowDataFiller,
DStarSlowDataNone,
} DStarSlowDataType;
struct DStarSlowData
{
void init()
{
counter = 0;
radioHeaderIndex = 0;
textFrameIndex = 0;
memset(radioHeader, 0, 41);
memset(text, 0x20, 20);
text[20] = '\0';
memset(gpsNMEA, 0, 256);
gpsIndex = 0;
gpsStart = true;
memset(locator, 0x20, 6);
locator[6] = '\0';
bearing = 0;
distance = 0.0;
currentDataType = DStarSlowDataNone;
}
int counter;
char radioHeader[41];
int radioHeaderIndex;
char text[20+1];
int textFrameIndex;
char gpsNMEA[256];
int gpsIndex;
bool gpsStart;
char locator[6+1];
int bearing;
float distance;
DStarSlowDataType currentDataType;
};
struct DPRS
{
DPRS() :
m_lon(0.0f),
m_lat(0.0f)
{}
bool matchDSTAR(const char *d);
unsigned int getCRC(const char *d);
float m_lon;
float m_lat;
LocPoint m_locPoint;
};
void initVoiceFrame();
void initDataFrame();
void processVoice();
void processData();
void processSlowData(bool firstFrame);
void processSlowDataByte(unsigned char byte);
void processSlowDataGroup();
void processDPRS();
void processSync();
void dstar_header_decode();
void reset_header_strings();
void storeSymbolDV(int bitindex, unsigned char bit, bool lsbFirst = true);
DSDDecoder *m_dsdDecoder;
int m_voiceFrameCount;
DStarFrameTYpe m_frameType;
int m_symbolIndex; //!< Current symbol index in non HD sequence
int m_symbolIndexHD; //!< Current symbol index in HD sequence
Viterbi3 m_viterbi;
DStarCRC m_crcDStar;
CRC m_crc;
// DSTAR
unsigned char nullBytes[4];
unsigned char slowdata[4];
unsigned int slowdataIx;
const int *w, *x;
// DSTAR-HD
DStarHeader m_header;
DStarSlowData m_slowData;
DPRS m_dprs;
// constants
static const int dW[72];
static const int dX[72];
static const unsigned char m_terminationSequence[48];
};
} // namespace DSDcc
#endif /* DSTAR_H_ */
|