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

"""
surface_pose_t.lcm
 Copyright 2019 MBARI

"""

from io import BytesIO
import struct

class surface_pose_t(object):

    __slots__ = ["CrossTrackDistance", "RangeDistance", "pseudoRangeTarget", "NormalRange", "SurveyHeading", "SurveyCS_SeqNum", "VehicleHeading", "PathPitchRelGravity", "TargetFramePitchRelGravity", "TargetFramePitchRelVehicle", "pVi", "pAi", "pVb", "pAb", "wLwi", "wLwb", "wLws", "sLsi", "sLsb", "bLbf", "wRp", "wRi", "wRb", "wRs", "bRf"]

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

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

    def __init__(self):
        self.CrossTrackDistance = 0.0
        """ LCM Type: double """
        self.RangeDistance = 0.0
        """
        Crosstrack distance of instrument from survey plane. (in direction of wRp[][1])
        LCM Type: double
        """

        self.pseudoRangeTarget = 0.0
        """
        Measured range.  Distance from instrument to tangent plane, in direction of wRp[][2])
        LCM Type: double
        """

        self.NormalRange = 0.0
        """
        pseudo range target.  Range target, per unit of desired normal distance.  i.e For 3m stand-off, multiply pRangeTarget by 3m and compare to RangeDistance
        LCM Type: double
        """

        self.SurveyHeading = 0.0
        """
        Normal Range,  Distance from instrument to closest point of the tangent plane.
        LCM Type: double
        """

        self.SurveyCS_SeqNum = 0
        """
        Survey line direction in degrees, specified by user
        LCM Type: int32_t
        """

        self.VehicleHeading = 0.0
        """
        Survey coordinate sequence number, changes when heading or lat/lon is updated.
        LCM Type: double
        """

        self.PathPitchRelGravity = 0.0
        """
        Vehicle heading relative to north in degrees. (0-360 degrees)
        LCM Type: double
        """

        self.TargetFramePitchRelGravity = 0.0
        """
        Pitch of Path along track relative to gravity (-180->180 degrees)
        LCM Type: double
        """

        self.TargetFramePitchRelVehicle = 0.0
        """
        Target Frame Pitch Relative to gravity (-180-180)
        LCM Type: double
        """

        self.pVi = [ 0.0 for dim0 in range(3) ]
        """
        Target Frame Pitch Relative to vehicle (-180-180)
        LCM Type: double[3]
        """

        self.pAi = [ 0.0 for dim0 in range(3) ]
        """
        Velocity of instrument in path coordinate system.  pVi[0] is the measured along-track speed  in direction of wRp[][0]
        LCM Type: double[3]
        """

        self.pVb = [ 0.0 for dim0 in range(3) ]
        """
        Accel of instrument in path coordinate system.  pAi[0] is the measured along-track accel  in direction of wRp[][0]
        LCM Type: double[3]
        """

        self.pAb = [ 0.0 for dim0 in range(3) ]
        """
        Velocity of vehicle in path coordinate system.  pVb[0] is the measured along-track speed  in direction of wRp[][0]
        LCM Type: double[3]
        """

        self.wLwi = [ 0.0 for dim0 in range(3) ]
        """
        Accel of vehicle in path coordinate system.  pAb[0] is the measured along-track accel  in direction of wRp[][0]
        LCM Type: double[3]
        """

        self.wLwb = [ 0.0 for dim0 in range(3) ]
        """
        Position of instrument in world coordinates
        LCM Type: double[3]
        """

        self.wLws = [ 0.0 for dim0 in range(3) ]
        """
        Location of vehicle body origin in world coordinates.
        LCM Type: double[3]
        """

        self.sLsi = [ 0.0 for dim0 in range(3) ]
        """
        Location of survey CS origin in world coordinates.
        LCM Type: double[3]
        """

        self.sLsb = [ 0.0 for dim0 in range(3) ]
        """
        Position of instrument in survey coordinates
        LCM Type: double[3]
        """

        self.bLbf = [ 0.0 for dim0 in range(3) ]
        """
        Position of ROV in survey coordinates
        LCM Type: double[3]
        """

        self.wRp = [ [ 0.0 for dim1 in range(3) ] for dim0 in range(3) ]
        """
        Position of Frame in body coordinates
        LCM Type: double[3][3]
        """

        self.wRi = [ [ 0.0 for dim1 in range(3) ] for dim0 in range(3) ]
        """
        Rotation from Path to World.  i.e. Path basis vectors written in world frame.
        LCM Type: double[3][3]
        """

        self.wRb = [ [ 0.0 for dim1 in range(3) ] for dim0 in range(3) ]
        """
        Orientation of instrument in world coordinates, Reported as RPY by kearfott
        LCM Type: double[3][3]
        """

        self.wRs = [ [ 0.0 for dim1 in range(3) ] for dim0 in range(3) ]
        """
        Orientation of body (ROV) in world coordinates
        LCM Type: double[3][3]
        """

        self.bRf = [ [ 0.0 for dim1 in range(3) ] for dim0 in range(3) ]
        """
        Rotation from Survey to World coordinate sysetem. 
        LCM Type: double[3][3]
        """


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

    def _encode_one(self, buf):
        buf.write(struct.pack(">dddddidddd", self.CrossTrackDistance, self.RangeDistance, self.pseudoRangeTarget, self.NormalRange, self.SurveyHeading, self.SurveyCS_SeqNum, self.VehicleHeading, self.PathPitchRelGravity, self.TargetFramePitchRelGravity, self.TargetFramePitchRelVehicle))
        buf.write(struct.pack('>3d', *self.pVi[:3]))
        buf.write(struct.pack('>3d', *self.pAi[:3]))
        buf.write(struct.pack('>3d', *self.pVb[:3]))
        buf.write(struct.pack('>3d', *self.pAb[:3]))
        buf.write(struct.pack('>3d', *self.wLwi[:3]))
        buf.write(struct.pack('>3d', *self.wLwb[:3]))
        buf.write(struct.pack('>3d', *self.wLws[:3]))
        buf.write(struct.pack('>3d', *self.sLsi[:3]))
        buf.write(struct.pack('>3d', *self.sLsb[:3]))
        buf.write(struct.pack('>3d', *self.bLbf[:3]))
        for i0 in range(3):
            buf.write(struct.pack('>3d', *self.wRp[i0][:3]))
        for i0 in range(3):
            buf.write(struct.pack('>3d', *self.wRi[i0][:3]))
        for i0 in range(3):
            buf.write(struct.pack('>3d', *self.wRb[i0][:3]))
        for i0 in range(3):
            buf.write(struct.pack('>3d', *self.wRs[i0][:3]))
        for i0 in range(3):
            buf.write(struct.pack('>3d', *self.bRf[i0][:3]))

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

    @staticmethod
    def _decode_one(buf):
        self = surface_pose_t()
        self.CrossTrackDistance, self.RangeDistance, self.pseudoRangeTarget, self.NormalRange, self.SurveyHeading, self.SurveyCS_SeqNum, self.VehicleHeading, self.PathPitchRelGravity, self.TargetFramePitchRelGravity, self.TargetFramePitchRelVehicle = struct.unpack(">dddddidddd", buf.read(76))
        self.pVi = struct.unpack('>3d', buf.read(24))
        self.pAi = struct.unpack('>3d', buf.read(24))
        self.pVb = struct.unpack('>3d', buf.read(24))
        self.pAb = struct.unpack('>3d', buf.read(24))
        self.wLwi = struct.unpack('>3d', buf.read(24))
        self.wLwb = struct.unpack('>3d', buf.read(24))
        self.wLws = struct.unpack('>3d', buf.read(24))
        self.sLsi = struct.unpack('>3d', buf.read(24))
        self.sLsb = struct.unpack('>3d', buf.read(24))
        self.bLbf = struct.unpack('>3d', buf.read(24))
        self.wRp = []
        for i0 in range(3):
            self.wRp.append(struct.unpack('>3d', buf.read(24)))
        self.wRi = []
        for i0 in range(3):
            self.wRi.append(struct.unpack('>3d', buf.read(24)))
        self.wRb = []
        for i0 in range(3):
            self.wRb.append(struct.unpack('>3d', buf.read(24)))
        self.wRs = []
        for i0 in range(3):
            self.wRs.append(struct.unpack('>3d', buf.read(24)))
        self.bRf = []
        for i0 in range(3):
            self.bRf.append(struct.unpack('>3d', buf.read(24)))
        return self

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

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

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

