1 #*****************************************************************************
5 # Object Name : $RCSfile$
6 # Revision : $Revision$
9 # Created By : Robert Heller
10 # Created : Sun Jul 26 09:16:15 2015
11 # Last Modified : <150728.1943>
19 #*****************************************************************************
21 # Copyright (C) 2015 Robert Heller D/B/A Deepwoods Software
23 # Wendell, MA 01379-9728
25 # This program is free software; you can redistribute it and/or modify
26 # it under the terms of the GNU General Public License as published by
27 # the Free Software Foundation; either version 2 of the License, or
28 # (at your option) any later version.
30 # This program is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 # GNU General Public License for more details.
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write to the Free Software
37 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
41 #*****************************************************************************
44 package require Azatrax;# require the Azatrax
package
45 package require snit;# require the SNIT OO framework
48 ## @defgroup Azatrax_Signals Using SR4s to Operate Signals
49 # @brief Classes to operate signals using SR4s.
51 # This file contains code to operate various sorts of signals using Azatrax
54 # Typical wiring for LED common anode signals:
55 # @image html Azatrax_Signals-thumb.png
56 # @image latex Azatrax_Signals.png "Connecting a three LED common anode signal to a SR4." width=5in
57 # See the specific classes for how they expect the signals to be wired.
62 # @brief Basic signal colors.
63 # The four values are dark, red, yellow, and green.
66 ## Dark, all lamps off, implies red.
69 ## Red, generally stop or stop and proceed.
72 ## Yellow, generally approach.
75 ## Green, generally clear.
79 ## @brief Single head signals, 3 color.
81 # Typically used for simple block signals. One SR4, with Q1 connected to
82 # the top lamp (green), Q2 connected to the middle lamp (yellow), and
83 # Q3 connected to the bottom lamp (red).
88 # azatrax_signals::OneHead3Color blocksignal1 -signalsn 0400001234 -signalname Signal1
91 # @author Robert Heller \<heller\@deepsoft.com\>
93 # Azatrax related options
94 option -signalsn -readonly yes -
default {}
96 option -signalname -readonly yes -
default {}
99 ## @private Signal driver (SR4)
101 typemethod validate {
object} {
102 ## Type validating code
103 # Raises an error if object is not either the empty string or a
104 # OneHead3Color type object.
105 # @param object Some object.
108 return $object;# Empty or
null objects are OK
109 } elseif {[
catch {$object info type} itstype]} {
110 error
"$object is not a $type";#
object is not a SNIT type
111 } elseif {$itstype eq $type} {
112 return $object;# Object is of our type.
114 error
"$object is not a $type";#
object is something
else
119 ## @brief Constructor: initialize the signal object.
121 # Create a low level actuator object and install it as a component.
123 # @param name Name of the signal object.
124 # @param ... Options:
125 # @arg -signalsn Serial number of the SR4 that controls this signal.
126 # @arg -signalname Name of the signal on the track work schematic.
129 # Prefetch the -signalsn option.
130 set options(-signalsn) [from args -signalsn]
131 if {$options(-signalsn) eq {}} {
132 error
"The -signalsn option is required!"
134 install signal
using Azatrax_OpenDevice $options(-signalsn) \
135 $::Azatrax_idSR4Product
136 # Disconnect relays from inputs.
137 $signal OutputRelayInputControl 0 0 0 0
138 # Turn off all relays (set signal to dark aspect).
139 $signal RelaysOff 1 1 1 0
142 method setaspect {aspect} {
143 ## Set signal aspect.
145 # @param aspect New aspect color.
148 $signal RelaysOff 1 1 1 0
149 set sig [$self cget -signalname]
150 if {$sig ne {}} {MainWindow ctcpanel setv $sig $aspect}
153 $signal RelaysOn 0 0 1 0
156 $signal RelaysOn 0 1 0 0
159 $signal RelaysOn 1 0 0 0
166 ## @typedef twoaspectlist
167 # @brief Aspects for two headed signals.
168 # This is a list of two aspect colors, the first element for the upper head
169 # and the second element for the lower head.
171 snit::type TwoHead3over2 {
172 ## @brief Two head signals, 3 over 2.
174 # Typically used for simple interlocking signals. Two SR4s, with one
175 # driving the top head: with Q1 connected to the top lamp (green), Q2
176 # connected to the middle lamp (yellow), and Q3 connected to the bottom
177 # lamp (red). The second SR4 wired to the lower head, its Q1 connected to
178 # the top lamp (green or yellow), and Q2 to the bottom lamp (red).
183 # azatrax_signals::TwoHead3over2 interlocksignal1 \
184 # -signalsnupper 0400001234 \
185 # -signalsnlower 0400001235 \
186 # -signalname Signal1
189 # @author Robert Heller \<heller\@deepsoft.com\>
191 # Azatrax related options
192 option -signalsnupper -readonly yes -
default {}
193 option -signalsnlower -readonly yes -
default {}
195 option -signalname -readonly yes -
default {}
197 component signalupper
198 ## @private Signal driver (SR4)
199 component signallower
200 ## @private Signal driver (SR4)
202 typemethod validate {
object} {
203 ## Type validating code
204 # Raises an error if object is not either the empty string or a
205 # TwoHead3over2 type object.
206 # @param object Some object.
209 return $object;# Empty or
null objects are OK
210 } elseif {[
catch {$object info type} itstype]} {
211 error
"$object is not a $type";#
object is not a SNIT type
212 } elseif {$itstype eq $type} {
213 return $object;# Object is of our type.
215 error
"$object is not a $type";#
object is something
else
220 ## @brief Constructor: initialize the signal object.
222 # Create a low level actuator object and install it as a component.
224 # @param name Name of the signal object.
225 # @param ... Options:
226 # @arg -signalsnupper Serial number of the SR4 that controls the upper
227 # head of this signal.
228 # @arg -signalsnlower Serial number of the SR4 that controls the lower
229 # head of this signal.
230 # @arg -signalname Name of the signal on the track work schematic.
233 # Prefetch the -signalsnupper and -signalsnlower options.
234 set options(-signalsnupper) [from args -signalsnupper]
235 if {$options(-signalsnupper) eq {}} {
236 error
"The -signalsnupper option is required!"
238 set options(-signalsnlower) [from args -signalsnlower]
239 if {$options(-signalsnlower) eq {}} {
240 error
"The -signalsnlower option is required!"
242 install signalupper
using Azatrax_OpenDevice $options(-signalsnupper) \
243 $::Azatrax_idSR4Product
244 install signallower
using Azatrax_OpenDevice $options(-signalsnlower) \
245 $::Azatrax_idSR4Product
246 # Disconnect relays from inputs.
247 $signalupper OutputRelayInputControl 0 0 0 0
248 $signallower OutputRelayInputControl 0 0 0 0
249 # Turn off all relays (set signal to dark aspect).
250 $signalupper RelaysOff 1 1 1 0
251 $signallower RelaysOff 1 1 0 0
254 method setaspect {aspect} {
255 ## Set signal aspect.
257 # @param aspect New aspect color.
260 $signalupper RelaysOff 1 1 1 0
261 $signallower RelaysOff 1 1 0 0
262 set sig [$self cget -signalname]
263 if {$sig ne {}} {MainWindow ctcpanel setv $sig $aspect}
264 switch [lindex $aspect 0] {
266 $signalupper RelaysOn 0 0 1 0
269 $signalupper RelaysOn 0 1 0 0
272 $signalupper RelaysOn 1 0 0 0
275 switch [lindex $aspect 1] {
277 $signallower RelaysOn 0 1 0 0
281 # upper color (of lower head) is either green or yellow.
282 $signallower RelaysOn 1 0 0 0
289 snit::type TwoHead2over2 {
290 ## @brief Two head signals, 2 over 2.
292 # Typically used for simple interlocking signals. One SR4, driving both
293 # heads: with Q1 connected to the top lamp (green) or the top head, Q2
294 # connected to the bottom lamp (red) of the top head. Then Q3 connected to
295 # the top lamp (green or yellow) of othe lower head, and Q4 to the bottom
296 # lamp (red) of the lower head.
301 # azatrax_signals::TwoHead2over2 interlocksignal1 -signalsn 0400001234 \
302 # -signalname Signal1
305 # @author Robert Heller \<heller\@deepsoft.com\>
307 # Azatrax related options
308 option -signalsn -readonly yes -
default {}
310 option -signalname -readonly yes -
default {}
313 ## @private Signal driver (SR4)
315 typemethod validate {
object} {
316 ## Type validating code
317 # Raises an error if object is not either the empty string or a
318 # TwoHead2over2 type object.
319 # @param object Some object.
322 return $object;# Empty or
null objects are OK
323 } elseif {[
catch {$object info type} itstype]} {
324 error
"$object is not a $type";#
object is not a SNIT type
325 } elseif {$itstype eq $type} {
326 return $object;# Object is of our type.
328 error
"$object is not a $type";#
object is something
else
333 ## @brief Constructor: initialize the signal object.
335 # Create a low level actuator object and install it as a component.
337 # @param name Name of the signal object.
338 # @param ... Options:
339 # @arg -signals Serial number of the SR4
340 # @arg -signalname Name of the signal on the track work schematic.
343 # Prefetch the -signalsn option.
344 set options(-signalsn) [from args -signalsn]
345 if {$options(-signalsn) eq {}} {
346 error
"The -signalsn option is required!"
348 install signal
using Azatrax_OpenDevice $options(-signalsn) \
349 $::Azatrax_idSR4Product
350 # Disconnect relays from inputs.
351 $signal OutputRelayInputControl 0 0 0 0
352 # Turn off all relays (set signal to dark aspect).
353 $signal RelaysOff 1 1 1 1
356 method setaspect {aspect} {
357 ## Set signal aspect.
359 # @param aspect New aspect color.
362 $signal RelaysOff 1 1 1 1
363 set sig [$self cget -signalname]
364 if {$sig ne {}} {MainWindow ctcpanel setv $sig $aspect}
365 switch [lindex $aspect 0] {
367 $signal RelaysOn 0 1 0 0
371 # upper color (of the upper head) is green.
372 $signal RelaysOn 1 0 0 0
375 switch [lindex $aspect 1] {
377 $signal RelaysOn 0 0 0 1
381 # upper color (of the lower head) is either green or yellow.
382 $signal RelaysOn 0 0 1 0
390 ## @typedef threeaspectlist
391 # @brief Aspects for three headed signals.
392 # This is a list of three aspect colors, the first element for the upper head
393 # and the second element for the middle head, and finally the third element
394 # for the bottom head.
396 snit::type ThreeHead3over2over2 {
397 ## @brief Three head signals, 3 over 2 over 2.
399 # Typically used for simple interlocking signals. Two SR4s, with one
400 # driving the top head: with Q1 connected to the top lamp (green), Q2
401 # connected to the middle lamp (yellow), and Q3 connected to the bottom
402 # lamp (red). The second SR4 wired to the middle and lower heads, its Q1
403 # connected to the top lamp (green or yellow) of the middle head, and Q2
404 # to the bottom lamp (red) of the middle head. Then Q3 is connected to the
405 # top lamp (green or yellow) of the bottom head, and Q4 connected to the
406 # bottom lamp (red) of the bottom head.
411 # azatrax_signals::TwoHead3over2over2 interlocksignal1 \
412 # -signalsnupper 0400001234 \
413 # -signalsnlower 0400001235 \
414 # -signalname Signal1
417 # @author Robert Heller \<heller\@deepsoft.com\>
419 # Azatrax related options
420 option -signalsnupper -readonly yes -
default {}
421 option -signalsnlower -readonly yes -
default {}
423 option -signalname -readonly yes -
default {}
425 component signalupper
426 ## @private Signal driver (SR4)
427 component signallower
428 ## @private Signal driver (SR4)
430 typemethod validate {
object} {
431 ## Type validating code
432 # Raises an error if object is not either the empty string or a
433 # TwoHead3over2over2 type object.
434 # @param object Some object.
437 return $object;# Empty or
null objects are OK
438 } elseif {[
catch {$object info type} itstype]} {
439 error
"$object is not a $type";#
object is not a SNIT type
440 } elseif {$itstype eq $type} {
441 return $object;# Object is of our type.
443 error
"$object is not a $type";#
object is something
else
448 ## @brief Constructor: initialize the signal object.
450 # Create a low level actuator object and install it as a component.
452 # @param name Name of the signal object.
453 # @param ... Options:
454 # @arg -signalsnupper Serial number of the SR4 that controls the upper
455 # head of this signal.
456 # @arg -signalsnlower Serial number of the SR4 that controls the lower
457 # two heads of this signal.
458 # @arg -signalname Name of the signal on the track work schematic.
461 # Prefetch the -signalsnupper and -signalsnlower options.
462 set options(-signalsnupper) [from args -signalsnupper]
463 if {$options(-signalsnupper) eq {}} {
464 error
"The -signalsnupper option is required!"
466 set options(-signalsnlower) [from args -signalsnlower]
467 if {$options(-signalsnlower) eq {}} {
468 error
"The -signalsnlower option is required!"
470 install signalupper
using Azatrax_OpenDevice $options(-signalsnupper) \
471 $::Azatrax_idSR4Product
472 install signallower
using Azatrax_OpenDevice $options(-signalsnlower) \
473 $::Azatrax_idSR4Product
474 # Disconnect relays from inputs.
475 $signalupper OutputRelayInputControl 0 0 0 0
476 $signallower OutputRelayInputControl 0 0 0 0
477 # Turn off all relays (set signal to dark aspect).
478 $signalupper RelaysOff 1 1 1 0
479 $signallower RelaysOff 1 1 1 1
482 method setaspect {aspect} {
483 ## Set signal aspect.
485 # @param aspect New aspect color.
488 $signalupper RelaysOff 1 1 1 0
489 $signallower RelaysOff 1 1 1 1
490 set sig [$self cget -signalname]
491 if {$sig ne {}} {MainWindow ctcpanel setv $sig $aspect}
493 switch [lindex $aspect 0] {
495 $signalupper RelaysOn 0 0 1 0
498 $signalupper RelaysOn 0 1 0 0
501 $signalupper RelaysOn 1 0 0 0
505 switch [lindex $aspect 1] {
507 $signallower RelaysOn 0 1 0 0
511 # upper color (of lower head) is either green or yellow.
512 $signallower RelaysOn 1 0 0 0
516 switch [lindex $aspect 2] {
518 $signallower RelaysOn 0 0 0 1
522 # upper color (of lower head) is either green or yellow.
523 $signallower RelaysOn 0 0 1 0
535 package provide Azatrax_Signals 1.0
Single head signals, 3 color.
listtype threeaspectlist
Aspects for three headed signals.
listtype twoaspectlist
Aspects for two headed signals.
signalcolors
Basic signal colors.
@ yellow
Yellow, generally approach.
@ green
Green, generally clear.
@ dark
Dark, all lamps off, implies red.
@ red
Red, generally stop or stop and proceed.