cz.cuni.amis.pogamut.usar2004.agent.module.master
Class SensorMasterModule

Package class diagram package SensorMasterModule
java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.module.AgentModule<AGENT>
      extended by cz.cuni.amis.pogamut.base.agent.module.SensorModule<USAR2004Bot>
          extended by cz.cuni.amis.pogamut.usar2004.agent.module.master.SensorMasterModule
All Implemented Interfaces:
cz.cuni.amis.pogamut.base.component.IComponent

public class SensorMasterModule
extends cz.cuni.amis.pogamut.base.agent.module.SensorModule<USAR2004Bot>

Master module for gathering every sensor message server sends. They are saved respectively by their type and than name. There is a listener for SEN messages that updates data in SensorContainer. Note that this is equvalent with SensorsContainerQueued. The difference is that the non queued version throws out records as soon as new comes along. It writes them over. This is needed when we do not care about precision - when we want to know what is happening right now!

Author:
vejmanm

Field Summary
protected  cz.cuni.amis.pogamut.usar2004.agent.module.master.SensorMasterModule.SensorMessageListener sensorListener
           
protected  SensorsContainer sensorModules
           
protected static SensorMasterModule singleton
           
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.SensorModule
worldView
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
agent, controller, eventBus, log
 
Constructor Summary
SensorMasterModule(USAR2004Bot bot)
          Private ctor
 
Method Summary
protected  void cleanUp()
           
protected  SuperSensor createNewSensor(SensorMessage message)
          Asks SensorType enum if it knows SensorType represented by string type.
protected  void fileMessage(SensorMessage message)
          Updates previous State on genuine Sensor or creates a new Record.
static SensorMasterModule getModuleInstance(USAR2004Bot bot)
          Method for obtaining the singleton.
 List<MessageDescriptor> getNonEmptyDescripton()
          For each type of sensor it adds all individuals to the returnee List as a couple (Type, Name)
 SuperSensor getSensorByTypeName(String type, String name)
          Gets sensor message representatives from local hashmap specified by type and by name.
 List<SuperSensor> getSensorsByClass(Class c)
          Adds every object that can be casted to initial class to the output list.
 List<SuperSensor> getSensorsBySensorType(SensorType type)
          Iterates through local hashmap values and seeks match.
 List<SuperSensor> getSensorsByType(String type)
          Gets sensor message representatives from local hashmap.
 Boolean isReady()
          Collection of sensor data check.
 boolean isSensorReady(SensorType type)
          Iterates through local hashmap values and seeks match.
protected  boolean updateSensorCollection(SensorMessage message)
          Returns a flag that indicates if sensorUpdate was successful.
 
Methods inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
getComponentId, getLog, getState, initComponentId, isRunning, kill, pause, reset, resume, start, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sensorListener

protected cz.cuni.amis.pogamut.usar2004.agent.module.master.SensorMasterModule.SensorMessageListener sensorListener

singleton

protected static SensorMasterModule singleton

sensorModules

protected SensorsContainer sensorModules
Constructor Detail

SensorMasterModule

public SensorMasterModule(USAR2004Bot bot)
Private ctor

Parameters:
bot - USAR2004Bot variable for creating instance of each new record in sensorModules(due to inheritance)
Method Detail

getModuleInstance

public static SensorMasterModule getModuleInstance(USAR2004Bot bot)
Method for obtaining the singleton.

Parameters:
bot - USAR2004Bot parameter for creation of the singleton instance when called for the first time.
Returns:
Returns singleton instance.

isReady

public Boolean isReady()
Collection of sensor data check.

Returns:
Returns false if either sensor collection is empty or null;

getSensorsByType

public List<SuperSensor> getSensorsByType(String type)
Gets sensor message representatives from local hashmap. Returns null if none matches or this hash map is empty.

Parameters:
type - String representing the type of sensor to return.
Returns:
Returns List of specified type of Sensor module.

getSensorsBySensorType

public List<SuperSensor> getSensorsBySensorType(SensorType type)
Iterates through local hashmap values and seeks match. Returns null if this hash map is empty. Note, that if type = UNKNOWN_SENSOR it returns all unknown sensors.

Parameters:
type - SensorType representing the type of sensor to return.
Returns:
Returns List of all sensors that suit input SensorType.

isSensorReady

public boolean isSensorReady(SensorType type)
Iterates through local hashmap values and seeks match. Returns null if this hash map is empty. Note, that if type = UNKNOWN_SENSOR it returns all unknown sensors.

Parameters:
type - SensorType representing the type of sensor to return.
Returns:
Returns List of all sensors that suit input SensorType.

getSensorsByClass

public List<SuperSensor> getSensorsByClass(Class c)
Adds every object that can be casted to initial class to the output list. Note that if You feed this method with SuperClass it will return all available submodules.

Parameters:
c - Class representing the type of which the return list should be
Returns:
Returns a list of eligible objects, that can be casted to Class c

getSensorByTypeName

public SuperSensor getSensorByTypeName(String type,
                                       String name)
Gets sensor message representatives from local hashmap specified by type and by name. Returns null if none matches or this hash map is empty.

Parameters:
type - String representing the type of sensor to return.
name - String representing the name of sensor to return.
Returns:
Returns List of specified type of Sensor module.

getNonEmptyDescripton

public List<MessageDescriptor> getNonEmptyDescripton()
For each type of sensor it adds all individuals to the returnee List as a couple (Type, Name)

Returns:
returns Map of couples (Type/Name) of non empty sensor representatives.

createNewSensor

protected SuperSensor createNewSensor(SensorMessage message)
Asks SensorType enum if it knows SensorType represented by string type. If it does, it also contains Class reference. This reference is then instantiated and returned. If it does not, it returns instance of base class SuperSensor which is represented by SensorType.UNKNOWN_SENSOR.

Parameters:
type - String representing possible valid SensorType.
Returns:
Returns Class instance relevant to input String.

updateSensorCollection

protected boolean updateSensorCollection(SensorMessage message)
Returns a flag that indicates if sensorUpdate was successful.

Parameters:
message - new SensorMessage object.
Returns:
Return false if this message type with this name does not exist. yet.

fileMessage

protected void fileMessage(SensorMessage message)
Updates previous State on genuine Sensor or creates a new Record.

Parameters:
message - This ought to be SensorMessage caught by listener.

cleanUp

protected void cleanUp()
Overrides:
cleanUp in class cz.cuni.amis.pogamut.base.agent.module.AgentModule<USAR2004Bot>


Copyright © 2015 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.