001package jmri.jmrix.roco.z21;
002
003/**
004 * Defines the standard/common routines used in multiple classes related to 
005 * a Roco z21 Command Station.
006 * <p>
007 * This class keeps track of the broadcast flags associated with the 
008 * currently connected Roco Z21 Command Station.
009 * <p>
010 * Brief descriptions of the flags are as follows (loosely
011 * translated from  section 2.16 of the manual from the German 
012 * with the aid of google translate).
013 * <ul>
014 * <li>0x00000001 send XpressNet related information (track
015 * power on/off, programming mode, short circuit, broadcast stop,
016 * locomotive information, turnout information).</li>
017 * <li>0x00000002 send data changes that occur on the RMBUS.</li>
018 * <li>0x00000004 (deprecated by Roco) send Railcom Data</li>
019 * <li>0x00000100 send changes in system state (such as track voltage)
020 * <li>0x00010000 send changes to locomotives on XpressNet (must also have
021 * 0x00000001 set.</li>
022 * <li>0x01000000 forward LocoNet data to the client.  Does not send
023 * Locomotive or turnout data.</li>
024 * <li>0x02000000 send Locomotive specific LocoNet data to the client.</li>
025 * <li>0x04000000 send Turnout specific LocoNet data to the client.</li>
026 * <li>0x08000000 send Occupancy information from LocoNet to the client</li>
027 * <li>0x00040000 Automatically send updates for Railcom data to the client</li>
028 * <li>0x00080000 send can detector messages to the client</li>
029 * </ul>
030 *
031 * @author Bob Jacobsen Copyright (C) 2001 
032 * @author      Paul Bender Copyright (C) 2016
033 */
034public class RocoZ21CommandStation extends jmri.jmrix.roco.RocoCommandStation {
035
036    private int broadcast_flags = 0; // holds the value of the broadcast flags.
037    private int serial_number = 0; // holds the serial number of the Z21.
038    private float software_version = 0; // holds the software version of the Z21.
039    private int hardware_version = 0; // holds the hardware version of the Z21.
040
041   /**
042    * get the serial number.
043    * @return serial number of the connected Z21 command station
044    */
045   public int getSerialNumber(){
046      return serial_number;
047   }
048
049   /**
050    * set the serial number associated with this Z21 command station.
051    * @param sn serial number
052    */
053   public void setSerialNumber(int sn){
054      serial_number = sn;
055   }
056 
057  /**
058    * get the software version.
059    * @return software version of the connected Z21 command station
060    */
061   public float getSoftwareVersion(){
062      return software_version;
063   }
064
065   /**
066    * set the software version associated with this Z21 command station.
067    * @param sv software version
068    */
069   public void setSoftwareVersion(float sv){
070      software_version=sv;
071   }
072
073  /**
074    * get the hardware version.
075    * @return hardware version of the connected Z21 command station
076    */
077   public int getHardwareVersion(){
078      return hardware_version;
079   }
080
081   /**
082    * set the hardware version associated with this Z21 command station.
083    * @param hv software version
084    */
085   public void setHardwareVersion(int hv){
086      hardware_version=hv;
087   }
088
089   /**
090    * get the current value of the broadcast flags as an int
091    * @return value representing the broadcast flags. 
092    */
093   public int getZ21BroadcastFlags(){
094        return broadcast_flags;
095   }
096
097   /**
098    * set the current value of the broadcast flags as an int
099    * @param flags representing the broadcast flags. 
100    */
101   public void setZ21BroadcastFlags(int flags){
102        broadcast_flags = flags;
103   }
104
105   /**
106    * Is flag bit 0x00000001 which tells the command station to send 
107    * XpressNet related information (track power on/off, programming
108    * mode, short circuit, broadcast stop, locomotive information, 
109    * turnout information) set?
110    * @return true if flag is set.
111    */
112    public boolean getXPressNetMessagesFlag(){
113        return((broadcast_flags & 0x00000001) == 0x00000001);
114    }
115
116   /**
117    * Set flag bit 0x00000001 which tells the command station to send 
118    * XpressNet related information (track power on/off, programming
119    * mode, short circuit, broadcast stop, locomotive information, 
120    * turnout information).
121    * @param flag true if flag is to be set.
122    */
123    public void setXPressNetMessagesFlag(boolean flag){
124        if(flag) {
125           broadcast_flags = broadcast_flags | 0x00000001;
126        }
127        else {
128           broadcast_flags = broadcast_flags & (~(0x00000001));
129        }
130    }
131
132   /**
133    * Is flag bit 0x00000002 which tells the command station to send 
134    * data changes on the RMBus to the client set?
135    * @return true if flag is set.
136    */
137    public boolean getRMBusMessagesFlag(){
138        return((broadcast_flags & 0x00000002) == 0x00000002);
139    }
140
141   /**
142    * Set flag bit 0x00000002 which tells the command station to send 
143    * data changes on the RMBus to the client set?
144    * @param flag true if flag is to be set.
145    */
146    public void setRMBusMessagesFlag(boolean flag){
147        if(flag) {
148           broadcast_flags = broadcast_flags | 0x00000002;
149        }
150        else {
151           broadcast_flags = broadcast_flags & (~(0x00000002));
152        }
153    }
154
155   /**
156    * Is flag bit 0x00000004, which tells the command station to 
157    * send Railcom data to the client set (this flag may no longer
158    * be supported by Roco). 
159    * @return true if flag is set.
160    */
161    public boolean getRailComMessagesFlag(){
162        return((broadcast_flags & 0x00000004) == 0x00000004);
163    }
164
165   /**
166    * Set flag bit 0x00000004, which tells the command station to 
167    * send Railcom data to the client set (this flag may no longer
168    * be supported by Roco). 
169    * @param flag true if flag is to be set.
170    */
171    public void setRailComMessagesFlag(boolean flag){
172        if(flag) {
173           broadcast_flags = broadcast_flags | 0x00000004;
174        }
175        else {
176           broadcast_flags = broadcast_flags & (~(0x00000004));
177        }
178    }
179
180   /**
181    * Is flag bit 0x00040000, which tells the command station to 
182    * automatically send Railcom data to the client set. 
183    * @return true if flag is set.
184    */
185    public boolean getRailComAutomaticFlag(){
186        return((broadcast_flags & 0x00040000) == 0x00040000);
187    }
188
189   /**
190    * Set flag bit 0x00040000, which tells the command station to 
191    * automatically send Railcom data to the client set. 
192    * @param flag true if flag is to be set.
193    */
194    public void setRailComAutomaticFlag(boolean flag){
195        if(flag) {
196           broadcast_flags = broadcast_flags | 0x00040000;
197        }
198        else {
199           broadcast_flags = broadcast_flags & (~(0x00040000));
200        }
201    }
202
203   /**
204    * Is flag bit 0x00080000, which tells the command station to 
205    * send CAN detector data to the client set. 
206    * @return true if flag is set.
207    */
208    public boolean getCanDetectorFlag(){
209        return((broadcast_flags & 0x00080000) == 0x00080000);
210    }
211
212   /**
213    * Set flag bit 0x00080000, which tells the command station to 
214    * send CAN detector data to the client. 
215    * @param flag true if flag is to be set.
216    */
217    public void setCanDetectorFlag(boolean flag){
218        if(flag) {
219           broadcast_flags = broadcast_flags | 0x00080000;
220        }
221        else {
222           broadcast_flags = broadcast_flags & (~(0x00080000));
223        }
224    }
225
226
227
228   /**
229    * Is flag bit 0x00000100 which tells the command station to send 
230    * changes in system state (such as track voltage) set?
231    * @return true if flag is set.
232    */
233    public boolean getSystemStatusMessagesFlag(){
234        return((broadcast_flags & 0x00000100) == 0x00000100);
235    }
236
237   /**
238    * Set flag bit 0x00000100 which tells the command station to send 
239    * changes in system state (such as track voltage).
240    * @param flag true if flag is to be set.
241    */
242    public void setSystemStatusMessagesFlag(boolean flag){
243        if(flag) {
244           broadcast_flags = broadcast_flags | 0x00000100;
245        }
246        else {
247           broadcast_flags = broadcast_flags & (~(0x00000100));
248        }
249    }
250
251   /**
252    * Is flag bit 0x00010000 which tells the command station to send 
253    * XpressNet related locomoitve information to the client set?
254    *
255    * @return true if flag is set
256    */
257    public boolean getXPressNetLocomotiveMessagesFlag(){
258        return((broadcast_flags & 0x00010000) == 0x00010000);
259    }
260
261   /**
262    * Set flag bit 0x00010000 which tells the command station to send 
263    * XpressNet related locomoitve information to the client.
264    * @param flag true if flag is to be set.
265    */
266    public void setXPressNetLocomotiveMessagesFlag(boolean flag){
267        if(flag) {
268           broadcast_flags = broadcast_flags | 0x00010000;
269        }
270        else {
271           broadcast_flags = broadcast_flags & (~(0x00010000));
272        }
273    }
274
275   /**
276    * Is flag bit 0x01000000 which tells the command station to send 
277    * LocoNet data,except Locomotive and Turnout data, to the client set?
278    * @return true if flag is set.
279    */
280    public boolean getLocoNetMessagesFlag(){
281        return((broadcast_flags & 0x01000000) == 0x01000000);
282    }
283
284   /**
285    * Set flag bit 0x01000000 which tells the command station to send
286    * LocoNet data,except Locomotive and Turnout data, to the client.
287    * @param flag true if flag is to be set.
288    */
289    public void setLocoNetMessagesFlag(boolean flag){
290        if(flag) {
291           broadcast_flags = broadcast_flags | 0x01000000;
292        }
293        else {
294           broadcast_flags = broadcast_flags & (~(0x01000000));
295        }
296    }
297
298   /**
299    * Is flag bit 0x02000000 which tells the command station to send 
300    * Locomotive specific LocoNet data to the client set?
301    * @return true if flag is set.
302    */
303    public boolean getLocoNetLocomotiveMessagesFlag(){
304        return((broadcast_flags & 0x02000000) == 0x02000000);
305    }
306
307   /**
308    * Set flag bit 0x02000000 which tells the command station to send 
309    * Locomotive specific LocoNet data to the client.
310    * @param flag true if flag is to be set.
311    */
312    public void setLocoNetLocomotiveMessagesFlag(boolean flag){
313        if(flag) {
314           broadcast_flags = broadcast_flags | 0x02000000;
315        }
316        else {
317           broadcast_flags = broadcast_flags & (~(0x02000000));
318        }
319    }
320
321   /**
322    * Is flag bit 0x04000000 which tells the command station to send 
323    * Turnout specific LocoNet data to the client set?
324    * @return true if flag is set.
325    */
326    public boolean getLocoNetTurnoutMessagesFlag(){
327        return((broadcast_flags & 0x04000000) == 0x04000000);
328    }
329
330   /**
331    * Set flag bit 0x04000000 which tells the command station to send 
332    * Turnout specific LocoNet data to the client set?
333    * @param flag true if flag is to be set.
334    */
335    public void setLocoNetTurnoutMessagesFlag(boolean flag){
336        if(flag) {
337           broadcast_flags = broadcast_flags | 0x04000000;
338        }
339        else {
340           broadcast_flags = broadcast_flags & (~(0x04000000));
341        }
342    }
343
344   /**
345    * Is flag bit 0x08000000 which tells the command station to send 
346    * Occupancy information from LocoNet to the client set?
347    * @return true if flag is set.
348    */
349    public boolean getLocoNetOccupancyMessagesFlag(){
350        return((broadcast_flags & 0x08000000) == 0x08000000);
351    }
352
353   /**
354    * <p>
355    * Set flag bit 0x08000000 which tells the command station to send 
356    * Occupancy information from LocoNet to the client
357    * </p>
358    * <p>
359    * If this flag is set to true, the Z21 will format Transponding messages
360    * as described in section 9.5 of the Z21 Lan Protocol.  This message format
361    * is currentlyunsupported by JMRI.
362    * </p>
363    *
364    * @param flag true if flag is to be set.
365    */
366    public void setLocoNetOccupancyMessagesFlag(boolean flag){
367        if(flag) {
368           broadcast_flags = broadcast_flags | 0x08000000;
369        }
370        else {
371           broadcast_flags = broadcast_flags & (~(0x08000000));
372        }
373    }
374
375}