Esempio n. 1
0
    def start(self):

        self._tracer.calls("XBeeXBIB.start()")

        # init self._xbee_manager and self._extended_address
        # then register ourself with our Xbee manager
        XBeeBase.pre_start(self)

        # Create a callback specification for our device address, endpoint
        # Digi XBee profile and sample cluster id:
        self._xbee_manager.register_sample_listener(self, self._extended_address,
                                                     self.sample_indication)

        # Configure node sleep behavior:
        sleep_ms = SettingsBase.get_setting(self, "sleep_ms")
        awake_time_ms = SettingsBase.get_setting(self, "awake_time_ms")
        # The original sample rate is used as the sleep rate:

        xbee_sleep_cfg = self._xbee_manager.get_sleep_block(
            self._extended_address,
            sleep=sleep_ms > 0,
            sleep_rate_ms=sleep_ms,
            awake_time_ms=awake_time_ms)

        self._xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg)

        # Create a DDO configuration block for this device:
        xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address)

        # Configure pins DIO0 .. DIO3 for digital input:
        for io_pin in ['D0', 'D1', 'D2', 'D3']:
            xbee_ddo_cfg.add_parameter(io_pin, 3)

        # Turn off LEDs:
        for led in LED_IO_MAP:
            xbee_ddo_cfg.add_parameter(LED_IO_MAP[led], 0)

        # Assert that all pin pull-ups are enabled:
        xbee_ddo_cfg.add_parameter('PR', 0x1fff)

        # Enable I/O line monitoring on pins DIO0 .. DIO3:
        xbee_ddo_cfg.add_parameter('IC', 0xf)

        # Register this configuration block with the XBee Device Manager:
        self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg)

        # Handle channels subscribed to output their data to our led
        # properties:
        cm = self._core.get_service("channel_manager")
        cp = cm.channel_publisher_get()
        for i in range(1, 4):
            setting_name = "led%d_source" % i
            channel_name = SettingsBase.get_setting(self, setting_name)
            if channel_name is not None:
                cp.subscribe(channel_name,
                    (lambda prop: lambda cn: self.update_property(prop, cn))(
                        "led%d" % i))

        # we've no more to config, indicate we're ready to configure.
        return XBeeBase.start(self)
    def probe():
        """\
            Collect important information about the driver.

            .. Note::

                * This method is a static method.  As such, all data returned
                  must be accessible from the class without having a instance
                  of the device created.

            Returns a dictionary that must contain the following 2 keys:
                    1) address_table:
                       A list of XBee address tuples with the first part of the
                       address removed that this device might send data to.
                       For example: [ 0xe8, 0xc105, 0x95 ]
                    2) supported_products:
                       A list of product values that this driver supports.
                       Generally, this will consist of Product Types that
                       can be found in 'devices/xbee/common/prodid.py'
        """
        probe_data = XBeeBase.probe()

        for address in XBeeSerial.ADDRESS_TABLE:
            probe_data['address_table'].append(address)
        for product in XBeeSerial.SUPPORTED_PRODUCTS:
            probe_data['supported_products'].append(product)

        return probe_data

    ## Functions which must be implemented to conform to the DeviceBase
    ## interface:

        XBeeBase.apply_settings()
Esempio n. 3
0
    def __init__(self, name, core_services, set_in=None, prop_in=None):
        """\
            Initialize an XBee Wall Router instance.

            Parameters:
                * name - The name of the XBee Wall Router instance.
                * core - The Core services instance.
                * set_in - settings from a derived class
                * prop_in - properties from a derived class

        """

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        ## XBeeBase manages these settings:
        #   xbee_device_manager: the name of an XBeeDeviceManager instance.
        #   extended_address:    the extended address of the XBee device you
        #                            would like to monitor.
        #
        ## This driver maintains
        #   sample_rate_ms: the sample rate in msec of the XBee Wall Router.
        #   offset:         a raw offset to add/subtract from resulting temperature
        #   degf:           T/F if degress Fahrenheit is desired instead of Celsius

        settings_list = [
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=self.DEF_SAMPLE_MS,
                verify_function=lambda x: x > 0 and x < 0xffff),
            Setting(
                name='offset', type=float, required=False,
                default_value=self.DEF_OFFSET),
            Setting(
                name='degf', type=bool, required=False,
                default_value=self.DEF_DEGF),
        ]
        # Add our settings_list entries into the settings passed to us.
        set_in = self.merge_settings(set_in, settings_list)

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="light", type=float,
                initial=Sample(timestamp=0, unit="not init", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature", type=float,
                initial=Sample(timestamp=0, unit="not init", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
        ]
        # Add our property_list entries into the properties passed to us.
        prop_in = self.merge_properties(prop_in, property_list)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, set_in, prop_in)

        self._tracer.calls("XBeeXBR.__init__()")
Esempio n. 4
0
    def __init__(self, name, core_services, set_in=None, prop_in=None):
        """\
            Initialize an XBee Wall Router instance.

            Parameters:
                * name - The name of the XBee Wall Router instance.
                * core - The Core services instance.
                * set_in - settings from a derived class
                * prop_in - properties from a derived class

        """

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        ## XBeeBase manages these settings:
        #   xbee_device_manager: the name of an XBeeDeviceManager instance.
        #   extended_address:    the extended address of the XBee device you
        #                            would like to monitor.
        #
        ## This driver maintains
        #   sample_rate_ms: the sample rate in msec of the XBee Wall Router.
        #   offset:         a raw offset to add/subtract from resulting temperature
        #   degf:           T/F if degress Fahrenheit is desired instead of Celsius

        settings_list = [
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=self.DEF_SAMPLE_MS,
                verify_function=lambda x: x > 0 and x < 0xffff),
            Setting(
                name='offset', type=float, required=False,
                default_value=self.DEF_OFFSET),
            Setting(
                name='degf', type=bool, required=False,
                default_value=self.DEF_DEGF),
        ]
        # Add our settings_list entries into the settings passed to us.
        set_in = self.merge_settings(set_in, settings_list)

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="light", type=float,
                initial=Sample(timestamp=0, unit="not init", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature", type=float,
                initial=Sample(timestamp=0, unit="not init", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
        ]
        # Add our property_list entries into the properties passed to us.
        prop_in = self.merge_properties(prop_in, property_list)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, set_in, prop_in)

        self._tracer.calls("XBeeXBR.__init__()")
Esempio n. 5
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services
        self.__tracer = get_tracer(name)
        self.__xbee_manager = None

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core, [], [])
    def __init__(self, name, core_services, property_list):
        self.__name = name
        self.__core = core_services
        self.__property_list = property_list

        ## Local State Variables:
        self.__xbee_manager = None

        self.sensor = None

        # Settings
        #
        # xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                      instance.
        # extended_address: the extended address of the XBee Watchport Sensor
        #                   device you would like to monitor.
        # sleep: True/False setting which determines if we should put the
        #        device to sleep between samples.
        # sample_rate_ms: the sample rate of the XBee adapter.
        # enable_low_battery: Force an adapter to enable support for
        #                     battery-monitor pin.
        #                     It should be only enabled if adapter is using
        #                     internal batteries. Optional, Off by default.

        settings_list = [
            Setting(
                name='sleep', type=bool, required=False,
                default_value=False),
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=60000,
                verify_function=lambda x: x >= 0 and x <= CYCLIC_SLEEP_EXT_MAX_MS),
            Setting(
                name='poll_clean_minutes', type=int, required=False,
                default_value=0,
                verify_function=self.__verify_clean_minutes),

            # This setting is provided for advanced users, it is not required:
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=5000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='enable_low_battery', type=Boolean, required=False,
                default_value=Boolean("Off", STYLE_ONOFF)),
        ]

        ## Channel Properties Definition:
        __property_list_internal = [

        ]
        property_list.extend(__property_list_internal)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
    def __init__(self, name, core_services, property_list):
        self.__name = name
        self.__core = core_services
        self.__property_list = property_list

        from core.tracing import get_tracer
        self._tracer = get_tracer(name)

        ## Local State Variables:
        self.__xbee_manager = None

        self.sensor = None

        # Settings
        #
        # xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                      instance.
        # extended_address: the extended address of the XBee Watchport Sensor
        #                   device you would like to monitor.
        # sleep: True/False setting which determines if we should put the
        #        device to sleep between samples.
        # sample_rate_ms: the sample rate of the XBee adapter.
        # enable_low_battery: Force an adapter to enable support for
        #                     battery-monitor pin.
        #                     It should be only enabled if adapter is using
        #                     internal batteries. Optional, Off by default.

        settings_list = [
            Setting(
                name='sleep', type=bool, required=False,
                default_value=False),
            Setting(
                name='sample_rate_ms', type=int, required=True,
                default_value=60000,
                verify_function=lambda x: x >= 0 and x <= CYCLIC_SLEEP_EXT_MAX_MS),

            # This setting is provided for advanced users, it is not required:
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=5000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='enable_low_battery', type=Boolean, required=False,
                default_value=Boolean("Off", STYLE_ONOFF)),
        ]

        ## Channel Properties Definition:
        __property_list_internal = [

        ]
        property_list.extend(__property_list_internal)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
    def __init__(self, name, core_services):
        """\
            Initialize an XBee Wall Router instance.

            Parameters:
                * name - The name of the XBee Wall Router instance.
                * core_services - The Core services instance.

        """

        self.__name = name
        self.__core = core_services

        ## Local State Variables:
        self.__xbee_manager = None
        
        from core.tracing import get_tracer
        self.__tracer = get_tracer(name)

        # Settings:
        #
        # xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                      instance.
        # extended_address: is the extended address of the XBee device you
        #                   would like to monitor.
        # sample_rate_ms:   is the sample rate of the XBee Wall Router.

        settings_list = [
            Setting(
                name = 'xbee_device_manager', type = str, required = False,
                default_value = ''),
            Setting(
                name = 'extended_address', type = str, required = False,
                default_value = ''),
            Setting(
                name = 'sample_rate_ms', type = int, required = False,
                default_value = 1000,
                verify_function = lambda x: x > 0 and x < 0xffff),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name = "light", type = float,
                initial = Sample(timestamp = 0, unit = "brightness", value = 0.0),
                perms_mask = DPROP_PERM_GET, options = DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name = "temperature", type = float,
                initial = Sample(timestamp = 0, unit = "C", value = 0.0),
                perms_mask = DPROP_PERM_GET, options = DPROP_OPT_AUTOTIMESTAMP),
        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 9
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        ## Local State Variables:
        self.__xbee_manager = None
        self.offset = 520.0
        self.__power_on_time = 0

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=1000,
                verify_function=lambda x: x > 0 and x < 0xffff),
            Setting(
                name='default_state', type=str, required=False,
                default_value="on",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='idle_off_seconds', type=int, required=False,
                default_value=0, verify_function=lambda x: x >= 0),
            Setting(name="power_on_source", type=str, required=False),
            Setting(name="pf_adjustment", type=float, required=False,
                    default_value=1.0,
                    verify_function=lambda i:0 < i and i <= 1.0),
            Setting(name="device_profile", type=str, required=False),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="light", type=float,
                initial=Sample(timestamp=0, unit="brightness", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature", type=float,
                initial=Sample(timestamp=0, unit="C", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="current", type=float,
                initial=Sample(timestamp=0, unit="A", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="power_on", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.prop_set_power_control),
        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 10
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services
        self.include_unit = "F"
        self.count = 0
        self.upCount = 11

        ## Local State Variables:
        self.__xbee_manager = None

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=60000,
                verify_function=lambda x: x > 0 and x < 0xffff),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="last_com", type=str,
                initial=Sample(timestamp=1, unit="", value=""),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="signal", type=str,
                initial=Sample(timestamp=0, unit="", value=""),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="volts", type=str,
                initial=Sample(timestamp=0, unit="", value=""),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="excl", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.exclude("excl", x)),
            ChannelSourceDeviceProperty(name="incl", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.include("incl", x)),
            ChannelSourceDeviceProperty(name="light", type=float,
                initial=Sample(timestamp=0, unit="brightness", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature", type=float,
                initial=Sample(timestamp=0, unit="F", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 11
0
    def __init__(self, name, core_services, set_in=None, prop_in=None):

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        ## Local State Variables:

        ## Settings Table Definition:
        settings_list = [
            Setting(name='baudrate',
                    type=int,
                    required=False,
                    default_value=self.DEF_BAUDRATE,
                    verify_function=self.__verify_baudrate),
            Setting(name='parity',
                    type=str,
                    required=False,
                    default_value=self.DEF_PARITY,
                    verify_function=self.__verify_parity),
            # NOTE: SB/Stop-bits is not available in all XBEE
            Setting(name='stopbits',
                    type=int,
                    required=False,
                    default_value=self.DEF_STOPBITS,
                    verify_function=self.__verify_stopbits),
            Setting(name='hardwareflowcontrol',
                    type=str,
                    required=False,
                    default_value=self.DEF_HWFLOW,
                    verify_function=self.__verify_hwflow),

            # These setting is for legacy compatibility & ignored.
            # Having it here is not appropriate given this driver is commonly
            # used with third party XBee products.
            Setting(name='enable_low_battery',
                    type=Boolean,
                    required=False,
                    default_value=False),
        ]
        # Add our settings_list entries into the settings passed to us.
        set_in = self.merge_settings(set_in, settings_list)

        ## Channel Properties Definition:
        # property_list = []
        # Add our property_list entries into the properties passed to us.
        # prop_in = self.merge_properties(prop_in, property_list)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, set_in, prop_in)

        self._tracer.calls("XBeeSerial.__init__()")
Esempio n. 12
0
    def start(self):

        self._tracer.calls("XBeeRPM.start()")

        # init self._xbee_manager and self._extended_address
        # register ourself with our Xbee manager
        # create the self.running_indication callback
        XBeeBase.pre_start(self)

        # Create a callback specification for our device address, endpoint
        # Digi XBee profile and sample cluster id:
        self._xbee_manager.register_sample_listener(self,
                                                    self._extended_address,
                                                    self.sample_indication)

        # Create a DDO configuration block for this device:
        xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address)

        # Configure pins DI1 .. DI3 for analog input:
        for io_pin in ['D1', 'D2', 'D3']:
            xbee_ddo_cfg.add_parameter(io_pin, 2)

        # Get the extended address of the device:
        default_state = SettingsBase.get_setting(self, 'default_state')

        if default_state != 'same':
            # Configure pin DI4 for digital output, default state setting:
            self.prop_set_power_control(
                Sample(0, str(Boolean(default_state, STYLE_ONOFF))))
        else:
            self.property_set('power_on', Sample(0, UNKNOWN_POWER_STATE))

        # Configure the IO Sample Rate:
        sample_rate = SettingsBase.get_setting(self, 'sample_rate_ms')
        xbee_ddo_cfg.add_parameter('IR', sample_rate)

        # new method for mesh health monitoring
        self.set_data_update_rate_seconds(sample_rate / 1000)

        # Handle subscribing the devices output to a named channel,
        # if configured to do so:
        power_on_source = SettingsBase.get_setting(self, 'power_on_source')
        if power_on_source is not None:
            cm = self._core.get_service('channel_manager')
            cp = cm.channel_publisher_get()
            cp.subscribe(power_on_source, self.update_power_state)

        # Register this configuration block with the XBee Device Manager:
        self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg)

        # we've no more to config, indicate we're ready to configure.
        return XBeeBase.start(self)
    def start(self):
        """Start the device driver.  Returns bool."""

        self._tracer.calls("XBeeSerial.start()")

        # init self._xbee_manager and self._extended_address
        # register ourself with our Xbee manager
        # create the self.running_indication callback
        XBeeBase.pre_start(self)

        self.initialize_xbee_serial()

        # we've no more to config, indicate we're ready to configure.
        return XBeeBase.start(self)
Esempio n. 14
0
    def start(self):
        """Start the device driver.  Returns bool."""

        self._tracer.calls("XBeeSerial.start()")

        # init self._xbee_manager and self._extended_address
        # register ourself with our Xbee manager
        # create the self.running_indication callback
        XBeeBase.pre_start(self)

        self.initialize_xbee_serial()

        # we've no more to config, indicate we're ready to configure.
        return XBeeBase.start(self)
    def __init__(self, name, core_services, set_in=None, prop_in=None):

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        ## Local State Variables:

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='baudrate', type=int, required=False,
                default_value=self.DEF_BAUDRATE,
                verify_function=self.__verify_baudrate),
            Setting(
                name='parity', type=str, required=False,
                default_value=self.DEF_PARITY,
                verify_function=self.__verify_parity),
            # NOTE: SB/Stop-bits is not available in all XBEE
            Setting(
                name='stopbits', type=int, required=False,
                default_value=self.DEF_STOPBITS,
                verify_function=self.__verify_stopbits),
            Setting(
                name='hardwareflowcontrol', type=str, required=False,
                default_value=self.DEF_HWFLOW,
                verify_function=self.__verify_hwflow),
                
            # These setting is for legacy compatibility & ignored.
            # Having it here is not appropriate given this driver is commonly
            # used with third party XBee products.
            Setting(
                name='enable_low_battery', type=Boolean, required=False,
                default_value=False),
        ]
        # Add our settings_list entries into the settings passed to us.
        set_in = self.merge_settings(set_in, settings_list)

        ## Channel Properties Definition:
        # property_list = []
        # Add our property_list entries into the properties passed to us.
        # prop_in = self.merge_properties(prop_in, property_list)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, set_in, prop_in)

        self._tracer.calls("XBeeSerial.__init__()")
