Search Active Devices Protocol (SADP)
This module covers basic operations and classes related to the UDP broadcast communication with hikvision devices.
Interface
- hiktools.sadp.unmarshal(root: Element)
Tries to de-serialize an XML-String.
Possible object types are: DiscoveryPacket, DeviceSafeCodePacket, ActionResponse, and BasicDictObject for messages that are not implemented yet.
- Parameters:
root (xmltree.Element) – The XML root element (non null).
- Returns:
A qualified object instance or None if the given argument was None or the input could not be converted.
- Return type:
? extends BasicDictObject, None
- hiktools.sadp.hik_code(serial: str, timestamp: tuple) str
Generates the old Hikvision reset code.
Arguments: :param serial: The device’s serial number. :type serial: str :param timestamp: A timestamp of the following format: (day, month, year) :type timestamp: str
- Returns:
The generated reset code (can be used within a reset packet).
- Return type:
str
- hiktools.sadp.fromdict(value: dict) SADPMessage
Converts a dict object into an SADPMessage object.
- Parameters:
value (dict) – The input dict containing the XML nodes.
- Returns:
An message object containing all nodes of the given dict object converted into an XML string.
- Return type:
SADPMessage
Classes
Client
- class hiktools.sadp.SADPClient(port: int = 37020, timeout: int = 2)
A simple UDP wrapper client.
This clas implements basic funtionalities of an UDP socket sending data from UDP broadcast. The with directive can be used and __iter__ is also implemented in order to iterate over reveiced SADPMessages.
Example usage
from hiktools import sadp
with sadp.SADPClient(timeout=3) as client:
# send data with client.write
client.write(some_message)
# receive bytes with client.recv_next() or just iterate
# over next SADPMessages:
for message in client:
if message is None: break
# de-serialize message
response = sadp.unmarshal(message)
Response Classes
- class hiktools.sadp.ActionResponse(root: Element | None = None)
A ‘reset’ message response packet.
The response packet just contains one field of interest named ‘Result’. It applies to the following values: failure, success, denied
- property success: bool
Returns whether the action invocation was successful.
- class hiktools.sadp.DiscoveryPacket(root: Element | None = None, exclude: list | None = None)
A simple discovery packet response wrapper.
Contains all information related to the inquiry response packet. Possible nodes are:
DeviceType, DeviceDescription, CommandPort, HttpPort, MAC, Ipv4Address, Ipv4SubnetMask, Ipv4Gateway, Ipv6Address, Ipv6Masklen, Ipv6Gateway, DHCP, AnalogChannelNum, DigitalChannelNum, DSPVersion, Activated and PasswordResetAbility.
- class hiktools.sadp.SafeCode(code: bytes)
The device’s safe code wrapper class.
A safe code is requested by the SADP Tool to export it and send it to the customer service. An unlock code should be returned which can reset the device.
- SAFECODE_FLAG = '03000000'
Safe code header value
- property checksum: c_uint
The checksum stored in the safe code.
- property code: str
The full safe code as a string