if s is not None:
        # There is a value to set

        # If the argparse type conversion was employed then convert
        # back to a string
        s = str(s)

        # Parse struct format string into order, quantity, type
        pfmt = AWEeprom.parse_unpack_format(eeprom[k]['format'])

        if pfmt[2] in ('c', 's', 'p'):
            # String data
            data = s
        else:
            # Convert into numeric data
            data = AWEeprom.safe_eval(s)

        if pfmt[1] > 1:
            # Multiple values required
            struct.pack_into(eeprom[k]['format'], eeprom_data,
                             eeprom[k]['address'], *data)
        else:
            struct.pack_into(eeprom[k]['format'], eeprom_data,
                             eeprom[k]['address'], data)


eeprom_image_filename = args.file + '.bin'
fh = open(eeprom_image_filename, 'wb')
fh.write(eeprom_data)
fh.close()
print('Wrote ' + str(eeprom_size) + ' bytes to ' + eeprom_image_filename)
Beispiel #2
0
    # If the argparse type conversion was employed then convert
    # back to a string
    s = str(s)

    m = re.match('^eeprom_(.*)', k)
    if m:
        cmd['name'] = 'write_eeprom'
        eeprom_setting = m.group(1)
        # Parse struct format string into order, quantity, type
        pfmt = AWEeprom.parse_unpack_format(eeprom[eeprom_setting]['format'])
        if pfmt[2] in ('c', 's', 'p'):
            # String data
            data = s
        else:
            # Convert into numeric data
            data = AWEeprom.safe_eval(s)

        # Pack data into suitable bytearrays matching the EEPROM layout
        if pfmt[1] > 1:
            # Multiple values required
            eeprom_data = struct.pack(eeprom[eeprom_setting]['format'],
                                      *data)
        else:
            # struct.pack_into(eeprom[eeprom_setting]['format'], eeprom_data,
            eeprom_data = struct.pack(eeprom[eeprom_setting]['format'],
                                           data)
            
        # Convert the bytewise values into a string, remembering to
        # prepend the address
        cmd['value'] = str(eeprom[eeprom_setting]['address']) + ',' + \
            ','.join([str(ord(x)) for x in eeprom_data])