Ejemplo n.º 1
0
    def indication(self, apdu):
        if _debug: WhoIsIAmApplication._debug("indication %r", apdu)

        if (isinstance(self._request, WhoIsRequest)) and (isinstance(apdu, IAmRequest)):
            device_type, device_instance = apdu.iAmDeviceIdentifier
            if device_type != 'device':
                raise DecodingError("invalid object type")

            if (self._request.deviceInstanceRangeLowLimit is not None) and \
                (device_instance < self._request.deviceInstanceRangeLowLimit):
                pass
            elif (self._request.deviceInstanceRangeHighLimit is not None) and \
                (device_instance > self._request.deviceInstanceRangeHighLimit):
                pass
            else:
                # print out the contents
                sys.stdout.write('\n')
                sys.stdout.write('Device Address        = ' + repr(apdu.pduSource) + '\n')
                sys.stdout.write('iAmDeviceIdentifier   = ' + str(apdu.iAmDeviceIdentifier) + '\n')
                sys.stdout.write('maxAPDULengthAccepted = ' + str(apdu.maxAPDULengthAccepted) + '\n')
                sys.stdout.write('segmentationSupported = ' + str(apdu.segmentationSupported) + '\n')
                sys.stdout.write('vendorID              = ' + str(apdu.vendorID) + '\n')
                sys.stdout.flush()

        # forward it along
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 2
0
    def indication(self, apdu):
        """Given an I-Am request, cache it.
        Indication will treat unconfirmed messages on the stack
        
        :param apdu: apdu
        """
        if _debug: ScriptApplication._debug("do_IAmRequest %r", apdu)
        if isinstance(apdu, IAmRequest):
            # build a key from the source, just use the instance number
            key = (
                str(apdu.pduSource),
                apdu.iAmDeviceIdentifier[1],
            )
            # count the times this has been received
            self.i_am_counter[key] += 1

        if isinstance(apdu, WhoIsRequest):
            # build a key from the source and parameters
            key = (
                str(apdu.pduSource),
                apdu.deviceInstanceRangeLowLimit,
                apdu.deviceInstanceRangeHighLimit,
            )

            # count the times this has been received
            self.who_is_counter[key] += 1
            BIPSimpleApplication.do_WhoIsRequest(self, apdu)
        # pass back to the default implementation
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 3
0
    def indication(self, apdu):
        if _debug: WhoIsIAmApplication._debug("indication %r", apdu)

        if (isinstance(self._request, WhoIsRequest)) and (isinstance(
                apdu, IAmRequest)):
            device_type, device_instance = apdu.iAmDeviceIdentifier
            if device_type != 'device':
                raise DecodingError("invalid object type")

            if (self._request.deviceInstanceRangeLowLimit is not None) and \
                    (device_instance < self._request.deviceInstanceRangeLowLimit):
                pass
            elif (self._request.deviceInstanceRangeHighLimit is not None) and \
                    (device_instance > self._request.deviceInstanceRangeHighLimit):
                pass
            else:
                # Received I-am from target's Device instance
                dev_ObjID = apdu.iAmDeviceIdentifier
                dev_pdusource = apdu.pduSource

                point_list[0][0] = str(dev_pdusource)
                point_list[1][0] = str(dev_pdusource)
                point_list[0][2] = dev_ObjID[1]
                point_list[1][2] = dev_ObjID[1]

                #fire off request. read device properties model name and software version
                deferred(self.next_request)

        # forward it along
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 4
0
    def indication(self, apdu):
        if _debug: WhoIsIAmApplication._debug("indication %r", apdu)

        if (isinstance(self._request, WhoIsRequest)) and (isinstance(apdu, IAmRequest)):
            device_type, device_instance = apdu.iAmDeviceIdentifier
            if device_type != 'device':
                raise DecodingError, "invalid object type"

            if (self._request.deviceInstanceRangeLowLimit is not None) and \
                (device_instance < self._request.deviceInstanceRangeLowLimit):
                pass
            elif (self._request.deviceInstanceRangeHighLimit is not None) and \
                (device_instance > self._request.deviceInstanceRangeHighLimit):
                pass
            else:
                # print out the contents
                sys.stdout.write('pduSource = ' + repr(apdu.pduSource) + '\n')
                sys.stdout.write('iAmDeviceIdentifier = ' + str(apdu.iAmDeviceIdentifier) + '\n')
                sys.stdout.write('maxAPDULengthAccepted = ' + str(apdu.maxAPDULengthAccepted) + '\n')
                sys.stdout.write('segmentationSupported = ' + str(apdu.segmentationSupported) + '\n')
                sys.stdout.write('vendorID = ' + str(apdu.vendorID) + '\n')
                sys.stdout.flush()

        # forward it along
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 5
0
	def indication(self, apdu):
		#
		# IAmRequest の 解析
		#
		if isinstance(apdu, IAmRequest):
			#
			# デバイスID, IPアドレスの取得
			#
			ipaddr = apdu.pduSource
			device_type, device_instance = apdu.iAmDeviceIdentifier

			#
			# デバイスID と IPアドレスのマッピング管理
			#
			self.device_map[device_instance] = ipaddr

			#
			# IAmRequest を 取得したことを通知する
			#
			self.responseQueue.put(device_instance)

		#
		# forward it along
		#
		BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 6
