/// <summary> /// Writes a list of perception (for SARL) /// </summary> /// <param name="writer">The binary writer</param> /// <param name="perceptionList">The list of perceptions</param> public static void Write(this BinaryWriter writer, PerceptionList perceptionList) { writer.WriteSarlString(perceptionList.Id); writer.WriteInt32BE(perceptionList.Perceptions.Count); foreach (var perception in perceptionList.Perceptions) { writer.Write(perception.Position); } }
/// <summary> /// Emits the perceptions to the SARL agents /// </summary> /// <param name="perceptionList">The list of perceptions</param> public void EmitPerceptions(PerceptionList perceptionList) { var ipEndPoint = new IPEndPoint(IPAddress.Loopback, this.emissionPort); using (MemoryStream stream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(perceptionList); } stream.Flush(); var buffer = stream.GetBuffer(); udpClient.Send(buffer, buffer.Length, ipEndPoint); } }