예제 #1
0
    def __init__(self):
        self.config = configparser.ConfigParser()
        #try:
        self.device = HiSPARCIII('FTKBO7Y')
        if USE_DEVICE2:
            self.device2 = HiSPARCIII('FTL919A')
        self.gps = TrimbleGPS("FT232R USB UART")
        self.initialize_device()

        station_name = self.config.get('DAQ', 'station_name')
        station_number = self.config.getint('DAQ', 'station_number')
        station_password = self.config.get('DAQ', 'station_password')

        self.datastore1 = storage2.CosmicLaserShowStorageManager(DBFILE)
예제 #2
0
파일: test_gps.py 프로젝트: HiSPARC/pysparc
class Main(object):

    def __init__(self):
        # try:
        #     self.device = HiSPARCIII()
        # except DeviceNotFoundError:
        #     self.device = HiSPARCII()
        self.gps = TrimbleGPS()

    def close(self):
        logging.info("Closing down")
        # self.device.close()
        self.gps.close()

    def run(self):
        t0 = t1 = time.time()
        has_reset = False

        # msg = gps_messages.ResetMessage(reset_mode='warm')
        # msg = gps_messages.SetInitialPosition(52, 4, 0)
        # self.gps.send_message(msg)

        try:
            while True:
                if time.time() - t1 > 1:
                    t1 = time.time()
                    self.gps._device.write('\x10\xbb\x00\x10\x03')

                if time.time() - t0 > 5 and has_reset is False:
                    msg = gps_messages.ResetMessage('factory')
                    self.gps.send_message(msg)
                    time.sleep(2.2)
                    msg = gps_messages.SetSurveyParameters(86400)
                    self.gps.send_message(msg)
                    has_reset = True

                msg = self.gps.read_message()
                if msg:
                    print msg
                if type(msg) == gps_messages.SupplementalTimingPacket:
                    print "Survey status: %d%%" % msg.survey_progress
                    print "Lat: %f, Lon: %f, Alt: %f" % (msg.latitude,
                                                         msg.longitude,
                                                         msg.altitude)
        except KeyboardInterrupt:
            logging.info("Keyboard interrupt, shutting down.")

        return self.gps._buffer
예제 #3
0
class Main(object):
    def __init__(self):
        # try:
        #     self.device = HiSPARCIII()
        # except DeviceNotFoundError:
        #     self.device = HiSPARCII()
        self.gps = TrimbleGPS()

    def close(self):
        logging.info("Closing down")
        # self.device.close()
        self.gps.close()

    def run(self):
        t0 = t1 = time.time()
        has_reset = False

        # msg = gps_messages.ResetMessage(reset_mode='warm')
        # msg = gps_messages.SetInitialPosition(52, 4, 0)
        # self.gps.send_message(msg)

        try:
            while True:
                if time.time() - t1 > 1:
                    t1 = time.time()
                    self.gps._device.write('\x10\xbb\x00\x10\x03')

                if time.time() - t0 > 5 and has_reset is False:
                    msg = gps_messages.ResetMessage('factory')
                    self.gps.send_message(msg)
                    time.sleep(2.2)
                    msg = gps_messages.SetSurveyParameters(86400)
                    self.gps.send_message(msg)
                    has_reset = True

                msg = self.gps.read_message()
                if msg:
                    print msg
                if type(msg) == gps_messages.SupplementalTimingPacket:
                    print "Survey status: %d%%" % msg.survey_progress
                    print "Lat: %f, Lon: %f, Alt: %f" % (
                        msg.latitude, msg.longitude, msg.altitude)
        except KeyboardInterrupt:
            logging.info("Keyboard interrupt, shutting down.")

        return self.gps._buffer
예제 #4
0
    def __init__(self):
        self.config = ConfigParser.ConfigParser()
        try:
            self.device = HiSPARCIII()
        except DeviceNotFoundError:
            self.device = HiSPARCII()
        self.gps = TrimbleGPS()
        self.initialize_device()

        station_name = self.config.get('DAQ', 'station_name')
        station_number = self.config.getint('DAQ', 'station_number')
        station_password = self.config.get('DAQ', 'station_password')

        # self.datastore1 = storage.TablesDataStore(DATAFILE)
        self.datastore2 = storage.NikhefDataStore(station_number,
                                                  station_password)
        self.storage_manager = storage.StorageManager()
        # self.storage_manager.add_datastore(self.datastore1, 'queue_file')
        self.storage_manager.add_datastore(self.datastore2, 'queue_nikhef')
        self.monitor = monitor.Monitor(station_name)
예제 #5
0
 def __init__(self):
     # try:
     #     self.device = HiSPARCIII()
     # except DeviceNotFoundError:
     #     self.device = HiSPARCII()
     self.gps = TrimbleGPS()
예제 #6
0
import time

from pysparc.hardware import HiSPARCIII, TrimbleGPS
from pysparc.messages import MeasuredDataMessage, OneSecondMessage
from pysparc.gps_messages import PrimaryTimingPacket


