# Path: wildfind/harrier/events.py
# SCAN_START, SCAN_DONE, \
#     GPS_OPEN, GPS_LOC, GPS_SATS, GPS_ERR, \
#     STATUS_IDLE, STATUS_WAIT, STATUS_CAPTURE, STATUS_PROCESS, \
#     INFO, WARN, ERR = range(13)
# class Event(object):
# class Post(object):
#     def __init__(self, eventType, **kwargs):
#     def get_type(self):
#     def get_arg(self, arg):
#     def get_args(self):
#     def __init__(self, queue):
#     def __post(self, event, delay=0):
#     def status(self, eventType):
#     def scan_start(self, delay=0):
#     def scan_done(self, collars=None, timeStamp=None):
#     def gps_open(self, delay):
#     def gps_location(self, location):
#     def gps_satellites(self, satellites):
#     def gps_error(self, error):
#     def error(self, error):
#     def warning(self, warning):
#     def info(self, info):
# 
# Path: wildfind/harrier/collar.py
# MOD_DESC = ['CW', 'AM']
# 
# Path: wildfind/harrier/receive.py
# class Receive(threading.Thread):
#     def __init__(self, settings, queue):
#         threading.Thread.__init__(self)
#         self.name = 'Receive'
#         self.daemon = True
# 
#         self._settings = settings
#         self._queue = queue
# 
#         self._cancel = False
#         self._receive = False
# 
#         self._sdr = None
#         self._capture = (ctypes.c_ubyte * int(2 * SAMPLE_RATE * SAMPLE_TIME))()
# 
#         self._captureBlock = 0
#         self._timeStamp = None
# 
#         devices = rtlsdr.librtlsdr.rtlsdr_get_device_count()
#         if self._settings.recvIndex >= devices:
#             error = 'Cannot find device at index {}'
#             error = error.format(self._settings.recvIndex)
#             events.Post(self._queue).error(error)
#         else:
#             self.start()
# 
#     def __capture(self, data, _sdr):
#         length = len(data)
#         pos = self._captureBlock * length
#         dst = ctypes.byref(self._capture, pos)
#         ctypes.memmove(dst, data, length * ctypes.sizeof(ctypes.c_ubyte))
# 
#         self._captureBlock += 1
#         if self._captureBlock == BLOCKS:
#             self._sdr.cancel_read_async()
#             self._captureBlock = 0
# 
#     def __receive(self):
#         self._receive = False
# 
#         events.Post(self._queue).status(events.STATUS_CAPTURE)
# 
#         try:
#             if self._sdr is None:
#                 self._sdr = rtlsdr.RtlSdr(device_index=self._settings.recvIndex)
#                 self._sdr.set_sample_rate(SAMPLE_RATE)
#                 self._sdr.set_center_freq(self._settings.freq * 1e6)
#                 time.sleep(1)
#                 self._sdr.set_gain(self._settings.recvGain)
#                 cal = int(self._settings.recvCal)
#                 if cal != 0:
#                     self._sdr.set_freq_correction(cal)
#             self._timeStamp = time.time()
# 
#             self._sdr.read_bytes_async(self.__capture,
#                                        2 * SAMPLE_RATE * SAMPLE_TIME / BLOCKS)
#             if self._cancel:
#                 return
# 
#             events.Post(self._queue).status(events.STATUS_PROCESS)
#             iq = stream_to_complex(self._capture)
#             if self._cancel:
#                 return
# 
#             scan = Scan(SAMPLE_RATE, iq)
#             frequencies = scan.search()
#             if self._cancel:
#                 return
# 
#             detect = Detect(SAMPLE_RATE, iq, frequencies)
#             collars = detect.search(self._settings.freq * 1e6)
# 
#             events.Post(self._queue).status(events.STATUS_IDLE)
#             events.Post(self._queue).scan_done(collars=collars,
#                                                timeStamp=self._timeStamp)
# 
#         except IOError as e:
#             error = 'Capture failed: {}'.format(e.message)
#             events.Post(self._queue).error(error)
# 
#     def run(self):
#         while not self._cancel:
#             if self._receive:
#                 self.__receive()
#             else:
#                 try:
#                     time.sleep(0.1)
#                 except IOError:
#                     pass
# 
#     def receive(self):
#         self._receive = True
# 
#     def stop(self):
#         self._cancel = True
#         if self._sdr is not None:
#             try:
#                 self._sdr.cancel_read_async()
#             except IOError:
#                 pass


import Queue
import signal
import sys
import time
from math import log10
from wildfind.harrier import events
from wildfind.harrier.collar import MOD_DESC
from wildfind.harrier.receive import Receive
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#




class TestMode(object):
    def __init__(self, settings):
        print 'Test mode'

        queue = Queue.Queue()

        self._receive = Receive(settings, queue)
        self._signal = signal.signal(signal.SIGINT, self.__close)

        events.Post(queue).scan_start()

        while self._receive.isAlive():
            if not queue.empty():
                self.__process_queue(settings, queue)

        self.__close()

    def __process_queue(self, _settings, queue):
        event = queue.get()
        eventType = event.get_type()


