Example #1
0
def setLMHOptions(device, lp, highgain, ladder, disaux):
    #Assemble the 2 data bytes
    datahigh = 0 | ((disaux & 0x01) << 2) | ((lp & 0x04) >> 2)
    datalow = ((lp & 0x03) << 6) | ((highgain & 0x01) << 4) | (ladder & 0x0F)
    bp = RAW_WIRE(device, 115200)
    print "Current LMH options:"
    readLMHOptions(bp)
    print "-------------------"

    #Send
    #bp.BBmode()
    #bp.enter_rawwire()
    #bp.raw_cfg_pins(PinCfg.CS)
    #if not bp.cfg_raw_wire((RAW_WIRECfg.BIT_ORDER & RAW_WIRE_BIT_ORDER_TYPE.MSB) |
    #                       (RAW_WIRECfg.WIRES & RAW_WIRE_WIRES_TYPE.TWO) |
    #                       (RAW_WIRECfg.OUT_TYPE & RAW_WIRE_OUT_TYPE._3V3)):
    #  raise IOError, "Failed to set pin type correctly"
    #bp.set_speed(RAW_WIRESpeed._400KHZ)
    #bp.CS_Low()
    #bp.bulk_trans(3, [0x00, datahigh, datalow])
    #bp.CS_High()
    #bp.resetBP()

    print "New LMH options:"
    readLMHOptions(bp)
    print "-------------------"
Example #2
0
def main():
    # First of all parse the command line

    parser = OptionParser()

    parser.add_option("-c",
                      "--capacity",
                      dest="capacity",
                      help="size of the memory chip.",
                      type="int")
    parser.add_option("-o",
                      "--org",
                      dest="org",
                      help="specify the memory organization mode (8 or 16).",
                      type="int")
    parser.add_option(
        "-a",
        "--addr",
        dest="addr",
        help="set the starting offset of the read or write procedure.",
        type="int",
        default=0)
    parser.add_option("-n",
                      "--number",
                      dest="n",
                      help="the number of data elements to read or write.",
                      type="int",
                      default=0)
    parser.add_option("-f",
                      "--file",
                      dest="file",
                      help="the input or output file.",
                      metavar="FILE")
    parser.add_option("-r",
                      "--read",
                      dest="action",
                      help="read the memory chip.",
                      default="read")
    parser.add_option("-w",
                      "--write",
                      dest="action",
                      help="write to the memory chip.")
    parser.add_option(
        "-d",
        "--device",
        dest="device",
        help="serial interface where bus pirate is in.[/dev/bus_pirate]",
        default="/dev/bus_pirate")
    parser.add_option("-v",
                      "--verbose",
                      dest="verbose",
                      help="don't be quiet.",
                      action="store_true")
    parser.add_option("-m",
                      "--more",
                      dest="more",
                      help="only for testing: read more data elements",
                      type="int",
                      default=0)

    (options, args) = parser.parse_args()

    if (not options.capacity) or (not options.org) or (not options.file):
        parser.print_help()
        exit()

    # Create an instance of the RAW_WIRE class as we are using the BitBang/RAW_WIRE mode
    #rw = RAW_WIRE( '/dev/bus_pirate', 115200 )
    rw = RAW_WIRE(options.device, 115200)

    if not rw.BBmode():
        print "Can't enter into BitBang mode."
        exit()

    # We have succesfully activated the BitBang Mode, so we continue with
    # the raw-wire mode.
    if not rw.enter_rawwire():
        print "Can't enable the raw-wire mode."
        exit()

    # Now we have raw-wire mode enabled, so first configure peripherals
    # (Power, PullUps, AUX, CS)

    if not rw.raw_cfg_pins(PinCfg.POWER | PinCfg.CS):
        print "Error enabling the internal voltage regulators."

    # Configure the raw-wire mode

    if not rw.cfg_raw_wire((RAW_WIRECfg.BIT_ORDER
                            & RAW_WIRE_BIT_ORDER_TYPE.MSB)
                           | (RAW_WIRECfg.WIRES & RAW_WIRE_WIRES_TYPE.THREE)
                           | (RAW_WIRECfg.OUT_TYPE & RAW_WIRE_OUT_TYPE._3V3)):
        print "Error configuring the raw-wire mode."

    # Set raw-wire speed

    if not rw.set_speed(RAW_WIRESpeed._5KHZ):
        print "Error setting raw-wire speed."

    # Open the file for reading or writting

    if options.action == "read":
        f = file(options.file, "wb")
    else:
        f = file(options.file, "rb")

    # How many elements to read or write?

    if options.n != 0:
        N = options.n + options.more
    else:
        N = options.capacity / options.org + options.more

    # Opcodes for microwire memory devices
    #
    #                Op             Address                 Data
    #Instruction SB Code        x8         x16          x8          x16     Comments
    #   READ     1   10     A8 – A0     A7 – A0                             Reads data stored in memory, at specified address
    #   EWEN     1   00    11XXXXXXX    11XXXXXX                            Write enable must precede all programming modes
    #
    # ....
    #

    if options.action == "read":
        # Enable the Chip select signal
        rw.CS_High()

        rw.bulk_trans(1, [0x6])

        rw.bulk_trans(1, [0x0])

        # and read the items

        if options.verbose:
            print "Reading %d elements of %d bits" % (N, options.org)

        if options.org == 8:
            for i in range(0, N):
                byte = rw.read_byte()
                f.write(byte)

                if options.verbose:
                    print "%02X" % (ord(byte), ),

        else:
            for i in range(0, N):
                byte = rw.read_byte()
                f.write(byte)

                if options.verbose:
                    print "%02X" % (ord(byte), ),

                byte = rw.read_byte()
                f.write(byte)

                if options.verbose:
                    print "%02X" % (ord(byte), ),

        f.close()

        rw.CS_Low()

        print "Done."

    # Reset the bus pirate
    rw.resetBP()
