def setnempositions(self, moved_netifs): """ Several NEMs have moved, from e.g. a WaypointMobilityModel calculation. Generate an EMANE Location Event having several entries for each netif that has moved. """ if len(moved_netifs) == 0: return if self.session.emane.service is None: logging.info("position service not available") return event = LocationEvent() i = 0 for netif in moved_netifs: nemid = self.getnemid(netif) ifname = netif.localname if nemid is None: logging.info("nemid for %s is unknown" % ifname) continue x, y, z = netif.node.getposition() lat, lon, alt = self.session.location.getgeo(x, y, z) # altitude must be an integer or warning is printed alt = int(round(alt)) event.append(nemid, latitude=lat, longitude=lon, altitude=alt) i += 1 self.session.emane.service.publish(0, event)
def setnempositions(self, moved_netifs): """ Several NEMs have moved, from e.g. a WaypointMobilityModel calculation. Generate an EMANE Location Event having several entries for each netif that has moved. """ if len(moved_netifs) == 0: return if self.session.emane.service is None: logger.info("position service not available") return event = LocationEvent() i = 0 for netif in moved_netifs: nemid = self.getnemid(netif) ifname = netif.localname if nemid is None: logger.info("nemid for %s is unknown" % ifname) continue x, y, z = netif.node.getposition() lat, long, alt = self.session.location.getgeo(x, y, z) logger.info("setnempositions %d %s (%s) x,y,z=(%d,%d,%s)(%.6f,%.6f,%.6f)", i, ifname, nemid, x, y, z, lat, long, alt) # altitude must be an integer or warning is printed alt = int(round(alt)) event.append(nemid, latitude=lat, longitude=long, altitude=alt) i += 1 self.session.emane.service.publish(0, event)
def set_nem_position(self, iface: CoreInterface) -> None: """ Publish a NEM location change event using the EMANE event service. :param iface: interface to set nem position for """ position = self.get_nem_position(iface) if position: nemid, lon, lat, alt = position event = LocationEvent() event.append(nemid, latitude=lat, longitude=lon, altitude=alt) self.publish_event(nemid, event, send_all=True)
def setnemposition(self, iface: CoreInterface) -> None: """ Publish a NEM location change event using the EMANE event service. :param iface: interface to set nem position for """ if self.session.emane.service is None: logging.info("position service not available") return position = self._nem_position(iface) if position: nemid, lon, lat, alt = position event = LocationEvent() event.append(nemid, latitude=lat, longitude=lon, altitude=alt) self.session.emane.service.publish(0, event)
def velocity(self, moduleid, eventtype, eventargs): # -Inf nem:45 velocity 30.0,20.0,200.0 nem = int(moduleid.split(':')[1]) if not nem in self._location_cache: raise ValueError('A velocity EEL sentence for nem "%d" ' 'has been specified without an associated ' 'location sentence. Quitting.' % nem) toks = eventargs[0].split(',') lat, lon, alt = self._location_cache[nem] azimuth, elevation, magnitude = list(map(float, toks[0:3])) events = defaultdict(lambda: LocationEvent()) events[0].append(nem, latitude=lat, longitude=lon, altitude=alt, azimuth=azimuth, elevation=elevation, magnitude=magnitude) return events
def orientation(self, moduleid, eventtype, eventargs): # -Inf nem:45 orientation 3.0,4.0,5.0 nem = int(moduleid.split(':')[1]) if not nem in self._location_cache: raise ValueError('An orientation EEL sentence for nem "%d" ' 'has been specified without an associated ' 'location sentence. Quitting.' % nem) toks = eventargs[0].split(',') lat, lon, alt = self._location_cache[nem] pitch, roll, yaw = list(map(float, toks[0:3])) events = defaultdict(lambda: LocationEvent()) events[0].append(nem, latitude=lat, longitude=lon, altitude=alt, pitch=pitch, roll=roll, yaw=yaw) return events
def handlelocationevent(self, rxnemid, eid, data): """ Handle an EMANE location event. """ 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: logger.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 handlelocationevent(self, rxnemid, eid, data): """ Handle an EMANE location event. """ 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: logger.warn("dropped invalid location event") continue # yaw,pitch,roll,azimuth,elevation,velocity are unhandled lat = attrs["latitude"] lon = attrs["longitude"] alt = attrs["altitude"] logger.debug("emane location event: %s,%s,%s", lat, lon, alt) self.handlelocationeventtoxyz(txnemid, lat, lon, alt)
def handlelocationevent(self, rxnemid: int, eid: int, data: str) -> None: """ Handle an EMANE location event. """ 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): logger.warning("dropped invalid location event") continue # yaw,pitch,roll,azimuth,elevation,velocity are unhandled lat = attrs["latitude"] lon = attrs["longitude"] alt = attrs["altitude"] logger.debug("emane location event: %s,%s,%s", lat, lon, alt) self.handlelocationeventtoxyz(txnemid, lat, lon, alt)
def setnemposition(self, netif, x, y, z): """ Publish a NEM location change event using the EMANE event service. """ if self.session.emane.service is None: logging.info("position service not available") return nemid = self.getnemid(netif) ifname = netif.localname if nemid is None: logging.info("nemid for %s is unknown", ifname) return lat, lon, alt = self.session.location.getgeo(x, y, z) event = LocationEvent() # altitude must be an integer or warning is printed # unused: yaw, pitch, roll, azimuth, elevation, velocity alt = int(round(alt)) event.append(nemid, latitude=lat, longitude=lon, altitude=alt) self.session.emane.service.publish(0, event)
def setnempositions(self, moved_netifs: List[CoreInterface]) -> None: """ Several NEMs have moved, from e.g. a WaypointMobilityModel calculation. Generate an EMANE Location Event having several entries for each netif that has moved. """ if len(moved_netifs) == 0: return if self.session.emane.service is None: logging.info("position service not available") return event = LocationEvent() for netif in moved_netifs: position = self._nem_position(netif) if position: nemid, lon, lat, alt = position event.append(nemid, latitude=lat, longitude=lon, altitude=alt) self.session.emane.service.publish(0, event)
def setnemposition(self, netif, x, y, z): """ Publish a NEM location change event using the EMANE event service. """ if self.session.emane.service is None: logger.info("position service not available") return nemid = self.getnemid(netif) ifname = netif.localname if nemid is None: logger.info("nemid for %s is unknown" % ifname) return lat, long, alt = self.session.location.getgeo(x, y, z) logger.info("setnemposition %s (%s) x,y,z=(%d,%d,%s)(%.6f,%.6f,%.6f)", ifname, nemid, x, y, z, lat, long, alt) event = LocationEvent() # altitude must be an integer or warning is printed # unused: yaw, pitch, roll, azimuth, elevation, velocity alt = int(round(alt)) event.append(nemid, latitude=lat, longitude=long, altitude=alt) self.session.emane.service.publish(0, event)
def location_gps(self, moduleid, eventtype, eventargs): # -Inf nem:45 location gps 40.025495,-74.315441,3.0 location_nem = int(moduleid.split(':')[1]) toks = eventargs[1].split(',') lat,lon,alt = list(map(float, toks[0:3])) events = defaultdict(lambda: LocationEvent()) events[0].append(location_nem, latitude=lat, longitude=lon, altitude=alt) return events
def location_gps(self, moduleid, eventtype, eventargs): # -Inf nem:45 location gps 40.025495,-74.315441,3.0 location_nem = int(moduleid.split(':')[1]) toks = eventargs[1].split(',') lat, lon, alt = list(map(float, toks[0:3])) self._location_cache[location_nem] = (lat,lon,alt) events = defaultdict(lambda: LocationEvent()) # all events are sent to nemid 0 - ie, received by every nem events[0].append(location_nem, latitude=lat, longitude=lon, altitude=alt) return events
def set_nem_positions(self, moved_ifaces: List[CoreInterface]) -> None: """ Several NEMs have moved, from e.g. a WaypointMobilityModel calculation. Generate an EMANE Location Event having several entries for each interface that has moved. """ if not moved_ifaces: return services = {} for iface in moved_ifaces: position = self.get_nem_position(iface) if not position: continue nem_id, lon, lat, alt = position service = self.nem_service.get(nem_id) if not service: continue event = services.setdefault(service, LocationEvent()) event.append(nem_id, latitude=lat, longitude=lon, altitude=alt) for service, event in services.items(): service.events.publish(0, event)
#!/usr/bin/env python try: from emane.events import EventService from emane.events import LocationEvent except: from emanesh.events import EventService from emanesh.events import LocationEvent # create the event service service = EventService(('224.1.2.8', 45703, 'emanenode0')) # create an event setting 10's position event = LocationEvent() event.append(10, latitude=40.031290, longitude=-74.523095, altitude=3.000000) # publish the event service.publish(0, event)