profi_dcp package

Subpackages

Submodules

profi_dcp.dcp_constants module

Copyright (c) 2024 Elias Rosch, Esslingen. Copyright (c) 2020 Codewerk GmbH, Karlsruhe. All Rights Reserved.

class profi_dcp.dcp_constants.FrameID

Bases: object

Constants for the different DCP frame IDs

GET_SET = 65277
IDENTIFY_REQUEST = 65278
class profi_dcp.dcp_constants.BlockQualifier

Bases: object

“DCP block qualifiers

STORE_PERMANENT = [0, 1]
RESET_COMMUNICATION = [0, 4]
STORE_TEMPORARY = [0, 0]
RESERVED = [0, 0]
class profi_dcp.dcp_constants.ResetFactoryModes

Bases: object

Reset to factory modes

RESET_APPLICATION_DATA = [0, 2]
RESET_COMMUNICATION = [0, 4]
RESET_ENGENEERING = [0, 6]
RESET_ALL_DATA = [0, 8]
RESET_DEVICE = [0, 16]
RESET_AND_RESTORE = [0, 18]
class profi_dcp.dcp_constants.ServiceType

Bases: object

Service type of a DCP packet

REQUEST = 0
RESPONSE = 1
class profi_dcp.dcp_constants.ServiceID

Bases: object

Service ID of a DCP packet

GET = 3
SET = 4
IDENTIFY = 5
class profi_dcp.dcp_constants.Option

Bases: object

Option and suboption pairs for DCP blocks.

IP_ADDRESS = (1, 2)
DEVICE_FAMILY = (2, 1)
NAME_OF_STATION = (2, 2)
DEVICE_ID = (2, 3)
RESET_FACTORY = (5, 5)
RESET_TO_FACTORY = (5, 6)
ALL = (255, 255)

profi_dcp.error module

Copyright (c) 2024 Elias Rosch, Esslingen. Copyright (c) 2020 Codewerk GmbH, Karlsruhe. All Rights Reserved.

exception profi_dcp.error.DcpError

Bases: Exception

Base class of the errors thrown by this DCP lib.

exception profi_dcp.error.DcpTimeoutError

Bases: DcpError

Thrown if a timeout occurs withing this DCP lib.

profi_dcp.profi_dcp module

Copyright (c) 2024 Elias Rosch, Esslingen. Copyright (c) 2020 Codewerk GmbH, Karlsruhe. All Rights Reserved.

class profi_dcp.profi_dcp.Device

Bases: object

A DCP device defined by its properties (name of station, mac address, ip address etc.).

Create a new device, all parameters are initialized with an empty string.

to_log()
class profi_dcp.profi_dcp.DCP(ip)

Bases: object

The DCP-class provides access to the DCP-functions of this library. After an instance with the ip address of the network adapter you want to use DCP on is created, DCP-functions are available through this instance.

Create a new instance, use the given ip to select the network interface. :param ip: The ip address used to select the network interface. :type ip: string

identify_all(timeout=None)

Send multicast request to identify ALL devices in current network interface and get information about them. :param timeout: Optional timeout in seconds. Since it is unknown how many devices will respond to the request, responses are received for the full duration of the timeout. The default is defined in self.default_timeout. :type timeout: integer :return: A list containing all devices found. :rtype: List[Device]

identify(mac)

Send a request to get information about specific device with the given mac address in the network interface. :param mac: MAC-address of the device to identify (as ‘:’ separated string) :type mac: string :return: The requested device. :rtype: Device

set_ip_address(mac, ip_conf, store_permanent=True)

Send a request to set or change the IP configuration of the device with the given mac address. :param mac: mac address of the target device (as ‘:’ separated string) :type mac: string :param ip_conf: list containing the values to set for the ip address, subnet mask, and router in that order. :type ip_conf: List[string] :param store_permanent: Optional, if set to False, the ip config will only be stored until the next power reset. :type store_permanent: Bool :return: The response code to the request. Evaluates to false if the request failed. Use get_message() to get a human-readable response message. :rtype: ResponseCode

set_name_of_station(mac, name, store_permanent=True)

Send a request to set or change the name of station of the device with the given mac address. :param mac: mac address of the target device (as ‘:’ separated string) :type mac: string :param name: The new name to be set. :type name: string :param store_permantent: Optional, if set to False, the name will only be stored until the next power reset. :type store_permantent: Bool :return: The response code to the request. Evaluates to false if the request failed. Use get_message() to get a human-readable response message. :rtype: ResponseCode

get_ip_address(mac)

Send a request to get the IP address of the device with the given mac address. :param mac: mac address of the target device (as ‘:’ separated string) :type mac: string :return: The requested IP-address. :rtype: string

get_name_of_station(mac)

