args = init('''OpenGrab EPM v3 production testing application. This application requires superuser priveleges to function correctly. Usage instructions: 1. Connect CAN adapter to this computer. 2. Start this application and follow its instructions.''', lambda p: p.add_argument('--iface', help='CAN interface name, e.g. "can0"'), lambda p: p.add_argument('--firmware', '-f', help='location of the firmware file', default=FIRMWARE_URL), lambda p: p.add_argument('--only-sign', help='skip testing, only install signature', action='store_true'), lambda p: p.add_argument('--generate-signed-image-for', help='only generate signed image for the provided unique ID. ' 'The ID should be provided as 4 comma-separated integers'), require_root=True) api = make_api_context_with_user_provided_credentials() def generate_signed_image_for(comma_separated_uid_integers): import struct import os try: unique_id_integers = list(map(int, comma_separated_uid_integers.split(','))) if len(unique_id_integers) != 4: raise ValueError('Unique ID must be composed of exactly 4 integers') unique_id = struct.pack('<IIII', *unique_id_integers) assert len(unique_id) == 128 / 8 except Exception as ex: fatal('Could not parse unique ID: %s', ex) info('Requesting signature for unique ID %s', ' '.join(['%02x' % x for x in unique_id]))
try: init_can_iface() info('CAN interface is OK') except Exception: logging.debug('CAN check error', exc_info=True) error('CAN interface is not working') ok = False if not ok: fatal('Required interfaces are not available. Please check your hardware configuration. ' 'If this application is running on a virtual machine, make sure that hardware ' 'sharing is configured correctly.') check_interfaces() licensing_api = make_api_context_with_user_provided_credentials() with CLIWaitCursor(): print('Please wait...') if args.firmware: firmware_data = download(args.firmware) else: firmware_data = download_newest(DEFAULT_FIRMWARE_GLOB) assert 30 < (len(firmware_data) / 1024) <= 240, 'Invalid firmware size' def process_one_device(set_device_info): out = input('1. Connect DroneCode Probe to the debug connector.\n' '2. Connect CAN to the first CAN1 connector on the device; terminate the other CAN1 connector.\n' '4. Connect an appropriate power supply (see the hardware specs for requirements).\n' ' Make sure the motor leads are NOT CONNECTED to anything.\n'