Skip to content

Commit

Permalink
More work with decoding and regenerating P25.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Sep 13, 2016
1 parent 30467a7 commit 0dc1f1b
Show file tree
Hide file tree
Showing 22 changed files with 450 additions and 164 deletions.
48 changes: 48 additions & 0 deletions Hamming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,54 @@ void CHamming::encode1393(bool* d)
d[12] = d[0] ^ d[2] ^ d[4] ^ d[5] ^ d[8];
}

// Hamming (10,6,3) check a boolean data array
bool CHamming::decode1063(bool* d)
{
assert(d != NULL);

// Calculate the checksum this column should have
bool c0 = d[0] ^ d[1] ^ d[2] ^ d[5];
bool c1 = d[0] ^ d[1] ^ d[3] ^ d[5];
bool c2 = d[0] ^ d[2] ^ d[3] ^ d[4];
bool c3 = d[1] ^ d[2] ^ d[3] ^ d[4];

unsigned char n = 0x00U;
n |= (c0 != d[6]) ? 0x01U : 0x00U;
n |= (c1 != d[7]) ? 0x02U : 0x00U;
n |= (c2 != d[8]) ? 0x04U : 0x00U;
n |= (c3 != d[9]) ? 0x08U : 0x00U;

switch (n) {
// Parity bit errors
case 0x01U: d[6] = !d[6]; return true;
case 0x02U: d[7] = !d[7]; return true;
case 0x04U: d[8] = !d[8]; return true;
case 0x08U: d[9] = !d[9]; return true;

// Data bit erros
case 0x07U: d[0] = !d[0]; return true;
case 0x0BU: d[1] = !d[1]; return true;
case 0x0DU: d[2] = !d[2]; return true;
case 0x0EU: d[3] = !d[3]; return true;
case 0x0CU: d[4] = !d[4]; return true;
case 0x03U: d[5] = !d[5]; return true;

// No bit errors
default: return false;
}
}

void CHamming::encode1063(bool* d)
{
assert(d != NULL);

// Calculate the checksum this column should have
d[6] = d[0] ^ d[1] ^ d[2] ^ d[5];
d[7] = d[0] ^ d[1] ^ d[3] ^ d[5];
d[8] = d[0] ^ d[2] ^ d[3] ^ d[4];
d[9] = d[1] ^ d[2] ^ d[3] ^ d[4];
}

