def send_to_device(self, json_obj, connection): """ Retrieves the good device in the database and builds the request to send. """ hostname = ''; dm = DeviceManager(int(json_obj['data']['room_device_id']), int(json_obj['data']['option_id']), DEBUG_MODE); dev = dm.load_from_db(); if dev is None: connection.close(); return ; if 'daemon_name' in dev: for host in self.hostlist: if dev['daemon_name'] == host._Hostname: hostname = host._Hostname; break; function_writing = int(dev['function_writing']); if (function_writing > 0): try: self.functions[function_writing](json_obj, dev, hostname); except Exception as e: self.logger.error(e); #add scenario check here to allow trigger on write ??? #self.scenario.check_all_scenarios(self.get_global_state(), self.trigger, self.schedule, connection, json_obj); connection.close();
def initUI(self): self.setWindowTitle("稳重校验器") self.setWindowFlags(QtCore.Qt.FramelessWindowHint) desktop = QtWidgets.QApplication.desktop() # 获取显示器分辨率大小 self.screenRect = desktop.screenGeometry() self.height = self.screenRect.height() self.width = self.screenRect.width() # self.width = 960 # self.height = 640 print("Screen Size#", self.width, "x", self.height) self.setFixedSize(self.width, self.height) self.resize(self.height, self.height) self.setStyleSheet(''' QWidget{ border:none; margin-bottom:0px; margin-left:0px; margin-top:0px; margin-right:0px; padding:0px; } ''') self.createMain() DeviceManager.startDevice(scene=self)
def main(): print "Replay started" pl = Pipeline() pl.addStep(EventGenerator(interval=3000,number=1000)) pl.addStep(TroubleInjector()) dev = dm.getDevice() pl.addStep(TroubleReplayer(dev)) pl.execute() print "Replay finished"
def main(): print "Replay started" pl = Pipeline() pl.addStep(EventGenerator(interval=3000, number=1000)) pl.addStep(TroubleInjector()) dev = dm.getDevice() pl.addStep(TroubleReplayer(dev)) pl.execute() print "Replay finished"
def main(): """ This example dumps all error messages in logcat and then clear it. After 5 seconds, it dumps all messages and finishes. Note that logcat encodes its output with utf-8 """ device = DeviceManager.getDevice() agent = LogcatAgent(device) print agent.dump(fmt=None, filterTuples=[('*', 'E')]) agent.clear() print 'Waiting for 5 seconds...' time.sleep(5) print agent.dump()
def send_to_device(self, json_obj, connection): """ Retrieves the good device in the database and builds the request to send. """ dm = DeviceManager(int(json_obj['data']['room_device_id']), int(json_obj['data']['option_id']), DEBUG_MODE); dev = dm.load_from_db(); if dev is None: connection.close(); return ; hostname = ''; for host in self.hostlist: if dev['daemon_name'] in host._Hostname: hostname = host._Hostname; break; if hostname != '': if dev['protocol_id'] == PROTOCOL_KNX: self.knx_manager.protocol_knx(json_obj, dev, hostname); elif dev['protocol_id'] == PROTOCOL_IP: json_obj['addr'] = dev['addr']; json_obj['port'] = dev['plus1']; self.protocol_function[dev['protocol_id']](json_obj, dev, hostname); connection.close();
def send_to_device(self, json_obj, connection, db): """ Retrieves the good device in the database and builds the request to send. """ hostname = ''; dm = DeviceManager(int(json_obj['data']['room_device_id']), int(json_obj['data']['option_id']), DEBUG_MODE); dev = dm.load_from_db(db); if dev is None: connection.close(); return ; if 'daemon_name' in dev: for host in self.hostlist: if dev['daemon_name'] == host._Hostname: hostname = host._Hostname; break; function_writing = int(dev['function_writing']); if (function_writing > 0): try: self.functions[function_writing](json_obj, dev, hostname); except Exception as e: self.logger.error(e); connection.close();
def start_cleaning(self): while True: time.sleep(wait_time) # Devices DeviceManager.get_mem_access() json = DeviceManager.get_mem_json() for device in json: device_time = float(device['insertion_timestamp']) actual_time = time.time() if actual_time - device_time > delete_margin: json.pop(device['device_id']) set_mem_json(json) DeviceManager.get_file_access() filename = DeviceManager.get_filename() DeviceManager.unlock_memory() with open(filename, 'w') as file: json.dumps(json, file) file.close() DeviceManager.unlock_file() #Services ServiceManager.get_mem_access() json = ServiceManager.get_mem_json() for service in json: service_time = float(service['insertion_timestamp']) actual_time = time.time() if actual_time - service_time > delete_margin: json.pop(service['service_id']) set_mem_json(json) ServiceManager.get_file_access() filename = ServiceManager.get_filename() ServiceManager.unlock_memory() with open(filename, 'w') as file: json.dumps(json, file) file.close() ServiceManager.unlock_file()
def startApp(): device = getDevice(DEVICE_NAME, DEVICE_PORT) current_time = time.time() start_time = current_time while True: if DeviceManager.isStop: break current_time = time.time() if current_time - start_time < 0.5: continue start_time = current_time print(time.strftime('The value is %Y %m %d %H:%M:%S', time.localtime())) print( "_____________________ 系统读取前64个货道数据帧 ______________________________" ) send64Command(device) global index index = 0 data = str(binascii.b2a_hex(device.read(149)))[2:-1] # Hex转换成字符串 weight_64 = decodeData(data) print( "_____________________ 读取第65-128个货道数据帧 ______________________________" ) send128Command(device) data = str(binascii.b2a_hex(device.read(149)))[2:-1] # Hex转换成字符串 weight_128 = decodeData(data) # 更新数据 DeviceManager.updateWeightInfo(weight_64, weight_128)
class HandlerIO: def __init__(self, aManageIRQ): self.deviceManage = DeviceManager(aManageIRQ) def handleIO(self, aPCB , nextInstruccion): aPCB.changeStatus(State.WAITING) device = nextInstruccion.getDeviceName() self.deviceManage.handle(device, aPCB, nextInstruccion) def initializeThread(self): self.deviceManage.initializeThread() def addDevice(self, aDevice): self.deviceManage.addDevice(aDevice)
def main(): """ This test launches a series of apps (with given package and main activity names) and repeats this for a given number of times. After that, the scripts dumps the error messages printed to logcat during the test. """ # constants APP_CLOCK = 'com.android.deskclock/com.android.deskclock.DeskClock' APP_SETTINGS = 'com.android.settings/com.android.settings.Settings' # configurations packages = [APP_SETTINGS, APP_CLOCK] sleep_interval = 2 repeats = 2 app_tag = 'ActivityManager' device = DeviceManager.getDevice() agent = LogcatAgent(device) agent.clear() print 'Start launching stress test' for _ in range(repeats): for p in packages: device.startActivity(component=p) time.sleep(sleep_interval) err = agent.dump(fmt=None, filterTuples=[(app_tag, 'E'), ('*', 'S')]) print 'Finishing test, dumping error messages:' print err
def module_path(): ''' returns the module path without the use of __file__. from http://stackoverflow.com/questions/729583/getting-file-path-of-imported-module''' return os.path.abspath(os.path.dirname(inspect.getsourcefile(module_path))) sys.path.append(module_path()) sys.path.append(os.path.join(module_path(), '..', 'src')) from Agents import CellularAgent, ScreenAgent, SystemStatusAgent, WifiAgent, KeypressAgent import DeviceManager from time import sleep device = DeviceManager.getDevice() #test = CellularAgent(device) #print 'current cellular data status', test.getCellularDataStatus() #print 'toggle cellular data status', test.toggleCellularDataStatus() #sleep(5) #print 'turn off cellular data status', test.turnOffCellularData() #sleep(5) #print 'turn on cellular data status', test.turnOnCellularData() # ##print device.shell('uiautomator runtest /sdcard/ChangeOrientationTest.jar -c edu.mcgill.lynxiayel.changeorientationtest.ChangeOrientationTest#testChangeRightDown').encode('utf-8') ##print os.system('adb shell uiautomator runtest /sdcard/ChangeOrientationTest.jar -c edu.mcgill.lynxiayel.changeorientationtest.ChangeOrientationTest#testChangeRightDown') #test = ScreenAgent(device) #print 'current screen rotation status', test.getScreenRotationStatus() #print 'current orientation', test.getOrientation() #print test.changeOrientation() #print test.changeOrientation()
dht11_temperature = MQTT.PublisherAdapter("/sensors/dht11/01/temperature", dht11.get_temperature) dht11_humidity = MQTT.PublisherAdapter("/sensors/dht11/01/humidity", dht11.get_humidity) rpi_cpu_temp = RPiSensors.CPUTemperature("/sensors/temperature/cpu") rpi_gpio_pump1 = RPiSensors.GPIO("/devices/pump/air", 27, True, RPi.GPIO.OUT, False) rpi_gpio_pump2 = RPiSensors.GPIO("/devices/pump/circulation", 22, False, RPi.GPIO.OUT, True) # temp_tank = I2CDevices.ADS1115_NTC_ChannelAdapter("/sensors/temperature/tank", ads_ntc, 1) # temp_ext = I2CDevices.ADS1115_NTC_ChannelAdapter("/sensors/temperature/ext", ads_ntc, 2) mqtt_client = MQTT.Client(device_id) mqtt_client.username_pw_set(mqtt_user, mqtt_pass) device_manager = DeviceManager.DeviceManager(mqtt_client) device_manager.add(dht11_temperature, 60) device_manager.add(dht11_humidity, 60) device_manager.add(rpi_cpu_temp, 60) device_manager.add(rpi_gpio_pump1, 60) device_manager.add(rpi_gpio_pump2, 60) device_manager.add(temp_tank, 60) device_manager.add(temp_ext, 60) device_manager.add(tank_level, 60) schedule.every(900).seconds.do(ads.reset) # reset ads every 15 minutes # finally connect connected = False while not connected: try:
import time import mysql.connector import DatabaseManager import SmartBulbManager import DeviceManager # Init Database database = DatabaseManager.DatabaseConnector() database.connect() database.createDataModel() database.disconnect() # Discover available devices deviceManager = DeviceManager.DeviceManager() deviceManager.fetchAvailableDevices() # Create Bulb #print('aqui') #bulb = SmartBulbManager.SmartBulb('Luz do Quarto','192.168.15.14') #bulb.turnOff()
def main(): signal.signal(signal.SIGABRT, handler) signal.signal(signal.SIGINT, handler) signal.signal(signal.SIGTERM, handler) print('Starting main program') try: errmsg = YRefParam() # Setup the API to use local USB devices if YAPI.RegisterHub("usb", errmsg) != YAPI.SUCCESS: print("init error" + errmsg.value) raise ServiceExit disp = YDisplay.FirstDisplay() if disp is None: print('No module connected') raise ServiceExit if not disp.isOnline(): print("Module not connected ") raise ServiceExit # display clean up disp.resetAll() l0 = disp.get_displayLayer(0) l1 = disp.get_displayLayer(1) l2 = disp.get_displayLayer(2) l1.hide() # L1 is hidden, l2 stays visible centerX = disp.get_displayWidth() / 2 centerY = disp.get_displayHeight() / 2 radius = disp.get_displayHeight() / 2 a = 0 x = 0 y = DeviceManager(queue) # d = DisplayManager(queue) y.start() # d.start() while True: # we draw in the hidden layer l1.clear() l1.selectFont("Large.yfm") drawText(l1, x, centerY, "Work") x += 1 if x > disp.get_layerWidth() + (disp.get_layerWidth() / 2): x = -(disp.get_layerWidth() / 2) disp.swapLayerContent(1, 2) # Do something print('Doing something imporant in the background (main)') num = queue.get() queue.task_done() print("Consumed", num) time.sleep(0.5) except ServiceExit: y.shutdown_flag.set() # d.shutdown_flag.set() y.join() # d.join() print("Exiting the main program")
data = {} data['ip_address'] = IP_ADDRESS data['port'] = PORT data['endpoints'] = [] data['endpoints'].append('/devices') data['endpoints'].append('/users') data['endpoints'].append('/services') data = json.dumps(data) return data if __name__ == "__main__": conf = { '/': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher(), } } cherrypy.tree.mount(BrokerInfo(), '/', conf) cherrypy.tree.mount(DeviceManager.DeviceManager(), '/devices', conf) cherrypy.tree.mount(ServiceManager.ServiceManager(), '/services', conf) cherrypy.tree.mount(UserManager.UserManager(), '/users', conf) cherrypy.config.update({ 'server.socket_host': IP_ADDRESS, 'server.socket_port': PORT }) Cleaner.Cleaner() cherrypy.engine.start() cherrypy.engine.block()
def __init__(self, aManageIRQ): self.deviceManage = DeviceManager(aManageIRQ)