import ctypes

ICD1553_TAS_KNOTS_LSB = 0.125
GC_K_KNOTS_TO_MS = 0.514444  # Definizione di esempio, controlla il valore corretto
ICD1553_TAS_MS_LSB = ICD1553_TAS_KNOTS_LSB * GC_K_KNOTS_TO_MS

class Tas(ctypes.Union):
    _fields_ = [("raw", ctypes.c_int16),
                ("true_air_speed", ctypes.c_int16),]

    def get(self):
        return self.raw * ICD1553_TAS_MS_LSB

    def set(self, value):
        self.raw = int(value / ICD1553_TAS_MS_LSB)
        
class _WindSpeedStr(ctypes.LittleEndianStructure):
    _pack_ = 1
    _fields_ = [
        ("spare", ctypes.c_uint16, 3),
        ("wind_velocity_amplitude", ctypes.c_uint16,13)
        ]
class WindSpeed(ctypes.Union):
    _pack_ = 1
    _fields_ = [
        ("raw", ctypes.c_int16),
        ("str", _WindSpeedStr)
        ]
    
    def get_wind_velocity_amplitude(self):
        """Extract the 13-bit wind velocity amplitude field"""
        return self.str.wind_velocity_amplitude
    
    def set_wind_velocity_amplitude(self, value):
        """Set the 13-bit wind velocity amplitude field"""
        self.str.wind_velocity_amplitude = int(value) & 0x1FFF
    
    def get(self):
        """Get wind velocity amplitude (for compatibility with other Union types)"""
        return self.str.wind_velocity_amplitude
    
    def get_wind_velocity_amplitude(self):
        """Extract the 13-bit wind velocity amplitude field"""
        return self.str.wind_velocity_amplitude
    
    def set_wind_velocity_amplitude(self, value):
        """Set the 13-bit wind velocity amplitude field"""
        self.str.wind_velocity_amplitude = int(value) & 0x1FFF
    
    def get(self):
        """Get wind velocity amplitude (for compatibility with other Union types)"""
        return self.str.wind_velocity_amplitude