Commit 3d9ae677 authored by Dorian Zedler's avatar Dorian Zedler

- pairing usb extensions now requires the command 5002 to be sent

- setting the system time is now supported
parent d5c7460b
......@@ -21,7 +21,6 @@ public:
private:
QSerialPort * serialPort;
QTimer * writeTimer;
QByteArray readBuffer;
QString lastWriteReply;
......
......@@ -307,6 +307,16 @@
"desc": "long string containing the version, new binary as base64 and an official signature of Itsblue Development",
"def": "<VER>major.minor.patch</VER><BIN>###updated binary as base64###</BIN>-SIGN-###signature###-SIGN-"
}
},
"5001": {
"desc": "update time",
"requestData": {
"type": "int",
"dev": "currentSecsSinceEpoch = UNIX timestamp"
}
},
"5002": {
"desc": "pair all extensions, that are currently connected via usb"
}
},
......
......@@ -726,6 +726,8 @@ void MainActivity::handleSocketCommand(SocketServer::socketClient *socketClient,
}
case 5000: {
// firmware update
if(this->state != IDLE){
replyHeader = 900;
break;
......@@ -799,8 +801,48 @@ void MainActivity::handleSocketCommand(SocketServer::socketClient *socketClient,
return;
}
case 5001: {
// update system time
if(requestData.toInt() < 1546300800) {
replyHeader = 406;
break;
}
QProcess timeSetProcess;
// set the system time
QString timeCommand = "sudo date +%s -s @" + QString::number(requestData.toInt());
timeSetProcess.start(timeCommand);
timeSetProcess.waitForFinished();
if(timeSetProcess.exitStatus() != QProcess::NormalExit) {
replyHeader = 500;
break;
}
// set the hardwareclock
timeCommand = "sudo hwclock -w";
timeSetProcess.start(timeCommand);
timeSetProcess.waitForFinished();
if(timeSetProcess.exitStatus() != QProcess::NormalExit) {
replyHeader = 500;
break;
}
replyHeader = 200;
break;
}
case 5002: {
// pair connected extensions
this->serialHandler->updateESPs();
replyHeader = 200;
break;
}
default:
// not found
replyHeader = 404;
break;
}
......
......@@ -3,9 +3,6 @@
SerialHandler::SerialHandler(QObject *parent) : QObject(parent)
{
this->serialPort = new QSerialPort(this);
this->writeTimer = new QTimer(this);
this->updateESPs();
}
void SerialHandler::updateESPs()
......@@ -28,8 +25,6 @@ void SerialHandler::updateESPs()
this->closeConnectionToPort();
}
}
writeTimer->singleShot(10000, this, &SerialHandler::updateESPs);
}
bool SerialHandler::connectToPort(QString portName, qint32 baudRate) {
......@@ -46,7 +41,6 @@ bool SerialHandler::connectToPort(QString portName, qint32 baudRate) {
if(serialPort->open(QSerialPort::ReadWrite)) {
serialPort->setDataTerminalReady(true);
serialPort->setRequestToSend(true);
writeTimer->start();
return true;
}
else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment