Password changing and displaying of the timezone.

This commit is contained in:
Andrius Štikonas 2015-02-15 12:31:21 +00:00
parent 742ea64c83
commit 802f910809
3 changed files with 48 additions and 9 deletions

View File

@ -62,6 +62,14 @@ void ConsoleReader::run()
case 'p':
(*sockets) [number]->toggle();
break;
case 'P':
{
std::string password;
std::cout << "Please enter a new password: ";
std::cin >> password;
(*sockets) [number]->changeSocketPassword(QString::fromStdString(password));
break;
}
case 'q':
cont = false;
emit ( QCoreApplication::quit() );
@ -71,6 +79,14 @@ void ConsoleReader::run()
--number; // count from 0
listSockets();
break;
case 't':
{
int timezone;
std::cout << "Please enter a new timezone (integer from -11 to 12): ";
std::cin >> timezone;
(*sockets) [number]->changeTimezone(timezone);
break;
}
default:
std::cout << "Invalid command: try again" << std::endl;
}
@ -81,11 +97,12 @@ void ConsoleReader::listSockets()
{
for ( std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i )
{
std::cout << "___________________________________________________________________________\n" << std::endl;
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)->name.toStdString() << "\t Remote Password: " << (*i)->remotePassword.toStdString() << std::endl;
std::cout << "Socket Name: " << (*i)->socketName.toStdString() << "\t Remote Password: " << (*i)->remotePassword.toStdString() << "\t Timezone: " << (*i)->timeZone.toHex().toStdString() << std::endl;
}
std::cout << "___________________________________________________________________________\n" << std::endl;
std::cout << "d - update table data\nn - change socket name (max 16 characters)\ns - pick another socket (default is 1)\np - toggle power state\nq - quit" << std::endl;
std::cout << "_____________________________________________________________________________\n" << std::endl;
std::cout << "d - update table data\nn - change socket name (max 16 characters)\np - toggle power state\nP - change remote password (max 12 characters)\n";
std::cout << "q - quit\ns - pick another socket (default is 1)\nt - change timezone" << std::endl;
std::cout << "Enter command: " << std::flush;
}

View File

@ -94,13 +94,32 @@ void Socket::toggle()
void Socket::changeSocketName ( QString newName )
{
QByteArray name = newName.toLatin1().leftJustified(16, ' ', true);
writeSocketData(name, remotePassword, timeZone);
}
QByteArray record = QByteArray::fromHex ( "01:00" ) /* record number = 1*/ + versionID + mac + twenties + rmac + twenties + remotePassword + name + icon + hardwareVersion + firmwareVersion + wifiFirmwareVersion + port + staticServerIP + port + QStringLiteral("vicenter.orvibo.com ").toLatin1() + twenties + twenties + twenties + localIP + localGatewayIP + localNetMask + dhcpNode + discoverable + timeZoneSet + timeZone + QByteArray::fromHex ( "00:ff" ) + countdown;
void Socket::changeSocketPassword ( QString newPassword )
{
QByteArray password = newPassword.toLatin1().leftJustified(12, ' ', true);
writeSocketData(socketName, password, timeZone);
}
void Socket::changeTimezone ( int8_t newTimezone )
{
QByteArray timezone;
QDataStream stream(&timezone, QIODevice::WriteOnly);
stream.setByteOrder(QDataStream::BigEndian);
stream << newTimezone;
writeSocketData(socketName, remotePassword, timezone);
}
void Socket::writeSocketData(QByteArray name, QByteArray password, QByteArray timezone)
{
QByteArray record = QByteArray::fromHex ( "01:00" ) /* record number = 1*/ + versionID + mac + twenties + rmac + twenties + password + name + icon + hardwareVersion + firmwareVersion + wifiFirmwareVersion + port + staticServerIP + port + QStringLiteral("vicenter.orvibo.com ").toLatin1() + twenties + twenties + twenties + localIP + localGatewayIP + localNetMask + dhcpNode + discoverable + timeZoneSet + timezone + QByteArray::fromHex ( "00:ff" ) + countdown;
QByteArray recordLength;
QDataStream stream(&recordLength, QIODevice::WriteOnly);
stream.setByteOrder(QDataStream::LittleEndian);
quint16 length = record.length();
uint16_t length = record.length();
stream << length;
datagram[WriteSocketData] = magicKey + QByteArray::fromHex ( "00 a5" ) + commandID[WriteSocketData] + mac + twenties + zeros + QByteArray::fromHex ( "04:00:01" ) /*table number and unknown*/ + recordLength + record;
@ -174,7 +193,7 @@ bool Socket::parseReply ( QByteArray reply )
index += 12; // length of rmac + padding
remotePassword = reply.mid ( index, 12 ); // max 12 symbols
index += 12;
name = reply.mid ( index, 16 ); // max 16 symbols
socketName = reply.mid ( index, 16 ); // max 16 symbols
index += 16;
icon = reply.mid ( index, 2 );
index += 2;

View File

@ -42,12 +42,15 @@ public:
void toggle();
void tableData();
void changeSocketName ( QString newName );
void changeSocketPassword ( QString newPassword );
void changeTimezone ( int8_t newTimezone );
bool parseReply ( QByteArray );
QHostAddress ip;
QByteArray mac;
bool powered;
QByteArray name, remotePassword;
QByteArray socketName, remotePassword;
QByteArray timeZone;
private:
enum Datagram {Subscribe, PowerOff, PowerOn, TableData, SocketData, TimingData, WriteSocketData, MaxCommands};
@ -56,6 +59,7 @@ private:
void subscribe();
void listen() { start(); }
void run();
void writeSocketData (QByteArray name, QByteArray password, QByteArray timezone);
QByteArray commandID[MaxCommands];
QByteArray datagram[MaxCommands];
@ -73,7 +77,6 @@ private:
QByteArray dhcpNode;
QByteArray discoverable;
QByteArray timeZoneSet;
QByteArray timeZone;
QByteArray countdown;
QByteArray socketTableNumber, socketTableVersion, timingTableNumber, timingTableVersion; // FIXME: not used yet