Add new processing blocks for CSBK and Data Headers.

This commit is contained in:
Jonathan Naylor 2017-08-01 21:55:47 +01:00
parent 367116bdf4
commit cd19de377e
7 changed files with 371 additions and 3 deletions

134
DMRCSBK.cpp Normal file
View file

@ -0,0 +1,134 @@
/*
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "DMRCSBK.h"
#include "BPTC19696.h"
#include "Utils.h"
#include "CRC.h"
#include <cstdio>
#include <cassert>
CDMRCSBK::CDMRCSBK() :
m_data(NULL),
m_CSBKO(CSBKO_NONE)
{
m_data = new unsigned char[12U];
}
CDMRCSBK::~CDMRCSBK()
{
delete[] m_data;
}
bool CDMRCSBK::put(const unsigned char* bytes)
{
assert(bytes != NULL);
CBPTC19696 bptc;
bptc.decode(bytes, m_data);
m_data[10U] ^= CSBK_CRC_MASK[0U];
m_data[11U] ^= CSBK_CRC_MASK[1U];
bool valid = CCRC::checkCCITT162(m_data, 12U);
if (!valid)
return false;
m_CSBKO = CSBKO(m_data[0U] & 0x3FU);
return true;
}
void CDMRCSBK::get(unsigned char* bytes) const
{
assert(bytes != NULL);
CCRC::addCCITT162(m_data, 12U);
m_data[10U] ^= CSBK_CRC_MASK[0U];
m_data[11U] ^= CSBK_CRC_MASK[1U];
CBPTC19696 bptc;
bptc.encode(m_data, bytes);
}
CSBKO CDMRCSBK::getCSBKO() const
{
return m_CSBKO;
}
bool CDMRCSBK::getGI() const
{
if (m_CSBKO == CSBKO_PRECCSBK)
return (m_data[2U] & 0x40U) == 0x40U;
else
return false;
}
unsigned int CDMRCSBK::getSrcId() const
{
if (m_CSBKO == CSBKO_NACKRSP)
return m_data[4U] << 16 | m_data[5U] << 8 | m_data[6U];
else
return m_data[7U] << 16 | m_data[8U] << 8 | m_data[9U];
}
unsigned int CDMRCSBK::getDstId() const
{
if (m_CSBKO == CSBKO_NACKRSP)
return m_data[7U] << 16 | m_data[8U] << 8 | m_data[9U];
else
return m_data[4U] << 16 | m_data[5U] << 8 | m_data[6U];
}
void CDMRCSBK::setGI(bool group)
{
if (m_CSBKO == CSBKO_PRECCSBK) {
if (group)
m_data[2U] |= 0x40U;
else
m_data[2U] &= ~0x40U;
}
}
void CDMRCSBK::setSrcId(unsigned int id)
{
if (m_CSBKO == CSBKO_NACKRSP) {
m_data[4U] = id >> 16;
m_data[5U] = id >> 8;
m_data[6U] = id >> 0;
} else {
m_data[7U] = id >> 16;
m_data[8U] = id >> 8;
m_data[9U] = id >> 0;
}
}
void CDMRCSBK::setDstId(unsigned int id)
{
if (m_CSBKO == CSBKO_NACKRSP) {
m_data[7U] = id >> 16;
m_data[8U] = id >> 8;
m_data[9U] = id >> 0;
} else {
m_data[4U] = id >> 16;
m_data[5U] = id >> 8;
m_data[6U] = id >> 0;
}
}

60
DMRCSBK.h Normal file
View file

@ -0,0 +1,60 @@
/*
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined(DMRCSBK_H)
#define DMRCSBK_H
#include "DMRDefines.h"
enum CSBKO {
CSBKO_NONE = 0x00,
CSBKO_UUVREQ = 0x04,
CSBKO_UUANSRSP = 0x05,
CSBKO_CTCSBK = 0x07,
CSBKO_NACKRSP = 0x26,
CSBKO_BSDWNACT = 0x38,
CSBKO_PRECCSBK = 0x3D
};
class CDMRCSBK
{
public:
CDMRCSBK();
~CDMRCSBK();
bool put(const unsigned char* bytes);
void get(unsigned char* bytes) const;
CSBKO getCSBKO() const;
bool getGI() const;
void setGI(bool group);
unsigned int getSrcId() const;
void setSrcId(unsigned int id);
unsigned int getDstId() const;
void setDstId(unsigned int id);
private:
unsigned char* m_data;
CSBKO m_CSBKO;
};
#endif

112
DMRDataHeader.cpp Normal file
View file

@ -0,0 +1,112 @@
/*
* Copyright (C) 2012 by Ian Wraith
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "DMRDataHeader.h"
#include "DMRDefines.h"
#include "BPTC19696.h"
#include "RS129.h"
#include "Utils.h"
#include "CRC.h"
#include "Log.h"
#include <cstdio>
#include <cassert>
#include <cstring>
CDMRDataHeader::CDMRDataHeader() :
m_data(NULL)
{
m_data = new unsigned char[12U];
}
CDMRDataHeader::~CDMRDataHeader()
{
delete[] m_data;
}
bool CDMRDataHeader::put(const unsigned char* bytes)
{
assert(bytes != NULL);
CBPTC19696 bptc;
bptc.decode(bytes, m_data);
m_data[10U] ^= DATA_HEADER_CRC_MASK[0U];
m_data[11U] ^= DATA_HEADER_CRC_MASK[1U];
bool valid = CCRC::checkCCITT162(m_data, 12U);
if (!valid)
return false;
unsigned char dpf = m_data[0U] & 0x0FU;
if (dpf == DPF_PROPRIETARY)
return false;
return true;
}
void CDMRDataHeader::get(unsigned char* bytes) const
{
assert(bytes != NULL);
CCRC::addCCITT162(m_data, 12U);
m_data[10U] ^= DATA_HEADER_CRC_MASK[0U];
m_data[11U] ^= DATA_HEADER_CRC_MASK[1U];
CBPTC19696 bptc;
bptc.encode(m_data, bytes);
}
bool CDMRDataHeader::getGI() const
{
return (m_data[0U] & 0x80U) == 0x80U;
}
unsigned int CDMRDataHeader::getSrcId() const
{
return m_data[5U] << 16 | m_data[6U] << 8 | m_data[7U];
}
unsigned int CDMRDataHeader::getDstId() const
{
return m_data[2U] << 16 | m_data[3U] << 8 | m_data[4U];
}
void CDMRDataHeader::setGI(bool group)
{
if (group)
m_data[0U] |= 0x80U;
else
m_data[0U] &= ~0x80U;
}
void CDMRDataHeader::setSrcId(unsigned int id)
{
m_data[5U] = id >> 16;
m_data[6U] = id >> 8;
m_data[7U] = id >> 0;
}
void CDMRDataHeader::setDstId(unsigned int id)
{
m_data[2U] = id >> 16;
m_data[3U] = id >> 8;
m_data[4U] = id >> 0;
}

46
DMRDataHeader.h Normal file
View file

@ -0,0 +1,46 @@
/*
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef DMRDataHeader_H
#define DMRDataHeader_H
class CDMRDataHeader
{
public:
CDMRDataHeader();
~CDMRDataHeader();
bool put(const unsigned char* bytes);
void get(unsigned char* bytes) const;
bool getGI() const;
void setGI(bool group);
unsigned int getSrcId() const;
void setSrcId(unsigned int id);
unsigned int getDstId() const;
void setDstId(unsigned int id);
private:
unsigned char* m_data;
};
#endif

View file

@ -155,7 +155,9 @@
<ClInclude Include="BPTC19696.h" />
<ClInclude Include="Conf.h" />
<ClInclude Include="CRC.h" />
<ClInclude Include="DMRCSBK.h" />
<ClInclude Include="DMRData.h" />
<ClInclude Include="DMRDataHeader.h" />
<ClInclude Include="DMRDefines.h" />
<ClInclude Include="DMREMB.h" />
<ClInclude Include="DMREmbeddedData.h" />
@ -193,7 +195,9 @@
<ClCompile Include="BPTC19696.cpp" />
<ClCompile Include="Conf.cpp" />
<ClCompile Include="CRC.cpp" />
<ClCompile Include="DMRCSBK.cpp" />
<ClCompile Include="DMRData.cpp" />
<ClCompile Include="DMRDataHeader.cpp" />
<ClCompile Include="DMREMB.cpp" />
<ClCompile Include="DMREmbeddedData.cpp" />
<ClCompile Include="DMRFullLC.cpp" />

View file

@ -119,6 +119,12 @@
<ClInclude Include="PassAllTG.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DMRCSBK.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DMRDataHeader.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Conf.cpp">
@ -220,5 +226,11 @@
<ClCompile Include="PassAllTG.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DMRCSBK.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DMRDataHeader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -4,9 +4,9 @@ CFLAGS = -g -O3 -Wall -std=c++0x -pthread
LIBS = -lpthread
LDFLAGS = -g
OBJECTS = BPTC19696.o Conf.o CRC.o DMRData.o DMREmbeddedData.o DMREMB.o DMRFullLC.o DMRGateway.o DMRLC.o DMRNetwork.o DMRSlotType.o Golay2087.o Hamming.o Log.o \
MMDVMNetwork.o PassAllPC.o PassAllTG.o QR1676.o RepeaterProtocol.o Rewrite.o RewritePC.o RewriteSrc.o RewriteTG.o RewriteType.o RS129.o SHA256.o StopWatch.o \
Sync.o Thread.o Timer.o UDPSocket.o Utils.o Voice.o
OBJECTS = BPTC19696.o Conf.o CRC.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREmbeddedData.o DMREMB.o DMRFullLC.o DMRGateway.o DMRLC.o DMRNetwork.o DMRSlotType.o \
Golay2087.o Hamming.o Log.o MMDVMNetwork.o PassAllPC.o PassAllTG.o QR1676.o RepeaterProtocol.o Rewrite.o RewritePC.o RewriteSrc.o RewriteTG.o RewriteType.o \
RS129.o SHA256.o StopWatch.o Sync.o Thread.o Timer.o UDPSocket.o Utils.o Voice.o
all: DMRGateway