import ctypes

class _CrsMotionYStr(ctypes.LittleEndianStructure):
    _pack_ = 1
    _fields_ = [
        ("spare", ctypes.c_uint16,7),
        ("rate_of_motion_y_display", ctypes.c_int16,9),
    ]

class CrsMotionY(ctypes.Union):
    _pack_ = 1
    _fields_ = [
        ("raw", ctypes.c_uint16),
        ("str", _CrsMotionYStr)
    ]

    def get_rate(self):
        return (self.raw >> 7) & 0x1FF

    def set_rate(self, value):
        self.raw &= ~(0x1FF << 7)
        self.raw |= (value << 7)

    def get_abs_pos(self):
        return (self.raw >> 0) & 0x01

    def set_abs_pos(self, value):
        self.raw &= ~(0x01 << 0)
        self.raw |= (value << 0)