def take_picture(fn_base):
    planner.hal.settle()
    img_dec = planner.imager.get()
    if not planner.dry:
        if store_bin:
            open(fn_base + '.bin', 'w').write(img_dec.raw)
        if store_png:
            img_dec.save(fn_base + '.png')
    planner.all_imgs += 1

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Planner module command line')
    parser.add_argument('--host', default='mk', help='Host.  Activates remote mode')
    parser.add_argument('--port', default=22617, type=int, help='Host port')
    parser.add_argument('--overwrite', action='store_true')
    add_bool_arg(parser, '--dry', default=True, help='Due to health hazard, default is True')
    add_bool_arg(parser, '--bin', default=False, help='Store raw .bin')
    add_bool_arg(parser, '--png', default=True, help='Store 16 bit .png')
    parser.add_argument('scan_json', nargs='?', default='scan.json', help='Scan parameters JSON')
    parser.add_argument('out', nargs='?', default='out/default', help='Output directory')
    args = parser.parse_args()

    store_bin = args.bin
    store_png = args.png

    if os.path.exists(args.out):
        if not args.overwrite:
            raise Exception("Refusing to overwrite")
        shutil.rmtree(args.out)
    if not args.dry:
        os.mkdir(args.out)
Exemple #2
0
    # Discarded 510 / 512 bytes => 2 bytes
    validate_read("\x85\x00", buff, "packet W: 233/234, R: 235/236")

    # The single packet below can be omitted
    # but anything else causes USB timeout when trying to read
    # Might indicate above is some sort of critical firmware
    # return
    
    # Generated from packet 237/238
    cmd_02(dev, "\x86\x00\xC0\x41\x09\x00", "packet W: 237/238, R: 239/240")

if __name__ == "__main__":
    import argparse 
    
    parser = argparse.ArgumentParser(description='Replay captured USB packets')
    add_bool_arg(parser, '--cycle', default=False, help='') 
    args = parser.parse_args()

    if args.cycle:
        startup.cycle()

    dev, usbcontext = startup.get()
    _bulkRead, bulkWrite, controlRead, controlWrite = usb_wraps(dev)

    replay(dev)
    
    #cmd.bulk86_dbg = 1

    buffs = set()
    i = 0
    while True:
Exemple #3
0
        pid = udev.getProductID()
        if (vid, pid) == (0x14b9, 0x0001):
            print
            print
            print 'Found device'
            print 'Bus %03i Device %03i: ID %04x:%04x' % (
                udev.getBusNumber(), udev.getDeviceAddress(), vid, pid)
            return udev.open()
    raise Exception("Failed to find a device")


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(description='Replay captured USB packets')
    add_bool_arg(parser, '--cycle', default=False, help='')
    add_bool_arg(parser, '--loop', default=False, help='')
    args = parser.parse_args()

    if args.cycle:
        print 'Cycling'
        wps = WPS7(host='raijin')
        wps.cycle([1, 2], t=2.0)
        # 1 second too short
        time.sleep(3)
        print 'Cycled'

    usbcontext = usb1.USBContext()
    dev = open_dev(usbcontext)
    dev.claimInterface(0)
Exemple #4
0
        return img_dec

def take_picture(fn_base):
    planner.hal.settle()
    img_dec = planner.imager.get()
    if not planner.dry:
        open(fn_base + '.bin', 'w').write(img_dec.raw)
        img_dec.save(fn_base + '.png')
    planner.all_imgs += 1

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Planner module command line')
    parser.add_argument('--host', default='mk', help='Host.  Activates remote mode')
    parser.add_argument('--port', default=22617, type=int, help='Host port')
    parser.add_argument('--overwrite', action='store_true')
    add_bool_arg(parser, '--dry', default=True, help='Due to health hazard, default is True')
    parser.add_argument('scan_json', nargs='?', default='scan.json', help='Scan parameters JSON')
    parser.add_argument('out', nargs='?', default='out/default', help='Output directory')
    args = parser.parse_args()

    if os.path.exists(args.out):
        if not args.overwrite:
            raise Exception("Refusing to overwrite")
        shutil.rmtree(args.out)
    if not args.dry:
        os.mkdir(args.out)

    wps = WPS7()
    imager = XrayImager(dry=args.dry)
    #imager = MockImager()
    hal = lcnc_ar.LcncPyHalAr(host=args.host, local_ini='config/xray/rsh.ini', dry=args.dry)
