Пример #1
0
    def indication(self, apdu):
        #We only care about indications if we sent out a who is request.
        if not isinstance(self._request, WhoIsRequest):
            _log.debug(
                "Ignoring indication as we don't have an outstanding WhoIs")
            return

        #We only care about IAmRequest
        if not isinstance(apdu, IAmRequest):
            _log.debug("Ignoring indication as apdu is not IAm")
            return

        #Ignore IAmRequests that don't have the device id we care about.
        if self.expected_device_id is not None:
            device_type, device_instance = apdu.iAmDeviceIdentifier

            if device_type != 'device':
                raise DecodingError("invalid object type")

            if device_instance != self.expected_device_id:
                _log.debug("Ignoring IAm. Expected ID: {} Received: {}".format(
                    self.expected_device_id, device_instance))
                return

        self.apdu = apdu
        stop()
Пример #2
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
        BIPForeignApplication.indication(self, apdu)
Пример #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)
Пример #4
0
    def decode(self, pdu):
        """decode the contents of the PDU into the BVLCI."""
        if _debug: BVLCI._debug("decode %s", str(pdu))

        # copy the basics
        PCI.update(self, pdu)

        self.bvlciType = pdu.get()
        if self.bvlciType != 0x84:
            raise DecodingError("invalid BVLCI type")

        self.bvlciFunction = pdu.get()
        self.bvlciLength = pdu.get_short()

        if (self.bvlciLength != len(pdu.pduData) + 4):
            raise DecodingError("invalid BVLCI length")
Пример #5
0
    def indication(self,apdu):

        self.apdu = apdu
        if (isinstance(self._request, WhoIsRequest)) and (isinstance(apdu, IAmRequest)):
            device_type, device_instance = apdu.iAmDeviceIdentifier
            self.device_instance = device_instance
            if device_type != 'device':
                raise DecodingError("invalid object type")
        self.release=False
        self.update=True
        self.updator()
Пример #6
0
    def decode(self, pdu):
        """Decode the contents of the PDU."""
        if _debug: MPCI._debug("decode %r", pdu)

        PCI.update(self, pdu)

        self.mpduTransactionID = pdu.get_short()
        self.mpduProtocolID = pdu.get_short()
        self.mpduLength = pdu.get_short()
        self.mpduUnitID = pdu.get()
        self.mpduFunctionCode = pdu.get()

        # check the length
        if self.mpduLength != len(pdu.pduData) + 2:
            raise DecodingError("invalid length")
Пример #7
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)
Пример #8
0
    def indication(self, apdu):
        if _debug: WhoIsIAmApplication._debug("indication %r", apdu)

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

            # 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
        MSTPSimpleApplication.indication(self, apdu)
Пример #9
0
    _log.debug("starting build")

    target_address = Address(args.address)

    request = WhoIsRequest()
    request.pduDestination = target_address
    result = this_application.make_request(request, expect_confirmation=False)

    if not isinstance(result, IAmRequest):
        result.debug_contents()
        raise TypeError("Error making WhoIs request")

    device_type, device_instance = result.iAmDeviceIdentifier
    if device_type != 'device':
        raise DecodingError("invalid object type")

    _log.debug('pduSource = ' + repr(result.pduSource))
    _log.debug('iAmDeviceIdentifier = ' + str(result.iAmDeviceIdentifier))
    _log.debug('maxAPDULengthAccepted = ' + str(result.maxAPDULengthAccepted))
    _log.debug('segmentationSupported = ' + str(result.segmentationSupported))
    _log.debug('vendorID = ' + str(result.vendorID))

    device_id = result.iAmDeviceIdentifier[1]

    device_name = read_prop(this_application, target_address, "device",
                            device_id, "objectName")
    _log.debug('device_name = ' + str(device_name))
    device_description = read_prop(this_application, target_address, "device",
                                   device_id, "description")
    _log.debug('description = ' + str(device_description))