Skip to content

Commit cf16aed

Browse files
author
simu4learn
committed
update
1 parent 120285c commit cf16aed

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/EtermLibrary.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,26 @@ class EtermLibrary(object):
2323
debug_level = 0
2424
eterm_print_pattern = re.compile(r"([^\r]{80})")
2525

26-
def __init__(self, host, port):
26+
def __init__(self):
2727
'''
2828
Constructor
2929
'''
30-
self.matip = MATIP(host, port)
30+
self.matip = MATIP()
3131
self.ascus = []
3232
self.currentSessionIndex = 0
3333

34+
def connect(self, host, port):
35+
self.matip.connect(host, port)
36+
3437
def __getMac(self):
3538
node = uuid.getnode()
3639
mac = uuid.UUID(int=node)
3740
return mac.hex[-12:]
3841

3942
def login(self, username, password):
4043
## 构造登录报文
41-
content = chr(self.ver) # version
42-
content += chr(0xa2) # 内容长度162个字节
44+
content = chr(self.ver) # version
45+
content += chr(0xa2) # 内容长度162个字节
4346

4447
assert(len(username) <= 16)
4548
assert(len(password) <= 32)
@@ -62,8 +65,8 @@ def login(self, username, password):
6265
if ord(resp[0]) == 0 and ord(resp[1]) == len(resp) and ord(resp[2]) == 1:
6366
self.sessionCount = ord(resp[4])
6467
for i in range(self.sessionCount):
65-
ind = 5+5*i
66-
self.ascus.append(resp[ind:ind+5]) # save the H1 H2 A1 A2
68+
ind = 5 + 5 * i
69+
self.ascus.append(resp[ind:ind + 5]) # save the H1 H2 A1 A2
6770
if resp[ind] != chr(0):
6871
h1s.append(resp[ind])
6972
break
@@ -87,9 +90,9 @@ def changeToSession(self, index):
8790
self.currentSessionIndex = index - 1
8891

8992
def eterm_print(self, cmd, text):
90-
beginIndex = text.find("\x1b\x4d")+2
93+
beginIndex = text.find("\x1b\x4d") + 2
9194
endIndex = text.rfind("\x1e\x1b\x62")
92-
content = ">"+ cmd + "\r" + text[beginIndex:endIndex] + ">"
95+
content = ">" + cmd + "\r" + text[beginIndex:endIndex] + ">"
9396
content = self.eterm_print_pattern.sub(r"\1\r", content)
9497
content = content.replace('\x0d', os.linesep)
9598
print content
@@ -116,15 +119,16 @@ def sendCmd(self, cmd):
116119

117120
server = config.get("eterm", "server")
118121
port = config.getint("eterm", "port")
119-
username = config.get("eterm", "username").encode('ascii','ignore')
120-
password = config.get("eterm", "password").encode('ascii','ignore')
122+
username = config.get("eterm", "username").encode('ascii', 'ignore')
123+
password = config.get("eterm", "password").encode('ascii', 'ignore')
121124

122-
el = EtermLibrary(server, port)
125+
el = EtermLibrary()
126+
el.connect(server, port)
123127
el.login(username, password)
124128
resp = el.sendCmd("da")
125129
resp = el.sendCmd("av:canpek/30oct/cz")
126130
# el.sendCmd("IHD:CA")
127131

128132

129133

130-
134+

0 commit comments

Comments
 (0)