Exemple #5
0
from uvscada import gxs700_util
from uvscada import util

import argparse
import binascii
import os

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Dump device data')
    parser.add_argument('--verbose', '-v', action='store_true', help='verbose')
    util.add_bool_arg(parser, '--eeprom', default=False, help='Dump only EEPROM')
    util.add_bool_arg(parser, '--flash', default=False, help='Dump only flash')
    util.add_bool_arg(parser, '--hexdump', default=False, help='Instead of writing out, just hexdump')
    parser.add_argument('dout', nargs='?', default='dump', help='File out')
    args = parser.parse_args()

    usbcontext, dev, gxs = gxs700_util.ez_open_ex()
    
    if not args.hexdump:
        if not os.path.exists(args.dout):
            os.mkdir(args.dout)
        _t = util.IOLog(out_fn=os.path.join(args.dout, 'out.txt'))

    alll = not (args.eeprom or args.flash)
    
    '''
    FIXME: couldn't get I2C to work
    probably doesn't matter since expect only EEPROM on bus
    
    List of  controlRead(0xC0, 0xB0,...)
    req     uses
Exemple #6
0
from uvscada.bpm import startup, cmd
from uvscada.util import hexdump, add_bool_arg
from uvscada.bpm.i87c51.read import replay

if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(description='Replay captured USB packets')
    add_bool_arg(parser, '--cycle', default=False, help='')
    add_bool_arg(parser, '--cont', default=True, help='Continuity check')
    add_bool_arg(parser,
                 '--freq',
                 default=False,
                 help='Byte frequency distribution')
    parser.add_argument('fout', nargs='?', help='Output file')
    args = parser.parse_args()

    if args.cycle:
        startup.cycle()

    dev, usbcontext = startup.get()

    fw_in = replay(dev, cont=args.cont)
    if args.fout:
        print 'Writing to %s' % args.fout
        open(args.fout, 'w').write(fw_in)
    else:
        hexdump(fw_in, indent='  ', label='Read data')
    print 'Bytes: %d 0x%04X' % (len(fw_in), len(fw_in))

    if args.freq:
Exemple #7
0
from uvscada.bpm import startup, cmd
from uvscada.util import hexdump, add_bool_arg
from uvscada.bpm.i87c51.write import replay

if __name__ == "__main__":
    import argparse 
    
    parser = argparse.ArgumentParser(description='Replay captured USB packets')
    add_bool_arg(parser, '--cycle', default=False, help='') 
    add_bool_arg(parser, '--cont', default=True, help='Continuity check') 
    add_bool_arg(parser, '--blank', default=True, help='Blank check') 
    parser.add_argument('fin', nargs='?', help='Input file') 
    args = parser.parse_args()

    if args.cycle:
        startup.cycle()

    dev, usbcontext = startup.get()

    if args.fin:
        fw = open(args.fin, 'r').read()
    else:
        fw = 4096 * '\xFF'
    if len(fw) != 4096:
        raise Exception("Bad FW length")
    replay(dev, fw, cont=args.cont, blank=args.blank)

    print 'Complete'
Exemple #8
0
from uvscada import gxs700_util
from uvscada import util

import argparse
import binascii
import os

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Dump device data')
    parser.add_argument('--verbose', '-v', action='store_true', help='verbose')
    util.add_bool_arg(parser,
                      '--eeprom',
                      default=False,
                      help='Dump only EEPROM')
    util.add_bool_arg(parser, '--flash', default=False, help='Dump only flash')
    util.add_bool_arg(parser,
                      '--hexdump',
                      default=False,
                      help='Instead of writing out, just hexdump')
    parser.add_argument('dout', nargs='?', default='dump', help='File out')
    args = parser.parse_args()

    usbcontext, dev, gxs = gxs700_util.ez_open_ex()

    if not args.hexdump:
        if not os.path.exists(args.dout):
            os.mkdir(args.dout)
        _t = util.IOLog(out_fn=os.path.join(args.dout, 'out.txt'))

    alll = not (args.eeprom or args.flash)
    '''
