Skip to content

Commit

Permalink
Add new Hamming for YSF.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Apr 19, 2016
1 parent 700ebda commit b560594
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
4 changes: 2 additions & 2 deletions BPTC19696.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
58 changes: 56 additions & 2 deletions Hamming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -63,7 +117,7 @@ bool CHamming::decode15113(bool* d)
}
}

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

Expand Down
9 changes: 6 additions & 3 deletions Hamming.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
Expand Down

0 comments on commit b560594

Please sign in to comment.