def main():
    # First of all parse the command line

    parser = OptionParser()

    parser.add_option(
        "-d",
        "--device",
        dest="device",
        help="serial interface where bus pirate is in.[/dev/bus_pirate]",
        default="/dev/bus_pirate")
    parser.add_option("-t",
                      "--temperature",
                      action="store_true",
                      dest="temperature",
                      help="get temperature from sht.",
                      default=False)
    parser.add_option("-H",
                      "--humidity",
                      dest="humidity",
                      action="store_true",
                      help="get humidity from sht.",
                      default=False)
    parser.add_option("-v",
                      "--verbose",
                      dest="verbose",
                      help="don't be quiet.",
                      action="store_true")

    (options, args) = parser.parse_args()

    if not (options.temperature or options.humidity):
        parser.print_help()
        exit()

    # Create an instance of the RAW_WIRE class as we are using the BitBang/RAW_WIRE mode
    rw = RAW_WIRE(options.device, 115200)

    if not rw.BBmode():
        print "Can't enter into BitBang mode."
        exit()

    # We have succesfully activated the BitBang Mode, so we continue with
    # the raw-wire mode.
    if not rw.enter_rawwire():
        print "Can't enable the raw-wire mode."
        exit()

    # Now we have raw-wire mode enabled, so first configure peripherals
    # (Power, PullUps, AUX, CS)

    if not rw.raw_cfg_pins(PinCfg.POWER | PinCfg.PULLUPS):
        print "Error enabling the internal voltage regulators."

    # Configure the raw-wire mode

    if not rw.cfg_raw_wire((RAW_WIRECfg.BIT_ORDER
                            & RAW_WIRE_BIT_ORDER_TYPE.MSB)
                           | (RAW_WIRECfg.WIRES & RAW_WIRE_WIRES_TYPE.TWO)
                           | (RAW_WIRECfg.OUT_TYPE & RAW_WIRE_OUT_TYPE.HIZ)):
        print "Error configuring the raw-wire mode."

    # Set raw-wire speed

    if not rw.set_speed(RAW_WIRESpeed._5KHZ):
        print "Error setting raw-wire speed."

    if options.temperature:
        print "Measuring temperature..."
        temperature = sht_temperature(rw, options)
        print "Temperature: %f°C" % temperature

    if options.humidity:
        print "Measuring humidity..."
        humidity = sht_humidity(rw, options)
        print "Humidity: %f%%" % humidity

    # Reset the bus pirate
    rw.resetBP()
def main():
    # First of all parse the command line

    parser = OptionParser()

    parser.add_option(
        "-d",
        "--device",
        dest="device",
        help="serial interface where bus pirate is in.[/dev/bus_pirate]",
        default="/dev/bus_pirate",
    )
    parser.add_option(
        "-t", "--temperature", action="store_true", dest="temperature", help="get temperature from sht.", default=False
    )
    parser.add_option(
        "-H", "--humidity", dest="humidity", action="store_true", help="get humidity from sht.", default=False
    )
    parser.add_option("-v", "--verbose", dest="verbose", help="don't be quiet.", action="store_true")

    (options, args) = parser.parse_args()

    if not (options.temperature or options.humidity):
        parser.print_help()
        exit()

    # Create an instance of the RAW_WIRE class as we are using the BitBang/RAW_WIRE mode
    rw = RAW_WIRE(options.device, 115200)

    if not rw.BBmode():
        print "Can't enter into BitBang mode."
        exit()

    # We have succesfully activated the BitBang Mode, so we continue with
    # the raw-wire mode.
    if not rw.enter_rawwire():
        print "Can't enable the raw-wire mode."
        exit()

    # Now we have raw-wire mode enabled, so first configure peripherals
    # (Power, PullUps, AUX, CS)

    if not rw.raw_cfg_pins(PinCfg.POWER | PinCfg.PULLUPS):
        print "Error enabling the internal voltage regulators."

    # Configure the raw-wire mode

    if not rw.cfg_raw_wire(
        (RAW_WIRECfg.BIT_ORDER & RAW_WIRE_BIT_ORDER_TYPE.MSB)
        | (RAW_WIRECfg.WIRES & RAW_WIRE_WIRES_TYPE.TWO)
        | (RAW_WIRECfg.OUT_TYPE & RAW_WIRE_OUT_TYPE.HIZ)
    ):
        print "Error configuring the raw-wire mode."

    # Set raw-wire speed

    if not rw.set_speed(RAW_WIRESpeed._5KHZ):
        print "Error setting raw-wire speed."

    if options.temperature:
        print "Measuring temperature..."
        temperature = sht_temperature(rw, options)
        print "Temperature: %f°C" % temperature

    if options.humidity:
        print "Measuring humidity..."
        humidity = sht_humidity(rw, options)
        print "Humidity: %f%%" % humidity

    # Reset the bus pirate
    rw.resetBP()
