How to use bacpypes - 10 common examples

To help you get started, we’ve selected a few bacpypes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JoelBender / bacpypes / tests / test_bvll / test_codec.py View on Github external
xxtob = lambda s: xtob(''.join(s.split()).replace('.', ''))
github ChristianTremblay / BAC0 / tests / test_ReadProperty.py View on Github external
raise ValueError("unknown object type")

        obj_inst = int(args[i])
        i += 1

        prop_reference_list = []
        while i < len(args):
            prop_id = args[i]
            if prop_id not in PropertyIdentifier.enumerations:
                break

            i += 1
            if prop_id in ('all', 'required', 'optional'):
                pass
            else:
                datatype = get_datatype(obj_type, prop_id)
                if not datatype:
                    raise ValueError(
                        "invalid property for object type : %s | %s" %
                        (obj_type, prop_id))

            # build a property reference
            prop_reference = PropertyReference(
                propertyIdentifier=prop_id,
            )

            # check for an array index
            if (i < len(args)) and args[i].isdigit():
                prop_reference.propertyArrayIndex = int(args[i])
                i += 1

            # add it to the list
github JoelBender / bacpypes / tests / test_pdu / test_address.py View on Github external
# test bad integer string
        with self.assertRaises(ValueError):
            Address("256")

        # test modern hex string
        test_addr = Address("0x01")
        self.match_address(test_addr, 2, None, 1, '01')
        assert str(test_addr) == "1"

        test_addr = Address("0x0102")
        self.match_address(test_addr, 2, None, 2, '0102')
        assert str(test_addr) == "0x0102"

        # test old school hex string
        test_addr = Address("X'01'")
        self.match_address(test_addr, 2, None, 1, '01')
        assert str(test_addr) == "1"

        test_addr = Address("X'0102'")
        self.match_address(test_addr, 2, None, 2, '0102')
        assert str(test_addr) == "0x0102"
github JoelBender / bacpypes / tests / test_network / helpers.py View on Github external
def __init__(self, address, vlan):
        if _debug: ApplicationLayerStateMachine._debug("__init__ %r %r", address, vlan)

        # build a name, save the address
        self.name = "app @ %s" % (address,)
        self.address = Address(address)

        # build a local device object
        local_device = TestDeviceObject(
            objectName=self.name,
            objectIdentifier=('device', int(address)),
            vendorIdentifier=999,
            )

        # build an address and save it
        self.address = Address(address)
        if _debug: ApplicationLayerStateMachine._debug("    - address: %r", self.address)

        # continue with initialization
        ApplicationServiceElement.__init__(self)
        ClientStateMachine.__init__(self, name=local_device.objectName)
github JoelBender / bacpypes / tests / test_bvll / helpers.py View on Github external
def confirmation(self, pdu):
        if _debug: FauxMultiplexer._debug("confirmation %r", pdu)

        # the PDU source and destination are tuples, convert them to Address instances
        src = Address(pdu.pduSource)

        # see if the destination was our broadcast address
        if pdu.pduDestination == self.broadcast_tuple:
            dest = LocalBroadcast()
        else:
            dest = Address(pdu.pduDestination)

        # continue upstream
        self.response(PDU(pdu, source=src, destination=dest))
github JoelBender / bacpypes / tests / test_primitive_data / test_double.py View on Github external
def test_double_tag(self):
        if _debug: TestDouble._debug("test_double_tag")

        tag = Tag(Tag.applicationTagClass, Tag.doubleAppTag, 8, xtob('3ff0000000000000'))
        obj = Double(tag)
        assert obj.value == 1.0

        tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob(''))
        with self.assertRaises(InvalidTag):
            Double(tag)

        tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff'))
        with self.assertRaises(InvalidTag):
            Double(tag)

        tag = Tag(Tag.openingTagClass, 0)
        with self.assertRaises(InvalidTag):
            Double(tag)
github JoelBender / bacpypes / tests / test_primitive_data / test_boolean.py View on Github external
def boolean_tag(value):
    """Convert an integer to an boolean application tag."""
    if _debug: boolean_tag._debug("boolean_tag %r", value)

    tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, int(value), xtob(''))
    if _debug: boolean_endec._debug("    - tag: %r", tag)

    return tag
github JoelBender / bacpypes / tests / test_primitive_data / test_double.py View on Github external
def test_double_tag(self):
        if _debug: TestDouble._debug("test_double_tag")

        tag = Tag(Tag.applicationTagClass, Tag.doubleAppTag, 8, xtob('3ff0000000000000'))
        obj = Double(tag)
        assert obj.value == 1.0

        tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob(''))
        with self.assertRaises(InvalidTag):
            Double(tag)

        tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff'))
        with self.assertRaises(InvalidTag):
            Double(tag)

        tag = Tag(Tag.openingTagClass, 0)
        with self.assertRaises(InvalidTag):
            Double(tag)
github JoelBender / bacpypes / tests / test_primitive_data / test_object_identifier.py View on Github external
def object_identifier_tag(x):
    """Convert a hex string to an object_identifier application tag."""
    if _debug: object_identifier_tag._debug("object_identifier_tag %r", x)

    b = xtob(x)
    tag = Tag(Tag.applicationTagClass, Tag.objectIdentifierAppTag, len(b), b)
    if _debug: object_identifier_endec._debug("    - tag: %r", tag)

    return tag
github JoelBender / bacpypes / tests / test_primitive_data / test_bit_string.py View on Github external
def test_bit_string_tag(self):
        if _debug: TestBitString._debug("test_bit_string_tag")

        tag = Tag(Tag.applicationTagClass, Tag.bitStringAppTag, 1, xtob('08'))
        obj = BitString(tag)
        if _debug: TestBitString._debug("    - obj.value: %r", obj.value)
        assert obj.value == []

        tag = Tag(Tag.applicationTagClass, Tag.bitStringAppTag, 2, xtob('0102'))
        obj = BitString(tag)
        if _debug: TestBitString._debug("    - obj.value: %r", obj.value)
        assert obj.value == [0, 0, 0, 0, 0, 0, 1]

        tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob(''))
        with self.assertRaises(InvalidTag):
            BitString(tag)

        tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff'))
        with self.assertRaises(InvalidTag):
            BitString(tag)

        tag = Tag(Tag.openingTagClass, 0)
        with self.assertRaises(InvalidTag):
            BitString(tag)