# Path: wildfind/harrier/events.py
# SCAN_START, SCAN_DONE, \
#     GPS_OPEN, GPS_LOC, GPS_SATS, GPS_ERR, \
#     STATUS_IDLE, STATUS_WAIT, STATUS_CAPTURE, STATUS_PROCESS, \
#     INFO, WARN, ERR = range(13)
# class Event(object):
# class Post(object):
#     def __init__(self, eventType, **kwargs):
#     def get_type(self):
#     def get_arg(self, arg):
#     def get_args(self):
#     def __init__(self, queue):
#     def __post(self, event, delay=0):
#     def status(self, eventType):
#     def scan_start(self, delay=0):
#     def scan_done(self, collars=None, timeStamp=None):
#     def gps_open(self, delay):
#     def gps_location(self, location):
#     def gps_satellites(self, satellites):
#     def gps_error(self, error):
#     def error(self, error):
#     def warning(self, warning):
#     def info(self, info):
# 
# Path: wildfind/harrier/collar.py
# MOD_DESC = ['CW', 'AM']
# 
# Path: wildfind/harrier/receive.py
# class Receive(threading.Thread):
#     def __init__(self, settings, queue):
#         threading.Thread.__init__(self)
#         self.name = 'Receive'
#         self.daemon = True
# 
#         self._settings = settings
#         self._queue = queue
# 
#         self._cancel = False
#         self._receive = False
# 
#         self._sdr = None
#         self._capture = (ctypes.c_ubyte * int(2 * SAMPLE_RATE * SAMPLE_TIME))()
# 
#         self._captureBlock = 0
#         self._timeStamp = None
# 
#         devices = rtlsdr.librtlsdr.rtlsdr_get_device_count()
#         if self._settings.recvIndex >= devices:
#             error = 'Cannot find device at index {}'
#             error = error.format(self._settings.recvIndex)
#             events.Post(self._queue).error(error)
#         else:
#             self.start()
# 
#     def __capture(self, data, _sdr):
#         length = len(data)
#         pos = self._captureBlock * length
#         dst = ctypes.byref(self._capture, pos)
#         ctypes.memmove(dst, data, length * ctypes.sizeof(ctypes.c_ubyte))
# 
#         self._captureBlock += 1
#         if self._captureBlock == BLOCKS:
#             self._sdr.cancel_read_async()
#             self._captureBlock = 0
# 
#     def __receive(self):
#         self._receive = False
# 
#         events.Post(self._queue).status(events.STATUS_CAPTURE)
# 
#         try:
#             if self._sdr is None:
#                 self._sdr = rtlsdr.RtlSdr(device_index=self._settings.recvIndex)
#                 self._sdr.set_sample_rate(SAMPLE_RATE)
#                 self._sdr.set_center_freq(self._settings.freq * 1e6)
#                 time.sleep(1)
#                 self._sdr.set_gain(self._settings.recvGain)
#                 cal = int(self._settings.recvCal)
#                 if cal != 0:
#                     self._sdr.set_freq_correction(cal)
#             self._timeStamp = time.time()
# 
#             self._sdr.read_bytes_async(self.__capture,
#                                        2 * SAMPLE_RATE * SAMPLE_TIME / BLOCKS)
#             if self._cancel:
#                 return
# 
#             events.Post(self._queue).status(events.STATUS_PROCESS)
#             iq = stream_to_complex(self._capture)
#             if self._cancel:
#                 return
# 
#             scan = Scan(SAMPLE_RATE, iq)
#             frequencies = scan.search()
#             if self._cancel:
#                 return
# 
#             detect = Detect(SAMPLE_RATE, iq, frequencies)
#             collars = detect.search(self._settings.freq * 1e6)
# 
#             events.Post(self._queue).status(events.STATUS_IDLE)
#             events.Post(self._queue).scan_done(collars=collars,
#                                                timeStamp=self._timeStamp)
# 
#         except IOError as e:
#             error = 'Capture failed: {}'.format(e.message)
#             events.Post(self._queue).error(error)
# 
#     def run(self):
#         while not self._cancel:
#             if self._receive:
#                 self.__receive()
#             else:
#                 try:
#                     time.sleep(0.1)
#                 except IOError:
#                     pass
# 
#     def receive(self):
#         self._receive = True
# 
#     def stop(self):
#         self._cancel = True
#         if self._sdr is not None:
#             try:
#                 self._sdr.cancel_read_async()
#             except IOError:
#                 pass


# Path: wildfind/harrier/testmode.py
import Queue
import signal
import sys
import time
from math import log10
from wildfind.harrier import events
from wildfind.harrier.collar import MOD_DESC
from wildfind.harrier.receive import Receive

# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#




class TestMode(object):
    def __init__(self, settings):
        print 'Test mode'

        queue = Queue.Queue()

        self._receive = Receive(settings, queue)
        self._signal = signal.signal(signal.SIGINT, self.__close)

        events.Post(queue).scan_start()

        while self._receive.isAlive():
            if not queue.empty():
                self.__process_queue(settings, queue)

        self.__close()

    def __process_queue(self, _settings, queue):
        event = queue.get()
        eventType = event.get_type()


        if eventType == events.SCAN_START: