# -*- coding:utf-8 -*- import os import sys import time import thread import json #from TST.SourceGenInput import * from ssat_sdk.service.Chroma22293 import * #import Chroma22293 from ssat_sdk.sat_environment import * from ssat_sdk.core.ibinder_listener import * from ssat_sdk.service.service_config import * from ssat_sdk.utils import LoggingUtil import inspect pyFileName = os.path.split(__file__)[-1] def get_current_function_name(): return inspect.stack()[1][3] class C22293Service(): Service_Name = "c22293" def __init__(self): self.serviceConfig = ServiceConfig() self.status = 0 self.listObj = {} self.default = '' self.className = self.__class__.__name__ def initC22293(self): print u"初始化22293采集卡" try: # self.SG = SourceGenInput() parseResourceCfg() list = getChroma22293() self.default = list["default"] for item in list["devices"]: obj = Chroma22293(item["port"]) if obj.open(): self.listObj[item["name"]] = obj else: LoggingUtil.getDebugLogger().info( pyFileName, self.className, get_current_function_name(), '22293启动失败'+str(item["name"])+str(item["port"])) # print u"22293启动失败:%s,%s" % (item["name"], item["port"]) except Exception, e: # print u"22293启动失败", e LoggingUtil.getDebugLogger().info( pyFileName, self.className, get_current_function_name(), '22293启动失败'+str(e)) self.status = 0 return 0, e.message ibinder = ListenerBinder(port=30200) self.listener, port = ibinder.createListener() self.serviceConfig.setC22293ListenerPort(port) # print u"22293启动成功,22293 Port:", port LoggingUtil.getDebugLogger().info( pyFileName, self.className, get_current_function_name(), '22293启动成功,22293 Port:'+str(port)) self.status = 1 while (True): try: conn = self.listener.accept() cmdLine = conn.recv() except Exception, e: # print u"22293接受指令失败", e LoggingUtil.getDebugLogger().info( pyFileName, self.className, get_current_function_name(), '22293接受指令失败:'+str(e)) continue print u"22293接收指令:", cmdLine # cmdLine:指令+参数 json {"command":"setPattern", "param":[]} result = self.execCommand(cmdLine) try: conn.send(result) except Exception, e: # print e LoggingUtil.getDebugLogger().info( pyFileName, self.className, get_current_function_name(), '22293发送指令失败:'+str(e)) def execCommand(self, cmdLine): data = json.loads(cmdLine) command = data["command"] param = data["param"] device = data["device"] # print u'deviceName:', device if len(device) == 0: device = self.default print u'deviceName=>', device if device in self.listObj.keys(): if ("getDeviceName" == command): return self.listObj[device].getDeviceName() elif ("getDeviceSoft" == command): return self.listObj[device].getDeviceSoft() elif ("getStatus" == command): return self.listObj[device].getStatus() elif ("setPattern" == command): return self.listObj[device].setPattern(param[0]) elif ("setTiming" == command): return self.listObj[device].setTiming(param[0]) elif ("setTimingPattern" == command): return self.listObj[device].setTimingPattern(param[0], param[1]) elif ("setBlueOFF" == command): return self.listObj[device].setBlueOFF() elif ("setBuleON" == command): return self.listObj[device].setBuleON() elif ("setGreenOFF" == command): return self.listObj[device].setGreenOFF() elif ("setGreenON" == command): return self.listObj[device].setGreenON() elif (" setRedOFF" == command): return self.listObj[device].setRedOFF() elif ("setRedON" == command): return self.listObj[device].setRedON() elif ("setKeyBoardLock" == command): return self.listObj[device].setKeyBoardLock() elif ("setKeyBoardUnLock" == command): return self.listObj[device].setKeyBoardUnLock() else: # print u'没有这个设备名称=%s,请检查是否书写正确' %device LoggingUtil.getDebugLogger().info( pyFileName, self.className, get_current_function_name(), '没有这个设备名称:'+str(device)) return False