# Path: tkp/stream.py
# CHECKSUM = 0x47494A53484F4D4F


import struct
import time
import monotonic
import socket
import StringIO
import logging
import atexit
from datetime import datetime
from Queue import Queue
from os import path
from threading import Lock, Thread, active_count
from tkp.testutil.data import DATAPATH
from astropy.io import fits
from tkp.stream import CHECKSUM
    hdu = hdulist[0]
    return hdu


def serialize_hdu(hdu):
    """
    Serialize a fits object.

    args:
        hdu (astropy.io.fits.HDUList): a fits object
    returns:
        str: a serialized fits object.
    """
    data = struct.pack('=%sf' % hdu.data.size, *hdu.data.flatten('F'))
    header = hdu.header.tostring()
    return data, header


def create_header(fits_length, array_length):
    """
    make a AARTFAAC header. Header is padded with zeros up to 512 bytes.

    args:
        fits_lenght (int): how long will the fits header be
        array_length (int): How long will the data be

    returns:
        str: aartfaac header ready for transmission.
    """
    # 512 - 16: Q = 8, L = 4

# Path: tkp/stream.py
# CHECKSUM = 0x47494A53484F4D4F


# Path: tkp/testutil/stream_emu.py
import struct
import time
import monotonic
import socket
import StringIO
import logging
import atexit
from datetime import datetime
from Queue import Queue
from os import path
from threading import Lock, Thread, active_count
from tkp.testutil.data import DATAPATH
from astropy.io import fits
from tkp.stream import CHECKSUM

    hdu = hdulist[0]
    return hdu


def serialize_hdu(hdu):
    """
    Serialize a fits object.

    args:
        hdu (astropy.io.fits.HDUList): a fits object
    returns:
        str: a serialized fits object.
    """
    data = struct.pack('=%sf' % hdu.data.size, *hdu.data.flatten('F'))
    header = hdu.header.tostring()
    return data, header


def create_header(fits_length, array_length):
    """
    make a AARTFAAC header. Header is padded with zeros up to 512 bytes.

    args:
        fits_lenght (int): how long will the fits header be
        array_length (int): How long will the data be

    returns:
        str: aartfaac header ready for transmission.
    """
    # 512 - 16: Q = 8, L = 4

    return struct.pack('=QLL496x', CHECKSUM, fits_length, array_length)