Click here to Skip to main content
15,886,045 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I draw the a topology where each node is an object of class SensorNode, the blue links indicate the links between each node with its neighbors where the circles around the nodes represent the transmission range for each node. The sink also is an object of class Sink. I need to instantiate messaging and communication between them but I have no idea what mechanisms should I used to perform message passing between theses objects (sensor nodes) where each node has its unique ID, the sink has a fixed ID which is 1 in my code because I use only a single sink.

The following are the classes where I am still stuck to how to implement send receive, and forward in terms of making this communication applicable between these different objects...

1 - Class "SensorNode"

C#
class SensorNode
    {
       public int snID;
       public string snName;
       public int snDepth;
       public DateTime schedulingTime;
       public double holdingTime;
       public double energy;

       public List<int> queue11 = new List<int>();
       public List<DateTime> queue12 = new List<DateTime>();

       public List<Packet> queue21 = new List<Packet>();
       public List<DateTime> queue22 = new List<DateTime>();

       public SensorNode(int id,string name,int depth, double energy)
       {
           this.snID = id;
           this.snName = name;
           this.snDepth = depth;
           this.energy = energy;
       }

       public void insertHistoryQueue(int packetID, DateTime receivingTime)
       {
           queue11.Add(packetID);
           queue12.Add(receivingTime);
       }

       public void insertPriorityQueue(Packet packet, DateTime schedulingTime)
       {
           queue21.Add(packet);
           queue22.Add(schedulingTime);
       }

       public DateTime schedulingTimeCalculations(double holdingTime, DateTime systemTime)       
       {
           schedulingTime = DateTime.FromOADate(holdingTime).Date + systemTime.TimeOfDay;

           return schedulingTime; 
       }

       public double holdingTimeCalculations(double alpha, double depth, double beta)
       {
           holdingTime = alpha * depth + beta;

           return holdingTime; 
       }

       public void receive(Packet packet)
       {
       }

       public void forward(Packet packet, int neighborID)
       {
       }

       public void remove()
       {
       }

       public void sendDirect(int rxID, Packet packet)
       {
       }
    }


2 - Class "Sink"


C#
class Sink
    {
        public string name;
        public int sinkID;
        public int sinkX;
        public int sinkY;

        public List<Packet> queue1 = new List<Packet>();
        public List<DateTime> queue2 = new List<DateTime>();

        public Sink(string name, int Id , int xLocation, int yLocation)
        {
            this.name = name;
            this.sinkID = Id;
            this.sinkX = xLocation;
            this.sinkY = yLocation;
        }

        public void insert(Packet packet, DateTime receivingTime)
        {
            queue1.Add(packet);
            queue2.Add(receivingTime);
        }
    }




Any idea, I need your suggestions and your help as I do not have an idea how to pass information between these objects (sensor nodes) and between the sensor nodes and the sink. What is the library which is responsible for this application in C#?

What I have tried:

To start communication between nodes (events)
Posted
Updated 30-Apr-17 22:15pm
Comments
[no name] 30-Apr-17 19:39pm    
You need to research events and delegates.

1 solution

What NotPolitcallyCorrect wrote is right. Perhaps the following might give you some starting point.

void Main()
{
	var s1 = new SensorNode(1, "don't care", 0, 0);
	var s2 = new SensorNode(2, "don't care", 0, 0);
	
	var sink = new Sink("don't care", 3, 0, 0);

	sink.AddSensor(s1);
	sink.AddSensor(s2);
	
	s1.SendNewData();
	s2.SendNewData();
	s1.SendNewData();

}


public class EventArgs<T> : EventArgs
{
	private readonly T _value;

	public EventArgs(T value)
	{
		_value = value;
	}

	public T Value
	{
		get { return _value; }
	}
}

public class Packet
{ 
	public int SensorId { get; set; }
	public string theData { get; set; }
	public Packet(int id, string data)
	{
		SensorId = id;
		theData = data;
	}
}

public interface ISensorNode
{ 
	event EventHandler<EventArgs<Packet>> DataSend;
}


class SensorNode : ISensorNode
{
	public event EventHandler<EventArgs<Packet>> DataSend;
	public int Id { get; set; }
	public SensorNode(int id,string name,int depth, double energy)
	{
		Id = id;
	}

	public void SendNewData()
	{
		Packet p = new Packet(Id, "123.4");
		var handler = DataSend;
		var args = new EventArgs<Packet>(p);
		handler?.Invoke(this, args);
	}
	
}


class Sink
{ 
	public Sink(string name, int Id , int xLocation, int yLocatio)
	{
		
	}

	public void AddSensor(ISensorNode newSensor)
	{		
		newSensor.DataSend += OnDataReceived;
	}

	private void OnDataReceived(object sender, EventArgs<Packet> e)
	{
		Packet packed = e.Value;
		Console.WriteLine($"received data {packed.theData} from sensor with id {packed.SensorId}");
	}
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900