Clear planner coolant and spindle state on stop, Fix web disconnect problem when...
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 8 Oct 2020 00:39:13 +0000 (17:39 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 8 Oct 2020 00:39:13 +0000 (17:39 -0700)
CHANGELOG.md
src/avr/src/state.c
src/pug/templates/admin-general-view.pug
src/py/bbctrl/Mach.py
src/py/bbctrl/Web.py

index 71826988c5e0f3e2b301f2616146500b62cfbb8c..e6bdab72df43a595f1130ee42365f3adad0be1da 100644 (file)
@@ -12,6 +12,7 @@ Buildbotics CNC Controller Firmware Changelog
  - Support for WJ200 VFD
  - Added M8.1 and M7.1 coolant off commands.
  - Clear planner coolant and spindle state on stop.
+ - Fix web disconnect problem when downloading a bug report.
 
 ## v0.4.14
  - Handle file uploads with '#' or '?' in the name.
index 6410b54196516a0fdb70f95030a8e636ad1903a4..946cae3f0133aa825bca05bafb714a9847688937 100644 (file)
@@ -126,7 +126,6 @@ static void _stop() {
     spindle_stop();
     outputs_stop();
     seek_cancel();
-    _set_state(STATE_HOLDING);
     break;
 
   case STATE_STOPPING:
index ac82ba1b5a9dc2a6742389583cc17e8aa97919f4..1bff7e0fa555e310653462ba3050a41cf36348f7 100644 (file)
@@ -64,5 +64,5 @@ script#admin-general-view-template(type="text/x-template")
     h2 Debugging
     a(href="/api/log", target="_blank")
       button.pure-button.pure-button-primary View Log
-    a(href="/api/bugreport")
+    a(href="/api/bugreport", download)
       button.pure-button.pure-button-primary Bug Report
index 9d3d79787469880f2a915f5cf0f1831a1b1869b3..8a11efc41e85bdd78ef161901d64729650609d41 100644 (file)
@@ -84,6 +84,7 @@ class Mach(Comm):
 
         self.planner = bbctrl.Planner(ctrl)
         self.unpausing = False
+        self.stopping = False
 
         ctrl.state.set('cycle', 'idle')
 
@@ -143,6 +144,12 @@ class Mach(Comm):
             self.planner.position_change()
             self._set_cycle('idle')
 
+        # Planner stop
+        if state == 'READY' and self.stopping:
+            self.planner.stop()
+            self.ctrl.state.set('line', 0)
+            self.stopping = False
+
         # Unpause sync
         if state_changed and state != 'HOLDING': self.unpausing = False
 
@@ -301,7 +308,11 @@ class Mach(Comm):
         else: super().i2c_command(Cmd.UNPAUSE)
 
 
-    def stop(self): super().i2c_command(Cmd.STOP)
+    def stop(self):
+        if self._get_state() != 'jogging': self.stopping = True
+        super().i2c_command(Cmd.STOP)
+
+
     def pause(self): super().pause()
 
 
index 0eb757c485a1cf5fd76524750dfbbf779b4a0ccc..9815c361809c7153acbb93c4f0cca391a253d1c0 100644 (file)
@@ -38,6 +38,8 @@ import socket
 import time
 from tornado.web import HTTPError
 from tornado import web, gen
+from tornado.concurrent import run_on_executor
+from concurrent.futures import ThreadPoolExecutor
 
 import bbctrl
 
@@ -101,16 +103,16 @@ class MessageAckHandler(bbctrl.APIHandler):
 
 
 class BugReportHandler(bbctrl.RequestHandler):
-    def get(self):
-        import tarfile, io
+    executor = ThreadPoolExecutor(max_workers = 4)
 
-        buf = io.BytesIO()
-        tar = tarfile.open(mode = 'w:bz2', fileobj = buf)
+
+    def get_files(self):
+        files = []
 
         def check_add(path, arcname = None):
             if os.path.isfile(path):
                 if arcname is None: arcname = path
-                tar.add(path, self.basename + '/' + arcname)
+                files.append((path, self.basename + '/' + arcname))
 
         def check_add_basename(path):
             check_add(path, os.path.basename(path))
@@ -124,9 +126,27 @@ class BugReportHandler(bbctrl.RequestHandler):
         check_add('config.json')
         check_add(ctrl.get_upload(ctrl.state.get('selected', '')))
 
+        return files
+
+
+    @run_on_executor
+    def task(self):
+        import tarfile, io
+
+        files = self.get_files()
+
+        buf = io.BytesIO()
+        tar = tarfile.open(mode = 'w:bz2', fileobj = buf)
+        for path, name in files: tar.add(path, name)
         tar.close()
 
-        self.write(buf.getvalue())
+        return buf.getvalue()
+
+
+    @gen.coroutine
+    def get(self):
+        res = yield self.task()
+        self.write(res)
 
 
     def set_default_headers(self):