-
Notifications
You must be signed in to change notification settings - Fork 87
/
dtmf_aprs_cc.py
200 lines (184 loc) · 4.96 KB
/
dtmf_aprs_cc.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
import sys
from os import system
import RPi.GPIO as GPIO
from RPi.GPIO import output
from time import sleep
import logging
logging.basicConfig(format='%(message)s')
# logging.warning('CC-Warning!')
if __name__ == "__main__":
powerPin = 16
txLed = 27
change_mode = False
debug_mode = False
counter = 1
if (len(sys.argv)) > 1:
# print("There are arguments!")
if ('d' == sys.argv[1]):
debug_mode = True
for line in sys.stdin:
# if (debug_mode):
print(line, end =" ")
logging.warning(line)
# if '^c' == line.rstrip():
# break
if ((line.find("MODE=a")) > 0):
system("echo '\nAPRS Mode!!\n'")
mode = 'a'
change_mode = True
counter = (counter + 1) % 2
if ((line.find("DTMF>APDW15:t1#")) > 0):
system("echo '\nAPRS Mode!!\n'")
mode = 'a'
change_mode = True
if ((line.find("MODE=f")) > 0):
system("echo '\nFSK Mode!!\n'")
mode = 'f'
change_mode = True
counter = (counter + 1) % 2
if ((line.find("DTMF>APDW15:t2#")) > 0):
system("echo '\nFSK Mode!!\n'")
mode = 'f'
change_mode = True
if ((line.find("MODE=b")) > 0):
system("echo '\nBPSK Mode!!\n'")
mode = 'b'
change_mode = True
counter = (counter + 1) % 2
if ((line.find("DTMF>APDW15:t3#")) > 0):
system("echo '\nBPSK Mode!!\n'")
mode = 'b'
change_mode = True
if ((line.find("MODE=s")) > 0):
system("echo '\nSSTV Mode!!\n'")
mode = 's'
change_mode = True
counter = (counter + 1) % 2
if ((line.find("DTMF>APDW15:t4#")) > 0):
system("echo '\nSSTV Mode!!\n'")
mode = 's'
change_mode = True
if ((line.find("MODE=m")) > 0):
system("echo '\nCW Mode!!\n'")
mode = 'm'
change_mode = True
counter = (counter + 1) % 2
if ((line.find("DTMF>APDW15:t5#")) > 0):
system("echo '\nCW Mode!!\n'")
mode = 'm'
change_mode = True
if ((line.find("MODE=n")) > 0):
system("echo '\nTransmit Commands Mode!!\n'")
mode = 'n'
change_mode = True
counter = (counter + 1) % 2
if ((line.find("DTMF>APDW15:t11#")) > 0):
system("echo '\nTransmit Commands Mode!!\n'")
mode = 'n'
change_mode = True
# Currently, C2C does not support Repeater mode e
if ((line.find("MODE=o")) > 0):
system("echo '\nBeacon Mode toggle!!\n'")
mode = 'o'
change_mode = True
counter = (counter + 1) % 2
if ((line.find("DTMF>APDW15:t10#")) > 0):
system("echo '\nBeacon Mode toggle!!\n'")
mode = 'o'
change_mode = True
if (debug_mode == False) and (change_mode == True) and (counter == 1): # skip every other APRS command since Direwolf prints them twice
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(powerPin, GPIO.OUT)
GPIO.setup(txLed, GPIO.OUT)
if (mode == 'f'):
GPIO.output(powerPin, 0) # blink two times
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(0.1)
GPIO.output(powerPin, 0)
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(1)
elif (mode == 'b'):
GPIO.output(powerPin, 0) # blink three times
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(0.1)
GPIO.output(powerPin, 0)
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(0.1)
GPIO.output(powerPin, 0)
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(1)
elif (mode == 's'):
GPIO.output(powerPin, 0) # blink four times
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(0.1)
GPIO.output(powerPin, 0)
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(0.1)
GPIO.output(powerPin, 0)
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(0.1)
GPIO.output(powerPin, 0)
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(1)
elif (mode == 'm'):
GPIO.output(powerPin, 0) # blink five times
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(0.1)
GPIO.output(powerPin, 0)
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(0.1)
GPIO.output(powerPin, 0)
sleep(0.1);
GPIO.output(powerPin, 1)
sleep(0.1)
GPIO.output(powerPin, 0)
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(0.1)
GPIO.output(powerPin, 0)
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(1)
elif (mode == 'a'):
mode = 'a'
GPIO.output(powerPin, 0) # blink one time
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(1)
try:
file = open("/home/pi/CubeSatSim/command_count.txt", "r")
string = file.read()
file.close()
command_count = int(string)
command_count += 1
filec = open("/home/pi/CubeSatSim/command_count.txt", "w")
command_count_string = str(command_count)
print(command_count_string)
string = filec.write(command_count_string)
filec.close()
except:
print("Can't write command_count file!")
print("Command_count: ")
print(command_count)
GPIO.output(txLed, 0)
GPIO.output(powerPin, 0)
system("sudo systemctl stop rpitx")
# system("sudo systemctl stop cubesatsim")
print("\n/home/pi/CubeSatSim/config -" + mode)
system("/home/pi/CubeSatSim/config -" + mode)
change_mode = False
print("Waiting 5 seconds to allow unplug and plug of soundcard")
sleep(5)
print("Done")