# Path: rtlsdr_scanner/constants.py
# class Display(object):
#     PLOT, SPECT, SURFACE, STATUS, TIMELINE, PREVIEW = range(6)
# 
# class Mode(object):
#     SINGLE, CONTIN, MAX = range(3)
# 
# class PlotFunc(object):
#     NONE, AVG, MIN, MAX, VAR, SMOOTH, DIFF, DELTA = range(8)
# 
# Path: rtlsdr_scanner/devices.py
# class DeviceRTL(object):
#     def __init__(self):
#         self.isDevice = True
#         self.indexRtl = None
#         self.name = None
#         self.serial = ''
#         self.server = 'localhost'
#         self.port = 1234
#         self.gains = []
#         self.gain = 0
#         self.calibration = 0
#         self.lo = 0
#         self.offset = 250e3
#         self.tuner = 0
#         self.levelOff = 0
# 
#     def set(self, device):
#         self.gain = device.gain
#         self.calibration = device.calibration
#         self.lo = device.lo
#         self.offset = device.offset
#         self.tuner = device.tuner
#         self.levelOff = device.levelOff
# 
#     def get_gains_str(self):
#         gainsStr = []
#         for gain in self.gains:
#             gainsStr.append(str(gain))
# 
#         return gainsStr
# 
#     def get_closest_gain_str(self, desired):
#         gain = min(self.gains, key=lambda n: abs(n - desired))
# 
#         return str(gain)
# 
# def format_device_rtl_name(name):
#     remove = ["/", "\\"]
#     for char in remove:
#         name = name.replace(char, " ")
# 
#     return name
# 
# class DeviceGPS(object):
#     NMEA_SERIAL, GPSD, GPSD_OLD, NMEA_TCP = range(4)
#     TYPE = ['NMEA (Serial)', 'GPSd', 'GPSd (Legacy)', 'NMEA (Server)']
#     BYTES = [serial.FIVEBITS, serial.SIXBITS, serial.SEVENBITS,
#              serial.EIGHTBITS]
#     PARITIES = [serial.PARITY_NONE, serial.PARITY_EVEN, serial.PARITY_ODD,
#                 serial.PARITY_MARK, serial.PARITY_SPACE]
#     STOPS = [serial.STOPBITS_ONE, serial.STOPBITS_ONE_POINT_FIVE,
#              serial.STOPBITS_TWO]
# 
#     def __init__(self):
#         self.name = 'GPS'
#         self.type = self.GPSD
#         self.resource = 'localhost:2947'
#         self.baud = 115200
#         self.bytes = serial.EIGHTBITS
#         self.parity = serial.PARITY_NONE
#         self.stops = serial.STOPBITS_ONE
#         self.soft = False
# 
#     def get_bauds(self):
#         if self.type == DeviceGPS.NMEA_SERIAL:
#             return serial.Serial.BAUDRATES
# 
#         return None
# 
#     def get_serial_desc(self):
#         port = self.resource.split('/')
#         return '{} {}-{}{}{:g}'.format(port[0], self.baud, self.bytes,
#                                        self.parity, self.stops)
# 
#     def get_desc(self):
#         if self.type == DeviceGPS.NMEA_SERIAL:
#             return self.get_serial_desc()
# 
#         return self.resource


import ConfigParser
import wx
from rtlsdr_scanner.constants import Display, Mode, PlotFunc
from rtlsdr_scanner.devices import DeviceRTL, format_device_rtl_name, DeviceGPS

    def __check_conf_serial(self, device):
        if device.type not in range(len(DeviceGPS.TYPE)):
            return 'Type "{}" should be between 0 and {}'.format(device.type,
                                                                 len(DeviceGPS.TYPE) - 1)

        if device.type == 0:
            if device.baud not in device.get_bauds():
                return 'Baud "{}" should be one of:\n  {}'.format(device.baud,
                                                                  device.get_bauds())
            if device.bytes not in DeviceGPS.BYTES:
                return 'Bits "{}" should be one of:\n  {}'.format(device.bytes,
                                                                  DeviceGPS.BYTES)
            if device.parity not in DeviceGPS.PARITIES:
                return 'Parity "{}" should be one of:\n  {}'.format(device.parity,
                                                                    DeviceGPS.PARITIES)
            if device.stops not in DeviceGPS.STOPS:
                return 'Stops "{}" should be one of:\n  {}'.format(device.stops,
                                                                   DeviceGPS.STOPS)

    def load_conf(self, filename):
        config = ConfigParser.SafeConfigParser()
        try:
            config.read(filename)
            sections = config.sections()
            if len(sections):
                device = DeviceGPS()
                device.name = sections[0]
                device.type = config.getint(sections[0], 'type')
                device.resource = config.get(sections[0], 'resource')

