All,
I have spent some time trying to handle location events using Java code with
emaneevent-location, and I thought I should post it to the list in case someone
is interested.
Following is code that de-serializes LocationEvent datagram packets generated
using Java source from the .proto files and retrieves latitude, longitude and
altitude values.
Here is the java code:
(mbreedy/sgalgano)
---------------------------------------------------------------
MulticastSocket mcs = new MulticastSocket (45703);
InetAddress group = InetAddress.getByName ("224.1.2.8");
mcs.joinGroup (group);
byte[] buf = new byte [256];
while (true) {
DatagramPacket dp = new DatagramPacket (buf, buf.length);
mcs.receive (dp);
ByteBuffer byteBuffer = ByteBuffer.wrap(dp.getData());
byteBuffer.order(ByteOrder.BIG_ENDIAN);
// first two bytes (in network byte order)
// represent the size of the event message
int messageLength = byteBuffer.getShort();
// verify you have the entire message
if (messageLength == dp.getLength()-2) {
byte[] message = new byte[messageLength];
byteBuffer.get(message);
// deserialize Event message
BasicEvent.Event event = BasicEvent.Event.parseFrom(message);
// Events can contain one or more Data serializations
// (actual event info: location, pathloss, etc)
for (BasicEvent.Event.Data.Serialization serialization :
event.getData().getSerializationsList()) {
// Location event id is 100 (see emane/events/eventids.h)
if (serialization.getEventId() == 100) {
// de-serialize the location event
Locationevent.LocationEvent locationEvent =
Locationevent.LocationEvent.parseFrom(serialization.getData());
// each location event contains info for 1 or more NEMs
for (Locationevent.LocationEvent.Location location :
locationEvent.getLocationsList()) {
System.out.println ("NemId : " + location.getNemId());
Locationevent.LocationEvent.Location.Position position =
location.getPosition();
System.out.println ("LatitudeDegrees : " +
position.getLatitudeDegrees());
System.out.println ("LongitudeDegrees: " +
position.getLongitudeDegrees());
System.out.println ("AltitudeMeters : " +
position.getAltitudeMeters());
}
}
}
}
}
---------------------------------------------------------------------
---------------------------------------------------------------------
Maggie R. Breedy
Research Associate
Institute for Human and Machine Cognition
Pensacola, FL.
voice: 850-202-4412_______________________________________________
emane-users mailing list
[email protected]
http://pf.itd.nrl.navy.mil/mailman/listinfo/emane-users