#20 first working prototype of time server

pull/32/head
Geoffrey Merck 4 years ago
parent 77634729d4
commit b237829b95

@ -19,9 +19,9 @@
#include <string>
#include <iostream>
#include <cassert>
#include "DGWTimeServerApp.h"
#include "TimeServerConfig.h"
int main(int argc, char * argv[])
{
@ -34,7 +34,62 @@ int main(int argc, char * argv[])
std::string configfile(argv[1]);
CTimeServerConfig config(configfile);
if(!config.load())
return 1;
CDGWTimeServerApp app(&config);
if(!app.init())
return 0;
return 1;
app.run();
return 0;
}
CDGWTimeServerApp::CDGWTimeServerApp(const CTimeServerConfig * config) :
m_config(config)
{
assert(config != nullptr);
}
CDGWTimeServerApp::~CDGWTimeServerApp()
{
delete m_thread;
}
bool CDGWTimeServerApp::init()
{
return createThread();
}
void CDGWTimeServerApp::run()
{
m_thread->Run();
m_thread->Wait();
}
bool CDGWTimeServerApp::createThread()
{
m_thread = new CTimeServerThread();
TTimeServer timeserver;
m_config->getTimeServer(timeserver);
std::vector<std::string> rptrs = { "", "", "", "" };
TRepeater repeater;
for(unsigned int i = 0u; i < m_config->getRepeaterCount(); i++) {
m_config->getRepeater(i, repeater);
rptrs[i].assign(repeater.band);
}
TPaths paths;
m_config->getPaths(paths);
m_thread = new CTimeServerThread();
bool ret = m_thread->setGateway(timeserver.callsign, rptrs[0], rptrs[1], rptrs[2], rptrs[3], timeserver.address, paths.data);
if(ret) {
m_thread->setAnnouncements(timeserver.language, timeserver.format, timeserver.interval);
}
return ret;
}

@ -19,3 +19,24 @@
#pragma once
#include "TimeServerDefs.h"
#include "TimeServerConfig.h"
#include "TimeServerThread.h"
class CDGWTimeServerApp
{
private:
/* data */
public:
CDGWTimeServerApp(const CTimeServerConfig * config);
~CDGWTimeServerApp();
bool init();
void run();
private:
bool createThread();
const CTimeServerConfig * m_config;
CTimeServerThread * m_thread;
};

@ -49,6 +49,7 @@ bool CTimeServerConfig::load()
ret = loadTimeServer(cfg) && ret;
ret = loadRepeaters(cfg) && ret;
ret = loadDaemon(cfg) && ret;
ret = loadPaths(cfg) && ret;
}
return ret;
@ -137,3 +138,34 @@ bool CTimeServerConfig::loadDaemon(const CConfig & cfg)
ret = cfg.getValue("daemon", "user", m_daemon.user, 0, 1024, "") && ret;
return ret;
}
bool CTimeServerConfig::loadPaths(const CConfig & cfg)
{
bool ret = cfg.getValue("paths", "data", m_paths.data, 1, 1024, "");
return ret;
}
void CTimeServerConfig::getTimeServer(TTimeServer& timeserver) const
{
timeserver = m_timeServer;
}
void CTimeServerConfig::getDameon(TDaemon& daemon) const
{
daemon = m_daemon;
}
unsigned int CTimeServerConfig::getRepeaterCount() const
{
return m_repeaters.size();
}
void CTimeServerConfig::getRepeater(unsigned int idx, TRepeater& repeater) const
{
repeater = *(m_repeaters[idx]);
}
void CTimeServerConfig::getPaths(TPaths& paths) const
{
paths = m_paths;
}

@ -33,7 +33,6 @@ typedef struct {
} TTimeServer;
typedef struct {
bool enabled;
std::string band;
} TRepeater;
@ -43,6 +42,9 @@ typedef struct {
std::string user;
} TDaemon;
typedef struct {
std::string data;
} TPaths;
class CTimeServerConfig
{
@ -51,15 +53,22 @@ public:
~CTimeServerConfig();
bool load();
void getTimeServer(TTimeServer& timeserver) const;
void getDameon(TDaemon& daemon) const;
unsigned int getRepeaterCount() const;
void getRepeater(unsigned int idx, TRepeater& repeater) const;
void getPaths(TPaths& paths) const;
private:
bool open(CConfig & cfg);
bool loadRepeaters(const CConfig & cfg);
bool loadTimeServer(const CConfig & cfg);
bool loadDaemon(const CConfig & cfg);
bool loadPaths(const CConfig & cfg);
std::string m_fileName;
std::vector<TRepeater *> m_repeaters;
TTimeServer m_timeServer;
TDaemon m_daemon;
TPaths m_paths;
};

