edu.ksu.cis.cooprobot.simulator.communication
Class CommunicationsSystem

java.lang.Object
  extended byedu.ksu.cis.cooprobot.simulator.communication.CommunicationsSystem

public class CommunicationsSystem
extends Object

The CommunicationsSystem class is served as a main interface, which interact with the environment. It provides function for robot and environment control panel. It is also responsible for sending message, delivering message to the right robot including the process of verifying participants.

Author:
Acharaporn Pattaravanichanon

Field Summary
static int BROADCAST
          Constant value of communication type indicates BROADCAST type.
static int BROADCASTANDP2P
          Constant value of communication type indicates POINT-TO-POINT and BROADCAST type.
private  int delay
          System delay time default is 0
private  int deliveryProb
          System delivery probability default is 100
private  edu.ksu.cis.cooprobot.simulator.environment.Environment env
           
static int INFINITE
          Constant value indicate infinite range limit.
private  boolean isLinkEnabled
          Status of System link (All links in the system) default set to true
static int POINT2POINT
          Constant value of communication type indicates POINT-TO-POINT type.
private  int range
          System maximum range limit default is -1 (infinite)
private  Vector robotCommRecordVector
          Vector of RobotCommRecord in the communication system
 
Constructor Summary
CommunicationsSystem()
          Constructor to start CommunicationsSystem
CommunicationsSystem(edu.ksu.cis.cooprobot.simulator.environment.Environment env)
           
 
Method Summary
private  void distributeMessages(RobotCommRecord senderRecord, Message msg, long timeStep)
          This method is used for distributing broadcast message.
 int getDelay()
          Get system delay
 int getDeliveryProb()
          Get system delivery probability
 Vector getMessage(String name, long timeStep)
          Retrieve message from the communication system.
 int getRange()
          Get system maximum range limit
 RobotCommRecord getRobotCommRecord(String name)
          Get RobotCommRecord with identified name
 int getRobotDelay(String robot1, String robot2)
          Get delay time between a pair of robot
 int getRobotDeliveryProb(String robot1, String robot2)
          Get delivery probability of a pair of robot
 int getRobotRange(String name)
          Get maximum range limit of a robot
private  int getTotalProb(int system, int robot)
          Get total value of delivery probability which is the average value of system delivery probability and robot delivery probability
private  boolean isInRangeLimit(String sender, String receiver, int robotRange)
           
 boolean isLinkEnabled()
          For checking if system link is enabled or not
 boolean isMsgLost(int random, int prob)
          Determine if message is lost or not by comparing random value of a message with total delivery probabibity
 boolean isRobotBroadcastEnabled(String name)
          Check if broadcast abililty is set to true
 boolean isRobotExist(String name)
          Check if this robot exists in the system.
 boolean isRobotP2PEnabled(String name)
          Check if point to point ability is set to true
 boolean isRobotReceiveEnabled(String name)
          Check if robot's incoming link is set to true
 boolean isRobotSendEnabled(String name)
          Check if robot's outgoing link is set to true
private  void processBroadcast(Message msg, long timeStep)
          It is used to process broadcast message by checking if sender is qualified and distribute messages to other robots.
private  void processP2P(Message msg, long timeStep)
          This method is used for processing point to point message by checking if sender and receiver are qualified and add message to the receiver's queue.
 boolean registerRobot(String name, int commType)
          Register robot into the system before starting communication session.
 void sendMessage(Message msg, long timeStep)
          Send message to other robots.
 void setDelay(int delay)
          Set system delay
 void setDeliveryProb(int prob)
          Set system delivery probability.
 void setRange(int range)
          Set system range which is the maximum range limit which robot can communicate with each other.
 void setRobotDelay(String robot1, String robot2, int delay)
          Set delay between a pair of robots.
 void setRobotDeliveryProb(String robot1, String robot2, int prob)
          Set delivery probalibity beween a pair of robot.
 void setRobotRange(String name, int range)
          Set maximum range limit which is the maximum distance of receiver which can receive messages from this robot.
 void shutdownAllLink()
          To shutdown system link
 void shutdownReceiveLink(String name)
          Shutdown robot's incoming link
 void shutdownSendLink(String name)
          Shutdown robot's outgoing link
 void startupAllLink()
          To start up system link
 void startupReceiveLink(String name)
          Startup robot's imcoming link
 void startupSendLink(String name)
          Start up robot's outgoing link
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INFINITE

