implement a FneUtils HEX2BIN and BIN2HEX for working with hex-bit datasets; port Golay24128 from C++; fix copyright header for ReedSolomonDecoder; define frame types for P25 and VHDR data lengths;

pull/1/head
Bryan Biedenkapp 2 years ago
parent 8cf9d6135c
commit f87ae8eb9f

File diff suppressed because it is too large Load Diff

@ -33,6 +33,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Text;

@ -95,7 +95,7 @@ namespace fnecore.EDAC.RS
{
uint offset = 0U;
for (uint i = 0U; i < 36U; i++, offset += 6)
codeword[27 + i] = bin2Hex(message, offset);
codeword[27 + i] = FneUtils.BIN2HEX(message, offset);
ReedSolomonDecoder rs362017 = new ReedSolomonDecoder(64, 47, 16, 0x43);
byte[] codewordEC = rs362017.DecodeEx(codeword);
@ -103,14 +103,14 @@ namespace fnecore.EDAC.RS
byte[] messageOut = new byte[message.Length];
offset = 0U;
for (uint i = 0U; i < 20U; i++, offset += 6)
hex2Bin(codewordEC[27 + i], ref messageOut, offset);
FneUtils.HEX2BIN(codewordEC[27 + i], ref messageOut, offset);
return messageOut;
}
else if (eccType == ErrorCorrectionCodeType.ReedSolomon_241213)
{
uint offset = 0U;
for (uint i = 0U; i < 24U; i++, offset += 6)
codeword[39 + i] = bin2Hex(message, offset);
codeword[39 + i] = FneUtils.BIN2HEX(message, offset);
ReedSolomonDecoder rs241213 = new ReedSolomonDecoder(64, 51, 12, 0x43);
byte[] codewordEC = rs241213.DecodeEx(codeword);
@ -118,14 +118,14 @@ namespace fnecore.EDAC.RS
byte[] messageOut = new byte[message.Length];
offset = 0U;
for (uint i = 0U; i < 12U; i++, offset += 6)
hex2Bin(codewordEC[39 + i], ref messageOut, offset);
FneUtils.HEX2BIN(codewordEC[39 + i], ref messageOut, offset);
return messageOut;
}
else if (eccType == ErrorCorrectionCodeType.ReedSolomon_24169)
{
uint offset = 0U;
for (uint i = 0U; i < 24U; i++, offset += 6)
codeword[39 + i] = bin2Hex(message, offset);
codeword[39 + i] = FneUtils.BIN2HEX(message, offset);
ReedSolomonDecoder rs24169 = new ReedSolomonDecoder(64, 55, 8, 0x43);
byte[] codewordEC = rs24169.DecodeEx(codeword);
@ -133,48 +133,11 @@ namespace fnecore.EDAC.RS
byte[] messageOut = new byte[message.Length];
offset = 0U;
for (uint i = 0U; i < 16U; i++, offset += 6)
hex2Bin(codewordEC[39 + i], ref messageOut, offset);
FneUtils.HEX2BIN(codewordEC[39 + i], ref messageOut, offset);
return messageOut;
}
else
throw new ArgumentException($"Invalid '{nameof(eccType)}' argument.", nameof(eccType));
}
/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <param name="offset"></param>
/// <returns></returns>
internal static byte bin2Hex(byte[] input, uint offset)
{
byte output = 0x00;
output |= (byte)(FneUtils.ReadBit(input, offset + 0U) ? 0x20U : 0x00U);
output |= (byte)(FneUtils.ReadBit(input, offset + 1U) ? 0x10U : 0x00U);
output |= (byte)(FneUtils.ReadBit(input, offset + 2U) ? 0x08U : 0x00U);
output |= (byte)(FneUtils.ReadBit(input, offset + 3U) ? 0x04U : 0x00U);
output |= (byte)(FneUtils.ReadBit(input, offset + 4U) ? 0x02U : 0x00U);
output |= (byte)(FneUtils.ReadBit(input, offset + 5U) ? 0x01U : 0x00U);
return output;
}
/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <param name="output"></param>
/// <param name="offset"></param>
/// <returns></returns>
internal static void hex2Bin(byte input, ref byte[] output, uint offset)
{
FneUtils.WriteBit(ref output, offset + 0U, (input & 0x20U) == 0x20U);
FneUtils.WriteBit(ref output, offset + 1U, (input & 0x10U) == 0x10U);
FneUtils.WriteBit(ref output, offset + 2U, (input & 0x08U) == 0x08U);
FneUtils.WriteBit(ref output, offset + 3U, (input & 0x04U) == 0x04U);
FneUtils.WriteBit(ref output, offset + 4U, (input & 0x02U) == 0x02U);
FneUtils.WriteBit(ref output, offset + 5U, (input & 0x01U) == 0x01U);
}
} // public static class ReedSolomonAlgorithm
} // namespace fnecore.EDAC.RS

