コード例 #1
0
def perform_config(dev, args):
    module_config = DEVICE[args.device_type]['config'][args.module]
    module_id = module_config['id']
    device_options = module_config['options']

    config_name = args.option
    value_type = device_options[config_name].type
    recipient = get_device_pid(args.device_type)

    if args.value is None:
        success, val = fetch_config(dev, recipient, config_name,
                                    device_options, module_id)
        if success:
            print('Fetched {}: {}'.format(config_name, val))
        else:
            print('Failed to fetch {}'.format(config_name))
    else:
        try:
            config_value = value_type(args.value)
        except ValueError:
            print('Invalid type for {}. Expected {}'.format(
                config_name, value_type))
            return
        success = change_config(dev, recipient, config_name, config_value,
                                device_options, module_id)

        if success:
            print('{} set to {}'.format(config_name, config_value))
        else:
            print('Failed to set {}'.format(config_name))
コード例 #2
0
 def fetchcpi(self):
     config_name = 'cpi'
     module_config = DEVICE[self.type]['config']['sensor']
     options = module_config['options']
     module_id = module_config['id']
     recipient = self.pid
     dev = self.dev
     success, val = fetch_config(dev, recipient, config_name, options,
                                 module_id)
     if success:
         return val
     else:
         print("Fetch CPI failed")
         return False
コード例 #3
0
def perform_config(dev, args):
    module_config = DEVICE[args.device_type]['config'][args.module]
    module_id = module_config['id']
    device_options = module_config['options']

    config_name = args.option
    recipient = get_device_pid(args.device_type)

    if args.value is None:
        success, val = fetch_config(dev, recipient, config_name,
                                    device_options, module_id)
        if success:
            print('Fetched {}: {}'.format(config_name, val))
        else:
            print('Failed to fetch {}'.format(config_name))
    else:
        config_value = int(args.value)
        success = change_config(dev, recipient, config_name, config_value,
                                device_options, module_id)

        if success:
            print('{} set to {}'.format(config_name, config_value))
        else:
            print('Failed to set {}'.format(config_name))