Skip to content

Commit

Permalink
Merge pull request g4klx#617 from jg1uaa/ipv6
Browse files Browse the repository at this point in the history
IPv6: catch up current source
  • Loading branch information
g4klx authored Jul 14, 2020
2 parents 19c8c65 + c40291d commit 34db212
Show file tree
Hide file tree
Showing 35 changed files with 1,981 additions and 463 deletions.
53 changes: 36 additions & 17 deletions Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ enum SECTION {
SECTION_OLED,
SECTION_LCDPROC,
SECTION_LOCK_FILE,
SECTION_MOBILE_GPS,
SECTION_GPSD,
SECTION_REMOTE_CONTROL
};

Expand Down Expand Up @@ -236,6 +236,7 @@ m_p25LocalPort(0U),
m_p25NetworkModeHang(3U),
m_p25NetworkDebug(false),
m_nxdnNetworkEnabled(false),
m_nxdnNetworkProtocol("Icom"),
m_nxdnGatewayAddress(),
m_nxdnGatewayPort(0U),
m_nxdnLocalAddress(),
Expand Down Expand Up @@ -282,9 +283,9 @@ m_lcdprocUTC(false),
m_lcdprocDimOnIdle(false),
m_lockFileEnabled(false),
m_lockFileName(),
m_mobileGPSEnabled(false),
m_mobileGPSAddress(),
m_mobileGPSPort(0U),
m_gpsdEnabled(false),
m_gpsdAddress(),
m_gpsdPort(),
m_remoteControlEnabled(false),
m_remoteControlAddress("127.0.0.1"),
m_remoteControlPort(0U)
Expand Down Expand Up @@ -367,8 +368,8 @@ bool CConf::read()
section = SECTION_LCDPROC;
else if (::strncmp(buffer, "[Lock File]", 11U) == 0)
section = SECTION_LOCK_FILE;
else if (::strncmp(buffer, "[Mobile GPS]", 12U) == 0)
section = SECTION_MOBILE_GPS;
else if (::strncmp(buffer, "[GPSD]", 6U) == 0)
section = SECTION_GPSD;
else if (::strncmp(buffer, "[Remote Control]", 16U) == 0)
section = SECTION_REMOTE_CONTROL;
else
Expand All @@ -390,6 +391,17 @@ bool CConf::read()
if (len > 1U && *value == '"' && value[len - 1U] == '"') {
value[len - 1U] = '\0';
value++;
} else {
char *p;

// if value is not quoted, remove after # (to make comment)
if ((p = strchr(value, '#')) != NULL)
*p = '\0';

// remove trailing tab/space
for (p = value + strlen(value) - 1;
p >= value && (*p == '\t' || *p == ' '); p--)
*p = '\0';
}

if (section == SECTION_GENERAL) {
Expand Down Expand Up @@ -843,6 +855,8 @@ bool CConf::read()
} else if (section == SECTION_NXDN_NETWORK) {
if (::strcmp(key, "Enable") == 0)
m_nxdnNetworkEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Protocol") == 0)
m_nxdnNetworkProtocol = value;
else if (::strcmp(key, "LocalAddress") == 0)
m_nxdnLocalAddress = value;
else if (::strcmp(key, "LocalPort") == 0)
Expand Down Expand Up @@ -914,7 +928,7 @@ bool CConf::read()
else if (::strcmp(key, "IdleBrightness") == 0)
m_nextionIdleBrightness = (unsigned int)::atoi(value);
else if (::strcmp(key, "ScreenLayout") == 0)
m_nextionScreenLayout = (unsigned int)::atoi(value);
m_nextionScreenLayout = (unsigned int)::strtoul(value, NULL, 0);
else if (::strcmp(key, "DisplayTempInFahrenheit") == 0)
m_nextionTempInFahrenheit = ::atoi(value) == 1;
} else if (section == SECTION_OLED) {
Expand Down Expand Up @@ -948,13 +962,13 @@ bool CConf::read()
m_lockFileEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "File") == 0)
m_lockFileName = value;
} else if (section == SECTION_MOBILE_GPS) {
} else if (section == SECTION_GPSD) {
if (::strcmp(key, "Enable") == 0)
m_mobileGPSEnabled = ::atoi(value) == 1;
m_gpsdEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Address") == 0)
m_mobileGPSAddress = value;
m_gpsdAddress = value;
else if (::strcmp(key, "Port") == 0)
m_mobileGPSPort = (unsigned int)::atoi(value);
m_gpsdPort = value;
} else if (section == SECTION_REMOTE_CONTROL) {
if (::strcmp(key, "Enable") == 0)
m_remoteControlEnabled = ::atoi(value) == 1;
Expand Down Expand Up @@ -1835,6 +1849,11 @@ bool CConf::getNXDNNetworkEnabled() const
return m_nxdnNetworkEnabled;
}

