Beispiel #1
0
 def CreateDefaultStructure(self):
     
     success = True
     
     # first check if there's a config file... load it
     if coreUtils.IsAccessible(self.stdConfig['cfg']):
         self.cfgStatus['cfg'] = self.ReadConfigFile()
         success = self.cfgStatus['cfg']
         
     # no config found...create standard
     else:
         # first check if directory exists
         if coreUtils.SafeMakeDir(self.stdConfig['cfg']):
             self.cfgStatus['cfg'] = coreUtils.DumpJsonFile(self.stdConfig, self.stdConfig['cfg'])
         else:
             success = False
     
     # check for log folder and permission
     # create if not exists
     if coreUtils.IsAccessible('./log/', 'write'):
         self.cfgStatus['lfl'] = True
     else:
         success = False
         
     # if stream folder does not exist, try to create
     if not coreUtils.IsAccessible(self.stdConfig['stf'], 'write'):
         if coreUtils.SafeMakeDir(self.stdConfig['stf']):
             self.cfgStatus['stf'] = True
         else:
             success = False
                 
     return success
Beispiel #2
0
    def StartPoll(self, sF=None):

        success = True
        useGivenStreamFolder = False

        # check if stream folder was given
        if sF:
            if coreUtils.IsAccessible(sF, 'write'):
                self._streamFolder = sF
                useGivenStreamFolder = True

            # if not, try to create new folders
        if not sF or not useGivenStreamFolder:
            sF = self._baseStreamFolder
            if coreUtils.SafeMakeDir(sF, self):
                sF += '/session_' + self.coreStartTime + '/'
                if coreUtils.SafeMakeDir(sF, self):
                    sF += 'stream%04d/' % self.strmFldrCnt
                    if coreUtils.SafeMakeDir(sF, self):
                        # set new stream folder to class var
                        self._streamFolder = sF
                        # increment folder counter for multiple streams
                        self._strmFldrCnt += 1
                    else:
                        success = False

        if success:

            # initialize new thread
            self._pollThread = threading.Thread(target=self._PollData)
            # once polling thread is started loop is running till StopPoll() was called
            self._poll = True
            # start parallel thread
            self._pollThread.start()

            self._recordString = 'Recording...'

        return success
Beispiel #3
0
    def __init__(self,
                 baseStreamFolder='./mat_files',
                 storageMode='fileSize',
                 **flags):

        # store chosen device name here
        self.deviceName = None

        # dictionary to store all demodulator results
        self._demods = {}

        # to stop measurement
        # initially no measurement is running
        self._poll = False
        self._pollThread = None
        # create locker to savely run parallel threads
        self._pollLocker = threading.Lock()

        # not know so far, cause no device is connected
        self._recordingDevices = ''

        self._recordString = 'Stopped.'

        # flags if somethign during recording went wrong
        self._recordFlags = {'dataloss': False, 'invalidtimestamp': False}

        # variables to count streams (folder + files)
        self._baseStreamFolder = baseStreamFolder
        self._streamFolder = baseStreamFolder
        self._strmFlCnt = 0
        self._strmFldrCnt = 0

        # check if folder is available, if not create
        coreUtils.SafeMakeDir(self._baseStreamFolder, self)

        if storageMode in self.__storageModes__:
            self._storageMode = storageMode
        else:
            raise Exception('Unsupported storage mode: %s' % storageMode)

        flags['detCallback'] = self.DetectDeviceAndSetupPort

        CoreDevice.__init__(self, **flags)
Beispiel #4
0
    def __init__(self,
                 logToFile=False,
                 logFile=None,
                 logLevel=None,
                 startTime=None):

        self._logFile = logFile
        self._logToFile = logToFile
        self._caller = self.__class__.__name__  # use parent name for logger init
        self._logLevel = logLevel if logLevel else log.DEBUG
        self._startTime = startTime if startTime else coreUtils.GetDateTimeAsString(
        )

        # write anyway to file
        if self._logFile:
            self._logToFile = True
        # do we need to create a new name?
        elif self._logToFile:
            self._logFile = 'session_' + self._startTime + '.log'

        # initialize logger
        # create logger with callers name
        self.logger = log.getLogger(self._caller)
        self.logger.setLevel(self._logLevel)

        # create formatter
        formatter = log.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
            datefmt='%m/%d/%Y %I:%M:%S %p')

        # create file handler and set level to debug
        # all messages higher in priority are written to file
        if self._logToFile:

            # create folder, if necessary and store result
            # if something went wrong, use command prompt
            self._logToFile = coreUtils.SafeMakeDir('./log/')

            # folder should exist
            # if something went wrong before it's still save to try
            # two errors will be visible
            if not coreUtils.IsAccessible('./log/' + logFile, 'write'):
                # write file
                # later on used by logger
                # -> close immediately
                try:
                    open('./log/' + logFile, 'wt').close()
                except PermissionError:
                    print(
                        'ERROR: Could not create log file!\nCheck permission...'
                    )
                    self._logToFile = False

            # create handler for writing logs to file
            ch = log.FileHandler('./log/' + logFile)
            ch.setLevel(log.DEBUG)

        # or just write them to prompt
        else:
            ch = log.StreamHandler()
            ch.setLevel(log.DEBUG)

        # add formatter to ch
        ch.setFormatter(formatter)

        # add ch to logger
        # apparently Spyder messes up, so let's check if something is already there
        if self.logger.handlers == []:
            self.logger.addHandler(ch)