Ejemplo n.º 1
0
def getDevicesJSON(compact=False):
    devname = "name"
    devtype = "type"

    devices = []
    for devName in DEVICES:
        if devName == "GPIO":
            continue
        #ADDED OVK
        if devName == "GPIOX":
            continue
        #ADDED OVK
        instance = DEVICES[devName]["device"]
        if hasattr(instance, "__family__"):
            family = instance.__family__()
            if isinstance(family, str):
                devices.append({devname: devName, devtype: family})
            else:
                for fam in family:
                    devices.append({devname: devName, devtype: fam})

        else:
            devices.append({devname: devName, type: instance.__str__()})

    return types.jsonDumps(sorted(devices, key=lambda dev: dev[devname]))
Ejemplo n.º 2
0
 def getJSON(self, compact=False):
     if compact:
         f = 'f'
         v = 'v'
     else:
         f = 'function'
         v = 'value'
     
     json = {}
     for (bus, value) in BUSLIST.items():
         json[bus] = int(value["enabled"])
     
     gpios = {}
     if len(self.export) > 0:
         export = self.export
     else:
         export = range(GPIO.GPIO_COUNT)
 
     for gpio in export:
         gpios[gpio] = {}
         if compact:
             gpios[gpio][f] = GPIO.getFunction(gpio)
         else:
             gpios[gpio][f] = GPIO.getFunctionString(gpio)
         gpios[gpio][v] = int(GPIO.input(gpio))
 
         if GPIO.getFunction(gpio) == GPIO.PWM:
             (pwmType, value) = GPIO.getPulse(gpio).split(':')
             gpios[gpio][pwmType] = value
     
     json['GPIO'] = gpios
     return types.jsonDumps(json)
Ejemplo n.º 3
0
    def getJSON(self, compact=False):
        if compact:
            f = 'f'
            v = 'v'
        else:
            f = 'function'
            v = 'value'

        json = {}
        for (bus, value) in BUSLIST.items():
            json[bus] = int(value["enabled"])

        gpios = {}
        if len(self.export) > 0:
            export = self.export
        else:
            export = range(GPIO.GPIO_COUNT)

        for gpio in export:
            gpios[gpio] = {}
            if compact:
                gpios[gpio][f] = GPIO.getFunction(gpio)
            else:
                gpios[gpio][f] = GPIO.getFunctionString(gpio)
            gpios[gpio][v] = int(GPIO.input(gpio))

            if GPIO.getFunction(gpio) == GPIO.PWM:
                (pwmType, value) = GPIO.getPulse(gpio).split(':')
                gpios[gpio][pwmType] = value

        json['GPIO'] = gpios
        return types.jsonDumps(json)
Ejemplo n.º 4
0
    def callDeviceFunction(self, method, path, data=None):
        (func, args) = self.getDeviceRoute(method, path)
        print(" ............... rest  callDeviceFunction path =" + str(path))
        if func == None:
            return (404, args, M_PLAIN)

        if func.data != None:
            args[func.data] = data

        result = func(**args)
        response = None
        contentType = None
        if result != None:
            if hasattr(func, "contentType"):
                contentType = func.contentType
                if contentType == M_JSON:
                    response = types.jsonDumps(result)
                else:
                    response = func.format % result
            else:
                response = result
        print(" ............... rest  callDeviceFunction response =" +
              str(response))

        return (200, response, contentType)
Ejemplo n.º 5
0
def getDevicesJSON(compact=False):
    devname = "name"
    devtype = "type"
    
    devices = []
    for devName in DEVICES:
        if devName == "GPIO":
            continue
        instance = DEVICES[devName]["device"]
        if hasattr(instance, "__family__"):
            family = instance.__family__()
            if isinstance(family, str):
                devices.append({devname: devName, devtype:family})
            else:
                for fam in family:
                    devices.append({devname: devName, devtype:fam})
                    
        else:
            devices.append({devname: devName, type:instance.__str__()})

    return types.jsonDumps(sorted(devices, key=lambda dev: dev[devname]))
Ejemplo n.º 6
0
    def callDeviceFunction(self, method, path, data=None):
        (func, args) = self.getDeviceRoute(method, path)
        if func == None:
            return (404, args, M_PLAIN)

        if func.data != None:
            args[func.data] = data
        
        result = func(**args)
        response = None
        contentType = None
        if result != None:
            if hasattr(func, "contentType"):
                contentType = func.contentType
                if contentType == M_JSON:
                    response = types.jsonDumps(result)
                else:
                    response = func.format % result
            else:
                response = result
        
        return (200, response, contentType)