Send a request to get the name of station of the device with the given mac address. :param mac: mac address of the target device (as ‘:’ separated string) :type mac: string :return: The requested name of station. :rtype: string

Send a request to let the led of the device with the given mac address flash. :param mac: mac address of the target device (as ‘:’ separated string) :type mac: string :return: The response code to the request. Evaluates to false if the request failed. Use get_message() to get a human-readable response message. :rtype: ResponseCode

reset_to_factory(mac, mode=[0, 4])

Send a request to reset certain data or parameters of the device with the given mac address to its factory settings. If no mode is given mode 2 (RESET_COMMUNICATION) is used. :param mac: mac address of the target device (as ‘:’ separated string) :type mac: string :param mode: reset mode :type mode: ResetFactoryModes :return: The response code to the request. Evaluates to false if the request failed. Use get_message() to get a human-readable response message. :rtype: ResponseCode

factory_reset(mac)

Send a request to reset the device with the given mac address to its factory settings. :param mac: mac address of the target device (as ‘:’ separated string) :type mac: string :return: The response code to the request. Evaluates to false if the request failed. Use get_message() to get a human-readable response message. :rtype: ResponseCode

class profi_dcp.profi_dcp.ResponseCode(code)

Bases: object

Encapsulates the response code given in response to a set/reset request.

Create a new ResponseCode object with the given response code. :param code: The response code, expects an int from the inclusive range [0, 6]. :type code: int

get_message()

Return a human readable response message associated with this response code. :return: The associated response message. :rtype: string

profi_dcp.protocol module

Copyright (c) 2024 Elias Rosch, Esslingen. Copyright (c) 2020 Codewerk GmbH, Karlsruhe. All Rights Reserved.

class profi_dcp.protocol.HeaderField(name, field_format, default_value=None, pack_function=None, unpack_function=None)

Bases: object

Used to describe a header field in a packet header.

Defines a field in a packet header. At least a name and format must be provided. Optionally, a default value can be given or additional pack and unpack functions to apply before/after packing/unpacking a value. :param name: The name of the header field. :type name: string :param field_format: The struct format for values stored in this field. :type field_format: string :param default_value: A default value to use for this header field when no other value is given. :type default_value: Optional[Any] :param pack_function: An additional function applied to the field’s value before packing. :type pack_function: Optional[Any -> Any] :param unpack_function: An additional function applied after unpacking a value. Should be inverse to pack_function. An example would be converting mac addresses to binary with the pack_function and reverting them to string with the unpack_function. :type unpack_function: Optional[Any -> Any]

pack(value)

Pack the given value using the pack_function (if defined). When the given value is None, the default value is used. :param value: The value to pack. :type value: Any :return: The packed value. :rtype: Any

unpack(value)

Unpack the given value using the unpack_function (if defined). :param value: The packed value. :type value: Any :return: The unpacked value. :rtype: Any

class profi_dcp.protocol.Packet(data=None, payload=None, **kwargs)

Bases: object

Base class to represent packets and pack/unpack them.

Create a new packet. If data is given, the packets is initialized by unpacking the data. Otherwise, the payload and header fields are initialized from the remaining arguments. :param data: A packed packet as expected by unpack. :type data: bytes :param payload: The payload of the packet. :type payload: Any :param kwargs: Can be used to initialize the header fields defined in HEADER_FIELD_FORMATS :type kwargs: Any

HEADER_FIELD_FORMATS = []
unpack(data)

Unpack the packet from the given data. :param data: The packet packed to a bytes object i.e. by Packet.pack() :type data: bytes

unpack_payload(data)

Unpack the payload from the data after the header has already been unpacked. :param data: The whole packet as bytes. :type data: bytes

pack()

Pack this packet into a bytes object containing the header and the optional payload. The header fields are packed according to the format defined by ‘preamble’. If there is a payload, it is converted to bytes and appended to the packed fields. :return: This packet converted to a bytes object. :rtype: bytes

class profi_dcp.protocol.EthernetPacket(destination=None, source=None, ether_type=None, payload=None, data=None)

Bases: Packet

An Ethernet packet consisting of destination and source mac address and an ether type.

Create a new ethernet packet. If data is given, the packets is initialized by unpacking the data. Otherwise, the payload and header fields are initialized from the remaining arguments. :param destination: The mac address of the destination to send to (as ‘:’ separated string). :type destination: string :param source: The mac address of source (as ‘:’ separated string). :type source: string :param ether_type: The ethernet type (i.e. protocol ID). :type ether_type: int :param payload: The payload of the packet. :type payload: Any :param data: A packed ethernet packet. :type data: bytes

