1 package cz.cuni.amis.pogamut.usar2004.agent.module.sensor; 2 3 import cz.cuni.amis.pogamut.usar2004.agent.module.datatypes.SensorType; 4 import cz.cuni.amis.pogamut.usar2004.communication.messages.usarinfomessages.SensorMessage; 5 6 /** 7 * It was initially abstract, but ctor with one parameter was inserted and now 8 * this class is used not only as base class for sensor modules, but also as 9 * class carrying elementary info about unknown sensors. 10 * 11 * @author vejmanm 12 */ 13 public /* 14 * abstract 15 */ class SuperSensor 16 { 17 protected SensorMessage lastMessage; 18 protected SensorType sensorType; 19 20 /** 21 * Ctor. Sensor type describes particular subject about which we want to 22 * know about. It is used to distinguish incoming message from the server. 23 */ 24 public SuperSensor() 25 { 26 this(SensorType.UNKNOWN_SENSOR); 27 } 28 29 /** 30 * Ctor. 31 * 32 * @param type Sensor type describes particular subject about which we want 33 * to know about. It is used to distinguish incoming message from the 34 * server. 35 */ 36 protected SuperSensor(SensorType type) 37 { 38 this.sensorType = type; 39 } 40 41 // @Override 42 // protected void cleanUp() 43 // { 44 // super.cleanUp(); 45 // bot=null; 46 // lastMessage = null; 47 // sensorType=null; 48 // } 49 /** 50 * Method used for updating the message object that provides particular 51 * properties for given type. Note that this object is created by yylex 52 * parser and contains properties for all configuration subject types. But 53 * only relevat to individual Sensor are filled. 54 * 55 * @param message Sensor message from server. 56 */ 57 public void updateMessage(SensorMessage message) 58 { 59 //if(message.getType().equalsIgnoreCase(SensorType)) 60 lastMessage = message; 61 } 62 63 /** 64 * Timestamp form the UT since server start in seconds. Note that time is 65 * optional parameter. 66 * 67 * @return Returns seconds elapsed from the start of the server. 68 */ 69 public double getTime() 70 { 71 return lastMessage.getTime(); 72 } 73 74 /** 75 * Used to make sure the object is filled. 76 * 77 * @return Returns true if the object is filled with sen. message. 78 */ 79 public Boolean isReady() 80 { 81 return (lastMessage != null); 82 } 83 84 /** 85 * Type describes the sensor type. It will be one of the following values: 86 * "RFID”, “RangeScanner”, “IR”, "IRScanner", "Tachometer", "Helper", 87 * "Sonar", "Odometry", "GPS", "INS", "INU", "Encoder", "Touch", 88 * "VictSensor","HumanMotion", "Sound" or "GroundTruth". 89 * 90 * @return Type of the sensor. 91 */ 92 public String getType() 93 { 94 return lastMessage.getType(); 95 } 96 97 /** 98 * SensorType is a descriptor used for creating particular instance and for 99 * getting type information about particular sensor. 100 * 101 * @return Returns SensorType. 102 */ 103 public SensorType getSensorType() 104 { 105 return sensorType; 106 } 107 108 /** 109 * Name of the sensor. 110 * 111 * @return Returns name of the sensor 112 */ 113 public String getName() 114 { 115 return lastMessage.getName(); 116 } 117 } 118 ///* 119 // * To change this template, choose Tools | Templates 120 // * and open the template in the editor. 121 // */ 122 //package cz.cuni.amis.pogamut.usar2004.agent.module.sensor; 123 // 124 //import cz.cuni.amis.pogamut.base.agent.module.SensorModule; 125 //import cz.cuni.amis.pogamut.base.communication.worldview.IWorldView; 126 //import cz.cuni.amis.pogamut.base.communication.worldview.event.IWorldEventListener; 127 //import cz.cuni.amis.pogamut.usar2004.agent.USAR2004Bot; 128 //import cz.cuni.amis.pogamut.usar2004.communication.messages.usarinfomessages.SensorMessage; 129 // 130 ///** 131 // * 132 // * @author vejmanm 133 // */ 134 //public abstract class SuperSensor extends SensorModule<USAR2004Bot> 135 //{ 136 // 137 // protected SensorMessageListener sensorListener; 138 // 139 // public SuperSensor(USAR2004Bot bot, String type) 140 // { 141 // super(bot); 142 // this.bot = bot; 143 // 144 // sensorListener = new SensorMessageListener(worldView, type); 145 // } 146 // 147 // private class SensorMessageListener implements IWorldEventListener<SensorMessage> 148 // { 149 // 150 // @Override 151 // public void notify(SensorMessage event) 152 // { 153 // //rfidsensor uses null 154 // if(type == null || event.getType().equalsIgnoreCase(type)) 155 // lastMessage = event; 156 // } 157 // private String type = null; 158 // 159 // public SensorMessageListener(IWorldView worldView, String type) 160 // { 161 // this.type = type; 162 // worldView.addEventListener(SensorMessage.class, this); 163 // } 164 // } 165 //}