1 // 2 // Copyright (c) 2010-2018 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using System; 8 using Antmicro.Renode.Peripherals.Wireless; 9 10 namespace Antmicro.Renode.Network 11 { 12 public static class RangeMediumExtension 13 { SetRangeWirelessFunction(this WirelessMedium wirelesMedium, int range = 0)14 public static void SetRangeWirelessFunction(this WirelessMedium wirelesMedium, int range = 0) 15 { 16 var function = new RangeMediumFunction(); 17 function.Range = range; 18 wirelesMedium.SetMediumFunction(function); 19 } 20 } 21 22 public sealed class RangeMediumFunction : IMediumFunction 23 { CanReach(Position from, Position to)24 public bool CanReach(Position from, Position to) 25 { 26 // any transmission that is not within range will fail 27 if(Math.Sqrt(Math.Pow((double)(to.X - from.X), 2) + Math.Pow((double)(to.Y - from.Y), 2) + Math.Pow((double)(to.Z - from.Z), 2)) > Range) 28 { 29 return false; 30 } 31 return true; 32 } 33 CanTransmit(Position from)34 public bool CanTransmit(Position from) 35 { 36 return true; 37 } 38 39 public int Range { get; set; } 40 41 public string FunctionName { get { return Name; } } 42 43 private const string Name = "range_medium_function"; 44 } 45 } 46 47