import os import sio.serial as serial import snetwork.httpserver as httpserver import snetwork.httputils as httputils from base.qt import * from log.log import * import time class cds_handle(httpserver.handle): engine = None def on_get(self, httppath): path = httputils.get_filepath_from_httppath(httppath) query = httputils.get_query_from_httppath(httppath) rtn = { 'path' : path, 'time' : int(time.time()) } if path == '/say' and query.get('content') is not None: content = query.get('content') print_info(content) if cds_handle.engine is None: cds_handle.engine = pyttsx.init() rate = cds_handle.engine.getProperty('rate') cds_handle.engine.setProperty('rate', rate-60) cds_handle.engine.say(content) cds_handle.engine.runAndWait() return self.wrap_data(rtn) httpserver.run(cds_handle)
import time class cmt_handle(httpserver.handle): serial_port = None tag = 'USB Serial Port' def on_get(self, path): rtn = { 'path' : path, 'time' : int(time.time()) } if path == '/type': rtn['type'] = 'char' elif path == '/data': if cmt_handle.serial_port is None: cmt_handle.serial_port = serial.HisSerial(cmt_handle.tag) if not cmt_handle.serial_port.open(QIODevice.ReadOnly): rtn['status'] = 'Serial Open Failed' cmt_handle.serial_port = None else: cmt_handle.serial_port.setBaudRate(9600) if cmt_handle.serial_port is not None: if cmt_handle.serial_port.waitForReadyRead(-1): ch = cmt_handle.serial_port.readAll() rtn['data'] = ord(ch[0]) else: print_error("Error Code %d" % cmt_handle.serial_port.error()) return self.wrap_data(rtn) httpserver.run(cmt_handle)
device_port = cnh_port_start cnh_port_pool[device_guid] = device_port query['port'] = device_port cnh_devices[device_guid] = query device_info = 'OK' rtn['data'] = device_port rtn['info'] = device_info device_storage_path = self.storage_path + '/storage/' + device_guid try: os.makedirs(device_storage_path) except: pass if os.path.isdir(device_storage_path): rtn['storage'] = device_storage_path device_log_path = self.log_path + '/' try: os.makedirs(device_log_path) except: pass if os.path.isdir(device_log_path): rtn['log_file'] = device_log_path + '/' + device_guid + '.log' return self.wrap_data(rtn) httpserver.run(cnh_handle,HIS_HOSTHUB_ROOT_PORT,True)