def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services
        
        self._logger = init_module_logger(name)        

        ## Local State Variables:
        self.__lora_manager = None
        
        self._extended_address_setting = None
        
        # Settings
        #
        # xbee_device_manager: must be set to the name of an XBeeDeviceManager
        #                      instance.
        # extended_address: the extended address of the XBee Sensor device you
        #                   would like to monitor.
        #
        # Advanced settings:
        #
        # None

        settings_list = [
                         
            Setting(
                name='lora_device_manager', type=str, required=True),
            Setting(
                name='extended_address', type=str, required=True),                         
                  
            Setting(
                name='log_level', type=str, required=False, default_value='DEBUG', verify_function=check_debug_level_setting),                  
          
            ]

        ## Channel Properties Definition:
        property_list = [
            # getable properties
            ChannelSourceDeviceProperty(name='software_version', type=str,
                initial=Sample(timestamp=digitime.time(), value=VERSION_NUMBER),
                perms_mask= DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP),
                         
            # setable properties
            ChannelSourceDeviceProperty(name='simulate_xbee_frame', type=str,
                initial=Sample(timestamp=0, value=''),
                perms_mask= DPROP_PERM_SET,
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self._simulate_xbee_frame_cb),
            ChannelSourceDeviceProperty(name='command', type=str,
                initial=Sample(timestamp=0, value=''),
                perms_mask= DPROP_PERM_SET,
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=self._send_command_to_sensor_cb),                         
                         
         ]
        
        ## Initialize the DeviceBase interface:
        DeviceBase.__init__(self, self.__name, self.__core,
                                        settings_list, property_list)
    def __init__(self, name, core_services):
        ## Initialize and declare class variables
        self.__name = name
        self.__core = core_services

        self.__logger = init_module_logger(name)

        ## Settings Table Definition:
        settings_list = [
            Setting(name='baudrate',
                    type=int,
                    required=False,
                    default_value=38400,
                    verify_function=lambda x: x > 0),
            Setting(name='port', type=str, required=False, default_value='11'),
            Setting(name='mainloop_serial_read_timeout',
                    type=int,
                    required=False,
                    default_value=30),
            Setting(name='log_level',
                    type=str,
                    required=False,
                    default_value='DEBUG',
                    verify_function=check_debug_level_setting),
        ]

        ## Channel Properties Definition:
        property_list = [
            ChannelSourceDeviceProperty(name='software_version',
                                        type=str,
                                        initial=Sample(
                                            timestamp=digitime.time(),
                                            value=VERSION_NUMBER),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="LoRaPlugAndSenseFrame",
                                        type=str,
                                        initial=Sample(timestamp=0, value=''),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        ## Initialize the DeviceBase interface:
        DeviceBase.__init__(self, self.__name, self.__core, settings_list,
                            property_list)

        ## Thread initialization:
        self.__stopevent = threading.Event()
        threading.Thread.__init__(self, name=name)
        threading.Thread.setDaemon(self, True)
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        self.__logger = init_module_logger(name)

        ## Settings Table Definition:
        settings_list = [
            Setting(name='log_level',
                    type=str,
                    required=False,
                    default_value='DEBUG',
                    verify_function=check_debug_level_setting),
        ]

        ## Channel Properties Definition:
        property_list = [
            # gettable properties
            ChannelSourceDeviceProperty(name="raw_out",
                                        type=str,
                                        initial=Sample(timestamp=0, value=""),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),

            # settable properties
            ChannelSourceDeviceProperty(name="raw_in",
                                        type=str,
                                        initial=Sample(
                                            timestamp=0,
                                            value='__INITIAL_SAMPLE__'),
                                        perms_mask=DPROP_PERM_SET,
                                        set_cb=self.__prop_set_raw_in),
            ChannelSourceDeviceProperty(name='software_version',
                                        type=str,
                                        initial=Sample(timestamp=0,
                                                       value=_VERSION_NUMBER),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        ## Initialize the DeviceBase interface:
        DeviceBase.__init__(self, self.__name, self.__core, settings_list,
                            property_list)

        ## Thread initialization:
        self.__stopevent = threading.Event()
        threading.Thread.__init__(self, name=name)
        threading.Thread.setDaemon(self, True)
Example #4
0
    def __init__(self, name, core_services):
        settings_list = [
            Setting(name='debug_sleep_time',
                    type=int,
                    required=False,
                    default_value=50,
                    verify_function=lambda x: 10 <= x <= 14400000),
            Setting(name='debug_wake_time',
                    type=int,
                    required=False,
                    default_value=20000,
                    verify_function=lambda x: 69 <= x <= 3600000),
        ]

        property_list = [
            ChannelSourceDeviceProperty(name='debug_mode',
                                        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=self.__handle_debug),
        ]

        # network debug mode flag
        self.__debug = False
        self.__debug_lock = threading.RLock()

        DigiMeshDeviceManager.__init__(self, name, core_services,
                                       settings_list, property_list)
    def _send_data_to_dia_channel(self, frame, addr):
              
        self._last_timestamp = digitime.time()
        io_sample=parser(decode_waspmote_frame(frame))
        
        self._logger.debug ('Found following information: %s' % str(io_sample))
          
        # route each information to its corresponding channel
        for key in io_sample.keys():
            
            if libelium_to_dia_map.has_key(key):
                channel_name, type_name, channel_unit = libelium_to_dia_map[key]
            else:
                # add this key to existing map for next loop
                                # use default values =>
                # ... the new channel has the information name
                channel_name = libelium_key_to_dia_channel_name (key)
                # ... type will be default
                type_name = str
                # ... unit will be none
                channel_unit = ''

                # extend the map (initialized in utils) with this new key                
                libelium_to_dia_map[key] = (channel_name, type_name, channel_unit)
                

            #verify the type of the value
            if type_name=='float':
                    sample_value=Convert_Str_Float(io_sample[key])
            elif type_name=='int':
                    sample_value=Convert_Str_Integer(io_sample[key])
            else:
                    sample_value=io_sample[key]
                    
            sample = Sample(self._last_timestamp, sample_value, channel_unit)
            
            #verify if the channel already exists. I not, create it. 
            if not self.property_exists(channel_name):
                # create the new channel
                self.add_property(
                   ChannelSourceDeviceProperty(channel_name,
                                               type=type(sample_value),
                                               initial=sample,
                                               perms_mask=DPROP_PERM_GET,
                                               options=DPROP_OPT_AUTOTIMESTAMP))
                self._logger.info ("Created channel \"%s\" for key \"%s\"" % (channel_name, key))
                
            # send the new sample
            self._logger.debug ('Put %s data to dia channel: %s' % (key, channel_name))
            self.property_set(channel_name, sample)                
Example #6
0
    def physically_create_filter_channel(self, original_channel,
                                         filter_channel_name):
        #create the filter property we are going to add

        # perm_mask draws the refresh setting from the channel we are following.
        # If it is refreshable, then our channel will be refreshable as well.
        is_refreshable = bool(original_channel.perm_mask()
                              & DPROP_PERM_REFRESH)
        if is_refreshable:
            perms_mask = DPROP_PERM_GET | DPROP_PERM_SET | DPROP_PERM_REFRESH
        else:
            perms_mask = DPROP_PERM_GET | DPROP_PERM_SET
        filter_channel = ChannelSourceDeviceProperty(
            name=filter_channel_name,
            type=original_channel.type(),
            initial=Sample(timestamp=0, value=original_channel.type()()),
            perms_mask=perms_mask,
            refresh_cb=self._refresh,
            options=DPROP_OPT_AUTOTIMESTAMP)
        return filter_channel
    def physically_create_filter_channel(self, original_channel,
                                         filter_channel_name):
        """\
            Optional override of the base channel's call of the same name.

            This allows us to create a new channel, and define its type,
               based on whatever type we desire it to be.

            Keyword arguments:

            original_channel -- the shadowed channel

            filter_channel_name -- the name of the channel we should create
        """
        filter_channel = ChannelSourceDeviceProperty(
            name=filter_channel_name,
            type=bool,
            initial=Sample(timestamp=0, value=bool()),
            perms_mask=DPROP_PERM_GET | DPROP_PERM_SET,
            options=DPROP_OPT_AUTOTIMESTAMP)
        return filter_channel
    def __init__(self, name, core_services):
        
        
        ## Initialize and declare class variables
        self.__name = name
        self.__core = core_services
        self.__cm = self.__core.get_service("channel_manager")
        self.__cp = self.__cm.channel_publisher_get()
        self.__cdb = self.__cm.channel_database_get()
        self._ec_key_to_dia_command_channel_name_cache = {}
        
        self._logger = init_module_logger(name)
        self._subscribed_channels = []
        
        self._ec_access_point_pub_key_setting = None
        self._dia_module_name_to_ec_device_public_key_setting_map = None
        self._sensor_channel_list_to_subscribe_to_setting = None
        self._incoming_command_channel_setting = None
        
        # semaphores and synchronization variables
        self._receive_sensor_data_callback_lock = threading.Lock()
        
        # will be appended to a DIA module name to get the name of the
        # channel to be used to send received commands
        self._sensor_channel_name_where_to_forward_commands = "command"
        
        settings_list = [
            Setting(name='ec_access_point_pub_key', type=str, required=False),
            Setting(name='channels', type=list, required=True, default_value=[]),
            Setting(name='exclude', type=list, required=False, default_value=[]),
            Setting(name='dia_channel_to_ec_sensor', type=dict, required=False, default_value={}),
            Setting(name='dia_module_to_ec_pub_key', type=dict, required=False, default_value={}),
            Setting(name='incoming_command_channel', type=str, required=False, default_value=''),

            Setting(name='log_level', type=str, required=False, default_value='DEBUG', verify_function=check_debug_level_setting),

        ]
        
        # Channel Properties Definition:
        
        property_list = [
                         
            #  properties
            
            ChannelSourceDeviceProperty(name='json_data', type=str,
                initial=Sample(timestamp=digitime.time(), value=""),
                perms_mask= DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP), 
                         
            ChannelSourceDeviceProperty(name='software_version', type=str,
                initial=Sample(timestamp=digitime.time(), value=VERSION_NUMBER),
                perms_mask= DPROP_PERM_GET,
                options=DPROP_OPT_AUTOTIMESTAMP),                         

        ]        
        
        
        ## Initialize the DeviceBase interface:
        DeviceBase.__init__(self, self.__name, self.__core,
                                        settings_list, property_list)
        
        self.__stopevent = threading.Event()        
        
        threading.Thread.__init__(self, name=name)
        threading.Thread.setDaemon(self, True)       
    def __init__(self,
                 name,
                 core_services,
                 settings_list=None,
                 property_list=None):
        if settings_list == None:
            settings_list = []
        if property_list == None:
            property_list = []

        # over-ride base-class defaults - YML still over-rides these over-rides

        # digimesh requires DH/DL to match the coordinator
        self.DH_DL_FORCE_DEFAULT = 'coordinator'
        # this is in minutes - default to once every 3 hours/180 minutes
        self.DH_DL_REFRESH_DEFAULT = 180

        # existing default of 00:00:00:00:00:00:FF:FF! is okay for DigiMesh
        # self.MESH_BROADCAST

        settings_list.extend([
            Setting(name='sleep_time',
                    type=int,
                    required=False,
                    default_value=self.DMMAN_DEF_SLEEP_TIME,
                    verify_function=lambda x:
                    (x == 0) or (10 <= x <= 14400000)),
            Setting(name='wake_time',
                    type=int,
                    required=False,
                    default_value=self.DMMAN_DEF_WAKE_TIME,
                    verify_function=lambda x: 69 <= x <= 3600000),

            # if True try setting IR/IF as required otherwise leave alone
            # and assume the user has managed all of this
            Setting(name='set_if',
                    type=bool,
                    required=False,
                    default_value=self.DMMAN_DEF_SET_IF),
        ])

        property_list.extend([
            ChannelSourceDeviceProperty(name='wake_time',
                                        type=int,
                                        initial=Sample(timestamp=0,
                                                       value=-1,
                                                       unit='ms'),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name='sleep_time',
                                        type=int,
                                        initial=Sample(timestamp=0,
                                                       value=-1,
                                                       unit='ms'),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
        ])

        XBeeDeviceManager.__init__(self, name, core_services, settings_list,
                                   property_list)

        # will be initialized during run() startup
        self.__dh_dl_refresh_sec = self.DH_DL_REFRESH_NOT_SET
        self.listener = SleepChecker(self)