std::string CConf::getNXDNNetworkProtocol() const
{
return m_nxdnNetworkProtocol;
}

std::string CConf::getNXDNGatewayAddress() const
{
return m_nxdnGatewayAddress;
Expand Down Expand Up @@ -2066,19 +2085,19 @@ std::string CConf::getLockFileName() const
return m_lockFileName;
}

bool CConf::getMobileGPSEnabled() const
bool CConf::getGPSDEnabled() const
{
return m_mobileGPSEnabled;
return m_gpsdEnabled;
}

std::string CConf::getMobileGPSAddress() const
std::string CConf::getGPSDAddress() const
{
return m_mobileGPSAddress;
return m_gpsdAddress;
}

unsigned int CConf::getMobileGPSPort() const
std::string CConf::getGPSDPort() const
{
return m_mobileGPSPort;
return m_gpsdPort;
}

bool CConf::getRemoteControlEnabled() const
Expand Down
16 changes: 9 additions & 7 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class CConf

// The NXDN Network section
bool getNXDNNetworkEnabled() const;
std::string getNXDNNetworkProtocol() const;
std::string getNXDNGatewayAddress() const;
unsigned int getNXDNGatewayPort() const;
std::string getNXDNLocalAddress() const;
Expand Down Expand Up @@ -305,10 +306,10 @@ class CConf
bool getLockFileEnabled() const;
std::string getLockFileName() const;

// The Mobile GPS section
bool getMobileGPSEnabled() const;
std::string getMobileGPSAddress() const;
unsigned int getMobileGPSPort() const;
// The GPSD section
bool getGPSDEnabled() const;
std::string getGPSDAddress() const;
std::string getGPSDPort() const;

// The Remote Control section
bool getRemoteControlEnabled() const;
Expand Down Expand Up @@ -510,6 +511,7 @@ class CConf
bool m_p25NetworkDebug;

bool m_nxdnNetworkEnabled;
std::string m_nxdnNetworkProtocol;
std::string m_nxdnGatewayAddress;
unsigned int m_nxdnGatewayPort;
std::string m_nxdnLocalAddress;
Expand Down Expand Up @@ -564,9 +566,9 @@ class CConf
bool m_lockFileEnabled;
std::string m_lockFileName;

bool m_mobileGPSEnabled;
std::string m_mobileGPSAddress;
unsigned int m_mobileGPSPort;
bool m_gpsdEnabled;
std::string m_gpsdAddress;
std::string m_gpsdPort;

