-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSequenceFactory.py
executable file
·135 lines (105 loc) · 4.06 KB
/
SequenceFactory.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
from XmlSequenceReader import *
class Command:
def __init__(self, cmd, response = ["OK"], waitBeforeNext = 5, timeout = 60):
self.cmd = cmd
self.response = response
self.waitBeforeNext = waitBeforeNext
self.timeout = timeout
class SequenceFactory:
def __init__(self):
radioBand = self.radioBand
smso = self.smso
pin = self.pin
creg020 = self.creg020
creg20 = self.creg20
creg1 = self.creg1
self.sequencesXml = {}
#self.readSequencesFromXml()
self.sequencesNew = {
'cmu850':
[ Command(smso(), ["SYSSTART"]),Command(radioBand(4,4)), Command(smso(), ["SYSSTART"]), Command(pin()),
Command(radioBand(8,12), creg1()), Command(radioBand(4,4), creg020()),
Command(radioBand(4,12), creg1())],
'cmu900':
[ Command(smso(), ["SYSSTART"]),Command(radioBand(4,4)), Command(smso(), ["SYSSTART"]), Command(pin()),
Command(radioBand(1,3), creg1()), Command(radioBand(4,4), creg020()),
Command(radioBand(2,3), creg1())]
}
self.sequences = {
'cmu850':
[ radioBand(4,4), smso(), pin(),radioBand(8,12),radioBand(4,4),
radioBand(4,12)],
'cmu850_AllowAll': #with Camp?!
[ radioBand(4,4), smso(), pin(),radioBand(8,15),radioBand(4,4),
radioBand(2,15)],
'cmu900':
[ radioBand(4,4), smso(), pin(),radioBand(1,3),radioBand(4,4),
radioBand(2,3)],
'cmu900_AllowAll':#with CAMP?! should camp on 2,2 or 4,4? Another Test Case?
[ radioBand(2,2), smso(), pin(),radioBand(1,15),radioBand(2,2),
radioBand(8,15)],
}
def getSequencesXml(self):
return self.sequencesXml
def readSequencesFromXml(self):
sequences = XmlSequenceReader("Sequences.xml").getSequences()
for sequence in sequences:
self.sequencesXml[sequence.attrib['name']] = []
print(sequence.attrib['name'])
sequenceCommands = self.sequencesXml[sequence.attrib['name']]
commands = list(sequence)
for command in commands:
atcmd = self.resolveCommand(command.find("atcmd").text)
print("A")
print(repr(atcmd))
tmp = command.find("response").text
response = tmp if tmp!=None else []
print(repr(response))
waitBeforeNext = command.find("waitBeforeNext").text
print(repr(waitBeforeNext))
timeout = command.find("timeout").text
print("D")
print(repr(timeout))
if (len(response) == 0) and (timeout == None) and (waitBeforeNext == None):
sequenceCommands.append(Command(atcmd))
continue
if (timeout == None) and (waitBeforeNext == None):
sequenceCommands.append(Command(atcmd, response))
continue
if (timeout == None):
sequenceCommands.append(Command(atcmd, response, waitBeforeNext))
else:
sequenceCommands.append(Command(atcmd, response, waitBeforeNext, timeout))
def resolveCommand(self, commandText):
if commandText == "smso":
return self.smso()
if commandText == "pin":
return self.pin()
if commandText == "creg020":
return self.creg020()
if commandText == "creg1":
return self.creg1()
if commandText.find("radioBand") == 0:
return eval("self."+commandText)
def creg(self, code):
return "+CREG: {0}".format(code)
def creg1(self):
return [self.creg(1)]
def creg20(self):
return [self.creg(2), self.creg(0)]
def creg020(self):
return [self.creg(0), self.creg(2), self.creg(0)]
def getNewSequence(self, sequenceName):
return self.sequencesNew[sequenceName]
def getSequence(self, sequenceName):
return self.sequences[sequenceName]
def getAllSequenceNames(self):
return self.sequences.keys()
def radioBand(self,preferred, allowed):
return "at^scfg=Radio/band,{0},{1}".format(preferred, allowed)
def pin(self,pinValue = 9999):
return "AT+CPIN={0}".format(pinValue)
def cmee2(self):
return "AT+CMEE=2"
def smso(self):
return "AT^SMSO"