HEADER_FIELD_FORMATS = [<profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>]
class profi_dcp.protocol.DCPPacket(frame_id=None, service_id=None, service_type=None, xid=None, response_delay=0, length=None, payload=0, data=None)

Bases: Packet

A DCP packet

Create a new DCP packet. If data is given, the packets is initialized by unpacking the data. Otherwise, the payload and header fields are initialized from the remaining arguments. :param frame_id: The DCP frame ID. :type frame_id: int :param service_id: The DCP service ID. :type service_id: int :param service_type: The DCP service type. :type service_type: int :param xid: The xid, used to identify the transaction. :type xid: int :param response_delay: The response delay, default is 0, should be set only for multi-cast requests like identify all. :type response_delay: int :param length: The length of the DCP data in the payload. Computed automatically from the provided payload if not specified. :type length: int :param payload: The payload of the packet. :type payload: Any :param data: A DCP packet as expected to be unpacked. :type data: bytes

HEADER_FIELD_FORMATS = [<profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>]
unpack_payload(data)

Unpack the payload of length self.len from the data after the header has already been unpacked. :param data: The whole packet as bytes. :type data: bytes

class profi_dcp.protocol.DCPBlockRequest(opt=None, subopt=None, length=None, payload=0, data=None)

Bases: Packet

A DCP block packet for a DCP request (excluded get-requests).

Create a new DCP block request packet. If data is given, the packets is initialized by unpacking the data. Otherwise, the payload and header fields are initialized from the remaining arguments. :param opt: The DCP option. :type opt: int :param subopt: The DCP sub-option. :type subopt: int :param length: The length of the payload. :type length: int :param payload: The payload of the packet. If the payload has uneven length, it will automatically padded with zeros to even length. :type payload: Any :param data: A DCP packet as expected to be unpacked. :type data: bytes

HEADER_FIELD_FORMATS = [<profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>]
unpack_payload(data)

Unpack the payload of length self.len from the data after the header has already been unpacked. :param data: The whole packet as bytes. :type data: bytes

class profi_dcp.protocol.DCPBlockRequestGet(opt=None, subopt=None)

Bases: Packet

A DCP block packet only for a DCP get-request.

Create a new DCP block for a DCP get-request packet. Header fields are initialized from the given arguments. :param opt: The DCP option. :type opt: int :param subopt: The DCP sub-option. :type subopt: int

HEADER_FIELD_FORMATS = [<profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>]
class profi_dcp.protocol.DCPBlock(opt=None, subopt=None, length=None, status=None, payload=0, data=None)

Bases: Packet

A DCP block packet.

Create a new DCP block packet. If data is given, the packets is initialized by unpacking the data. Otherwise, the payload and header fields are initialized from the remaining arguments. :param opt: The DCP option. :type opt: int :param subopt: The DCP sub-option. :type subopt: int :param length: The length of the payload. :type length: int :param status: The block status :type status: int :param payload: The payload of the packet. :type payload: Any :param data: A DCP packet as expected to be unpacked. :type data: bytes

HEADER_FIELD_FORMATS = [<profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>, <profi_dcp.protocol.HeaderField object>]
unpack_payload(data)

Unpack the payload of length self.length - 2 from the data after the header has already been unpacked. :param data: The whole packet as bytes. :type data: bytes

profi_dcp.util module

Copyright (c) 2024 Elias Rosch, Esslingen. Copyright (c) 2020 Codewerk GmbH, Karlsruhe. All Rights Reserved.

profi_dcp.util.mac_address_to_bytes(mac_address)

Converts the mac address from ‘:’-separated strings to bytes by encoding each part as binary and concatenating them. :param mac_address: The mac address given as ‘:’-separated strings. :type mac_address: string :return: The mac address encoded as bytes. :rtype: bytes

profi_dcp.util.mac_address_to_string(mac_address)

Converts the mac address from bytes to ‘:’-separated strings by decoding each byte to a 2-digit lower-case string and concatenating them separated by ‘:’. :param mac_address: The mac address encoded as bytes. :type mac_address: bytes :return: The mac address as ‘:’-separated lower-case strings. :rtype: string

profi_dcp.util.ip_address_to_string(ip_address)

Converts the ip address from bytes to string using socket.inet_ntoa. :param ip_address: The ip address encoded as bytes. :type ip_address: bytes :return: The ip address as string. :rtype: string

profi_dcp.util.ip_address_to_bytes(ip_address)

Converts the IP address from ‘.’-separated string to bytes using socket.inet_aton. :param ip_address: The IP address given as ‘.’-separated strings. :type ip_address: string :return: The IP address encoded as bytes. :rtype: bytes

Module contents

Copyright (c) 2024 Elias Rosch, Esslingen. Copyright (c) 2020 Codewerk GmbH, Karlsruhe. All Rights Reserved.