void InterfaceSerial::parse() { QByteArray receptionTmp; int a = port->bytesAvailable(); receptionTmp.resize(a); port->read(receptionTmp.data(), receptionTmp.size()); if(enable) { reception.append(receptionTmp); bool nextMessage = true; while(nextMessage) { nextMessage = false; quint16 index = 0; QString command; while((index < reception.size()) && (!nextMessage)) { if(reception.at(index) == COMMAND_END_BYTE) { reception = reception.remove(0, index); index = 0; command = command.remove('\n'); command = command.remove('\r'); if(command != "") MessageManager::incomingMessage(MessageIncomming("serial", portName, 0, "", command, command.split(" ", QString::SkipEmptyParts))); command = ""; } else command += reception.at(index); index++; } } } }
void InterfaceHttp::parseRequest(QNetworkReply *reply) { if(!enable) return; QStringList commandItems = QString(reply->readAll()).split(COMMAND_END, QString::SkipEmptyParts);; foreach(const QString & command, commandItems) MessageManager::incomingMessage(MessageIncomming("http", reply->url().host(), reply->url().port(), reply->url().path(), command, command.split(" ", QString::SkipEmptyParts))); }
void InterfaceHttp::webSocketsProcessMessage(const QString &message) { WebSocket *webSocket = qobject_cast<WebSocket *>(sender()); if(webSocket) { QStringList commandItems = message.split(COMMAND_END, QString::SkipEmptyParts);; QString response; foreach(const QString & command, commandItems) response += MessageManager::incomingMessage(MessageIncomming("http", webSocket->peerAddress().toString(), webSocket->peerPort(), "", command, command.split(" ", QString::SkipEmptyParts)), true, (command != "goto")); if(!response.isEmpty()) webSocket->send(response); } }
void InterfaceHttp::parseSocket(QTcpSocket *socket) { if(!enable) return; QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*")); if((tokens.count() > 1) && (tokens.at(0) == "GET")) { QUrl url(tokens.at(1)); QList<QString> commands; QPair<QString,qint8> picFormat; picFormat.first = "png"; picFormat.second = -1; bool isPic = false, isSync = false; #ifdef QT4 for(quint16 index = 0 ; index < url.queryItems().count() ; index++) { QString first = url.queryItems().at(index).first.toLower(); if((first == "png") || (first == "jpg") || (first == "mjpg")) { isPic = true; picFormat.first = first; picFormat.second = url.queryItems().at(index).second.toInt(); } else if(first == "sync") isSync = true; else commands.append(url.queryItems().at(index).second); } #endif QTextStream os(socket); if((commands.count() > 0) && (!isPic) && (!isSync)) { os.setAutoDetectUnicode(true); os << "HTTP/1.0 200 Ok\r\n" "Content-Type: text/plain; charset=\"utf-8\"\r\n" "Access-Control-Allow-Origin: *\r\n" "\r\n"; QString response; foreach(const QString & command, commands) response += MessageManager::incomingMessage(MessageIncomming("http", socket->peerAddress().toString(), socket->peerPort(), url.path(), command, command.split(" ", QString::SkipEmptyParts)), true, (command != "goto")) + "\n"; os << response; }