const char * WiFlyDevice::getIp(boolean pauseRequired) { static char ip[16] = ""; byte offset = 0; if (enterCommandMode(pauseRequired) && sendCommand("get ip", "IP=")) { while (offset < 15) { char character = uart.read(); LOG_READ(character); if (character == ':') { ip[offset] = '\x00'; break; } else if (character != -1) { ip[offset] = character; offset++; } } } ip[offset] = '\x00'; waitForPrompt(); exitCommandMode(); return ip; }
GdbProcess(const QString &program) : QProcess() { setProcessChannelMode(MergedChannels); // don't attempt to load .gdbinit in home (may cause unexpected results) QProcess::start("gdb", (QStringList() << "-nx" << (BINARY_PATH + '/' + program))); const bool started = waitForStarted(); if (!started) { qDebug() << "Failed to start 'gdb' executable:" << errorString(); Q_ASSERT(false); return; } QByteArray prompt = waitForPrompt(); QVERIFY(!prompt.contains("No such file or directory")); execute("set confirm off"); execute("set print pretty on"); execute("set disable-randomization off"); // see https://phabricator.kde.org/D2188 QList<QByteArray> p; QDir printersDir = QFileInfo(__FILE__).dir(); printersDir.cdUp(); // go up to get to the main printers directory p << "python" << "import sys" << "sys.path.insert(0, '"+printersDir.path().toLatin1()+"')" << "from qt import register_qt_printers" << "register_qt_printers (None)" << "from kde import register_kde_printers" << "register_kde_printers (None)" << "end"; foreach (const QByteArray &i, p) { write(i + "\n"); }
void WiFlyDevice::leave() { if (!enterCommandMode()) return; if (!sendCommand("leave")) return; waitForPrompt(); }
boolean WiFlyDevice::join(const char * ssid) { if (!enterCommandMode()) return false; sendCommandPart("join "); if (sendCommand(ssid, "Associated!", 30000)) { waitForPrompt(); return true; } return false; }
boolean WiFlyDevice::join(const char * ssid, const char * passphrase, boolean isWPA) { if (!enterCommandMode()) return false; sendCommandPart("set wlan "); if (isWPA) sendCommandPart("passphrase "); else sendCommandPart("key "); sendCommand(passphrase); waitForPrompt(); sendCommandPart("join "); if (sendCommand(ssid, "Associated!", 30000)) { waitForPrompt(); return true; } return false; }
WiFlyDevice::Status WiFlyDevice::getStatus(boolean pauseRequired) { if (!enterCommandMode(pauseRequired) || !sendCommand("show c", "8")) { waitForPrompt(); exitCommandMode(); return StatusError; } char result[3] = {0, 0, 0}; for (int i=0; i<3;) { result[i] = uart.read(); LOG_READ(result[i]); if (result[i] <= 0 || result[i] > 128) continue; i++; } Status status; if (strchr("02468ACEace", result[1])) status = StatusNotAssociated; else if (result[2] == '3') status = StatusNoIp; else if (result[2] == '4') status = StatusConnecting; else if (result[2] == '1') status = StatusConnected; else status = StatusDisconnected; waitForPrompt(); exitCommandMode(); return status; }
void WiFlyDevice::begin() { uart.begin(); reboot(); enterCommandMode(false); sendCommand("get uart", "Flow=0x"); while (!uart.available()) { //delay(1); } char flowControlState = uart.read(); LOG_READ(flowControlState); waitForPrompt(); if (flowControlState != '1') { sendCommand("set uart flow 1"); waitForPrompt(); sendCommand("save", "Storing in config"); waitForPrompt(); sendCommand("get uart", "Flow=0x1"); waitForPrompt(); reboot(); enterCommandMode(false); } sendCommand("set wlan join 0"); waitForPrompt(); sendCommandPart("set ip localport "); sendCommandPart(serverPort); sendCommand(""); waitForPrompt(); sendCommand("set comm remote 0"); waitForPrompt(); }
boolean WiFlyDevice::enterCommandMode(boolean pauseRequired) { if (inCommandMode) return true; for (int retryCount = 0; retryCount < RETRY_ATTEMPTS; retryCount++) { if (pauseRequired) delay(250); sendCommandPart("$$$"); delay(250); sendCommand("", ""); sendCommand("", ""); if (waitForPrompt()) { inCommandMode = true; return true; } } return false; }
QByteArray execute(const QByteArray &cmd) { write(cmd + "\n"); return waitForPrompt(); }