@@ -23,23 +23,26 @@ class EtermLibrary(object):
23
23
debug_level = 0
24
24
eterm_print_pattern = re .compile (r"([^\r]{80})" )
25
25
26
- def __init__ (self , host , port ):
26
+ def __init__ (self ):
27
27
'''
28
28
Constructor
29
29
'''
30
- self .matip = MATIP (host , port )
30
+ self .matip = MATIP ()
31
31
self .ascus = []
32
32
self .currentSessionIndex = 0
33
33
34
+ def connect (self , host , port ):
35
+ self .matip .connect (host , port )
36
+
34
37
def __getMac (self ):
35
38
node = uuid .getnode ()
36
39
mac = uuid .UUID (int = node )
37
40
return mac .hex [- 12 :]
38
41
39
42
def login (self , username , password ):
40
43
## 构造登录报文
41
- content = chr (self .ver ) # version
42
- content += chr (0xa2 ) # 内容长度162个字节
44
+ content = chr (self .ver ) # version
45
+ content += chr (0xa2 ) # 内容长度162个字节
43
46
44
47
assert (len (username ) <= 16 )
45
48
assert (len (password ) <= 32 )
@@ -62,8 +65,8 @@ def login(self, username, password):
62
65
if ord (resp [0 ]) == 0 and ord (resp [1 ]) == len (resp ) and ord (resp [2 ]) == 1 :
63
66
self .sessionCount = ord (resp [4 ])
64
67
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
67
70
if resp [ind ] != chr (0 ):
68
71
h1s .append (resp [ind ])
69
72
break
@@ -87,9 +90,9 @@ def changeToSession(self, index):
87
90
self .currentSessionIndex = index - 1
88
91
89
92
def eterm_print (self , cmd , text ):
90
- beginIndex = text .find ("\x1b \x4d " )+ 2
93
+ beginIndex = text .find ("\x1b \x4d " ) + 2
91
94
endIndex = text .rfind ("\x1e \x1b \x62 " )
92
- content = ">" + cmd + "\r " + text [beginIndex :endIndex ] + ">"
95
+ content = ">" + cmd + "\r " + text [beginIndex :endIndex ] + ">"
93
96
content = self .eterm_print_pattern .sub (r"\1\r" , content )
94
97
content = content .replace ('\x0d ' , os .linesep )
95
98
print content
@@ -116,15 +119,16 @@ def sendCmd(self, cmd):
116
119
117
120
server = config .get ("eterm" , "server" )
118
121
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' )
121
124
122
- el = EtermLibrary (server , port )
125
+ el = EtermLibrary ()
126
+ el .connect (server , port )
123
127
el .login (username , password )
124
128
resp = el .sendCmd ("da" )
125
129
resp = el .sendCmd ("av:canpek/30oct/cz" )
126
130
# el.sendCmd("IHD:CA")
127
131
128
132
129
133
130
-
134
+
0 commit comments