Skip to content

Commit a2fa303

Browse files
committed
reorganize code, move Network class from host into common as its being used more as a generic peer network class; add some warning messaging to the FNE when a peer link or external peer (i.e. intra-FNE connection) drops;
1 parent 0496737 commit a2fa303

19 files changed

Lines changed: 201 additions & 150 deletions

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ include(CPack)
7777
include(src/fne/CMakeLists.txt)
7878
add_executable(dvmfne ${common_INCLUDE} ${dvmfne_SRC})
7979
target_link_libraries(dvmfne PRIVATE common ${OPENSSL_LIBRARIES} asio::asio Threads::Threads)
80-
target_include_directories(dvmfne PRIVATE ${OPENSSL_INCLUDE_DIR} src src/host src/fne)
80+
target_include_directories(dvmfne PRIVATE ${OPENSSL_INCLUDE_DIR} src src/fne)
8181

8282
#
8383
## dvmmon
@@ -141,4 +141,4 @@ if (COMPILE_WIN32)
141141
else ()
142142
target_link_libraries(dvmbridge PRIVATE common vocoder ${OPENSSL_LIBRARIES} dl asio::asio Threads::Threads)
143143
endif (COMPILE_WIN32)
144-
target_include_directories(dvmbridge PRIVATE ${OPENSSL_INCLUDE_DIR} src src/host src/bridge)
144+
target_include_directories(dvmbridge PRIVATE ${OPENSSL_INCLUDE_DIR} src src/bridge)

