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

"""

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

"""

from io import BytesIO
import struct

import oi

class oi_strobe_tilter_t(object):

    __slots__ = ["header", "mux_channel_cmd", "tilt_angle_cmd", "tilt_deg", "tilt_deg_sec", "tilt_cnts", "tilt_cw_limit", "tilt_ccw_limit", "cmd", "measure", "rate_cmd", "rate_measure", "output", "integral", "kp", "ki", "kd", "output_scale", "uptime_sec", "loop_exec_ms", "missed_updates", "serial_connected"]

    __typenames__ = ["oi.lcm_header_t", "int32_t", "double", "double", "double", "int32_t", "int32_t", "int32_t", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "int64_t", "boolean"]

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

    def __init__(self):
        self.header = oi.lcm_header_t()
        """
        message header
        LCM Type: oi.lcm_header_t
        """

        self.mux_channel_cmd = 0
        """
        current command values
        LCM Type: int32_t
        """

        self.tilt_angle_cmd = 0.0
        """ LCM Type: double """
        self.tilt_deg = 0.0
        """
        positioner status
        LCM Type: double
        """

        self.tilt_deg_sec = 0.0
        """ LCM Type: double """
        self.tilt_cnts = 0
        """ LCM Type: int32_t """
        self.tilt_cw_limit = 0
        """ LCM Type: int32_t """
        self.tilt_ccw_limit = 0
        """ LCM Type: int32_t """
        self.cmd = 0.0
        """
        controller 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.output = 0.0
        """
        controller output and integral
        LCM Type: double
        """

        self.integral = 0.0
        """ LCM Type: double """
        self.kp = 0.0
        """
        controller 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 """
        self.uptime_sec = 0.0
        """
        process statistics
        LCM Type: double
        """

        self.loop_exec_ms = 0.0
        """ LCM Type: double """
        self.missed_updates = 0
        """ LCM Type: int64_t """
        self.serial_connected = False
        """ LCM Type: boolean """

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

    def _encode_one(self, buf):
        assert self.header._get_packed_fingerprint() == oi.lcm_header_t._get_packed_fingerprint()
        self.header._encode_one(buf)
        buf.write(struct.pack(">idddiiiddddddddddddqb", self.mux_channel_cmd, self.tilt_angle_cmd, self.tilt_deg, self.tilt_deg_sec, self.tilt_cnts, self.tilt_cw_limit, self.tilt_ccw_limit, self.cmd, self.measure, self.rate_cmd, self.rate_measure, self.output, self.integral, self.kp, self.ki, self.kd, self.output_scale, self.uptime_sec, self.loop_exec_ms, self.missed_updates, self.serial_connected))

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

    @staticmethod
    def _decode_one(buf):
        self = oi_strobe_tilter_t()
        self.header = oi.lcm_header_t._decode_one(buf)
        self.mux_channel_cmd, self.tilt_angle_cmd, self.tilt_deg, self.tilt_deg_sec, self.tilt_cnts, self.tilt_cw_limit, self.tilt_ccw_limit, self.cmd, self.measure, self.rate_cmd, self.rate_measure, self.output, self.integral, self.kp, self.ki, self.kd, self.output_scale, self.uptime_sec, self.loop_exec_ms, self.missed_updates = struct.unpack(">idddiiiddddddddddddq", buf.read(144))
        self.serial_connected = bool(struct.unpack('b', buf.read(1))[0])
        return self

    @staticmethod
    def _get_hash_recursive(parents):
        if oi_strobe_tilter_t in parents: return 0
        newparents = parents + [oi_strobe_tilter_t]
        tmphash = (0xba9008ca62a7df82+ oi.lcm_header_t._get_hash_recursive(newparents)) & 0xffffffffffffffff
        tmphash  = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff
        return tmphash
    _packed_fingerprint = None

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

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

