Tables

AddressTable

class knx_stack.AddressTable(ia: knx_stack.Address, addresses: Iterable[knx_stack.GroupAddress], max_size: int)

4.9 Group Address Table (GrAT)

4.9.1 Abstract Resource definition

The GrAT shall be a shared Resource of both the Data Link Layer and the group oriented Transport Layer.

The Data Link Layer shall use the Group Address Table as a look up reference to check whether it should pass a decoded frame to the upper layers or not.

The group oriented Transported Layer shall consult the Group Address Table to map an incoming LSAP (Group Address) to a TSAP in receiving direction and vice-versa in sending direction.

[…]

>>> import knx_stack
>>> table = knx_stack.AddressTable(knx_stack.Address(4097),
...                                      [knx_stack.GroupAddress(free_style=0xBB),
...                                       knx_stack.GroupAddress(free_style=0xAA),
...                                       knx_stack.GroupAddress(free_style=0xCC)],
...                                      255)
>>> table.individual_address
0x1001
>>> table.individual_address = knx_stack.Address(4098)
>>> table.individual_address
0x1002
>>> table.max_size
255
>>> table.addresses
[(0x00AA 0/170 0/0/170), (0x00BB 0/187 0/0/187), (0x00CC 0/204 0/0/204)]
>>> table.tsaps
[0, 1, 2, 3]
>>> table.get_address(0)
0x1002
>>> table.get_address(2)
(0x00BB 0/187 0/0/187)
>>> table.get_address(4)
Traceback (most recent call last):
...
IndexError: list index out of range
>>> table.get_tsap(knx_stack.GroupAddress(free_style=0xCC))
3
>>> table.get_tsap(knx_stack.GroupAddress(free_style=0xDD))
>>> table.add(knx_stack.GroupAddress(205))
>>> table.addresses
[(0x00AA 0/170 0/0/170), (0x00BB 0/187 0/0/187), (0x00CC 0/204 0/0/204), (0x00CD 0/205 0/0/205)]
>>> table.remove(knx_stack.GroupAddress(205))
>>> table.addresses
[(0x00AA 0/170 0/0/170), (0x00BB 0/187 0/0/187), (0x00CC 0/204 0/0/204)]
>>> table
AddressTable: individual address: 0x1002, max_size=255

    tsap -> individual address
    0 -> 0x1002
    tsap -> group address (hex_free_style two_level_style three_level_style)
    1 -> (0x00AA 0/170 0/0/170)
    2 -> (0x00BB 0/187 0/0/187)
    3 -> (0x00CC 0/204 0/0/204)
property individual_address: knx_stack.Address
property max_size: int
property tsaps: Iterable[int]
property addresses: Iterable[knx_stack.GroupAddress]
get_address(tsap: int) int
get_tsap(address: knx_stack.GroupAddress) int
add(address: knx_stack.Address) knx_stack.AddressTable

Returns a new Address Table containing the given group address

Parameters

address – a new group address to be inserted

Returns

a new AddressTable instance

remove(address: knx_stack.GroupAddress) knx_stack.AddressTable

Returns a new Address Table without the given group address

Parameters

address – a group address to be removed

Returns

a new AddressTable instance

ASAP

class knx_stack.ASAP(value: int, name: Optional[str] = None)

Application Service Access Point

Ideally connects a piece of code with messages from/to one or more group addressess.

An ASAP in KNX specifications is an int.

This implementation can add to the ASAP identifier (an int value) a name.

>>> import knx_stack
>>> asap_no_name = knx_stack.ASAP(1)
>>> asap_no_name
1
>>> asap_with_name = knx_stack.ASAP(1, 'a meaningfull name to the connected piece of code')
>>> asap_with_name
1 (a meaningfull name to the connected piece of code)
>>> asap_no_name == asap_with_name
True
>>> len(set([asap_no_name, asap_with_name]))
1
property value
property name

AssociationTable

class knx_stack.AssociationTable(address_table: knx_stack.AddressTable, associations: Iterable[Association] = None)

4.10 Group Object Association Table (GrOAT)

4.10.1 Abstract Resource definition

The Group Objects Association Table shall be a parameter of the Application Layer.

