reorganize utility macros from Defines.h to Utils.h; cleanup unneeded includes in some places; cleanup files;

pull/48/head
Bryan Biedenkapp 2 years ago
parent 596fad3e30
commit 9611af1374

@ -169,158 +169,9 @@ const uint8_t IP_COMPRESS_RFC1144_COMPRESS = 0x01U;
const uint8_t IP_COMPRESS_RFC1144_UNCOMPRESS = 0x02U;
// ---------------------------------------------------------------------------
// Inlines
// Class Helper Macros
// ---------------------------------------------------------------------------
/// <summary>
/// String from boolean.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string __BOOL_STR(const bool& value) {
std::stringstream ss;
ss << std::boolalpha << value;
return ss.str();
}
/// <summary>
/// String from integer number.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string __INT_STR(const int& value) {
std::stringstream ss;
ss << value;
return ss.str();
}
/// <summary>
/// String from hex integer number.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string __INT_HEX_STR(const int& value) {
std::stringstream ss;
ss << std::hex << value;
return ss.str();
}
/// <summary>
/// String from floating point number.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string __FLOAT_STR(const float& value) {
std::stringstream ss;
ss << value;
return ss.str();
}
/// <summary>
/// IP address from ulong64_t value.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string __IP_FROM_ULONG(const ulong64_t& value) {
std::stringstream ss;
ss << ((value >> 24) & 0xFFU) << "." << ((value >> 16) & 0xFFU) << "." << ((value >> 8) & 0xFFU) << "." << (value & 0xFFU);
return ss.str();
}
/// <summary>
/// Helper to lower-case an input string.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string strtolower(const std::string value) {
std::string v = value;
std::transform(v.begin(), v.end(), v.begin(), ::tolower);
return v;
}
/// <summary>
/// Helper to upper-case an input string.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string strtoupper(const std::string value) {
std::string v = value;
std::transform(v.begin(), v.end(), v.begin(), ::toupper);
return v;
}
// ---------------------------------------------------------------------------
// Macros
// ---------------------------------------------------------------------------
/// <summary>Pointer magic to get the memory address of a floating point number.</summary>
/// <param name="x">Floating Point Variable</param>
#define __FLOAT_ADDR(x) (*(uint32_t*)& x)
/// <summary>Pointer magic to get the memory address of a double precision number.</summary>
/// <param name="x">Double Precision Variable</param>
#define __DOUBLE_ADDR(x) (*(uint64_t*)& x)
#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])
/// <summary>Sets a uint32_t into 4 bytes.</summary>
/// <param name="val">uint32_t value to set</param>
/// <param name="buffer">uint8_t buffer to set value on</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __SET_UINT32(val, buffer, offset) \
buffer[0U + offset] = (val >> 24) & 0xFFU; \
buffer[1U + offset] = (val >> 16) & 0xFFU; \
buffer[2U + offset] = (val >> 8) & 0xFFU; \
buffer[3U + offset] = (val >> 0) & 0xFFU;
/// <summary>Gets a uint32_t consisting of 4 bytes.</summary>
/// <param name="buffer">uint8_t buffer to get value from</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __GET_UINT32(buffer, offset) \
(buffer[offset + 0U] << 24) | \
(buffer[offset + 1U] << 16) | \
(buffer[offset + 2U] << 8) | \
(buffer[offset + 3U] << 0);
/// <summary>Sets a uint32_t into 3 bytes.</summary>
/// <param name="val">uint32_t value to set</param>
/// <param name="buffer">uint8_t buffer to set value on</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __SET_UINT16(val, buffer, offset) \
buffer[0U + offset] = (val >> 16) & 0xFFU; \
buffer[1U + offset] = (val >> 8) & 0xFFU; \
buffer[2U + offset] = (val >> 0) & 0xFFU;
/// <summary>Gets a uint32_t consisting of 3 bytes. (This is a shortened uint32_t).</summary>
/// <param name="buffer">uint8_t buffer to get value from</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __GET_UINT16(buffer, offset) \
(buffer[offset + 0U] << 16) | \
(buffer[offset + 1U] << 8) | \
(buffer[offset + 2U] << 0);
/// <summary>Sets a uint16_t into 2 bytes.</summary>
/// <param name="val">uint16_t value to set</param>
/// <param name="buffer">uint8_t buffer to set value on</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __SET_UINT16B(val, buffer, offset) \
buffer[0U + offset] = (val >> 8) & 0xFFU; \
buffer[1U + offset] = (val >> 0) & 0xFFU;
/// <summary>Gets a uint16_t consisting of 2 bytes.</summary>
/// <param name="buffer">uint8_t buffer to get value from</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __GET_UINT16B(buffer, offset) \
((buffer[offset + 0U] << 8) & 0xFF00U) | \
((buffer[offset + 1U] << 0) & 0x00FFU);
#define new_unique(type, ...) std::unique_ptr<type>(new type(__VA_ARGS__))
/// <summary>Creates a named unique buffer.</summary>
#define __UNIQUE_BUFFER(name, type, length) \
std::unique_ptr<type[]> name = std::unique_ptr<type[]>(new type[length]); \
::memset(name.get(), 0x00U, length);
typedef std::unique_ptr<uint8_t[]> UInt8Array;
/// <summary>Creates a named uint8_t array buffer.</summary>
#define __UNIQUE_UINT8_ARRAY(name, length) __UNIQUE_BUFFER(name, uint8_t, length)
/**
* Class Copy Code Pattern
*/