public static final int INFINITE
Constant value indicate infinite range limit.

See Also:
Constant Field Values

delay

private int delay
System delay time default is 0


range

private int range
System maximum range limit default is -1 (infinite)


deliveryProb

private int deliveryProb
System delivery probability default is 100


isLinkEnabled

private boolean isLinkEnabled
Status of System link (All links in the system) default set to true


robotCommRecordVector

private Vector robotCommRecordVector
Vector of RobotCommRecord in the communication system


BROADCAST

public static final int BROADCAST
Constant value of communication type indicates BROADCAST type.

See Also:
Constant Field Values

POINT2POINT

public static final int POINT2POINT
Constant value of communication type indicates POINT-TO-POINT type.

See Also:
Constant Field Values

BROADCASTANDP2P

public static final int BROADCASTANDP2P
Constant value of communication type indicates POINT-TO-POINT and BROADCAST type.

See Also:
Constant Field Values

env

private edu.ksu.cis.cooprobot.simulator.environment.Environment env
Constructor Detail

CommunicationsSystem

public CommunicationsSystem()
Constructor to start CommunicationsSystem


CommunicationsSystem

public CommunicationsSystem(edu.ksu.cis.cooprobot.simulator.environment.Environment env)
Method Detail

registerRobot

public boolean registerRobot(String name,
                             int commType)
Register robot into the system before starting communication session.

Parameters:
name - - robot name
commType - - communication types which registered robot can use to communicate
Returns:
true if successfully registered, false otherwise

sendMessage

public void sendMessage(Message msg,
                        long timeStep)
Send message to other robots. There are two parameters which are sending message and the current time step. Time step is used for synchronization within the robot simulator system. Therefore, every message has sent time and received time. Sent time is the time step which this message is sending out. Received time is the time step which receiver should get this message. Received time calculates by adding system delay and robot delay to the sent time.

Parameters:
msg - - message to others robot.
timeStep - - current time step.

getMessage

public Vector getMessage(String name,
                         long timeStep)
Retrieve message from the communication system. The parameters are robot name and time step. The robot name is the name of robot who would like to retreive messages at the defined time step.

Parameters:
name - - the owner of the message
timeStep - - the time step of messages which robot want to get messages.
Returns:
A vector of messages.

processBroadcast

private void processBroadcast(Message msg,
                              long timeStep)
It is used to process broadcast message by checking if sender is qualified and distribute messages to other robots. The qualified sender is sender's send link enabled and broadcast ability enabled.

Parameters:
msg - - broadcast message
timeStep - - current time step

processP2P

private void processP2P(Message msg,
                        long timeStep)
This method is used for processing point to point message by checking if sender and receiver are qualified and add message to the receiver's queue.

Parameters:
msg - - point to point message
timeStep - - current time step

distributeMessages

private void distributeMessages(RobotCommRecord senderRecord,
                                Message msg,
                                long timeStep)
This method is used for distributing broadcast message. It will check every robot if it is qualified for receiving message from this sender or not.

Parameters:
senderRecord - - The sender RobotCommRecord
msg - - sending broadcast message
timeStep - - current time step

getTotalProb

private int getTotalProb(int system,
                         int robot)
Get total value of delivery probability which is the average value of system delivery probability and robot delivery probability

Parameters:
system - - system delivery probability
robot - - robot delivery probability
Returns:
The average of system and robot delivery probability

isMsgLost

public boolean isMsgLost(int random,
                         int prob)
Determine if message is lost or not by comparing random value of a message with total delivery probabibity

Parameters:
random - - message random value
prob - - total delivery probability
Returns:
true if random > prob , a message will be lost if random value is beyond the probability.

isLinkEnabled

public boolean isLinkEnabled()
For checking if system link is enabled or not

Returns:
the status of system link