0
    def indication(self, apdu):
        if _debug: WhoIsIAmApplication._debug("indication %r", apdu)

        if (isinstance(self._request, WhoIsRequest)) and (isinstance(apdu, IAmRequest)):
            device_type, device_instance = apdu.iAmDeviceIdentifier
            if device_type != 'device':
                raise DecodingError("invalid object type")

            if (self._request.deviceInstanceRangeLowLimit is not None) and \
                (device_instance < self._request.deviceInstanceRangeLowLimit):
                pass
            elif (self._request.deviceInstanceRangeHighLimit is not None) and \
                (device_instance > self._request.deviceInstanceRangeHighLimit):
                pass
            else:
                # print out the contents
                sys.stdout.write('\n')
                sys.stdout.write('Device Address        = ' + repr(apdu.pduSource) + '\n')
                sys.stdout.write('Device Id             = ' + str(device_instance) + '\n')
                sys.stdout.write('maxAPDULengthAccepted = ' + str(apdu.maxAPDULengthAccepted) + '\n')
                sys.stdout.write('segmentationSupported = ' + str(apdu.segmentationSupported) + '\n')
                sys.stdout.write('vendorID              = ' + str(apdu.vendorID) + '\n')
                sys.stdout.flush()
                if this_csv_file is not None:
                    row = {"address":apdu.pduSource,
                           "device_id": device_instance,
                           "max_apdu_length": apdu.maxAPDULengthAccepted,
                           "segmentation_supported": apdu.segmentationSupported,
                           "vendor_id": apdu.vendorID}
                    this_csv_file.writerow(row)

        # forward it along
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 7
0
    def indication(self, apdu):
        """Given an I-Am request, cache it.
        Indication will treat unconfirmed messages on the stack
        
        :param apdu: apdu
        """
        if _debug: ScriptApplication._debug("do_IAmRequest %r", apdu)
        if isinstance(apdu, IAmRequest):
            # build a key from the source, just use the instance number
            key = (str(apdu.pduSource),
                   apdu.iAmDeviceIdentifier[1],
            )
            # count the times this has been received
            self.i_am_counter[key] += 1
        
        if isinstance(apdu, WhoIsRequest):        
        # build a key from the source and parameters
            key = (str(apdu.pduSource),
                apdu.deviceInstanceRangeLowLimit,
                apdu.deviceInstanceRangeHighLimit,
                )

        # count the times this has been received
            self.who_is_counter[key] += 1
            BIPSimpleApplication.do_WhoIsRequest(self, apdu)
        # pass back to the default implementation
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 8
0
    def indication(self, apdu):
        if isinstance(apdu, IAmRequest):
            device_type, device_instance = apdu.iAmDeviceIdentifier
            if device_type != 'device':
                # Bail without an error.
                return

            _log.debug("Calling IAm callback.")

            self.i_am_callback(str(apdu.pduSource),
                               device_instance,
                               apdu.maxAPDULengthAccepted,
                               str(apdu.segmentationSupported),
                               apdu.vendorID)

        elif isinstance(apdu, ConfirmedCOVNotificationRequest):
            # Handling for ConfirmedCOVNotificationRequests. These requests are
            # sent by the device when a point with a COV subscription updates
            # past the covIncrement threshold(See COV_Detection class in
            # Bacpypes:
            # https://bacpypes.readthedocs.io/en/latest/modules/service/cov.html)
            _log.debug("ConfirmedCOVNotificationRequest received from {}"
                       .format(apdu.pduSource))
            point_name = None
            device_path = None

            result_dict = {}
            for element in apdu.listOfValues:
                property_id = element.propertyIdentifier
                if not property_id == "statusFlags":
                    values = []
                    for tag in element.value.tagList:
                        values.append(tag.app_to_object().value)
                    if len(values) == 1:
                        result_dict[property_id] = values[0]
                    else:
                        result_dict[property_id] = values

            if result_dict:
                context = \
                    self.sub_cov_contexts[apdu.subscriberProcessIdentifier]
                point_name = context.point_name
                device_path = context.device_path

            if point_name and device_path:
                self.forward_cov_callback(device_path, point_name, result_dict)
            else:
                _log.debug("Device {} does not have a subscription context."
                           .format(apdu.monitoredObjectIdentifier))

        # forward it along
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 9
0
    def indication(self, apdu):
        if isinstance(apdu, IAmRequest):
            device_type, device_instance = apdu.iAmDeviceIdentifier
            if device_type != 'device':
                # Bail without an error.
                return

            _log.debug("Calling IAm callback.")

            self.i_am_callback(str(apdu.pduSource), device_instance,
                               apdu.maxAPDULengthAccepted,
                               str(apdu.segmentationSupported), apdu.vendorID)

        elif isinstance(apdu, ConfirmedCOVNotificationRequest):
            # Handling for ConfirmedCOVNotificationRequests. These requests are
            # sent by the device when a point with a COV subscription updates
            # past the covIncrement threshold(See COV_Detection class in
            # Bacpypes:
            # https://bacpypes.readthedocs.io/en/latest/modules/service/cov.html)
            _log.debug(
                "ConfirmedCOVNotificationRequest received from {}".format(
                    apdu.pduSource))
            point_name = None
            device_path = None

            result_dict = {}
            for element in apdu.listOfValues:
                property_id = element.propertyIdentifier
                if not property_id == "statusFlags":
                    values = []
                    for tag in element.value.tagList:
                        values.append(tag.app_to_object().value)
                    if len(values) == 1:
                        result_dict[property_id] = values[0]
                    else:
                        result_dict[property_id] = values

            if result_dict:
                context = self.sub_cov_contexts[
                    apdu.subscriberProcessIdentifier]
                point_name = context.point_name
                device_path = context.device_path

            if point_name and device_path:
                self.forward_cov_callback(device_path, point_name, result_dict)
            else:
                _log.debug(
                    "Device {} does not have a subscription context.".format(
                        apdu.monitoredObjectIdentifier))

        # forward it along
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 10
0
    def indication(self, apdu):
        if isinstance(apdu, IAmRequest):
            device_type, device_instance = apdu.iAmDeviceIdentifier
            if device_type != 'device':
                # Bail without an error.
                return

            _log.debug("Calling IAm callback.")

            self.i_am_callback(str(apdu.pduSource), device_instance,
                               apdu.maxAPDULengthAccepted,
                               str(apdu.segmentationSupported), apdu.vendorID)

        # forward it along
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 11
0
    def indication(self, apdu):
        """ function called as indication that an apdu was received """

        if isinstance(apdu, IAmRequest):
            dev_data = {}
            dev_data["addr"] = str(apdu.pduSource)
            dev_data["device_id"] = apdu.iAmDeviceIdentifier[
                1]  # just the number
            dev_data["device_identifier"] = ":".join(
                [str(x) for x in apdu.iAmDeviceIdentifier])
            dev_data["max_apdu"] = str(apdu.maxAPDULengthAccepted)
            dev_data["segmentationSupported"] = str(apdu.segmentationSupported)
            dev_data["vendor_id"] = str(apdu.vendorID)
            self.devices[apdu.iAmDeviceIdentifier[1]] = dev_data

        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 12
