Ejemplo n.º 1
0
void GroundStation::print_action_packet(Protocol::ActionPacket& packet){
    double 	lat, lon;
    float	alt, speed;

    QTextStream(stdout) << "Type: ActionPacket" << endl;
    Protocol::ActionType type = packet.GetAction();

    switch(type)
    {
        case Protocol::ActionType::Start : QTextStream(stdout) << "Start: " << (uint8_t)type << endl; break;
        case Protocol::ActionType::RequestInfo : QTextStream(stdout) << "Request Info: " << (uint8_t)type << endl; break;
        case Protocol::ActionType::AddWaypoint : QTextStream(stdout) << "Add Waypoint: " << (uint8_t)type << endl; break;
        case Protocol::ActionType::SetHome : QTextStream(stdout) << "Set Home: " << (uint8_t)type << endl; break;
        case Protocol::ActionType::RemoveWaypoint : QTextStream(stdout) << "Remove Waypoint: " << (uint8_t)type << endl; break;
        case Protocol::ActionType::Stop : QTextStream(stdout) << "Stop: " << (uint8_t)type << endl; break;
        case Protocol::ActionType::Shutdown : QTextStream(stdout) << "Shutdown: " << (uint8_t)type << endl; break;
        default :   QTextStream(stdout) << "Unknown Type: " << (uint8_t)type << endl; break;
    }

    Protocol::Waypoint waypoint = packet.GetWaypoint();
    lat = waypoint.lat;
    lon = waypoint.lon;
    alt = waypoint.alt;
    speed = waypoint.speed;

    QTextStream(stdout) << "Latitude: " << lat << endl;
    QTextStream(stdout) << "Longitude: " << lon << endl;
    QTextStream(stdout) << "Altitude: " << alt << endl;
    QTextStream(stdout) << "Speed: " << speed << endl;


}
Ejemplo n.º 2
0
void UAV::addWaypoint(Protocol::ActionPacket ap)
{
    //QTextStream(stdout) << "Waypoint added" << endl;
    Protocol::Waypoint wp = ap.GetWaypoint();
    
    pointOfInterest.push(wp);
}
Ejemplo n.º 3
0
void UAV::respond_to_action_packet(Protocol::ActionPacket ap)
{
    Protocol::ActionType ap_type = ap.GetAction();

    // Simple one packet send first.
    switch(ap_type)
    {
        case Protocol::ActionType::RequestInfo:
            if(uavOn)
                send_info_packet();
            
            break;
        case Protocol::ActionType::AddWaypoint:
            if(uavOn && can_add_waypoint())
            {
                QTextStream(stdout) << "Adding new waypoint" << endl;
                uavWaypointsReady = true;
                ++currentNumOfPoints;
                addWaypoint(ap);
            }
            else
                QTextStream(stdout) << "Cannot add waypoint." << endl;
            break;
        case Protocol::ActionType::SetHome:
            {
            Protocol::Waypoint newHome = ap.GetWaypoint();
            QTextStream(stdout) << "Setting Home: (" << newHome.lat << "," << newHome.lon << ")" << endl;
            uavHomeLat = newHome.lat;
            uavHomeLng = newHome.lon;
            }
            break;
        case Protocol::ActionType::Stop:
            QTextStream(stdout) << "STOPPING" << endl;
            uavFlying = false;
            stopAction = true;
            break;
        case Protocol::ActionType::Start:
            //if(uavOn && !receivedInfoPacketReq && uavWaypointsReady)
            if(!uavOn)
            {
                QTextStream(stdout) << "STARTING... "<< endl;
                uavOn = true;
                uavFlying = true;
                receivedInfoPacketReq = true;
                timer->start(200);                
            }
            break;
        case Protocol::ActionType::Shutdown:
            shutdownAction = true;
            uavOn = false;
            timer->stop();
            break;
        default:
            break;

    }
}
Ejemplo n.º 4
0
void NetworkListener::processPendingDatagrams() {
    static int pack_number = 1;
    QByteArray datagram;
    datagram.resize(udpSocket.pendingDatagramSize());
    udpSocket.readDatagram(datagram.data(), datagram.size());

    Protocol::Packet* incPack = Protocol::Packet::Parse((uint8_t*)datagram.data(), datagram.size());
    Protocol::PacketType type = incPack->get_type();
    if (type == Protocol::PacketType::Ack) {
        std::cout<< "AckPacket Recieved" << std::endl;
        Protocol::AckPacket *ackPacket = (Protocol::AckPacket*)incPack;
        myMessageBox->addAckPacket(*ackPacket);
    } else if (type == Protocol::PacketType::Action) {
        std::cout<< "ActionPacket Recieved" << std::endl;
        Protocol::ActionPacket *actionPacket = (Protocol::ActionPacket*)incPack;
        Protocol::Waypoint test_wp;
        test_wp = actionPacket->GetWaypoint();
        std::cout << pack_number << " Latitude: " << test_wp.lat << " Longitude: " << test_wp.lon << std::endl;
        ++pack_number;

        if (actionPacket->GetAction() == Protocol::ActionType::AddWaypoint) {
            Protocol::TelemetryPacket telem;
            telem.SetLocation(test_wp.lat,test_wp.lon,200);
            myMessageBox->addTelemetryPacket(telem);
        }

        myMessageBox->addActionPacket(*actionPacket);
    } else if (type == Protocol::PacketType::Telem) {
        std::cout<< "TelemPacket Recieved" << std::endl;
        Protocol::TelemetryPacket *telemPacket = (Protocol::TelemetryPacket*)incPack;
        //std::cout << pack_number << " Latitude: " << telemPacket << " Longitude: " << telemPacket->lon << std::endl;
        ++pack_number;
        myMessageBox->addTelemetryPacket(*telemPacket);
    } else if (type == Protocol::PacketType::Info) {
        std::cout<< "InfoPacket Recieved" << std::endl;
        Protocol::InfoPacket *infoPacket = (Protocol::InfoPacket*)incPack;
        myMessageBox->addInfoPacket(*infoPacket);
    } else {
        std::cout<< "UNKNOWN PACKET TYPE RECIEVED!" << std::endl;
    }
    return;
}