import math


def rat_from_rtc(rtc_s):
    """
    Turn a real-time clock value into a radio time value

    Args:
      rtc_s: real-time-clock in seconds

    Returns:
        rat_s: radio time in seconds
        rat_t: radio time in ticks

    """
    # Updated assumed RAT tick based on RTC value (magic magic)
    # Doing the same assumptions as done inside the RF  (0x100000000LL/32768)
    # RTC in ticks like on our devices
    rtc_sec = int((math.floor(rtc_s) * 32768))
    rtc_subsec = int((rtc_s - rtc_sec) * 2 ** 32)
    new_rat = (rtc_sec << 32) + rtc_subsec
    # Conservatively assume that we are just about to increment
    # the RTC Scale with the 4 MHz that the RAT is running
    # Add the RAT offset for RTC == 0 * /
    new_rat += 4294967296 / 32768
    new_rat *= 4000000  # Scale to 4 MHz ticks
    new_rat = new_rat / 4294967296
    # Store as ticks
    rat_t = new_rat
    # Store as time
    rat_s = new_rat / 4000000
    return rat_s, rat_t