|
@@ -12,6 +12,8 @@ import binascii
|
|
|
DataHeader = np.dtype({'names': ['protocol', 'len', 'cmd'], 'formats': ['u1', 'u4', 'u1']}, align=False)
|
|
|
UserInfo = np.dtype({'names': ['userName', 'password', 'actuator'], 'formats': ['|S260', '|S260', '|S260']}, align=False)
|
|
|
LoginResp = np.dtype({'names': ['bStatus', 'szMessage'], 'formats': ['?', '|S260']}, align=False)
|
|
|
+# 通知SATService正常关机、重启;
|
|
|
+NoticeResp = np.dtype({'names': ['TimeStamp', 'NoticeType'], 'formats': ['u8', 'u4']}, align=False)
|
|
|
|
|
|
class BaseClient(object):
|
|
|
__metaclass__ = abc.ABCMeta
|
|
@@ -194,6 +196,31 @@ class SATClient(object):
|
|
|
except Exception, e:
|
|
|
print "BaseClient=> recv Error:", e
|
|
|
return False
|
|
|
+
|
|
|
+
|
|
|
+ # 发送通知,不接收返回;
|
|
|
+ def sendnotice(self, type):
|
|
|
+ '''是否连接'''
|
|
|
+ if self.constate is False:
|
|
|
+ if self.connect() is False:
|
|
|
+ return None
|
|
|
+
|
|
|
+ '''拼装要发送的数据包'''
|
|
|
+ notice = np.array([(time.time(), type)], dtype=NoticeResp)
|
|
|
+
|
|
|
+ '''发送请求数据'''
|
|
|
+ try:
|
|
|
+ self.sock.settimeout(5)
|
|
|
+ phead = np.array([(0xAA, notice.itemsize + np.array([(0xAA, 0, 0x01)], dtype=DataHeader).itemsize, 0x06)], dtype=DataHeader)
|
|
|
+ '''一次性发送完整包'''
|
|
|
+ self.sock.sendall(bytearray(phead.tobytes() + notice.tobytes()))
|
|
|
+ self.sock.settimeout(None)
|
|
|
+ except Exception, e:
|
|
|
+ print "BaseClient=> send Error:", e
|
|
|
+ self.disconnect()
|
|
|
+ self.connect()
|
|
|
+ return False
|
|
|
+
|
|
|
|
|
|
'''断开连接'''
|
|
|
|