Esempio n. 16
0
    def probe():
        #   Collect important information about the driver.
        #
        #   .. Note::
        #
        #       This method is a static method.  As such, all data returned
        #       must be accessible from the class without having a instance
        #       of the device created.
        #
        #   Returns a dictionary that must contain the following 2 keys:
        #           1) address_table:
        #              A list of XBee address tuples with the first part of the
        #              address removed that this device might send data to.
        #              For example: [ 0xe8, 0xc105, 0x95 ]
        #           2) supported_products:
        #              A list of product values that this driver supports.
        #              Generally, this will consist of Product Types that
        #              can be found in 'devices/xbee/common/prodid.py'

        probe_data = XBeeBase.probe()

        for address in XBeeAIO.ADDRESS_TABLE:
            probe_data['address_table'].append(address)
        for product in XBeeAIO.SUPPORTED_PRODUCTS:
            probe_data['supported_products'].append(product)

        return probe_data
Esempio n. 17
0
    def running_indication(self):
        self._tracer.calls("XBeeAIO.running_indication()")

        # Our device is now running, load our initial state:
        self.make_request()

        return XBeeBase.running_indication(self)
Esempio n. 18
0
    def probe():
        """\
            Collect important information about the driver.

            .. Note::

                * This method is a static method.  As such, all data returned
                  must be accessible from the class without having a instance
                  of the device created.

            Returns a dictionary that must contain the following 2 keys:
                    1) address_table:
                       A list of XBee address tuples with the first part of the
                       address removed that this device might send data to.
                       For example: [ 0xe8, 0xc105, 0x95 ]
                    2) supported_products:
                       A list of product values that this driver supports.
                       Generally, this will consist of Product Types that
                       can be found in 'devices/xbee/common/prodid.py'
        """
        self._tracer.calls('WirelessSensor Probe called')
        probe_data = XBeeBase.probe()

        for address in WirelessSensor.ADDRESS_TABLE:
            probe_data['address_table'].append(address)
        for product in WirelessSensor.SUPPORTED_PRODUCTS:
            probe_data['supported_products'].append(product)

        return probe_data
Esempio n. 19
0
    def probe():
        #   Collect important information about the driver.
        #
        #   .. Note::
        #
        #       This method is a static method.  As such, all data returned
        #       must be accessible from the class without having a instance
        #       of the device created.
        #
        #   Returns a dictionary that must contain the following 2 keys:
        #           1) address_table:
        #              A list of XBee address tuples with the first part of the
        #              address removed that this device might send data to.
        #              For example: [ 0xe8, 0xc105, 0x95 ]
        #           2) supported_products:
        #              A list of product values that this driver supports.
        #              Generally, this will consist of Product Types that
        #              can be found in 'devices/xbee/common/prodid.py'

        probe_data = XBeeBase.probe()

        for address in XBeeSensor.ADDRESS_TABLE:
            probe_data['address_table'].append(address)
        for product in XBeeSensor.SUPPORTED_PRODUCTS:
            probe_data['supported_products'].append(product)

        return probe_data
Esempio n. 20
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services


        ## Local State Variables:
        self.__xbee_manager = None

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=10000,
                verify_function=lambda x: x > 0 and x < 0xffff),
            Setting(
                name='idle_off_seconds', type=int, required=False,
                default_value=0, verify_function=lambda x: x >= 0),
            Setting(name='input_source', type=str, required=False, default_value=None),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="adder_reg1", type=float,
                initial=Sample(timestamp=0, value=0.0),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.prop_set_adder("adder_reg1", x)),
            ChannelSourceDeviceProperty(name="power_on", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.prop_set_power_control1),

        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list) 
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services
        
        self.__xbee_manager = None
        
        from core.tracing import get_tracer
        self.__tracer = get_tracer(name)

        # Settings:
        #
        # xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                      instance.
        # extended_address: is the extended address of the XBee device you
        #                   would like to monitor.
        # sample_rate_ms:   is the sample rate of the XBee device.

        settings_list = [
            Setting(
                name='xbee_device_manager', type=str, required=False,
                default_value=''),
            Setting(
                name='extended_address', type=str, required=False,
                default_value=''),
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=2000,
                verify_function=lambda x: x > 0 and x < 0xffff),
            Setting(
                name='channel_settings', type=str, required=False,
                default_value="name,unit"),
        ]
        ## Channel Properties Definition:
        property_list = []
                                            
        ## Initialize the DeviceBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 22
0
    def start(self):

        self._tracer.calls("XBeeXBR.start()")

        # init self._xbee_manager and self._extended_address
        # register ourself with our Xbee manager
        # create the self.running_indication callback
        XBeeBase.pre_start(self)

        # Create a callback specification for our device address, endpoint
        # Digi XBee profile and sample cluster id:
        self._xbee_manager.register_sample_listener(self, self._extended_address,
                                                     self._sample_indication)

        # Create a DDO configuration block for this device:
        xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address)

        # Configure pins DI1 & DI2 for analog input:
        for io_pin in ['D1', 'D2']:
            xbee_ddo_cfg.add_parameter(io_pin, 2)

        # Register this configuration block with the XBee Device Manager:
        self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg)

        # Configure the IO Sample Rate:
        sample_rate = SettingsBase.get_setting(self, "sample_rate_ms")

        # DigiMesh requires at least 'Sleep Compatibility'
        # this call will also set IR to sample_rate
        xbee_sleep_cfg = self._xbee_manager.get_sleep_block(
            self._extended_address,
            sleep=False, sleep_rate_ms=sample_rate, awake_time_ms=0)

        self._xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg)

        # we've no more to config, indicate we're ready to configure.
        return XBeeBase.start(self)
Esempio n. 23
0
    def start(self):

        self._tracer.calls("XBeeXBR.start()")

        # init self._xbee_manager and self._extended_address
        # register ourself with our Xbee manager
        # create the self.running_indication callback
        XBeeBase.pre_start(self)

        # Create a callback specification for our device address, endpoint
        # Digi XBee profile and sample cluster id:
        self._xbee_manager.register_sample_listener(self, self._extended_address,
                                                     self._sample_indication)

        # Create a DDO configuration block for this device:
        xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address)

        # Configure pins DI1 & DI2 for analog input:
        for io_pin in ['D1', 'D2']:
            xbee_ddo_cfg.add_parameter(io_pin, 2)

        # Register this configuration block with the XBee Device Manager:
        self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg)

        # Configure the IO Sample Rate:
        sample_rate = SettingsBase.get_setting(self, "sample_rate_ms")

        # DigiMesh requires at least 'Sleep Compatibility'
        # this call will also set IR to sample_rate
        xbee_sleep_cfg = self._xbee_manager.get_sleep_block(
            self._extended_address,
            sleep=False, sleep_rate_ms=sample_rate, awake_time_ms=0)

        self._xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg)

        # we've no more to config, indicate we're ready to configure.
        return XBeeBase.start(self)
Esempio n. 24
0
    def __init__(self, name, core_services, set_in=None, prop_in=None):
        """\
            Initialize an XBee Wall Router instance.

            Parameters:
                * name - The name of the XBee Wall Router instance.
                * core - The Core services instance.
                * set_in - settings from a derived class
                * prop_in - properties from a derived class

        """

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        # Settings
        #
        # sleep: True/False setting which determines if we should put the
        #        device to sleep between samples.
        # sleep_time_ms: If set for sleep, specifies the length of time that
        #                the module will sleep after a period of awake_time_ms
        #                each cycle.
        # sample_rate_ms: If set, then value is loaded into IR to
        #                 cause period data updated regardless of
        #                 change.  Also, if non-zero then samples are
        #                 always updated (timestamp refreshed)
        #                 even if there was no change.
        #                 (Is Optional, defaults to 0/off, valid range 0-60000)
        # power: True/False setting to enable/disable the power output
        #        on terminal 6 of the adapter.
        # channel1_dir: Operating I/O mode for pin 1 of the adapter.
        #               Must be a string value comprised of one of the
        #               following:
        #                   "In" - pin is configured to be an input.
        #                   "Out" - pin is configured to be an output.
        # channel2_dir: Operating I/O mode for pin 2 of the adapter.
        #               See channel1_dir for valid setting information.
        # channel3_dir: Operating I/O mode for pin 3 of the adapter.
        #               See channel1_dir for valid setting information.
        # channel4_dir: Operating I/O mode for pin 4 of the adapter.
        #               See channel1_dir for valid setting information.
        # channel1_source: If channel1_dir is configured as an output, this
        #                  option setting may be specified to a
        #                  "device.channel" channel name.  The Boolean value
        #                  of this channel will specify to logic state for
        #                  pin 1 on the adapter.
        # channel2_source: Configures output value source channel for pin 2
        #                  of the adapter.
        #                  See channel1_source setting information.
        # channel3_source: Configures output value source channel for pin 3
        #                  of the adapter.
        #                  See channel1_source setting information.
        # channel4_source: Configures output value source channel for pin 4
        #                  of the adapter.
        #                   See channel1_source setting information.
        # awake_time_ms: How many milliseconds should the device remain
        #                awake after waking from sleep.
        # sample_predelay: How long, in milliseconds, to wait after waking
        #                  up from sleep before taking a sample from the
        #                  inputs.
        # enable_low_battery: Force an adapter to enable support for
        #                     battery-monitor pin.
        #                     It should be only enabled if adapter is using
        #                     internal batteries. Optional, Off by default.

        settings_list = [
            Setting(
                name='sleep', type=Boolean, required=False,
                default_value=Boolean(False)),
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=0,
                verify_function=lambda x: x == 0 or \
                            CYCLIC_SLEEP_MIN_MS <= x <= 60000),
           Setting(
                name='sleep_time_ms', type=int, required=False,
                default_value=60000,
                verify_function=lambda x: x >= 0 and \
                                x <= CYCLIC_SLEEP_EXT_MAX_MS),
            Setting(
                name='power', type=Boolean, required=False,
                default_value=Boolean("On", STYLE_ONOFF)),
            Setting(
                name='channel1_dir', type=str, required=False,
                default_value='In'),
            Setting(
                name='channel1_default', type=Boolean, required=False),
            Setting(
                name='channel1_source', type=str, required=False,
                default_value=''),
            Setting(
                name='channel2_dir', type=str, required=False,
                default_value='In'),
            Setting(
                name='channel2_default', type=Boolean, required=False),
            Setting(
                name='channel2_source', type=str, required=False,
                default_value=''),
            Setting(
                name='channel3_dir', type=str, required=False,
                default_value='In'),
            Setting(
                name='channel3_default', type=Boolean, required=False),
            Setting(
                name='channel3_source', type=str, required=False,
                default_value=''),
            Setting(
                name='channel4_dir', type=str, required=False,
                default_value='In'),
            Setting(
                name='channel4_default', type=Boolean, required=False),
            Setting(
                name='channel4_source', type=str, required=False,
                default_value=''),

            # This setting is provided for advanced users, it is not required:
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=5000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=1000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='enable_low_battery', type=Boolean, required=False,
                default_value=Boolean("Off", STYLE_ONOFF)),
        ]
        # Add our settings_list entries into the settings passed to us.
        set_in = self.merge_settings(set_in, settings_list)

        ## Channel Properties Definition:
        # This device hardware can monitor the state of its output
        # pins.  Therefore, there are always four input channels.
        # The other properties and channels will be populated when we
        # know the directions of our IO ports.
        property_list = [
            ChannelSourceDeviceProperty(
                name=self.CHN_INPUT_NAME[0], type=bool,
                initial=Sample(timestamp=0, value=False, unit='bool'),
                perms_mask=DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name=self.CHN_INPUT_NAME[1], type=bool,
                initial=Sample(timestamp=0, value=False, unit='bool'),
                perms_mask=DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name=self.CHN_INPUT_NAME[2], type=bool,
                initial=Sample(timestamp=0, value=False, unit='bool'),
                perms_mask=DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name=self.CHN_INPUT_NAME[3], type=bool,
                initial=Sample(timestamp=0, value=False, unit='bool'),
                perms_mask=DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP),
        ]
        # Add our property_list entries into the properties passed to us.
        prop_in = self.merge_properties(prop_in, property_list)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, set_in, prop_in)

        self._tracer.calls("XBeeDIO.__init__()")
