Ejemplo n.º 1
0
    def run(self, progressCallback=None):
        try:
            printer.disconnect()
        except:
            pass
        time.sleep(0.5)

        hexFile = intelHex.readHex(self._filename)
        programmer = stk500v2.Stk500v2()
        programmer.progressCallback = progressCallback if progressCallback else self.onProgress

        try:
            programmer.connect(self._port)
        except ispBase.IspError:
            self._logger.error(
                'Failed to find machine for firmware upgrade! Is your machine had been connected?'
            )

        if programmer.isConnected():
            self._logger.info("Uploading firmware...")
            try:
                programmer.programChip(hexFile)
                self._logger.info("Done! Installed firmware: %s" %
                                  (os.path.basename(self._filename)))
            except ispBase.IspError as e:
                self._logger.error("Failed to write firmware.\n" + str(e))
            try:
                programmer.close()
            except:
                pass
            time.sleep(0.5)

        printer.connect(port=self._port,
                        baudrate=settings().get(["serial", "baudrate"]))
Ejemplo n.º 2
0
def connectionCommand(request=None):
    valid_commands = {"connect": ["autoconnect"], "disconnect": []}

    command, data, response = util.getJsonCommandFromRequest(
        request, valid_commands)
    print "connectionCommand", command, data, response, "connectionCommand"
    if response is not None:
        return response

    if command == "connect":
        options = getConnectionOptions()

        port = None
        baudrate = None
        if "port" in data.keys():
            port = data["port"]
            if port not in options["ports"]:
                return make_response("Invalid port: %s" % port, 400)
        if "baudrate" in data.keys():
            baudrate = data["baudrate"]
            if baudrate not in options["baudrates"]:
                return make_response("Invalid baudrate: %d" % baudrate, 400)
        if "save" in data.keys() and data["save"]:
            settings().set(["serial", "port"], port)
            settings().setInt(["serial", "baudrate"], baudrate)
        if "autoconnect" in data.keys():
            settings().setBoolean(["serial", "autoconnect"],
                                  data["autoconnect"])
        settings().save()
        printer.connect(port=port, baudrate=baudrate)
    elif command == "disconnect":
        printer.disconnect()

    return NO_CONTENT
Ejemplo n.º 3
0
def connectionCommand():
	valid_commands = {
		"connect": ["autoconnect"],
		"disconnect": []
	}

	command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
	if response is not None:
		return response

	if command == "connect":
		options = getConnectionOptions()

		port = None
		baudrate = None
		if "port" in data.keys():
			port = data["port"]
			if port not in options["ports"]:
				return make_response("Invalid port: %s" % port, 400)
		if "baudrate" in data.keys():
			baudrate = data["baudrate"]
			if baudrate not in options["baudrates"]:
				return make_response("Invalid baudrate: %d" % baudrate, 400)
		if "save" in data.keys() and data["save"]:
			settings().set(["serial", "port"], port)
			settings().setInt(["serial", "baudrate"], baudrate)
		settings().setBoolean(["serial", "autoconnect"], data["autoconnect"])
		settings().save()
		printer.connect(port=port, baudrate=baudrate)
	elif command == "disconnect":
		printer.disconnect()

	return jsonify(SUCCESS)
Ejemplo n.º 4
0
def connectionCommand():
    valid_commands = {"connect": [], "disconnect": []}

    command, data, response = get_json_command_from_request(
        request, valid_commands)
    if response is not None:
        return response

    if command == "connect":
        connection_options = get_connection_options()

        port = None
        port1 = None
        projector = None
        baudrate = None
        printerProfile = None
        if "port" in data.keys():
            port = data["port"]
            if port not in connection_options["ports"]:
                return make_response("Invalid port: %s" % port, 400)
        if "baudrate" in data.keys():
            baudrate = data["baudrate"]
            if baudrate not in connection_options["baudrates"]:
                return make_response("Invalid baudrate: %d" % baudrate, 400)
        if "printerProfile" in data.keys():
            printerProfile = data["printerProfile"]
            if not printerProfileManager.exists(printerProfile):
                return make_response(
                    "Invalid printer profile: %s" % printerProfile, 400)
        if "save" in data.keys() and data["save"]:
            port1 = data["port1"]
            projector = data["projector"]
            settings().set(["serial", "port"], port)
            settings().set(["serial", "port1"], port1)
            settings().set(["serial", "projector"], projector)
            settings().setInt(["serial", "baudrate"], baudrate)
            printerProfileManager.set_default(printerProfile)
        if "autoconnect" in data.keys():
            settings().setBoolean(["serial", "autoconnect"],
                                  data["autoconnect"])
        settings().save()
        printer.connect(port=port, baudrate=baudrate, profile=printerProfile)
    elif command == "disconnect":
        printer.disconnect()

    return NO_CONTENT
