Ejemplo n.º 1
0
def gen_logs(fn, progt=5.0, limit=None, verbose=False, convert=True):
    tprint = time.time()
    errs = 0
    for itr, l in enumerate(open(fn)):
        if limit and not limit(itr):
            continue

        if time.time() - tprint > progt:
            print '%d' % itr
            tprint = time.time()
        l = l.strip()
        if not l:
            continue
        try:
            j = json.loads(l)
        except:
            # Truncated record?
            if itr > 1:
                continue
            raise
        raw = binascii.unhexlify(j['data'])

        try:
            dec = parse(raw, convert=convert)
        except ValueError as e:
            # Lots of CRC errors
            # Ocassional sequence errors
            if verbose:
                print 'WARNING: %s bad packet: %s' % (itr, e)
            errs += 1
            continue
        except Exception:
            print itr
            raise

        yield (j['t'], dec)
    if verbose:
        print '%d packet errors' % errs
Ejemplo n.º 2
0
def gen_logs(fn, progt=5.0, limit=None, verbose=False, convert=True):
    tprint = time.time()
    errs = 0
    for itr, l in enumerate(open(fn)):
        if limit and not limit(itr):
            continue

        if time.time() - tprint > progt:
            print "%d" % itr
            tprint = time.time()
        l = l.strip()
        if not l:
            continue
        try:
            j = json.loads(l)
        except:
            # Truncated record?
            if itr > 1:
                continue
            raise
        raw = binascii.unhexlify(j["data"])

        try:
            dec = parse(raw, convert=convert)
        except ValueError as e:
            # Lots of CRC errors
            # Ocassional sequence errors
            if verbose:
                print "WARNING: %s bad packet: %s" % (itr, e)
            errs += 1
            continue
        except Exception:
            print itr
            raise

        yield (j["t"], dec)
    if verbose:
        print "%d packet errors" % errs
Ejemplo n.º 3
0
    while True:
        try:
            retb = pp.getb()
        except Exception as e:
            print 'WARNING: failure'
            traceback.print_exc()
            continue

        # 1 day charging => 24 * 60 * 60 =              86400
        # 3 month charging => 3 * 30 * 24 * 60 * 60 = 7776000
        # eh do 6 digit, mostly expect few days max
        with open(os.path.join('log', 'l%06d.bin' % itr), 'w') as f:
            f.write(retb)
        fj.write(json.dumps({'t': time.time(), 'i': itr}) + '\n')
        fj.flush()

        try:
            retd = parse(retb)
        except Exception as e:
            print 'WARNING: failure'
            traceback.print_exc()
            continue

        print '%s: I: % 4dmV, OM: %d, OS: %d, CN: %d, O: % 4dmV @ % 4dmA' % (
            datetime.datetime.now().isoformat(), retd['Input Voltage[1]'],
            retd['Operation Mode[1]'], retd['Operation Status[1]'],
            retd['Cycle Number[1]'], retd['Output Voltage[1]'],
            retd['Output Current[1]'])
        time.sleep(1)
        itr += 1
Ejemplo n.º 4
0
    
    pp = PPro(port=args.port)
    itr = 0
    fj = open(args.outf, 'w')
    while True:
        try:
            retb = pp.getb()
        except Exception as e:
            print 'WARNING: failure'
            traceback.print_exc()
            continue

        fj.write(json.dumps({'t': time.time(), 'i': itr, 'data': binascii.hexlify(retb)}) + '\n')
        fj.flush()

        try:
            retd = parse(retb)
        except Exception as e:
            print 'WARNING: failure'
            traceback.print_exc()
            continue
        
        #ppprint(retd)
        print '%s: I: % 4dmV, OM: % 6s, OS: % 6s, CN: % 6s, O: % 4dmV @ % 4dmA' % (
                datetime.datetime.now().isoformat(),
                retd['Input Voltage[1]'],
                retd['Operation Mode[1]'], retd['Operation Status[1]'], retd['Cycle Number[1]'],
                retd['Output Voltage[1]'], retd['Output Current[1]'])
        time.sleep(1)
        itr += 1