@ -7,26 +7,31 @@
*
*/
//
// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost)
// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0)
// Based on code from the ErrorCorrection project. (https://github.com/antiduh/ErrorCorrection)
// Licensed under the BSD 2-clause License (https://opensource.org/license/bsd-2-clause/)
//
/*
* Copyright (C) 2016 by Jonathan Naylor G4KLX
* Copyright (C) 2017-2023 by Bryan Biedenkapp N2PLL
* Copyright (C) 2016 by Kevin Thompson
*
* 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.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 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.
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;

@ -117,14 +117,14 @@ namespace fnecore.EDAC.RS
uint offs = 0U;
for (uint j = 0U; j < 12U; j++, offs += 6U)
{
byte hexbit = ReedSolomonAlgorithm.bin2Hex(data, offs);
byte hexbit = FneUtils.BIN2HEX(data, offs);
codeword[i] ^= gf6Mult(hexbit, ENCODE_MATRIX[j][i]);
}
}
uint offset = 0U;
for (uint i = 0U; i < 24U; i++, offset += 6U)
ReedSolomonAlgorithm.hex2Bin(codeword[i], ref data, offset);
FneUtils.HEX2BIN(codeword[i], ref data, offset);
}
/// <summary>
@ -145,14 +145,14 @@ namespace fnecore.EDAC.RS
uint offs = 0U;
for (uint j = 0U; j < 16U; j++, offs += 6U)
{
byte hexbit = ReedSolomonAlgorithm.bin2Hex(data, offs);
byte hexbit = FneUtils.BIN2HEX(data, offs);
codeword[i] ^= gf6Mult(hexbit, ENCODE_MATRIX_24169[j][i]);
}
}
uint offset = 0U;
for (uint i = 0U; i < 24U; i++, offset += 6U)
ReedSolomonAlgorithm.hex2Bin(codeword[i], ref data, offset);
FneUtils.HEX2BIN(codeword[i], ref data, offset);
}
/// <summary>
@ -173,14 +173,14 @@ namespace fnecore.EDAC.RS
uint offs = 0U;
for (uint j = 0U; j < 20U; j++, offs += 6U)
{
byte hexbit = ReedSolomonAlgorithm.bin2Hex(data, offs);
byte hexbit = FneUtils.BIN2HEX(data, offs);
codeword[i] ^= gf6Mult(hexbit, ENCODE_MATRIX_362017[j][i]);
}
}
uint offset = 0U;
for (uint i = 0U; i < 36U; i++, offset += 6U)
ReedSolomonAlgorithm.hex2Bin(codeword[i], ref data, offset);
FneUtils.HEX2BIN(codeword[i], ref data, offset);
}
/// <summary>

@ -544,6 +544,43 @@ namespace fnecore
return (long)ToUInt64(buffer, offset);
}
/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static byte BIN2HEX(byte[] input, uint offset)
{
byte output = 0x00;
output |= (byte)(ReadBit(input, offset + 0U) ? 0x20U : 0x00U);
output |= (byte)(ReadBit(input, offset + 1U) ? 0x10U : 0x00U);
output |= (byte)(ReadBit(input, offset + 2U) ? 0x08U : 0x00U);
output |= (byte)(ReadBit(input, offset + 3U) ? 0x04U : 0x00U);
output |= (byte)(ReadBit(input, offset + 4U) ? 0x02U : 0x00U);
output |= (byte)(ReadBit(input, offset + 5U) ? 0x01U : 0x00U);
return output;
}
/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <param name="output"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static void HEX2BIN(byte input, ref byte[] output, uint offset)
{
WriteBit(ref output, offset + 0U, (input & 0x20U) == 0x20U);
WriteBit(ref output, offset + 1U, (input & 0x10U) == 0x10U);
WriteBit(ref output, offset + 2U, (input & 0x08U) == 0x08U);
WriteBit(ref output, offset + 3U, (input & 0x04U) == 0x04U);
WriteBit(ref output, offset + 4U, (input & 0x02U) == 0x02U);
WriteBit(ref output, offset + 5U, (input & 0x01U) == 0x01U);
}
/// <summary>
/// Primitive conversion from Unicode to ASCII that preserves special characters.
/// </summary>
@ -815,5 +852,23 @@ namespace fnecore
using (SHA256 hash = SHA256Managed.Create())
return hash.ComputeHash(value);
}
/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <param name="v"></param>
/// <returns></returns>
public static uint CountBits(uint v)
{
uint count = 0U;
while (v != 0U)
{
v &= v - 1U;
count++;
}
return count;
}
} // public class FneUtils
} // namespace fnecore

@ -51,6 +51,9 @@ namespace fnecore.P25
public const uint P25_DFSI_LDU2_VOICE17_FRAME_LENGTH_BYTES = 17;
public const uint P25_DFSI_LDU2_VOICE18_FRAME_LENGTH_BYTES = 16;
public const uint P25_DFSI_VHDR_RAW_LEN = 36;
public const uint P25_DFSI_VHDR_LEN = 27;
public const byte P25_DFSI_STATUS_NO_ERROR = 0x00; //
public const byte P25_DFSI_STATUS_ERASE = 0x02; //
@ -131,6 +134,11 @@ namespace fnecore.P25
/// </summary>
public class P25Defines
{
public const byte P25_FT_HDU_VALID = 0x01;
public const byte P25_FT_HDU_LATE_ENTRY = 0x02;
public const byte P25_FT_TERMINATOR = 0x03;
public const byte P25_FT_DATA_UNIT = 0x00;
public const byte P25_MFG_STANDARD = 0x00;
public const byte P25_ALGO_UNENCRYPT = 0x80;

Loading…
Cancel
Save

Powered by TurnKey Linux.