2 * Created on Sep 19, 2005
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
8 package diku
.distlab
.motecontrolclientlib
.client
;
9 import diku
.distlab
.motecontrolclientlib
.protocols
.motecontrol
.*;
11 import java
.util
.Observable
;
12 import java
.util
.Observer
;
16 * TODO To change the template for this generated type comment go to
17 * Window - Preferences - Java - Code Style - Code Templates
19 public class SimpleMoteStatus
22 public static final short UNKNOWN
= MsgStatus
.UNKNOWN
;
23 public static final short UNAVAILABLE
= MsgStatus
.UNAVAILABLE
;
24 public static final short STOPPED
= MsgStatus
.STOPPED
;
25 public static final short RUNNING
= MsgStatus
.RUNNING
;
26 public static final short PROGRAMMING
= MsgStatus
.PROGRAMMING
;
29 public static final short INVALID
= 60;
30 public static final short REQ_STATUS
= 61;
31 public static final short REQ_START
= 62;
32 public static final short REQ_STOP
= 63;
33 public static final short REQ_RESET
= 64;
34 public static final short REQ_PROGRAM
= 65;
35 public static final short REQ_CANCELPROGRAMMING
= 66;
37 protected SimpleMote mote
;
38 protected short status
= 0;
39 protected short lastCommand
= -1;
40 protected short lastResult
= -1;
42 protected ExposedObservable eventDispatcher
= new ExposedObservable();
44 protected class ObserverWrapper
implements Observer
46 protected SimpleMoteStatusListener listener
;
47 protected SimpleMote mote
;
49 public ObserverWrapper(SimpleMote mote
, SimpleMoteStatusListener listener
)
52 this.listener
= listener
;
56 public void update(Observable o
, Object arg
) {
57 this.listener
.simpleMoteStatusChange(this.mote
);
61 protected SimpleMoteStatus(SimpleMote mote
)
67 public short getStatus() {
71 public boolean isReady()
73 return status
== RUNNING
||
74 status
== PROGRAMMING
||
75 status
== REQ_PROGRAM
||
80 public void addChangeListener(SimpleMoteStatusListener listener
)
82 eventDispatcher
.addWrappedObserver(listener
,new ObserverWrapper(this.mote
,listener
));
85 public void removeChangeListener(SimpleMoteStatusListener listener
)
87 eventDispatcher
.deleteWrappedObserver(listener
);
90 protected void setStatus(short status
)
93 this.fireChangeEvent();
96 public short getLastCommand() {
101 public short getLastResult() {
106 protected void update(MsgConfirm confirm
)
108 this.lastResult
= confirm
.getResult().getValue();
109 this.lastCommand
= confirm
.getCommand().getValue();
110 this.status
= confirm
.getStatus().getValue();
111 this.fireChangeEvent();
114 protected void update(MsgRequest request
)
116 switch (request
.getCommand().getValue())
118 case MsgCommand
.PROGRAM
:
119 this.status
= REQ_PROGRAM
;
121 case MsgCommand
.CANCELPROGRAMMING
:
122 this.status
= REQ_CANCELPROGRAMMING
;
124 case MsgCommand
.RESET
:
125 this.status
= REQ_RESET
;
127 case MsgCommand
.START
:
128 this.status
= REQ_START
;
130 case MsgCommand
.STATUS
:
131 this.status
= REQ_STATUS
;
133 case MsgCommand
.STOP
:
134 this.status
= REQ_STOP
;
137 this.status
= INVALID
;
139 this.fireChangeEvent();
142 protected void fireChangeEvent()
144 this.eventDispatcher
.setChanged();
145 this.eventDispatcher
.notifyObservers();