"""LCM type definitions
This file automatically generated by lcm.
DO NOT MODIFY BY HAND!!!!
"""

try:
    import cStringIO.StringIO as BytesIO
except ImportError:
    from io import BytesIO
import struct

class rdi_pd4_t(object):
    __slots__ = ["utime", "system_config", "btv", "btv_status", "wtv", "wtv_status", "wtv_layer_start", "wtv_layer_end", "range", "altitude", "tofp_hour", "tofp_minute", "tofp_second", "tofp_hundredth", "builtin_test", "speed_of_sound", "xducer_head_temp"]

    __typenames__ = ["int64_t", "byte", "double", "byte", "double", "byte", "double", "double", "double", "double", "int8_t", "int8_t", "int8_t", "int8_t", "byte", "double", "double"]

    __dimensions__ = [None, None, [4], None, [4], None, None, None, [4], None, None, None, None, None, [2], None, None]

    SYSTEM_CONFIG_COORD_MASK = 192
    SYSTEM_CONFIG_COORD_BEAM = 0
    SYSTEM_CONFIG_COORD_INST = 64
    SYSTEM_CONFIG_COORD_SHIP = 128
    SYSTEM_CONFIG_COORD_EARTH = 192
    SYSTEM_CONFIG_TILT_MASK = 32
    SYSTEM_CONFIG_TILT_USED = 32
    SYSTEM_CONFIG_3BEAM_MASK = 16
    SYSTEM_CONFIG_3BEAM_USED = 16
    SYSTEM_CONFIG_KHZ_MASK = 7
    SYSTEM_CONFIG_KHZ_300 = 2
    SYSTEM_CONFIG_KHZ_600 = 3
    SYSTEM_CONFIG_KHZ_1200 = 4
    BTV_SENTINAL = -32.768
    BTV_STATUS_BEAM4_LOW_ECHO_AMPLITUDE = 128
    BTV_STATUS_BEAM4_LOW_CORRELATION = 64
    BTV_STATUS_BEAM3_LOW_ECHO_AMPLITUDE = 32
    BTV_STATUS_BEAM3_LOW_CORRELATION = 16
    BTV_STATUS_BEAM2_LOW_ECHO_AMPLITUDE = 8
    BTV_STATUS_BEAM2_LOW_CORRELATION = 4
    BTV_STATUS_BEAM1_LOW_ECHO_AMPLITUDE = 2
    BTV_STATUS_BEAM1_LOW_CORRELATION = 1
    BTV_STATUS_OK = 0
    WTV_SENTINAL = -32.768
    WTV_STATUS_ALTITUDE_TOO_SHALLOW = 16
    WTV_STATUS_BEAM4_LOW_CORRELATION = 8
    WTV_STATUS_BEAM3_LOW_CORRELATION = 4
    WTV_STATUS_BEAM2_LOW_CORRELATION = 2
    WTV_STATUS_BEAM1_LOW_CORRELATION = 1
    WTV_STATUS_OK = 0
    RANGE_SENTINAL = 0.0
    ALTITUDE_SENTINAL = 0.0
    BUILTIN_TEST_OK = 0

    def __init__(self):
        self.utime = 0
        self.system_config = 0
        self.btv = [ 0.0 for dim0 in range(4) ]
        self.btv_status = 0
        self.wtv = [ 0.0 for dim0 in range(4) ]
        self.wtv_status = 0
        self.wtv_layer_start = 0.0
        self.wtv_layer_end = 0.0
        self.range = [ 0.0 for dim0 in range(4) ]
        self.altitude = 0.0
        self.tofp_hour = 0
        self.tofp_minute = 0
        self.tofp_second = 0
        self.tofp_hundredth = 0
        self.builtin_test = b""
        self.speed_of_sound = 0.0
        self.xducer_head_temp = 0.0

    def encode(self):
        buf = BytesIO()
        buf.write(rdi_pd4_t._get_packed_fingerprint())
        self._encode_one(buf)
        return buf.getvalue()

    def _encode_one(self, buf):
        buf.write(struct.pack(">qB", self.utime, self.system_config))
        buf.write(struct.pack('>4d', *self.btv[:4]))
        buf.write(struct.pack(">B", self.btv_status))
        buf.write(struct.pack('>4d', *self.wtv[:4]))
        buf.write(struct.pack(">Bdd", self.wtv_status, self.wtv_layer_start, self.wtv_layer_end))
        buf.write(struct.pack('>4d', *self.range[:4]))
        buf.write(struct.pack(">dbbbb", self.altitude, self.tofp_hour, self.tofp_minute, self.tofp_second, self.tofp_hundredth))
        buf.write(bytearray(self.builtin_test[:2]))
        buf.write(struct.pack(">dd", self.speed_of_sound, self.xducer_head_temp))

    def decode(data):
        if hasattr(data, 'read'):
            buf = data
        else:
            buf = BytesIO(data)
        if buf.read(8) != rdi_pd4_t._get_packed_fingerprint():
            raise ValueError("Decode error")
        return rdi_pd4_t._decode_one(buf)
    decode = staticmethod(decode)

    def _decode_one(buf):
        self = rdi_pd4_t()
        self.utime, self.system_config = struct.unpack(">qB", buf.read(9))
        self.btv = struct.unpack('>4d', buf.read(32))
        self.btv_status = struct.unpack(">B", buf.read(1))[0]
        self.wtv = struct.unpack('>4d', buf.read(32))
        self.wtv_status, self.wtv_layer_start, self.wtv_layer_end = struct.unpack(">Bdd", buf.read(17))
        self.range = struct.unpack('>4d', buf.read(32))
        self.altitude, self.tofp_hour, self.tofp_minute, self.tofp_second, self.tofp_hundredth = struct.unpack(">dbbbb", buf.read(12))
        self.builtin_test = buf.read(2)
        self.speed_of_sound, self.xducer_head_temp = struct.unpack(">dd", buf.read(16))
        return self
    _decode_one = staticmethod(_decode_one)

    def _get_hash_recursive(parents):
        if rdi_pd4_t in parents: return 0
        tmphash = (0xa3a5e0187342f43e) & 0xffffffffffffffff
        tmphash  = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff
        return tmphash
    _get_hash_recursive = staticmethod(_get_hash_recursive)
    _packed_fingerprint = None

    def _get_packed_fingerprint():
        if rdi_pd4_t._packed_fingerprint is None:
            rdi_pd4_t._packed_fingerprint = struct.pack(">Q", rdi_pd4_t._get_hash_recursive([]))
        return rdi_pd4_t._packed_fingerprint
    _get_packed_fingerprint = staticmethod(_get_packed_fingerprint)

    def get_hash(self):
        """Get the LCM hash of the struct"""
        return struct.unpack(">Q", rdi_pd4_t._get_packed_fingerprint())[0]

