def get_updates(since): return {"devices": Device.get_updated_since(int(since))}
def __init__(self, name): # Run the Device initialization. Device.__init__(self, name) # Run simulation is controlled by its own # Append relevant descriptors self.descriptors.append('GCP') self.descriptors.append('roseda') self.descriptors.append('repository') # Defining the elemental procedures self.requirements['Connect']['key_file'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'key json', } self.requirements['Upload'] = {} self.requirements['Upload']['ufile'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'file or list of files to be uploaded', } self.requirements['Download'] = {} self.requirements['Download']['address'] = { 'value': '', 'source': 'direct', 'address': '', 'desc': 'address of the program or pointer to it', } self.heartbeat = 2 self.timeout = 60
def __init__(self, name): # Run the Device initialization. Device.__init__(self, name) # Run simulation is controlled by its own # Append relevant descriptors self.descriptors.append('system') # Defining the elemental procedures self.requirements['Dwell'] = {} self.requirements['Dwell']['dtime'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'time to wait in seconds', } self.requirements['Run'] = {} self.requirements['Run']['address'] = { 'value': '', 'source': 'direct', 'address': '', 'desc': 'address of the program or pointer to it', } self.requirements['Run']['addresstype'] = { 'value': '', 'source': 'direct', 'address': '', 'desc': 'type of address', } self.requirements['Run']['arguments'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'list of the arguments for the program in order. Will be decomposed with * operator', }
def __init__(self, name): Device.__init__(self, name) self.descriptors.append('pump') self.requirements['Set'] = {} self.requirements['Set']['pressure'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'Pump pressure in kPa', }
def get_device_action(id): device = Device.to_api(id) if device: return {"actions": device["actions"]} else: response.status = 404 return {"error": "Device {} not found.".format(id)}
def get_device_params(id): device = Device.to_api(id) if device: return device["params"] else: response.status = 404 return {"error": "Device {} not found.".format(id)}
def get_device_params(id, name): device = Device.to_api(id) if device: if device["params"].has_key(name): return {name: device["params"][name]} else: response.status = 404 return {"error": "Params {} not found in device {}.".format(name, id)} else: response.status = 404 return {"error": "Device {} not found.".format(id)}
def get_device_params(id, name): device = Device.to_api(id) if device: if device["params"].has_key(name): return {name: device["params"][name]} else: response.status = 404 return { "error": "Params {} not found in device {}.".format(name, id) } else: response.status = 404 return {"error": "Device {} not found.".format(id)}
def post_device_infos(id): device = Device.to_api(id) if device: infos = request.json if not infos: response.status = 204 return if api.core.update_infos(device, infos): response.status = 204 else: response.status = 403 return {"error": "Impossible to set infos for device {}".format(id)} else: response.status = 404 return {"error": "Device {} not found.".format(id)}
def post_device_infos(id): device = Device.to_api(id) if device: infos = request.json if not infos: response.status = 204 return if api.core.update_infos(device, infos): response.status = 204 else: response.status = 403 return { "error": "Impossible to set infos for device {}".format(id) } else: response.status = 404 return {"error": "Device {} not found.".format(id)}
def post_action(id, name): device = Device.to_api(id) action = Action.to_api(name) if device and action: if not device["connected"]: response.status = 403 return {"error": "Device {} is not connected.".format(id)} args = dict([(arg, request.json.get(arg)) for arg in action["args"]]) if api.core.do(device, action, **args): response.status = 204 else: response.status = 403 return {"error": "Impossible to do action {} for device {} with args {}".format(name, id, args)} else: response.status = 404 return {"error": "Device {} not found.".format(id)}
def post_action(id, name): device = Device.to_api(id) action = Action.to_api(name) if device and action: if not device["connected"]: response.status = 403 return {"error": "Device {} is not connected.".format(id)} args = dict([(arg, request.json.get(arg)) for arg in action["args"]]) if api.core.do(device, action, **args): response.status = 204 else: response.status = 403 return { "error": "Impossible to do action {} for device {} with args {}".format( name, id, args) } else: response.status = 404 return {"error": "Device {} not found.".format(id)}
def get_devices(): query = {} for k in request.params.keys(): query[k] = request.params.get(k) return {"devices": Device.all_to_api(query)}
def __init__(self, name): Device.__init__(self, name) self.returnformat = '' self.result = ''
def query_devices(): return {"actions": Device.all_to_api(request.json)}
def __init__(self, name): # Run the Device initialization. Device.__init__(self, name) # Run simulation is controlled by its own # Append relevant descriptors self.descriptors.append('motion') # This log hold commands to be sent self.commandlog = [] # This is the default motion type. Currently, only linear motion is # set up here. self.motiontype = 'linear' # There are two modes here, 'loadrun' and 'cmd' # 'loadrun' does not send the commandlog until explicitly told to # 'cmd' sends each command as it gets them self.motionmode = 'loadrun' # Defines the motion axes of the motion device self.axes = ['X', 'x', 'Y', 'y', 'Z', 'z'] # Storage location for default motion settings self.motionsetting = {} # Defining the elemental procedures self.requirements['Move'] = {} self.requirements['Move']['point'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'Dictionary with the motions sytem axes as keys and target values', } self.requirements['Move']['speed'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'speed of motion, typicaly in mm/s', } self.requirements['Move']['motiontype'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'speed of motion, typicaly in mm/s', } self.requirements['Move']['motionmode'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'cmd or loadrun', } self.requirements['Set_Motion'] = {} self.requirements['Set_Motion']['RelAbs'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'Relative or Absolute motion', } self.requirements['Set_Motion']['dmotionmode'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'default motion mode', } self.requirements['Set_Motion']['dmotiontype'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'default motion type', } self.requirements['Set_Motion']['motionmode'] = { 'value': '', 'source': 'apparatus', 'address': '', 'desc': 'cmd or loadrun', }
# Realiza una prueba de envío de información al servidor SmartHydro # Utiliza un mensajero tipo Http from Devices import Device from RandomSensor import RandomSensor from HttpMessenger import HttpMessenger sensor = RandomSensor() reading_interval = 120 # segundos dataEndpoint = 'https://smarthydro.central-iot.com/apirest/lecturas/' messenger = HttpMessenger(dataEndpoint) deviceUuid = "d73882fd-a29d-4b5d-9532-a2c257918f89" device = Device(reading_interval, messenger, sensor, uuid_=deviceUuid) device.run()
# Ejecuta una prueba de la funcionalidad de device usando un sensor aleatorio from Devices import Device from RandomSensor import RandomSensor from ConsoleMessenger import ConsoleMessenger sensor = RandomSensor() messenger = ConsoleMessenger() reading_interval = 5 # segundos device = Device(reading_interval, messenger, sensor) device.run()
{ "nombre": "IDENTIFICADOR SOLO PARA AYUDA-MEMORIA", "dataEndpoint": "ENDPOINT", "deviceUuid": "SMARTHYDRO_UUID", "transform": "VALID_FORMULA", "readingInterval": "INTERVALO" }, ... ] """ # VALID FORMULA: Por ej: "5*x", "1.34*x*x" # En general se tolera un polinomio! with open('random-sensors.json', "r") as tf: data = json.load(tf) devices = [] for sensorData in data: #novusSensor = NovusSensor(sensorData['sensorCik'], sensorData['dataAlias'], transformRule = sensorData['transform']) sensor = TransformableRandomSensor(transformRule=sensorData['transform']) readingInterval = sensorData['readingInterval'] messenger = HttpMessenger(sensorData['dataEndpoint']) deviceUuid = sensorData['deviceUuid'] device = Device(readingInterval, messenger, sensor, uuid_=deviceUuid) devices.append(device) import threading for dev in devices: dev_thread = threading.Thread(target=dev.run) dev_thread.start()
def main(): global hasPyHook, dev # Initialize ADB and push some touching scripts device = Device() device.pushScripts() usePyHook = False if hasPyHook and device.PYHOOK: usePyHook = True if usePyHook: dev = device hooks_manager = pyHook.HookManager() hooks_manager.KeyDown = pyHookOnKeyDown hooks_manager.KeyUp = pyHookOnKeyUp hooks_manager.HookKeyboard() # Initialize pygame module pygame.init() pygame.font.init() pygame.display.set_mode(UIConfig.WINDOW_SIZE) pygame.display.set_caption("Love Live! School Idol Festival: Keyboard Controller") screen = pygame.display.get_surface() screen.fill(UIConfig.BG_COLOR) config = ConfigParser.ConfigParser(allow_no_value=True) config.read('config.cfg') if config.getboolean("Main", "iconify"): pygame.display.iconify() firstFrame = True keyFont = pygame.font.Font(None, UIConfig.KEY_FONT_SIZE) pauseFont = pygame.font.Font(None, UIConfig.PAUSE_FONT_SIZE) while True: try: screenUpdate = False # Alway update screen for first frame if firstFrame: screenUpdate = True firstFrame = False # Detect keyboard input and send to device module for handling for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: keyData = getKey(event.key) if keyData == -1: sys.exit() elif not usePyHook and keyData > -1: screenUpdate = True device.registerKey(keyData) elif event.type == pygame.KEYUP: keyData = getKey(event.key) if keyData == -1: sys.exit() elif not usePyHook and keyData > -1: screenUpdate = True device.unregisterKey(keyData) if usePyHook: pythoncom.PumpWaitingMessages() screenUpdate = True # Update touch event on devices (up to device module) device.updateTouch() # Update UI if screenUpdate: # Pause button if device.isKeyPressed(0): pygame.draw.rect(screen, UIConfig.PAUSE_BUTTON_PRESSED_COLOR, pygame.Rect(UIConfig.PAUSE_BUTTON_POS, UIConfig.PAUSE_BUTTON_SIZE)) else: pygame.draw.rect(screen, UIConfig.PAUSE_BUTTON_UNPRESSED_COLOR, pygame.Rect(UIConfig.PAUSE_BUTTON_POS, UIConfig.PAUSE_BUTTON_SIZE)) pygame.draw.rect(screen, UIConfig.PAUSE_BUTTON_BORDER_COLOR, pygame.Rect(UIConfig.PAUSE_BUTTON_POS, UIConfig.PAUSE_BUTTON_SIZE), UIConfig.PAUSE_BUTTON_BORDER_WIDTH) text = pauseFont.render("| |", 1, UIConfig.PAUSE_FONT_COLOR) textpos = text.get_rect() textpos.centerx = UIConfig.PAUSE_BUTTON_POS[0] + (UIConfig.PAUSE_BUTTON_SIZE[0] / 2) textpos.centery = UIConfig.PAUSE_BUTTON_POS[1] + (UIConfig.PAUSE_BUTTON_SIZE[1] / 2) screen.blit(text, textpos) # Each circles i = 0 for c in UIConfig.CIRCLE_POSITION: if c == None: i += 1 continue if device.isKeyPressed(i): pygame.draw.circle(screen, UIConfig.CIRCLE_PRESSED_COLOR, c, UIConfig.CIRCLE_RADIUS) else: pygame.draw.circle(screen, UIConfig.CIRCLE_UNPRESSED_COLOR, c, UIConfig.CIRCLE_RADIUS) pygame.draw.circle(screen, UIConfig.CIRCLE_BORDER_COLOR, c, UIConfig.CIRCLE_BORDER_RADIUS, UIConfig.CIRCLE_BORDER_WIDTH) text = keyFont.render(KeyConfig.getKeyName(KeyConfig.KEYS_ARRAY[i]), 1, UIConfig.KEY_FONT_COLOR) textpos = text.get_rect() textpos.centerx = c[0] textpos.centery = c[1] screen.blit(text, textpos) i += 1 # Update screen pygame.display.flip() except KeyboardInterrupt as e: break