0
    def indication(self, apdu):
        if isinstance(apdu, IAmRequest):
            device_type, device_instance = apdu.iAmDeviceIdentifier
            if device_type != 'device':
                #Bail without an error.
                return

            _log.debug("Calling IAm callback.")

            self.i_am_callback(str(apdu.pduSource),
                               device_instance,
                               apdu.maxAPDULengthAccepted,
                               str(apdu.segmentationSupported),
                               apdu.vendorID)

        # forward it along
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 13
0
    def indication(self, apdu):
        """
        Indication will treat unconfirmed messages on the stack

        :param apdu: apdu
        """
        log_debug("do_IAmRequest %r", apdu)

        if _DEBUG:
            if apdu.pduSource == self.local_unicast_tuple[0]:
                log_debug("indication:received broadcast from self\n")
            else:
                log_debug(
                    "indication:received broadcast from %s (local:%s|source:%s)\n"
                    %
                    (apdu.pduSource, self.local_unicast_tuple, apdu.pduSource))
        else:
            log_debug("cannot test broadcast")

        # Given an I-Am request, cache it.
        if isinstance(apdu, IAmRequest):
            # build a key from the source, just use the instance number
            key = (
                str(apdu.pduSource),
                apdu.iAmDeviceIdentifier[1],
            )
            # count the times this has been received
            self.i_am_counter[key] += 1

        # Given an Who Is request, cache it.
        if isinstance(apdu, WhoIsRequest):
            # build a key from the source and parameters
            key = (
                str(apdu.pduSource),
                apdu.deviceInstanceRangeLowLimit,
                apdu.deviceInstanceRangeHighLimit,
            )

            # count the times this has been received
            self.who_is_counter[key] += 1

        # pass back to the default implementation
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 14
0
    def indication(self, apdu):
        """
        Indication will treat unconfirmed messages on the stack

        :param apdu: apdu
        """
        log_debug("do_IAmRequest %r", apdu)

        if _DEBUG:
            if apdu.pduSource == self.local_unicast_tuple[0]:
                log_debug("indication:received broadcast from self\n")
            else:
                log_debug("indication:received broadcast from %s (local:%s|source:%s)\n" %
                          (apdu.pduSource, self.local_unicast_tuple, apdu.pduSource))
        else:
            log_debug("cannot test broadcast")

        # Given an I-Am request, cache it.
        if isinstance(apdu, IAmRequest):
            # build a key from the source, just use the instance number
            key = (str(apdu.pduSource),
                   apdu.iAmDeviceIdentifier[1],)
            # count the times this has been received
            self.i_am_counter[key] += 1

        # Given an Who Is request, cache it.
        if isinstance(apdu, WhoIsRequest):
            # build a key from the source and parameters
            key = (str(apdu.pduSource),
                   apdu.deviceInstanceRangeLowLimit,
                   apdu.deviceInstanceRangeHighLimit,
                   )

            # count the times this has been received
            self.who_is_counter[key] += 1
            
        # pass back to the default implementation
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 15
0
 def indication(self, apdu, forwarded=False):
     if _debug:
         ModbusSimpleApplication._debug("[%s]indication %r %r",
                                        self.localAddress, apdu, forwarded)
     BIPSimpleApplication.indication(self, apdu, forwarded=forwarded)
Ejemplo n.º 16
0
 def indication(self, apdu):
     BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 17
0
 def indication(self, apdu):
     if _debug: SampleApplication._debug("indication %r", apdu)
     BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 18
0
    def indication(self, apdu):
        if _debug: TestApplication._debug("indication %r", apdu)

        # forward it along
        BIPSimpleApplication.indication(self, apdu)
Ejemplo n.º 19
0
 def indication(self, apdu):
     if _debug: SampleApplication._debug("indication %r", apdu)
     BIPSimpleApplication.indication(self, apdu)
 def indication(self, apdu):
     BIPSimpleApplication.indication(self, apdu)