diff --git a/consolereader.cpp b/consolereader.cpp index ca2d1b4..ac9d5ba 100644 --- a/consolereader.cpp +++ b/consolereader.cpp @@ -57,15 +57,6 @@ void ConsoleReader::run() broadcastPassword(QString::fromStdString(password)); // HF-LPB100 chip can be controlled over port 49999 break; } - case 'c': - uint16_t countdown; - std::cout << "Countdown time in seconds: "; - std::cin >> countdown; - (*sockets) [activeSocket]->setCountDown(countdown); - break; - case 'C': - (*sockets) [activeSocket]->toggleCountDown(); - break; case 'd': (*sockets) [activeSocket]->tableData(); break; @@ -87,6 +78,15 @@ void ConsoleReader::run() (*sockets) [activeSocket]->powerOff(); else if (command == "on") (*sockets) [activeSocket]->powerOn(); + else { + uint16_t offTime; + std::cout << "Off time in seconds: "; + std::cin >> offTime; + (*sockets) [activeSocket]->setOffTimer(offTime); + } + break; + case 'O': + (*sockets) [activeSocket]->toggleOffTimer(); break; case 'P': { std::string password; @@ -126,7 +126,7 @@ void ConsoleReader::listSockets() std::cout << "_____________________________________________________________________________\n" << std::endl; std::cout << "IP Address: " << (*i)->ip.toString().toStdString() << "\t MAC Address: " << (*i)->mac.toHex().toStdString() << "\t Power: " << ((*i)->powered ? "On" : "Off") << std::endl; std::cout << "Socket Name: " << (*i)->socketName.toStdString() << "\t Remote Password: " << (*i)->remotePassword.toStdString() << "\t Timezone: " << +(*i)->timezone << std::endl; - std::cout << "Countdown: " << (*i)->countdown << " " << ((*i)->countdownEnabled ? "(enabled)" : "(disabled)") << "\t\t Time: " << (*i)->socketDateTime.toString().toStdString() << std::endl; + std::cout << "Off timer: " << (*i)->offTime << " " << ((*i)->offTimerEnabled ? "(enabled)" : "(disabled)") << "\t\t Time: " << (*i)->socketDateTime.toString().toStdString() << std::endl; } std::cout << "_____________________________________________________________________________\n" << std::endl; if (sockets->size() > 0) { @@ -134,13 +134,14 @@ void ConsoleReader::listSockets() } std::cout << "a - add unpaired socket (WiFi needed)\n"; std::cout << "A - add unpaired socket (no WiFi needed)\n"; - std::cout << "c - set countdown\n"; - std::cout << "C - enable/disable countdown\n"; std::cout << "d - update table data\n"; std::cout << "D - resend discovery packet to the current socket\n"; std::cout << "n - change socket name (max 16 characters)\n"; + std::cout << "o - set switch off timer\n"; + std::cout << "O - enable/disable switch off timer\n"; std::cout << "p - toggle power state (there are also \"on\" and \"off\" commands)\n"; - std::cout << "P - change remote password (max 12 characters)\nq - quit\ns - select another socket (default is 1)\nt - change timezone" << std::endl; + std::cout << "P - change remote password (max 12 characters)\nq - quit\ns - select another socket (default is 1)\n"; + std::cout << "t - change timezone" << std::endl; std::cout << "Enter command: " << std::endl; } diff --git a/socket.cpp b/socket.cpp index cdfdeb3..f4c9ce1 100644 --- a/socket.cpp +++ b/socket.cpp @@ -138,36 +138,34 @@ void Socket::powerOn() void Socket::changeSocketName(QString newName) { QByteArray name = newName.toLatin1().leftJustified(16, ' ', true); - writeSocketData(name, remotePassword, timezone, countdown); + writeSocketData(name, remotePassword, timezone, offTime); } void Socket::changeSocketPassword(QString newPassword) { QByteArray password = newPassword.toLatin1().leftJustified(12, ' ', true); - writeSocketData(socketName, password, timezone, countdown); + writeSocketData(socketName, password, timezone, offTime); } void Socket::changeTimezone(int8_t newTimezone) { - writeSocketData(socketName, remotePassword, newTimezone, countdown); + writeSocketData(socketName, remotePassword, newTimezone, offTime); } -void Socket::setCountDown(uint16_t countdown) +void Socket::setOffTimer(uint16_t offTime) { - writeSocketData(socketName, remotePassword, timezone, countdown); + writeSocketData(socketName, remotePassword, timezone, offTime); } -void Socket::toggleCountDown() +void Socket::toggleOffTimer() { - countdownEnabled=!countdownEnabled; - writeSocketData(socketName, remotePassword, timezone, countdown); + offTimerEnabled=!offTimerEnabled; + writeSocketData(socketName, remotePassword, timezone, offTime); } -void Socket::writeSocketData(QByteArray socketName, QByteArray remotePassword, int8_t timezone, uint16_t countdown) +void Socket::writeSocketData(QByteArray socketName, QByteArray remotePassword, int8_t timezone, uint16_t offTime) { - QByteArray countDown = intToHex(countdown, 2); // 2 bytes - - QByteArray record = QByteArray::fromHex("01:00") /* record number = 1*/ + versionID + mac + twenties + rmac + twenties + remotePassword + socketName + icon + hardwareVersion + firmwareVersion + wifiFirmwareVersion + port + staticServerIP + port + domainServerName + localIP + localGatewayIP + localNetMask + dhcpNode + discoverable + timeZoneSet + intToHex(timezone, 1) + (countdownEnabled ? QByteArray::fromHex("01:00") : QByteArray::fromHex("00:ff")) + countDown + zeros + zeros + zeros + QStringLiteral("000000000000000000000000000000").toLocal8Bit(); + QByteArray record = QByteArray::fromHex("01:00") /* record number = 1*/ + versionID + mac + twenties + rmac + twenties + remotePassword + socketName + icon + hardwareVersion + firmwareVersion + wifiFirmwareVersion + port + staticServerIP + port + domainServerName + localIP + localGatewayIP + localNetMask + dhcpNode + discoverable + timeZoneSet + intToHex(timezone, 1) + (offTimerEnabled ? QByteArray::fromHex("01:00") : QByteArray::fromHex("00:ff")) + intToHex(offTime, 2) + zeros + zeros + zeros + QStringLiteral("000000000000000000000000000000").toLocal8Bit(); QByteArray recordLength = intToHex(record.length(), 2); // 2 bytes @@ -274,9 +272,9 @@ bool Socket::parseReply(QByteArray reply) timezone = hexToInt(reply.mid(index, 1)); socketDateTime = socketDateTime.addSecs(timezone *3600); ++index; - countdownEnabled = reply.mid(index, 2) == QByteArray::fromHex("01:00"); + offTimerEnabled = reply.mid(index, 2) == QByteArray::fromHex("01:00"); index += 2; - countdown = hexToInt(reply.mid(index, 2)); + offTime = hexToInt(reply.mid(index, 2)); Q_EMIT stateChanged(); break; } diff --git a/socket.h b/socket.h index 0a0b48d..b44d8fc 100644 --- a/socket.h +++ b/socket.h @@ -48,8 +48,8 @@ public: void changeSocketName(QString newName); void changeSocketPassword(QString newPassword); void changeTimezone(int8_t newTimezone); - void setCountDown(uint16_t countdown); - void toggleCountDown(); + void setOffTimer(uint16_t offTime); + void toggleOffTimer(); bool parseReply(QByteArray); QHostAddress ip; @@ -57,8 +57,8 @@ public: bool powered; QByteArray socketName, remotePassword; int8_t timezone; - uint16_t countdown; - bool countdownEnabled; + uint16_t offTime; + bool offTimerEnabled; QDateTime socketDateTime; private: @@ -81,7 +81,7 @@ private: start(); } void run(); - void writeSocketData(QByteArray socketName, QByteArray remotePassword, int8_t timeZone, uint16_t countdown); + void writeSocketData(QByteArray socketName, QByteArray remotePassword, int8_t timeZone, uint16_t offTime); QByteArray intToHex(unsigned int value, unsigned int length, bool littleEndian = true); int hexToInt(QByteArray value, bool littleEndian = true);