Ejemplo n.º 1
0
 def sendPing(self):
     for (ac_id, value) in self.ac_downlink_status.items():
         if messages_xml_map.PROTOCOL_VERSION == "2.0":
             # For pprzlink V2.0 set the receiver id
             self.udp.send(message.PprzMessage('datalink', 'PING'), 0,
                           self.ac_downlink_status[int(ac_id)].address,
                           ac_id)
         else:
             self.udp.send(message.PprzMessage('datalink', 'PING'), 0,
                           self.ac_downlink_status[int(ac_id)].address)
         value.last_ping_time = time.time()
     self.ping_timer = threading.Timer(PING_PERIOD, self.sendPing)
     self.ping_timer.start()
Ejemplo n.º 2
0
    def run(self):
        try:
            # Start the UDP interface
            self.udp.start()

            if self.ping_sender:
                # Create a PING message
                ping = message.PprzMessage('datalink', 'PING')

            # Wait for a ^C
            while True:
                if self.ping_sender:
                    # Send PING message
                    print("Sending %s to %s:%d (%d)" %
                          (ping, remote_address, ping_port, my_receiver_id))
                    self.udp.send(
                        ping,  # The message to send
                        my_sender_id,  # Our numerical id
                        remote_address,  # The IP address of the destination
                        my_receiver_id  # The id of the destination
                    )
                time.sleep(2)

        except KeyboardInterrupt:
            self.udp.stop()
Ejemplo n.º 3
0
 def proccess_msg(self,
                  sender,
                  address,
                  msg,
                  length,
                  receiver_id=None,
                  component_id=None):
     # If it is a PING send a PONG, else print message information
     if msg.name == "PING":
         print("Received PING from %i %s [%d Bytes]" %
               (sender, address, length))
         pong = message.PprzMessage('telemetry', 'PONG')
         print("Sending back %s to %s:%d (%d)" %
               (pong, address[0], address[1], sender))
         self.udp.send(pong, receiver_id, address[0], receiver=sender)
     else:
         print("Received message from %i %s [%d Bytes]: %s" %
               (sender, address, length, msg))
Ejemplo n.º 4
0
    def run(self):
        print("Starting serial interface on %s at %i baud" %
              (args.dev, self.baudrate))

        try:
            self.serial_interface.start()

            # give the thread some time to properly start
            time.sleep(0.1)

            while self.serial_interface.isAlive():
                self.serial_interface.join(1)

                # create a ping message
                ping = message.PprzMessage('datalink', 'PING')

                # send a ping message to ourselves
                print("Sending ping")
                self.serial_interface.send(ping, self.ac_id, self.ac_id)

        except (KeyboardInterrupt, SystemExit):
            print('Shutting down...')
            self.serial_interface.stop()
            exit()
Ejemplo n.º 5
0
def recv_callback(ac_id, pprzMsg):
    # Print the message and the sender id
    print ("Received message %s from %s" % (pprzMsg,ac_id))
    # Send back a PONG message
    ivy.send(message.PprzMessage("telemetry", "PONG"), sender_id= 2, receiver_id= ac_id)
Ejemplo n.º 6
0
import pprzlink.messages_xml_map as messages_xml_map
import pprzlink.message as message
import time

# Function called when a PING message is received
def recv_callback(ac_id, pprzMsg):
    # Print the message and the sender id
    print ("Received message %s from %s" % (pprzMsg,ac_id))
    # Send back a PONG message
    ivy.send(message.PprzMessage("telemetry", "PONG"), sender_id= 2, receiver_id= ac_id)

# Creation of the ivy interface
ivy = pprzlink.ivy.IvyMessagesInterface(
            agent_name="PprzlinkIvyTutorial",   # Ivy agent name
            start_ivy=False,                    # Do not start the ivy bus now
            ivy_bus="127.255.255.255:2010")     # address of the ivy bus

try:
    # starts the ivy interface
    ivy.start()

    # Subscribe to PING messages and sets recv_callback as the callback function.
    ivy.subscribe(recv_callback,message.PprzMessage("datalink", "PING"))

    # Wait untill ^C is pressed
    while True:
        time.sleep(5)
except KeyboardInterrupt:
    ivy.shutdown()
Ejemplo n.º 7
0
 def initial_ivy_binds(self):
     # Subscribe to all datalink messages
     messages_datalink = messages_xml_map.get_msgs("datalink")
     for msg in messages_datalink:
         self.ivy.subscribe(self.proccess_uplink_msg,
                            message.PprzMessage("datalink", msg))
Ejemplo n.º 8
0
 def process_incoming_message(self, source, pprz_message):
     print("Received message from %i: %s" % (source, pprz_message))
     if pprz_message.name == "PING":
         print("Sending back PONG")
         pong = message.PprzMessage('telemetry', 'PONG')
         self.serial_interface.send(pong, self.ac_id, source)
Ejemplo n.º 9
0

def proccess_msg(sender,
                 address,
                 msg,
                 length,
                 receiver_id=None,
                 component_id=None):
    print("Got message from %i %s [%d Bytes]: %s" %
          (sender, address, length, msg))


udp = pprzlink.udp.UdpMessagesInterface(callback=proccess_msg,
                                        uplink_port=outgoing_port,
                                        downlink_port=incoming_port,
                                        interface_id=my_id)

try:
    udp.start()

    ping = message.PprzMessage('datalink', 'PING')

    while True:
        print("Sending %s to %s:%d (%d)" %
              (ping, remote_address, outgoing_port, other_id))
        udp.send(ping, my_id, remote_address, other_id)
        time.sleep(2)

except KeyboardInterrupt:
    udp.stop()