QVideoWidget::QVideoWidget(QWidget *parent) : QWidget(parent), lastSize(0, 0), active(this->windowState() & Qt::WindowActive), mouseIn( underMouse() ) { setMouseTracking(Ui::crosshair); connect( this, SIGNAL(forceUpdate()), this, SLOT(receiveUpdate()) ); }
void Game::update() { //New objects objectMutex.lock(); for (unsigned i = 0; i < newObjects.size(); i++) { std::pair<std::unordered_map<uint32_t, ObjectVisual*>::iterator, bool> insert = objectVisuals.insert({ newObjects[i].ID, new ObjectVisual() }); if (insert.second) insert.first->second->polygon.setPosition(newObjects[i].x - applicationData->getWindowWidthHalf(), newObjects[i].y - applicationData->getWindowWidthHalf()); } newObjects.clear(); objectMutex.unlock(); //Gather state contents size_t offset = 0; std::vector<unsigned char> inputPacket(sizeof(packet::PacketType) + sizeof(CLIENT_ID_TYPE) + sizeof(int16_t) * 2 + sizeof(unsigned)/*Reserve elements for atleast id + mouse pos + held buttons count*/); //Packet type inputPacket[offset] = packet::updateInput; offset += sizeof(packet::PacketType); //ID idMutex.lock(); memcpy(&inputPacket[offset], &ID, sizeof(ID)); offset += sizeof(ID); idMutex.unlock(); //Mouse x/y int16_t mousePosVal(inputManager->getMouseX()); memcpy(&inputPacket[offset], &mousePosVal, sizeof(mousePosVal)); offset += sizeof(mousePosVal); mousePosVal = inputManager->getMouseY(); memcpy(&inputPacket[offset], &mousePosVal, sizeof(mousePosVal)); offset += sizeof(mousePosVal); ////Pressed buttons //Check every held button std::vector<unsigned> held; for (auto it = inputManager->keyMap.begin(); it != inputManager->keyMap.end(); it++) { if (it->second) held.push_back(it->first); } unsigned size = held.size(); memcpy(&inputPacket[offset], &size, sizeof(unsigned)); offset += sizeof(size); if (size > 0) { inputPacket.resize(inputPacket.size() + sizeof(unsigned) * size); memcpy(&inputPacket[offset], &held[0], sizeof(unsigned) * size); offset += sizeof(unsigned) * size; } //Synchronous update send/receive state data socketUDP.send(boost::asio::buffer(inputPacket)); socketUDP.receive(boost::asio::buffer(receiveBufferUDP)); receiveUpdate();//Wait untill a server update arrives }
//************************************************************** //main distance vector execution function that calls other routines //************************************************************** void dvRouting(struct node * connectTable) { char * hostname; int len; if(gethostname(hostname, len) != 0) { fprintf(stderr, "router: gethostname error\n"); return; } dvRoutingTable * table; table = initDVroutingTable(connectTable); if(!fork()){ //needs to be threads receiveUpdate(table, connectTable, hostname); } updateExchange(table, connectTable, hostname); printRoutingTable(table); }
void Simulator::onStart() { QMutexLocker locker(&lock); QThread* mainThread = QThread::currentThread(); qDebug() << "Simulator Thread: "<< mainThread; // Get required UAVObjects ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager* objManager = pm->getObject<UAVObjectManager>(); actDesired = ActuatorDesired::GetInstance(objManager); manCtrlCommand = ManualControlCommand::GetInstance(objManager); posHome = HomeLocation::GetInstance(objManager); velActual = VelocityActual::GetInstance(objManager); posActual = PositionActual::GetInstance(objManager); altActual = BaroAltitude::GetInstance(objManager); attActual = AttitudeActual::GetInstance(objManager); attRaw = AttitudeRaw::GetInstance(objManager); gpsPos = GPSPosition::GetInstance(objManager); telStats = GCSTelemetryStats::GetInstance(objManager); // Listen to autopilot connection events TelemetryManager* telMngr = pm->getObject<TelemetryManager>(); connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect())); connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect())); //connect(telStats, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(telStatsUpdated(UAVObject*))); // If already connect setup autopilot GCSTelemetryStats::DataFields stats = telStats->getData(); if ( stats.Status == GCSTelemetryStats::STATUS_CONNECTED ) onAutopilotConnect(); inSocket = new QUdpSocket(); outSocket = new QUdpSocket(); setupUdpPorts(settings.hostAddress,settings.inPort,settings.outPort); emit processOutput("\nLocal interface: " + settings.hostAddress + "\n" + \ "Remote interface: " + settings.remoteHostAddress + "\n" + \ "inputPort: " + QString::number(settings.inPort) + "\n" + \ "outputPort: " + QString::number(settings.outPort) + "\n"); qxtLog->info("\nLocal interface: " + settings.hostAddress + "\n" + \ "Remote interface: " + settings.remoteHostAddress + "\n" + \ "inputPort: " + QString::number(settings.inPort) + "\n" + \ "outputPort: " + QString::number(settings.outPort) + "\n"); // if(!inSocket->waitForConnected(5000)) // emit processOutput(QString("Can't connect to %1 on %2 port!").arg(settings.hostAddress).arg(settings.inPort)); // outSocket->connectToHost(settings.hostAddress,settings.outPort); // FG // if(!outSocket->waitForConnected(5000)) // emit processOutput(QString("Can't connect to %1 on %2 port!").arg(settings.hostAddress).arg(settings.outPort)); connect(inSocket, SIGNAL(readyRead()), this, SLOT(receiveUpdate()),Qt::DirectConnection); // Setup transmit timer txTimer = new QTimer(); connect(txTimer, SIGNAL(timeout()), this, SLOT(transmitUpdate()),Qt::DirectConnection); txTimer->setInterval(updatePeriod); txTimer->start(); // Setup simulator connection timer simTimer = new QTimer(); connect(simTimer, SIGNAL(timeout()), this, SLOT(onSimulatorConnectionTimeout()),Qt::DirectConnection); simTimer->setInterval(simTimeout); simTimer->start(); // setup time time = new QTime(); time->start(); current.T=0; current.i=0; }
void Exporter::onStart() { QMutexLocker locker(&lock); QThread* mainThread = QThread::currentThread(); qDebug() << "Exporter Thread: "<< mainThread; // Get required UAVObjects ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager* objManager = pm->getObject<UAVObjectManager>(); actDesired = ActuatorDesired::GetInstance(objManager); actCommand = ActuatorCommand::GetInstance(objManager); manCtrlCommand = ManualControlCommand::GetInstance(objManager); gcsReceiver= GCSReceiver::GetInstance(objManager); flightStatus = FlightStatus::GetInstance(objManager); posHome = HomeLocation::GetInstance(objManager); velActual = VelocityActual::GetInstance(objManager); posActual = PositionActual::GetInstance(objManager); baroAlt = BaroAltitude::GetInstance(objManager); airspeedActual = AirspeedActual::GetInstance(objManager); attActual = AttitudeActual::GetInstance(objManager); attSettings = AttitudeSettings::GetInstance(objManager); accels = Accels::GetInstance(objManager); gyros = Gyros::GetInstance(objManager); gpsPos = GPSPosition::GetInstance(objManager); gpsVel = GPSVelocity::GetInstance(objManager); telStats = GCSTelemetryStats::GetInstance(objManager); // Listen to autopilot connection events TelemetryManager* telMngr = pm->getObject<TelemetryManager>(); connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect())); connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect())); //connect(telStats, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(telStatsUpdated(UAVObject*))); // If already connect setup autopilot GCSTelemetryStats::DataFields stats = telStats->getData(); if ( stats.Status == GCSTelemetryStats::STATUS_CONNECTED ) onAutopilotConnect(); inSocket = new QUdpSocket(); outSocket = new QUdpSocket(); setupUdpPorts(settings.hostAddress,settings.inPort,settings.outPort); emit processOutput("\nLocal interface: " + settings.hostAddress + "\n" + \ "Remote interface: " + settings.remoteAddress + "\n" + \ "inputPort: " + QString::number(settings.inPort) + "\n" + \ "outputPort: " + QString::number(settings.outPort) + "\n"); qxtLog->info("\nLocal interface: " + settings.hostAddress + "\n" + \ "Remote interface: " + settings.remoteAddress + "\n" + \ "inputPort: " + QString::number(settings.inPort) + "\n" + \ "outputPort: " + QString::number(settings.outPort) + "\n"); connect(inSocket, SIGNAL(readyRead()), this, SLOT(receiveUpdate()),Qt::DirectConnection); // Setup transmit timer txTimer = new QTimer(); connect(txTimer, SIGNAL(timeout()), this, SLOT(transmitUpdate()),Qt::DirectConnection); txTimer->setInterval(updatePeriod); txTimer->start(); // Setup exporter connection timer exporterTimer = new QTimer(); connect(exporterTimer, SIGNAL(timeout()), this, SLOT(onExporterConnectionTimeout()),Qt::DirectConnection); exporterTimer->setInterval(exporterTimeout); exporterTimer->start(); // setup time time = new QTime(); time->start(); current.T=0; current.i=0; }