Пример #1
0
def setSerial(w, id):
	createBaudCombo(w, id)
	try:
		config.cur_serial_port = id
		if ser.serial.isOpen():
			ser.resetBoard()
			ser.serial.close()
		ser.serial.port = id
		ser.serial.open()
		p.setValue("serial.port", id)
		p.saveValues()
	except Exception,e:
		misc.clearConsole(tw)
		misc.printMessage(tw, str(e))
		print(e)
Пример #2
0
def setSerial(w, id):
    createBaudCombo(w, id)
    try:
        config.cur_serial_port = id
        if ser.serial.isOpen():
            ser.resetBoard()
            ser.serial.close()
        ser.serial.port = id
        ser.serial.baudrate = config.serial_baud_rate
        ser.serial.open()
        p.setValue("serial.port", id)
        p.saveValues()
    except Exception, e:
        misc.clearConsole(tw)
        misc.printMessage(tw, str(e))
        print(e)
Пример #3
0
def compile(tw, sourcefile, id, output, notify):
	buf =  tw.get_buffer()
	cont = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
	if cont is "": return -1
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Compiling..."))
	misc.printMessageLn(output, 'Compile start')
	misc.printLogMessageLn('Compile start')
	misc.clearConsole(output)
	tmpdir = id
	tempobj = tempfile.mktemp("", "Tempobj", id)
	global p
	global queue
	queue = []
	p = prefs.preferences()
	b = board.Board()
	#compile inter c objects
	try:
		"""preproces pde"""
		(pre_file, lines) = preproc.addHeaders(id, buf)
		"""compile C targets"""
		misc.printLogMessageLn('processing C targets')
		(run, sout) = compileObjects(cobj, defc, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			raise NameError("compile error")
		"""deprecated C targets (pre 1.0)"""
		if misc.getArduinoVersion() < 100:
			(run, sout) = compileObjects(cobj_deprecated, defc, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
		"""compile C++ targets"""
		misc.printLogMessageLn('processing C++ targets')
		(run, sout) = compileObjects(cppobj, defcpp, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), sout)
			raise NameError("compile error")
		"""compile C++ additional (1.0) targets"""
		if misc.getArduinoVersion() >= 100:
			misc.printLogMessageLn('processing C++ additional targets')
			(run, sout) = compileObjects(cppobj_additional, defcpp, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), sout)
				raise NameError("compile error")
		"""generate archive objects"""
		misc.printLogMessageLn('generating ar objects')
		objects = cobj + cppobj
		if misc.getArduinoVersion() >= 100:
			objects += cppobj_additional
		else:
			objects += cobj_deprecated
		for i in objects:
			compline = [j for j in defar]
			compline.append(id+"/core.a")
			compline.append(id+"/"+i+".o")
			misc.printMessageLn(output, ' '.join(compline)+"\n")
			misc.printLogMessageLn(' '.join(compline))
			(run, sout) = misc.runProg(compline)
			misc.printLogMessageLn(sout)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
			else:
				misc.printMessageLn(output, sout)
		"""precompile pde"""
		misc.printLogMessageLn('pde compile')
		misc.printLogMessageLn('-----------')
		compline=[j for j in defcpp]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		flags = []
		flags = preproc.generateCFlags(id, cont)
		compline.extend(flags)
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		compline.extend(misc.getArduinoIncludes())
		compline.append(pre_file)
		compline.append("-o"+pre_file+".o")
		compline.append("-I"+os.path.dirname(sourcefile))
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			moveCursor(tw, int(getErrorLine(sout, lines)))
			raise NameError('compile-error')
		else:
			misc.printMessageLn(output, sout)

		"""compile all objects"""
		misc.printLogMessageLn('compile objects')
		misc.printLogMessageLn('---------------')
		compline = [i for i in link]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-o"+tempobj+".elf")
		compline.append(pre_file+".o")
		tmplibs = []
		for i in preproc.generateLibs(id, buf):
			tmplibs.extend(validateLib(os.path.basename(i), tempobj, flags, output, notify))
		compline.extend(list(set(tmplibs)))
		compline.extend(["-I" + i for i in preproc.generateLibs(id, buf)])
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		compline.append(id+"/core.a")
		compline.append("-L"+id)
		compline.append("-lm")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Linking error"), stripOut(sout, pre_file))
			raise NameError('linking-error')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in eep]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".eep")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in hex]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".hex")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		size = computeSize(tempobj+".hex")
		notify.pop(context)
		notify.push(context, _("Done compiling."))
		misc.printLogMessageLn("compile done.")

		misc.printMessageLn(output, \
			_("Binary sketch size: %s bytes (of a %s bytes maximum)\n") % (size, b.getBoardMemory(b.getBoard())), 'true')
	except StandardError as e:
		print "Error: %s" % e
		return -1
	except Exception as e:
		print "Error compiling. Op aborted!"
		print "Error: %s" % e
		return -1
	return tempobj