It shall store the relationship between Transport Layer Service Access Points (TSAPs) and Application Layer Service Access Points (ASAP). The information on this relationship is needed when mapping the Multicast Communication Mode messages A_GroupValue_Read, A_GroupValue_Response and A_GroupValue_Write to T_Data_Group-messages and vice versa.

The TSAP shall be an index in the Group Address Table.

The ASAP shall be the Group Object number.

The lowest ASAP shall be 0. The ASAP shall in this Resource be a unique identifier for a Group Object to the Application Layer. The ASAP for this Resource shall thus be a Group Object Number.

[…]

>>> import knx_stack
>>> address_table = knx_stack.AddressTable(knx_stack.Address(4097), [], 255)
>>> asap_pippo = knx_stack.ASAP(1, "one")
>>> asap_pluto = knx_stack.ASAP(2, "two")
>>> table = knx_stack.AssociationTable(address_table, [knx_stack.Association(asap=asap_pippo,
...                                                                          address=knx_stack.GroupAddress(free_style=111))])
>>> table.associate(asap_pippo, [knx_stack.GroupAddress(free_style=112)])
>>> table.associate(asap_pippo, [knx_stack.GroupAddress(free_style=110)])
>>> table.associate(asap_pluto, [knx_stack.GroupAddress(free_style=109)])
>>> table.get_tsap(knx_stack.GroupAddress(free_style=111))
3
>>> table.get_addresses([3, 4, 2])
[(0x006F 0/111 0/0/111), (0x0070 0/112 0/0/112), (0x006E 0/110 0/0/110)]
>>> table.asaps
dict_keys([0 (individual address), 1 (one), 2 (two)])
>>> table.disassociate(asap_pippo, [knx_stack.GroupAddress(free_style=112)])
>>> table.get_addresses([3, 2])
[(0x006F 0/111 0/0/111), (0x006E 0/110 0/0/110)]
>>> table.get_tsaps(asap_pippo)
[3, 2]
>>> table.get_tsap(knx_stack.GroupAddress(free_style=110))
2
>>> table
AssociationTable: asap -> addresses
    0 (individual address) -> [0x1001]
    1 (one) -> [(0x006F 0/111 0/0/111), (0x006E 0/110 0/0/110)]
    2 (two) -> [(0x006D 0/109 0/0/109)]
AddressTable: individual address: 0x1001, max_size=255

    tsap -> individual address
    0 -> 0x1001
    tsap -> group address (hex_free_style two_level_style three_level_style)
    1 -> (0x006D 0/109 0/0/109)
    2 -> (0x006E 0/110 0/0/110)
    3 -> (0x006F 0/111 0/0/111)
property individual_address: knx_stack.Address
get_tsap(address: knx_stack.GroupAddress) int
get_tsaps(asap: knx_stack.ASAP) Iterable[int]
get_asaps(tsap: int) Iterable[knx_stack.ASAP]
get_asaps_from_address(address: knx_stack.GroupAddress) Iterable[knx_stack.ASAP]
property asaps
get_free_asap_value()
get_addresses(tsaps: Iterable[int])
associate(asap: knx_stack.ASAP, addresses: Iterable[knx_stack.GroupAddress]) None
disassociate(asap: knx_stack.ASAP, addresses: Iterable[knx_stack.GroupAddress]) None

GroupObjectTable

class knx_stack.GroupObjectTable(associations: Optional[Dict] = None)

A simplified version of a Group Object Table (4.11) with just an association between ASAPs and Datapoint Types.

>>> import knx_stack
>>> table = knx_stack.GroupObjectTable({knx_stack.ASAP(1): knx_stack.datapointtypes.DPT_UpDown})
>>> table.associate(knx_stack.ASAP(2), knx_stack.datapointtypes.DPT_Switch)
>>> table
GroupObjectTable: ASAP -> datapointtype
    1 -> DPT_UpDown
    2 -> DPT_Switch

>>> len(table.associations)
2
>>> table.disassociate(knx_stack.ASAP(1))
>>> len(table.associations)
1
property associations
associate(asap: knx_stack.ASAP, datapointtype: knx_stack.datapointtypes.DPT)
disassociate(asap: knx_stack.ASAP)