Skip to content

Commit

Permalink
DMR beacon handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Jan 14, 2016
1 parent bab0c34 commit f165b3c
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 14 deletions.
8 changes: 8 additions & 0 deletions Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ m_modemDebug(false),
m_dstarEnabled(true),
m_dstarModule("C"),
m_dmrEnabled(true),
m_dmrBeacons(false),
m_dmrId(0U),
m_dmrColorCode(2U),
m_fusionEnabled(true),
Expand Down Expand Up @@ -209,6 +210,8 @@ bool CConf::read()
} else if (section == SECTION_DMR) {
if (::strcmp(key, "Enabled") == 0)
m_dmrEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Beacons") == 0)
m_dmrBeacons = ::atoi(value) == 1;
else if (::strcmp(key, "Id") == 0)
m_dmrId = (unsigned int)::atoi(value);
else if (::strcmp(key, "ColorCode") == 0)
Expand Down Expand Up @@ -403,6 +406,11 @@ bool CConf::getDMREnabled() const
return m_dmrEnabled;
}

bool CConf::getDMRBeacons() const
{
return m_dmrBeacons;
}

unsigned int CConf::getDMRId() const
{
return m_dmrId;
Expand Down
2 changes: 2 additions & 0 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class CConf

// The DMR section
bool getDMREnabled() const;
bool getDMRBeacons() const;
unsigned int getDMRId() const;
unsigned int getDMRColorCode() const;

Expand Down Expand Up @@ -134,6 +135,7 @@ class CConf
std::string m_dstarModule;

bool m_dmrEnabled;
bool m_dmrBeacons;
unsigned int m_dmrId;
unsigned int m_dmrColorCode;

Expand Down
4 changes: 2 additions & 2 deletions Log.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016 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 Down Expand Up @@ -53,7 +53,7 @@ static bool LogOpen()
}

char filename[50U];
#if defined(WIN32)
#if defined(_WIN32) || defined(_WIN64)
::sprintf(filename, "%s\\%s-%04d-%02d-%02d.log", m_path.c_str(), m_root.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
#else
::sprintf(filename, "%s/%s-%04d-%02d-%02d.log", m_path.c_str(), m_root.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
Expand Down
5 changes: 3 additions & 2 deletions MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Display=None
RXFrequency=435000000
TXFrequency=435000000
Power=1
Latitude=51.0
Longitude=-1.0
Latitude=0.0
Longitude=0.0
Height=0
Location=Nowhere
Description=Multi-Mode Repeater
Expand Down Expand Up @@ -40,6 +40,7 @@ Module=C

[DMR]
Enable=1
Beacons=1
Id=123456
ColorCode=1

Expand Down
32 changes: 28 additions & 4 deletions MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

#include <cstdio>

#if !defined(WIN32)
#if !defined(_WIN32) && !defined(_WIN64)
#include <unistd.h>
#include <signal.h>
#endif

static bool m_killed = false;

#if !defined(WIN32)
#if !defined(_WIN32) && !defined(_WIN64)
static void sigHandler(int)
{
m_killed = true;
Expand All @@ -55,7 +55,7 @@ int main(int argc, char** argv)
return 1;
}

#if !defined(WIN32)
#if !defined(_WIN32) && !defined(_WIN64)
::signal(SIGUSR1, sigHandler);
#endif

Expand Down Expand Up @@ -120,6 +120,9 @@ int CMMDVMHost::run()
return 1;
}

CTimer dmrBeaconTimer(1000U, 4U);
bool dmrBeaconsEnabled = m_dmrEnabled && m_conf.getDMRBeacons();

CStopWatch stopWatch;
stopWatch.start();

Expand Down Expand Up @@ -188,6 +191,7 @@ int CMMDVMHost::run()
}
} else if (mode == MODE_DMR) {
dmr->writeModemSlot1(data);
dmrBeaconTimer.stop();
modeTimer.start();
} else {
LogWarning("DMR data received when in mode %u", mode);
Expand All @@ -208,6 +212,7 @@ int CMMDVMHost::run()
}
} else if (mode == MODE_DMR) {
dmr->writeModemSlot2(data);
dmrBeaconTimer.stop();
modeTimer.start();
} else {
LogWarning("DMR data received when in mode %u", mode);
Expand Down Expand Up @@ -272,6 +277,7 @@ int CMMDVMHost::run()
}
if (len > 0U && mode == MODE_DMR) {
m_modem->writeDMRData1(data, len);
dmrBeaconTimer.stop();
modeTimer.start();
}
}
Expand All @@ -285,6 +291,7 @@ int CMMDVMHost::run()
}
if (len > 0U && mode == MODE_DMR) {
m_modem->writeDMRData2(data, len);
dmrBeaconTimer.stop();
modeTimer.start();
}
}
Expand All @@ -306,6 +313,16 @@ int CMMDVMHost::run()
}
}

if (m_dmrNetwork != NULL) {
bool run = m_dmrNetwork->wantsBeacon();

if (dmrBeaconsEnabled && run && mode == MODE_IDLE) {
mode = MODE_DMR;
m_modem->writeDMRStart(true);
dmrBeaconTimer.start();
}
}

unsigned int ms = stopWatch.elapsed();
m_modem->clock(ms);
modeTimer.clock(ms);
Expand All @@ -317,8 +334,15 @@ int CMMDVMHost::run()
ysf->clock(ms);
stopWatch.start();

dmrBeaconTimer.clock(ms);
if (dmrBeaconTimer.isRunning() && dmrBeaconTimer.hasExpired()) {
dmrBeaconTimer.stop();
m_modem->writeDMRStart(false);
mode = MODE_IDLE;
}

if (ms < 5U) {
#if defined(WIN32)
#if defined(_WIN32) || defined(_WIN64)
::Sleep(5UL); // 5ms
#else
::usleep(5000); // 5ms
Expand Down
4 changes: 2 additions & 2 deletions SHA256.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
* Copyright (C) 2011,2015 by Jonathan Naylor G4KLX
* Copyright (C) 2011,2015,2016 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 @@ -20,7 +20,7 @@
#ifndef SHA256_H
#define SHA256_H

#if defined(WIN32)
#if defined(_WIN32) || defined(_WIN64)
typedef unsigned int uint32_t;
#else
#include <cstdint>
Expand Down
6 changes: 3 additions & 3 deletions SerialController.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2002-2004,2007-2011,2013,2014,2015 by Jonathan Naylor G4KLX
* Copyright (C) 2002-2004,2007-2011,2013,2014-2016 by Jonathan Naylor G4KLX
* Copyright (C) 1999-2001 by Thomas Sailor HB9JNX
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -24,7 +24,7 @@

#include <sys/types.h>

#if defined(WIN32)
#if defined(_WIN32) || defined(_WIN64)
#include <setupapi.h>
#include <winioctl.h>
#else
Expand All @@ -37,7 +37,7 @@
#endif


#if defined(WIN32)
#if defined(_WIN32) || defined(_WIN64)

const unsigned int BUFFER_LENGTH = 1000U;

Expand Down
2 changes: 1 addition & 1 deletion StopWatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CStopWatch
unsigned int elapsed();

private:
#if defined(WIN32)
#if defined(_WIN32) || defined(_WIN64)
LARGE_INTEGER m_frequency;
LARGE_INTEGER m_start;
#else
Expand Down

0 comments on commit f165b3c

Please sign in to comment.