Пример #4
0
def burnBootloader(serial, output, notify, id):
	p = prefs.preferences()
	misc.clearConsole(output)
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Burning bootloader..."))
	b = board.Board()
	compline=[i for i in avr_bl]
	pgm = programmer.Programmer()
	if pgm.getCommunication(id) == 'serial':
        	port = serial.getConfigSerialPort(notify, output)
	        if port != -1:
        	        serial.resetBoard()
        	"""De-fuse and erase board"""

		port = serial.getConfigSerialPort(notify, output)
		if port == -1:
			notify.pop(context)
			notify.push(context, _("Flashing error."))
			return
		compline.append("-P" + port)
		if pgm.getSpeed(id) != 0:
			compline.append("-b" + pgm.getSpeed(id))
	elif pgm.getCommunication(id) == 'usb':
		compline.append("-Pusb")
	compline.append("-c" + pgm.getProtocol(id))
	compline.append("-p" + b.getBoardMCU(b.getBoard()))
	compline.append("-e")
	if pgm.getForce(id) == 'true':
		compline.append("-F")
	compline.append("-Ulock:w:" + b.getFuseUnlock(b.getBoard()) + ":m")
	if b.getBoardMCU(b.getBoard()) != 'atmega8':
		compline.append("-Uefuse:w:" + b.getFuseExtended(b.getBoard()) + ":m")
	compline.append("-Uhfuse:w:" + b.getFuseHigh(b.getBoard()) + ":m")
	compline.append("-Ulfuse:w:" + b.getFuseLow(b.getBoard()) + ":m")
	try:
		if p.getBoolValue("upload.verbose"):
			sys.stderr.write(' '.join(compline)+"\n")
			misc.printMessageLn(output, ' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"), 'false')
		if p.getBoolValue("upload.verbose"): sys.stderr.write(sout+"\n")
		if run == False: raise
	except:
		misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
		return
	"""Burn and fuse board"""
	compline=[i for i in avr_bl]
	compline.append("-c" + pgm.getProtocol(id))
	if pgm.getCommunication(id) == 'serial':
		port = serial.getConfigSerialPort(notify, output)
		if port == -1:
			notify.pop(context)
			notify.push(context, _("Flashing error."))
			return
		compline.append("-P" + port)
		if pgm.getSpeed(id) != 0:
			compline.append("-b" + pgm.getSpeed(id))
	elif pgm.getCommunication(id) == 'usb':
		compline.append("-Pusb")
	compline.append("-p" + b.getBoardMCU(b.getBoard()))
	compline.append("-e")
	if pgm.getForce(id) == 'true':
		compline.append("-F")
	compline.append("-Uflash:w:" + findBootLoader() + ":i")
	compline.append("-Ulock:w:" + b.getFuseLock(b.getBoard()) + ":m")
	try:
		if p.getBoolValue("upload.verbose"):
			sys.stderr.write(' '.join(compline)+"\n")
			misc.printMessageLn(output, ' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"), 'false')
		if p.getBoolValue("upload.verbose"): sys.stderr.write(sout+"\n")
		if run == False: raise
	except:
		misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
		return
	notify.pop(context)
	notify.push(context, _("Burn complete."))
	misc.printMessageLn(output, \
		"Burn OK.");
Пример #5
0
def burnBootloader(serial, output, notify, id):
    p = prefs.preferences()
    misc.clearConsole(output)
    context = notify.get_context_id("main")
    notify.pop(context)
    notify.push(context, _("Burning bootloader..."))
    b = board.Board()
    compline = [i for i in avr_bl]
    pgm = programmer.Programmer()
    if pgm.getCommunication(id) == 'serial':
        port = serial.getConfigSerialPort(notify, output)
        if port != -1:
            serial.resetBoard()
        """De-fuse and erase board"""

        port = serial.getConfigSerialPort(notify, output)
        if port == -1:
            notify.pop(context)
            notify.push(context, _("Flashing error."))
            return
        compline.append("-P" + port)
        if pgm.getSpeed(id) != 0:
            compline.append("-b" + pgm.getSpeed(id))
    elif pgm.getCommunication(id) == 'usb':
        compline.append("-Pusb")
    compline.append("-c" + pgm.getProtocol(id))
    compline.append("-p" + b.getBoardMCU(b.getBoard()))
    compline.append("-e")
    if pgm.getForce(id) == 'true':
        compline.append("-F")
    compline.append("-Ulock:w:" + b.getFuseUnlock(b.getBoard()) + ":m")
    if b.getBoardMCU(b.getBoard()) != 'atmega8':
        compline.append("-Uefuse:w:" + b.getFuseExtended(b.getBoard()) + ":m")
    compline.append("-Uhfuse:w:" + b.getFuseHigh(b.getBoard()) + ":m")
    compline.append("-Ulfuse:w:" + b.getFuseLow(b.getBoard()) + ":m")
    try:
        if p.getBoolValue("upload.verbose"):
            sys.stderr.write(' '.join(compline) + "\n")
            misc.printMessageLn(output, ' '.join(compline))
        (run, sout) = misc.runProg(compline)
        misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"),
                            'false')
        if p.getBoolValue("upload.verbose"): sys.stderr.write(sout + "\n")
        if run == False: raise
    except:
        misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
        return
    """Burn and fuse board"""
    compline = [i for i in avr_bl]
    compline.append("-c" + pgm.getProtocol(id))
    if pgm.getCommunication(id) == 'serial':
        port = serial.getConfigSerialPort(notify, output)
        if port == -1:
            notify.pop(context)
            notify.push(context, _("Flashing error."))
            return
        compline.append("-P" + port)
        if pgm.getSpeed(id) != 0:
            compline.append("-b" + pgm.getSpeed(id))
    elif pgm.getCommunication(id) == 'usb':
        compline.append("-Pusb")
    compline.append("-p" + b.getBoardMCU(b.getBoard()))
    compline.append("-e")
    if pgm.getForce(id) == 'true':
        compline.append("-F")
    compline.append("-Uflash:w:" + findBootLoader() + ":i")
    compline.append("-Ulock:w:" + b.getFuseLock(b.getBoard()) + ":m")
    try:
        if p.getBoolValue("upload.verbose"):
            sys.stderr.write(' '.join(compline) + "\n")
            misc.printMessageLn(output, ' '.join(compline))
        (run, sout) = misc.runProg(compline)
        misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"),
                            'false')
        if p.getBoolValue("upload.verbose"): sys.stderr.write(sout + "\n")
        if run == False: raise
    except:
        misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
        return
    notify.pop(context)
    notify.push(context, _("Burn complete."))
    misc.printMessageLn(output, \
     "Burn OK.")
