profi_dcp package
Subpackages
- profi_dcp.cli package
- profi_dcp.l2socket package
- Submodules
- profi_dcp.l2socket.l2socket module
- profi_dcp.l2socket.pcap_wrapper module
- profi_dcp.l2socket.winpcap module
- Module contents
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:
objectConstants 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:
objectReset 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:
objectService type of a DCP packet
- REQUEST = 0
- RESPONSE = 1
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:
ExceptionBase class of the errors thrown by 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:
objectA 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:
objectThe 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
- blink(mac)
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:
objectEncapsulates 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:
objectUsed 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:
objectBase 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:
PacketAn 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:
PacketA 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:
PacketA 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:
PacketA 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:
PacketA 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.