if __name__ == '__main__':
    gps = TrimbleGPS()
    hisparc = HiSPARCIII()

    hisparc.config.ch1_voltage = 900
    hisparc.config.ch1_threshold_low = 1000
    hisparc.config.trigger_condition = 1
    hisparc.config.one_second_enabled = True

    while True:
        msg = hisparc.read_message()
        if type(msg) == MeasuredDataMessage:
            print msg.gps_seconds
        if type(msg) == OneSecondMessage:
            print "ONE:", msg.gps_seconds
        msg = gps.read_message()
        if type(msg) == PrimaryTimingPacket:
            print "GPS:", msg.seconds
예제 #7
0
파일: test_gps.py 프로젝트: HiSPARC/pysparc
 def __init__(self):
     # try:
     #     self.device = HiSPARCIII()
     # except DeviceNotFoundError:
     #     self.device = HiSPARCII()
     self.gps = TrimbleGPS()
예제 #8
0
class Main(object):
    def __init__(self):
        self.config = configparser.ConfigParser()
        #try:
        self.device = HiSPARCIII('FTKBO7Y')
        if USE_DEVICE2:
            self.device2 = HiSPARCIII('FTL919A')
        self.gps = TrimbleGPS("FT232R USB UART")
        self.initialize_device()

        station_name = self.config.get('DAQ', 'station_name')
        station_number = self.config.getint('DAQ', 'station_number')
        station_password = self.config.get('DAQ', 'station_password')

        self.datastore1 = storage2.CosmicLaserShowStorageManager(DBFILE)

        # self.datastore2 = storage.NikhefDataStore(station_number,
        #station_password)
        #self.storage_manager = storage.StorageManager()
        #self.storage_manager.add_datastore(self.datastore1, 'queue_file')
        # self.storage_manager.add_datastore(self.datastore2, 'queue_nikhef')
        #self.monitor = monitor.Monitor(station_name)

    def initialize_device(self):
        logging.info("Reading config from file")
        self.config.read(ALL_CONFIG_FILES)

        logging.info("Initializing device configuration")
        self.device.config.read_config(self.config)
        if USE_DEVICE2:
            self.device2.config.read_config(self.config)

        if self.config.getboolean('DAQ', 'force_reset_gps'):
            logging.info("Force reset GPS to factory defaults.")
            self.gps.reset_defaults()
            self.config.set('DAQ', 'force_reset_gps', 'False')

        if self.config.getboolean('DAQ', 'force_align_adcs'):
            logging.info("Force aligning ADCs.")
            align_adcs = AlignADCs(self.device)
            align_adcs.align()
            #if USE_DEVICE2:
            #align_adcs = AlignADCs(self.device2)
            #align_adcs.align()
            self.config.set('DAQ', 'force_align_adcs', 'False')

        self.write_config()

    def run(self):
        # The first configuration message does not include GPS information.
        # Flush it, and possibly other outdated messages, and request it later.
        self.device.flush_device()
        if USE_DEVICE2:
            self.device2.flush_device()

        stew = Stew()
        stew2 = Stew()
        stews = [stew, stew2]

        logging.info("Taking data.")
        # Give hardware at least 20 seconds to startup
        t_msg = time.time() + 20
        t_log = time.time() - .5
        t_status = time.time()
        t_config = datetime.date(1970, 1, 1)
        try:
            while True:
                t = time.time()
                msg = self.device.read_message()
                device = self.device
                device_id = 0
                if USE_DEVICE2 and msg is None:
                    msg = self.device2.read_message()
                    device = self.device2
                    device_id = 1
                if msg is not None:
                    t_msg = t
                    logging.debug("Data received from {}: {}".format(
                        device_id, msg))
                    if isinstance(msg, messages.MeasuredDataMessage):
                        msg.device_id = device_id
                        stews[device_id].add_event_message(msg)
                    elif isinstance(msg, messages.OneSecondMessage):
                        stews[device_id].add_one_second_message(msg)
                        logging.debug("One-second received from {}: {}".format(
                            device_id, msg.timestamp))
                    elif isinstance(msg, messages.ControlParameterList):
                        config = ConfigEvent(device.config)
                        self.datastore1.store_event(config)
                        t_config = datetime.date.today()
                        logging.info(
                            "Sent configuration message to device {}".format(
                                device_id))
                else:
                    if t - t_msg > 20:
                        logging.warning("Hardware is silent, resetting.")
                        self.device.reset_hardware()
                        self.device2.reset_hardware()
                        if USE_DEVICE2:
                            self.device2.reset_hardware()
                        # Give hardware at least 20 seconds to startup
                        t_msg = t

                if t - t_log >= 1:
                    logging.info("Event rate: %.1f Hz", stew.event_rate())
                    t_log += 1

                    for s in stews:
                        s.stir()
                        events = s.serve_events()
                        self.store_events(events)
                        s.drain()

                # Periodically send status messages to the monitor,
                # currently Nagios, and config messages
                if t - t_status >= 60:
                    t_status += 60
                    #self.monitor.send_uptime()
                    #self.monitor.send_cpu_load()
                    #self.monitor.send_trigger_rate(stew.event_rate())
                    if t_config < datetime.date.today():
                        # update config (set t_config when sent, not here)
                        self.device.send_message(
                            messages.GetControlParameterList())
                        if USE_DEVICE2:
                            self.device2.send_message(
                                messages.GetControlParameterList())

        except KeyboardInterrupt:
            logging.info("Interrupted by user.")

    def store_events(self, events):
        for event in events:
            try:
                self.datastore1.store_event(event)
            except Exception as e:
                logging.error(str(e))
        logging.debug("Stored %d events.", len(events))

    def write_config(self):
        self.device.config.write_config(self.config)
        if USE_DEVICE2:
            self.device2.config.write_config(self.config)
        with open(CONFIGFILE, 'w') as f:
            self.config.write(f)

    def close(self):
        logging.info("Closing down")
        self.device.close()
        if USE_DEVICE2:
            self.device2.close()
        self.datastore1.close()
