IoHandler::IoHandler(QObject *pParent)
{
    pMyParent = (QMainWindow *)pParent;

    comPort = new ComPort(this);

    RefreshComPort();

    connect(this, SIGNAL(dataReceived(/*int index*/)), pParent, SLOT(dataReceived(/*int index*/)));
    connect(this, SIGNAL(pingReceived()), pParent, SLOT(pingReceived()));
    connect(this, SIGNAL(noPingResponse()), pParent, SLOT(noPingResponse()));

    // Create instance to Node Database.
    pNodeDb = new NodeDb;

	pLog= NULL;
}
Ejemplo n.º 2
0
//! [0]
Window::Window()
{

    createActions();
    createTrayIcon();
    centralWidget = new PydioGui(this);

    connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
    connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));

    const QIcon& icon = QIcon(":/images/Pydio16.png");
    trayIcon->setIcon(icon);
    setWindowIcon(icon);
    trayIcon->show();
    running = false;

    context = nzmqt::createDefaultContext(this);
    context->start();
    nzmqt::Subscriber* sub = new nzmqt::Subscriber(*context, "tcp://127.0.0.1:5556", "sync", this);
    connect(sub, SIGNAL(pingReceived(QList<QByteArray>)), SLOT(pingReceived(QList<QByteArray>)));
    // Start command.
    sub->start();

    nzmqt::Subscriber* sub2 = new nzmqt::Subscriber(*context, "tcp://127.0.0.1:5556", "status", this);
    connect(sub2, SIGNAL(pingReceived(QList<QByteArray>)), SLOT(statusReceived(QList<QByteArray>)));
    // Start command.
    sub2->start();

/*
    nzmqt::Requester* req = new nzmqt::Requester(*context, "tcp://127.0.0.1:5557", "STATUS", this);
    connect(req, SIGNAL(replyReceived(QList<QByteArray>)), this, SLOT(statusReceived(QList<QByteArray>)));
    req->start();
*/

    setWindowTitle(tr("Systray"));
    resize(400, 300);
}
//-----------------------------------------------------------------------------
void IoHandler::handlePacket() 
{
    QByteArray *pPacket;

    if (comPort->getThread()->getPacket(&pPacket) > 0)
    {
        unsigned short cmdID;  // Command ID
        //LENGTH(1)-CMD(2)-DATA(....)-FCS(1)
        cmdID = MAKE_WORD_LE(pPacket,1);

        switch (cmdID)
        {
            case SYS_PING_RESPONSE:
				unsigned short profileID;
				profileID= MAKE_WORD_LE(pPacket,3);
				pNodeDb->setProfileID(profileID);
                pingAnswered = true;
                emit pingReceived();
                break;
            case ZB_RECEIVE_DATA_INDICATION:
                handleData(pPacket);
                break;
            default:
                emit unknownMessage();
        }

		if (pLog)
			pLog->enterPacket(pPacket);
        
    }
    else
    {
        emit emptyPacket();
    }
    
}
/*!
    \internal
 */
bool QWebSocketDataProcessor::processControlFrame(const QWebSocketFrame &frame)
{
    bool mustStopProcessing = true; //control frames never expect additional frames to be processed
    switch (frame.opCode()) {
    case QWebSocketProtocol::OpCodePing:
        Q_EMIT pingReceived(frame.payload());
        break;

    case QWebSocketProtocol::OpCodePong:
        Q_EMIT pongReceived(frame.payload());
        break;

    case QWebSocketProtocol::OpCodeClose:
    {
        quint16 closeCode = QWebSocketProtocol::CloseCodeNormal;
        QString closeReason;
        QByteArray payload = frame.payload();
        if (Q_UNLIKELY(payload.size() == 1)) {
            //size is either 0 (no close code and no reason)
            //or >= 2 (at least a close code of 2 bytes)
            closeCode = QWebSocketProtocol::CloseCodeProtocolError;
            closeReason = tr("Payload of close frame is too small.");
        } else if (Q_LIKELY(payload.size() > 1)) {
            //close frame can have a close code and reason
            closeCode = qFromBigEndian<quint16>(reinterpret_cast<const uchar *>(payload.constData()));
            if (Q_UNLIKELY(!QWebSocketProtocol::isCloseCodeValid(closeCode))) {
                closeCode = QWebSocketProtocol::CloseCodeProtocolError;
                closeReason = tr("Invalid close code %1 detected.").arg(closeCode);
            } else {
                if (payload.size() > 2) {
                    QTextCodec *tc = QTextCodec::codecForName(QByteArrayLiteral("UTF-8"));
                    QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull);
                    closeReason = tc->toUnicode(payload.constData() + 2, payload.size() - 2, &state);
                    const bool failed = (state.invalidChars != 0) || (state.remainingChars != 0);
                    if (Q_UNLIKELY(failed)) {
                        closeCode = QWebSocketProtocol::CloseCodeWrongDatatype;
                        closeReason = tr("Invalid UTF-8 code encountered.");
                    }
                }
            }
        }
        Q_EMIT closeReceived(static_cast<QWebSocketProtocol::CloseCode>(closeCode), closeReason);
        break;
    }

    case QWebSocketProtocol::OpCodeContinue:
    case QWebSocketProtocol::OpCodeBinary:
    case QWebSocketProtocol::OpCodeText:
    case QWebSocketProtocol::OpCodeReserved3:
    case QWebSocketProtocol::OpCodeReserved4:
    case QWebSocketProtocol::OpCodeReserved5:
    case QWebSocketProtocol::OpCodeReserved6:
    case QWebSocketProtocol::OpCodeReserved7:
    case QWebSocketProtocol::OpCodeReservedC:
    case QWebSocketProtocol::OpCodeReservedB:
    case QWebSocketProtocol::OpCodeReservedD:
    case QWebSocketProtocol::OpCodeReservedE:
    case QWebSocketProtocol::OpCodeReservedF:
        //do nothing
        //case statements added to make C++ compiler happy
        break;

    default:
        Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeProtocolError,
                                tr("Invalid opcode detected: %1").arg(int(frame.opCode())));
        //do nothing
        break;
    }
    return mustStopProcessing;
}