Commit 72b82d67 authored by Guillaume Seguin's avatar Guillaume Seguin

Add basic RPC server to serve print status

parent fb7b2740
...@@ -38,6 +38,7 @@ from .utils import install_locale, run_command, get_command_output, \ ...@@ -38,6 +38,7 @@ from .utils import install_locale, run_command, get_command_output, \
install_locale('pronterface') install_locale('pronterface')
from printrun.power import powerset_print_start, powerset_print_stop from printrun.power import powerset_print_start, powerset_print_stop
from printrun import gcoder from printrun import gcoder
from .rpc import ProntRPC
from functools import wraps from functools import wraps
...@@ -301,6 +302,7 @@ class Settings(object): ...@@ -301,6 +302,7 @@ class Settings(object):
self._add(StringSetting("port", "", _("Serial port"), _("Port used to communicate with printer"))) self._add(StringSetting("port", "", _("Serial port"), _("Port used to communicate with printer")))
self._add(ComboSetting("baudrate", 115200, self.__baudrate_list(), _("Baud rate"), _("Communications Speed"))) self._add(ComboSetting("baudrate", 115200, self.__baudrate_list(), _("Baud rate"), _("Communications Speed")))
self._add(BooleanSetting("tcp_streaming_mode", False, _("TCP streaming mode"), _("When using a TCP connection to the printer, the streaming mode will not wait for acks from the printer to send new commands. This will break things such as ETA prediction, but can result in smoother prints.")), root.update_tcp_streaming_mode) self._add(BooleanSetting("tcp_streaming_mode", False, _("TCP streaming mode"), _("When using a TCP connection to the printer, the streaming mode will not wait for acks from the printer to send new commands. This will break things such as ETA prediction, but can result in smoother prints.")), root.update_tcp_streaming_mode)
self._add(BooleanSetting("rpc_server", True, _("RPC server"), _("Enable RPC server to allow remotely querying print status")), root.update_rpc_server)
self._add(SpinSetting("bedtemp_abs", 110, 0, 400, _("Bed temperature for ABS"), _("Heated Build Platform temp for ABS (deg C)"), "Printer")) self._add(SpinSetting("bedtemp_abs", 110, 0, 400, _("Bed temperature for ABS"), _("Heated Build Platform temp for ABS (deg C)"), "Printer"))
self._add(SpinSetting("bedtemp_pla", 60, 0, 400, _("Bed temperature for PLA"), _("Heated Build Platform temp for PLA (deg C)"), "Printer")) self._add(SpinSetting("bedtemp_pla", 60, 0, 400, _("Bed temperature for PLA"), _("Heated Build Platform temp for PLA (deg C)"), "Printer"))
self._add(SpinSetting("temperature_abs", 230, 0, 400, _("Extruder temperature for ABS"), _("Extruder temp for ABS (deg C)"), "Printer")) self._add(SpinSetting("temperature_abs", 230, 0, 400, _("Extruder temperature for ABS"), _("Extruder temp for ABS (deg C)"), "Printer"))
...@@ -974,6 +976,10 @@ class pronsole(cmd.Cmd): ...@@ -974,6 +976,10 @@ class pronsole(cmd.Cmd):
def update_tcp_streaming_mode(self, param, value): def update_tcp_streaming_mode(self, param, value):
self.p.tcp_streaming_mode = self.settings.tcp_streaming_mode self.p.tcp_streaming_mode = self.settings.tcp_streaming_mode
def update_rpc_server(self, param, value):
if value and self.rpc_server is not None:
self.rpc_server = ProntRPC(self)
# -------------------------------------------------------------- # --------------------------------------------------------------
# Command line options handling # Command line options handling
# -------------------------------------------------------------- # --------------------------------------------------------------
......
from SimpleXMLRPCServer import SimpleXMLRPCServer
from threading import Thread
RPC_PORT = 7978
class ProntRPC(object):
server = None
def __init__(self, pronsole, port = RPC_PORT):
self.pronsole = pronsole
self.server = SimpleXMLRPCServer(("localhost", port))
self.server.register_function(self.get_status, 'status')
self.thread = Thread(target = self.run_server)
self.thread.start()
def run_server(self):
self.server.serve_forever()
def get_status(self):
if self.pronsole.p.printing:
progress = 100 * float(self.pronsole.p.queueindex) / len(self.pronsole.p.mainqueue)
elif self.pronsole.sdprinting:
progress = self.percentdone
else: progress = None
if self.pronsole.p.printing or self.pronsole.sdprinting:
eta = self.get_eta()
else:
eta = None
return {"filename": self.pronsole.filename,
"progress": progress,
"eta": eta,
}
...@@ -18,7 +18,10 @@ ...@@ -18,7 +18,10 @@
import sys import sys
try: try:
import wxversion
wxversion.select("3.0")
import wx # NOQA import wx # NOQA
print wx.__version__
except: except:
print("wxPython is not installed. This program requires wxPython to run.") print("wxPython is not installed. This program requires wxPython to run.")
if sys.version_info.major >= 3: if sys.version_info.major >= 3:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment