added support for subscribing to EMANE 0.9.1 location events
(Boeing r1845)
This commit is contained in:
parent
adc7a4d601
commit
33ea3e95ec
1 changed files with 83 additions and 54 deletions
|
@ -692,6 +692,8 @@ class Emane(ConfigurableManager):
|
||||||
# reset the service, otherwise nextEvent won't work
|
# reset the service, otherwise nextEvent won't work
|
||||||
self.initeventservice()
|
self.initeventservice()
|
||||||
if self.eventmonthread is not None:
|
if self.eventmonthread is not None:
|
||||||
|
if self.version == self.EMANE091:
|
||||||
|
self.eventmonthread._Thread__stop()
|
||||||
self.eventmonthread.join()
|
self.eventmonthread.join()
|
||||||
self.eventmonthread = None
|
self.eventmonthread = None
|
||||||
|
|
||||||
|
@ -700,36 +702,62 @@ class Emane(ConfigurableManager):
|
||||||
'''
|
'''
|
||||||
if self.service is None:
|
if self.service is None:
|
||||||
return
|
return
|
||||||
if self.version == self.EMANE091:
|
self.info("Subscribing to EMANE location events (not generating them). " \
|
||||||
raise NotImplementedError, \
|
"(%s) " % threading.currentThread().getName())
|
||||||
"EMANE eventmonitorloop() not implemented for EMANE 0.9"
|
|
||||||
self.info("subscribing to EMANE location events")
|
|
||||||
#self.service.subscribe(emaneeventlocation.EVENT_ID,
|
|
||||||
# self.handlelocationevent)
|
|
||||||
#self.service.loop()
|
|
||||||
#self.service.subscribe(emaneeventlocation.EVENT_ID, None)
|
|
||||||
while self.doeventloop is True:
|
while self.doeventloop is True:
|
||||||
(event, platform, nem, component, data) = self.service.nextEvent()
|
if self.version == self.EMANE091:
|
||||||
|
(uuid, seq, events) = self.service.nextEvent()
|
||||||
|
if not self.doeventloop:
|
||||||
|
break # this occurs with 0.9.1 event service
|
||||||
|
for event in events:
|
||||||
|
(nem, eid, data) = event
|
||||||
|
if eid == LocationEvent.IDENTIFIER:
|
||||||
|
self.handlelocationevent2(nem, eid, data)
|
||||||
|
else:
|
||||||
|
(event, platform, nem, cmp, data) = self.service.nextEvent()
|
||||||
if event == emaneeventlocation.EVENT_ID:
|
if event == emaneeventlocation.EVENT_ID:
|
||||||
self.handlelocationevent(event, platform, nem, component, data)
|
self.handlelocationevent(event, platform, nem, cmp, data)
|
||||||
|
self.info("Unsubscribing from EMANE location events. (%s) " % \
|
||||||
self.info("unsubscribing from EMANE location events")
|
threading.currentThread().getName())
|
||||||
#self.service.unsubscribe(emaneeventlocation.EVENT_ID)
|
|
||||||
|
|
||||||
def handlelocationevent(self, event, platform, nem, component, data):
|
def handlelocationevent(self, event, platform, nem, component, data):
|
||||||
''' Handle an EMANE location event.
|
''' Handle an EMANE location event (EMANE 0.8.1 and earlier).
|
||||||
'''
|
'''
|
||||||
event = emaneeventlocation.EventLocation(data)
|
event = emaneeventlocation.EventLocation(data)
|
||||||
entries = event.entries()
|
entries = event.entries()
|
||||||
for e in entries.values():
|
for e in entries.values():
|
||||||
# yaw,pitch,roll,azimuth,elevation,velocity are unhandled
|
# yaw,pitch,roll,azimuth,elevation,velocity are unhandled
|
||||||
(nemid, lat, long, alt) = e[:4]
|
(nemid, lat, long, alt) = e[:4]
|
||||||
|
self.handlelocationeventtoxyz(nemid, lat, long, alt)
|
||||||
|
|
||||||
|
def handlelocationevent2(self, rxnemid, eid, data):
|
||||||
|
''' Handle an EMANE location event (EMANE 0.9.1+).
|
||||||
|
'''
|
||||||
|
events = LocationEvent()
|
||||||
|
events.restore(data)
|
||||||
|
for event in events:
|
||||||
|
(txnemid, attrs) = event
|
||||||
|
if 'latitude' not in attrs or 'longitude' not in attrs or \
|
||||||
|
'altitude' not in attrs:
|
||||||
|
self.warn("dropped invalid location event")
|
||||||
|
continue
|
||||||
|
# yaw,pitch,roll,azimuth,elevation,velocity are unhandled
|
||||||
|
lat = attrs['latitude']
|
||||||
|
long = attrs['longitude']
|
||||||
|
alt = attrs['altitude']
|
||||||
|
self.handlelocationeventtoxyz(txnemid, lat, long, alt)
|
||||||
|
|
||||||
|
def handlelocationeventtoxyz(self, nemid, lat, long, alt):
|
||||||
|
''' Convert the (NEM ID, lat, long, alt) from a received location event
|
||||||
|
into a node and x,y,z coordinate values, sending a Node Message.
|
||||||
|
Returns True if successfully parsed and a Node Message was sent.
|
||||||
|
'''
|
||||||
# convert nemid to node number
|
# convert nemid to node number
|
||||||
(emanenode, netif) = self.nemlookup(nemid)
|
(emanenode, netif) = self.nemlookup(nemid)
|
||||||
if netif is None:
|
if netif is None:
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
self.info("location event for unknown NEM %s" % nemid)
|
self.info("location event for unknown NEM %s" % nemid)
|
||||||
continue
|
return False
|
||||||
n = netif.node.objid
|
n = netif.node.objid
|
||||||
# convert from lat/long/alt to x,y,z coordinates
|
# convert from lat/long/alt to x,y,z coordinates
|
||||||
(x, y, z) = self.session.location.getxyz(lat, long, alt)
|
(x, y, z) = self.session.location.getxyz(lat, long, alt)
|
||||||
|
@ -748,7 +776,7 @@ class Emane(ConfigurableManager):
|
||||||
self.info(warntxt)
|
self.info(warntxt)
|
||||||
self.session.exception(coreapi.CORE_EXCP_LEVEL_ERROR,
|
self.session.exception(coreapi.CORE_EXCP_LEVEL_ERROR,
|
||||||
"emane", None, warntxt)
|
"emane", None, warntxt)
|
||||||
continue
|
return False
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# int.bit_length() not present on Python 2.6
|
# int.bit_length() not present on Python 2.6
|
||||||
pass
|
pass
|
||||||
|
@ -759,12 +787,13 @@ class Emane(ConfigurableManager):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.warn("location event NEM %s has no corresponding node %s" \
|
self.warn("location event NEM %s has no corresponding node %s" \
|
||||||
% (nemid, n))
|
% (nemid, n))
|
||||||
continue
|
return False
|
||||||
# don't use node.setposition(x,y,z) which generates an event
|
# don't use node.setposition(x,y,z) which generates an event
|
||||||
node.position.set(x,y,z)
|
node.position.set(x,y,z)
|
||||||
msg = node.tonodemsg(flags=0)
|
msg = node.tonodemsg(flags=0)
|
||||||
self.session.broadcastraw(None, msg)
|
self.session.broadcastraw(None, msg)
|
||||||
self.session.sdt.updatenodegeo(node.objid, lat, long, alt)
|
self.session.sdt.updatenodegeo(node.objid, lat, long, alt)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class EmaneModel(WirelessModel):
|
class EmaneModel(WirelessModel):
|
||||||
|
|
Loading…
Add table
Reference in a new issue