Esempio n. 25
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services
        self.parser = WirelessPacketParser()

        self.trace = True

        if self.trace:        
            print 'WirelessSensor(%s) init' % self.__name
        
        ## Local State Variables:
        self.__xbee_manager = None

        ## Settings Table Definition:
        settings_list = [
                Setting(name = self.KEY_SAMPLE_RATE, type = int, required = False,
                default_value = 60,
                verify_function = lambda x: \
                                  x >= 30 and \
                                  x <= 525600 * 60),
                Setting(name = self.parser.KEY_XMIT_PERIOD, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_ALARM_EXIT, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_TRIES, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_HYSTERISIS, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_LOG_PERIOD, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_HI_VAL1, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_HI_TIME1, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_LO_VAL1, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_LO_TIME1, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_HI_VAL2, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_HI_TIME2, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_LO_VAL2, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_LO_TIME2, type = dict, required = False,
                default_value = {}),
                                  ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name=self.KEY_CHANNEL + str(1), type=float,
                initial=Sample(timestamp=0, value=-9223372036854775808.0, unit="units"),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_CHANNEL + str(2), type=float,
                initial=Sample(timestamp=0, value=-9223372036854775808.0, unit="units"),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_CHANNEL + str(3), type=float,
                initial=Sample(timestamp=0, value=-9223372036854775808.0, unit="units"),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_CHANNEL + str(4), type=float,
                initial=Sample(timestamp=0, value=-9223372036854775808.0, unit="units"),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),

            ChannelSourceDeviceProperty(name=self.KEY_ALARM, type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_BATTERY_COUNT, type=int,
                initial=Sample(timestamp=0, value=0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_BATTERY_LOW, type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_DEVICE_ID, type=str,
                initial=Sample(timestamp=0, value=''),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_DOOR_OPEN, type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_ERROR, type=list,
                initial=Sample(timestamp=0, value=[]),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_LINE_POWERED, type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_LOCALLY_CONFIGURED, type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_PACKET_COUNT, type=int,
                initial=Sample(timestamp=0, value=0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_REMAINING_BATT_PCT, type=float,
                initial=Sample(timestamp=0, value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_SERIAL_NO, type=str,
                initial=Sample(timestamp=0, value=''),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_SERVICE_PRESSED, type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        #set up the parser
        self.parser = WirelessPacketParser()

        #initialize packet cache
        self.packetCache = None
        self.packetCacheTimestamp = 0

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 26
0
    def __init__(self, name, core_services, set_in=None, prop_in=None):

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        ## XBeeBase manages these settings:
        #   xbee_device_manager: the name of an XBeeDeviceManager instance.
        #   extended_address:    the extended address of the XBee device you
        #                            would like to monitor.

        ## Local State Variables:
        self._last_timestamp = 0
        self.offset = 520.0
        self.__power_on_time = 0

        # Settings
        #
        # xbee_device_manager: must be set to the name of an
        #                      XBeeDeviceManager instance.
        # extended_address: the extended address of the XBee device you
        #                   would like to monitor.
        # sample_rate_ms: the sample rate of the XBee SmartPlug.
        # default_state: "On"/"Off"/"Same", if "On" the plug will default to
        #                being switched on.
        # idle_off_seconds: Number of seconds to go by before forcing
        #                   power off.
        #                   If not set the value defauts to 0, which means
        #                   the device never idles out.
        # power_on_source: optional setting; string name of a Boolean
        #                  "device.channel" to be used as the state.  For
        #                  example, if set to the name of a channel which
        #                  changes value from False to True, the SmartPlug
        #                  would change from being off to on.
        # pf_adjustment: optional setting; floating point value between
        #                0 and 1, that is used to adjust the current
        #                output given a known power factor.
        #                defaults to 1 (i.e no adjustment)
        #                Note: The unit cannot determine the pf,
        #                it is strictly a user supplied value.
        # device_profile: optional setting; string value corresponding
        #                 to a preset pf_adjustment value.
        #                 These values are by not intended to be precise;
        #                 they are only estimates.
        #                 For a list of valid device_profile settings see the
        #                 check_profiles() function in the driver source.

        settings_list = [
            Setting(name='sample_rate_ms',
                    type=int,
                    required=False,
                    default_value=self.DEF_SAMPLE_MS,
                    verify_function=lambda x: x > 0 and x < 0xffff),
            Setting(name='default_state',
                    type=str,
                    required=False,
                    default_value=self.DEF_STATE,
                    parser=lambda s: s.lower(),
                    verify_function=lambda s: s in initial_states),
            Setting(name='idle_off_seconds',
                    type=int,
                    required=False,
                    default_value=self.DEF_IDLE_OFF,
                    verify_function=lambda x: x >= 0),
            Setting(name="power_on_source", type=str, required=False),
            Setting(name="pf_adjustment",
                    type=float,
                    required=False,
                    default_value=self.DEF_PF,
                    verify_function=lambda i: 0 < i and i <= 1.0),
            Setting(name="device_profile", type=str, required=False),
            Setting(name="degf",
                    type=bool,
                    required=False,
                    default_value=self.DEF_DEGF),
        ]

        # Add our settings_list entries into the settings passed to us.
        set_in = self.merge_settings(set_in, settings_list)

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="light",
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="brightness",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature",
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="C",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="current",
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="A",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name="power_on",
                type=str,
                initial=Sample(timestamp=0,
                               value=str(Boolean(True, style=STYLE_ONOFF))),
                perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.prop_set_power_control),
        ]

        # Add our property_list entries into the properties passed to us.
        prop_in = self.merge_properties(prop_in, property_list)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, set_in, prop_in)

        self._tracer.calls("XBeeRPM.__init__()")
Esempio n. 27
0
    def __init__(self, name, core_services, set_in=None, prop_in=None):
        """\
            Initialize an XBee Wall Router instance.

            Parameters:
                * name - The name of the XBee Wall Router instance.
                * core - The Core services instance.
                * set_in - settings from a derived class
                * prop_in - properties from a derived class

        """

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        ## Settings Table Definition:

        settings_list = [
            Setting(
                name='sleep_ms', type=int, required=False,
                default_value=self.DEF_SLEEP_MS,
                verify_function=lambda x: x >= 0 and \
                                x <= CYCLIC_SLEEP_EXT_MAX_MS),
            Setting(name="led1_source", type=str, required=False),
            Setting(name="led2_source", type=str, required=False),
            Setting(name="led3_source", type=str, required=False),
            # This setting is provided for advanced users:
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=self.DEF_AWAKE_MS,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
        ]
        # Add our settings_list entries into the settings passed to us.
        set_in = self.merge_settings(set_in, settings_list)

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="sw1",
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="sw2",
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="sw3",
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="sw4",
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            # gettable and settable properties
            ChannelSourceDeviceProperty(
                name="led1",
                type=Boolean,
                initial=Sample(timestamp=0,
                               value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.prop_set_led("led1", sample)),
            ChannelSourceDeviceProperty(
                name="led2",
                type=Boolean,
                initial=Sample(timestamp=0,
                               value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.prop_set_led("led2", sample)),
            ChannelSourceDeviceProperty(
                name="led3",
                type=Boolean,
                initial=Sample(timestamp=0,
                               value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.prop_set_led("led3", sample)),
        ]
        # Add our property_list entries into the properties passed to us.
        prop_in = self.merge_properties(prop_in, property_list)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, set_in, prop_in)

        self._tracer.calls("XBeeXBIB.__init__()")
Esempio n. 28
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services
        self.__event_timer = None

        ## Local State Variables:
        self.__xbee_manager = None
        self.update_timer = None

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='sleep', type=bool, required=False,
                default_value=True),
            Setting(
                name='sample_rate_sec', type=int, required=False,
                default_value=30,
                verify_function=lambda x: x >= 10 and x < 0xffff),
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=5000,
                verify_function=lambda x: x >= 0 and x <= CYCLIC_SLEEP_EXT_MAX_MS), 
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=50,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=50,
                verify_function=lambda x: x >= 0 and x <= 0xffff),           
            Setting(
                name='default_state1', type=str, required=False,
                default_value="same",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='default_state2', type=str, required=False,
                default_value="off",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='default_state3', type=str, required=False,
                default_value="off",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='idle_off_seconds', type=int, required=False,
                default_value=0, verify_function=lambda x: x >= 0),
            Setting(name='input_source', type=str, required=False, default_value=None),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
#            ChannelSourceDeviceProperty(name="input", type=tuple,
#                initial=Sample(timestamp=0, value=(0,None)),
#                perms_mask=DPROP_PERM_SET | DPROP_PERM_GET,
#                set_cb=self.prop_set_power_control1),
            ChannelSourceDeviceProperty(name="open_close", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.open),
            ChannelSourceDeviceProperty(name="auto", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.auto),
            ChannelSourceDeviceProperty(name="aa", type=str,
                initial=Sample(timestamp=0, value="vent"),
                 perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET), options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="zone_temperature", type=str,
                initial=Sample(timestamp=0, value=""),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.prop_set_adder("zone_temperature", x)),
            ChannelSourceDeviceProperty(name="driving_thermostat", type=str,
                initial=Sample(timestamp=0, value="thermostat.on_for_ac_off_for_heat_status"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.prop_set_adder("driving_thermostat", x)),
            ChannelSourceDeviceProperty(name="battery", type=int,
                initial=Sample(timestamp=0, unit="V", value=0),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="driving_temp", type=float,
                initial=Sample(timestamp=0, value=0.0),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.prop_set_adder("desired_temp", x)),
            ChannelSourceDeviceProperty(name="desired_temp", type=float,
                initial=Sample(timestamp=0, value=0.0),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.prop_set_adder("desired_temp", x)),
            ChannelSourceDeviceProperty(name="thermostat_mode", type=str,
                initial=Sample(timestamp=0, unit="N/A", value="Off"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
                
            
                
                
             # settable properties
 #           ChannelSourceDeviceProperty(name="counter_reset", type=int,
 #               perms_mask=DPROP_PERM_SET,
 #               set_cb=self.prop_set_counter_reset),


        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list) 
Esempio n. 29
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        ## Local State Variables:
        self.__xbee_manager = None

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='sleep', type=bool, required=False,
                default_value=True),
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=10000,
                verify_function=lambda x: x >= 0 and x <= CYCLIC_SLEEP_EXT_MAX_MS), 
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=1100,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=250,
                verify_function=lambda x: x >= 0 and x <= 0xffff),           
            Setting(
                name='idle_off_seconds', type=int, required=False,
                default_value=0, verify_function=lambda x: x >= 0),            
            Setting(name='device_profile', type=str, required=False),
            Setting(name='input_source', type=str, required=False, default_value=None),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
