/usr/lib/python2.7/dist-packages/ola/DUBDecoder.py is in ola-python 0.10.5.nojsmin-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# DUBDecoder.py
# Copyright (C) 2012 Simon Newton
import itertools
from ola.UID import UID
"""Decodes a DUB response."""
__author__ = 'nomis52@gmail.com (Simon Newton)'
def DecodeResponse(data):
"""Decode a DUB response.
Args:
data: an iterable of data like a bytearray
Returns:
The UID that responded, or None if the response wasn't valid.
"""
# min length is 18 bytes
if len(data) < 18:
return None
# must start with 0xfe
if data[0] != 0xfe:
return None
data = list(itertools.dropwhile(lambda x: x == 0xfe, data))
if len(data) < 17 or data[0] != 0xaa:
return None
data = data[1:]
checksum = 0
for b in data[0:12]:
checksum += b
packet_checksum = (
(data[12] & data[13]) << 8 |
(data[14] & data[15])
)
if checksum != packet_checksum:
return None
manufacturer_id = (
(data[0] & data[1]) << 8 |
(data[2] & data[3])
)
device_id = (
(data[4] & data[5]) << 24 |
(data[6] & data[7]) << 16 |
(data[8] & data[9]) << 8 |
(data[10] & data[11])
)
return UID(manufacturer_id, device_id)
|