Ejemplo n.º 5
0
def connectionCommand():
	valid_commands = {
		"connect": [],
		"disconnect": [],
		"fake_ack": []
	}

	command, data, response = get_json_command_from_request(request, valid_commands)
	if response is not None:
		return response

	if command == "connect":
		connection_options = get_connection_options()

		port = None
		baudrate = None
		printerProfile = None
		if "port" in data.keys():
			port = data["port"]
			if port not in connection_options["ports"] and port != "AUTO":
				return make_response("Invalid port: %s" % port, 400)
		if "baudrate" in data.keys():
			baudrate = data["baudrate"]
			if baudrate not in connection_options["baudrates"] and baudrate != 0:
				return make_response("Invalid baudrate: %d" % baudrate, 400)
		if "printerProfile" in data.keys():
			printerProfile = data["printerProfile"]
			if not printerProfileManager.exists(printerProfile):
				return make_response("Invalid printer profile: %s" % printerProfile, 400)
		if "save" in data.keys() and data["save"]:
			settings().set(["serial", "port"], port)
			settings().setInt(["serial", "baudrate"], baudrate)
			printerProfileManager.set_default(printerProfile)
		if "autoconnect" in data.keys():
			settings().setBoolean(["serial", "autoconnect"], data["autoconnect"])
		settings().save()
		printer.connect(port=port, baudrate=baudrate, profile=printerProfile)
	elif command == "disconnect":
		printer.disconnect()
	elif command == "fake_ack":
		printer.fake_ack()

	return NO_CONTENT
Ejemplo n.º 6
0
def connectionCommand():
    valid_commands = {"connect": [], "disconnect": [], "fake_ack": []}

    command, data, response = get_json_command_from_request(
        request, valid_commands)
    if response is not None:
        return response

    if command == "connect":
        connection_options = printer.__class__.get_connection_options()

        port = None
        baudrate = None
        printerProfile = None
        if "port" in data:
            port = data["port"]
            if port not in connection_options["ports"] and port != "AUTO":
                abort(400, description="port is invalid")
        if "baudrate" in data:
            baudrate = data["baudrate"]
            if baudrate not in connection_options[
                    "baudrates"] and baudrate != 0:
                abort(400, description="baudrate is invalid")
        if "printerProfile" in data:
            printerProfile = data["printerProfile"]
            if not printerProfileManager.exists(printerProfile):
                abort(400, description="printerProfile is invalid")
        if "save" in data and data["save"]:
            settings().set(["serial", "port"], port)
            settings().setInt(["serial", "baudrate"], baudrate)
            printerProfileManager.set_default(printerProfile)
        if "autoconnect" in data:
            settings().setBoolean(["serial", "autoconnect"],
                                  data["autoconnect"])
        settings().save()
        printer.connect(port=port, baudrate=baudrate, profile=printerProfile)
    elif command == "disconnect":
        printer.disconnect()
    elif command == "fake_ack":
        printer.fake_ack()

    return NO_CONTENT
Ejemplo n.º 7
0
def connect():
	if "command" in request.values.keys() and request.values["command"] == "connect":
		port = None
		baudrate = None
		if "port" in request.values.keys():
			port = request.values["port"]
		if "baudrate" in request.values.keys():
			baudrate = request.values["baudrate"]
		if "save" in request.values.keys():
			settings().set(["serial", "port"], port)
			settings().setInt(["serial", "baudrate"], baudrate)
			settings().save()
		if "autoconnect" in request.values.keys():
			settings().setBoolean(["serial", "autoconnect"], True)
			settings().save()
		printer.connect(port=port, baudrate=baudrate)
	elif "command" in request.values.keys() and request.values["command"] == "disconnect":
		printer.disconnect()

	return jsonify(SUCCESS)
Ejemplo n.º 8
0
	def restartServer(self):
		if platform == "linux" or platform == "linux2":
			from astroprint.boxrouter import boxrouterManager
			from octoprint.server import printer

			#let's be nice about shutthing things down
			br = boxrouterManager()

			br.boxrouter_disconnect()
			printer.disconnect()

			actions = self._settings.get(["system", "actions"])
			for a in actions:
				if a['action'] == 'astrobox-restart':
					subprocess.call(a['command'].split(' '))
					return True

			subprocess.call(['restart', 'astrobox'])

		return True
Ejemplo n.º 9
0
	def restartServer(self):
		if platform == "linux" or platform == "linux2":
			from astroprint.boxrouter import boxrouterManager
			from octoprint.server import printer

			#let's be nice about shutthing things down
			br = boxrouterManager()

			br.boxrouter_disconnect()
			printer.disconnect()

			actions = self._settings.get(["system", "actions"])
			for a in actions:
				if a['action'] == 'astrobox-restart':
					subprocess.call(a['command'].split(' '))
					return True

			subprocess.call(['restart', 'astrobox'])

		return True
Ejemplo n.º 10
0
def connect():
    command = requests.values.get("command", None)

    if command == "connect":
        port = requests.values.get("port", None)
        baudrate = requests.values.get("baudrate", None)

        if "save" in request.values:
            settings.set("serial", "port", port)
            settings.set("serial", "baudrate", baudrate)
            settings.save()

        if "autoconnect" in request.values:
            settings.set("serial", "autoconnect", True)
            settings.save()

        printer.connect(port=port, baudrate=baudrate)
    elif command == "disconnect":
        printer.disconnect()

    return jsonify(SUCCESS)
Ejemplo n.º 11
0
def connect():
    if "command" in request.values.keys(
    ) and request.values["command"] == "connect":
        port = None
        baudrate = None
        if "port" in request.values.keys():
            port = request.values["port"]
        if "baudrate" in request.values.keys():
            baudrate = request.values["baudrate"]
        if "save" in request.values.keys():
            settings().set(["serial", "port"], port)
            settings().setInt(["serial", "baudrate"], baudrate)
            settings().save()
        if "autoconnect" in request.values.keys():
            settings().setBoolean(["serial", "autoconnect"], True)
            settings().save()
        printer.connect(port=port, baudrate=baudrate)
    elif "command" in request.values.keys(
    ) and request.values["command"] == "disconnect":
        printer.disconnect()

    return jsonify(SUCCESS)