Ejemplo n.º 1
0
    def __init__(self, refresh=1, loginstance=None, polling=False):
        # Initialise the object and create the device driver
        threading.Thread.__init__(
            self)  # initialise the thread for automatic monitoring
        self.refresh = refresh
        self.polling = polling
        self.alive = False  # Set to false to permanently stop the thread that automatic monitors for received commands
        self.paused = False  # Set to True to temporarily stop automatic monitoring of receive commands
        self.initialised = False  # True when the device has been opened and the driver initialised successfully
        self.device = False  # USB device class instance
        self.receivequeue = []  # Queue of commands received automatically
        self.receivequeuecount = 0  # Number of items in the receive queue
        self.protocol = {
        }  # Dict containing the communications protocol for the CM19a

        # Set up logging
        if loginstance:
            self.log = loginstance
        else:
            # No logger instance provided so create one
            import logger
            self.log = logger.start_logging("CM19a_X10_USB", "./CM19a.log")

        # Find the correct USB device
        self.USB_device = USBdevice(self.VENDOR_ID, self.PRODUCT_ID)
        # save the USB instance that points to the CM19a
        self.device = self.USB_device.device
        if not self.device:
            print >> sys.stderr, "The CM19a is probably not plugged in or is being controlled by another USB driver."
            self.log.error(
                'The CM19a is probably not plugged in or is being controlled by another USB driver.'
            )
            return

        # Open the device for send/receive
        if not self._open_device():
            # Device was not opened successfully
            return

        self.print_device_info()

        # Load the communications protocol
        self._load_protocol()

        # Initialise the device to read the remote controls
        self._initialise_remotes()

        # Start the thread for automatically polling for inbound commands
        # If you just send commands via the CM19a and do not need to check for incoming commands from a remote control
        # then set 'start' to False when the class instance is created
        if self.polling:
            self.start()
Ejemplo n.º 2
0
    def __init__(self, refresh=1, loginstance=None, polling=False):
        # Initialise the object and create the device driver
        threading.Thread.__init__(self)     # initialise the thread for automatic monitoring
        self.refresh = refresh
        self.polling = polling
        self.alive = False                  # Set to false to permanently stop the thread that automatic monitors for received commands
        self.paused = False                 # Set to True to temporarily stop automatic monitoring of receive commands
        self.initialised = False            # True when the device has been opened and the driver initialised successfully
        self.device = False                 # USB device class instance
        self.receivequeue = []              # Queue of commands received automatically
        self.receivequeuecount = 0          # Number of items in the receive queue
        self.protocol = {}                  # Dict containing the communications protocol for the CM19a

        # Set up logging
        if loginstance:
            self.log = loginstance
        else:
            # No logger instance provided so create one
            import logger
            self.log = logger.start_logging("CM19a_X10_USB", "/tmp/CM19a.log")

        # Find the correct USB device
        self.USB_device = USBdevice(self.VENDOR_ID, self.PRODUCT_ID)
        # save the USB instance that points to the CM19a
        self.device = self.USB_device.device
        if not self.device:
            print >> sys.stderr, "The CM19a is probably not plugged in or is being controlled by another USB driver."
            self.log.error('The CM19a is probably not plugged in or is being controlled by another USB driver.')
            return

        # Open the device for send/receive
        if not self._open_device():
            # Device was not opened successfully
            return

        self.print_device_info()

        # Load the communications protocol
        self._load_protocol()

        # Initialise the device to read the remote controls
        self._initialise_remotes()

        # Start the thread for automatically polling for inbound commands
        # If you just send commands via the CM19a and do not need to check for incoming commands from a remote control
        # then set 'start' to False when the class instance is created
        if self.polling:
            self.start()
Ejemplo n.º 3
0
def startLogging(progname="CM19a_X10_USB", logfile='./cm19a.log'):
    return logger.start_logging(progname, logfile)
Ejemplo n.º 4
0
def startLogging(progname="CM19a_X10_USB", logfile='./cm19a.log'):
    return logger.start_logging(progname, logfile)
Ejemplo n.º 5
0
Created on Fri Oct 13 21:04:17 2017

@author: AK
"""
import os

import astropy.io.fits as pf
import skimage as ski
import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt

from logger import start_logging


logger = start_logging('debug', fmt='')

def check_params(mfiles):
    """
    Check that all the files have the same params
    Input: mfiles -- iterable of filenames to stack
    """
    for mfile in mfiles:
        if not os.path.exists(mfile):
            logger.error('No such file: {}'.format(mfile))
#        par =




Ejemplo n.º 6
0
    def __init__(self,
                 input_file,
                 title,
                 measurements,
                 graphics=False,
                 log=False):
        """
        Main container

        :param input_file: file with structural data
        :param title: title of the project
        :param measurements: list of measured degree of freedoms, like ['12X', '15Z']
        :param graphics: switch for GUI
        :param log: switch for saving logs
        """
        self.options = {'graphics': graphics, 'log': log}

        setup_folder('results')
        setup_folder('logs')

        # Labeling object
        if title != '':
            self.title = title
        else:
            self.title = input_file.replace('.str', '')

        # Initializing logger
        self.logger = start_logging(file=self.options['log'], label=self.title)

        self.logger.info(
            '*******************************************************')
        self.logger.info('              STARTING TRUSS UPDATER')
        self.logger.info('Structure: %s' % self.title)
        self.logger.info('Input:     %s' % input_file)
        self.logger.info('Measured nodes: %s' % str(measurements))
        self.logger.info(
            '*******************************************************\n')

        # Reading structural data, boundaries and loads
        (node_list, element_list, boundaries) = read_structure_file(input_file)

        # Setting up basic structure
        self.original = StructuralData(node_list, element_list)

        # Setting up boundaries
        self.boundaries = Boundaries(boundaries)

        # Setting up loads
        self.loads = Loads({'forces': [[25, -9.8]]})

        # Setup Input
        self.measurement = ArduinoMeasurements(measurements)
        self.logger.debug("Calibration is mocked: set to 0")

        # Initiating updated structure
        self.updated = deepcopy(self.original)

        if self.options['graphics']:
            self.fig = plt.figure()
            if self.dof() == 2:
                self.ax = self.fig.add_subplot(111)
            else:
                self.ax = self.fig.add_subplot(111, projection='3d')

            # plt.axis('equal')

            self.fig.canvas.draw()
            plt.show(block=False)
Ejemplo n.º 7
0
import flask
import os
import qrcode
import logger
import io
import time
import secrets
from threading import Thread
from server import Server

app = flask.Flask(__name__)
app.debug = False
app.secret_key = os.urandom(24)

app_logger = logger.start_logging("root")
s = Server(app_logger)

token = ""


class User:
    def __init__(self, id, username, password):
        self.id = id
        self.username = username
        self.password = password
        self.qr_codes = []


users = []
users.append(User(id=1, username='******', password='******'))
users.append(User(id=2, username='******', password='******'))