#            ChannelSourceDeviceProperty(name="input", type=tuple,
#                initial=Sample(timestamp=0, value=(0,None)),
#                perms_mask=DPROP_PERM_SET | DPROP_PERM_GET,
#                set_cb=self.prop_set_power_control1),
            ChannelSourceDeviceProperty(name="driving_temp", type=float,
                initial=Sample(timestamp=0, unit="F", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature", type=float,
                initial=Sample(timestamp=0, unit="F", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="aa", type=str,
                initial=Sample(timestamp=0, value="thermostat"),
                 perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET), options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="red_light", type=float,
                initial=Sample(timestamp=0, unit="mv", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="on", type=float,
                initial=Sample(timestamp=0, unit="mv", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="heat", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.heat),
            ChannelSourceDeviceProperty(name="AC", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.ac),
            ChannelSourceDeviceProperty(name="heat_ac_on", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="on_for_ac_off_for_heat_status", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="fan_on", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="fan", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.fan),
            ChannelSourceDeviceProperty(name="switch_to_old", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.old_thermostat),
            ChannelSourceDeviceProperty(name="old_thermostat_on", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),

            ChannelSourceDeviceProperty(name="user_input_1", type=str,
                initial=Sample(timestamp=0, value="thermostat.temperature"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.prop_set_adder("user_input_1", x)),                                                                                                                
            ChannelSourceDeviceProperty(name="desired_temp", type=float,
                initial=Sample(timestamp=0, value=0.0),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.prop_set_adder("desired_temp", x)),

                
                
             # settable properties
 #           ChannelSourceDeviceProperty(name="counter_reset", type=int,
 #               perms_mask=DPROP_PERM_SET,
 #               set_cb=self.prop_set_counter_reset),


        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list) 
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services
        
        self.__xbee_manager = None
        
        from core.tracing import get_tracer
        self.__tracer = get_tracer(name)

        # Settings:
        #
        # xbee_device_manager:  must be set to the name of an XBeeDeviceManager
        #                       instance.
        # extended_address:     is the extended address of the XBee device you
        #                       would like to monitor.
        # sleep:                True/False setting which determines if we should put the
        #                       device to sleep between samples.  Default: True
        # sample_rate_ms:       the sample rate of the XBee adapter. Default:
        #                       20,000 ms or 20 sec.
        #
        # Advanced settings:
        #
        # awake_time_ms:        how long should the sensor stay awake after taking
        #                       a sample?  The default is 1000 ms.
        # sample_predelay:      how long should the sensor be awake for before taking
        #                       its sample reading?  This delay is used to allow the
        #                       device's sensoring components to warm up before
        #                       taking a sample.  The default is 125ms.

        settings_list = [
            Setting(
                name='xbee_device_manager', type=str, required=False,#actually this must be true
                default_value=''),
            Setting(
                name='extended_address', type=str, required=False,#actually this must be true
                default_value=''),
            Setting(
                name='sleep', type=bool, required=False,
                default_value=True),
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=20000),
            # These settings are provided for advanced users, they
            # are not required:
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=1000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=125,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            
        ]
        ## Channel Properties Definition:
        property_list = [
            ChannelSourceDeviceProperty(name='data_channel', type=str,
                initial=Sample(timestamp=0, value="", unit='hex'),
                perms_mask=DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP,
            )
        ]
                                            
        ## Initialize the DeviceBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 31
0
    def start(self):
        """Start the device driver.  Returns bool."""

        self._tracer.calls('WirelessSensor start')

        # init self._xbee_manager and self._extended_address
        # register ourself with our Xbee manager
        # create the self.running_indication callback
        XBeeBase.pre_start(self)

        # Get the extended address of the device:
        self._addr = (self._extended_address, 0xe8, 0xc105, 0x11)

        # Retrieve the flag which tells us if we should sleep:

        # Create a callback specification for our device address, endpoint
        # Digi XBee profile and sample cluster id:
        xbdm_rx_event_spec = XBeeDeviceManagerRxEventSpec()
        xbdm_rx_event_spec.cb_set(self.sample_indication)
        xbdm_rx_event_spec.match_spec_set(
            (self._extended_address, 0xe8, 0xc105, 0x11),
            (True, True, True, True))
        self._xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec)

        # Create a callback specification that calls back this driver when
        # our device has left the configuring state and has transitioned
        # to the running state:
        xbdm_running_event_spec = XBeeDeviceManagerRunningEventSpec()
        xbdm_running_event_spec.cb_set(self.running_indication)
        self._xbee_manager.xbee_device_event_spec_add(self,
                                                      xbdm_running_event_spec)

        # Define a Network Sleep block.
        # This block will NOT send any sleep parameters to the device,
        # but instead, will provide a hint to the DIA about how long
        # we expect our device to sleep for.
        # This is required for long sleeping nodes, as the coordinator
        # and all routers on the network need to know these values.
        xbee_sleep_cfg = XBeeConfigNetworkSleep(self._extended_address)
        sleep_rate = SettingsBase.get_setting(self, self.KEY_SAMPLE_RATE)
        self._tracer.debug('pushing sleep config for %d seconds', sleep_rate)
        sleep_rate *= 1000
        xbee_sleep_cfg.sleep_cycle_set(1, sleep_rate)
        self._xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg)

        # see if there are sensor configurations
        self._tracer.debug('loading configuration changes')
        #generate configurations as a dictionary of dictionaries, one for global and
        #one for each serial number as appropriate
        self.configurations = {}
        self.addConfiguration(
            self.parser.KEY_XMIT_PERIOD,
            SettingsBase.get_setting(self, self.parser.KEY_XMIT_PERIOD))
        self.addConfiguration(
            self.parser.KEY_ALARM_EXIT,
            SettingsBase.get_setting(self, self.parser.KEY_ALARM_EXIT))
        self.addConfiguration(
            self.parser.KEY_TRIES,
            SettingsBase.get_setting(self, self.parser.KEY_TRIES))
        self.addConfiguration(
            self.parser.KEY_HYSTERISIS,
            SettingsBase.get_setting(self, self.parser.KEY_HYSTERISIS))
        self.addConfiguration(
            self.parser.KEY_LOG_PERIOD,
            SettingsBase.get_setting(self, self.parser.KEY_LOG_PERIOD))
        self.addConfiguration(
            self.parser.KEY_HI_VAL1,
            SettingsBase.get_setting(self, self.parser.KEY_HI_VAL1))
        self.addConfiguration(
            self.parser.KEY_HI_TIME1,
            SettingsBase.get_setting(self, self.parser.KEY_HI_TIME1))
        self.addConfiguration(
            self.parser.KEY_LO_VAL1,
            SettingsBase.get_setting(self, self.parser.KEY_LO_VAL1))
        self.addConfiguration(
            self.parser.KEY_LO_TIME1,
            SettingsBase.get_setting(self, self.parser.KEY_LO_TIME1))
        self.addConfiguration(
            self.parser.KEY_HI_VAL2,
            SettingsBase.get_setting(self, self.parser.KEY_HI_VAL2))
        self.addConfiguration(
            self.parser.KEY_HI_TIME2,
            SettingsBase.get_setting(self, self.parser.KEY_HI_TIME2))
        self.addConfiguration(
            self.parser.KEY_LO_VAL2,
            SettingsBase.get_setting(self, self.parser.KEY_LO_VAL2))
        self.addConfiguration(
            self.parser.KEY_LO_TIME2,
            SettingsBase.get_setting(self, self.parser.KEY_LO_TIME2))

        # Indicate that we have no more configuration to add:
        self._tracer.debug('completing configuration')

        # we've no more to config, indicate we're ready to configure.
        return XBeeBase.start(self)
