|
@@ -70,15 +70,15 @@ class TestWizardClient():
|
|
|
recvBytes = bytearray(self.sock.recv(1024))
|
|
|
data = self.parseRetData(recvBytes, phead.itemsize)
|
|
|
if int(data) == 1:
|
|
|
- print "Info:__send %s: %s success!"%(cmdType, command)
|
|
|
+ print "Info:__send %s: %s success!" % (cmdType, command)
|
|
|
return True
|
|
|
- print "Error:__send %s: %s fail!"%(cmdType, command)
|
|
|
+ print "Error:__send %s: %s fail!" % (cmdType, command)
|
|
|
except Exception, e:
|
|
|
print "__send " + cmdType + "=> recv Error:", e
|
|
|
return False
|
|
|
|
|
|
def parseRetData(self, recvByteArray, headSize):
|
|
|
- version = recvByteArray[0]&0xff
|
|
|
+ version = recvByteArray[0] & 0xff
|
|
|
recvLen = self.byte4ToInt(recvByteArray, 1)
|
|
|
if version == 0xAC and recvLen == recvByteArray.__len__():
|
|
|
byteArr = bytes(recvByteArray)
|
|
@@ -86,20 +86,20 @@ class TestWizardClient():
|
|
|
return data
|
|
|
return "0"
|
|
|
|
|
|
- def byte4ToInt(self,bytearray, start):
|
|
|
+ def byte4ToInt(self, bytearray, start):
|
|
|
i = (bytearray[start] & 0xff) \
|
|
|
- | (bytearray[start+1] & 0xff) << 8 \
|
|
|
- | (bytearray[start+2] & 0xff) << 16\
|
|
|
- | (bytearray[start+3] & 0xff) << 24
|
|
|
+ | (bytearray[start + 1] & 0xff) << 8 \
|
|
|
+ | (bytearray[start + 2] & 0xff) << 16 \
|
|
|
+ | (bytearray[start + 3] & 0xff) << 24
|
|
|
return i
|
|
|
|
|
|
# 发送消息;
|
|
|
def sendKey(self, keyname, times=1, duration=1):
|
|
|
while times > 0:
|
|
|
times -= 1
|
|
|
- self.__sendkey(keyname)
|
|
|
+ self.__sendCmd("ir", keyname)
|
|
|
time.sleep(duration)
|
|
|
-
|
|
|
+
|
|
|
# 发送多个按键;
|
|
|
def sendKeys(self, keyNames, duration):
|
|
|
for key in keyNames:
|
|
@@ -110,22 +110,35 @@ class TestWizardClient():
|
|
|
if TestWizardBLK.BLK_DIC.has_key(bleKeyName.lower()):
|
|
|
cmdStr = "*INPUT BLEKEY " + TestWizardBLK.BLK_DIC[bleKeyName.lower()]
|
|
|
ret = self.__sendCmd("cmd", cmdStr)
|
|
|
- time.sleep(1)
|
|
|
+ # time.sleep(1)
|
|
|
return ret
|
|
|
else:
|
|
|
return False
|
|
|
|
|
|
'''
|
|
|
- 电源开关,所有电源同时控制,不区分LAN口
|
|
|
- :param onOff: ON代表开,OFF代表关,区分大小写。
|
|
|
- :return True代表成功,False达标失败
|
|
|
+ 函数:电源开关,如果lanNum=-1设置所有LAN口;
|
|
|
+ 参数:
|
|
|
+ onOff:字符串,只能是ON或OFF
|
|
|
+ lanNum:整型或None
|
|
|
+ 返回:设置成功返回True
|
|
|
'''
|
|
|
- def setAllPower(self, onOff):
|
|
|
+
|
|
|
+ def setPower(self, onOff, lanNum=-1):
|
|
|
+ cmdStr = None
|
|
|
if onOff <> "ON" and onOff <> "OFF":
|
|
|
return False
|
|
|
- cmdStr = "*SET " + onOff
|
|
|
+ if isinstance(lanNum, int) == False:
|
|
|
+ return False
|
|
|
+
|
|
|
+ if lanNum <= -1: # 认为负数都是全控制;
|
|
|
+ cmdStr = "*SET POWER " + onOff
|
|
|
+ elif lanNum > 0: # LAN0不是电源控制,排除掉;
|
|
|
+ cmdStr = "*SET LAN %d POWER %s" % (lanNum, onOff)
|
|
|
+
|
|
|
+ if cmdStr is None:
|
|
|
+ return False
|
|
|
ret = self.__sendCmd("cmd", cmdStr)
|
|
|
- time.sleep(1)
|
|
|
+ # time.sleep(1)
|
|
|
return ret
|
|
|
|
|
|
def sendUsbSwitch(self, index):
|
|
@@ -155,7 +168,6 @@ class TestWizardClient():
|
|
|
def getCurrentDeviceName(self):
|
|
|
pass
|
|
|
|
|
|
-
|
|
|
'''断开连接'''
|
|
|
|
|
|
def disconnect(self):
|
|
@@ -166,21 +178,31 @@ class TestWizardClient():
|
|
|
print "TestWizardClient=> socket disconnect error:", e
|
|
|
|
|
|
|
|
|
+# 单例模块;
|
|
|
+tw_singleton = TestWizardClient()
|
|
|
+print u"tw_singleton地址", tw_singleton
|
|
|
+
|
|
|
+
|
|
|
+def API_UsbSwitch(index):
|
|
|
+ return tw_singleton.sendUsbSwitch(index)
|
|
|
+
|
|
|
+
|
|
|
+def API_SetPower(onOff, lanNum):
|
|
|
+ return tw_singleton.setPower(onOff, lanNum)
|
|
|
+
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
- tw = TestWizardClient()
|
|
|
- tw.sendUsbSwitch(0)
|
|
|
- time.sleep(2)
|
|
|
- tw.sendUsbSwitch(1)
|
|
|
- # tw.sendKey('POWER')
|
|
|
- # tw.sendKey('down')
|
|
|
- # print 'sleep'
|
|
|
- # time.sleep(3)
|
|
|
- # tw.sendKey('up')
|
|
|
- # print 111111
|
|
|
- # print tw.sendBLEKey("uparrow")
|
|
|
- # time.sleep(3)
|
|
|
- # print tw.sendBLEKey("downarrow")
|
|
|
- # time.sleep(3)
|
|
|
- # print 2222222
|
|
|
- # print tw.setAllPower("OFF")
|
|
|
- # print tw.setAllPower("ON")
|
|
|
+ API_SetPower("ON", -1)
|
|
|
+ time.sleep(3)
|
|
|
+ API_SetPower("OFF", -1)
|
|
|
+ time.sleep(3)
|
|
|
+ API_SetPower("ON", 3)
|
|
|
+ time.sleep(3)
|
|
|
+ API_SetPower("OFF", 3)
|
|
|
+ # 切换usb;
|
|
|
+ time.sleep(3)
|
|
|
+ API_UsbSwitch(0)
|
|
|
+ time.sleep(10)
|
|
|
+ API_UsbSwitch(1)
|
|
|
+ # 发送红外;
|
|
|
+ tw_singleton.sendKey("setting")
|