# Path: rtlsdr_scanner/events.py
# def post_event(destination, status):
#     if isinstance(destination, Queue.Queue):
#         destination.put(status)
#     elif isinstance(destination, wx.EvtHandler):
#         wx.PostEvent(destination, status)
# 
# class EventThread(wx.PyEvent):
#     def __init__(self, status, arg1=None, arg2=None):
#         wx.PyEvent.__init__(self)
#         self.SetEventType(EVENT_THREAD)
#         self.data = Status(status, arg1, arg2)
# 
# class Event(object):
#     STARTING, STEPS, INFO, DATA, STOPPED, ERROR, FINISHED, PROCESSED, \
#         CAL, LEVEL, UPDATED, DRAW, \
#         DELAY_COUNT, DELAY_START, \
#         LOC, LOC_RAW, LOC_WARN, LOC_ERR, LOC_SAT = range(19)


import array
import socket
import struct
import threading
import numpy
from rtlsdr_scanner.events import post_event, EventThread, Event
    def __get_header(self):
        header = self.threadBuffer.get_header()
        if len(header) == 12:
            if header.startswith('RTL0'):
                self.tuner = ((ord(header[4]) << 24) |
                              (ord(header[5]) << 16) |
                              (ord(header[6]) << 8) |
                              ord(header[7]))

    def __send_command(self, command, data):
        send = array.array('c', '\0' * 5)

        struct.pack_into('>l', send, 1, data)
        send[0] = struct.pack('<b', command)

        self.threadBuffer.sendall(send)

    def __read_raw(self, samples):
        return self.threadBuffer.recv(samples * 2)

    def __raw_to_iq(self, raw):
        iq = numpy.empty(len(raw) / 2, 'complex')
        iq.real, iq.imag = raw[::2], raw[1::2]
        iq /= (255 / 2)
        iq -= 1

        return iq

    def set_sample_rate(self, rate):
        self.__send_command(RtlTcpCmd.SET_SAMPLE_RATE, rate)

# Path: rtlsdr_scanner/events.py
# def post_event(destination, status):
#     if isinstance(destination, Queue.Queue):
#         destination.put(status)
#     elif isinstance(destination, wx.EvtHandler):
#         wx.PostEvent(destination, status)
# 
# class EventThread(wx.PyEvent):
#     def __init__(self, status, arg1=None, arg2=None):
#         wx.PyEvent.__init__(self)
#         self.SetEventType(EVENT_THREAD)
#         self.data = Status(status, arg1, arg2)
# 
# class Event(object):
#     STARTING, STEPS, INFO, DATA, STOPPED, ERROR, FINISHED, PROCESSED, \
#         CAL, LEVEL, UPDATED, DRAW, \
#         DELAY_COUNT, DELAY_START, \
#         LOC, LOC_RAW, LOC_WARN, LOC_ERR, LOC_SAT = range(19)


# Path: rtlsdr_scanner/rtltcp.py
import array
import socket
import struct
import threading
import numpy
from rtlsdr_scanner.events import post_event, EventThread, Event

    def __get_header(self):
        header = self.threadBuffer.get_header()
        if len(header) == 12:
            if header.startswith('RTL0'):
                self.tuner = ((ord(header[4]) << 24) |
                              (ord(header[5]) << 16) |
                              (ord(header[6]) << 8) |
                              ord(header[7]))

    def __send_command(self, command, data):
        send = array.array('c', '\0' * 5)

        struct.pack_into('>l', send, 1, data)
        send[0] = struct.pack('<b', command)

        self.threadBuffer.sendall(send)

    def __read_raw(self, samples):
        return self.threadBuffer.recv(samples * 2)

    def __raw_to_iq(self, raw):
        iq = numpy.empty(len(raw) / 2, 'complex')
        iq.real, iq.imag = raw[::2], raw[1::2]
        iq /= (255 / 2)
        iq -= 1

        return iq

    def set_sample_rate(self, rate):
        self.__send_command(RtlTcpCmd.SET_SAMPLE_RATE, rate)

        self.rate = rate