Пример #1
0
void CAppInterface::CreateServerApp()
{
    //connect ServerCore Signal
    QObject::connect(ServerCore::GetInstance(), &ServerCore::deviceAdded, [=](QString uid)
    {
        if (m_DevicesInfoListModel->isExist(uid))
        {
            DeviceHandle* kDevicesIfo = new DeviceHandle;
            DeviceInfo kInfo = ServerCore::GetInstance()->queryDeviceInfo(uid);
            kDevicesIfo->setUID(uid);
            kDevicesIfo->setIP(kInfo.getIP());
            kDevicesIfo->setName(kInfo.getName());
            kDevicesIfo->setCmdKeys(kInfo.getSupportCommands());

            QList<QString> kDisplayName;
            for (auto i : kDevicesIfo->getCmdKeys())
            {
                DeviceCommand kCmd = kInfo.getDeviceCommandDetail(i);
                kDisplayName.append(kCmd.getCommandDisplayName());
            }
            kDevicesIfo->setCmdDisplayName(kInfo.getSupportCommands());

            m_DevicesInfoListModel->addDevice(*kDevicesIfo);
            m_DeviceCmdListModel->addDevice(*kDevicesIfo);
        }
    });

    QObject::connect(ServerCore::GetInstance(), &ServerCore::commandReturned, [=](QString uid, QVariantMap retMap)
    {
        QString kText(uid + " returns:\n");
        for (QString key : retMap.keys())
        {
            kText+= key + ": " + retMap[key].toString()+"\n";
        }

        Q_EMIT m_pSender->commandReturned(kText);
    });
    /*
    QObject::connect(ServerCore::GetInstance(), &ServerCore::dataWrittenToDevice, [=]
    {
    });
    QObject::connect(ui.GetStatusButton, &QPushButton::clicked, [=]
    {
        QVariantMap paramMap;
        paramMap.insert("command", "queryDisplayInfo");
        ServerCore::GetInstance()->sendCommandToDevice("az0000", paramMap);
    });

    QObject::connect(ServerCore::GetInstance(), &ServerCore::commandReturned, [=](QString uid, QVariantMap retMap)
    {
        ui.plainTextEdit->appendPlainText(uid + " returns: ");

        for (QString key : retMap.keys())
        {
            ui.plainTextEdit->appendPlainText(key + ": " + retMap[key].toString());
        }
    });
    */
    ServerCore::GetInstance()->startServer();
}
Пример #2
0
QTcpSocket* ServerCore::createSocket(QString deviceUID)
{
	DeviceInfo info = DeviceManagerModule()->GetDeviceInfo(deviceUID);
	QTcpSocket *socket = new QTcpSocket(this);
	socket->connectToHost(info.getIP(), PORT_SERVER_BROADCAST, QIODevice::ReadWrite);
	return socket;
}