View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.agent.module.state;
2   
3   import cz.cuni.amis.pogamut.usar2004.agent.module.datatypes.VehicleType;
4   import cz.cuni.amis.pogamut.usar2004.communication.messages.usarinfomessages.StateMessage;
5   
6   /**
7    * Parent class for all possible state subjects. It covers the basic and common
8    * properties for all the state subjects.
9    *
10   * @author vejmanm
11   */
12  public /*
13           * abstract
14           */ class SuperState
15  {
16      protected StateMessage lastMessage;
17      protected VehicleType vehicleType;
18  
19      /**
20       * Ctor. State type describes particular subject about which we want to know
21       * about. It is used to distinguish incoming message from the server.
22       */
23      public SuperState()
24      {
25          this(VehicleType.UNKNOWN);
26      }
27  
28      /**
29       * Ctor.
30       *
31       * @param type Configuration type describes particular subject about which
32       * we want to know about. It is used to distinguish incoming message from
33       * the server.
34       */
35      protected SuperState(VehicleType type)
36      {
37          this.vehicleType = type;
38      }
39  
40  //    @Override
41  //    protected void cleanUp()
42  //    {
43  //        super.cleanUp();
44  //        bot=null;
45  //        lastMessage = null;
46  //        sensorType=null;
47  //    }
48      /**
49       * Method used for updating the message object that provides particular
50       * properties for given type. Note that this object is created by yylex
51       * parser and contains properties for all configuration subject types. But
52       * only relevat to individual Config Subject are filled.
53       *
54       * @param message State message from server.
55       */
56      public void updateMessage(StateMessage message)
57      {
58          //if(message.getType().equalsIgnoreCase(SensorType))
59          lastMessage = message;
60      }
61  
62      /**
63       * Timestamp form the UT since server start in seconds.
64       *
65       * @return Returns seconds elapsed from the start of the server.
66       */
67      public double getTime()
68      {
69          return lastMessage.getTime();
70      }
71  
72      /**
73       * Used to make sure the object is filled.
74       *
75       * @return Returns true if the object is filled with State message.
76       */
77      public Boolean isReady()
78      {
79          return (lastMessage != null);
80      }
81  
82      /**
83       * Type will be one of the following values: "GroundVehicle”, “LeggedRobot”,
84       * “NauticVehicle”, or “AerialVehicle”.
85       *
86       * @return Returns Type of the vehicle.
87       */
88      public String getType()
89      {
90          return lastMessage.getType();
91      }
92  
93      /**
94       * Power state of the battery. It is the battery lifetime in second. It’s
95       * the total time remaining for the robot to run.
96       *
97       * @return Returns remaining battery life.
98       */
99      public int getBattery()
100     {
101         return lastMessage.getBattery();
102     }
103 
104     /**
105      * Light intensity of the headlight. Right now, it always is 100.
106      *
107      * @return Returns the intensity of the Headlight.
108      */
109     public int getFlashLightIntensity()
110     {
111         return lastMessage.getLightIntensity();
112     }
113 
114     /**
115      * Indicate whether the headlight has been turned on.
116      *
117      * @return Returns wether the Headlight is on or not.
118      */
119     public boolean isFlashLightToogle()
120     {
121         return lastMessage.isLightToggle();
122     }
123 
124     /**
125      * VehicleType is a descriptor used for creating particular instance and for
126      * getting type information about particular state subject.
127      *
128      * @return Returns VehicleType.
129      */
130     public VehicleType getVehicleType()
131     {
132         return vehicleType;
133     }
134 }