-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathModuleRemoteRelay.tcl
More file actions
216 lines (182 loc) · 4.92 KB
/
ModuleRemoteRelay.tcl
File metadata and controls
216 lines (182 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
###############################################################################
#
# RemoteRelay module implementation by F8ASB (F8ASB.COM)
# Activating RemoteRelay Module 9#
# Remote 4 relays on Pin 20,21,22,23 of the Raspberry
# 3 choices:
# OFF = 0 ON = 1 PULSE 100ms = 2
# For example: 201# -> put ON Relay K1
# 20 (gpio from relay) + choice
###############################################################################
#
# This is the namespace in which all functions and variables below will exist.
# The name must match the configuration variable "NAME" in the
# [ModulePropagationMonitor] section in the configuration file. The name may
# be changed but it must be changed in both places.
#
namespace eval RemoteRelay {
#
# Check if this module is loaded in the current logic core
#
if {![info exists CFG_ID]} {
return;
}
#
# Extract the module name from the current namespace
#
set module_name [namespace tail [namespace current]]
#
# A convenience function for printing out information prefixed by the
# module name
#
# msg - The message to print
#
proc printInfo {msg} {
variable module_name
puts "$module_name: $msg"
}
#
# A convenience function for calling an event handler
#
# ev - The event string to execute
#
proc processEvent {ev} {
variable module_name
::processEvent "$module_name" "$ev"
}
#
# Executed when this module is being activated
#
proc activateInit {} {
printInfo "Module activated"
}
#
# Executed when this module is being deactivated.
#
proc deactivateCleanup {} {
printInfo "Module deactivated"
}
#
# Executed when a DTMF digit (0-9, A-F, *, #) is received
#
# char - The received DTMF digit
# duration - The duration of the received DTMF digit
#
proc dtmfDigitReceived {char duration} {
printInfo "DTMF digit $char received with duration $duration milliseconds"
}
#
# Executed when a DTMF command is received
#
# cmd - The received DTMF command
#
proc dtmfCmdReceived {cmd} {
printInfo "DTMF command received: $cmd"
# ON command 201 211 221 231
if {$cmd == "201"} {
printInfo "Relay K1 ON"
playMsg "relay1on";
puts "Executing external command"
exec gpio -g write 20 1 &
} elseif {$cmd == "211"} {
printInfo "Relay K2 ON"
playMsg "relay2on";
puts "Executing external command"
exec gpio -g write 21 1 &
} elseif {$cmd == "221"} {
printInfo "Relay K3 ON"
playMsg "relay3on";
puts "Executing external command"
exec gpio -g write 22 1 &
} elseif {$cmd == "231"} {
printInfo "Relay K4 ON"
playMsg "relay4on";
puts "Executing external command"
exec gpio -g write 23 1 &
#OFF command 200 210 220 230
} elseif {$cmd == "200"} {
printInfo "Relay K1 OFF"
playMsg "relay1off";
puts "Executing external command"
exec gpio -g write 20 0 &
} elseif {$cmd == "210"} {
printInfo "Relay K2 OFF"
playMsg "relay2off";
puts "Executing external command"
exec gpio -g write 21 0 &
} elseif {$cmd == "220"} {
printInfo "Relay K3 OFF"
playMsg "relay3off";
puts "Executing external command"
exec gpio -g write 22 0 &
} elseif {$cmd == "230"} {
printInfo "Relay K4 OFF"
playMsg "relay4off";
puts "Executing external command"
exec gpio -g write 23 0 &
# PULSE command 202 212 222 232
} elseif {$cmd == "202"} {
printInfo "Relay K1 PULSE"
playMsg "relay1pulse";
puts "Executing external command"
exec gpio -g write 20 1 &
after 100
exec gpio -g write 20 0 &
} elseif {$cmd == "212"} {
printInfo "Relay K2 PULSE"
playMsg "relay2pulse";
puts "Executing external command"
exec gpio -g write 21 1 &
after 100
exec gpio -g write 21 0 &
} elseif {$cmd == "222"} {
printInfo "Relay K3 PULSE"
playMsg "relay3pulse";
puts "Executing external command"
exec gpio -g write 22 1 &
after 100
exec gpio -g write 22 0 &
} elseif {$cmd == "232"} {
printInfo "Relay K4 PULSE"
playMsg "relay4pulse";
puts "Executing external command"
exec gpio -g write 23 1 &
after 100
exec gpio -g write 23 0 &
} elseif {$cmd == ""} {
deactivateModule
} else {
processEvent "unknown_command $cmd"
}
}
#
# Executed when a DTMF command is received in idle mode. That is, a command is
# received when this module has not been activated first.
#
# cmd - The received DTMF command
#
proc dtmfCmdReceivedWhenIdle {cmd} {
printInfo "DTMF command received when idle: $cmd"
}
#
# Executed when the squelch open or close.
#
# is_open - Set to 1 if the squelch is open otherwise it's set to 0
#
proc squelchOpen {is_open} {
if {$is_open} {set str "OPEN"} else { set str "CLOSED"}
printInfo "The squelch is $str"
}
#
# Executed when all announcement messages has been played.
# Note that this function also may be called even if it wasn't this module
# that initiated the message playing.
#
proc allMsgsWritten {} {
printInfo "Test allMsgsWritten called..."
}
# end of namespace
}
#
# This file has not been truncated
#