@ -19,7 +19,7 @@
#pragma once
const std::string APPLICATION_NAME("Time Server");
const std::string APPLICATION_NAME("DStarGateway time Server");
enum LANGUAGE {
LANG_ENGLISH_UK_1,

File diff suppressed because it is too large Load Diff

@ -0,0 +1,122 @@
/*
* Copyright (C) 2012,2013 by Jonathan Naylor G4KLX
* Copyright (C) 2022 by Geoffrey Merck F4FXL / KC3FRA
*
* 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.
*/
#pragma once
#include <unordered_map>
#include "SlowDataEncoder.h"
#include "UDPReaderWriter.h"
#include "TimeServerDefs.h"
#include "HeaderData.h"
#include "AMBEData.h"
#include "Thread.h"
class CIndexRecord {
public:
CIndexRecord(const std::string& name, unsigned int start, unsigned int length) :
m_name(name),
m_start(start),
m_length(length)
{
}
std::string getName() const
{
return m_name;
}
unsigned int getStart() const
{
return m_start;
}
unsigned int getLength() const
{
return m_length;
}
private:
std::string m_name;
unsigned int m_start;
unsigned int m_length;
};
class CTimeServerThread : public CThread
{
public:
CTimeServerThread();
~CTimeServerThread();
bool setGateway(const std::string& callsign, const std::string& rpt1, const std::string& rpt2, const std::string& rpt3, const std::string& rpt4, const std::string& address, const std::string& dataPath);
void setAnnouncements(LANGUAGE language, FORMAT format, INTERVAL interval);
void * Entry();
void kill();
private:
CUDPReaderWriter m_socket;
std::string m_callsign;
std::string m_callsignA;
std::string m_callsignB;
std::string m_callsignC;
std::string m_callsignD;
std::string m_callsignE;
std::string m_callsignG;
in_addr m_address;
LANGUAGE m_language;
FORMAT m_format;
INTERVAL m_interval;
unsigned char* m_ambe;
unsigned int m_ambeLength;
std::unordered_map<std::string, CIndexRecord*> m_index;
unsigned int m_seqNo;
unsigned int m_in;
CSlowDataEncoder m_encoder;
CAMBEData** m_data;
bool m_killed;
std::string m_dataPath;
void sendTime(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeEnGB1(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeEnGB2(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeEnUS1(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeEnUS2(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeDeDE1(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeDeDE2(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeFrFR(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeNlNL(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeSeSE(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeEsES(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimeNoNO(unsigned int hour, unsigned int min);
std::vector<std::string> sendTimePtPT(unsigned int hour, unsigned int min);
bool send(const std::vector<std::string>& words, unsigned int hour, unsigned int min);
bool sendHeader(const CHeaderData& header);
bool sendData(const CAMBEData& data);
bool loadAMBE();
bool readAMBE(const std::string& dir, const std::string& name);
bool readIndex(const std::string& dir, const std::string& name);
bool lookup(const std::string& id);
void end();
};

@ -5,6 +5,9 @@ format= # possible values are voice, text, voiceandtext, defaults to voice a
language= # valid values: english_uk_1, english_uk_2, english_us_1, english_us_2, deutsch_1, deutsch_2, francais, nederlands, svenska, espanol, norsk, portugues. Defaults to english_uk_1
interval= # valid values are 15, 30 and 60, defaults to 30
[Paths]
data=/usr/local/share/dstargateway.d/ #Path where the data (hostfiles, audio files etc) can be found
# Up to 4 repeaters can be enabled to transmit time beacons
[Repeater_1]
enabled=true # enable time beacons on this repeater

Loading…
Cancel
Save

Powered by TurnKey Linux.