import ctypes

ICD1553_CAS_KNOTS_LSB = 1.0
GC_K_KNOTS_TO_MS = 0.514444
ICD1553_CAS_MS_LSB = ICD1553_CAS_KNOTS_LSB * GC_K_KNOTS_TO_MS

class _CasStr(ctypes.LittleEndianStructure):
    _pack_ = 1
    _fields_ = [
        ("spare", ctypes.c_uint16, 6),
        ("ownship_calibrated_air_speed", ctypes.c_uint16, 10)
        ]
class Cas(ctypes.Union):
    _pack_ = 1
    _fields_ = [
        ("raw", ctypes.c_uint16),
        ("str", _CasStr)
        ]

    def get(self):
        return ((self.raw >> 6) & 0x3FF) * ICD1553_CAS_MS_LSB

    def set(self, value):
        self.raw &= ~(0x3FF << 6)
        self.raw |= (int(value / ICD1553_CAS_MS_LSB) << 6)