Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
# CMakeLists.txt fuer DateTimeSyncer
|
||||
#
|
||||
|
||||
SET (dateTimeSyncer_SRCS
|
||||
system_caller.cpp
|
||||
system_caller.h
|
||||
logger.cpp
|
||||
logger.h
|
||||
tcp_server.cpp
|
||||
tcp_server.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
NGL_ADD_EXECUTABLE(DateTimeSyncer WS NO_TRANSLATION ${dateTimeSyncer_SRCS})
|
||||
NGL_TARGET_LINK_LIBRARIES(DateTimeSyncer
|
||||
LtsCommandLineParser
|
||||
Qt5::Core
|
||||
Qt5::Network
|
||||
NGLLogger
|
||||
nglapplication
|
||||
nglsettings
|
||||
ngltools
|
||||
)
|
||||
|
||||
NGL_INSTALL_TARGET(DateTimeSyncer)
|
||||
NGL_INSTALL(WS FILES log4cxx_dateTimeSyncer.props DESTINATION bin)
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
log4j.reset=true
|
||||
log4j.rootLogger=WARN, file
|
||||
|
||||
# Service: SerialToTcpConverter
|
||||
###########################################################
|
||||
|
||||
#log4j.logger.SystemCaller=DEBUG
|
||||
|
||||
|
||||
#
|
||||
# Lts::RollingFileAppender
|
||||
log4j.appender.file=Lts::RollingFileAppender
|
||||
log4j.appender.file.MaxFileSize=1MB
|
||||
log4j.appender.file.MaxBackupIndex=9
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d %-5p %c |#| %m (%.50F:%L) %n
|
||||
|
||||
|
||||
# Appnd_Console
|
||||
###########################################################
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern= %d %p %c %c{1} - %m (%-.30F:%L) %n
|
||||
|
||||
|
||||
# Appnd_Syslog
|
||||
###########################################################
|
||||
log4j.appender.syslog=org.apache.log4j.SyslogAppender
|
||||
log4j.appender.syslog.Threshold=ERROR
|
||||
log4j.appender.syslog.SysLogHost=localhost
|
||||
log4j.appender.syslog.Facility=LOCAL7
|
||||
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.syslog.layout.ConversionPattern= %-4r %-5p %c %x - %m
|
||||
log4j.appender.syslog.LevelRangeFilter.AcceptOnMatch=true
|
||||
log4j.appender.syslog.LevelRangeFilter.LevelMin=INFO
|
||||
log4j.appender.syslog.LevelRangeFilter.LevelMax=FATAL
|
||||
|
||||
|
||||
###########################################################
|
||||
###########################################################
|
||||
###########################################################
|
||||
# 1) Available Levels in LOG4CXX Version 0.10.0:
|
||||
# TRACE,
|
||||
# DEBUG,
|
||||
# INFO,
|
||||
# WARN,
|
||||
# ERROR
|
||||
# FATAL
|
||||
#
|
||||
# d = date/time
|
||||
# p = priority (Level)
|
||||
# c = category/channel
|
||||
# m = message
|
||||
# F = file
|
||||
# L = line
|
||||
# n = platform dependent line separator character or characters.
|
||||
# ....
|
||||
#
|
||||
# Examples for console:
|
||||
# a)
|
||||
# %d %p %c #%m# (%.50F:%L)%n
|
||||
# date/time
|
||||
# priority
|
||||
# category/channel
|
||||
# #message#
|
||||
# (Maximal 50Character des Filename von rechts:Line)
|
||||
# line separator
|
||||
#
|
||||
# b)
|
||||
# %d (%.15F:%L) %-5p %c |#| %m%n
|
||||
# date/time
|
||||
# (Maximal 15Character des Filename von rechts:Line)
|
||||
# priority, Right pad with spaces if the priority name is less than 5 characters long.
|
||||
# category/channel
|
||||
# message
|
||||
# line separator
|
||||
#
|
||||
# Examples for files:
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Building Config - logging facility
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
namespace DateTimeSyncer
|
||||
{
|
||||
|
||||
LOGGER_T getLogger(const char *name)
|
||||
{
|
||||
static const char ns[] = "DateTimeSyncer.";
|
||||
std::string loggerName;
|
||||
const size_t len = strlen(name);
|
||||
loggerName.reserve(sizeof(ns) + len);
|
||||
loggerName.append(ns, sizeof(ns) - 1);
|
||||
loggerName.append(name, len);
|
||||
|
||||
try
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
|
||||
getNGLLogger(loggerName);
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace DateTimeSyncer
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Logging for XxxXxxXxx
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
namespace DateTimeSyncer
|
||||
{
|
||||
typedef NGL::INGLLogger &LOGGER_T;
|
||||
|
||||
LOGGER_T getLogger(const char *name);
|
||||
inline LOGGER_T getLogger(const QString &loggerName)
|
||||
{
|
||||
return getLogger(loggerName.toUtf8().constData());
|
||||
}
|
||||
} // namespace DateTimeSyncer
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* DateTimeSyncer to set Time and Date
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, NLE, 07-03-2019
|
||||
*/
|
||||
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <nglapplication/nglapplication.h>
|
||||
#include <QNetworkProxy>
|
||||
|
||||
#include "system_caller.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NGLApplication app(argc, argv);
|
||||
QNetworkProxy::setApplicationProxy(QNetworkProxy());
|
||||
|
||||
LtsCommandLineParser::LtsCommandLineParser options(LtsCommandLineParser::LtsCommandLineParser::ProvideCommandLineParameterOptions::CustomConfigFile);
|
||||
if (!options.init())
|
||||
return -1;
|
||||
|
||||
app.createLogger("DateTimeSyncer", "log4cxx_dateTimeSyncer.props");
|
||||
NGL::INGLLogger &logger = app.baseLogger();
|
||||
QCoreApplication::setApplicationName(QLatin1String("Date Time Syncer"));
|
||||
QCoreApplication::setOrganizationName(QLatin1String("RME"));
|
||||
|
||||
int retval = 0;
|
||||
STARTUP_LOG(logger);
|
||||
{
|
||||
DateTimeSyncer::SystemCaller controller;
|
||||
controller.init(13777);
|
||||
retval = app.exec();
|
||||
|
||||
SHUTDOWN_LOG(logger);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
Executable
+118
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* SystemCaller to set Time and Date
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, NLE, 07-03-2019
|
||||
*/
|
||||
#include "system_caller.h"
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace DateTimeSyncer
|
||||
{
|
||||
|
||||
SystemCaller::SystemCaller(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_tcpServer(new TcpServer(this))
|
||||
, m_sockets(QVector<QTcpSocket*>())
|
||||
, m_logger(getLogger("SystemCaller"))
|
||||
{}
|
||||
|
||||
SystemCaller::~SystemCaller()
|
||||
{
|
||||
for (auto socket : qAsConst(m_sockets))
|
||||
{
|
||||
socket->close();
|
||||
socket->deleteLater();
|
||||
}
|
||||
|
||||
m_tcpServer->close();
|
||||
|
||||
delete m_tcpServer;
|
||||
}
|
||||
|
||||
bool SystemCaller::init(int tcpPort)
|
||||
{
|
||||
connect(m_tcpServer, &TcpServer::newConnection, this, &SystemCaller::newConnection);
|
||||
bool result = m_tcpServer->listen(QHostAddress::Any, tcpPort);
|
||||
quint16 actualPort = m_tcpServer->serverPort();
|
||||
|
||||
NOTICE_LOG(m_logger) << "Start listen to port " << actualPort << " result: " << result;
|
||||
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SystemCaller::newConnection()
|
||||
{
|
||||
while (m_tcpServer->hasPendingConnections())
|
||||
{
|
||||
// store socket and connect to signals
|
||||
QTcpSocket *socket = m_tcpServer->nextPendingConnection();
|
||||
connect(socket, &QTcpSocket::readyRead, this, &SystemCaller::readTcp);
|
||||
connect(socket, &QTcpSocket::disconnected, this, &SystemCaller::tcpDisconnected);
|
||||
m_sockets.append(socket);
|
||||
|
||||
NOTICE_LOG(m_logger) << "New TCP-connection on port " << m_tcpServer->serverPort();
|
||||
}
|
||||
}
|
||||
|
||||
void SystemCaller::readTcp()
|
||||
{
|
||||
QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
|
||||
if (!socket)
|
||||
return;
|
||||
|
||||
QByteArray ba = socket->readAll();
|
||||
qint64 time = ba.toLongLong();
|
||||
DEBUG_LOG(m_logger) << "New Time " << time;
|
||||
|
||||
QDateTime newDateTime = QDateTime::fromSecsSinceEpoch(time);
|
||||
|
||||
if (newDateTime.isValid())
|
||||
{
|
||||
#ifndef WIN32
|
||||
//linux
|
||||
QString string = newDateTime.toString(QStringLiteral("\"yyyy-MM-dd hh:mm:ss\""));
|
||||
QString dateTimeString(QStringLiteral("date --set="));
|
||||
dateTimeString.append(string);
|
||||
int systemDateTimeStatus = system(dateTimeString.toStdString().c_str());
|
||||
if (systemDateTimeStatus == -1)
|
||||
WARNING_LOG(m_logger) << "Failed to change date time";
|
||||
int systemHwClockStatus = system("/sbin/hwclock -w");
|
||||
if (systemHwClockStatus == -1)
|
||||
WARNING_LOG(m_logger) << "Failed to sync hardware clock";
|
||||
#else
|
||||
QString dateString = newDateTime.toString(QStringLiteral("dd-MM-yy"));
|
||||
QString timeString = newDateTime.toString(QStringLiteral("hh:mm:ss"));
|
||||
QString systemDateString(QStringLiteral("date "));
|
||||
QString systemTimeString(QStringLiteral("time "));
|
||||
systemDateString.append(dateString);
|
||||
systemTimeString.append(timeString);
|
||||
int systemDateStatus = system(systemDateString.toLocal8Bit().data());
|
||||
if (systemDateStatus == -1)
|
||||
WARNING_LOG(m_logger) << "Failed to change date";
|
||||
int systemTimeStatus = system(systemTimeString.toLocal8Bit().data());
|
||||
if (systemTimeStatus == -1)
|
||||
WARNING_LOG(m_logger) << "Failed to change date";
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void SystemCaller::tcpDisconnected()
|
||||
{
|
||||
QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
|
||||
m_sockets.removeOne(socket);
|
||||
}
|
||||
|
||||
void SystemCaller::handleTcpError(QAbstractSocket::SocketError error)
|
||||
{
|
||||
Q_UNUSED(error)
|
||||
//TODO: TCP-Socket Error handling
|
||||
}
|
||||
|
||||
} //namespace DateTimeSyncer
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* SystemCaller to set Time and Date
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, NLE, 07-03-2019
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QTcpSocket>
|
||||
#include <QThread>
|
||||
|
||||
#include "tcp_server.h"
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace DateTimeSyncer
|
||||
{
|
||||
|
||||
class SystemCaller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SystemCaller(QObject *parent = nullptr);
|
||||
~SystemCaller();
|
||||
|
||||
bool init(int tcpPort);
|
||||
|
||||
private slots:
|
||||
// tcp
|
||||
void newConnection();
|
||||
void readTcp();
|
||||
void tcpDisconnected();
|
||||
void handleTcpError(QAbstractSocket::SocketError error);
|
||||
|
||||
private:
|
||||
TcpServer *m_tcpServer;
|
||||
QVector<QTcpSocket *> m_sockets;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
|
||||
} //namespace DateTimeSyncer
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* TCP server
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, NLT, 30-11-2018
|
||||
*/
|
||||
|
||||
#include "tcp_server.h"
|
||||
|
||||
namespace DateTimeSyncer
|
||||
{
|
||||
|
||||
TcpServer::TcpServer(QObject *parent)
|
||||
: QTcpServer(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TcpServer::~TcpServer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} //namespace DateTimeSyncer
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* TCP server
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, NLT, 30-11-2018
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QTcpServer>
|
||||
|
||||
namespace DateTimeSyncer
|
||||
{
|
||||
|
||||
class TcpServer : public QTcpServer
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TcpServer(QObject *parent = nullptr);
|
||||
~TcpServer();
|
||||
};
|
||||
|
||||
} //namespace DateTimeSyncer
|
||||
Reference in new issue
Block a user