Example #5
0
def main():
    # First of all parse the command line
    
    parser = OptionParser()
    
    parser.add_option("-c", "--capacity", dest="capacity", help="size of the memory chip.", type="int")
    parser.add_option("-o", "--org", dest="org", help="specify the memory organization mode (8 or 16).", type="int")
    parser.add_option("-a", "--addr", dest="addr", help="set the starting offset of the read or write procedure.", type="int", default=0)
    parser.add_option("-n", "--number", dest="n", help="the number of data elements to read or write.", type="int", default=0)
    parser.add_option("-f", "--file", dest="file", help="the input or output file.", metavar="FILE")
    parser.add_option("-r", "--read", dest="action", help="read the memory chip.", default="read")
    parser.add_option("-w", "--write", dest="action", help="write to the memory chip.")
    parser.add_option("-d", "--device", dest="device", help="serial interface where bus pirate is in.[/dev/bus_pirate]", default="/dev/bus_pirate")
    parser.add_option("-v", "--verbose", dest="verbose", help="don't be quiet.", action="store_true")
    parser.add_option("-m", "--more", dest="more", help="only for testing: read more data elements", type="int", default=0)
    
    (options,args) = parser.parse_args()
    
    if (not options.capacity) or (not options.org) or (not options.file):
        parser.print_help()
        exit()      
    
    # Create an instance of the RAW_WIRE class as we are using the BitBang/RAW_WIRE mode
    #rw = RAW_WIRE( '/dev/bus_pirate', 115200 )
    rw = RAW_WIRE( options.device, 115200 )
    
    if not rw.BBmode():
        print "Can't enter into BitBang mode."
        exit()

    # We have succesfully activated the BitBang Mode, so we continue with
    # the raw-wire mode.
    if not rw.enter_rawwire():
        print "Can't enable the raw-wire mode."
        exit()
        
    # Now we have raw-wire mode enabled, so first configure peripherals
    # (Power, PullUps, AUX, CS)
    
    if not rw.raw_cfg_pins( PinCfg.POWER | PinCfg.CS ):
        print "Error enabling the internal voltage regulators."
        
    # Configure the raw-wire mode
    
    if not rw.cfg_raw_wire( (RAW_WIRECfg.BIT_ORDER & RAW_WIRE_BIT_ORDER_TYPE.MSB) | (RAW_WIRECfg.WIRES & RAW_WIRE_WIRES_TYPE.THREE) | (RAW_WIRECfg.OUT_TYPE & RAW_WIRE_OUT_TYPE._3V3) ):
        print "Error configuring the raw-wire mode."
    
    # Set raw-wire speed
    
    if not rw.set_speed( RAW_WIRESpeed._5KHZ ):
        print "Error setting raw-wire speed."

    # Open the file for reading or writting
    
    if options.action == "read":
        f = file(options.file, "wb")
    else:
        f = file(options.file, "rb")
        
    # How many elements to read or write?
    
    if options.n != 0:
        N = options.n + options.more
    else:
        N = options.capacity / options.org + options.more
    
    # Opcodes for microwire memory devices
    #
    #                Op             Address                 Data
    #Instruction SB Code        x8         x16          x8          x16     Comments
    #   READ     1   10     A8 – A0     A7 – A0                             Reads data stored in memory, at specified address
    #   EWEN     1   00    11XXXXXXX    11XXXXXX                            Write enable must precede all programming modes
    #
    # ....
    #

    if options.action == "read":
        # Enable the Chip select signal
        rw.CS_High()
    
        rw.bulk_trans(1, [0x6])
            
        rw.bulk_trans(1, [0x0])
        
        # and read the items
        
        if options.verbose:
            print "Reading %d elements of %d bits" % (N, options.org)
        
        if options.org == 8:
            for i in range(0,N):
                byte = rw.read_byte()
                f.write(byte)
                
                if options.verbose:
                    print "%02X" % (ord(byte),) ,
                    
        else:
            for i in range(0,N):
                byte = rw.read_byte()
                f.write(byte)
                
                if options.verbose:
                    print "%02X" % (ord(byte),) ,
                
                byte = rw.read_byte()
                f.write(byte)
                
                if options.verbose:
                    print "%02X" % (ord(byte),) ,
        
        f.close()
        
        rw.CS_Low()
        
        print "Done."
    

    
    # Reset the bus pirate
    rw.resetBP();