bool m_remoteControlEnabled;
std::string m_remoteControlAddress;
Expand Down
18 changes: 11 additions & 7 deletions DMRNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ m_height(0),
m_location(),
m_description(),
m_url(),
m_beacon(false)
m_beacon(false),
m_random()
{
assert(!address.empty());
assert(port > 0U);
Expand All @@ -86,11 +87,13 @@ m_beacon(false)
m_id[2U] = id >> 8;
m_id[3U] = id >> 0;

CStopWatch stopWatch;
::srand(stopWatch.start());
std::random_device rd;
std::mt19937 mt(rd());
m_random = mt;

m_streamId[0U] = ::rand() + 1U;
m_streamId[1U] = ::rand() + 1U;
std::uniform_int_distribution<uint32_t> dist(0x00000001, 0xfffffffe);
m_streamId[0U] = dist(m_random);
m_streamId[1U] = dist(m_random);
}

CDMRNetwork::~CDMRNetwork()
Expand Down Expand Up @@ -247,17 +250,18 @@ bool CDMRNetwork::write(const CDMRData& data)

unsigned int slotIndex = slotNo - 1U;

std::uniform_int_distribution<uint32_t> dist(0x00000001, 0xfffffffe);
unsigned char dataType = data.getDataType();
if (dataType == DT_VOICE_SYNC) {
buffer[15U] |= 0x10U;
} else if (dataType == DT_VOICE) {
buffer[15U] |= data.getN();
} else {
if (dataType == DT_VOICE_LC_HEADER)
m_streamId[slotIndex] = ::rand() + 1U;
m_streamId[slotIndex] = dist(m_random);

if (dataType == DT_CSBK || dataType == DT_DATA_HEADER)
m_streamId[slotIndex] = ::rand() + 1U;
m_streamId[slotIndex] = dist(m_random);

buffer[15U] |= (0x20U | dataType);
}
Expand Down
2 changes: 2 additions & 0 deletions DMRNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <string>
#include <cstdint>
#include <random>

class CDMRNetwork
{
Expand Down Expand Up @@ -107,6 +108,7 @@ class CDMRNetwork
std::string m_url;

bool m_beacon;
std::mt19937 m_random;

bool writeLogin();
bool writeAuthorisation();
Expand Down
11 changes: 7 additions & 4 deletions DStarNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ m_inId(0U),
m_buffer(1000U, "D-Star Network"),
m_pollTimer(1000U, 60U),
m_linkStatus(LS_NONE),
m_linkReflector(NULL)
m_linkReflector(NULL),
m_random()
{
CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen);

m_linkReflector = new unsigned char[DSTAR_LONG_CALLSIGN_LENGTH];

CStopWatch stopWatch;
::srand(stopWatch.start());
std::random_device rd;
std::mt19937 mt(rd());
m_random = mt;
}

CDStarNetwork::~CDStarNetwork()
Expand Down Expand Up @@ -85,7 +87,8 @@ bool CDStarNetwork::writeHeader(const unsigned char* header, unsigned int length
buffer[4] = busy ? 0x22U : 0x20U;

// Create a random id for this transmission
m_outId = (::rand() % 65535U) + 1U;
std::uniform_int_distribution<uint16_t> dist(0x0001, 0xfffe);
m_outId = dist(m_random);

buffer[5] = m_outId / 256U; // Unique session id
buffer[6] = m_outId % 256U;
Expand Down
2 changes: 2 additions & 0 deletions DStarNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <cstdint>
#include <string>
#include <random>

class CDStarNetwork {
public:
Expand Down Expand Up @@ -64,6 +65,7 @@ class CDStarNetwork {
CTimer m_pollTimer;
LINK_STATUS m_linkStatus;
unsigned char* m_linkReflector;
std::mt19937 m_random;

bool writePoll(const char* text);
};
Expand Down
2 changes: 1 addition & 1 deletion Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ CDisplay* CDisplay::createDisplay(const CConf& conf, CUMP* ump, CModem* modem)
}
} else {
SERIAL_SPEED baudrate = SERIAL_9600;
if (screenLayout==4U)
if (screenLayout&0x0cU)
baudrate = SERIAL_115200;

LogInfo(" Display baudrate: %u ",baudrate);
Expand Down
Loading

0 comments on commit 34db212

Please sign in to comment.