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


from io import BytesIO
import struct

import oi

class sled_control_t(object):

    __slots__ = ["time_unix_sec", "count_publish", "sender_id", "valvesetting", "valvezero", "kft_pitch", "kft_valid", "rov_imu_pitch", "rov_imu_valid", "beam_1", "beam_2", "beam_3", "beam_4", "beam_height", "beam_pitch_source", "beam_diff", "beam_valid", "pitch_source", "selected_pitch", "target_pitch", "axle_valid", "axle_pitch", "axle_sine", "axle_cosine", "command", "pid_on", "moog_on", "coil_drive_on", "axle_on", "kp", "ki", "kd", "kbi", "kbp", "selected_mode", "limits"]

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

    __dimensions__ = [None, None, None, None, None, None, None, None, None, None, None, None, None, None, 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.time_unix_sec = 0.0
        """
        Time since Unix Epoch
        LCM Type: double
        """

        self.count_publish = 0
        """
        LCM publish count
        LCM Type: int64_t
        """

        self.sender_id = ""
        """
        Self identifier for sender.
        LCM Type: string
        """

        self.valvesetting = 0.0
        """
        valve output
        LCM Type: double
        """

        self.valvezero = 0.0
        """ LCM Type: double """
        self.kft_pitch = 0.0
        """
        Kearfott
        LCM Type: double
        """

        self.kft_valid = False
        """ LCM Type: boolean """
        self.rov_imu_pitch = 0.0
        """
        ROV IMU
        LCM Type: double
        """

        self.rov_imu_valid = False
        """ LCM Type: boolean """
        self.beam_1 = 0
        """
        DVL
        LCM Type: int64_t
        """

        self.beam_2 = 0
        """ LCM Type: int64_t """
        self.beam_3 = 0
        """ LCM Type: int64_t """
        self.beam_4 = 0
        """ LCM Type: int64_t """
        self.beam_height = 0.0
        """ LCM Type: double """
        self.beam_pitch_source = 0.0
        """ LCM Type: double """
        self.beam_diff = 0.0
        """ LCM Type: double """
        self.beam_valid = False
        """ LCM Type: boolean """
        self.pitch_source = 0.0
        """ LCM Type: double """
        self.selected_pitch = 0.0
        """ LCM Type: double """
        self.target_pitch = 0.0
        """ LCM Type: double """
        self.axle_valid = False
        """ LCM Type: boolean """
        self.axle_pitch = 0.0
        """ LCM Type: double """
        self.axle_sine = 0
        """ LCM Type: int32_t """
        self.axle_cosine = 0
        """
        counts of the sensor
        LCM Type: int32_t
        """

        self.command = 0.0
        """
        counts of the opposed sensor
        LCM Type: double
        """

        self.pid_on = False
        """
        error value of the control loop
        status
        LCM Type: boolean
        """

        self.moog_on = False
        """
        status of the pid_loop
        LCM Type: boolean
        """

        self.coil_drive_on = False
        """
        power status of the moog amplifier
        LCM Type: boolean
        """

        self.axle_on = False
        """
        coil drive circuit
        LCM Type: boolean
        """

        self.kp = 0.0
        """
        switch status of the tilt sensor
        current control loop gains
        LCM Type: double
        """

        self.ki = 0.0
        """ LCM Type: double """
        self.kd = 0.0
        """ LCM Type: double """
        self.kbi = 0.0
        """ LCM Type: double """
        self.kbp = 0.0
        """ LCM Type: double """
        self.selected_mode = 0
        """ LCM Type: int32_t """
        self.limits = oi.sled_control_limits_t()
        """ LCM Type: oi.sled_control_limits_t """

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">dq", self.time_unix_sec, self.count_publish))
        __sender_id_encoded = self.sender_id.encode('utf-8')
        buf.write(struct.pack('>I', len(__sender_id_encoded)+1))
        buf.write(__sender_id_encoded)
        buf.write(b"\0")
        buf.write(struct.pack(">dddbdbqqqqdddbdddbdiidbbbbdddddi", self.valvesetting, self.valvezero, self.kft_pitch, self.kft_valid, self.rov_imu_pitch, self.rov_imu_valid, self.beam_1, self.beam_2, self.beam_3, self.beam_4, self.beam_height, self.beam_pitch_source, self.beam_diff, self.beam_valid, self.pitch_source, self.selected_pitch, self.target_pitch, self.axle_valid, self.axle_pitch, self.axle_sine, self.axle_cosine, self.command, self.pid_on, self.moog_on, self.coil_drive_on, self.axle_on, self.kp, self.ki, self.kd, self.kbi, self.kbp, self.selected_mode))
        assert self.limits._get_packed_fingerprint() == oi.sled_control_limits_t._get_packed_fingerprint()
        self.limits._encode_one(buf)

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

    @staticmethod
    def _decode_one(buf):
        self = sled_control_t()
        self.time_unix_sec, self.count_publish = struct.unpack(">dq", buf.read(16))
        __sender_id_len = struct.unpack('>I', buf.read(4))[0]
        self.sender_id = buf.read(__sender_id_len)[:-1].decode('utf-8', 'replace')
        self.valvesetting, self.valvezero, self.kft_pitch = struct.unpack(">ddd", buf.read(24))
        self.kft_valid = bool(struct.unpack('b', buf.read(1))[0])
        self.rov_imu_pitch = struct.unpack(">d", buf.read(8))[0]
        self.rov_imu_valid = bool(struct.unpack('b', buf.read(1))[0])
        self.beam_1, self.beam_2, self.beam_3, self.beam_4, self.beam_height, self.beam_pitch_source, self.beam_diff = struct.unpack(">qqqqddd", buf.read(56))
        self.beam_valid = bool(struct.unpack('b', buf.read(1))[0])
        self.pitch_source, self.selected_pitch, self.target_pitch = struct.unpack(">ddd", buf.read(24))
        self.axle_valid = bool(struct.unpack('b', buf.read(1))[0])
        self.axle_pitch, self.axle_sine, self.axle_cosine, self.command = struct.unpack(">diid", buf.read(24))
        self.pid_on = bool(struct.unpack('b', buf.read(1))[0])
        self.moog_on = bool(struct.unpack('b', buf.read(1))[0])
        self.coil_drive_on = bool(struct.unpack('b', buf.read(1))[0])
        self.axle_on = bool(struct.unpack('b', buf.read(1))[0])
        self.kp, self.ki, self.kd, self.kbi, self.kbp, self.selected_mode = struct.unpack(">dddddi", buf.read(44))
        self.limits = oi.sled_control_limits_t._decode_one(buf)
        return self

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

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

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