예제 #9
0
class Main(object):

    def __init__(self):
        self.config = ConfigParser.ConfigParser()
        try:
            self.device = HiSPARCIII()
        except DeviceNotFoundError:
            self.device = HiSPARCII()
        self.gps = TrimbleGPS()
        self.initialize_device()

        station_name = self.config.get('DAQ', 'station_name')
        station_number = self.config.getint('DAQ', 'station_number')
        station_password = self.config.get('DAQ', 'station_password')

        # self.datastore1 = storage.TablesDataStore(DATAFILE)
        self.datastore2 = storage.NikhefDataStore(station_number,
                                                  station_password)
        self.storage_manager = storage.StorageManager()
        # self.storage_manager.add_datastore(self.datastore1, 'queue_file')
        self.storage_manager.add_datastore(self.datastore2, 'queue_nikhef')
        self.monitor = monitor.Monitor(station_name)

    def initialize_device(self):
        logging.info("Reading config from file")
        self.config.read(ALL_CONFIG_FILES)

        logging.info("Initializing device configuration")
        self.device.config.read_config(self.config)

        if self.config.getboolean('DAQ', 'force_reset_gps'):
            logging.info("Force reset GPS to factory defaults.")
            self.gps.reset_defaults()
            self.config.set('DAQ', 'force_reset_gps', False)

        if self.config.getboolean('DAQ', 'force_align_adcs'):
            logging.info("Force aligning ADCs.")
            align_adcs = AlignADCs(self.device)
            align_adcs.align()
            self.config.set('DAQ', 'force_align_adcs', False)

        self.write_config()

    def run(self):
        # The first configuration message does not include GPS information.
        # Flush it, and possibly other outdated messages, and request it later.
        self.device.flush_device()

        stew = Stew()

        logging.info("Taking data.")
        # Give hardware at least 20 seconds to startup
        t_msg = time.time() + 20
        t_log = time.time() - .5
        t_status = time.time()
        t_config = datetime.date(1970, 1, 1)
        try:
            while True:
                t = time.time()
                msg = self.device.read_message()
                if msg is not None:
                    t_msg = t
                    # logging.debug("Data received: %s", msg)
                    if isinstance(msg, messages.MeasuredDataMessage):
                        stew.add_event_message(msg)
                    elif isinstance(msg, messages.OneSecondMessage):
                        stew.add_one_second_message(msg)
                        logging.debug("One-second received: %d", msg.timestamp)
                    elif isinstance(msg, messages.ControlParameterList):
                        config = ConfigEvent(self.device.config)
                        self.storage_manager.store_event(config)
                        t_config = datetime.date.today()
                        logging.info("Sent configuration message.")
                else:
                    if t - t_msg > 20:
                        logging.warning("Hardware is silent, resetting.")
                        self.device.reset_hardware()
                        # Give hardware at least 20 seconds to startup
                        t_msg = t

                if t - t_log >= 1:
                    logging.info("Event rate: %.1f Hz", stew.event_rate())
                    t_log += 1

                    stew.stir()
                    events = stew.serve_events()
                    self.store_events(events)
                    stew.drain()

                # Periodically send status messages to the monitor,
                # currently Nagios, and config messages
                if t - t_status >= 60:
                    t_status += 60
                    self.monitor.send_uptime()
                    self.monitor.send_cpu_load()
                    self.monitor.send_trigger_rate(stew.event_rate())
                    if t_config < datetime.date.today():
                        # update config (set t_config when sent, not here)
                        self.device.send_message(
                            messages.GetControlParameterList())

        except KeyboardInterrupt:
            logging.info("Interrupted by user.")

    def store_events(self, events):
        for event in events:
            try:
                self.storage_manager.store_event(event)
            except Exception as e:
                logging.error(str(e))
        logging.debug("Stored %d events.", len(events))

    def write_config(self):
        self.device.config.write_config(self.config)
        with open(CONFIGFILE, 'w') as f:
            self.config.write(f)

    def close(self):
        logging.info("Closing down")
        self.device.close()
        self.storage_manager.close()
        # self.datastore1.close()
        self.datastore2.close()