Add new Hamming for YSF.

This commit is contained in:
Jonathan Naylor 2016-04-19 06:50:51 +01:00
parent 700ebda210
commit b560594cac
3 changed files with 64 additions and 7 deletions

View File

@ -162,7 +162,7 @@ void CBPTC19696::decodeErrorCheck()
// Run through each of the 9 rows containing data
for (unsigned int r = 0U; r < 9U; r++) {
unsigned int pos = (r * 15U) + 1U;
if (CHamming::decode15113(m_deInterData + pos))
if (CHamming::decode15113_2(m_deInterData + pos))
fixing = true;
}
@ -272,7 +272,7 @@ void CBPTC19696::encodeErrorCheck()
// Run through each of the 9 rows containing data
for (unsigned int r = 0U; r < 9U; r++) {
unsigned int pos = (r * 15U) + 1U;
CHamming::encode15113(m_deInterData + pos);
CHamming::encode15113_2(m_deInterData + pos);
}
// Run through each of the 15 columns

View File

@ -21,8 +21,62 @@
#include <cstdio>
#include <cassert>
// Hamming (15,11,3) check a boolean data array
bool CHamming::decode15113_1(bool* d)
{
assert(d != NULL);
// Calculate the parity it should have
bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6];
bool c1 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[7] ^ d[8] ^ d[9];
bool c2 = d[0] ^ d[1] ^ d[4] ^ d[5] ^ d[7] ^ d[8] ^ d[10];
bool c3 = d[0] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[9] ^ d[10];
unsigned char n = 0U;
n |= (c0 != d[11]) ? 0x01U : 0x00U;
n |= (c1 != d[12]) ? 0x02U : 0x00U;
n |= (c2 != d[13]) ? 0x04U : 0x00U;
n |= (c3 != d[14]) ? 0x08U : 0x00U;
switch (n)
{
// Parity bit errors
case 0x01U: d[11] = !d[11]; return true;
case 0x02U: d[12] = !d[12]; return true;
case 0x04U: d[13] = !d[13]; return true;
case 0x08U: d[14] = !d[14]; return true;
// Data bit errors
case 0x0FU: d[0] = !d[0]; return true;
case 0x07U: d[1] = !d[1]; return true;
case 0x0BU: d[2] = !d[2]; return true;
case 0x03U: d[3] = !d[3]; return true;
case 0x0DU: d[4] = !d[4]; return true;
case 0x05U: d[5] = !d[5]; return true;
case 0x09U: d[6] = !d[6]; return true;
case 0x0EU: d[7] = !d[7]; return true;
case 0x06U: d[8] = !d[8]; return true;
case 0x0AU: d[9] = !d[9]; return true;
case 0x0CU: d[10] = !d[10]; return true;
// No bit errors
default: return false;
}
}
void CHamming::encode15113_1(bool* d)
{
assert(d != NULL);
// Calculate the checksum this row should have
d[11] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6];
d[12] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[7] ^ d[8] ^ d[9];
d[13] = d[0] ^ d[1] ^ d[4] ^ d[5] ^ d[7] ^ d[8] ^ d[10];
d[14] = d[0] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[9] ^ d[10];
}
// Hamming (15,11,3) check a boolean data array
bool CHamming::decode15113(bool* d)
bool CHamming::decode15113_2(bool* d)
{
assert(d != NULL);
@ -63,7 +117,7 @@ bool CHamming::decode15113(bool* d)
}
}
void CHamming::encode15113(bool* d)
void CHamming::encode15113_2(bool* d)
{
assert(d != NULL);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016 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
@ -21,8 +21,11 @@
class CHamming {
public:
static void encode15113(bool* d);
static bool decode15113(bool* d);
static void encode15113_1(bool* d);
static bool decode15113_1(bool* d);
static void encode15113_2(bool* d);
static bool decode15113_2(bool* d);
static void encode1393(bool* d);
static bool decode1393(bool* d);