コード例 #1
0
        r = r.strip().lower()
        if r in ['a', 'b', 'c', '']:
            if '' == r:
                r = 'b'
            break

    # a numeric code, not in real time unit
    # check the C definitions for the code-to-second mapping
    # internally, logger uses {0,1,2...}
    logging_interval_code = int(ord(r) - ord('a'))

    cool = False
    for i in range(MAX_RETRY):
        ser.write(
            'set_logging_interval{}\n'.format(logging_interval_code).encode())
        c = get_logging_config(ser)
        if c['logging_interval_code'] == logging_interval_code:
            cool = True
            break
    if not cool:
        logging.error('Could not set sampling interval. Terminating.')
        sys.exit()

    if not probably_empty(ser):
        print('(Memory is not clean.)')

    time.sleep(1)
    ser.flushInput()

    while True:
        r = input('Wipe memory? (yes/no; default=yes)')
コード例 #2
0
        print('Looking for logger...')
        if is_logging(ser):
            r = input('Logger is logging. Stop it? (yes/no; default=no)')
            if r.strip().lower() in ['yes']:
                logging.debug('User wants to stop logging.')
                ser.write(b'stop_logging')
            else:
                print('This script cannot proceed while logger is still running. ABORT.')
                sys.exit()

        logger_name = get_logger_name(ser)
        flash_id = get_flash_id(ser)
        vbatt = read_vbatt(ser)
        rtc = read_rtc(ser)
        config = get_logging_config(ser)
        logging_start_time = config['logging_start_time']
        sample_interval_second = SAMPLE_INTERVAL_CODE_MAP[config['logging_interval_code']]

        print('Logger "{}" (ID={})'.format(logger_name, flash_id))
        print('Battery voltage {:.1f} V, clock {}'.format(vbatt, ts2dt(rtc)))
        print('Scanning logger memory...', end='', flush=True)
        sample_count = get_sample_count(ser)
        if 0 == sample_count:
            print(' Logger is empty. Terminating.')
            sys.exit()

        number_to_read = min(DOWNSAMPLE_N, sample_count)
        STRIDE = int(sample_count // number_to_read)
        m = '{} in steps of {}'.format(number_to_read, STRIDE) if STRIDE > 1 else 'everything'
        print(' {} sample(s) in memory.\r\nRequested {} sample(s); will read {}.'.\
コード例 #3
0
        try:
            logger_name = get_logger_name(ser)
            print('Name: {}'.format(logger_name))
            flash_id = get_flash_id(ser)
            print('ID: {}'.format(flash_id))
        except InvalidResponseException:
            print('Cannot read logger name/ID. Terminating.')
            sys.exit()

        #if '' == name:
        #    name = 'noname'
        #makedirs(join('data', flash_id + ' ({})'.format(logger_name)), exist_ok=True)
        makedirs(join('data', flash_id), exist_ok=True)

        # store meta data to config file
        metadata = get_logging_config(ser)
        logging.debug(metadata)

        configfilename = '{}_{}.config'.format(flash_id, metadata['logging_start_time'])
        configfilename = join('data', flash_id, configfilename)
        config = {}
        if exists(configfilename):
            config = json.loads(open(configfilename).read())
        else:
            logging.warning('No existing config file.')
        config['logger_name'] = logger_name
        config['flash_id'] = flash_id
        config['logging_start_time'] = metadata['logging_start_time']
        config['logging_stop_time'] = metadata['logging_stop_time']
        config['logging_interval_code'] = metadata['logging_interval_code']
        if stop_logging_time is not None: