Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jg1uaa committed Jun 30, 2020
2 parents 236d467 + df47466 commit 9742514
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 228 deletions.
32 changes: 16 additions & 16 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 @@ -283,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_remoteControlPort(0U)
{
Expand Down Expand Up @@ -367,8 +367,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 Down Expand Up @@ -950,13 +950,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 @@ -2071,19 +2071,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
14 changes: 7 additions & 7 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,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 @@ -565,9 +565,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;
unsigned int m_remoteControlPort;
Expand Down
103 changes: 103 additions & 0 deletions GPSD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2018,2020 by Jonathan Naylor G4KLX
*
* 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 "GPSD.h"

#if defined(USE_GPSD)

#include <cstdio>
#include <cassert>
#include <cstring>
#include <cmath>

CGPSD::CGPSD(const std::string& address, const std::string& port, CDMRNetwork* network) :
m_gpsdAddress(address),
m_gpsdPort(port),
m_network(network),
m_gpsdData(),
m_idTimer(1000U, 60U)
{
assert(!address.empty());
assert(!port.empty());
assert(network != NULL);
}

CGPSD::~CGPSD()
{
}

bool CGPSD::open()
{
int ret = ::gps_open(m_gpsdAddress.c_str(), m_gpsdPort.c_str(), &m_gpsdData);
if (ret != 0) {
LogError("Error when opening access to gpsd - %d - %s", errno, ::gps_errstr(errno));
return false;
}

::gps_stream(&m_gpsdData, WATCH_ENABLE | WATCH_JSON, NULL);

LogMessage("Connected to GPSD");

m_idTimer.start();

return true;
}

void CGPSD::clock(unsigned int ms)
{
m_idTimer.clock(ms);

if (m_idTimer.hasExpired()) {
sendReport();
m_idTimer.start();
}
}

void CGPSD::close()
{
::gps_stream(&m_gpsdData, WATCH_DISABLE, NULL);
::gps_close(&m_gpsdData);
}

void CGPSD::sendReport()
{
if (!::gps_waiting(&m_gpsdData, 0))
return;

#if GPSD_API_MAJOR_VERSION >= 7
if (::gps_read(&m_gpsdData, NULL, 0) <= 0)
return;
#else
if (::gps_read(&m_gpsdData) <= 0)
return;
#endif

if (m_gpsdData.status != STATUS_FIX)
return;

bool latlonSet = (m_gpsdData.set & LATLON_SET) == LATLON_SET;
if (!latlonSet)
return;

float latitude = float(m_gpsdData.fix.latitude);
float longitude = float(m_gpsdData.fix.longitude);

m_network->writeHomePosition(latitude, longitude);
}

#endif
41 changes: 16 additions & 25 deletions MobileGPS.h → GPSD.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 by Jonathan Naylor G4KLX
* Copyright (C) 2018,2020 by Jonathan Naylor G4KLX
*
* 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
Expand All @@ -16,32 +16,22 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef MobileGPS_H
#define MobileGPS_H
#ifndef GPSD_H
#define GPSD_H

#if defined(USE_GPSD)

#include "DMRNetwork.h"
#include "UDPSocket.h"
#include "Timer.h"

#include <string>

#if !defined(_WIN32) && !defined(_WIN64)
#include <netdb.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#else
#include <winsock.h>
#endif
#include <gps.h>

class CMobileGPS {
class CGPSD {
public:
CMobileGPS(const std::string& address, unsigned int port, CDMRNetwork* network);
~CMobileGPS();
CGPSD(const std::string& address, const std::string& port, CDMRNetwork* network);
~CGPSD();

bool open();

Expand All @@ -50,14 +40,15 @@ class CMobileGPS {
void close();

private:
CTimer m_idTimer;
in_addr m_address;
unsigned int m_port;
CUDPSocket m_socket;
CDMRNetwork* m_network;
std::string m_gpsdAddress;
std::string m_gpsdPort;
CDMRNetwork* m_network;
struct gps_data_t m_gpsdData;
CTimer m_idTimer;

bool pollGPS();
void sendReport();
};

#endif

#endif
4 changes: 2 additions & 2 deletions MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ UTC=0
Enable=0
File=/tmp/MMDVM_Active.lck

[Mobile GPS]
[GPSD]
Enable=0
Address=127.0.0.1
Port=7834
Port=2947

[Remote Control]
Enable=0
Expand Down
42 changes: 25 additions & 17 deletions MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ m_id(0U),
m_cwCallsign(),
m_lockFileEnabled(false),
m_lockFileName(),
m_mobileGPS(NULL),
#if defined(USE_GPSD)
m_gpsd(NULL),
#endif
m_remoteControl(NULL),
m_fixedMode(false)
{
Expand Down Expand Up @@ -1004,8 +1006,10 @@ int CMMDVMHost::run()
if (m_pocsagNetwork != NULL)
m_pocsagNetwork->clock(ms);

if (m_mobileGPS != NULL)
m_mobileGPS->clock(ms);
#if defined(USE_GPSD)
if (m_gpsd != NULL)
m_gpsd->clock(ms);
#endif

m_cwIdTimer.clock(ms);
if (m_cwIdTimer.isRunning() && m_cwIdTimer.hasExpired()) {
Expand Down Expand Up @@ -1082,10 +1086,12 @@ int CMMDVMHost::run()
m_display->close();
delete m_display;

if (m_mobileGPS != NULL) {
m_mobileGPS->close();
delete m_mobileGPS;
#if defined(USE_GPSD)
if (m_gpsd != NULL) {
m_gpsd->close();
delete m_gpsd;
}
#endif

if (m_ump != NULL) {
m_ump->close();
Expand Down Expand Up @@ -1392,23 +1398,25 @@ bool CMMDVMHost::createDMRNetwork()
return false;
}

bool mobileGPSEnabled = m_conf.getMobileGPSEnabled();
if (mobileGPSEnabled) {
std::string mobileGPSAddress = m_conf.getMobileGPSAddress();
unsigned int mobileGPSPort = m_conf.getMobileGPSPort();
#if defined(USE_GPSD)
bool gpsdEnabled = m_conf.getGPSDEnabled();
if (gpsdEnabled) {
std::string gpsdAddress = m_conf.getGPSDAddress();
std::string gpsdPort = m_conf.getGPSDPort();

LogInfo("Mobile GPS Parameters");
LogInfo(" Address: %s", mobileGPSAddress.c_str());
LogInfo(" Port: %u", mobileGPSPort);
LogInfo("GPSD Parameters");
LogInfo(" Address: %s", gpsdAddress.c_str());
LogInfo(" Port: %s", gpsdPort.c_str());

m_mobileGPS = new CMobileGPS(address, port, m_dmrNetwork);
m_gpsd = new CGPSD(gpsdAddress, gpsdPort, m_dmrNetwork);

ret = m_mobileGPS->open();
ret = m_gpsd->open();
if (!ret) {
delete m_mobileGPS;
m_mobileGPS = NULL;
delete m_gpsd;
m_gpsd = NULL;
}
}
#endif

m_dmrNetwork->enable(true);

Expand Down
6 changes: 4 additions & 2 deletions MMDVMHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
#include "P25Network.h"
#include "DMRNetwork.h"
#include "DMRLookup.h"
#include "MobileGPS.h"
#include "Display.h"
#include "Timer.h"
#include "Modem.h"
#include "Conf.h"
#include "GPSD.h"
#include "UMP.h"

#include <string>
Expand Down Expand Up @@ -102,7 +102,9 @@ class CMMDVMHost
std::string m_cwCallsign;
bool m_lockFileEnabled;
std::string m_lockFileName;
CMobileGPS* m_mobileGPS;
#if defined(USE_GPSD)
CGPSD* m_gpsd;
#endif
CRemoteControl* m_remoteControl;
bool m_fixedMode;

Expand Down
Loading

0 comments on commit 9742514

Please sign in to comment.