public void Demonstrate() { Console.WriteLine("[SENDER - INFO] Started sending example"); //Marnehuizen double lat = 53.3889139; double lon = 6.263677777777778; EntityStatePdu espdu = new EntityStatePdu(); espdu.ExerciseID = 1; EntityID eid = espdu.EntityID; eid.Site = 0; eid.Application = 1; eid.Entity = 2; EntityType entityType = espdu.EntityType; entityType.Country = (ushort)Country.Netherlands; // NL entityType.EntityKind = (byte)EntityKind.LifeForm; // Life form (vs platform, munition, sensor, etc.) entityType.Domain = (byte)Platform.Land; // Land (vs air, surface, subsurface, space) entityType.Category = 0; //empty entityType.Subcategory = 1; // Dismounted entityType.Specific = 5; //carrying an assault rifle entityType.Extra = 1; //Moving alone while (true) { lat += (1d / 11132000); lon += (1d / 40075) * Math.Cos(lat) / 360d; double[] disCoordinates = CoordinateConversions.getXYZfromLatLonDegrees(lat, lon, 0.0); Console.WriteLine("[SENDER - INFO] Entity is now at (lat:{0}, long:{1}", lat, lon); Vector3Double location = espdu.EntityLocation; location.X = disCoordinates[0]; location.Y = disCoordinates[1]; location.Z = disCoordinates[2]; espdu.Timestamp = DisTime.DisRelativeTimestamp; //send the constructed PDU to the specified multicast group _connector.sendPDU(espdu, MulticastGroup.Parse("224.5.5.5")); Console.WriteLine("[SENDER - INFO] PDU broadcasted"); Thread.Sleep(15000); } }
// Update is called once per frame void Update() { goalPosition = manager.transform.position; transform.up = this.velocity; if (this.velocity.magnitude == 0) { this.GetComponent <Rigidbody2D>().velocity = new Vector2(Random.Range(-5f, 5f), Random.Range(-5f, 5f)) .normalized * 2; } flock(); goalPosition = manager.transform.position; stayInBorder(); if ( (this.location.x - this.prev_location.x) > threshold // If position in x axis > threshold value, send Espdu ) { this.prev_location = this.location; this.sendNewEspdu = true; } else if ( (this.location.y - this.prev_location.y) > threshold // If position in y axis > threshold value, send Espdu ) { this.prev_location = this.location; this.sendNewEspdu = true; } else { this.sendNewEspdu = false; } for (int i = 0; i < 1; i++) { // Declaring the position of the Bird (in WSP - World Space Position) Vector3Double pos = new Vector3Double(); pos.X = this.location.x; pos.Y = this.location.y; pos.Z = 0.0; Vector2 GPSloc = new Vector2(); GPSloc.x = (float)pos.X; GPSloc.y = (float)pos.Y; double[] ODLoc = CoordinateConversions .getXYZfromLatLonDegrees(GPSloc.x, GPSloc.y, pos.Z); Vector3Double loc = new Vector3Double(); loc.X = ODLoc[0]; loc.Y = ODLoc[1]; loc.Z = ODLoc[2]; espdu.EntityLocation = loc; // Declaring the Bird's velocity Vector3Float vel = espdu.EntityLinearVelocity; vel.X = this.velocity.x; vel.Y = this.velocity.y; vel.Z = 0.0f; // Declaring the DeadReckoning Algorithm to be used (R, P, W) espdu.DeadReckoningParameters.DeadReckoningAlgorithm = (byte)2; //// THIS IS IN TESTING PHASE -------------------------------------------------------------------- //// Setting the angular velocity of the Bird (as above) //Vector3Float angvelo = new Vector3Float //{ // X = this.GetComponent<Rigidbody2D>().angularVelocity, // Y = 0.0f, // Z = 0.0f //}; //espdu.DeadReckoningParameters.EntityAngularVelocity = angvelo; //// END OF TESTING BLOCK ------------------------------------------------------------------------ if (this.sendNewEspdu) { espdu.Timestamp = DisTime.DisRelativeTimestamp; // Prepare output DataOutputStream dos = new DataOutputStream(Endian.Big); espdu.MarshalAutoLengthSet(dos); // Transmit broadcast messages Sender.SendMessages(dos.ConvertToBytes()); string mess = string .Format("Message sent with TimeStamp [{0}] Time Of[{1}]", espdu.Timestamp, (espdu.Timestamp >> 1)); Debug.Log(mess); } } }
public static void Main(string[] args) { mcastAddress = IPAddress.Parse("239.1.2.3"); mcastPort = 62040; broadcastPort = 62040; //3000 for DisMapper default var espdu = new EntityStatePdu(); //Could use factory but easier this way //Alcatraz const double lat = 37.827; double lon = -122.425; // Configure socket. //JoinMulticast(); //Used to talk to C# receiver. No need to connect as we are just sending multicast //StartMulticast(); //Least preffered StartBroadcast(); //Used for DisMapper //Setup EntityState PDU espdu.ExerciseID = 1; var eid = espdu.EntityID; eid.Site = 0; eid.Application = 1; eid.Entity = 2; // Set the entity type. SISO has a big list of enumerations, so that by // specifying various numbers we can say this is an M1A2 American tank, // the USS Enterprise, and so on. We'll make this a tank. There is a // separate project elsehwhere in this project that implements DIS // enumerations in C++ and Java, but to keep things simple we just use // numbers here. var entityType = espdu.EntityType; entityType.EntityKind = 1; // Platform (vs lifeform, munition, sensor, etc.) entityType.Country = 255; // USA entityType.Domain = 1; // Land (vs air, surface, subsurface, space) entityType.Category = 1; // Tank entityType.Subcategory = 1; // M1 Abrams entityType.Specific = 3; // M1A2 Abrams for (int i = 0; i < 100; i++) { lon += (i / 1000.0); double[] disCoordinates = CoordinateConversions.getXYZfromLatLonDegrees(lat, lon, 0.0); var location = espdu.EntityLocation; location.X = disCoordinates[0]; location.Y = disCoordinates[1]; location.Z = disCoordinates[2]; espdu.Timestamp = DisTime.DisRelativeTimestamp; //Prepare output var dos = new DataOutputStream(Endian.Big); espdu.MarshalAutoLengthSet(dos); // Transmit broadcast messages SendMessages(dos.ConvertToBytes()); Console.Write("Message sent with TimeStamp [{0}] Time Of[{1}]", espdu.Timestamp, espdu.Timestamp >> 1); //Thread.Sleep(1000); Console.Write("Hit Enter for Next PDU. Ctrl-C to Exit"); Console.ReadLine(); } mcastSocket.Close(); }