// A Hamming (16,11,4) Check
bool CHamming::decode16114(bool* d)
{
Expand Down
3 changes: 3 additions & 0 deletions Hamming.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class CHamming {
static void encode1393(bool* d);
static bool decode1393(bool* d);

static void encode1063(bool* d);
static bool decode1063(bool* d);

static void encode16114(bool* d);
static bool decode16114(bool* d);

Expand Down
2 changes: 1 addition & 1 deletion MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ TXLevel=50
OscOffset=0
RSSIMultiplier=1
RSSIOffset=10
Debug=1
Debug=0

[D-Star]
Enable=1
Expand Down
4 changes: 4 additions & 0 deletions MMDVMHost.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@
<ClInclude Include="P25Control.h" />
<ClInclude Include="P25Defines.h" />
<ClInclude Include="P25Data.h" />
<ClInclude Include="P25LowSpeedData.h" />
<ClInclude Include="P25NID.h" />
<ClInclude Include="P25Utils.h" />
<ClInclude Include="QR1676.h" />
<ClInclude Include="RingBuffer.h" />
<ClInclude Include="RS129.h" />
Expand Down Expand Up @@ -242,7 +244,9 @@
<ClCompile Include="P25Audio.cpp" />
<ClCompile Include="P25Control.cpp" />
<ClCompile Include="P25Data.cpp" />
<ClCompile Include="P25LowSpeedData.cpp" />
<ClCompile Include="P25NID.cpp" />
<ClCompile Include="P25Utils.cpp" />
<ClCompile Include="QR1676.cpp" />
<ClCompile Include="RS129.cpp" />
<ClCompile Include="SerialController.cpp" />
Expand Down
12 changes: 12 additions & 0 deletions MMDVMHost.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@
<ClInclude Include="P25Data.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="P25Utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="P25LowSpeedData.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BPTC19696.cpp">
Expand Down Expand Up @@ -346,5 +352,11 @@
<ClCompile Include="P25Data.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="P25Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="P25LowSpeedData.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LDFLAGS = -g
OBJECTS = \
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o Log.o MMDVMHost.o \
Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25NID.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o \
Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25NID.o P25Utils.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o \
Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost

Expand Down
4 changes: 2 additions & 2 deletions Makefile.Pi.Adafruit
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LDFLAGS = -g -L/usr/local/lib
OBJECTS = \
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o Log.o \
MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25NID.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o \
Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25NID.o P25Utils.o QR1676.o RS129.o SerialController.o SHA256.o \
StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost

Expand Down
4 changes: 2 additions & 2 deletions Makefile.Pi.HD44780
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LDFLAGS = -g -L/usr/local/lib
OBJECTS = \
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o Log.o \
MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25NID.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o \
Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25NID.o P25Utils.o QR1676.o RS129.o SerialController.o SHA256.o \
StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost

Expand Down
4 changes: 2 additions & 2 deletions Makefile.Pi.OLED
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LDFLAGS = -g -L/usr/local/lib
OBJECTS = \
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o OLED.o Log.o \
MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25NID.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o \
Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25NID.o P25Utils.o QR1676.o RS129.o SerialController.o SHA256.o \
StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost

Expand Down
4 changes: 2 additions & 2 deletions Makefile.Pi.PCF8574
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LDFLAGS = -g -L/usr/local/lib
OBJECTS = \
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o Log.o \
MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25NID.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o \
Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25NID.o P25Utils.o QR1676.o RS129.o SerialController.o SHA256.o \
StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost

Expand Down
4 changes: 2 additions & 2 deletions Makefile.Solaris
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LDFLAGS = -g
OBJECTS = \
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o Log.o MMDVMHost.o \
Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25NID.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o \
Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25NID.o P25Utils.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o \
Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost

Expand Down
66 changes: 19 additions & 47 deletions P25Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@
*/

#include "P25Audio.h"
#include "P25Utils.h"

#include <cstdio>
#include <cassert>

const unsigned char BIT_MASK_TABLE[] = { 0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U };

#define WRITE_BIT(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_BIT(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])

CP25Audio::CP25Audio() :
m_fec()
{
Expand All @@ -43,65 +39,41 @@ unsigned int CP25Audio::process(unsigned char* data)

unsigned char imbe[18U];

read(data, imbe, 114U, 262U, 142U, 143U, 214U, 215U);
CP25Utils::decode(data, imbe, 114U, 262U);
errs += m_fec.regenerateIMBE(imbe);
write(data, imbe, 114U, 262U, 142U, 143U, 214U, 215U);
CP25Utils::encode(imbe, data, 114U, 262U);

read(data, imbe, 262U, 410U, 286U, 287U, 358U, 359U);
CP25Utils::decode(data, imbe, 262U, 410U);
errs += m_fec.regenerateIMBE(imbe);
write(data, imbe, 262U, 410U, 286U, 287U, 358U, 359U);
CP25Utils::encode(imbe, data, 262U, 410U);

read(data, imbe, 452U, 600U, 502U, 503U, 574U, 575U);
CP25Utils::decode(data, imbe, 452U, 600U);
errs += m_fec.regenerateIMBE(imbe);
write(data, imbe, 452U, 600U, 502U, 503U, 574U, 575U);
CP25Utils::encode(imbe, data, 452U, 600U);

read(data, imbe, 640U, 788U, 646U, 647U, 718U, 719U);
CP25Utils::decode(data, imbe, 640U, 788U);
errs += m_fec.regenerateIMBE(imbe);
write(data, imbe, 640U, 788U, 646U, 647U, 718U, 719U);
CP25Utils::encode(imbe, data, 640U, 788U);

read(data, imbe, 830U, 978U, 862U, 863U, 934U, 935U);
CP25Utils::decode(data, imbe, 830U, 978U);
errs += m_fec.regenerateIMBE(imbe);
write(data, imbe, 830U, 978U, 862U, 863U, 934U, 935U);
CP25Utils::encode(imbe, data, 830U, 978U);

read(data, imbe, 1020U, 1168U, 1078U, 1079U, 1150U, 1151U);
CP25Utils::decode(data, imbe, 1020U, 1168U);
errs += m_fec.regenerateIMBE(imbe);
write(data, imbe, 1020U, 1168U, 1078U, 1079U, 1150U, 1151U);
CP25Utils::encode(imbe, data, 1020U, 1168U);

read(data, imbe, 1208U, 1356U, 1222U, 1223U, 1294U, 1295U);
CP25Utils::decode(data, imbe, 1208U, 1356U);
errs += m_fec.regenerateIMBE(imbe);
write(data, imbe, 1208U, 1356U, 1222U, 1223U, 1294U, 1295U);
CP25Utils::encode(imbe, data, 1208U, 1356U);

read(data, imbe, 1398U, 1546U, 1438U, 1439U, 1510U, 1511U);
CP25Utils::decode(data, imbe, 1398U, 1546U);
errs += m_fec.regenerateIMBE(imbe);
write(data, imbe, 1398U, 1546U, 1438U, 1439U, 1510U, 1511U);
CP25Utils::encode(imbe, data, 1398U, 1546U);

read(data, imbe, 1578U, 1726U, 1582U, 1583U, 1654U, 1655U);
CP25Utils::decode(data, imbe, 1578U, 1726U);
errs += m_fec.regenerateIMBE(imbe);
write(data, imbe, 1578U, 1726U, 1582U, 1583U, 1654U, 1655U);
CP25Utils::encode(imbe, data, 1578U, 1726U);

return errs;
}

void CP25Audio::read(const unsigned char* data, unsigned char* out, unsigned int start, unsigned int stop, unsigned int avoid1, unsigned int avoid2, unsigned int avoid3, unsigned int avoid4)
{
unsigned int n = 0U;
for (unsigned int offset = start; offset < stop; offset++) {
if (offset != avoid1 && offset != avoid2 && offset != avoid3 && offset != avoid4) {
bool b = READ_BIT(data, offset);
WRITE_BIT(out, n, b);
n++;
}
}
}

void CP25Audio::write(unsigned char* data, const unsigned char* in, unsigned int start, unsigned int stop, unsigned int avoid1, unsigned int avoid2, unsigned int avoid3, unsigned int avoid4)
{
unsigned int n = 0U;
for (unsigned int offset = start; offset < stop; offset++) {
if (offset != avoid1 && offset != avoid2 && offset != avoid3 && offset != avoid4) {
bool b = READ_BIT(in, n);
WRITE_BIT(data, offset, b);
n++;
}
}
}
3 changes: 0 additions & 3 deletions P25Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class CP25Audio {

private:
CAMBEFEC m_fec;

void read(const unsigned char* data, unsigned char* out, unsigned int start, unsigned int stop, unsigned int avoid1, unsigned int avoid2, unsigned int avoid3, unsigned int avoid4);
void write(unsigned char* data, const unsigned char* in, unsigned int start, unsigned int stop, unsigned int avoid1, unsigned int avoid2, unsigned int avoid3, unsigned int avoid4);
};

#endif
13 changes: 9 additions & 4 deletions P25Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "P25Control.h"
#include "P25LowSpeedData.h"
#include "P25Defines.h"
#include "Sync.h"
#include "Log.h"
Expand Down Expand Up @@ -62,7 +63,7 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len)
{
assert(data != NULL);

CUtils::dump(1U, "P25 Data", data, len);
// CUtils::dump(1U, "P25 Data", data, len);

bool sync = data[1U] == 0x01U;

Expand Down Expand Up @@ -129,6 +130,9 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len)
// Regenerate LDU1 Data
m_rfData.processLDU1(data + 2U);

// Regenerate the Low Speed Data
CP25LowSpeedData::process(data + 2U);

// Regenerate Audio
unsigned int errors = m_audio.process(data + 2U);
LogDebug("P25, LDU1 audio, errs: %u/1233", errors);
Expand Down Expand Up @@ -159,13 +163,14 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len)
if (m_rfState == RS_RF_LISTENING)
return false;

// Decode LDU2
m_rfData.processLDU2(data + 2U);

// Regenerate Sync
CSync::addP25Sync(data + 2U);

// Regenerate LDU2 Data
m_rfData.processLDU2(data + 2U);

// Regenerate the Low Speed Data
CP25LowSpeedData::process(data + 2U);

// Regenerate Audio
unsigned int errors = m_audio.process(data + 2U);
Expand Down
Loading

0 comments on commit 0dc1f1b

Please sign in to comment.