Add some debugging output when pairing.

This commit is contained in:
Andrius Štikonas 2016-03-14 00:35:40 +00:00
parent 504a700b80
commit cd52a6063e
2 changed files with 14 additions and 6 deletions

View File

@ -62,7 +62,7 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
for (auto & x : nc) {
if (x.bearerType() == QNetworkConfiguration::BearerWLAN) {
if (x.name() == "WiWo-S20") {
qWarning() << "Connecting to WiWo-S20 wireless";
qDebug() << "Connecting to WiWo-S20 wireless";
cfg = &x;
stop = true;
}
@ -72,9 +72,9 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
QNetworkSession *session = new QNetworkSession(*cfg, this);
session->open();
qWarning() << "Wait for connected!";
qDebug() << "Wait for connected!";
if (session->waitForOpened())
qWarning() << "Connected!";
qDebug() << "Connected!";
QUdpSocket *udpSocketSend = new QUdpSocket();
udpSocketGet = new QUdpSocket();
@ -82,20 +82,27 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
QByteArray reply;
qDebug() << "Send: HF-A11ASSISTHREAD";
udpSocketGet->writeDatagram(QByteArray::fromStdString("HF-A11ASSISTHREAD"), QHostAddress::Broadcast, port);
reply = listen(QByteArray::fromStdString("HF-A11ASSISTHREAD"));
QList<QByteArray> list = reply.split(',');
QHostAddress ip(QString::fromLatin1(list[0]));
qWarning() << "IP: " << ip.toString();
qDebug() << "IP: " << ip.toString();
qDebug() << "Send: +ok";
udpSocketGet->writeDatagram(QByteArray::fromStdString("+ok"), ip, port);
qDebug() << "Send: AT+WSSSID=" + QString::fromLatin1(ssid) + "\r";
udpSocketGet->writeDatagram(QByteArray::fromStdString("AT+WSSSID=") + ssid + QByteArray::fromStdString("\r"), ip, port);
listen();
qDebug() << "Send: AT+WSKEY=WPA2PSK,AES," + QString::fromLatin1(password) + "\r";
udpSocketGet->writeDatagram(QByteArray::fromStdString("AT+WSKEY=WPA2PSK,AES,") + password + QByteArray::fromStdString("\r"), ip, port); // FIXME: support different security settings
// OPEN, SHARED, WPAPSK......NONE, WEP, TKIP, AES
listen();
qDebug() << "Send: AT+WMODE=STA\\r";
udpSocketGet->writeDatagram(QByteArray::fromStdString("AT+WMODE=STA\r"), ip, port);
listen();
qDebug() << "Send: AT+Z\\r";
udpSocketGet->writeDatagram(QByteArray::fromStdString("AT+Z\r"), ip, port); // reboot
listen();
session->close();
// FIXME: discover the new socket
qWarning() << "Finished";
@ -122,6 +129,7 @@ QByteArray Server::listen(QByteArray message)
while (udpSocketGet->hasPendingDatagrams()) {
reply.resize(udpSocketGet->pendingDatagramSize());
udpSocketGet->readDatagram(reply.data(), reply.size(), &sender, &senderPort);
qDebug() << "Reply: " << QString::fromLatin1(reply.data());
if (reply != message) {
stop = true;
}

View File

@ -35,7 +35,7 @@ Socket::Socket(QHostAddress IPaddress, QByteArray reply)
commandID[QueryAll] = QStringLiteral("qa").toLatin1();
commandID[Discover] = QStringLiteral("qg").toLatin1(); // qg
commandID[Subscribe] = QStringLiteral("cl").toLatin1(); // Login Command
commandID[Subscribe] = QStringLiteral("cl").toLatin1(); // Claim
commandID[PowerOn] = QStringLiteral("sf").toLatin1(); // State Flip (change of power state)
commandID[PowerOff] = commandID[PowerOn];
commandID[ReadTable] = QStringLiteral("rt").toLatin1();
@ -49,7 +49,7 @@ Socket::Socket(QHostAddress IPaddress, QByteArray reply)
datagram[Subscribe] = commandID[Subscribe] + mac + twenties + rmac + twenties;
datagram[PowerOn] = commandIDPower + mac + twenties + zeros + one;
datagram[PowerOff] = commandIDPower + mac + twenties + zeros + zero;
datagram[ReadTable] = commandID[ReadTable] + mac + twenties + /*zeros*/QByteArray::fromHex("72 00 00 00") + QByteArray::fromHex("01 00 00") + zeros;
datagram[ReadTable] = commandID[ReadTable] + mac + twenties + /*zeros*/QByteArray::fromHex("00 00 00 00") /*cookie*/ + QByteArray::fromHex("01 00") + zero + zeros;
udpSocket = new QUdpSocket();
udpSocket->connectToHost(ip, 10000);