Пример #1
0
    def parse_entries(object_list):
        parsed_objects = list()
        for obj in object_list:
            interface = enumerations.CosemInterface(obj[0]).value
            version = obj[1]
            logical_name = cosem.Obis.from_bytes(obj[2])
            access_rights = obj[3]
            attribute_access_rights = (
                AssociationObjectListParser.parse_attribute_access_rights(
                    access_rights[0]))
            attribute_access_dict = {
                access.attribute: access
                for access in attribute_access_rights
            }
            method_access_rights = (
                AssociationObjectListParser.parse_method_access_rights(
                    access_rights[1]))
            method_access_dict = {
                access.method: access
                for access in method_access_rights
            }

            parsed_objects.append(
                AssociationObjectListItem(
                    interface=interface,
                    version=version,
                    logical_name=logical_name,
                    attribute_access_rights=attribute_access_dict,
                    method_access_rights=method_access_dict,
                ))
        return parsed_objects
Пример #2
0
 def from_bytes(cls, source_bytes: bytes):
     if len(source_bytes) != cls.LENGTH:
         raise ValueError(
             f"Data is not of correct length. Should be {cls.LENGTH} but is "
             f"{len(source_bytes)}")
     interface = enumerations.CosemInterface(
         int.from_bytes(source_bytes[:2], "big"))
     instance = Obis.from_bytes(source_bytes[2:8])
     method = source_bytes[-1]
     return cls(interface, instance, method)
Пример #3
0
    def from_bytes(cls, source_bytes: bytes) -> "RangeDescriptor":
        data = bytearray(source_bytes)
        access_descriptor = data.pop(0)
        if access_descriptor is not cls.ACCESS_DESCRIPTOR:
            raise ValueError(
                f"Access descriptor {access_descriptor} is not valid for "
                f"RangeDescriptor. It should be {cls.ACCESS_DESCRIPTOR}"
            )
        parsed_data = utils.parse_as_dlms_data(data)

        restricting_object_data = parsed_data[0]
        from_value_data = parsed_data[1]
        to_value_data = parsed_data[2]
        selected_values_data = parsed_data[3]

        restricting_cosem_attribute = cosem.CosemAttribute(
            interface=enumerations.CosemInterface(restricting_object_data[0]),
            instance=cosem.Obis.from_bytes(restricting_object_data[1]),
            attribute=restricting_object_data[2],
        )
        restricting_object = CaptureObject(
            cosem_attribute=restricting_cosem_attribute,
            data_index=restricting_object_data[3],
        )
        from_dt, clock_status = time.datetime_from_bytes(from_value_data)
        to_dt, clock_status = time.datetime_from_bytes(to_value_data)
        if selected_values_data:
            raise NotImplementedError()
        else:
            selected_values = None

        return cls(
            restricting_object=restricting_object,
            from_value=from_dt,
            to_value=to_dt,
            selected_values=selected_values,
        )