예제 #1
0
void droneNavData::slotRead()
{
    QHostAddress sender ;
    quint16 senderPort;
    QByteArray datagram;


    while (hasPendingDatagrams())
    {
        datagram.resize(pendingDatagramSize());

        readDatagram(datagram.data(), datagram.size(), &sender, &senderPort) ;

        Navdata *nav = (Navdata*) datagram.data() ;
        NavdataDemo *navdataDemo = (NavdataDemo*) &nav->options[0] ;

        //qDebug() << "vx : " << navdataDemo->vx ;

        //qDebug() << "vy : " << navdataDemo->vy ;

        qDebug() << "psi :" << navdataDemo->psi/1000 ;


        emit newNavData(navdataDemo->vbat, navdataDemo->ctrl_state, navdataDemo->theta/1000, navdataDemo->phi/1000, navdataDemo->psi/1000 - BIAIS, (double)((double)navdataDemo->altitude)/1000.0, navdataDemo->vx/10, navdataDemo->vy/10, navdataDemo->vz/10);
    }
}
예제 #2
0
void MySocket::myOnReceive()
{
    while (hasPendingDatagrams())
        {
            QByteArray buf;
            int len=pendingDatagramSize();
            buf.resize(len);
            this->readDatagram(buf.data(),len,&clientIP,&clientPort);
            qDebug("%s",buf.data());
            QString str(buf);
            int x=str.indexOf(" ");
            QString funcName=str.left(x);
            QString funcArgs=str.mid(x);
            if(funcName=="start")
            {
                start(funcArgs);
            }else if(funcName=="stop"){
                stop(funcArgs);
            }else if(funcName=="pause"){
                pause(funcArgs);
            }else if(funcName=="state"){
                state(funcArgs);
            }

        }
}
예제 #3
0
void ClientUdpSocket::onReadPendingDatagram()
{
  while (hasPendingDatagrams()) {
    QByteArray datagram;
    QHostAddress sender;
    quint16 senderPort;
    datagram.resize(pendingDatagramSize());
    readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);

    QDataStream in(datagram);

    quint8 magic = 0;
    in >> magic;
    if (magic != DGMAGICBIT) {
      qDebug() << QString("Datagram with invalid magic byte (size=%1)").arg(datagram.size());
      continue;
    }

    quint8 type;
    in >> type;
    switch (type) {
      case DGHELLO:
        processHello(in, sender, senderPort);
        break;
      case DGDATA:
        processFileData(in, sender, senderPort);
        break;
      default:
        qDebug() << QString("Unknown datagram type");
        break;
    }
  }
}
예제 #4
0
void QamUdpSocket::sockRead()
{
	while ( hasPendingDatagrams() ) {
		QByteArray  datagram ;
		datagram.resize( pendingDatagramSize() ) ;
		readDatagram(datagram.data(), datagram.size(), &m_distAddr, &m_distPort ) ;
		emit sockInfo(QString("RECV from %1:%2").arg( m_distAddr.toString() ).arg( m_distPort) ) ;
		emit sockReceived( datagram ) ;
	}
}
예제 #5
0
void UDPSocket::readPendingDatagrams() {
    //qDebug()<<"----UDPSocket::readPendingDatagrams()";

    while (hasPendingDatagrams()) {
        datagram->clear();
        qint64 datagramSize = pendingDatagramSize();
        datagram->resize(datagramSize);
        QHostAddress peerAddress;
        quint16 peerPort;

        qint64 readSize = readDatagram(datagram->data(), datagramSize, &peerAddress, &peerPort);
        if(readSize == -1){
            qWarning()<<"Can not read datagram!";
            break;
        }
        //qDebug()<<"~~datagramSize:"<<datagramSize;

        QDataStream in(datagram, QIODevice::ReadOnly);
        in.setVersion(QDataStream::Qt_4_7);
        QVariant v;
        in >> v;
        if (v.canConvert<Packet>()){
            //Packet *packet = new Packet();
            Packet *packet = PacketHandlerBase::getPacket();
            *packet = v.value<Packet>();
            packet->setTransmissionProtocol(TP_UDP);
            packet->setPeerHostAddress(peerAddress);
            packet->setPeerHostPort(peerPort);
            packet->setLocalHostAddress(localAddress());
            packet->setLocalHostPort(localPort());

//            qWarning()<<"";
//            qWarning()<<"~~packet->getPacketData().size():"<<packet->getPacketData().size();
//            qWarning()<<"~~peerAddress.toString():"<<peerAddress.toString();
//            qWarning()<<"~~peerPort:"<<peerPort;
//            qWarning()<<"~~localAddress():"<<localAddress().toString();
//            qWarning()<<"~~localPort():"<<localPort();
//            qWarning()<<"";


            emit signalNewUDPPacketReceived(packet);

        }else{
            qWarning()<<"ERROR! Can not convert UDP data to Packet!";
        }

    }


    datagram->clear();
    datagram->resize(0);

}
예제 #6
0
void Broadcast::processDatagrams()
{
    while (hasPendingDatagrams()) {
             QByteArray datagram;
             QHostAddress address;
             datagram.resize(pendingDatagramSize());
             readDatagram(datagram.data(), datagram.size(),&address);
             qDebug()<<"Received broadcast:"<<datagram<<" "<<address;
             if(QString("MULTITALK_5387132")==datagram.data())
                emit gotConnectionRequest(address);
             else
                 qDebug()<<"bad magic text in udp packet";
    }
}
예제 #7
0
void AutoDiscovery::readPendingDatagrams()
{
	while(hasPendingDatagrams())
	{
		QByteArray datagram;
		datagram.resize(pendingDatagramSize());

		QHostAddress sender;
		quint16 senderPort;

		readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);

		parseDatagram(datagram, sender);
	}
}
예제 #8
0
void AudioDataSocket::ready_read()
{
//    fprintf(stderr, "receving data from %d to %d\n", peerPort(), localPort());
    char buf[1024];
    if(hasPendingDatagrams())
    {
        quint64 len = pendingDatagramSize();
        if(len > sizeof(buf))
        {
            qDebug("out of buffer");
            exit(EXIT_FAILURE);
        }
        readDatagram(buf, len);
        auddev->write_data((short*)buf, len);
    }
}
예제 #9
0
void PeerInformationSocket::handleReadReady()
{
  while (hasPendingDatagrams()) 
    {
      QByteArray datagram;
      datagram.resize(pendingDatagramSize());
      QHostAddress sender;
      quint16 senderPort;

      if (-1 != readDatagram(datagram.data(), datagram.size(),
			     &sender, &senderPort))
	{
	  processPacket(sender, datagram);
	}
    }
}
예제 #10
0
void ChatRoomListenSocket::dispatchDatagram()
{
    while (hasPendingDatagrams()) {
        QByteArray datagram;
        datagram.resize(pendingDatagramSize());
        if (readDatagram(datagram.data(), datagram.size()) == -1)
            return;
        
        QDataStream stream(&datagram, QIODevice::ReadOnly);
        int messageType;
        QString userName, identifier, ipAddress, message;
        stream >> messageType >> userName >> identifier;
        if (messageType == NEWPARTICIPANT) {
            stream >> ipAddress;
            emit newParticipant(userName, identifier, ipAddress);
        } else if (messageType == MESSAGE) {
예제 #11
0
void CBasicListener::OnReadyRead()
{
    /* Determine the size of the incoming datagram and
       create room for it in a buffer. */
    QByteArray message;
    message.resize(pendingDatagramSize());

    /* Grab the message (and the address that sent it). */
    QHostAddress address;
    readDatagram(message.data(), message.size(), &address);

    /* Decode the JSON we received. */
    bool ok;
    QVariantMap map = QJson::Parser().parse(message, &ok).toMap();

    /* Make sure that there were no errors decoding the JSON and that
       we can read the results without any problems. */
    if(!ok || !map.contains("version") || map["version"].toInt() != Definitions::ProtocolVersion)
    {
        /* We only want to alert the user once. */
        static bool displayed_warning = false;

        if(!displayed_warning)
        {
            QMessageBox::warning(NULL, tr("Warning:"), tr("One of the machines on your network ('%1') is running a different version of NitroShare than this machine (%2). Please ensure both machines are running the latest version of NitroShare.")
                                 .arg(address.toString()).arg(Definitions::Version));
            displayed_warning = true;
        }

        return;
    }

    /* Make sure none of the properties are ending. */
    if(!map.contains("id") || !map.contains("name") ||
            !map.contains("transmission_port") || !map.contains("uptime"))
    {
        qDebug() << "Ping received from" << address.toString() << "is invalid.";
        return;
    }

    /* Next, make sure that this is not one of _our_ packets. */
    if(map["id"] == Settings::GetID())
        return;

    /* Seems like a valid packet. */
    emit Ping(address, map);
}
예제 #12
0
파일: server.cpp 프로젝트: krdcl/USpeak
void Server::readPendingDatagrams()
{
    while (hasPendingDatagrams()) {
        QByteArray datagram;
        datagram.resize(pendingDatagramSize());
        QHostAddress sender;
        quint16 senderPort;

        readDatagram(datagram.data(), datagram.size(),
                     &sender, &senderPort);


        // processTheDatagram(datagram);
      //  if (port != senderPort)
            emit massageReceived(datagram);
    }
}
예제 #13
0
void Discovery::onReadyRead()
{
    while (hasPendingDatagrams()) {
        QByteArray datagram;
        datagram.resize(pendingDatagramSize());
        QHostAddress sender;
        quint16 senderPort;

        readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);

//        qDebug() << "got datagram" << datagram;
        if (!m_reportedBridges.contains(sender)) {
            m_reportedBridges << sender;
            emit foundBridge(sender);
        }
    }
}
예제 #14
0
void UpnpDiscovery::readData()
{
    QByteArray data;
    QHostAddress hostAddress;
    QUrl location;

    // read the answere from the multicast
    while (hasPendingDatagrams()) {
        data.resize(pendingDatagramSize());
        readDatagram(data.data(), data.size(), &hostAddress);
    }

    if (data.contains("NOTIFY")) {
        emit upnpNotify(data);
        return;
    }

    // if the data contains the HTTP OK header...
    if (data.contains("HTTP/1.1 200 OK")) {
        const QStringList lines = QString(data).split("\r\n");
        foreach (const QString& line, lines) {
            int separatorIndex = line.indexOf(':');
            QString key = line.left(separatorIndex).toUpper();
            QString value = line.mid(separatorIndex+1).trimmed();

            // get location
            if (key.contains("LOCATION")) {
                location = QUrl(value);
            }
        }

        UpnpDeviceDescriptor upnpDeviceDescriptor;
        upnpDeviceDescriptor.setLocation(location);
        upnpDeviceDescriptor.setHostAddress(hostAddress);
        upnpDeviceDescriptor.setPort(location.port());

        foreach (UpnpDiscoveryRequest *upnpDiscoveryRequest, m_discoverRequests) {
            QNetworkRequest networkRequest = upnpDiscoveryRequest->createNetworkRequest(upnpDeviceDescriptor);
            requestDeviceInformation(networkRequest, upnpDeviceDescriptor);
        }
예제 #15
0
void Socket::readData()
{
	while(hasPendingDatagrams()){
		QByteArray data;
		data.resize(pendingDatagramSize());
		QHostAddress address;
		readDatagram(data.data(),data.size(),&address);
		switch(Event::getType(data)){
		case Event::Drop:{
			DropEvent event(data);
			emit getDropEvent(event,address);
			break;
		}
		case Event::Get:{
			GetEvent event(data);
			emit getGetEvent(event,address);
			break;
		}
		case Event::Player:{
			PlayerEvent event(data);
			emit getPlayerEvent(event,address);
			break;
		}
		case Event::Update:{
			UpdateEvent event(data);
			emit getUpdateEvent(event,address);
			break;
		}
		case Event::User:{
			UserEvent event(data);
			emit getUserEvent(event,address);
			break;
		}
		}
	}
}