move build system to cmake, add train overlord
This commit is contained in:
75
src/trainOverlord/trainoverlord.cpp
Normal file
75
src/trainOverlord/trainoverlord.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QIODevice>
|
||||
#include <QTcpSocket>
|
||||
#include <iostream>
|
||||
|
||||
#include "microcontroller.h"
|
||||
#include "nfcuid.h"
|
||||
#include "overlorditemstore.h"
|
||||
#include "train.h"
|
||||
#include "turnout.h"
|
||||
#include "signal.h"
|
||||
|
||||
void gotTag(NfcUid uid)
|
||||
{
|
||||
std::cout<<"Got tag from "<<uid.reader<<" uid ";
|
||||
for(size_t i = 0; i < uid.length; ++i)
|
||||
{
|
||||
std::cout<<(int)uid.bytes[i]<<(i == uid.length-1 ? "" : ":");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
//set info
|
||||
QCoreApplication::setOrganizationName("UVOS");
|
||||
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
||||
QCoreApplication::setApplicationName("TrainOverlord");
|
||||
QCoreApplication::setApplicationVersion("0.1");
|
||||
|
||||
//parse comand line
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("Train control application");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main",
|
||||
"Set server host ip addres"), "adress");
|
||||
parser.addOption(hostOption);
|
||||
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main",
|
||||
"Set server Port in TCP mode or Serial port in serial mode"), "port");
|
||||
parser.addOption(portOption);
|
||||
parser.process(a);
|
||||
|
||||
QTcpSocket microSocket;
|
||||
|
||||
int port = 6856;
|
||||
if(parser.isSet(portOption))
|
||||
port = parser.value(portOption).toInt();
|
||||
|
||||
QString host("127.0.0.1");
|
||||
if(parser.isSet(hostOption)) host = parser.value(hostOption);
|
||||
std::cout<<"connecting to "<<host.toStdString()<<':'<<port<<'\n';
|
||||
microSocket.connectToHost(host, port, QIODevice::ReadWrite);
|
||||
if(!microSocket.waitForConnected(3000))
|
||||
{
|
||||
std::cout<<"Can not connect to to Server.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
OverlordItemStore items;
|
||||
|
||||
Microcontroller micro(µSocket);
|
||||
QObject::connect(µ, &Microcontroller::gotTag, gotTag);
|
||||
QObject::connect(µ, &Microcontroller::gotTag, &items, &OverlordItemStore::gotNfcTag);
|
||||
QObject::connect(µ, &Microcontroller::gotItemList, &items, &OverlordItemStore::addItems);
|
||||
QObject::connect(µ, &Microcontroller::itemChanged, &items, &OverlordItemStore::itemStateChanged);
|
||||
|
||||
Train::micro = µ
|
||||
Turnout::micro = µ
|
||||
Signal::micro = µ
|
||||
|
||||
return a.exec();
|
||||
}
|
Reference in New Issue
Block a user