getRobotCommRecord

public RobotCommRecord getRobotCommRecord(String name)
Get RobotCommRecord with identified name

Parameters:
name - - robot name
Returns:
identified RobotCommRecord

isRobotExist

public boolean isRobotExist(String name)
Check if this robot exists in the system.

Parameters:
name - - name of a robot
Returns:
true if this robot exists, false otherwise

startupAllLink

public void startupAllLink()
To start up system link


shutdownAllLink

public void shutdownAllLink()
To shutdown system link


setDelay

public void setDelay(int delay)
Set system delay

Parameters:
delay - - system delay

setRange

public void setRange(int range)
Set system range which is the maximum range limit which robot can communicate with each other.

Parameters:
range - - System Range Limit

setDeliveryProb

public void setDeliveryProb(int prob)
Set system delivery probability. With delivery probability 100%, the system assures that all messages will be delivered to the right receivers. Delivery probability value is between 0 and 100.

Parameters:
prob - - delivery probaility (0 to 100)

setRobotDelay

public void setRobotDelay(String robot1,
                          String robot2,
                          int delay)
Set delay between a pair of robots.

Parameters:
robot1 - - the first robot's name.
robot2 - - the second tobot's name.
delay - - delay time between these two robots.

setRobotRange

public void setRobotRange(String name,
                          int range)
Set maximum range limit which is the maximum distance of receiver which can receive messages from this robot.

Parameters:
name - - robot name
range - - maximum range limit

setRobotDeliveryProb

public void setRobotDeliveryProb(String robot1,
                                 String robot2,
                                 int prob)
Set delivery probalibity beween a pair of robot.

Parameters:
robot1 - - first robot's name
robot2 - - second robot's name
prob - - delivery probability (value between 0-100)

getDelay

public int getDelay()
Get system delay

Returns:
system delay

getRange

public int getRange()
Get system maximum range limit

Returns:
system range limit

getDeliveryProb

public int getDeliveryProb()
Get system delivery probability

Returns:
system delivery probability

getRobotDelay

public int getRobotDelay(String robot1,
                         String robot2)
Get delay time between a pair of robot

Parameters:
robot1 - - first robot name
robot2 - - second robot name
Returns:
delay time between robot1 and robot2

getRobotRange

public int getRobotRange(String name)
Get maximum range limit of a robot

Parameters:
name - - robot name
Returns:
maximum range limit

getRobotDeliveryProb

public int getRobotDeliveryProb(String robot1,
                                String robot2)
Get delivery probability of a pair of robot

Parameters:
robot1 - - first robot name
robot2 - - second robot name
Returns:
delivery probability between robot1 and robot2

startupSendLink

public void startupSendLink(String name)
Start up robot's outgoing link

Parameters:
name - - robot name

shutdownSendLink

public void shutdownSendLink(String name)
Shutdown robot's outgoing link

Parameters:
name - - robot name

startupReceiveLink

public void startupReceiveLink(String name)
Startup robot's imcoming link

Parameters:
name - - robot name

shutdownReceiveLink

public void shutdownReceiveLink(String name)
Shutdown robot's incoming link

Parameters:
name - - robot name

isRobotBroadcastEnabled

public boolean isRobotBroadcastEnabled(String name)
Check if broadcast abililty is set to true

Parameters:
name - - robot name
Returns:
true - if broadcast is enabled, false otherwise

isRobotP2PEnabled

public boolean isRobotP2PEnabled(String name)
Check if point to point ability is set to true

Parameters:
name - - robot name
Returns:
true - if point to point is enabled, false otherwise

isRobotSendEnabled

public boolean isRobotSendEnabled(String name)
Check if robot's outgoing link is set to true

Parameters:
name - - robot name
Returns:
true - if outgoing link is enabled, false otherwise

isRobotReceiveEnabled

public boolean isRobotReceiveEnabled(String name)
Check if robot's incoming link is set to true

Parameters:
name - - robot name
Returns:
true - if incoming link is enabled, false otherwise

isInRangeLimit

private boolean isInRangeLimit(String sender,
                               String receiver,
                               int robotRange)