-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRigControl.py
executable file
·301 lines (245 loc) · 9.98 KB
/
RigControl.py
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#
# WB1FJ Antenna Control
#
# This is a GUI to control relays that switch a software defined
# radio connected to a telemetry computer and a TS-2000 among an
# omni dual band satellite antenna, an LEO Pack 70cm and 2m beam,
# and a dual-band J-pole for local work
#
#Relays:
#
#Preamp70: Preamp on 70cm Beam
#Preamp2m: Preamp on 2m Beam
#Beam70: Switch 70cm Beam to TS2K bus or SDR Bus
#Beam2m: Switch 2m Beam to TS2K bus or SDR Bus
#TS2K: Switch TS-2000 to TS2K bus or dual band J-pole
#SDR: Switch SDR to SDR Bus or Lindenblad (Omni)
#
# Button Relay States
#
#U/v Satellite COM: Preamp70: off
# Preamp2m: on
# Beam70: TS2K Bus
# Beam2m: TS2K Bus
# TS2K: TS2K
# SDR: Omni
#
#V/u Satellite COM: Preamp70 on
# Preamp2m off
# Beam70: TS2K Bus
# Beam2m: TS2K Bus
# TS2K: TS2K
# SDR: Omni
#
#Local Repeater: Preamp70 off
# Preamp2m off
# Beam70: TS2K Bus
# Beam2m: TS2K Bus
# TS2K: J-pole
# SDR: Omni
#
#UHF Beam Telem: Preamp70: on
# Preamp2m: off
# Beam70: SDR Bus
# Beam2m: TS2K Bus
# TS2K: TS2K Bus
# SDR: SDR Bus
#
#VHF Beam Telem: Preamp70 off
# Preamp2m on
# Beam70: TS2K Bus
# Beam2m: SDR Bus
# TS2K: TS2K
# SDR: SDR Bus
UDP_IP = ""
UDP_PORT = 9932
#import tkinter as tk
import tkinter as tk
import RPi.GPIO as GPIO
import time
import sys
import socket
DebugRelaySet = False #Set true to get some printouts
class Relay: #This is for the Sunfounder/Huayao relay board where a high GPIO turns the relay coil off.
# If you create a Relay instance with a checkbutton, that checkbutton is activated or deactivated
# when the relay is turned on or off
def __init__(self,gpioNum1,initialState,checkbutton=None):
self.gpioNum = gpioNum1
GPIO.setup(self.gpioNum,GPIO.OUT)
self.fixButton=checkbutton
self.set(initialState)
def setAssociatedButton(self,button):
#Associated Button's select or deselect method is called to match this
#relay's state. It also let's the button turn the relay on and off
#rather than doing it here.
self.fixButton=button
def setOnly(self,state):
#Set the relay without calling the button method. Used by the button method itself
self.state= state
GPIO.output(self.gpioNum,not self.state) #High for off, low for on
def set(self,state):
self.setOnly(state)
if self.fixButton is not None:
if state:
self.fixButton.select()
else:
self.fixButton.deselect()
def get(self):
return self.state
#Define values for the relays that name the purpose for the relay in that position
On=True #For Preamps (Default)
Off=False
TS2K=False #For Beam Bus TS2K End (Default)
SDR=True
Beam=True #For TS2k and SDR
JPole=False #For TS2K
Omni=False #For SDR
## GUI definitions
#Button Values
UvButtonNum=0
VuButtonNum=1
RepeaterButtonNum=2
UHFTlmButtonNum=3
VHFTlmButtonNum=4
VUTlmButtonNum=5
#Callback routines for checkbuttons. They set the relay to the value of the checkbox
def Switch2mPreamp():
RelayList[relayPreamp2m].setOnly(P2mValue.get()==1)
def Switch70Preamp():
RelayList[relayPreamp70].setOnly(P70Value.get()==1)
#Define the relay index numbers for various relays
relayPreamp70 = 0
relayPreamp2m = 1 #ok
relay2mBeamTS2KorSDR = 2 #Ok
relay70BeamTS2KorSDR = 3 #ok
relayTS2KbeamOrJPole = 4 #ok
relaySDRbeamOrOmni = 5 #ok
GPIO.setmode(GPIO.BOARD) #Define GPIOs by board pin number
#Now define the pin numbers for each relay index
#relayPinNumbers=[5,7,11,13,15,8]
relayPinNumbers=[37,40,29,31,33,35] #These are for PiZero with SPI Screen
#Now create the relay objects for each relay
RelayList = []
for i in range (0,len(relayPinNumbers)):
RelayList.append(Relay(relayPinNumbers[i],False))
#The following table tells what values to set each relay (columns) to for each configuration(row)
#Row numbers have to match the value passed to the variable in the radio buttons; column number
#must match the order of the relays in RelayList
RelayActionsForButton = [
#70Pre 2mPre 2mBeam 70Beam TS2KAnt SDRAnt Spares <-Relays
[Off, On, TS2K, TS2K, Beam, Omni, Off, Off], #UVButton
[On, Off, TS2K, TS2K, Beam, Omni, Off, Off], #VUButton
[Off, Off, TS2K, TS2K, JPole, Omni, Off, Off], #Repeater
[On, Off, TS2K, SDR, Beam, Beam, Off, Off], #UTelemButton
[Off, On, SDR, TS2K, Beam, Beam, Off, Off], #VTelemButton
[On, On, SDR, SDR, JPole, Beam, Off, Off] #VUTelemButton
]
#Here are callback routines for all the buttons and checkboxes
def Leave(): #This one is for the exit radio button
GPIO.cleanup()
sys.exit(1)
def RelayGroupSwitch(): #This is for all other radio buttons
thisButtonIndex = CurrentButton.get()
if(DebugRelaySet):
print("Button number ",thisButtonIndex)
RelaySettings = RelayActionsForButton[thisButtonIndex]
for i in range(len(RelayList)):
thisRelay = RelayList[i]
thisRelay.set(RelaySettings[i])
if(DebugRelaySet):
print("Setting relay",i, "to", RelaySettings[i])
#Here is where we set up the layout for the screen
win = tk.Tk()
#win.geometry("200x200")
win.title("WB1FJ Antenna Switcher")
CurrentButton=tk.IntVar()
tk.Label(win,text="Configuration:").grid(row=0,columnspan=2,sticky=tk.W)
#Here are 2 checkboxes for preamps that are overrides of the standard values for a confiruration.
#For example, you can turn on the preamp while in the local repeater configuration.
tk.Label(win,text="Preamp Override:").grid(row=8,column=0,sticky=tk.E)
tk.Label(win,text="________________________________________________________________________________").grid(row=7,column=0,columnspan=2)
P70Value = tk.IntVar()
Preamp70Button = tk.Checkbutton(win,text="70Cm",variable=P70Value,command=Switch70Preamp)
Preamp70Button.grid(column=1,row=8)
P2mValue=tk.IntVar()
Preamp2mButton = tk.Checkbutton(win,text="2M",variable=P2mValue,command=Switch2mPreamp)
Preamp2mButton.grid(column=1,row=8,sticky=tk.W)
RelayList[relayPreamp70].setAssociatedButton(Preamp70Button) #Make sure when a configuration sets one of these relays,---
RelayList[relayPreamp2m].setAssociatedButton(Preamp2mButton) #...the checkbox matches
# Here are the radio buttons that let you choose the configuration--only one is active at a time.
SatComUvButton = tk.Radiobutton(win,text = "U/v Satcom",command=RelayGroupSwitch,selectcolor="Red")
SatComUvButton.config(variable=CurrentButton,value=UvButtonNum,indicatoron=False,width=30,pady=20)
SatComUvButton.grid(row=4,column=0)
SatComVuButton = tk.Radiobutton(win,text = "V/u Satcom",command=RelayGroupSwitch,selectcolor="Red")
SatComVuButton.grid(row=4,column=1,columnspan=1)
SatComVuButton.config(variable=CurrentButton,value=VuButtonNum,indicatoron=False,width=30,pady=20)
RepeaterButton = tk.Radiobutton(win,text = "Local Repeater",command=RelayGroupSwitch,selectcolor="Red")
RepeaterButton.grid(row=6,column=0,columnspan=1)
RepeaterButton.config(variable=CurrentButton,value=RepeaterButtonNum,indicatoron=False,width=30,pady=20)
SatTlmVButton = tk.Radiobutton(win,text = "VHF Telemetry",command=RelayGroupSwitch,selectcolor="Red")
SatTlmVButton.grid(row=5,column=0,columnspan=1)
SatTlmVButton.config(variable=CurrentButton,value=VHFTlmButtonNum,indicatoron=False,width=30,pady=20)
SatTlmUButton = tk.Radiobutton(win,text = "UHF Telemetry",command=RelayGroupSwitch,selectcolor="Red")
SatTlmUButton.grid(row=5,column=1,columnspan=1)
SatTlmUButton.config(variable=CurrentButton,value=UHFTlmButtonNum,indicatoron=False,width=30,pady=20)
SatTlmVUButton = tk.Radiobutton(win,text = "VU Telemetry",command=RelayGroupSwitch,selectcolor="Red")
SatTlmVUButton.grid(row=6,column=1,columnspan=1)
SatTlmVUButton.config(variable=CurrentButton,value=VUTlmButtonNum,indicatoron=False,width=30,pady=20)
ExitButton = tk.Radiobutton(win,text = "Exit",command=Leave,variable=CurrentButton,value=99,indicatoron=False)
ExitButton.grid(row=8,column=0,sticky=tk.W)
#Set the default button
CurrentButton.set(RepeaterButtonNum)
RelayGroupSwitch() #Set up everything for the above default button
DebugRelayID = False
#This is to make sure we know which relay is which
if DebugRelayID:
for i in range(len(RelayList)):
thisRelay = RelayList[i]
thisRelay.set(True)
print("Setting relay",i, "to True")
time.sleep(1)
for i in range(len(RelayList)):
thisRelay = RelayList[i]
thisRelay.set(False)
print("Setting relay",i, "to False")
time.sleep(1)
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
sock.settimeout(.1)
while 1:
win.update() # This allows me to do something else besides Tk. Equiv to mainloop, but it returns
try:
databytes, addr = sock.recvfrom(128) # buffer size is 128 bytes
datastr = (databytes.decode('UTF-8'))
#print("UDP message:",datastr)
strList=datastr.split(',')
#print(strList)
if(strList[0] == "SAT" and strList[1]=="TRANSPONDER"):
#This would be for the CSN Technologies SAT device
downlink = int(float(strList[5]))/1000000 #Make it in MHz
else:
#This is for MacDoppler, but it requires a script that WB1FJ wrote
downlink = int(float(strList[1]))
print("Downlink is ",downlink)
curBut = CurrentButton.get()
if (downlink < 400):
if(curBut == VuButtonNum):
CurrentButton.set(UvButtonNum)
if(curBut == UHFTlmButtonNum):
CurrentButton.set(VHFTlmButtonNum)
if (downlink >= 400):
if(curBut == UvButtonNum):
CurrentButton.set(VuButtonNum)
if(curBut == VHFTlmButtonNum):
CurrentButton.set(UHFTlmButtonNum)
RelayGroupSwitch();
except:
pass
#win.mainloop()
UvButtonNum=0
VuButtonNum=1
RepeaterButtonNum=2
UHFTlmButtonNum=3
VHFTlmButtonNum=4
VUTlmButtonNum=5