예제 #1
1
파일: server.py 프로젝트: k4nar/Sweet-eHome
def get_updates(since):
    return {"devices": Device.get_updated_since(int(since))}
예제 #2
0
파일: Roseda.py 프로젝트: jhardin4/APE
    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
예제 #3
0
    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',
        }
예제 #4
0
파일: Pump.py 프로젝트: narn01101110/APE-1
 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',
     }
예제 #5
0
파일: server.py 프로젝트: k4nar/Sweet-eHome
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)}
예제 #6
0
파일: server.py 프로젝트: k4nar/Sweet-eHome
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)}
예제 #7
0
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)}
예제 #8
0
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)}
예제 #9
0
파일: server.py 프로젝트: k4nar/Sweet-eHome
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)}
예제 #10
0
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)}
예제 #11
0
파일: server.py 프로젝트: k4nar/Sweet-eHome
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)}
예제 #12
0
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)}
예제 #13
0
파일: server.py 프로젝트: k4nar/Sweet-eHome
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)}
예제 #14
0
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)}
예제 #15
0
파일: server.py 프로젝트: k4nar/Sweet-eHome
def get_devices():
    query = {}
    for k in request.params.keys():
        query[k] = request.params.get(k)
    return {"devices": Device.all_to_api(query)}
예제 #16
0
 def __init__(self, name):
     Device.__init__(self, name)
     self.returnformat = ''
     self.result = ''
예제 #17
0
파일: server.py 프로젝트: k4nar/Sweet-eHome
def query_devices():
    return {"actions": Device.all_to_api(request.json)}
예제 #18
0
def query_devices():
    return {"actions": Device.all_to_api(request.json)}
예제 #19
0
def get_devices():
    query = {}
    for k in request.params.keys():
        query[k] = request.params.get(k)
    return {"devices": Device.all_to_api(query)}
예제 #20
0
def get_updates(since):
    return {"devices": Device.get_updated_since(int(since))}
예제 #21
0
    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',
        }
예제 #22
0
# 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()
예제 #23
0
# 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()
예제 #25
-1
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