Пример #6
0
def compile(tw, id, output, notify):
	buf =  tw.get_buffer()
	cont = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
	if cont is "": return -1
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Compiling..."))
	misc.printMessageLn(output, 'Compile start')
	misc.printLogMessageLn('Compile start')
	misc.clearConsole(output)
	tmpdir = id
	tempobj = tempfile.mktemp("", "Tempobj", id)
	global p
	global queue
	queue = []
	p = prefs.preferences()
	b = board.Board()
	#compile inter c objects
	try:
		"""preproces pde"""
		(pre_file, lines) = preproc.addHeaders(id, buf)
		"""compile C targets"""
		misc.printLogMessageLn('processing C targets')
		(run, sout) = compileObjects(cobj, defc, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			raise NameError("compile error")
		"""deprecated C targets (pre 1.0)"""
		if misc.getArduinoVersion() < 100:
			(run, sout) = compileObjects(cobj_deprecated, defc, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
		"""compile C++ targets"""
		misc.printLogMessageLn('processing C++ targets')
		(run, sout) = compileObjects(cppobj, defcpp, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), sout)
			raise NameError("compile error")
		"""compile C++ additional (1.0) targets"""
		if misc.getArduinoVersion() >= 100:
			misc.printLogMessageLn('processing C++ additional targets')
			(run, sout) = compileObjects(cppobj_additional, defcpp, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), sout)
				raise NameError("compile error")
		"""generate archive objects"""
		misc.printLogMessageLn('generating ar objects')
		objects = cobj + cppobj
		if misc.getArduinoVersion() >= 100:
			objects += cppobj_additional
		else:
			objects += cobj_deprecated
		for i in objects:
			compline = [j for j in defar]
			compline.append(id+"/core.a")
			compline.append(id+"/"+i+".o")
			misc.printMessageLn(output, ' '.join(compline)+"\n")
			misc.printLogMessageLn(' '.join(compline))
			(run, sout) = misc.runProg(compline)
			misc.printLogMessageLn(sout)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
			else:
				misc.printMessageLn(output, sout)
		"""precompile pde"""
		misc.printLogMessageLn('pde compile')
		misc.printLogMessageLn('-----------')
		compline=[j for j in defcpp]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		flags = []
		flags = preproc.generateCFlags(id, cont)
		compline.extend(flags)
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		compline.extend(misc.getArduinoIncludes())
		compline.extend(["-I"+os.getcwd()])
		try:
			localDir = os.path.dirname(tw.get_data("file"))
			compline.extend(["-I"+localDir])
			compline.extend(["-I"+os.path.abspath(os.path.join(localDir, ".."))])
		except: pass
		compline.append(pre_file)
		compline.append("-o"+pre_file+".o")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			moveCursor(tw, int(getErrorLine(sout, lines)))
			raise NameError('compile-error')
		else:
			misc.printMessageLn(output, sout)

		"""compile all objects"""
		misc.printLogMessageLn('compile objects')
		misc.printLogMessageLn('---------------')
		compline = [i for i in link]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-o"+tempobj+".elf")
		compline.append(pre_file+".o")
		tmplibs = []
		for i in preproc.generateLibs(id, buf):
			tmplibs.extend(validateLib(os.path.basename(i), tempobj, flags, output, notify))
		compline.extend(list(set(tmplibs)))
		compline.extend(["-I" + i for i in preproc.generateLibs(id, buf)])
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		compline.append(id+"/core.a")
		compline.append("-L"+id)
		compline.append("-lm")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Linking error"), stripOut(sout, pre_file))
			raise NameError('linking-error')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in eep]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".eep")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in hex]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".hex")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		size = computeSize(tempobj+".hex")
		notify.pop(context)
		notify.push(context, _("Done compiling."))
		misc.printLogMessageLn("compile done.")

		misc.printMessageLn(output, \
			_("Binary sketch size: %s bytes (of a %s bytes maximum)\n") % (size, b.getBoardMemory(b.getBoard())), 'true')
	except StandardError as e:
		print "Error: %s" % e
		return -1
	except Exception as e:
		print "Error compiling. Op aborted!"
		print "Error: %s" % e
		return -1
	return tempobj