Esempio n. 32
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services
        self.__event_timer = None
        self.__serial_lock = Lock()

        ## Local State Variables:
        self.__xbee_manager = None
        self.update_timer = None
        self.modes = {"off":0, "heat":1, "cool":2, "auto":3}

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='xbee_device_manager', type=str, required=True),
            Setting(
                name='extended_address', type=str, required=True),
            Setting(
                name='sample_rate_sec', type=int, required=False,
                default_value=300,
                verify_function=lambda x: x >= 10 and x < 0xffff),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="serialReceive", type=str,
                initial=Sample(timestamp=0, unit="", value=""),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="serialSend", type=str,
                initial=Sample(timestamp=0, unit="", value=""),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.serial_send),
            ChannelSourceDeviceProperty(name="current_temp", type=int,
                initial=Sample(timestamp=0, unit="F", value=0),
                perms_mask=(DPROP_PERM_GET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="spt", type=int,
                initial=Sample(timestamp=0, unit="F", value=75),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.set_sp("spt", x)),
            ChannelSourceDeviceProperty(name="spht", type=int,
                initial=Sample(timestamp=0, unit="F", value=80),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.set_sph("spht", x)),
            ChannelSourceDeviceProperty(name="splt", type=int,
                initial=Sample(timestamp=0, unit="F", value=65),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.set_spc("splt", x)),
            ChannelSourceDeviceProperty(name="mode", type=str,
                initial=Sample(timestamp=0, unit="o/h/c/a", value="Off"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.set_mode("mode", x)),
            ChannelSourceDeviceProperty(name="start", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.set_fan("start", x)),
            ChannelSourceDeviceProperty(name="stop", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.set_fan("stop", x)),
            ChannelSourceDeviceProperty(name="ac_1", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),                
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="ac_2", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="heat_1", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="heat_2", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="heat_3", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        ## Initialize the DeviceBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 33
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        from core.tracing import get_tracer
        self.__tracer = get_tracer(name)

        ## Local State Variables:
        self.__xbee_manager = None

        self.__OLD_HARDWARE = False
        self.__scale = 0.0
        self.__offset = 0.0

        # Force a calibration every read.
        self.__calibration_interval = 0
        self.__calibration_time = -self.__calibration_interval

        self.__lock = threading.Lock()

        # Settings
        #
        # xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                      instance.
        # sample_rate_ms: the sample rate of the XBee adapter.
        # channel1_mode: Operating input mode for pin 1 of the adapter.
        #                Must be a string value comprised of one of the following:
        #                    "TenV" - 0-10v input available on any channel.
        #                    "CurrentLoop" - 0-20 mA current loop available on
        #                                    any channel.
        # channel2_mode: Operating input mode for pin 2 of the adapter.
        #                See channel1_mode for valid setting information.
        # channel3_mode: Operating input mode for pin 3 of the adapter.
        #                See channel1_mode for valid setting information.
        # channel4_mode: Operating input mode for pin 4 of the adapter.
        #                See channel1_mode for valid setting information.

        settings_list = [
            # Setting( This is in xbee_base!
            #    name='extended_address', type=str, required=False,
            #    default_value=''),
            Setting(name='sample_rate_ms',
                    type=int,
                    required=True,
                    default_value=60000,
                    verify_function=lambda x: x >= 0 and x <=
                    CYCLIC_SLEEP_EXT_MAX_MS),
            Setting(name='channel1_mode',
                    type=str,
                    required=False,
                    verify_function=_verify_channel_mode,
                    default_value=self.LOCAL_AIO_MODE_TENV),
            Setting(name='channel2_mode',
                    type=str,
                    required=False,
                    verify_function=_verify_channel_mode,
                    default_value=self.LOCAL_AIO_MODE_TENV),
            Setting(name='channel3_mode',
                    type=str,
                    required=False,
                    verify_function=_verify_channel_mode,
                    default_value=self.LOCAL_AIO_MODE_TENV),
            Setting(name='channel4_mode',
                    type=str,
                    required=False,
                    verify_function=_verify_channel_mode,
                    default_value=self.LOCAL_AIO_MODE_TENV),
        ]

        ## Channel Properties Definition:
        property_list = [
            ChannelSourceDeviceProperty(name="channel1_value",
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="V",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET
                                        | DPROP_PERM_REFRESH,
                                        options=DPROP_OPT_AUTOTIMESTAMP,
                                        refresh_cb=self.refresh),
            ChannelSourceDeviceProperty(name="channel2_value",
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="V",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET
                                        | DPROP_PERM_REFRESH,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="channel3_value",
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="V",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET
                                        | DPROP_PERM_REFRESH,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="channel4_value",
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="V",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET
                                        | DPROP_PERM_REFRESH,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core, settings_list,
                          property_list)
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services
    #    self.__event_timer = None
        self.__event_timer3 = None
        self.__event_timer4 = None
        self.__xbee_manager = None
        self.local = 0
        self.hour_timer = 0
        self.source2 = None 
        self.source1 = None
        self.ud_once = 0
        self.sched = 0
        self.w_retry = 0
        self.timer_c = 0
        
        

        
       # self.update_timer = None
   #     self.__stopevent = core_services
        

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='count_init', type=int, required=False, default_value=0,
                  verify_function=lambda x: x >= 0),
            Setting(
                name='xbee_device_manager', type=str, required=False, default_value="xbee_device_manager"),
            Setting(
                name='pin3_source', type=str, required=False,
                default_value=''),
            Setting(
                name='pin4_source', type=str, required=False,
                default_value=''),
            Setting(
                name='extended_address', type=str, required=False, default_value="00:00:a2:00:40:33:9b:f3!"),
            Setting(
                name='sample_rate_sec_w', type=int, required=False,
                default_value=600,
                verify_function=lambda x: x >= 1 and x < 0xffff),
            Setting(
                name='sample_rate_sec', type=int, required=False,
                default_value=30,
                verify_function=lambda x: x >= 1 and x < 0xffff),
            Setting(
                name='update_rate', type=float, required=False, default_value=10,
                  verify_function=lambda x: x > 0.0),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            
            #driving io pins on DIO
            ChannelSourceDeviceProperty(name="heat_off", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            
            ChannelSourceDeviceProperty(name="med", type=str,
                initial=Sample(timestamp=0, unit="med", value="0"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            
            ChannelSourceDeviceProperty(name="w_t", type=str,
                initial=Sample(timestamp=0, unit="degF", value="60"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            
            ChannelSourceDeviceProperty(name="w_h", type=str,
                initial=Sample(timestamp=0, unit="percent", value="O"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            
            #driving io pins on DIO
            ChannelSourceDeviceProperty(name="heat_on", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            
            ChannelSourceDeviceProperty(name="sch", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("sch", x)),
            
            ChannelSourceDeviceProperty(name="err", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("err", x)),
            
            ChannelSourceDeviceProperty(name="hour", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.set_hour("hour", x)),
            
            ChannelSourceDeviceProperty(name="pin_2", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.set_pin_2("pin_2", x)),
            
            ChannelSourceDeviceProperty(name="heat_4", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            
            ChannelSourceDeviceProperty(name="heat_5", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            
            ChannelSourceDeviceProperty(name="heat_7", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
                   
            ChannelSourceDeviceProperty(name="heat_6", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            
            ChannelSourceDeviceProperty(name="heat_1", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP),
            
            ChannelSourceDeviceProperty(name="ac_1", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),                
                options=DPROP_OPT_AUTOTIMESTAMP),
                      
            ChannelSourceDeviceProperty(name="current_temp", type=str,
                initial=Sample(timestamp=0, unit="apyF", value="0"),
                perms_mask=(DPROP_PERM_GET),
                options=DPROP_OPT_AUTOTIMESTAMP),
           
            
            
            # setable channesls
            
            
            
            ChannelSourceDeviceProperty(name="f_count", type=int,
                initial=Sample(timestamp=0, unit="failed", value=0),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.send_failed("f_count", x)),
            
            ChannelSourceDeviceProperty(name="hd1_on1", type=str,
                initial=Sample(timestamp=0, unit="degF", value="4"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("hd1_on1", x)),
            
            ChannelSourceDeviceProperty(name="hd1_off1", type=str,
                initial=Sample(timestamp=0, unit="degF", value="4"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("hd1_off1", x)),
            
            ChannelSourceDeviceProperty(name="ot_on1", type=str,
                initial=Sample(timestamp=0, unit="degF", value="0"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("ot_on1", x)),
            
            ChannelSourceDeviceProperty(name="mode1", type=str,
                initial=Sample(timestamp=0, unit="o/h/c/a", value="O"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("mode1", x)),
                      
            ChannelSourceDeviceProperty(name="dev_h1", type=str,
                initial=Sample(timestamp=0, unit="dev", value="3"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("dev_h1", x)),
            
            ChannelSourceDeviceProperty(name="dev_l1", type=str,
                initial=Sample(timestamp=0, unit="dev", value="3"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("dev_l1", x)),         
                   
            ChannelSourceDeviceProperty(name="splt1", type=str,
                initial=Sample(timestamp=0, unit="degF", value="65"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("splt1", x)),
            
            ChannelSourceDeviceProperty(name="hd1_on2", type=str,
                initial=Sample(timestamp=0, unit="degF", value="4"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("hd1_on2", x)),
            
            ChannelSourceDeviceProperty(name="hd1_off2", type=str,
                initial=Sample(timestamp=0, unit="degF", value="4"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("hd1_off2", x)),
            
            ChannelSourceDeviceProperty(name="ot_on2", type=str,
                initial=Sample(timestamp=0, unit="degF", value="0"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("ot_on2", x)),
            
            ChannelSourceDeviceProperty(name="mode2", type=str,
                initial=Sample(timestamp=0, unit="o/h/c/a", value="O"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("mode2", x)),
                      
            ChannelSourceDeviceProperty(name="dev_h2", type=str,
                initial=Sample(timestamp=0, unit="dev", value="3"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("dev_h2", x)),
            
            ChannelSourceDeviceProperty(name="dev_l2", type=str,
                initial=Sample(timestamp=0, unit="dev", value="3"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("dev_l2", x)),         
                   
            ChannelSourceDeviceProperty(name="splt2", type=str,
                initial=Sample(timestamp=0, unit="degF", value="65"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("splt2", x)),
            
            ChannelSourceDeviceProperty(name="hd1_on", type=str,
                initial=Sample(timestamp=0, unit="degF", value="4"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("hd1_on", x)),
            
            ChannelSourceDeviceProperty(name="hd1_off", type=str,
                initial=Sample(timestamp=0, unit="degF", value="4"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("hd1_off", x)),
            
            ChannelSourceDeviceProperty(name="ot_on", type=str,
                initial=Sample(timestamp=0, unit="degF", value="0"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("ot_on", x)),
            
            ChannelSourceDeviceProperty(name="mode", type=str,
                initial=Sample(timestamp=0, unit="o/h/c/a", value="O"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("mode", x)),
                      
            ChannelSourceDeviceProperty(name="dev_h", type=str,
                initial=Sample(timestamp=0, unit="dev", value="3"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("dev_h", x)),
            
            ChannelSourceDeviceProperty(name="dev_l", type=str,
                initial=Sample(timestamp=0, unit="dev", value="3"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("dev_l", x)),         
                   
            ChannelSourceDeviceProperty(name="splt", type=str,
                initial=Sample(timestamp=0, unit="degF", value="65"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("splt", x)),          
                     
            ChannelSourceDeviceProperty(name="zip", type=str,
                initial=Sample(timestamp=0, unit="zip", value="10001"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.update_name("zip", x)),          


        ]
                                            
        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
  
        self.start()
Esempio n. 35
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        from core.tracing import get_tracer
        self.__tracer = get_tracer(name)

        ## Local State Variables:
        self.__xbee_manager = None

        # Settings
        #  xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                       instance.
        # sample_rate_ms: the sample rate of the XBee adapter.
        # channel1_dir: Operating I/O mode for pin 1 of the adapter.
        #               Must be a string value comprised of one of the following:
        #                   "In" - pin is configured to be an input.
        #                   "Out" - pin is configured to be an output.
        # channel2_dir: Operating I/O mode for pin 2 of the adapter.
        #               See channel2_dir for valid setting information.  
        # channel3_dir: Operating I/O mode for pin 3 of the adapter.
        #               See channel3_dir for valid setting information.
        # channel4_dir: Operating I/O mode for pin 4 of the adapter.  
        #               See channel4_dir for valid setting information.
        # channel1_source: If channel1_dir is configed as an output, this
        #                  option setting may be specified to a
        #                  "device.channel" channel name.  The Boolean value
        #                  of this channel will specify to logic state for
        #                  pin 1 on the adapter.
        # channel2_source: Configures output value source channel for pin 2
        #                  of the adapter.
        #                  See channel1_source setting information.
        # channel3_source: Configures output value source channel for pin 3
        #                  of the adapter.
        #                  See channel1_source setting information.
        # channel4_source: Configures output value source channel for pin 4
        #                  of the adapter.
        #                  See channel1_source setting information.

        settings_list = [
            Setting(
                name='extended_address', type=str, required=False,
                default_value=''),
            Setting(
                name='sample_rate_ms', type=int, required=True,
                default_value=60000,
                verify_function=lambda x: x >= 0 and x <= CYCLIC_SLEEP_EXT_MAX_MS),
           Setting(
                name='channel1_dir', type=str, required=True),
            Setting(
                name='channel1_source', type=str, required=False,
                default_value=''),
            Setting(
                name='channel2_dir', type=str, required=True),
            Setting(
                name='channel2_source', type=str, required=False,
                default_value=''),   
            Setting(
                name='channel3_dir', type=str, required=True),  
            Setting(
                name='channel3_source', type=str, required=False,
                default_value=''),
            Setting(
                name='channel4_dir', type=str, required=True),
            Setting(
                name='channel4_source', type=str, required=False,
                default_value=''),
        ]

        ## Channel Properties Definition:
        property_list = [
            ChannelSourceDeviceProperty(
                name='channel1_input', type=bool,
                initial=Sample(timestamp=0, value=False, unit='bool'),
                perms_mask=DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name='channel2_input', type=bool,
                initial=Sample(timestamp=0, value=False, unit='bool'),
                perms_mask=DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name='channel3_input', type=bool,
                initial=Sample(timestamp=0, value=False, unit='bool'),
                perms_mask=DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name='channel4_input', type=bool,
                initial=Sample(timestamp=0, value=False, unit='bool'),
                perms_mask=DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP),
        ]
                                            
        self.DIO_CONTROL_LINES = [ "d0", "d1", "d2", "d3" ]
        self.INPUT_CHANNEL_TO_PIN = [ 0, 1, 2, 3 ]
        self.DIO_MODE_INPUT = 3
        self.DIO_MODE_OUTPUT_HIGH = 3
        self.DIO_MODE_OUTPUT_LOW = 4

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 36
0
    def start(self):

        self._tracer.calls("XBeeSensor.start()")

        # init self._xbee_manager and self._extended_address
        # register ourself with our Xbee manager
        # create the self.running_indication callback
        XBeeBase.pre_start(self)

        # Retrieve the flag which tells us if we should sleep:

        # Create a callback specification for our device address
        self._xbee_manager.register_sample_listener(self,
                                                    self._extended_address,
                                                    self.sample_indication)

        # Create a DDO configuration block for this device:
        xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address)

        # Configure pins DI1 .. DI3 for analog input:
        for io_pin in ['D1', 'D2', 'D3']:
            xbee_ddo_cfg.add_parameter(io_pin, 2)

        # Configure battery-monitor pin DIO11/P1 for digital input:
        xbee_ddo_cfg.add_parameter('P1', 3)
        # Enable change detection on DIO11:
        #
        # 0x   8    0    0
        #   1000 0000 0000 (b)
        #   DDDD DDDD DDDD
        #   IIII IIII IIII
        #   OOOO OOOO OOOO
        #   1198 7654 3210
        #   10
        #
        xbee_ddo_cfg.add_parameter('IC', 0x800)

        if SettingsBase.get_setting(self, "humidity_present"):
            # Get gateway module_id, universal to all nodes on the network:
            gw_dd = self._xbee_manager.xbee_device_ddo_get_param(
                None, 'DD', use_cache=True)
            module_id, product_id = parse_dd(gw_dd)
            # Re-program DD value to set sensor type to /L/T/H:
            device_dd = format_dd(module_id, PROD_DIGI_XB_SENSOR_LTH)
            xbee_ddo_cfg.add_parameter('DD', device_dd)

        # Configure the IO Sample Rate:
        # Clip sample_rate_ms to the max value of IR:
        sample_rate_ms = SettingsBase.get_setting(self, "sample_rate_ms")
        sample_rate_ms = min(sample_rate_ms, 0xffff)
        xbee_ddo_cfg.add_parameter('IR', sample_rate_ms)

        # Register this configuration block with the XBee Device Manager:
        self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg)

        # Setup the sleep parameters on this device:
        will_sleep = SettingsBase.get_setting(self, "sleep")
        sample_predelay = SettingsBase.get_setting(self, "sample_predelay")
        awake_time_ms = (SettingsBase.get_setting(self, "awake_time_ms") +
                         sample_predelay)

        if will_sleep:
            # Sample time pre-delay, allow the circuitry to power up and
            # settle before we allow the XBee to send us a sample:
            xbee_ddo_wh_block = XBeeConfigBlockDDO(self._extended_address)
            xbee_ddo_wh_block.apply_only_to_modules((
                MOD_XB_ZB,
                MOD_XB_S2C_ZB,
            ))
            xbee_ddo_wh_block.add_parameter('WH', sample_predelay)
            self._xbee_manager.xbee_device_config_block_add(
                self, xbee_ddo_wh_block)

        # The original sample rate is used as the sleep rate:
        sleep_rate_ms = SettingsBase.get_setting(self, "sample_rate_ms")

        # new method for mesh health monitoring
        self.set_data_update_rate_seconds(sleep_rate_ms / 1000)

        # not including sample_predelay here... specially configured above
        xbee_sleep_cfg = self._xbee_manager.get_sleep_block(
            self._extended_address,
            sleep=will_sleep,
            sleep_rate_ms=sleep_rate_ms,
            awake_time_ms=awake_time_ms)

        self._xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg)

        # we've no more to config, indicate we're ready to configure.
        return XBeeBase.start(self)
Esempio n. 37
0
    def __init__(self, name, core_services, set_in=None, prop_in=None):
        """\
            Initialize an XBee Wall Router instance.

            Parameters:
                * name - The name of the XBee Wall Router instance.
                * core - The Core services instance.
                * set_in - settings from a derived class
                * prop_in - properties from a derived class

        """

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        # Settings
        #
        # sleep: True/False setting which determines if we should put the
        #        device to sleep between samples.
        # sample_rate_ms: the sample rate of the XBee adapter.
        # power: True/False setting to enable/disable the power output
        #        on terminal 6 of the adapter.
        #
        # raw_value: On/Off; On makes output sample raw binary, Off for scaled
        #            output.  Defaults to Off/False.
        # zero_clamp: min raw binary setting to call zero; if zero is disabled,
        #             else forces low values to zero.
        # channel1_mode: Operating input mode for pin 1 of the adapter.
        #                Must be a string value comprised of one of
        #                the following:
        #                "TenV" - 0-10v input available on any channel.
        #                "CurrentLoop" - 0-20 mA current loop available on
        #                                any channel.
        #                "Differential" - +/- 2.4a differential current mode
        #                                 enabled on channel1 & channel2 or
        #                                 channel3 & channel4.
        # channel2_mode: Operating input mode for pin 2 of the adapter.
        #                See channel1_mode for valid setting information.
        # channel3_mode: Operating input mode for pin 3 of the adapter.
        #                See channel1_mode for valid setting information.
        # channel4_mode: Operating input mode for pin 4 of the adapter.
        #                See channel1_mode for valid setting information.
        # awake_time_ms: How many milliseconds should the device remain
        #                awake after waking from sleep.
        # sample_predelay: How long, in milliseconds, to wait after waking
        #                  up from sleep before taking a sample from the
        #                  inputs.
        # enable_low_battery: Force an adapter to enable support for
        #                     battery-monitor pin.
        #                     It should be only enabled if adapter is using
        #                     internal batteries. Optional, Off by default.
        settings_list = [
            Setting(
                name='sleep', type=bool, required=False,
                default_value=False),
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=60000,
                verify_function=lambda x: x >= 0 and \
                                x <= CYCLIC_SLEEP_EXT_MAX_MS),
            Setting(
                name='power', type=Boolean, required=False,
                default_value=Boolean("On", STYLE_ONOFF)),
            Setting(
                name='raw_value', type=Boolean, required=False,
                default_value=Boolean("Off", STYLE_ONOFF)),
            Setting(
                name='zero_clamp', type=int, required=False,
                default_value=0, verify_function=lambda x: x >= 0),
            Setting(
                name=self.CHN_MODE_NAME[0], type=str, required=False,
                verify_function=_verify_channel_mode,
                default_value=AIO_MODE_TENV),
            Setting(
                name=self.CHN_MODE_NAME[1], type=str, required=False,
                verify_function=_verify_channel_mode,
                default_value=AIO_MODE_TENV),
            Setting(
                name=self.CHN_MODE_NAME[2], type=str, required=False,
                verify_function=_verify_channel_mode,
                default_value=AIO_MODE_TENV),
            Setting(
                name=self.CHN_MODE_NAME[3], type=str, required=False,
                verify_function=_verify_channel_mode,
                default_value=AIO_MODE_TENV),

            # These settings are provided for advanced users, they are
            # not required:
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=5000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=1000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='enable_low_battery', type=Boolean, required=False,
                default_value=Boolean("Off", STYLE_ONOFF)),
        ]
        # Add our settings_list entries into the settings passed to us.
        set_in = self.merge_settings(set_in, settings_list)

        ## Channel Properties Definition:
        property_list = [
            ChannelSourceDeviceProperty(name=self.CHN_VALUE_NAME[0],
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="V",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.CHN_VALUE_NAME[1],
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="V",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.CHN_VALUE_NAME[2],
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="V",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.CHN_VALUE_NAME[3],
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       unit="V",
                                                       value=0.0),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        # Add our property_list entries into the properties passed to us.
        prop_in = self.merge_properties(prop_in, property_list)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, set_in, prop_in)

        self._tracer.calls("XBeeAIO.__init__()")
Esempio n. 38
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services
        self.include_unit = "F"
        self.signals = 1
        self.count = 700
        self.sleeping = 0

        ## Local State Variables:
        self.__xbee_manager = None

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='sleep', type=bool, required=False,
                default_value=True),
            Setting(
                name='sample_rate_ms', type=int, required=True,
                default_value=10000,
                verify_function=lambda x: x >= 0 and x <= CYCLIC_SLEEP_EXT_MAX_MS),

            # These settings are provided for advanced users, they
            # are not required:

            Setting(
                name='trace', type=Boolean, required=False,
                default_value=Boolean("On", STYLE_ONOFF)),
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=1500,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=125,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='humidity_present', type=bool, required=False,
                default_value=False)
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="excl", type=Boolean,
                initial=Sample(timestamp=1315351550.0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.exclude("excl", x)),
            ChannelSourceDeviceProperty(name="get_signal", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.set_sig_update()),
            ChannelSourceDeviceProperty(name="signal", type=str,
                initial=Sample(timestamp=0, unit="", value=""),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="volts", type=str,
                initial=Sample(timestamp=0, unit="", value=""),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="incl", type=Boolean,
                initial=Sample(timestamp=1315351550.0,
                value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.include("incl", x)),
            ChannelSourceDeviceProperty(name="light", type=float,
                initial=Sample(timestamp=0, value=0.0, unit="brightness"),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature", type=float,
                initial=Sample(timestamp=0, value=0.0, unit="F"),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="low_battery", type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            
        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 39
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        self.__tracer = get_tracer(name)

        ## Local State Variables:
        self.__xbee_manager = None
        self.offset = 520.0
        self.__power_on_time = 0

        # Settings
        #
        # xbee_device_manager: must be set to the name of an
        #                      XBeeDeviceManager instance.
        # extended_address: the extended address of the XBee device you
        #                   would like to monitor.
        # sample_rate_ms: the sample rate of the XBee SmartPlug.
        # default_state: "On"/"Off"/"Same", if "On" the plug will default to
        #                being switched on.
        # idle_off_seconds: Number of seconds to go by before forcing
        #                   power off.
        #                   If not set the value defauts to 0, which means
        #                   the device never idles out.
        # power_on_source: optional setting; string name of a Boolean
        #                  "device.channel" to be used as the state.  For
        #                  example, if set to the name of a channel which
        #                  changes value from False to True, the SmartPlug
        #                  would change from being off to on.
        # pf_adjustment: optional setting; floating point value between
        #                0 and 1, that is used to adjust the current
        #                output given a known power factor.
        #                defaults to 1 (i.e no adjustment)
        #                Note: The unit cannot determine the pf,
        #                it is strictly a user supplied value.
        # device_profile: optional setting; string value corresponding
        #                 to a preset pf_adjustment value.
        #                 These values are by not intended to be precise;
        #                 they are only estimates.
        #                 For a list of valid device_profile settings see the
        #                 check_profiles() function in the driver source.

        settings_list = [
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=self.DEF_SAMPLE_MS,
                verify_function=lambda x: x > 0 and x < 0xffff),
            Setting(
                name='default_state', type=str, required=False,
                default_value=self.DEF_STATE,
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='idle_off_seconds', type=int, required=False,
                default_value=self.DEF_IDLE_OFF,
                verify_function=lambda x: x >= 0),
            Setting(name="power_on_source", type=str, required=False),
            Setting(name="pf_adjustment", type=float, required=False,
                    default_value=self.DEF_PF,
                    verify_function=lambda i:0 < i and i <= 1.0),
            Setting(name="device_profile", type=str, required=False),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="light", type=float,
                initial=Sample(timestamp=0, unit="brightness", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature", type=float,
                initial=Sample(timestamp=0, unit="C", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="current", type=float,
                initial=Sample(timestamp=0, unit="A", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="power_on", type=str,
                initial=Sample(timestamp=0,
                    value=str(Boolean(True, style=STYLE_ONOFF))),
                perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.prop_set_power_control),
        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 40
0
    def __init__(self, name, core_services, set_in=None, prop_in=None):
        """\
            Initialize an XBee Wall Router instance.

            Parameters:
                * name - The name of the XBee Wall Router instance.
                * core - The Core services instance.
                * set_in - settings from a derived class
                * prop_in - properties from a derived class

        """

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        ## Settings Table Definition:

        settings_list = [
            Setting(
                name='sleep_ms', type=int, required=False,
                default_value=self.DEF_SLEEP_MS,
                verify_function=lambda x: x >= 0 and \
                                x <= CYCLIC_SLEEP_EXT_MAX_MS),
            Setting(name="led1_source", type=str, required=False),
            Setting(name="led2_source", type=str, required=False),
            Setting(name="led3_source", type=str, required=False),
            # This setting is provided for advanced users:
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=self.DEF_AWAKE_MS,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
        ]
        # Add our settings_list entries into the settings passed to us.
        set_in = self.merge_settings(set_in, settings_list)

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="sw1", type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="sw2", type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="sw3", type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="sw4", type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            # gettable and settable properties
            ChannelSourceDeviceProperty(name="led1", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.prop_set_led("led1", sample)),
            ChannelSourceDeviceProperty(name="led2", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.prop_set_led("led2", sample)),
            ChannelSourceDeviceProperty(name="led3", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.prop_set_led("led3", sample)),
        ]
        # Add our property_list entries into the properties passed to us.
        prop_in = self.merge_properties(prop_in, property_list)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, set_in, prop_in)

        self._tracer.calls("XBeeXBIB.__init__()")
Esempio n. 41
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        ## Local State Variables:
        self.__xbee_manager = None

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='sleep', type=bool, required=False,
                default_value=True),
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=400,
                verify_function=lambda x: x >= 0 and x <= CYCLIC_SLEEP_EXT_MAX_MS), 
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=5000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=125,
                verify_function=lambda x: x >= 0 and x <= 0xffff),           
            Setting(
                name='default_state1', type=str, required=False,
                default_value="same",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='default_state2', type=str, required=False,
                default_value="off",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='default_state3', type=str, required=False,
                default_value="off",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='idle_off_seconds', type=int, required=False,
                default_value=0, verify_function=lambda x: x >= 0),
            Setting(name='power_on_source1', type=str, required=False),
            Setting(name='power_on_source2', type=str, required=False),
            Setting(name='power_on_source3', type=str, required=False),            
            Setting(name='device_profile', type=str, required=False),
            Setting(name='input_source', type=str, required=False, default_value=None),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
#            ChannelSourceDeviceProperty(name="input", type=tuple,
#                initial=Sample(timestamp=0, value=(0,None)),
#                perms_mask=DPROP_PERM_SET | DPROP_PERM_GET,
#                set_cb=self.prop_set_power_control1),
            ChannelSourceDeviceProperty(name="activate", type=Boolean,
                initial=Sample(timestamp=0,
                value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.unlock),
            ChannelSourceDeviceProperty(name="aa", type=str,
                initial=Sample(timestamp=0, value="lock"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET), options=DPROP_OPT_AUTOTIMESTAMP),
            
                
                
             # settable properties
 #           ChannelSourceDeviceProperty(name="counter_reset", type=int,
 #               perms_mask=DPROP_PERM_SET,
 #               set_cb=self.prop_set_counter_reset),


        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list) 
Esempio n. 42
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        ## Local State Variables:
        self.__xbee_manager = None

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='sleep', type=bool, required=False,
                default_value=True),
            Setting(
                name='sample_rate_ms', type=int, required=True,
                default_value=60000,
                verify_function=lambda x: x >= 0 and x <= CYCLIC_SLEEP_EXT_MAX_MS),


            # These settings are provided for advanced users, they
            # are not required:

            Setting(
                name='default_state', type=str, required=False,
                default_value="off",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(name="power_on_source", type=str, required=False),
            Setting(
                name='trace', type=Boolean, required=False,
                default_value=Boolean("On", STYLE_ONOFF)),
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=1000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=125,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='humidity_present', type=bool, required=False,
                default_value=False),
            Setting(
                name='count_init', type=int, required=False, default_value=0,
                  verify_function=lambda x: x >= 0),
            Setting(
                name='update_rate', type=float, required=False, default_value=1.0,
                  verify_function=lambda x: x > 0.0),
            Setting(
                name='temp', type=float, required=False, default_value=1.0),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties            
            ChannelSourceDeviceProperty(name="aa", type=str,
                initial=Sample(timestamp=0, value="temp_motion"),
                 perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET), options=DPROP_OPT_AUTOTIMESTAMP),            
            ChannelSourceDeviceProperty(name="motion", type=float,
                initial=Sample(timestamp=0, value=0.0, unit="F"),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature", type=float,
                initial=Sample(timestamp=0, value=0.0, unit="F"),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="low_battery", type=Boolean,
                initial=Sample(timestamp=0, value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="motion_event", type=Boolean,
                initial=Sample(timestamp=0, value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="power_on", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.prop_set_power_control),
           
                      

        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 43
0
    def start(self):

        self._tracer.calls("XBeeXBIB.start()")

        # init self._xbee_manager and self._extended_address
        # then register ourself with our Xbee manager
        XBeeBase.pre_start(self)

        # Create a callback specification for our device address, endpoint
        # Digi XBee profile and sample cluster id:
        self._xbee_manager.register_sample_listener(self,
                                                    self._extended_address,
                                                    self.sample_indication)

        # Configure node sleep behavior:
        sleep_ms = SettingsBase.get_setting(self, "sleep_ms")
        awake_time_ms = SettingsBase.get_setting(self, "awake_time_ms")
        # The original sample rate is used as the sleep rate:

        xbee_sleep_cfg = self._xbee_manager.get_sleep_block(
            self._extended_address,
            sleep=sleep_ms > 0,
            sleep_rate_ms=sleep_ms,
            awake_time_ms=awake_time_ms)

        self._xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg)

        # Create a DDO configuration block for this device:
        xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address)

        # Configure pins DIO0 .. DIO3 for digital input:
        for io_pin in ['D0', 'D1', 'D2', 'D3']:
            xbee_ddo_cfg.add_parameter(io_pin, 3)

        # Turn off LEDs:
        for led in LED_IO_MAP:
            xbee_ddo_cfg.add_parameter(LED_IO_MAP[led], 0)

        # Assert that all pin pull-ups are enabled:
        xbee_ddo_cfg.add_parameter('PR', 0x1fff)

        # Enable I/O line monitoring on pins DIO0 .. DIO3:
        xbee_ddo_cfg.add_parameter('IC', 0xf)

        # Register this configuration block with the XBee Device Manager:
        self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg)

        # Handle channels subscribed to output their data to our led
        # properties:
        cm = self._core.get_service("channel_manager")
        cp = cm.channel_publisher_get()
        for i in range(1, 4):
            setting_name = "led%d_source" % i
            channel_name = SettingsBase.get_setting(self, setting_name)
            if channel_name is not None:
                cp.subscribe(
                    channel_name,
                    (lambda prop: lambda cn: self.update_property(prop, cn))(
                        "led%d" % i))

        # we've no more to config, indicate we're ready to configure.
        return XBeeBase.start(self)
Esempio n. 44
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        ## Local State Variables:
        self.__xbee_manager = None
        self.trace = True

                          

        settings_list = [
            Setting(
                name='sleep', type=Boolean, required=False,
                default_value=Boolean(False)),
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=0,
                verify_function=lambda x: x >= 0 and x <= 60000),
           Setting(
                name='sleep_time_ms', type=int, required=False,
                default_value=60000,
                verify_function=lambda x: x >= 0 and \
                                x <= CYCLIC_SLEEP_EXT_MAX_MS),
            Setting(
                name='power', type=Boolean, required=True,
                default_value=Boolean("On", STYLE_ONOFF)),
            Setting(
                name='channel1_dir', type=str, required=True),
            Setting(
                name='channel1_source', type=str, required=False,
                default_value=''),
            Setting(
                name='channel2_dir', type=str, required=True),
            Setting(
                name='channel2_source', type=str, required=False,
                default_value=''),
            Setting(
                name='channel3_dir', type=str, required=True),
            Setting(
                name='channel3_source', type=str, required=False,
                default_value=''),
            Setting(
                name='channel4_dir', type=str, required=True),
            Setting(
                name='channel4_source', type=str, required=False,
                default_value=''),

            # This setting is provided for advanced users, it is not required:
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=5000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=1000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='enable_low_battery', type=Boolean, required=False,
                default_value=Boolean("Off", STYLE_ONOFF)),                             
        ]

        ## Channel Properties Definition:
        # This device hardware can monitor the state of its output
        # pins.  Therefore, there are always four input channels.
        # The other properties and channels will be populated when we
        # know the directions of our IO ports.
        property_list = [
            ChannelSourceDeviceProperty(
                name='channel1_input', type=bool,
                initial=Sample(timestamp=0, value=False, unit='1'),
                perms_mask=DPROP_PERM_GET, 
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name='channel2_input', type=bool,
                initial=Sample(timestamp=0, value=False, unit='1'),  
                perms_mask=DPROP_PERM_GET, 
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name='channel3_input', type=bool,
                initial=Sample(timestamp=0, value=False, unit='s1'),
                perms_mask=DPROP_PERM_GET, 
                options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name='channel4_input', type=bool,
                initial=Sample(timestamp=0, value=False, unit='s2'),
                perms_mask=DPROP_PERM_GET, 
                options=DPROP_OPT_AUTOTIMESTAMP),
        ]
        
        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 45
0
    def start(self):

        self._tracer.calls("XBeeAIO.start()")

        # init self._xbee_manager and self._extended_address
        # then register ourself with our Xbee manager
        XBeeBase.pre_start(self)

        # Create a callback specification for our device address, endpoint
        # Digi XBee profile and sample cluster id:
        self._xbee_manager.register_sample_listener(self,
                                                    self._extended_address,
                                                    self.sample_indication)

        # XBeeBase.pre_start(self) enables self.running_indication

        # Create a DDO configuration block for this device:
        xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address)

        for io_pin in range(4):
            # I/O pin for analog input:
            xbee_ddo_cfg.add_parameter('D%d' % (io_pin), 2)

            mode = SettingsBase.get_setting(self, self.CHN_MODE_NAME[io_pin])
            mode = AIO_MODE_MAP[mode.lower()]

            if io_pin % 2 == 1:
                last_mode = SettingsBase.\
                            get_setting(self, 'channel%d_mode' % (io_pin))
                last_mode = AIO_MODE_MAP[last_mode.lower()]

                if mode == AIO_MODE_DIFFERENTIAL:
                    if last_mode != AIO_MODE_DIFFERENTIAL:
                        raise ValueError("Differential mode may only "\
                                         "be set on odd channels.")
                    elif last_mode == AIO_MODE_DIFFERENTIAL:
                        # Nothing to do for this paired channel.
                        continue

                elif mode != AIO_MODE_DIFFERENTIAL and \
                    last_mode == AIO_MODE_DIFFERENTIAL:
                    raise ValueError("Unable to change mode, paired " \
                                     "channel is configured for "\
                                     "Differential operation.")

            if mode == AIO_MODE_CURRENTLOOP:
                xbee_ddo_cfg.add_parameter(
                    AIO_CONTROL_LINES[io_pin][AIO_LINE_A], 4)
                xbee_ddo_cfg.add_parameter(
                    AIO_CONTROL_LINES[io_pin][AIO_LINE_B], 4)
            elif mode == AIO_MODE_TENV:
                xbee_ddo_cfg.add_parameter(
                    AIO_CONTROL_LINES[io_pin][AIO_LINE_A], 5)
                xbee_ddo_cfg.add_parameter(
                    AIO_CONTROL_LINES[io_pin][AIO_LINE_B], 4)
            elif mode == AIO_MODE_DIFFERENTIAL:
                xbee_ddo_cfg.add_parameter(
                    AIO_CONTROL_LINES[io_pin][AIO_LINE_A], 4)
                xbee_ddo_cfg.add_parameter(
                    AIO_CONTROL_LINES[io_pin][AIO_LINE_B], 5)
                xbee_ddo_cfg.add_parameter(
                    AIO_CONTROL_LINES[io_pin + 1][AIO_LINE_A], 4)
            # else: for OFF, do nothing

            # TODO: in the future when we support changing the settings
            #       for this adapter on the fly we would need to do:
            #if previous_mode == Differential and new_mode != Differential:
            #    xbee_ddo_cfg.add_paramseter(
            #        (AIO_CONTROL_LINES[io_pin+1][AIO_LINE_A], 5))
            #    # TODO: Set setting for io_pin+1 to TenV Mode

        # if adapter is using internal batteries, then configure
        # battery-monitor pin and add low_battery channel
        if SettingsBase.get_setting(self, "enable_low_battery"):
            # configure battery-monitor pin DIO11/P1 for digital input
            xbee_ddo_cfg.add_parameter('P1', 3)
            # add low_battery channel
            self._tracer.info("adapter is using internal batteries... " +
                              "adding low battery channel")
            self.add_property(
                ChannelSourceDeviceProperty(name="low_battery", type=bool,
                    initial=Sample(timestamp=0, value=False),
                    perms_mask=DPROP_PERM_GET, \
                                            options=DPROP_OPT_AUTOTIMESTAMP))
        else:
            self._tracer.info("adapter is not using internal batteries.")

        # disable the triggered low-battery alarm since it causes problems
        # we see the value every time new values are sent anyway
        ic = 0
        xbee_ddo_cfg.add_parameter('IC', ic)

        # Assert input pull-ups
        xbee_ddo_cfg.add_parameter('PR', 0x1fff)

        # Is the unit meant to sleep or not?
        will_sleep = SettingsBase.get_setting(self, "sleep")

        # Configure the IO Sample Rate.
        #
        # This gets a little trickier in cases where the unit is NOT
        # in sleep mode, yet the sampling rate is over a minute.
        #
        # (The max value for IR is 64K and is in milliseconds.
        # This ends up being a tad over a minute.
        #
        # So if we are NOT in sleep mode, and our sample rate
        # is over 1 minute, 5 seconds (64K), we will set IR to 0,
        # and set up DIA (in the make_request call), to call us back
        # when our poll rate is about to trigger.

        # self._xbee_manager.get_sleep_block() manages 'IR'

        # Enable/disable power output on terminal 6:
        power = SettingsBase.get_setting(self, "power")
        if power:
            xbee_ddo_cfg.add_parameter('p3', 5)
        else:
            xbee_ddo_cfg.add_parameter('p3', 4)

        # Register this configuration block with the XBee Device Manager:
        self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg)

        # Setup the sleep parameters on this device:
        will_sleep = SettingsBase.get_setting(self, "sleep")
        sample_predelay = SettingsBase.get_setting(self, "sample_predelay")
        awake_time_ms = (SettingsBase.get_setting(self, "awake_time_ms") +
                         sample_predelay)
        # The original sample rate is used as the sleep rate:
        sleep_rate_ms = SettingsBase.get_setting(self, "sample_rate_ms")

        xbee_sleep_cfg = self._xbee_manager.get_sleep_block(
            self._extended_address,
            sleep=will_sleep,
            sample_predelay=sample_predelay,
            awake_time_ms=awake_time_ms,
            sleep_rate_ms=sleep_rate_ms)

        self._xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg)

        # we've no more to config, indicate we're ready to configure.
        return XBeeBase.start(self)
Esempio n. 46
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        from core.tracing import get_tracer
        self.__tracer = get_tracer(name)

        ## Local State Variables:
        self.__xbee_manager = None

        self.__OLD_HARDWARE = False
        self.__scale = 0.0
        self.__offset = 0.0

        # Force a calibration every read.
        self.__calibration_interval = 0
        self.__calibration_time = -self.__calibration_interval

        self.__lock = threading.Lock()

        # Settings
        #
        # xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                      instance.
        # sample_rate_ms: the sample rate of the XBee adapter.
        # channel1_mode: Operating input mode for pin 1 of the adapter.
        #                Must be a string value comprised of one of the following:
        #                    "TenV" - 0-10v input available on any channel.
        #                    "CurrentLoop" - 0-20 mA current loop available on
        #                                    any channel.
        # channel2_mode: Operating input mode for pin 2 of the adapter.
        #                See channel1_mode for valid setting information.
        # channel3_mode: Operating input mode for pin 3 of the adapter.
        #                See channel1_mode for valid setting information.
        # channel4_mode: Operating input mode for pin 4 of the adapter.
        #                See channel1_mode for valid setting information.

        settings_list = [
            Setting(
                name='extended_address', type=str, required=False,
                default_value=''),
            Setting(
                name='sample_rate_ms', type=int, required=True,
                default_value=60000,
                verify_function=lambda x: x >= 0 and x <= CYCLIC_SLEEP_EXT_MAX_MS),
            Setting(
                name='channel1_mode', type=str, required=False,
                verify_function=_verify_channel_mode,
                default_value=self.LOCAL_AIO_MODE_TENV),
            Setting(
                name='channel2_mode', type=str, required=False,
                verify_function=_verify_channel_mode,
                default_value=self.LOCAL_AIO_MODE_TENV),
            Setting(
                name='channel3_mode', type=str, required=False,
                verify_function=_verify_channel_mode,
                default_value=self.LOCAL_AIO_MODE_TENV),
            Setting(
                name='channel4_mode', type=str, required=False,
                verify_function=_verify_channel_mode,
                default_value=self.LOCAL_AIO_MODE_TENV),

        ]

        ## Channel Properties Definition:
        property_list = [
            ChannelSourceDeviceProperty(name="channel1_value", type=float,
                initial=Sample(timestamp=0, unit="V", value=0.0),
                perms_mask=DPROP_PERM_GET|DPROP_PERM_REFRESH, options=DPROP_OPT_AUTOTIMESTAMP,
                refresh_cb = self.refresh),
            ChannelSourceDeviceProperty(name="channel2_value", type=float,
                initial=Sample(timestamp=0, unit="V", value=0.0),
                perms_mask=DPROP_PERM_GET|DPROP_PERM_REFRESH, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="channel3_value", type=float,
                initial=Sample(timestamp=0, unit="V", value=0.0),
                perms_mask=DPROP_PERM_GET|DPROP_PERM_REFRESH, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="channel4_value", type=float,
                initial=Sample(timestamp=0, unit="V", value=0.0),
                perms_mask=DPROP_PERM_GET|DPROP_PERM_REFRESH, options=DPROP_OPT_AUTOTIMESTAMP),
        ]
                                            
        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 47
0
    def __init__(self, name, core_services, set_in=None, prop_in=None):

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        ## XBeeBase manages these settings:
        #   xbee_device_manager: the name of an XBeeDeviceManager instance.
        #   extended_address:    the extended address of the XBee device you
        #                            would like to monitor.

        ## Local State Variables:
        self._last_timestamp = 0

        # Settings
        #
        # xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                      instance.
        # extended_address: the extended address of the XBee Sensor device you
        #                   would like to monitor.
        # sleep: True/False setting which determines if we should put the
        #        device to sleep between samples.  Default: True
        # sample_rate_ms: the sample rate of the XBee adapter. Default:
        #                 60,000 ms or one minute.
        #
        # Advanced settings:
        #
        # awake_time_ms: how long should the sensor stay awake after taking
        #                a sample?  The default is 1000 ms.
        # sample_predelay: how long should the sensor be awake for
        #                  before taking its sample reading?  This
        #                  delay is used to allow the
        #                  device's sensoring components to warm up before
        #                  taking a sample.  The default is 125ms.
        # humidity_present: force a sensor which has not been detected to have
        #                   humidity capability to having humidity capability
        #                   present.  Writes the devices DD device-type value
        #                   as a side effect.
        # degf:             The temperature channel will output in Fahrenheit,
        #                   and units will be "F", if this boolean is set to True
        # offset:           A simple float that will be applied against the temperature.
        #                   This offset is in degrees Celsius if degf = False,
        #                   and in degrees Fahrenheit if degf = True.

        settings_list = [
            Setting(
                name='sleep', type=bool, required=False,
                default_value=self.DEF_SLEEP),
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=self.DEF_SAMPLE_MS,
                verify_function=lambda x: x >= 0 and \
                                          x <= CYCLIC_SLEEP_EXT_MAX_MS),

            # These settings are provided for advanced users, they
            # are not required:

            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=self.DEF_AWAKE_MS,
                verify_function=lambda x: x >= 0 and x <= 0xffff),

            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=self.DEF_PREDELAY,
                verify_function=lambda x: x >= 0 and x <= 0xffff),

            Setting(
                name='humidity_present', type=bool, required=False,
                default_value=self.DEF_HUMIDITY),

            Setting(
                name='degf', type=bool, required=False,
                default_value=self.DEF_DEGF),

            Setting(
                name='offset', type=float, required=False,
                default_value=self.DEF_OFFSET),
            ]

        # Add our settings_list entries into the settings passed to us.
        set_in = self.merge_settings(set_in, settings_list)

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="light",
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       value=0.0,
                                                       unit="brightness"),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature",
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       value=0.0,
                                                       unit="C"),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="low_battery",
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        # Add our property_list entries into the properties passed to us.
        prop_in = self.merge_properties(prop_in, property_list)

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, set_in, prop_in)

        self._tracer.calls("XBeeSensor.__init__()")
Esempio n. 48
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services


        ## Local State Variables:
        self.__xbee_manager = None

        ## Settings Table Definition:
        settings_list = [
            Setting(
                name='sample_rate_ms', type=int, required=False,
                default_value=1000,
                verify_function=lambda x: x > 0 and x < 0xffff),
            Setting(
                name='default_state1', type=str, required=False,
                default_value="off",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='default_state2', type=str, required=False,
                default_value="off",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='default_state3', type=str, required=False,
                default_value="off",
                parser=lambda s: s.lower(),
                verify_function=lambda s: s in initial_states),
            Setting(
                name='idle_off_seconds', type=int, required=False,
                default_value=0, verify_function=lambda x: x >= 0),
            Setting(name='power_on_source1', type=str, required=False),
            Setting(name='power_on_source2', type=str, required=False),
            Setting(name='power_on_source3', type=str, required=False),            
            Setting(name='device_profile', type=str, required=False),
            Setting(name='input_source', type=str, required=False, default_value=None),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="input", type=tuple,
                initial=Sample(timestamp=0, value=(0,None)),
                perms_mask=DPROP_PERM_SET | DPROP_PERM_GET,
                set_cb=self.prop_set_power_control1),
            ChannelSourceDeviceProperty(name="utemp", type=float,
                initial=Sample(timestamp=0, unit="F", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="up", type=float,
                initial=Sample(timestamp=0, unit="mv", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="aa", type=str,
                initial=Sample(timestamp=0, value="thermostat_switch"),
                 perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET), options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="down", type=float,
                initial=Sample(timestamp=0, unit="mv", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="on", type=float,
                initial=Sample(timestamp=0, unit="mv", value=0.0),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="power_on", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.prop_set_power_control1),
            ChannelSourceDeviceProperty(name="dim_up", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.prop_set_power_control2),
            ChannelSourceDeviceProperty(name="dim_down", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(True, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self.prop_set_power_control3),
            ChannelSourceDeviceProperty(name="user_input_1", type=str,
                initial=Sample(timestamp=0, value="TempLight.temperature"),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.prop_set_adder("user_input_1", x)),
            ChannelSourceDeviceProperty(name="adder_reg1", type=float,
                initial=Sample(timestamp=0, value=0.0),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.prop_set_adder("adder_reg1", x)),
            ChannelSourceDeviceProperty(name="adder_reg2", type=float,
                initial=Sample(timestamp=0, value=0.0),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda x: self.prop_set_adder("adder_reg2", x)),
            ChannelSourceDeviceProperty(name="adder_total", type=float,
                initial=Sample(timestamp=0, value=0.0),
                perms_mask=DPROP_PERM_GET, 
                options=DPROP_OPT_AUTOTIMESTAMP, set_cb=self.prop_set_power_control1),  
            ChannelSourceDeviceProperty(name="counter", type=int,
                initial=Sample(timestamp=0, value=0),
                perms_mask=DPROP_PERM_GET|DPROP_PERM_REFRESH, 
                options=DPROP_OPT_AUTOTIMESTAMP,
                refresh_cb = self.refresh_counter),
                
             # settable properties
            ChannelSourceDeviceProperty(name="counter_reset", type=int,
                perms_mask=DPROP_PERM_SET,
                set_cb=self.prop_set_counter_reset),

            ChannelSourceDeviceProperty(name="global_reset", type=int, 
                perms_mask=DPROP_PERM_SET, 
                set_cb=self.prop_set_global_reset),
        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list) 
Esempio n. 49
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        from core.tracing import get_tracer
        self.__tracer = get_tracer(name)

        ## Local State Variables:
        self.__xbee_manager = None

        # Settings
        #  xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                       instance.
        # sample_rate_ms: the sample rate of the XBee adapter.
        # channel1_dir: Operating I/O mode for pin 1 of the adapter.
        #               Must be a string value comprised of one of the following:
        #                   "In" - pin is configured to be an input.
        #                   "Out" - pin is configured to be an output.
        # channel2_dir: Operating I/O mode for pin 2 of the adapter.
        #               See channel2_dir for valid setting information.
        # channel3_dir: Operating I/O mode for pin 3 of the adapter.
        #               See channel3_dir for valid setting information.
        # channel4_dir: Operating I/O mode for pin 4 of the adapter.
        #               See channel4_dir for valid setting information.
        # channel1_source: If channel1_dir is configed as an output, this
        #                  option setting may be specified to a
        #                  "device.channel" channel name.  The Boolean value
        #                  of this channel will specify to logic state for
        #                  pin 1 on the adapter.
        # channel2_source: Configures output value source channel for pin 2
        #                  of the adapter.
        #                  See channel1_source setting information.
        # channel3_source: Configures output value source channel for pin 3
        #                  of the adapter.
        #                  See channel1_source setting information.
        # channel4_source: Configures output value source channel for pin 4
        #                  of the adapter.
        #                  See channel1_source setting information.

        settings_list = [
            Setting(name='extended_address',
                    type=str,
                    required=False,
                    default_value=''),
            Setting(name='sample_rate_ms',
                    type=int,
                    required=True,
                    default_value=60000,
                    verify_function=lambda x: x >= 0 and x <=
                    CYCLIC_SLEEP_EXT_MAX_MS),
            Setting(name='channel1_dir', type=str, required=True),
            Setting(name='channel1_source',
                    type=str,
                    required=False,
                    default_value=''),
            Setting(name='channel2_dir', type=str, required=True),
            Setting(name='channel2_source',
                    type=str,
                    required=False,
                    default_value=''),
            Setting(name='channel3_dir', type=str, required=True),
            Setting(name='channel3_source',
                    type=str,
                    required=False,
                    default_value=''),
            Setting(name='channel4_dir', type=str, required=True),
            Setting(name='channel4_source',
                    type=str,
                    required=False,
                    default_value=''),
        ]

        ## Channel Properties Definition:
        property_list = [
            ChannelSourceDeviceProperty(name='channel1_input',
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False,
                                                       unit='bool'),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name='channel2_input',
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False,
                                                       unit='bool'),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name='channel3_input',
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False,
                                                       unit='bool'),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name='channel4_input',
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False,
                                                       unit='bool'),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        self.DIO_CONTROL_LINES = ["d0", "d1", "d2", "d3"]
        self.INPUT_CHANNEL_TO_PIN = [0, 1, 2, 3]
        self.DIO_MODE_INPUT = 3
        self.DIO_MODE_OUTPUT_HIGH = 3
        self.DIO_MODE_OUTPUT_LOW = 4

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core, settings_list,
                          property_list)
Esempio n. 50
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        from core.tracing import get_tracer
        self.__tracer = get_tracer(name)

        ## Local State Variables:
        self.__xbee_manager = None

        # Settings
        #
        # xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                      instance.
        # extended_address: the extended address of the XBee Sensor device you
        #                   would like to monitor.
        # sleep: True/False setting which determines if we should put the
        #        device to sleep between samples.  Default: True
        # sample_rate_ms: the sample rate of the XBee adapter. Default:
        #                 60,000 ms or one minute.
        #
        # Advanced settings:
        #
        # awake_time_ms: how long should the sensor stay awake after taking
        #                a sample?  The default is 1000 ms.
        # sample_predelay: how long should the sensor be awake for before taking
        #                  its sample reading?  This delay is used to allow the
        #                  device's sensoring components to warm up before
        #                  taking a sample.  The default is 125ms.
        # humidity_present: force a sensor which has not been detected to have
        #                   humidity capability to having humidity capability
        #                   present.  Writes the devices DD device-type value
        #                   as a side effect.

        settings_list = [
            Setting(
                name='sleep', type=bool, required=False,
                default_value=True),
            Setting(
                name='sample_rate_ms', type=int, required=True,
                default_value=60000,
                verify_function=lambda x: x >= 0 and x <= CYCLIC_SLEEP_EXT_MAX_MS),

            # These settings are provided for advanced users, they
            # are not required:
            
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=1000,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='sample_predelay', type=int, required=False,
                default_value=125,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
            Setting(
                name='humidity_present', type=bool, required=False,
                default_value=False)
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="light", type=float,
                initial=Sample(timestamp=0, value=0.0, unit="brightness"),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature", type=float,
                initial=Sample(timestamp=0, value=0.0, unit="C"),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="low_battery", type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        ## Local State Variables:
        self.__xbee_manager = None

        from core.tracing import get_tracer
        self.__tracer = get_tracer(name)

        ## Settings Table Definition:

        settings_list = [
            Setting(
                name = 'xbee_device_manager', type = str, required = False,
                default_value = ''),
            Setting(
                name = 'extended_address', type = str, required = False,
                default_value = ''),
            Setting(
                name='sleep_ms', type=int, required=False,
                default_value=1000),
            Setting(name="led1_source", type=str, required=False),
            Setting(name="led2_source", type=str, required=False),
            Setting(name="led3_source", type=str, required=False),
            # This setting is provided for advanced users:
            Setting(
                name='awake_time_ms', type=int, required=False,
                default_value=1500,
                verify_function=lambda x: x >= 0 and x <= 0xffff),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="sw1", type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="sw2", type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="sw3", type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="sw4", type=bool,
                initial=Sample(timestamp=0, value=False),
                perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP),
            # gettable and settable properties
            ChannelSourceDeviceProperty(name="led1", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.prop_set_led("led1", sample)),
            ChannelSourceDeviceProperty(name="led2", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.prop_set_led("led2", sample)),
            ChannelSourceDeviceProperty(name="led3", type=Boolean,
                initial=Sample(timestamp=0,
                    value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.prop_set_led("led3", sample)),
        ]

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, self.__name, self.__core,
                                settings_list, property_list)
Esempio n. 52
0
    def __init__(self, name, core_services):

        # DeviceBase will create:
        #   self._name, self._core, self._tracer,
        # XBeeBase will create:
        #   self._xbee_manager, self._extended_address

        ## XBeeBase manages these settings:
        #   xbee_device_manager: the name of an XBeeDeviceManager instance.
        #   extended_address:    the extended address of the XBee device you
        #                            would like to monitor.

        ## Local State Variables:
        self._last_timestamp = 0
        self.parser = WirelessPacketParser()

        ## Settings Table Definition:
        settings_list = [
                Setting(name = self.KEY_SAMPLE_RATE, type = int, required = False,
                default_value = 60,
                verify_function = lambda x: \
                                  x >= 30 and \
                                  x <= 525600 * 60),
                Setting(name = self.parser.KEY_XMIT_PERIOD, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_ALARM_EXIT, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_TRIES, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_HYSTERISIS, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_LOG_PERIOD, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_HI_VAL1, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_HI_TIME1, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_LO_VAL1, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_LO_TIME1, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_HI_VAL2, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_HI_TIME2, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_LO_VAL2, type = dict, required = False,
                default_value = {}),
                Setting(name = self.parser.KEY_LO_TIME2, type = dict, required = False,
                default_value = {}),
                                  ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name=self.KEY_CHANNEL + str(1),
                                        type=float,
                                        initial=Sample(
                                            timestamp=0,
                                            value=-9223372036854775808.0,
                                            unit="units"),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_CHANNEL + str(2),
                                        type=float,
                                        initial=Sample(
                                            timestamp=0,
                                            value=-9223372036854775808.0,
                                            unit="units"),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_CHANNEL + str(3),
                                        type=float,
                                        initial=Sample(
                                            timestamp=0,
                                            value=-9223372036854775808.0,
                                            unit="units"),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_CHANNEL + str(4),
                                        type=float,
                                        initial=Sample(
                                            timestamp=0,
                                            value=-9223372036854775808.0,
                                            unit="units"),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_ALARM,
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_BATTERY_COUNT,
                                        type=int,
                                        initial=Sample(timestamp=0, value=0),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_BATTERY_LOW,
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_DEVICE_ID,
                                        type=str,
                                        initial=Sample(timestamp=0, value=''),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_DOOR_OPEN,
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_ERROR,
                                        type=list,
                                        initial=Sample(timestamp=0, value=[]),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_LINE_POWERED,
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_LOCALLY_CONFIGURED,
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_PACKET_COUNT,
                                        type=int,
                                        initial=Sample(timestamp=0, value=0),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_REMAINING_BATT_PCT,
                                        type=float,
                                        initial=Sample(timestamp=0, value=0.0),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_SERIAL_NO,
                                        type=str,
                                        initial=Sample(timestamp=0, value=''),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name=self.KEY_SERVICE_PRESSED,
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=False),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        #initialize packet cache
        self.packetCache = None
        self.packetCacheTimestamp = 0

        ## Initialize the XBeeBase interface:
        XBeeBase.__init__(self, name, core_services, settings_list,
                          property_list)

        self._tracer.calls('WirelessSensor init')
Esempio n. 53
0
    def start(self):

        self._tracer.calls("XBeeDIO.start()")

        # init self._xbee_manager and self._extended_address
        # then register ourself with our Xbee manager
        XBeeBase.pre_start(self)

        cm = self._core.get_service("channel_manager")
        cp = cm.channel_publisher_get()
        
        self._xbee_manager.register_sample_listener(self, self._extended_address,
                                                     self.sample_indication)

        # XbeeBase enables self.running_indication

        # Create a DDO configuration block for this device:
        xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address)

        # Configure pins DIO0 .. DIO3 for digital input:
        pr = 0xe1 # DIO0-3 pullups off, all else on
        ic = 0

        for io_pin in range(4):
            dir = SettingsBase.get_setting(self, 'channel%d_dir' % \
                                           (io_pin + 1))
            dir = dir.lower()

            # Enable input on all pins:
            xbee_ddo_cfg.add_parameter(CONTROL_LINES[io_pin][IN], 3)

            # Build our change detection mask for all io pins:
            ic |= 1 << INPUT_CHANNEL_TO_PIN[io_pin]

            if dir == 'in':
                # Disable sinking driver output:
                xbee_ddo_cfg.add_parameter(CONTROL_LINES[io_pin][OUT], 4)

            elif dir == 'out':
                # Create the output channel for this IO pin:
                self.add_property(
                    ChannelSourceDeviceProperty(
                        name=self.CHN_OUTPUT_NAME[io_pin], type=Boolean,
                        initial=Sample(timestamp=0, value=Boolean(False),
                                       unit='bool'),
                        perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                        options=DPROP_OPT_AUTOTIMESTAMP,
                        set_cb=lambda sample, io=io_pin: \
                                self.set_output(sample, io)))

                # If set, subscribe to the channel that drives our
                # output logic:
                source = SettingsBase.get_setting(self, 'channel%d_source'
                                                  % (io_pin + 1))
                if len(source):
                    cp.subscribe(source,
                                 lambda chan, io=io_pin: \
                                       self.update(chan, io))

                    self._tracer.debug("Linking DOUT %d to channel %s", io_pin+1, source)
                    
                # If not set, attempt to grab the default output setting,
                # and use that instead.
                else:
                    out = SettingsBase.get_setting(self, 'channel%d_default'
                                                   % (io_pin + 1))
                    if out == True:
                        self._tracer.debug("Setting default output to High")
                        xbee_ddo_cfg.add_parameter(CONTROL_LINES[io_pin][OUT],
                                                   5)
                    elif out == False:
                        self._tracer.debug("Setting default output to Low")
                        xbee_ddo_cfg.add_parameter(CONTROL_LINES[io_pin][OUT],
                                                   4)
                    else:
                        self._tracer.debug("Not setting default output value")

        # if adapter is using internal batteries, then configure
        # battery-monitor pin and add low_battery channel
        if SettingsBase.get_setting(self, "enable_low_battery"):
            # configure battery-monitor pin DIO11/P1 for digital input
            xbee_ddo_cfg.add_parameter('P1', 3)
            # add low_battery channel
            self._tracer.debug("Adapter is using internal batteries... " +
                               "adding low_battery channel")
            self.add_property(
                ChannelSourceDeviceProperty(name="low_battery", type=bool,
                    initial=Sample(timestamp=0, value=False),
                    perms_mask=DPROP_PERM_GET,
                    options=DPROP_OPT_AUTOTIMESTAMP))
        else:
            self._tracer.debug("Adapter is not using internal batteries.")

        # Enable I/O line monitoring on pins DIO0 .. DIO3 &
        # enable change detection on DIO11:
        #
        # 0x   8    0    0
        #   1000 0000 0000 (b)
        #   DDDD DDDD DDDD
        #   IIII IIII IIII
        #   OOOO OOOO OOOO
        #   1198 7654 3210
        #   10
        #
        xbee_ddo_cfg.add_parameter('IC', ic)

        # Assert input pull-ups
        xbee_ddo_cfg.add_parameter('PR', 0x1fff)

        # self._xbee_manager.get_sleep_block() manages 'IR'

        # Enable/disable power output on terminal 6:
        power = SettingsBase.get_setting(self, "power")
        if power:
            xbee_ddo_cfg.add_parameter('p3', 5)
        else:
            xbee_ddo_cfg.add_parameter('p3', 4)

        # Register this configuration block with the XBee Device Manager:
        self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg)

        # Setup the sleep parameters on this device:
        will_sleep = SettingsBase.get_setting(self, "sleep")
        sample_predelay = SettingsBase.get_setting(self, "sample_predelay")
        awake_time_ms = (SettingsBase.get_setting(self, "awake_time_ms") +
                         sample_predelay)
        # The original sample rate is used as the sleep rate:
        sleep_rate_ms = SettingsBase.get_setting(self, "sample_rate_ms")

        if sleep_rate_ms == 0 and will_sleep:
            # bounding sleep rate in when sampling is disabled and
            # sleeping is enabled
            sleep_rate_ms = CYCLIC_SLEEP_MIN_MS

        xbee_sleep_cfg = self._xbee_manager.get_sleep_block(\
            self._extended_address,
            sleep=will_sleep,
            sample_predelay=sample_predelay,
            awake_time_ms=awake_time_ms,
            sleep_rate_ms=sleep_rate_ms)

        self._xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg)
        self._xbee_manager.xbee_device_configure(self)
        return True