-
Notifications
You must be signed in to change notification settings - Fork 2
/
DaikonTX.py
162 lines (136 loc) · 3.3 KB
/
DaikonTX.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
#!/usr/bin/python3
from rflib import *
import os
import time
import sys
def ask(mod, home, path):
file = open(home + path + ".ys1")
content = file.readlines()
file.close()
freq=str(content[0]).replace('Freq:', '')
freq=str(freq).replace('.', '')
freq=int(freq)*10000
baud=str(content[2]).replace('Baud: ', '')
baud=int(baud)*1
repeat=str(content[3]).replace('Repeat: ', '')
repeat=repeat.strip()
repeat=int(repeat)*1
pre=str(content[4]).replace('Preamble: ', '')
pre=pre.strip()
if pre == '':
pre=0
else:
chk=len(pre)
if (chk % 2) == 0:
pre=bytes.fromhex(pre)
else:
print("Preamble hex length is not divisible by 2, cannot convert to bytes")
sys.exit(130)
data=str(content[5]).replace('Data: ', '')
data=data.strip()
chk=len(data)
if (chk % 2) == 0:
data=bytes.fromhex(data)
else:
print("Data hex length is not divisible by 2, cannot convert to bytes")
sys.exit(130)
tx(freq, mod, baud, repeat, pre, data)
def fsk(mod, home, path):
file = open(home + path + ".ys1")
content = file.readlines()
file.close()
freq=str(content[0]).replace('Freq:', '')
freq=str(freq).replace('.', '')
freq=int(freq)*10000
baud=str(content[2]).replace('Baud: ', '')
baud=int(baud)*1
dev=str(content[3]).replace('Deviation: ', '')
dev=dev.strip()
dev=int(dev)*1
repeat=str(content[4]).replace('Repeat: ', '')
repeat=repeat.strip()
repeat=int(repeat)*1
pre=str(content[5]).replace('Preamble: ', '')
pre=pre.strip()
if pre == '':
pre=0
else:
chk=len(pre)
if (chk % 2) == 0:
pre=bytes.fromhex(pre)
else:
print("Pre hex length is not divisible by 2, cannot convert to bytes")
sys.exit(130)
data=str(content[6]).replace('Data: ', '')
data=data.strip()
chk=len(data)
if (chk % 2) == 0:
data=bytes.fromhex(data)
else:
print("Data hex length is not divisible by 2, cannot convert to bytes")
sys.exit(130)
tx (freq, mod, baud, repeat, pre, data, dev)
def tx(freq, mod, baud, repeat, pre, data, dev=0)
d = RfCat()
d.setModeIDLE()
time.sleep(1)
d.setFreq(freq)
print('Set Freq: %s' % freq)
if mod == "ASK":
d.setMdmModulation(MOD_ASK_OOK)
print("Set Mod: ASK")
else:
d.setMdmModulation(MOD_2FSK)
print("Set Mod: FSK")
d.setMdmDeviatn(dev)
print('Set Deviation: %s' % dev)
d.setMdmDRate(baud)
print('Set Baud: %s' % baud)
d.setMaxPower()
#d.setAmpMode(ampmode=1)
if repeat == 0:
print("Continuous playback, press ENTER to Stop")
if pre == 0:
print("No Preamble")
else:
d.RFxmit(pre)
while not keystop():
try:
d.RFxmit(data)
except ChipconUsbTimeoutException:
pass
else:
print('Total Repeats:%s' % repeat)
if pre == 0:
print("No Preamble")
else:
d.RFxmit(pre)
for x in range (repeat):
d.RFxmit(data)
time.sleep(0)
d.setModeIDLE()
time.sleep(1)
d = None
sys.exit(130)
def main():
home = os.path.expanduser( '~/Saved_TX/' )
os.system('clear')
print("Available files:\n")
for x in os.listdir(home):
if x.endswith(".ys1"):
print(x)
path = input("\nEnter filename without extension: \n")
os.system('clear')
file = open(home + path + ".ys1")
content = file.readlines()
file.close()
mod=str(content[1]).replace('Mod: ', '')
mod=mod.strip()
if mod == "ASK":
ask(mod, home, path)
elif mod == "FSK":
fsk(mod, home, path)
else:
print("Unsupported Modulation")
if __name__ == '__main__':
main()