Skip to content

Commit

Permalink
[EXPERIMENTAL] initial TIA-102 DFSI packet support (not enabled yet);
Browse files Browse the repository at this point in the history
  • Loading branch information
gatekeep committed Jan 9, 2025
1 parent ddda823 commit 2d450f6
Show file tree
Hide file tree
Showing 17 changed files with 1,278 additions and 314 deletions.
14 changes: 9 additions & 5 deletions src/common/p25/dfsi/frames/BlockHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2024 Bryan Biedenkapp, N2PLL
* Copyright (C) 2024-2025 Bryan Biedenkapp, N2PLL
*
*/
#include "common/p25/dfsi/frames/BlockHeader.h"
Expand All @@ -26,17 +26,21 @@ using namespace p25::dfsi::frames;
/* Initializes a instance of the BlockHeader class. */

BlockHeader::BlockHeader() :
m_payloadType(false),
m_blockLength(BlockType::UNDEFINED)
m_payloadType(true),
m_blockType(BlockType::UNDEFINED),
m_timestampOffset(0U),
m_blockLength(0U)
{
/* stub */
}

/* Initializes a instance of the BlockHeader class. */

BlockHeader::BlockHeader(uint8_t* data, bool verbose) :
m_payloadType(false),
m_blockLength(BlockType::UNDEFINED)
m_payloadType(true),
m_blockType(BlockType::UNDEFINED),
m_timestampOffset(0U),
m_blockLength(0U)
{
decode(data, verbose);
}
Expand Down
6 changes: 3 additions & 3 deletions src/common/p25/dfsi/frames/BlockHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2024 Bryan Biedenkapp, N2PLL
* Copyright (C) 2024-2025 Bryan Biedenkapp, N2PLL
*
*/
/**
Expand Down Expand Up @@ -53,8 +53,8 @@ namespace p25
*/
class HOST_SW_API BlockHeader {
public:
static const uint8_t LENGTH = 1;
static const uint8_t VERBOSE_LENGTH = 4;
static const uint8_t LENGTH = 1U;
static const uint8_t VERBOSE_LENGTH = 4U;

/**
* @brief Initializes a copy instance of the BlockHeader class.
Expand Down
4 changes: 2 additions & 2 deletions src/common/p25/dfsi/frames/ControlOctet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2024 Bryan Biedenkapp, N2PLL
* Copyright (C) 2024-2025 Bryan Biedenkapp, N2PLL
*
*/
/**
Expand Down Expand Up @@ -45,7 +45,7 @@ namespace p25
*/
class HOST_SW_API ControlOctet {
public:
static const uint8_t LENGTH = 1;
static const uint8_t LENGTH = 1U;

/**
* @brief Initializes a copy instance of the ControlOctet class.
Expand Down
23 changes: 20 additions & 3 deletions src/common/p25/dfsi/frames/FullRateVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2024 Bryan Biedenkapp, N2PLL
* Copyright (C) 2024-2025 Bryan Biedenkapp, N2PLL
*
*/
#include "common/p25/dfsi/frames/FullRateVoice.h"
Expand Down Expand Up @@ -95,7 +95,15 @@ bool FullRateVoice::decode(const uint8_t* data)
// CAI 9 and 10 are 3 bytes of additional data not 4
::memcpy(additionalData, data + 14U, ADDITIONAL_LENGTH - 1U);
} else {
::memcpy(additionalData, data + 14U, ADDITIONAL_LENGTH);
uint8_t buffer[ADDITIONAL_LENGTH - 1U];
::memset(buffer, 0x00U, ADDITIONAL_LENGTH - 1U);
::memcpy(buffer, data + 14U, ADDITIONAL_LENGTH - 1U);
buffer[2U] &= 0xC0U; // mask low bits

uint32_t offset = 0;
for (uint8_t i = 0; i < ADDITIONAL_LENGTH - 1U; i++, offset += 6) {
Utils::hex2Bin(additionalData[i], buffer, offset);
}
}
} else {
if (additionalData != nullptr)
Expand Down Expand Up @@ -128,7 +136,16 @@ void FullRateVoice::encode(uint8_t* data)
// CAI 9 and 10 are 3 bytes of additional data not 4
::memcpy(data + 14U, additionalData, ADDITIONAL_LENGTH - 1U);
} else {
::memcpy(data + 14U, additionalData, ADDITIONAL_LENGTH);
uint8_t buffer[ADDITIONAL_LENGTH - 1U];
::memset(buffer, 0x00U, ADDITIONAL_LENGTH - 1U);
::memcpy(buffer, additionalData, ADDITIONAL_LENGTH - 1U);

uint32_t offset = 0;
for (uint8_t i = 0; i < ADDITIONAL_LENGTH - 1U; i++, offset += 6) {
buffer[i] = Utils::bin2Hex(additionalData, offset);
}

::memcpy(data + 14U, buffer, ADDITIONAL_LENGTH);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/common/p25/dfsi/frames/FullRateVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2024 Bryan Biedenkapp, N2PLL
* Copyright (C) 2024-2025 Bryan Biedenkapp, N2PLL
*
*/
/**
Expand Down Expand Up @@ -133,10 +133,10 @@ namespace p25
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | IMBE 8 | IMBE 9 | IMBE 10 | IMBE 11 |
* +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
* | Et | Er |M|L|E| E1 |SF | B | Link Ctrl | Link Ctrl |
* | | | | |4| | | | | |
* | Et | Er |M|L|E| E1 |SF | B | Link Ctrl | Link Ctrl | Link |
* | | | | |4| | | | | | |
* +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
* | Link Ctrl |R| Status |
* |Ctr|R| Status | Rsvd |
* +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
*
* CAI Frames 12 - 17.
Expand All @@ -150,10 +150,10 @@ namespace p25
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | IMBE 8 | IMBE 9 | IMBE 10 | IMBE 11 |
* +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
* | Et | Er |M|L|E| E1 |SF | B | Enc Sync | Enc Sync |
* | | | | |4| | | | | |
* | Et | Er |M|L|E| E1 |SF | B | Enc Sync | Enc Sync | Enc |
* | | | | |4| | | | | | |
* +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
* | Enc Sync |R| Status |
* |Syn|R| Status | Rsvd |
* +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
*
* CAI Frames 9 and 10.
Expand All @@ -177,9 +177,9 @@ namespace p25
*/
class HOST_SW_API FullRateVoice {
public:
static const uint8_t LENGTH = 18;
static const uint8_t ADDITIONAL_LENGTH = 4;
static const uint8_t IMBE_BUF_LEN = 11;
static const uint8_t LENGTH = 18U;
static const uint8_t ADDITIONAL_LENGTH = 4U;
static const uint8_t IMBE_BUF_LEN = 11U;

/**
* @brief Initializes a copy instance of the FullRateVoice class.
Expand Down
6 changes: 3 additions & 3 deletions src/common/p25/dfsi/frames/MotFullRateVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ namespace p25
*/
class HOST_SW_API MotFullRateVoice {
public:
static const uint8_t LENGTH = 17;
static const uint8_t SHORTENED_LENGTH = 14;
static const uint8_t ADDITIONAL_LENGTH = 4;
static const uint8_t LENGTH = 17U;
static const uint8_t SHORTENED_LENGTH = 14U;
static const uint8_t ADDITIONAL_LENGTH = 4U;

/**
* @brief Initializes a copy instance of the MotFullRateVoice class.
Expand Down
2 changes: 1 addition & 1 deletion src/common/p25/dfsi/frames/MotPDUFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace p25
*/
class HOST_SW_API MotPDUFrame {
public:
static const uint8_t LENGTH = 20;
static const uint8_t LENGTH = 20U;

/**
* @brief Initializes a copy instance of the MotPDUFrame class.
Expand Down
4 changes: 2 additions & 2 deletions src/common/p25/dfsi/frames/MotStartOfStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ namespace p25
*/
class HOST_SW_API MotStartOfStream {
public:
static const uint8_t LENGTH = 10;
static const uint8_t FIXED_MARKER = 0x02;
static const uint8_t LENGTH = 10U;
static const uint8_t FIXED_MARKER = 0x02U;

/**
* @brief Initializes a copy instance of the MotStartOfStream class.
Expand Down
2 changes: 1 addition & 1 deletion src/common/p25/dfsi/frames/MotStartVoiceFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace p25
*/
class HOST_SW_API MotStartVoiceFrame {
public:
static const uint8_t LENGTH = 22;
static const uint8_t LENGTH = 22U;

/**
* @brief Initializes a copy instance of the MotStartVoiceFrame class.
Expand Down
2 changes: 1 addition & 1 deletion src/common/p25/dfsi/frames/MotTSBKFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace p25
*/
class HOST_SW_API MotTSBKFrame {
public:
static const uint8_t LENGTH = 24;
static const uint8_t LENGTH = 24U;

/**
* @brief Initializes a copy instance of the MotTSBKFrame class.
Expand Down
4 changes: 2 additions & 2 deletions src/common/p25/dfsi/frames/MotVoiceHeader1.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ namespace p25
*/
class HOST_SW_API MotVoiceHeader1 {
public:
static const uint8_t LENGTH = 30;
static const uint8_t HCW_LENGTH = 21;
static const uint8_t LENGTH = 30U;
static const uint8_t HCW_LENGTH = 21U;

/**
* @brief Initializes a copy instance of the MotVoiceHeader1 class.
Expand Down
4 changes: 2 additions & 2 deletions src/common/p25/dfsi/frames/MotVoiceHeader2.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ namespace p25
*/
class HOST_SW_API MotVoiceHeader2 {
public:
static const uint8_t LENGTH = 22;
static const uint8_t HCW_LENGTH = 20;
static const uint8_t LENGTH = 22U;
static const uint8_t HCW_LENGTH = 20U;

/**
* @brief Initializes a copy instance of the MotVoiceHeader2 class.
Expand Down
4 changes: 2 additions & 2 deletions src/common/p25/dfsi/frames/StartOfStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2024 Bryan Biedenkapp, N2PLL
* Copyright (C) 2024-2025 Bryan Biedenkapp, N2PLL
*
*/
/**
Expand Down Expand Up @@ -45,7 +45,7 @@ namespace p25
*/
class HOST_SW_API StartOfStream {
public:
static const uint8_t LENGTH = 4;
static const uint8_t LENGTH = 4U;

/**
* @brief Initializes a copy instance of the StartOfStream class.
Expand Down
14 changes: 11 additions & 3 deletions src/common/p25/lc/LC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ LC& LC::operator=(const LC& data)

/* Decode a header data unit. */

bool LC::decodeHDU(const uint8_t* data)
bool LC::decodeHDU(const uint8_t* data, bool rawOnly)
{
assert(data != nullptr);

// deinterleave
uint8_t rs[P25_HDU_LENGTH_BYTES + 1U];
uint8_t raw[P25_HDU_LENGTH_BYTES + 1U];
P25Utils::decode(data, raw, 114U, 780U);
if (rawOnly)
::memcpy(raw, data, P25_HDU_LENGTH_BYTES);
else
P25Utils::decode(data, raw, 114U, 780U);

// decode Golay (18,6,8) FEC
decodeHDUGolay(raw, rs);
Expand Down Expand Up @@ -167,7 +170,7 @@ bool LC::decodeHDU(const uint8_t* data)

/* Encode a header data unit. */

void LC::encodeHDU(uint8_t* data)
void LC::encodeHDU(uint8_t* data, bool rawOnly)
{
assert(data != nullptr);
assert(m_mi != nullptr);
Expand Down Expand Up @@ -202,6 +205,11 @@ void LC::encodeHDU(uint8_t* data)
// encode Golay (18,6,8) FEC
encodeHDUGolay(raw, rs);

if (rawOnly) {
::memcpy(data, raw, P25_HDU_LENGTH_BYTES);
return;
}

// interleave
P25Utils::encode(raw, data, 114U, 780U);

Expand Down
6 changes: 4 additions & 2 deletions src/common/p25/lc/LC.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ namespace p25
/**
* @brief Decode a header data unit.
* @param[in] data Buffer containing the HDU to decode.
* @param rawOnly Flag indicating only the raw bytes of the LC should be decoded.
* @returns True, if HDU decoded, otherwise false.
*/
bool decodeHDU(const uint8_t* data);
bool decodeHDU(const uint8_t* data, bool rawOnly = false);
/**
* @brief Encode a header data unit.
* @param[out] data Buffer to encode an HDU.
* @param rawOnly Flag indicating only the raw bytes of the LC should be encoded.
*/
void encodeHDU(uint8_t* data);
void encodeHDU(uint8_t* data, bool rawOnly = false);

/**
* @brief Decode a logical link data unit 1.
Expand Down
Loading

0 comments on commit 2d450f6

Please sign in to comment.