# Path: rtlsdr_scanner/constants.py
# class Display(object):
#     PLOT, SPECT, SURFACE, STATUS, TIMELINE, PREVIEW = range(6)
# 
# class Mode(object):
#     SINGLE, CONTIN, MAX = range(3)
# 
# class PlotFunc(object):
#     NONE, AVG, MIN, MAX, VAR, SMOOTH, DIFF, DELTA = range(8)
# 
# Path: rtlsdr_scanner/devices.py
# class DeviceRTL(object):
#     def __init__(self):
#         self.isDevice = True
#         self.indexRtl = None
#         self.name = None
#         self.serial = ''
#         self.server = 'localhost'
#         self.port = 1234
#         self.gains = []
#         self.gain = 0
#         self.calibration = 0
#         self.lo = 0
#         self.offset = 250e3
#         self.tuner = 0
#         self.levelOff = 0
# 
#     def set(self, device):
#         self.gain = device.gain
#         self.calibration = device.calibration
#         self.lo = device.lo
#         self.offset = device.offset
#         self.tuner = device.tuner
#         self.levelOff = device.levelOff
# 
#     def get_gains_str(self):
#         gainsStr = []
#         for gain in self.gains:
#             gainsStr.append(str(gain))
# 
#         return gainsStr
# 
#     def get_closest_gain_str(self, desired):
#         gain = min(self.gains, key=lambda n: abs(n - desired))
# 
#         return str(gain)
# 
# def format_device_rtl_name(name):
#     remove = ["/", "\\"]
#     for char in remove:
#         name = name.replace(char, " ")
# 
#     return name
# 
# class DeviceGPS(object):
#     NMEA_SERIAL, GPSD, GPSD_OLD, NMEA_TCP = range(4)
#     TYPE = ['NMEA (Serial)', 'GPSd', 'GPSd (Legacy)', 'NMEA (Server)']
#     BYTES = [serial.FIVEBITS, serial.SIXBITS, serial.SEVENBITS,
#              serial.EIGHTBITS]
#     PARITIES = [serial.PARITY_NONE, serial.PARITY_EVEN, serial.PARITY_ODD,
#                 serial.PARITY_MARK, serial.PARITY_SPACE]
#     STOPS = [serial.STOPBITS_ONE, serial.STOPBITS_ONE_POINT_FIVE,
#              serial.STOPBITS_TWO]
# 
#     def __init__(self):
#         self.name = 'GPS'
#         self.type = self.GPSD
#         self.resource = 'localhost:2947'
#         self.baud = 115200
#         self.bytes = serial.EIGHTBITS
#         self.parity = serial.PARITY_NONE
#         self.stops = serial.STOPBITS_ONE
#         self.soft = False
# 
#     def get_bauds(self):
#         if self.type == DeviceGPS.NMEA_SERIAL:
#             return serial.Serial.BAUDRATES
# 
#         return None
# 
#     def get_serial_desc(self):
#         port = self.resource.split('/')
#         return '{} {}-{}{}{:g}'.format(port[0], self.baud, self.bytes,
#                                        self.parity, self.stops)
# 
#     def get_desc(self):
#         if self.type == DeviceGPS.NMEA_SERIAL:
#             return self.get_serial_desc()
# 
#         return self.resource


# Path: rtlsdr_scanner/settings.py
import ConfigParser
import wx
from rtlsdr_scanner.constants import Display, Mode, PlotFunc
from rtlsdr_scanner.devices import DeviceRTL, format_device_rtl_name, DeviceGPS


    def __check_conf_serial(self, device):
        if device.type not in range(len(DeviceGPS.TYPE)):
            return 'Type "{}" should be between 0 and {}'.format(device.type,
                                                                 len(DeviceGPS.TYPE) - 1)

        if device.type == 0:
            if device.baud not in device.get_bauds():
                return 'Baud "{}" should be one of:\n  {}'.format(device.baud,
                                                                  device.get_bauds())
            if device.bytes not in DeviceGPS.BYTES:
                return 'Bits "{}" should be one of:\n  {}'.format(device.bytes,
                                                                  DeviceGPS.BYTES)
            if device.parity not in DeviceGPS.PARITIES:
                return 'Parity "{}" should be one of:\n  {}'.format(device.parity,
                                                                    DeviceGPS.PARITIES)
            if device.stops not in DeviceGPS.STOPS:
                return 'Stops "{}" should be one of:\n  {}'.format(device.stops,
                                                                   DeviceGPS.STOPS)

    def load_conf(self, filename):
        config = ConfigParser.SafeConfigParser()
        try:
            config.read(filename)
            sections = config.sections()
            if len(sections):
                device = DeviceGPS()
                device.name = sections[0]
                device.type = config.getint(sections[0], 'type')
                device.resource = config.get(sections[0], 'resource')

                if device.type == DeviceGPS.NMEA_SERIAL: