本文整理汇总了Python中devices.xbee.xbee_config_blocks.xbee_config_block_ddo.XBeeConfigBlockDDO类的典型用法代码示例。如果您正苦于以下问题:Python XBeeConfigBlockDDO类的具体用法?Python XBeeConfigBlockDDO怎么用?Python XBeeConfigBlockDDO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XBeeConfigBlockDDO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
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)
示例2: __init__
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)
示例3: start
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
示例4: start
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
示例5: start
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)
示例6: start
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
示例7: start
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
示例8: start
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
示例9: start
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)
示例10: start
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
示例11: start
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
示例12: start
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
示例13: start
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
示例14: start
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))
#.........这里部分代码省略.........
示例15: start
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)
#.........这里部分代码省略.........