def start(self): """Start the device driver. Returns bool.""" self._tracer.calls("MassaM300.start()") # create our M300 object bus_id = SettingsBase.get_setting(self, "bus_id") self.__sensor = MassaM300_Sensor(bus_id) # if bus_id isn't 0, treat as multi-drop self.__sensor.set_mode_multidrop(bus_id != 0) # 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.pre_start() # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address) # Enable +12v output terminal on RS-485 adapter pin 6: xbee_ddo_cfg.add_parameter('D2', 5) # Register configuration blocks with the XBee Device Manager: self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Call the XBeeSerial function to add the initial set up of our device. # This will set up the destination address of the devidce, and also set # the default baud rate, parity, stop bits and flow control. return XBeeSerial.start(self)
def __init__(self, xbee_manager, addr, callback): self.__xbee_manager = xbee_manager self.__addr = addr self.__callback = callback self.DESTINATION = (addr, 0xe8, 0xc105, 0x11) self.__xbee_manager.xbee_device_register(self) # 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._dataReceived) xbdm_rx_event_spec.match_spec_set((addr, 0xe8, 0xc105, 0x11), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(addr) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for data to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # TODO, might want to think about adding serial config, etc. # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self)
def __init__(self, xbee_manager, addr, callback): self.__xbee_manager = xbee_manager self.__addr = addr self.__callback = callback self.DESTINATION=(addr, 0xe8, 0xc105, 0x11) self.__xbee_manager.xbee_device_register(self) # 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._dataReceived) xbdm_rx_event_spec.match_spec_set( (addr, 0xe8, 0xc105, 0x11), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(addr) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for data to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # TODO, might want to think about adding serial config, etc. # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self)
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, 'extended_address') # Create a callback specification for our device address, endpoint # Digi XBee profile and sample cluster id: self.__xbee_manager.register_sample_listener(self, extended_address, self.sample_indication) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(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) # 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) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Call the XBeeSerial function to add the initial set up of our device. # This will set up the destination address of the devidce, and also set # the default baud rate, parity, stop bits and flow control. XBeeSerial.initialize_xbee_serial(self, xbee_ddo_cfg) # 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(extended_address) xbee_ddo_wh_block.apply_only_to_modules((MOD_XB_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") xbee_sleep_cfg = XBeeConfigBlockSleep(extended_address) if will_sleep: xbee_sleep_cfg.sleep_cycle_set(awake_time_ms, sleep_rate_ms, enable_pin_wake=True) else: xbee_sleep_cfg.sleep_mode_set(SM_DISABLED) self.__xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
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 start(self): """Start the device driver. Returns bool.""" # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) xbee_ddo_cfg.add_parameter("NI", "") # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) #gw_mac = #xbee_ddo_cfg.add_parameter('ID', gw_mac) # Configure pins DI1 & DI2 for analog input: for io_pin in [ 'D1', 'D2' ]: xbee_ddo_cfg.add_parameter(io_pin, 2) # Configure the IO Sample Rate: sample_rate = SettingsBase.get_setting(self, "sample_rate_ms") xbee_ddo_cfg.add_parameter('IR', sample_rate) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) self.property_set("incl", Sample(0, value=Boolean(bool(1), style=STYLE_ONOFF))) self.property_set("excl", Sample(0, value=Boolean(bool(0), style=STYLE_ONOFF))) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): """Start the device driver. Returns bool.""" try: self.ch_name, self.ch_unit = SettingsBase.get_setting(self, "channel_settings").split(',') except: self.ch_name, self.ch_unit = 'name', 'unit' self.add_property( ChannelSourceDeviceProperty(name=self.ch_name, type=str, initial=Sample(timestamp=0, value="", unit=self.ch_unit), perms_mask=(DPROP_PERM_GET), options=DPROP_OPT_AUTOTIMESTAMP ) ) # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): """Start the device driver. Returns bool.""" # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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.serial_receive) xbdm_rx_event_spec.match_spec_set( (extended_address, 0xe8, 0xc105, 0x11), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) #register a callback for when the config is done xb_rdy_state_spec = XBeeDeviceManagerRunningEventSpec() xb_rdy_state_spec.cb_set(self._config_done_cb) self.__xbee_manager.xbee_device_event_spec_add(self, xb_rdy_state_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): """Start the device driver. Returns bool.""" self.logger.info("========== Starting up ==========") self.apply_settings() # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Call the XBeeSerial function to add the initial set up of our device. # This will set up the destination address of the devide, and also set # the default baud rate, parity, stop bits and flow control. XBeeSerial.initialize_xbee_serial(self, xbee_ddo_cfg) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) threading.Thread.start(self) return True
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)
def start(self): """Start the device driver. Returns bool.""" # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Call the XBeeSerial function to add the initial set up of our device. # This will set up the destination address of the devidce, and also set # the default baud rate, parity, stop bits and flow control. XBeeSerial.initialize_xbee_serial(self, xbee_ddo_cfg) # TODO - these RS-485 issues should be abstracted to XBeeSerial # Assert that the AT node is enabled for RS-485 HIGH: xbee_ddo_cfg.add_parameter('D7', 7) # Enable +12v outpout terminal on RS-485 adapter pin 6: xbee_ddo_cfg.add_parameter('D2', 5) # Packetization timeout to 6 characters (standard M300 msg len): xbee_ddo_cfg.add_parameter('RO', 6) # Register configuration blocks with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
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): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) cm = self.__core.get_service("channel_manager") cp = cm.channel_publisher_get() # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: self.__extended_address = SettingsBase.get_setting(self, "extended_address") address = self.__extended_address self.thermostat = TemplateDevice(("thermostat_" + address), self.__core) time.sleep(3) SettingsBase.set_pending_setting(self, "channel1_source", ("thermostat_" + address + ".heat_on")) SettingsBase.set_pending_setting(self, "channel2_source", ("thermostat_" + address + ".heat_off")) # channel1_source: "thermostat_[00:05:a2:00:40:52:e0:fc]!.heat_on" # channel2_source: "thermostat_[00:05:a2:00:40:52:e0:fc]!.heat_off" print print ("thermostat_" + address + ".heat_on") print ("thermostat_" + address + ".heat_off") # str1 = ("thermostat_" + address + ".heat_on") # str2 = ("thermostat_" + address + ".heat_off") self.apply_settings() # 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, 0x92), (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) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(self.__extended_address) xbee_ddo_cfg.add_parameter("NI", "") # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # 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='channel%d_output' % (io_pin+1), type=Boolean, initial=Sample(timestamp=0, value=Boolean(False), unit='1'), 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)) print print "here is the place that really matters when it comes to the source" print source if len(source): cp.subscribe(source, lambda chan, io=io_pin: self.update(chan, io) ) # Set initial value of output to low: # TODO: add a default output condition here: xbee_ddo_cfg.add_parameter(CONTROL_LINES[io_pin][OUT], 4) # 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 print ("XBeeDIO(%s): adapter is using internal batteries adding " \ + "low_battery channel") % self.__name 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: print "XBeeDIO(%s): adapter is not using internal batteries." \ % self.__name # 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 # #ic |= 0x800 #xbee_ddo_cfg.add_parameter('IC', ic) # disable the triggered low-battery alarm since a hardware bug # causes it to be unrealiable #ic |= 0x800 xbee_ddo_cfg.add_parameter('IC', ic) # Assert input pull-ups xbee_ddo_cfg.add_parameter('PR', 0x1fff) # this defaults to 0 xbee_ddo_cfg.add_parameter('IR', SettingsBase.get_setting(self, 'sample_rate_ms')) # 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_time_ms = SettingsBase.get_setting(self, "sleep_time_ms") xbee_sleep_cfg = XBeeConfigBlockSleep(self.__extended_address) if will_sleep: xbee_sleep_cfg.sleep_cycle_set(awake_time_ms, sleep_time_ms) else: xbee_sleep_cfg.sleep_mode_set(SM_DISABLED) self.__xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg) 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,)) xbee_ddo_wh_block.add_parameter('WH', sample_predelay) self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_wh_block) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): """Start the device driver. Returns bool.""" # Attempt to detect if we are on older units that require a different # algorithm for determine calibration. try: device_info = query_state("device_info") for item in device_info: hardware_strapping = item.find('hardwarestrapping') if hardware_strapping != None: hardware_strapping = hardware_strapping.text break else: hardware_strapping = '' if hardware_strapping == self.OLD_HARDWARE_STRAPPING_A or hardware_strapping == self.OLD_HARDWARE_STRAPPING_B: self.__tracer.info("Old hardware detected. " + "Turning on old support flag.") self.__OLD_HARDWARE = True except: pass # Grab the calibration rate setting, and store it self.__calibration_interval = SettingsBase.get_setting(self.__parent, "calibration_rate_ms") self.__calibration_interval /= 1000.0 # Force a calibration the first time getting samples. self.__calibration_time = -self.__calibration_interval # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self.__parent, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Walk through the channels, allocating required channel types # and creating each channels respective channel properties. for channel in self.__aio_channels: channel_name = "channel%d" % (channel + 1) mode = SettingsBase.get_setting(self.__parent, 'channel%d_mode' % (channel + 1)) aio_chan = XBeeLocalAIO(channel_name, self, channel, mode.lower()) self.__aio_channel_structures.append(aio_chan) for channel in self.__dio_channels: channel_name = "channel%d" % (channel + 1) direction = SettingsBase.get_setting(self.__parent, 'channel%d_dir' % (channel + 1)) direction = direction.lower() source = SettingsBase.get_setting(self.__parent, 'channel%d_source' % (channel + 1)) source = source.lower() dio_chan = XBeeLocalDIO(channel_name, self, channel, direction.lower(), source) self.__dio_channel_structures.append(dio_chan) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # 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) # 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((None, xbdm_rx_event_spec.match_spec_set((gw_extended_address(), 0xe8, 0xc105, 0x92), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device. # None indicates that we will be using the local radio. xbee_ddo_cfg = XBeeConfigBlockDDO(None) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # For the X3, aux power can be turned on/off. # For all other platforms, it is always on, and cannot be turned off. if get_platform_name() == 'digix3': power = SettingsBase.get_setting(self.__parent, "power") if power == Boolean(True, style = STYLE_ONOFF): xbee_ddo_cfg.add_parameter('d4', 5) elif power == Boolean(False, style=STYLE_ONOFF): xbee_ddo_cfg.add_parameter('d4', 4) # Call each channels start function to configure itself and start. # It will append any needed DDO commands to the 'xbee_ddo_cfg' block # we pass in. for channel in self.__aio_channel_structures: channel.start(xbee_ddo_cfg) for channel in self.__dio_channel_structures: channel.start(xbee_ddo_cfg) # Walk the digital channels again, if any are set to input, # we need to have the pin monitored. ic = 0 for channel in self.__dio_channel_structures: if channel.mode() == "in": ic |= 1 << channel.channel() # 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) # Disable any periodic I/O sampling: xbee_ddo_cfg.add_parameter('IR', 0) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): """Start the device driver. Returns bool.""" # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (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) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # 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('D2', 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) # 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(extended_address) xbee_ddo_wh_block.apply_only_to_modules((MOD_XB_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") xbee_sleep_cfg = XBeeConfigBlockSleep(extended_address) if will_sleep: xbee_sleep_cfg.sleep_cycle_set(awake_time_ms, sleep_rate_ms, enable_pin_wake=True) else: xbee_sleep_cfg.sleep_mode_set(SM_DISABLED) self.__xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg) # 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) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): """Start the device driver. Returns bool.""" # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # 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, Boolean(default_state, STYLE_ONOFF))) else: # Retrieve current state from device for channel d4 = self.__xbee_manager.xbee_device_ddo_get_param(extended_address, "d4") d4 = struct.unpack('B', d4)[0] if d4 == 5: state = True # Treat as having just been turned on for shut-off self.__power_on_time = time.time() elif d4 == 4: state = False else: raise Exception, "Unrecognized initial power_on state" self.property_set("power_on", Sample(0, Boolean(state, style=STYLE_ONOFF))) # Configure the IO Sample Rate: sample_rate = SettingsBase.get_setting(self, "sample_rate_ms") xbee_ddo_cfg.add_parameter('IR', sample_rate) # 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) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) self.reset_stored_values() return True
def start(self): """Start the device driver. Returns bool.""" # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) #""" IF YOUR XBEE DEVICE DON'N SLEEP AND YOU SEND DATA FROM XBEE DEVICE TO ConnectPort X manually then uncoment the start of that line. # 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(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") xbee_sleep_cfg = XBeeConfigBlockSleep(extended_address) if will_sleep: xbee_sleep_cfg.sleep_cycle_set(awake_time_ms, sleep_rate_ms) else: xbee_sleep_cfg.sleep_mode_set(SM_DISABLED) self.__xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg) #""" # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) #threading.Thread.start(self) return True
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)
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Attempt to detect if we are on older units that require a different # algorithm for determine calibration. try: device_info = query_state("device_info") for item in device_info: hardware_strapping = item.find('hardwarestrapping') if hardware_strapping != None: hardware_strapping = hardware_strapping.text break else: hardware_strapping = '' if hardware_strapping == self.LOCAL_AIO_R1_STRAPPING_A or hardware_strapping == self.LOCAL_AIO_R1_STRAPPING_B: self.__tracer.info( "Old hardware detected. Turning on old support flag.") self.__OLD_HARDWARE = True except: pass # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # 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) extended_address = None # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(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, 'channel%d_mode' % (io_pin + 1)) mode = self.LOCAL_AIO_MODE_MAP[mode.lower()] if mode == self.LOCAL_AIO_MODE_CURRENTLOOP: digihw.configure_channel(io_pin, 1) xbee_ddo_cfg.add_parameter( self.LOCAL_AIO_CONTROL_LINES[io_pin], 2) elif mode == self.LOCAL_AIO_MODE_TENV: digihw.configure_channel(io_pin, 2) xbee_ddo_cfg.add_parameter( self.LOCAL_AIO_CONTROL_LINES[io_pin], 2) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
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
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # 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) extended_address = None my_address = ':'.join( ["%02x" % ord(b) for b in ''.join(gw_extended_address_tuple())]) my_address = '[' + my_address + ']!' # 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((my_address, 0xe8, 0xc105, 0x92), (False, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # 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(self.DIO_CONTROL_LINES[io_pin], 3) # Build our change detection mask for all io pins: ic |= 1 << self.INPUT_CHANNEL_TO_PIN[io_pin] if dir == 'in': # Disable sinking driver output: pass elif dir == 'out': # Create the output channel for this IO pin: self.add_property( ChannelSourceDeviceProperty( name='channel%d_output' % (io_pin+1), type=bool, initial=Sample(timestamp=0, value=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) ) ) # Set initial value of output to low: digihw.configure_channel(io_pin, self.DIO_MODE_OUTPUT_LOW) # 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): if source == "True": sample = Sample(digitime.time(), Boolean(True, style=STYLE_TF)) self.set_output(sample, io_pin) elif source == "False": sample = Sample(digitime.time(), Boolean(False, style=STYLE_TF)) self.set_output(sample, io_pin) else: cm = self.__core.get_service("channel_manager") cp = cm.channel_publisher_get() cp.subscribe( source, lambda chan, io=io_pin: self.update(chan, io)) # 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) # Disable any periodic I/O sampling: xbee_ddo_cfg.add_parameter('IR', 0) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (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) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # 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 = XBeeConfigBlockSleep(extended_address) if sleep_ms > 0: # Configure node to sleep for the specified interval: xbee_sleep_cfg.sleep_cycle_set(awake_time_ms, sleep_ms) else: # If sleep_ms is 0, disable sleeping on the node altogether: xbee_sleep_cfg.sleep_mode_set(SM_DISABLED) self.__xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg) # 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) # Disable any periodic I/O sampling: xbee_ddo_cfg.add_parameter('IR', 0) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) # 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)) return True
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # 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") ic = 0 xbee_ddo_cfg.add_parameter('IC', ic) # 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") awake_time_ms = SettingsBase.get_setting(self, "awake_time_ms") # The original sample rate is used as the sleep rate: sleep_rate_ms = SettingsBase.get_setting(self, "sample_rate_ms") xbee_sleep_cfg = XBeeConfigBlockSleep(extended_address) if will_sleep: xbee_sleep_cfg.sleep_cycle_set(awake_time_ms, sleep_rate_ms) else: xbee_sleep_cfg.sleep_mode_set(SM_DISABLED) self.__xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) # Scheduling first request and watchdog heart beat poll, # but only if we aren't in sleep mode. if will_sleep != True: self.__schedule_request() self.__reschedule_retry_watchdog() return True
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (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) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # 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(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") xbee_sleep_cfg = XBeeConfigBlockSleep(extended_address) if will_sleep: xbee_sleep_cfg.sleep_cycle_set(awake_time_ms, sleep_rate_ms) else: xbee_sleep_cfg.sleep_mode_set(SM_DISABLED) self.__xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): """Start the device driver. Returns bool.""" # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # Configure pins DI1 & DI2 & DI0 for analog input: for io_pin in [ 'D1', 'D2', 'D3' ]: xbee_ddo_cfg.add_parameter(io_pin, 2) # Configure the IO Sample Rate: sample_rate = SettingsBase.get_setting(self, "sample_rate_ms") xbee_ddo_cfg.add_parameter('IR', sample_rate) # Handle subscribing the devices output to a named channel, # if configured to do so: # power_on_source1 = SettingsBase.get_setting(self, 'power_on_source1') # if power_on_source1 is not None: # cm = self.__core.get_service("channel_manager") # cp = cm.channel_publisher_get() # self.property_set("adder_reg2", Sample(0, float(power_on_source1))) # cp.subscribe(power_on_source1, self.update_power_state1) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Attempt to detect if we are on older units that require a different # algorithm for determine calibration. try: device_info = query_state("device_info") for item in device_info: hardware_strapping = item.find('hardwarestrapping') if hardware_strapping != None: hardware_strapping = hardware_strapping.text break else: hardware_strapping = '' if hardware_strapping == self.LOCAL_AIO_R1_STRAPPING_A or hardware_strapping == self.LOCAL_AIO_R1_STRAPPING_B: self.__tracer.info("Old hardware detected. Turning on old support flag.") self.__OLD_HARDWARE = True except: pass # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # 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) extended_address = None # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(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, 'channel%d_mode' % (io_pin+1) ) mode = self.LOCAL_AIO_MODE_MAP[mode.lower()] if mode == self.LOCAL_AIO_MODE_CURRENTLOOP: digihw.configure_channel(io_pin, 1) xbee_ddo_cfg.add_parameter(self.LOCAL_AIO_CONTROL_LINES[io_pin], 2) elif mode == self.LOCAL_AIO_MODE_TENV: digihw.configure_channel(io_pin, 2) xbee_ddo_cfg.add_parameter(self.LOCAL_AIO_CONTROL_LINES[io_pin], 2) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): """Start the device driver. Returns bool.""" # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (True, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # Configure pins DI1 & DI2 & DI0 for analog input: xbee_ddo_cfg.add_parameter('D0', 1) for io_pin in ['D3', 'D4', 'D6', 'D7' ]: xbee_ddo_cfg.add_parameter(io_pin, 4) # Configure the IO Sample Rate: sample_rate = SettingsBase.get_setting(self, "sample_rate_ms") xbee_ddo_cfg.add_parameter('IR', sample_rate) # Handle subscribing the devices output to a named channel, # if configured to do so: # power_on_source1 = SettingsBase.get_setting(self, 'power_on_source1') # if power_on_source1 is not None: # cm = self.__core.get_service("channel_manager") # cp = cm.channel_publisher_get() # self.property_set("adder_reg2", Sample(0, float(power_on_source1))) # cp.subscribe(power_on_source1, self.update_power_state1) # power_on_source2 = SettingsBase.get_setting(self, 'power_on_source2') # if power_on_source2 is not None: #W cm = self.__core.get_service("channel_manager") # cp = cm.channel_publisher_get() # cp.subscribe(power_on_source2, self.update_power_state2) # power_on_source3 = SettingsBase.get_setting(self, 'power_on_source3') # if power_on_source3 is not None: # cm = self.__core.get_service("channel_manager") # cp = cm.channel_publisher_get() # cp.subscribe(power_on_source3, self.update_power_state3) # 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(extended_address) xbee_ddo_wh_block.apply_only_to_modules((MOD_XB_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") xbee_sleep_cfg = XBeeConfigBlockSleep(extended_address) if will_sleep: xbee_sleep_cfg.sleep_cycle_set(awake_time_ms, sleep_rate_ms) else: xbee_sleep_cfg.sleep_mode_set(SM_DISABLED) self.__xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg) self.setup(Sample(0, Boolean("off", STYLE_ONOFF))) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
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 initialize_xbee_serial(self, xbee_ddo_cfg=None): """\ Creates a DDO command sequence of the user selected serial settings. .. Note:: * This routine does everything EXCEPT calling for final configuration * It will add its own ddo config block * The caller can add another after the return For example:: XBeeSerial.initialize_xbee_serial(self) my_ddo_cfg = XBeeConfigBlockDDO(self._extended_address) my_ddo_cfg.add_parameter('IR', 60000) self._xbee_manager.xbee_device_config_block_add(self, my_ddo_cfg) self._xbee_manager.xbee_device_configure(self) Returns True if successful, False on failure. """ self._tracer.calls("XBeeSerial.initialize_xbee_serial()") # Create a callback specification for our device address, endpoint # Digi XBee profile and sample cluster id: self._xbee_manager.register_serial_listener(self, self._extended_address, self.__read_callback) # callback for cb_set(self.__running_indication) is in xbee_base() # Create a DDO configuration block for this device: if xbee_ddo_cfg is None: xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address) # Set up the baud rate for the device. try: baud = SettingsBase.get_setting(self, "baudrate") except: baud = self.DEF_BAUDRATE baud = self.__derive_baudrate(baud) xbee_ddo_cfg.add_parameter('BD', baud) # Set up the parity for the device. try: parity = SettingsBase.get_setting(self, "parity") except: parity = self.DEF_PARITY parity = self.__derive_parity(parity) xbee_ddo_cfg.add_parameter('NB', parity) if self._xbee_manager.is_zigbee(): # Set up the stop bits for the device. try: stopbits = SettingsBase.get_setting(self, "stopbits") except: stopbits = self.DEF_STOPBITS stopbits = self.__derive_stopbits(stopbits) # The SB command is new. # It may or may not be supported on the XBee Serial Device/Adapter. # If its not supported, then we know the device # is simply at 1 stop bit, and we can ignore the failure. xbee_ddo_cfg.add_parameter('SB', stopbits, failure_callback=self.__ignore_if_fail) # else skip it for 802.15.4 or DigiMesh # Set up the hardware flow control mode for the device. try: hwflow = SettingsBase.get_setting(self, "hardwareflowcontrol") except: hwflow = self.DEF_HWFLOW d6, d7 = self.__derive_hardwareflowcontrol(hwflow) xbee_ddo_cfg.add_parameter('D6', d6) xbee_ddo_cfg.add_parameter('D7', d7) self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) return True
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # 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) extended_address = None my_address = ':'.join(["%02x"%ord(b) for b in ''.join(gw_extended_address_tuple())]) my_address = '[' + my_address + ']!' # 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((my_address, 0xe8, 0xc105, 0x92), (False, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # 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(self.DIO_CONTROL_LINES[io_pin], 3) # Build our change detection mask for all io pins: ic |= 1 << self.INPUT_CHANNEL_TO_PIN[io_pin] if dir == 'in': # Disable sinking driver output: pass elif dir == 'out': # Create the output channel for this IO pin: self.add_property( ChannelSourceDeviceProperty( name='channel%d_output' % (io_pin+1), type=bool, initial=Sample(timestamp=0, value=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) ) ) # Set initial value of output to low: digihw.configure_channel(io_pin, self.DIO_MODE_OUTPUT_LOW) # 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): if source == "True": sample = Sample(digitime.time(), Boolean(True, style=STYLE_TF)) self.set_output(sample, io_pin) elif source == "False": sample = Sample(digitime.time(), Boolean(False, style=STYLE_TF)) self.set_output(sample, io_pin) else: cm = self.__core.get_service("channel_manager") cp = cm.channel_publisher_get() cp.subscribe(source, lambda chan, io=io_pin: self.update(chan, io)) # 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) # Disable any periodic I/O sampling: xbee_ddo_cfg.add_parameter('IR', 0) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
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)
def initialize_xbee_serial(self, xbee_ddo_cfg=None): """\ Creates a DDO command sequence of the user selected serial settings. .. Note:: * This routine does everything EXCEPT calling for final configuration * It will add its own ddo config block * The caller can add another after the return For example:: XBeeSerial.initialize_xbee_serial(self) my_ddo_cfg = XBeeConfigBlockDDO(self._extended_address) my_ddo_cfg.add_parameter('IR', 60000) self._xbee_manager.xbee_device_config_block_add(self, my_ddo_cfg) self._xbee_manager.xbee_device_configure(self) Returns True if successful, False on failure. """ self._tracer.calls("XBeeSerial.initialize_xbee_serial()") # Create a callback specification for our device address, endpoint # Digi XBee profile and sample cluster id: self._xbee_manager.register_serial_listener(self, self._extended_address, self.__read_callback) # callback for cb_set(self.__running_indication) is in xbee_base() # Create a DDO configuration block for this device: if xbee_ddo_cfg is None: xbee_ddo_cfg = XBeeConfigBlockDDO(self._extended_address) # Set up the baud rate for the device. try: baud = SettingsBase.get_setting(self, "baudrate") except: baud = self.DEF_BAUDRATE baud = self.__derive_baudrate(baud) xbee_ddo_cfg.add_parameter('BD', baud) # Set up the parity for the device. try: parity = SettingsBase.get_setting(self, "parity") except: parity = self.DEF_PARITY parity = self.__derive_parity(parity) xbee_ddo_cfg.add_parameter('NB', parity) if self._xbee_manager.is_zigbee(): # Set up the stop bits for the device. try: stopbits = SettingsBase.get_setting(self, "stopbits") except: stopbits = self.DEF_STOPBITS stopbits = self.__derive_stopbits(stopbits) # The SB command is new. # It may or may not be supported on the XBee Serial Device/Adapter. # If its not supported, then we know the device # is simply at 1 stop bit, and we can ignore the failure. xbee_ddo_cfg.add_parameter('SB', stopbits, failure_callback=self.__ignore_if_fail) # else skip it for 802.15.4 or DigiMesh # Set up the hardware flow control mode for the device. try: hwflow = SettingsBase.get_setting(self, "hardwareflowcontrol") except: hwflow = self.DEF_HWFLOW d6, d7 = self.__derive_hardwareflowcontrol(hwflow) xbee_ddo_cfg.add_parameter('D6', d6) #xbee_ddo_cfg.add_parameter('D7', d7) xbee_ddo_cfg.add_parameter('D7', 7) self._xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) return True
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Get the extended address of the device: extended_address = SettingsBase.get_setting(self, "extended_address") # 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( (extended_address, 0xe8, 0xc105, 0x92), (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) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) 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, 'channel%d_mode' % (io_pin+1) ) 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. sample_rate_ms = SettingsBase.get_setting(self, "sample_rate_ms") if will_sleep or (not will_sleep and sample_rate_ms <= 0xffff): # Clip sample_rate_ms to the max value of IR: sample_rate_ms = min(sample_rate_ms, 0xffff) xbee_ddo_cfg.add_parameter('IR', sample_rate_ms) else: xbee_ddo_cfg.add_parameter('IR', 0) # 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 = XBeeConfigBlockSleep(extended_address) if will_sleep: xbee_sleep_cfg.sleep_cycle_set(awake_time_ms, sleep_rate_ms) else: xbee_sleep_cfg.sleep_mode_set(SM_DISABLED) self.__xbee_manager.xbee_device_config_block_add(self, xbee_sleep_cfg) 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(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) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True