Restore ability to set a different ssid.

Add on and off commands.
This commit is contained in:
Andrius Štikonas 2015-05-26 00:02:19 +01:00
parent df5cc31355
commit de16fea254
6 changed files with 35 additions and 6 deletions

View File

@ -43,10 +43,12 @@ void ConsoleReader::run()
case 'a': case 'a':
{ {
std::cout << "Please set your Orvibo socket to pair mode (rapidly blinking blue light) and wait until new wifi network (WiWo-S20) appears" << std::endl; std::cout << "Please set your Orvibo socket to pair mode (rapidly blinking blue light) and wait until new wifi network (WiWo-S20) appears" << std::endl;
std::string password; std::string ssid, password;
std::cout << "Wireless name (\"c\" for current wifi): ";
std::cin >> ssid;
std::cout << "Password: "; std::cout << "Password: ";
std::cin >> password; std::cin >> password;
Server *server = new Server(48899, QByteArray::fromStdString(password)); // HF-LPB100 chip can be controlled over port 48899 Server *server = new Server(48899, QByteArray::fromStdString(ssid), QByteArray::fromStdString(password)); // HF-LPB100 chip can be controlled over port 48899
break; break;
} }
case 'A': case 'A':
@ -75,6 +77,12 @@ void ConsoleReader::run()
case 'p': case 'p':
(*sockets) [number]->toggle(); (*sockets) [number]->toggle();
break; break;
case 'o':
if (command == "off")
(*sockets) [number]->powerOff();
else if (command == "on")
(*sockets) [number]->powerOn();
break;
case 'P': case 'P':
{ {
std::string password; std::string password;

View File

@ -1,4 +1,4 @@
SOURCES = consolereader.cpp main.cpp server.cpp socket.cpp SOURCES = consolereader.cpp main.cpp server.cpp socket.cpp
HEADERS = consolereader.h server.h socket.h HEADERS = consolereader.h server.h socket.h
QT += network QT += network
CONFIG += c++11 CONFIG += console c++11

View File

@ -40,14 +40,19 @@ Server::Server ( std::vector<Socket*> *sockets_vector )
start(); start();
} }
Server::Server(uint16_t port, QByteArray password) Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
{ {
QNetworkConfiguration *cfgInitial = new QNetworkConfiguration; QNetworkConfiguration *cfgInitial = new QNetworkConfiguration;
QNetworkConfiguration *cfg = new QNetworkConfiguration; QNetworkConfiguration *cfg = new QNetworkConfiguration;
QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager; QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
ncm->updateConfigurations(); ncm->updateConfigurations();
*cfgInitial = ncm->defaultConfiguration(); *cfgInitial = ncm->defaultConfiguration();
QByteArray ssid = cfgInitial->name().toLocal8Bit();
if (ssid == "c")
{
ssid = cfgInitial->name().toLocal8Bit();
qDebug() << "SSID unspecified, using current network: " << ssid;
}
bool stop = false; bool stop = false;
while ( !stop ) while ( !stop )

View File

@ -30,7 +30,7 @@ Q_OBJECT
public: public:
Server ( std::vector<Socket*> *sockets_vector ); Server ( std::vector<Socket*> *sockets_vector );
Server ( uint16_t port, QByteArray password ); Server ( uint16_t port, QByteArray ssid, QByteArray password );
~Server(); ~Server();
void discoverSockets(); void discoverSockets();

View File

@ -127,6 +127,20 @@ void Socket::toggle()
sendDatagram ( powered ? PowerOff : PowerOn ); sendDatagram ( powered ? PowerOff : PowerOn );
} }
void Socket::powerOff()
{
if (powered)
sendDatagram ( PowerOff );
Q_EMIT stateChanged();
}
void Socket::powerOn()
{
if (!powered)
sendDatagram ( PowerOn );
Q_EMIT stateChanged();
}
void Socket::changeSocketName ( QString newName ) void Socket::changeSocketName ( QString newName )
{ {
QByteArray name = newName.toLatin1().leftJustified(16, ' ', true); QByteArray name = newName.toLatin1().leftJustified(16, ' ', true);

View File

@ -41,6 +41,8 @@ public:
Socket ( QHostAddress, QByteArray ); // from discovery packet Socket ( QHostAddress, QByteArray ); // from discovery packet
~Socket(); ~Socket();
void toggle(); void toggle();
void powerOff();
void powerOn();
void discover(); void discover();
void tableData(); void tableData();
void changeSocketName ( QString newName ); void changeSocketName ( QString newName );