src/bridge/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
# *
99
# */
1010
file(GLOB bridge_SRC
11-
"src/host/network/Network.h"
12-
"src/host/network/Network.cpp"
13-
1411
"src/bridge/audio/*.h"
1512
"src/bridge/audio/*.c"
1613

src/bridge/network/PeerNetwork.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,32 +159,32 @@ bool PeerNetwork::writeConfig()
159159
json::object config = json::object();
160160

161161
// identity and frequency
162-
config["identity"].set<std::string>(m_identity); // Identity
163-
config["rxFrequency"].set<uint32_t>(m_rxFrequency); // Rx Frequency
164-
config["txFrequency"].set<uint32_t>(m_txFrequency); // Tx Frequency
162+
config["identity"].set<std::string>(m_metadata->identity); // Identity
163+
config["rxFrequency"].set<uint32_t>(m_metadata->rxFrequency); // Rx Frequency
164+
config["txFrequency"].set<uint32_t>(m_metadata->txFrequency); // Tx Frequency
165165

166166
// system info
167167
json::object sysInfo = json::object();
168-
sysInfo["latitude"].set<float>(m_latitude); // Latitude
169-
sysInfo["longitude"].set<float>(m_longitude); // Longitude
168+
sysInfo["latitude"].set<float>(m_metadata->latitude); // Latitude
169+
sysInfo["longitude"].set<float>(m_metadata->longitude); // Longitude
170170

171-
sysInfo["height"].set<int>(m_height); // Height
172-
sysInfo["location"].set<std::string>(m_location); // Location
171+
sysInfo["height"].set<int>(m_metadata->height); // Height
172+
sysInfo["location"].set<std::string>(m_metadata->location); // Location
173173
config["info"].set<json::object>(sysInfo);
174174

175175
// channel data
176176
json::object channel = json::object();
177-
channel["txPower"].set<uint32_t>(m_power); // Tx Power
178-
channel["txOffsetMhz"].set<float>(m_txOffsetMhz); // Tx Offset (Mhz)
179-
channel["chBandwidthKhz"].set<float>(m_chBandwidthKhz); // Ch. Bandwidth (khz)
180-
channel["channelId"].set<uint8_t>(m_channelId); // Channel ID
181-
channel["channelNo"].set<uint32_t>(m_channelNo); // Channel No
177+
channel["txPower"].set<uint32_t>(m_metadata->power); // Tx Power
178+
channel["txOffsetMhz"].set<float>(m_metadata->txOffsetMhz); // Tx Offset (Mhz)
179+
channel["chBandwidthKhz"].set<float>(m_metadata->chBandwidthKhz); // Ch. Bandwidth (khz)
180+
channel["channelId"].set<uint8_t>(m_metadata->channelId); // Channel ID
181+
channel["channelNo"].set<uint32_t>(m_metadata->channelNo); // Channel No
182182
config["channel"].set<json::object>(channel);
183183

184184
// RCON
185185
json::object rcon = json::object();
186-
rcon["password"].set<std::string>(m_restApiPassword); // REST API Password
187-
rcon["port"].set<uint16_t>(m_restApiPort); // REST API Port
186+
rcon["password"].set<std::string>(m_metadata->restApiPassword); // REST API Password
187+
rcon["port"].set<uint16_t>(m_metadata->restApiPort); // REST API Port
188188
config["rcon"].set<json::object>(rcon);
189189

190190
config["software"].set<std::string>(std::string(software)); // Software ID

src/bridge/network/PeerNetwork.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "Defines.h"
2424
#include "common/dmr/data/EmbeddedData.h"
25-
#include "host/network/Network.h"
25+
#include "common/network/Network.h"
2626

2727
#include <string>
2828
#include <cstdint>
Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/*
3-
* Digital Voice Modem - Modem Host Software
3+
* Digital Voice Modem - Common Library
44
* GPLv2 Open Source. Use is subject to license terms.
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66
*
7-
* Copyright (C) 2015,2016,2017 Jonathan Naylor, G4KLX
87
* Copyright (C) 2017-2025 Bryan Biedenkapp, N2PLL
98
*
109
*/
@@ -56,23 +55,10 @@ Network::Network(const std::string& address, uint16_t port, uint16_t localPort,
5655
m_timeoutTimer(1000U, 60U),
5756
m_pktSeq(0U),
5857
m_loginStreamId(0U),
59-
m_identity(),
60-
m_rxFrequency(0U),
61-
m_txFrequency(0U),
62-
m_txOffsetMhz(0.0F),
63-
m_chBandwidthKhz(0.0F),
64-
m_channelId(0U),
65-
m_channelNo(0U),
66-
m_power(0U),
67-
m_latitude(0.0F),
68-
m_longitude(0.0F),
69-
m_height(0),
70-
m_location(),
71-
m_restApiPassword(),
72-
m_restApiPort(0),
73-
m_conventional(false),
58+
m_metadata(nullptr),
7459
m_remotePeerId(0U),
7560
m_promiscuousPeer(false),
61+
m_userHandleProtocol(false),
7662
m_dmrInCallCallback(nullptr),
7763
m_p25InCallCallback(nullptr),
7864
m_nxdnInCallCallback(nullptr),
@@ -89,6 +75,8 @@ Network::Network(const std::string& address, uint16_t port, uint16_t localPort,
8975
m_rxDMRStreamId[1U] = 0U;
9076
m_rxP25StreamId = 0U;
9177
m_rxNXDNStreamId = 0U;
78+
79+
m_metadata = new PeerMetadata();
9280
}
9381

9482
/* Finalizes a instance of the Network class. */
@@ -97,6 +85,7 @@ Network::~Network()
9785
{
9886
delete[] m_salt;
9987
delete[] m_rxDMRStreamId;
88+
delete m_metadata;
10089
}
10190

10291
/* Resets the DMR ring buffer for the given slot. */
@@ -143,28 +132,29 @@ void Network::setLookups(lookups::RadioIdLookup* ridLookup, lookups::TalkgroupRu
143132
void Network::setMetadata(const std::string& identity, uint32_t rxFrequency, uint32_t txFrequency, float txOffsetMhz, float chBandwidthKhz,
144133
uint8_t channelId, uint32_t channelNo, uint32_t power, float latitude, float longitude, int height, const std::string& location)
145134
{
146-
m_identity = identity;
147-
m_rxFrequency = rxFrequency;
148-
m_txFrequency = txFrequency;
149-
150-
m_txOffsetMhz = txOffsetMhz;
151-
m_chBandwidthKhz = chBandwidthKhz;
152-
m_channelId = channelId;
153-
m_channelNo = channelNo;
154-
155-
m_power = power;
156-
m_latitude = latitude;
157-
m_longitude = longitude;
158-
m_height = height;
159-
m_location = location;
135+
m_metadata->identity = identity;
136+
137+
m_metadata->rxFrequency = rxFrequency;
138+
m_metadata->txFrequency = txFrequency;
139+
140+
m_metadata->txOffsetMhz = txOffsetMhz;
141+
m_metadata->chBandwidthKhz = chBandwidthKhz;
142+
m_metadata->channelId = channelId;
143+
m_metadata->channelNo = channelNo;
144+
145+
m_metadata->power = power;
146+
m_metadata->latitude = latitude;
147+
m_metadata->longitude = longitude;
148+
m_metadata->height = height;
149+
m_metadata->location = location;
160150
}
161151

162152
/* Sets REST API configuration settings from the modem. */
163153

164154
void Network::setRESTAPIData(const std::string& password, uint16_t port)
165155
{
166-
m_restApiPassword = password;
167-
m_restApiPort = port;
156+
m_metadata->restApiPassword = password;
157+
m_metadata->restApiPort = port;
168158
}
169159

170160
/* Sets endpoint preshared encryption key. */
@@ -265,6 +255,13 @@ void Network::clock(uint32_t ms)
265255
switch (fneHeader.getFunction()) {
266256
case NET_FUNC::PROTOCOL:
267257
{
258+
// are protocol messages being user handled?
259+
if (m_userHandleProtocol) {
260+
userPacketHandler(fneHeader.getPeerId(), { fneHeader.getFunction(), fneHeader.getSubFunction() },
261+
buffer.get(), length, fneHeader.getStreamId());
262+
break;
263+
}
264+
268265
if (fneHeader.getSubFunction() == NET_SUBFUNC::PROTOCOL_SUBFUNC_DMR) { // Encapsulated DMR data frame
269266
if (m_enabled && m_dmrEnabled) {
270267
uint32_t slotNo = (buffer[15U] & 0x80U) == 0x80U ? 1U : 0U; // this is the raw index for the stream ID array
@@ -931,36 +928,38 @@ bool Network::writeConfig()
931928
json::object config = json::object();
932929

933930
// identity and frequency
934-
config["identity"].set<std::string>(m_identity); // Identity
935-
config["rxFrequency"].set<uint32_t>(m_rxFrequency); // Rx Frequency
936-
config["txFrequency"].set<uint32_t>(m_txFrequency); // Tx Frequency
931+
config["identity"].set<std::string>(m_metadata->identity); // Identity
932+
config["rxFrequency"].set<uint32_t>(m_metadata->rxFrequency); // Rx Frequency
933+
config["txFrequency"].set<uint32_t>(m_metadata->txFrequency); // Tx Frequency
937934

938935
// system info
939936
json::object sysInfo = json::object();
940-
sysInfo["latitude"].set<float>(m_latitude); // Latitude
941-
sysInfo["longitude"].set<float>(m_longitude); // Longitude
937+
sysInfo["latitude"].set<float>(m_metadata->latitude); // Latitude
938+
sysInfo["longitude"].set<float>(m_metadata->longitude); // Longitude
942939

943-
sysInfo["height"].set<int>(m_height); // Height
944-
sysInfo["location"].set<std::string>(m_location); // Location
940+
sysInfo["height"].set<int>(m_metadata->height); // Height
941+
sysInfo["location"].set<std::string>(m_metadata->location); // Location
945942
config["info"].set<json::object>(sysInfo);
946943

947944
// channel data
948945
json::object channel = json::object();
949-
channel["txPower"].set<uint32_t>(m_power); // Tx Power
950-
channel["txOffsetMhz"].set<float>(m_txOffsetMhz); // Tx Offset (Mhz)
951-
channel["chBandwidthKhz"].set<float>(m_chBandwidthKhz); // Ch. Bandwidth (khz)
952-
channel["channelId"].set<uint8_t>(m_channelId); // Channel ID
953-
channel["channelNo"].set<uint32_t>(m_channelNo); // Channel No
946+
channel["txPower"].set<uint32_t>(m_metadata->power); // Tx Power
947+
channel["txOffsetMhz"].set<float>(m_metadata->txOffsetMhz); // Tx Offset (Mhz)
948+
channel["chBandwidthKhz"].set<float>(m_metadata->chBandwidthKhz); // Ch. Bandwidth (khz)
949+
channel["channelId"].set<uint8_t>(m_metadata->channelId); // Channel ID
950+
channel["channelNo"].set<uint32_t>(m_metadata->channelNo); // Channel No
954951
config["channel"].set<json::object>(channel);
955952

956953
// RCON
957954
json::object rcon = json::object();
958-
rcon["password"].set<std::string>(m_restApiPassword); // REST API Password
959-
rcon["port"].set<uint16_t>(m_restApiPort); // REST API Port
955+
rcon["password"].set<std::string>(m_metadata->restApiPassword); // REST API Password
956+
rcon["port"].set<uint16_t>(m_metadata->restApiPort); // REST API Port
960957
config["rcon"].set<json::object>(rcon);
961958

962-
config["conventionalPeer"].set<bool>(m_conventional); // Conventional Peer Marker
963-
config["software"].set<std::string>(std::string(software)); // Software ID
959+
// Flags
960+
config["conventionalPeer"].set<bool>(m_metadata->isConventional); // Conventional Peer Marker
961+
962+
config["software"].set<std::string>(std::string(software));
964963

965964
json::value v = json::value(config);
966965
std::string json = v.serialize();

0 commit comments

Comments
 (0)