[python] add pprz_env with usable default IVY_BUS

- pprz_env.IVY_BUS is either the env variable IVY_BUS or appropriate default (checks for OSX)
- some fixes for udp_link

should fix #1495 and the python part of #204
This commit is contained in:
Felix Ruess
2015-12-22 11:47:43 +01:00
parent eaf971bfad
commit 34e076e2f7
7 changed files with 57 additions and 24 deletions
@@ -16,6 +16,7 @@ import messagepicker
PPRZ_SRC = getenv("PAPARAZZI_SRC", path.normpath(path.join(path.dirname(path.abspath(__file__)), '../../../../')))
sys.path.append(PPRZ_SRC + "/sw/lib/python")
import pprz_env
from pprz_msg import messages_xml_map
@@ -244,7 +245,7 @@ class PlotPanel(object):
# is given ; this is performed by IvyStart (C)
try:
logging.getLogger('Ivy').setLevel(logging.WARN)
IvyStart("")
IvyStart(pprz_env.IVY_BUS)
# binding to every message
# IvyBindMsg(self.OnIvyMsg, "(.*)")
except:
@@ -31,6 +31,8 @@ from ivy.std_api import *
PPRZ_HOME = os.getenv("PAPARAZZI_HOME")
sys.path.append(PPRZ_HOME + "/sw/lib/python")
import pprz_env
from pprz_msg import messages_xml_map
class Circular_Buffer:
@@ -161,7 +163,7 @@ class Link_Combiner:
# starting the bus
logging.getLogger('Ivy').setLevel(logging.WARN)
IvyStart("")
IvyStart(pprz_env.IVY_BUS)
IvyBindMsg(self.onIvyMessage, "^([^ ]+) TELEMETRY_MESSAGE ([^ ]+) ([^ ]+) ([^ ]+)$")
def onIvyMessage(self, agent, *larg):
+27 -8
View File
@@ -9,9 +9,14 @@ import sys
import threading
import time
sys.path.append(os.getenv("PAPARAZZI_HOME") + "/sw/lib/python")
# if PAPARAZZI_SRC not set, then assume the tree containing this
# file is a reasonable substitute
PPRZ_SRC = os.getenv("PAPARAZZI_SRC", os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'../../../../')))
sys.path.append(PPRZ_SRC + "/sw/lib/python")
import messages_xml_map
import pprz_env
from pprz_msg import messages_xml_map
PING_PERIOD = 5.0
STATUS_PERIOD = 1.0
@@ -39,12 +44,13 @@ class DownLinkStatus():
class IvyUdpLink():
def __init__(self):
self.InitIvy()
self.ivy_id = 0
self.status_timer = threading.Timer(STATUS_PERIOD, self.sendStatus)
self.ping_timer = threading.Timer(STATUS_PERIOD, self.sendPing)
self.ac_downlink_status = {}
self.rx_err = 0
messages_xml_map.ParseMessages()
messages_xml_map.parse_messages()
self.data_types = {'float': ['f', 4],
'uint8': ['B', 1],
'uint16': ['H', 2],
@@ -54,6 +60,15 @@ class IvyUdpLink():
'int32': ['l', 4]
}
def __del__(self):
self.stop()
def stop(self):
self.status_timer.cancel()
self.ping_timer.cancel()
IvyUnBindMsg(self.ivy_id)
IvyStop()
def Unpack(self, data_fields, type, start, length):
return struct.unpack(type, "".join(data_fields[start:start + length]))[0]
@@ -68,8 +83,8 @@ class IvyUdpLink():
# starting the bus
logging.getLogger('Ivy').setLevel(logging.WARN)
IvyStart("")
IvyBindMsg(self.OnSettingMsg, "(^.* SETTING .*)")
IvyStart(pprz_env.IVY_BUS)
self.ivy_id = IvyBindMsg(self.OnSettingMsg, "(^.* SETTING .*)")
def calculate_checksum(self, msg):
ck_a = 0
@@ -227,14 +242,18 @@ class IvyUdpLink():
self.server.bind(('0.0.0.0', DOWNLINK_PORT))
self.status_timer.start()
self.ping_timer.start()
while True:
(msg, address) = self.server.recvfrom(2048)
self.ProcessPacket(msg, address)
try:
while True:
(msg, address) = self.server.recvfrom(2048)
self.ProcessPacket(msg, address)
except KeyboardInterrupt:
print("Stopping server on request")
def main():
udp_interface = IvyUdpLink()
udp_interface.Run()
udp_interface.stop()
if __name__ == '__main__':