@ -30,7 +30,6 @@
#if !defined(__THREAD_FUNC_H__)
#define __THREAD_FUNC_H__
#include "common/Defines.h"
#include "common/Thread.h"
#include <cassert>

@ -285,6 +285,37 @@ void Utils::bitsToByteLE(const bool* bits, uint8_t& byte)
byte |= bits[7U] ? 0x80U : 0x00U;
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
uint16_t Utils::reverseEndian(uint16_t value)
{
return (value << 8 & 0xff00) | (value >> 8);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
uint32_t Utils::reverseEndian(uint32_t value)
{
return (value << 24 | (value & 0xFF00U) << 8 | (value & 0xFF0000U) >> 8 | value >> 24);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
uint64_t Utils::reverseEndian(uint64_t value)
{
return (value << 56 | (value & 0xFF00U) << 40 | (value & 0xFF0000U) << 24 | (value & 0xFF000000U) << 8 |
(value & 0xFF00000000U) >> 8 | (value & 0xFF0000000000U) >> 24 | (value & 0xFF000000000000U) >> 40 | value >> 56);
}
/// <summary>
///
/// </summary>
@ -292,6 +323,7 @@ void Utils::bitsToByteLE(const bool* bits, uint8_t& byte)
/// <param name="out"></param>
/// <param name="start"></param>
/// <param name="stop"></param>
/// <returns></returns>
uint32_t Utils::getBits(const uint8_t* in, uint8_t* out, uint32_t start, uint32_t stop)
{
assert(in != nullptr);
@ -313,6 +345,7 @@ uint32_t Utils::getBits(const uint8_t* in, uint8_t* out, uint32_t start, uint32_
/// <param name="out"></param>
/// <param name="start"></param>
/// <param name="length"></param>
/// <returns></returns>
uint32_t Utils::getBitRange(const uint8_t* in, uint8_t* out, uint32_t start, uint32_t length)
{
return getBits(in, out, start, start + length);
@ -325,6 +358,7 @@ uint32_t Utils::getBitRange(const uint8_t* in, uint8_t* out, uint32_t start, uin
/// <param name="out"></param>
/// <param name="start"></param>
/// <param name="stop"></param>
/// <returns></returns>
uint32_t Utils::setBits(const uint8_t* in, uint8_t* out, uint32_t start, uint32_t stop)
{
assert(in != nullptr);
@ -346,6 +380,7 @@ uint32_t Utils::setBits(const uint8_t* in, uint8_t* out, uint32_t start, uint32_
/// <param name="out"></param>
/// <param name="start"></param>
/// <param name="length"></param>
/// <returns></returns>
uint32_t Utils::setBitRange(const uint8_t* in, uint8_t* out, uint32_t start, uint32_t length)
{
return setBits(in, out, start, start + length);

@ -30,6 +30,159 @@
#include <string>
// ---------------------------------------------------------------------------
// Inlines
// ---------------------------------------------------------------------------
/// <summary>
/// String from boolean.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string __BOOL_STR(const bool& value) {
std::stringstream ss;
ss << std::boolalpha << value;
return ss.str();
}
/// <summary>
/// String from integer number.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string __INT_STR(const int& value) {
std::stringstream ss;
ss << value;
return ss.str();
}
/// <summary>
/// String from hex integer number.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string __INT_HEX_STR(const int& value) {
std::stringstream ss;
ss << std::hex << value;
return ss.str();
}
/// <summary>
/// String from floating point number.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string __FLOAT_STR(const float& value) {
std::stringstream ss;
ss << value;
return ss.str();
}
/// <summary>
/// IP address from ulong64_t value.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string __IP_FROM_ULONG(const ulong64_t& value) {
std::stringstream ss;
ss << ((value >> 24) & 0xFFU) << "." << ((value >> 16) & 0xFFU) << "." << ((value >> 8) & 0xFFU) << "." << (value & 0xFFU);
return ss.str();
}
/// <summary>
/// Helper to lower-case an input string.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string strtolower(const std::string value) {
std::string v = value;
std::transform(v.begin(), v.end(), v.begin(), ::tolower);
return v;
}
/// <summary>
/// Helper to upper-case an input string.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
inline std::string strtoupper(const std::string value) {
std::string v = value;
std::transform(v.begin(), v.end(), v.begin(), ::toupper);
return v;
}
// ---------------------------------------------------------------------------
// Macros
// ---------------------------------------------------------------------------
/// <summary>Pointer magic to get the memory address of a floating point number.</summary>
/// <param name="x">Floating Point Variable</param>
#define __FLOAT_ADDR(x) (*(uint32_t*)& x)
/// <summary>Pointer magic to get the memory address of a double precision number.</summary>
/// <param name="x">Double Precision Variable</param>
#define __DOUBLE_ADDR(x) (*(uint64_t*)& x)
#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])
/// <summary>Sets a uint32_t into 4 bytes.</summary>
/// <param name="val">uint32_t value to set</param>
/// <param name="buffer">uint8_t buffer to set value on</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __SET_UINT32(val, buffer, offset) \
buffer[0U + offset] = (val >> 24) & 0xFFU; \
buffer[1U + offset] = (val >> 16) & 0xFFU; \
buffer[2U + offset] = (val >> 8) & 0xFFU; \
buffer[3U + offset] = (val >> 0) & 0xFFU;
/// <summary>Gets a uint32_t consisting of 4 bytes.</summary>
/// <param name="buffer">uint8_t buffer to get value from</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __GET_UINT32(buffer, offset) \
(buffer[offset + 0U] << 24) | \
(buffer[offset + 1U] << 16) | \
(buffer[offset + 2U] << 8) | \
(buffer[offset + 3U] << 0);
/// <summary>Sets a uint32_t into 3 bytes.</summary>
/// <param name="val">uint32_t value to set</param>
/// <param name="buffer">uint8_t buffer to set value on</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __SET_UINT16(val, buffer, offset) \
buffer[0U + offset] = (val >> 16) & 0xFFU; \
buffer[1U + offset] = (val >> 8) & 0xFFU; \
buffer[2U + offset] = (val >> 0) & 0xFFU;
/// <summary>Gets a uint32_t consisting of 3 bytes. (This is a shortened uint32_t).</summary>
/// <param name="buffer">uint8_t buffer to get value from</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __GET_UINT16(buffer, offset) \
(buffer[offset + 0U] << 16) | \
(buffer[offset + 1U] << 8) | \
(buffer[offset + 2U] << 0);
/// <summary>Sets a uint16_t into 2 bytes.</summary>
/// <param name="val">uint16_t value to set</param>
/// <param name="buffer">uint8_t buffer to set value on</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __SET_UINT16B(val, buffer, offset) \
buffer[0U + offset] = (val >> 8) & 0xFFU; \
buffer[1U + offset] = (val >> 0) & 0xFFU;
/// <summary>Gets a uint16_t consisting of 2 bytes.</summary>
/// <param name="buffer">uint8_t buffer to get value from</param>
/// <param name="offset">Offset within uint8_t buffer</param>
#define __GET_UINT16B(buffer, offset) \
((buffer[offset + 0U] << 8) & 0xFF00U) | \
((buffer[offset + 1U] << 0) & 0x00FFU);
#define new_unique(type, ...) std::unique_ptr<type>(new type(__VA_ARGS__))
/// <summary>Creates a named unique buffer.</summary>
#define __UNIQUE_BUFFER(name, type, length) \
std::unique_ptr<type[]> name = std::unique_ptr<type[]>(new type[length]); \
::memset(name.get(), 0x00U, length);
typedef std::unique_ptr<uint8_t[]> UInt8Array;
/// <summary>Creates a named uint8_t array buffer.</summary>
#define __UNIQUE_UINT8_ARRAY(name, length) __UNIQUE_BUFFER(name, uint8_t, length)
// ---------------------------------------------------------------------------
// Class Declaration
// Implements various helper utilities.
@ -60,6 +213,13 @@ public:
/// <summary></summary>
static void bitsToByteLE(const bool* bits, uint8_t& byte);
/// <summary></summary>
static uint16_t reverseEndian(uint16_t value);
/// <summary></summary>
static uint32_t reverseEndian(uint32_t value);
/// <summary></summary>
static uint64_t reverseEndian(uint64_t value);
/// <summary></summary>
static uint32_t getBits(const uint8_t* in, uint8_t* out, uint32_t start, uint32_t stop);
/// <summary></summary>

@ -27,7 +27,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "common/Defines.h"
#include "common/dmr/SlotType.h"
#include "common/edac/Golay2087.h"

@ -26,7 +26,6 @@
#define __DMR_DATA__DATA_H__
#include "common/Defines.h"
#include "common/dmr/DMRDefines.h"
namespace dmr
{

@ -28,6 +28,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Defines.h"
#include "dmr/DMRDefines.h"
#include "dmr/data/EmbeddedData.h"
#include "edac/Hamming.h"
#include "edac/CRC.h"

@ -31,7 +31,6 @@
#define __DMR_DATA__EMBEDDED_DATA_H__
#include "common/Defines.h"
#include "common/dmr/DMRDefines.h"
#include "common/dmr/lc/LC.h"
namespace dmr

@ -32,9 +32,9 @@
#define __DMR_LC__CSBK_H__
#include "common/Defines.h"
#include "common/dmr/DMRDefines.h"
#include "common/dmr/SiteData.h"
#include "common/lookups/IdenTableLookup.h"
#include "common/Utils.h"
namespace dmr
{

@ -34,7 +34,6 @@
#include "common/Defines.h"
#include "common/dmr/lc/LC.h"
#include "common/dmr/lc/PrivacyLC.h"
#include "common/dmr/SlotType.h"
#include "common/edac/BPTC19696.h"
namespace dmr

@ -29,6 +29,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Defines.h"
#include "dmr/DMRDefines.h"
#include "dmr/lc/LC.h"
#include "Utils.h"

@ -32,7 +32,6 @@
#define __DMR_LC__LC_H__
#include "common/Defines.h"
#include "common/dmr/DMRDefines.h"
namespace dmr
{

@ -24,6 +24,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Defines.h"
#include "dmr/DMRDefines.h"
#include "dmr/lc/PrivacyLC.h"
#include "edac/CRC.h"
#include "Utils.h"

@ -28,7 +28,6 @@
#define __DMR_LC__PRIVACY_LC_H__
#include "common/Defines.h"
#include "common/dmr/DMRDefines.h"
namespace dmr
{

@ -82,6 +82,7 @@
*/
#include "Defines.h"
#include "edac/BCH.h"
#include "Utils.h"
using namespace edac;

@ -26,6 +26,7 @@
#include "Defines.h"
#include "edac/Trellis.h"
#include "Log.h"
#include "Utils.h"
using namespace edac;

@ -28,7 +28,6 @@
#include "common/Defines.h"
#include "common/lookups/LookupTable.h"
#include "common/Thread.h"
#include <string>
#include <unordered_map>

@ -31,7 +31,6 @@
#endif
#include "common/Defines.h"
#include "common/Log.h"
#include "common/Thread.h"
#include "common/Timer.h"

@ -33,7 +33,6 @@
#include "common/Defines.h"
#include "common/lookups/LookupTable.h"
#include "common/Thread.h"
#include <string>
#include <unordered_map>

@ -28,7 +28,6 @@
#include "common/Defines.h"
#include "common/lookups/LookupTable.h"
#include "common/Thread.h"
#include "common/yaml/Yaml.h"
#include <string>

@ -29,6 +29,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Defines.h"
#include "common/dmr/DMRDefines.h"
#include "common/p25/dfsi/DFSIDefines.h"
#include "common/p25/dfsi/LC.h"
#include "edac/SHA256.h"
#include "network/BaseNetwork.h"
#include "Log.h"

@ -32,23 +32,16 @@
#define __BASE_NETWORK_H__
#include "common/Defines.h"
#include "common/dmr/DMRDefines.h"
#include "common/p25/P25Defines.h"
#include "common/nxdn/NXDNDefines.h"
#include "common/dmr/data/Data.h"
#include "common/p25/data/DataHeader.h"
#include "common/p25/data/LowSpeedData.h"
#include "common/p25/dfsi/DFSIDefines.h"
#include "common/p25/dfsi/LC.h"
#include "common/p25/lc/LC.h"
#include "common/p25/lc/TSBK.h"
#include "common/p25/lc/TDULC.h"
#include "common/p25/Audio.h"
#include "common/nxdn/lc/RTCH.h"
#include "common/network/FrameQueue.h"
#include "common/network/UDPSocket.h"
#include "common/RingBuffer.h"
#include "common/Timer.h"
#include "common/Utils.h"
#include <string>
#include <cstdint>

@ -27,6 +27,9 @@
#include "edac/CRC.h"
#include "network/BaseNetwork.h"
#include "network/FrameQueue.h"
#include "network/RTPHeader.h"
#include "network/RTPExtensionHeader.h"
#include "network/RTPFNEHeader.h"
#include "Log.h"
#include "Utils.h"
@ -47,11 +50,8 @@ using namespace network::frame;
/// </FrameQueue>
/// <param name="socket">Local port used to listen for incoming data.</param>
/// <param name="peerId">Unique ID of this modem on the network.</param>
FrameQueue::FrameQueue(UDPSocket* socket, uint32_t peerId, bool debug) :
m_peerId(peerId),
m_socket(socket),
m_buffers(),
m_debug(debug)
FrameQueue::FrameQueue(UDPSocket* socket, uint32_t peerId, bool debug) : RawFrameQueue(socket, debug),
m_peerId(peerId)
{
assert(peerId < 999999999U);
}
@ -232,45 +232,3 @@ void FrameQueue::enqueueMessage(const uint8_t* message, uint32_t length, uint32_
m_buffers.push_back(dgram);
}
/// <summary>
/// Flush the message queue.
/// </summary>
/// <returns></returns>
bool FrameQueue::flushQueue()
{
if (m_buffers.empty()) {
return false;
}
// bryanb: this is the same as above -- but for some assinine reason prevents
// weirdness
if (m_buffers.size() == 0U) {
return false;
}
// LogDebug(LOG_NET, "m_buffers len = %u", m_buffers.size());
bool ret = true;
if (!m_socket->write(m_buffers)) {
LogError(LOG_NET, "Failed writing data to the network");
ret = false;
}
for (auto& buffer : m_buffers) {
if (buffer != nullptr) {
// LogDebug(LOG_NET, "deleting buffer, addr %p len %u", buffer->buffer, buffer->length);
if (buffer->buffer != nullptr) {
delete buffer->buffer;
buffer->length = 0;
buffer->buffer = nullptr;
}
delete buffer;
buffer = nullptr;
}
}
m_buffers.clear();
return ret;
}

@ -27,28 +27,25 @@
#define __FRAME_QUEUE_H__
#include "common/Defines.h"
#include "common/network/UDPSocket.h"
#include "common/network/RTPHeader.h"
#include "common/network/RTPExtensionHeader.h"
#include "common/network/RTPFNEHeader.h"
#include "common/network/RawFrameQueue.h"
namespace network
{
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
const uint32_t DATA_PACKET_LENGTH = 8192U;
const uint8_t DVM_RTP_PAYLOAD_TYPE = 0x56U;
const uint8_t DVM_CTRL_RTP_PAYLOAD_TYPE = 0x57U; // these are still RTP, but do not carry stream IDs or sequence data
// ---------------------------------------------------------------------------
// Class Declaration
// Implements the network frame queuing logic.
// Implements the network RTP frame queuing logic.
// ---------------------------------------------------------------------------
class HOST_SW_API FrameQueue {
class HOST_SW_API FrameQueue : public RawFrameQueue {
public: typedef std::pair<const uint8_t, const uint8_t> OpcodePair;
public:
/// <summary>Initializes a new instance of the FrameQueue class.</summary>
@ -67,20 +64,9 @@ namespace network
void enqueueMessage(const uint8_t* message, uint32_t length, uint32_t streamId, uint32_t peerId,
uint32_t ssrc, OpcodePair opcode, uint16_t rtpSeq, sockaddr_storage& addr, uint32_t addrLen);
/// <summary>Flush the message queue.</summary>
bool flushQueue();
private:
uint32_t m_peerId;
sockaddr_storage m_addr;
uint32_t m_addrLen;
UDPSocket* m_socket;
BufferVector m_buffers;
bool m_debug;
};
} // namespace network
#endif // __FRAME_QUEUE_H__
#endif // __FRAME_QUEUE_H__

@ -25,6 +25,7 @@
*/
#include "Defines.h"
#include "network/RTPFNEHeader.h"
#include "Utils.h"
using namespace network::frame;

@ -26,6 +26,7 @@
#include "Defines.h"
#include "network/RTPHeader.h"
#include "Clock.h"
#include "Utils.h"
using namespace system_clock;
using namespace network::frame;

@ -0,0 +1,168 @@
/**
* Digital Voice Modem - Common Library
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / Common Library
*
*/
/*
* Copyright (C) 2024 by Bryan Biedenkapp N2PLL
*
* 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.
*
* 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.
*
* 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.
*/
#include "Defines.h"
#include "network/RawFrameQueue.h"
#include "network/UDPSocket.h"
#include "Log.h"
#include "Utils.h"
using namespace network;
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
// ---------------------------------------------------------------------------
// Public Class Members
// ---------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the RawFrameQueue class.
/// </summary>
/// <param name="socket">Local port used to listen for incoming data.</param>
/// <param name="debug"></param>
RawFrameQueue::RawFrameQueue(UDPSocket* socket, bool debug) :
m_socket(socket),
m_buffers(),
m_debug(debug)
{
/* stub */
}
/// <summary>
/// Finalizes a instance of the RawFrameQueue class.
/// </summary>
RawFrameQueue::~RawFrameQueue()
{
/* stub */
}
/// <summary>
/// Read message from the received UDP packet.
/// </summary>
/// <param name="messageLength">Actual length of message read from packet.</param>
/// <param name="address">IP address data read from.</param>
/// <param name="addrLen"></param>
/// <returns>Buffer containing message read.</returns>
UInt8Array RawFrameQueue::read(int& messageLength, sockaddr_storage& address, uint32_t& addrLen)
{
messageLength = -1;
// read message from socket
uint8_t buffer[DATA_PACKET_LENGTH];
::memset(buffer, 0x00U, DATA_PACKET_LENGTH);
int length = m_socket->read(buffer, DATA_PACKET_LENGTH, address, addrLen);
if (length < 0) {
LogError(LOG_NET, "Failed reading data from the network");
return nullptr;
}
if (length > 0) {
if (m_debug)
Utils::dump(1U, "Network Packet", buffer, length);
// copy message
messageLength = length;
__UNIQUE_UINT8_ARRAY(message, length);
::memcpy(message.get(), buffer, length);
return message;
}
return nullptr;
}
/// <summary>
/// Cache "message" to frame queue.
/// </summary>
/// <param name="message">Message buffer to frame and queue.</param>
/// <param name="length">Length of message.</param>
/// <param name="addr">IP address to write data to.</param>
/// <param name="addrLen"></param>
/// <returns></returns>
void RawFrameQueue::enqueueMessage(const uint8_t* message, uint32_t length, sockaddr_storage& addr, uint32_t addrLen)
{
assert(message != nullptr);
assert(length > 0U);
uint8_t* buffer = new uint8_t[length];
::memset(buffer, 0x00U, length);
::memcpy(buffer, message, length);
if (m_debug)
Utils::dump(1U, "RawFrameQueue::enqueueMessage() Buffered Message", buffer, length);
UDPDatagram* dgram = new UDPDatagram;
dgram->buffer = buffer;
dgram->length = length;
dgram->address = addr;
dgram->addrLen = addrLen;
m_buffers.push_back(dgram);
}
/// <summary>
/// Flush the message queue.
/// </summary>
/// <returns></returns>
bool RawFrameQueue::flushQueue()
{
if (m_buffers.empty()) {
return false;
}
// bryanb: this is the same as above -- but for some assinine reason prevents
// weirdness
if (m_buffers.size() == 0U) {
return false;
}
// LogDebug(LOG_NET, "m_buffers len = %u", m_buffers.size());
bool ret = true;
if (!m_socket->write(m_buffers)) {
LogError(LOG_NET, "Failed writing data to the network");
ret = false;
}
for (auto& buffer : m_buffers) {
if (buffer != nullptr) {
// LogDebug(LOG_NET, "deleting buffer, addr %p len %u", buffer->buffer, buffer->length);
if (buffer->buffer != nullptr) {
delete buffer->buffer;
buffer->length = 0;
buffer->buffer = nullptr;
}
delete buffer;
buffer = nullptr;
}
}
m_buffers.clear();
return ret;
}

@ -0,0 +1,73 @@
/**
* Digital Voice Modem - Common Library
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / Common Library
*
*/
/*
* Copyright (C) 2024 by Bryan Biedenkapp N2PLL
*
* 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.
*
* 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.
*
* 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.
*/
#if !defined(__RAW_FRAME_QUEUE_H__)
#define __RAW_FRAME_QUEUE_H__
#include "common/Defines.h"
#include "common/network/UDPSocket.h"
#include "common/Utils.h"
namespace network
{
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
const uint32_t DATA_PACKET_LENGTH = 8192U;
// ---------------------------------------------------------------------------
// Class Declaration
// Implements the network frame queuing logic.
// ---------------------------------------------------------------------------
class HOST_SW_API RawFrameQueue {
public:
/// <summary>Initializes a new instance of the RawFrameQueue class.</summary>
RawFrameQueue(UDPSocket* socket, bool debug);
/// <summary>Finalizes a instance of the RawFrameQueue class.</summary>
virtual ~RawFrameQueue();
/// <summary>Read message from the received UDP packet.</summary>
UInt8Array read(int& messageLength, sockaddr_storage& address, uint32_t& addrLen);
/// <summary>Cache "message" to frame queue.</summary>
void enqueueMessage(const uint8_t* message, uint32_t length, sockaddr_storage& addr, uint32_t addrLen);
/// <summary>Flush the message queue.</summary>
bool flushQueue();
protected:
sockaddr_storage m_addr;
uint32_t m_addrLen;
UDPSocket* m_socket;
BufferVector m_buffers;
bool m_debug;
};
} // namespace network
#endif // __FRAME_QUEUE_H__

@ -41,7 +41,6 @@
#include "common/network/rest/http/HTTPLexer.h"
#include "common/network/rest/http/HTTPPayload.h"
#include "common/Log.h"
#include "common/Utils.h"
#include <array>
#include <memory>

@ -39,6 +39,7 @@
#include "common/Defines.h"
#include "common/Log.h"
#include "common/Utils.h"
#include <string>
#include <vector>

@ -41,7 +41,6 @@
#include "common/network/rest/http/HTTPLexer.h"
#include "common/network/rest/http/HTTPPayload.h"
#include "common/Log.h"
#include "common/Utils.h"
#include <array>
#include <memory>

@ -31,6 +31,7 @@
#include "nxdn/NXDNDefines.h"
#include "nxdn/channel/LICH.h"
#include "Log.h"
#include "Utils.h"
using namespace nxdn;
using namespace nxdn::channel;

@ -31,7 +31,6 @@
#define __NXDN_LC__RCCH_H__
#include "common/Defines.h"
#include "common/nxdn/lc/PacketInformation.h"
#include "common/nxdn/SiteData.h"
#include "common/lookups/IdenTableLookup.h"

@ -32,6 +32,7 @@
#include "p25/P25Utils.h"
#include "edac/Golay24128.h"
#include "edac/Hamming.h"
#include "Utils.h"
using namespace p25;

@ -30,6 +30,7 @@
#include "Defines.h"
#include "p25/P25Defines.h"
#include "p25/P25Utils.h"
#include "Utils.h"
using namespace p25;

@ -29,7 +29,6 @@
#include "common/Defines.h"
#include "common/p25/data/LowSpeedData.h"
#include "common/p25/lc/LC.h"
#include "common/p25/lc/TSBK.h"
#include "common/edac/RS634717.h"
#include <string>

@ -33,6 +33,7 @@
#include "common/p25/SiteData.h"
#include "common/edac/RS634717.h"
#include "common/lookups/IdenTableLookup.h"
#include "common/Utils.h"
#include <string>

@ -33,6 +33,7 @@
#include "common/p25/SiteData.h"
#include "common/edac/RS634717.h"
#include "common/lookups/IdenTableLookup.h"
#include "common/Utils.h"
#include <string>

@ -30,6 +30,7 @@
#include "nxdn/Audio.h"
#include "common/edac/Golay24128.h"
#include "common/Utils.h"
using namespace nxdn;
using namespace edac;

Loading…
Cancel
Save

Powered by TurnKey Linux.