"""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

import compas_lcmtypes.stdlcm.header_t

class ahrs_t(object):
    __slots__ = ["header", "orientation", "angRate", "xyz_ddot", "magfield"]

    __typenames__ = ["compas_lcmtypes.stdlcm.header_t", "double", "double", "double", "double"]

    __dimensions__ = [None, [4], [3], [3], [3]]

    def __init__(self):
        self.header = compas_lcmtypes.stdlcm.header_t()
        self.orientation = [ 0.0 for dim0 in range(4) ]
        self.angRate = [ 0.0 for dim0 in range(3) ]
        self.xyz_ddot = [ 0.0 for dim0 in range(3) ]
        self.magfield = [ 0.0 for dim0 in range(3) ]

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

    def _encode_one(self, buf):
        assert self.header._get_packed_fingerprint() == compas_lcmtypes.stdlcm.header_t._get_packed_fingerprint()
        self.header._encode_one(buf)
        buf.write(struct.pack('>4d', *self.orientation[:4]))
        buf.write(struct.pack('>3d', *self.angRate[:3]))
        buf.write(struct.pack('>3d', *self.xyz_ddot[:3]))
        buf.write(struct.pack('>3d', *self.magfield[:3]))

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

    def _decode_one(buf):
        self = ahrs_t()
        self.header = compas_lcmtypes.stdlcm.header_t._decode_one(buf)
        self.orientation = struct.unpack('>4d', buf.read(32))
        self.angRate = struct.unpack('>3d', buf.read(24))
        self.xyz_ddot = struct.unpack('>3d', buf.read(24))
        self.magfield = struct.unpack('>3d', buf.read(24))
        return self
    _decode_one = staticmethod(_decode_one)

    def _get_hash_recursive(parents):
        if ahrs_t in parents: return 0
        newparents = parents + [ahrs_t]
        tmphash = (0x7ffb7870ea25455+ compas_lcmtypes.stdlcm.header_t._get_hash_recursive(newparents)) & 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 ahrs_t._packed_fingerprint is None:
            ahrs_t._packed_fingerprint = struct.pack(">Q", ahrs_t._get_hash_recursive([]))
        return ahrs_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", ahrs_t._get_packed_fingerprint())[0]