Exemple #9
0
from uvscada import gxs700_util
from uvscada import util

import argparse
import binascii
import os

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Dump device data')
    parser.add_argument('--verbose', '-v', action='store_true', help='verbose')
    util.add_bool_arg(parser, '--quick', default=True, help='')
    util.add_bool_arg(parser, '--eeprom', default=False, help='')
    util.add_bool_arg(parser, '--flash', default=False, help='')
    parser.add_argument('din', nargs='?', default='dump', help='File in')
    args = parser.parse_args()

    usbcontext, dev, gxs = gxs700_util.ez_open_ex()

    print 'Ready'
    
    if args.eeprom:
        print
        print 'Writing EEPROM'
        eeprom_w = open(os.path.join(args.din, 'eeprom.bin'), 'r').read()
        if args.quick:
            eeprom_w = eeprom_w[0:0x400]
        gxs.eeprom_w(0x0000, eeprom_w)
        
        print 'Reading back to verify'
        eeprom_r = gxs.eeprom_r()
        if eeprom_w != eeprom_r:
Exemple #10
0
from uvscada.bpm import startup, cmd
from uvscada.util import hexdump, add_bool_arg
from uvscada.bpm.i87c51.read import replay

if __name__ == "__main__":
    import argparse 
    
    parser = argparse.ArgumentParser(description='Replay captured USB packets')
    add_bool_arg(parser, '--cycle', default=False, help='') 
    add_bool_arg(parser, '--cont', default=True, help='Continuity check') 
    add_bool_arg(parser, '--freq', default=False, help='Byte frequency distribution') 
    parser.add_argument('fout', nargs='?', help='Output file') 
    args = parser.parse_args()

    if args.cycle:
        startup.cycle()

    dev, usbcontext = startup.get()

    fw_in = replay(dev, cont=args.cont)
    if args.fout:
        print 'Writing to %s' % args.fout
        open(args.fout, 'w').write(fw_in)
    else:
        hexdump(fw_in, indent='  ', label='Read data')
    print 'Bytes: %d 0x%04X' % (len(fw_in), len(fw_in))
    
    if args.freq:
        freqs = {}
        for b in fw_in:
            freqs[b] = freqs.get(b, 0) + 1
Exemple #11
0
            print '% 3u: %s' % (pin, floats(dn[pin]))
        return 0
    else:
        score_rms = do_score_rms(ln, rn, inf=inf, verbose=verbose)

        # Prefer integers
        #ret = score_rms * 100
        ret = score_rms
        if verbose:
            print 'Score: %0.3f' % ret
        return ret


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Impedance scanner')
    add_bool_arg(parser, '--verbose', default=True, help='')
    add_bool_arg(parser, '--lin', default=False, help='')
    add_bool_arg(parser, '--inf', default=True, help='')
    parser.add_argument('--cmp', default='log', help='')
    parser.add_argument('l', help='')
    parser.add_argument('r', help='')
    args = parser.parse_args()

    ret = score(args.l,
                args.r,
                inf=args.inf,
                verbose=args.verbose,
                cmp=args.cmp)
    if not args.verbose:
        print 'Score: %0.3f' % ret
Exemple #12
0
from uvscada.util import add_bool_arg

import argparse
import zcmp

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Impedance scanner')
    add_bool_arg(parser, '--inf', default=True, help='')
    parser.add_argument('ref', help='')
    parser.add_argument('check', nargs='+', help='')
    args = parser.parse_args()

    results = []
    print 'Ref: %s' % args.ref
    for check in args.check:
        score = zcmp.score(args.ref, check, inf=args.inf, verbose=False)
        results.append((score, check))

    results = sorted(results)
    for score, check in results:
        print '% -60s: %0.3f' % (check, score)

    best_score, best = results[1]
    print
    print 'Best'
    print '% -60s: %0.3f' % (best, best_score)