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

"""

Copyright 2019 MBARI.                                                    //
MBARI Proprietary Information. All rights reserved.                      //

"""

from io import BytesIO
import struct

class controller_status_t(object):

    __slots__ = ["cmd", "measure", "rate_cmd", "rate_measure", "integral", "output", "kp", "ki", "kd", "output_scale"]

    __typenames__ = ["double", "double", "double", "double", "double", "double", "double", "double", "double", "double"]

    __dimensions__ = [None, None, None, None, None, None, None, None, None, None]

    def __init__(self):
        self.cmd = 0.0
        """
        inputs
        LCM Type: double
        """

        self.measure = 0.0
        """ LCM Type: double """
        self.rate_cmd = 0.0
        """ LCM Type: double """
        self.rate_measure = 0.0
        """ LCM Type: double """
        self.integral = 0.0
        """
        integral and output
        LCM Type: double
        """

        self.output = 0.0
        """ LCM Type: double """
        self.kp = 0.0
        """
        gains
        LCM Type: double
        """

        self.ki = 0.0
        """ LCM Type: double """
        self.kd = 0.0
        """ LCM Type: double """
        self.output_scale = 0.0
        """ LCM Type: double """

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">dddddddddd", self.cmd, self.measure, self.rate_cmd, self.rate_measure, self.integral, self.output, self.kp, self.ki, self.kd, self.output_scale))

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

    @staticmethod
    def _decode_one(buf):
        self = controller_status_t()
        self.cmd, self.measure, self.rate_cmd, self.rate_measure, self.integral, self.output, self.kp, self.ki, self.kd, self.output_scale = struct.unpack(">dddddddddd", buf.read(80))
        return self

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

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

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

