From d504157c6f4f7f77fc789a4c39ed992467d7bcb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 11 Aug 2014 15:21:50 +0200 Subject: [PATCH 1/7] Added sanity check for extruder selection in gcode files Any T command targeting a number higher than the value specified in the settings for gcodeAnalysis.maxExtruders (defaults to 10) will be ignored and trigger a warning in the log file. Fix for #539 (cherry picked from commit 7d5c55f) --- src/octoprint/settings.py | 3 +++ src/octoprint/util/gcodeInterpreter.py | 37 ++++++++++++++------------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index db912c56..377634b3 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -65,6 +65,9 @@ default_settings = { "mobileSizeThreshold": 2 * 1024 * 1024, # 2MB "sizeThreshold": 20 * 1024 * 1024, # 20MB }, + "gcodeAnalysis": { + "maxExtruders": 10 + }, "feature": { "temperatureGraph": True, "waitForStartOnConnect": False, diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index a456ef1f..b901a12f 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -92,23 +92,26 @@ class gcode(object): T = getCodeInt(line, 'T') if T is not None: - posOffset[0] -= offsets[currentExtruder]["x"] if currentExtruder < len(offsets) else 0 - posOffset[1] -= offsets[currentExtruder]["y"] if currentExtruder < len(offsets) else 0 - - currentExtruder = T - - posOffset[0] += offsets[currentExtruder]["x"] if currentExtruder < len(offsets) else 0 - posOffset[1] += offsets[currentExtruder]["y"] if currentExtruder < len(offsets) else 0 - - if len(currentE) <= currentExtruder: - for i in range(len(currentE), currentExtruder + 1): - currentE.append(0.0) - if len(maxExtrusion) <= currentExtruder: - for i in range(len(maxExtrusion), currentExtruder + 1): - maxExtrusion.append(0.0) - if len(totalExtrusion) <= currentExtruder: - for i in range(len(totalExtrusion), currentExtruder + 1): - totalExtrusion.append(0.0) + if T > settings().getInt(["gcodeAnalysis", "maxExtruders"]): + self._logger.warn("GCODE tried to select tool %d, that looks wrong, ignoring for GCODE analysis" % T) + else: + posOffset[0] -= offsets[currentExtruder]["x"] if currentExtruder < len(offsets) else 0 + posOffset[1] -= offsets[currentExtruder]["y"] if currentExtruder < len(offsets) else 0 + + currentExtruder = T + + posOffset[0] += offsets[currentExtruder]["x"] if currentExtruder < len(offsets) else 0 + posOffset[1] += offsets[currentExtruder]["y"] if currentExtruder < len(offsets) else 0 + + if len(currentE) <= currentExtruder: + for i in range(len(currentE), currentExtruder + 1): + currentE.append(0.0) + if len(maxExtrusion) <= currentExtruder: + for i in range(len(maxExtrusion), currentExtruder + 1): + maxExtrusion.append(0.0) + if len(totalExtrusion) <= currentExtruder: + for i in range(len(totalExtrusion), currentExtruder + 1): + totalExtrusion.append(0.0) G = getCodeInt(line, 'G') if G is not None: From 389962687013e949e145fc147a9a2689dcd9e825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 11 Aug 2014 18:26:33 +0200 Subject: [PATCH 2/7] If a tool did not extrude anything, skip it in the filament usage summary Also targets #539 (cherry picked from commit dffa00d) --- src/octoprint/static/js/app/viewmodels/files.js | 4 +++- src/octoprint/static/js/app/viewmodels/printerstate.js | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/files.js b/src/octoprint/static/js/app/viewmodels/files.js index c3717abb..5bab23f3 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -201,7 +201,9 @@ function GcodeFilesViewModel(printerStateViewModel, loginStateViewModel) { } else { var i = 0; do { - output += "Filament (Tool " + i + "): " + formatFilament(data["gcodeAnalysis"]["filament"]["tool" + i]) + "
"; + if (filament["tool" + i].hasOwnProperty("length") && filament["tool" + i]["length"] > 0) { + output += "Filament (Tool " + i + "): " + formatFilament(filament["tool" + i]) + "
"; + } i++; } while (filament.hasOwnProperty("tool" + i)); } diff --git a/src/octoprint/static/js/app/viewmodels/printerstate.js b/src/octoprint/static/js/app/viewmodels/printerstate.js index c8e5eec1..09312c07 100644 --- a/src/octoprint/static/js/app/viewmodels/printerstate.js +++ b/src/octoprint/static/js/app/viewmodels/printerstate.js @@ -129,10 +129,12 @@ function PrinterStateViewModel(loginStateViewModel) { var i = 0; do { var key = "tool" + i; - result[i] = { - name: ko.observable("Tool " + i), - data: ko.observable(data.filament[key]) - }; + if (data.filament[key].hasOwnProperty("length") && data.filament[key].length > 0) { + result.push({ + name: ko.observable("Tool " + i), + data: ko.observable(data.filament[key]) + }); + } i++; } while (data.filament.hasOwnProperty("tool" + i)); } From 30e43f9c416b3994905337e11bb8cb171430bf71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 1 Feb 2015 17:27:12 +0100 Subject: [PATCH 3/7] Fixed a bug causing gcodeInterpreter to hiccup on GCODES containing invalid coordinates such as Xnan or Yinf, causing in turn the file API to fail until the offending file was deleted and its metadata removed (cherry picked from commit ce363ce) --- src/octoprint/util/gcodeInterpreter.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index b901a12f..9c3d05ae 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -249,13 +249,16 @@ def getCodeInt(line, code): def getCodeFloat(line, code): + import math n = line.find(code) + 1 if n < 1: return None m = line.find(' ', n) try: if m < 0: - return float(line[n:]) - return float(line[n:m]) + val = float(line[n:]) + else: + val = float(line[n:m]) + return val if not (math.isnan(val) or math.isinf(val)) else None except: return None From d8694107b7096834fc717be4bbd98f89cbf591de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 23 Mar 2015 10:08:01 +0100 Subject: [PATCH 4/7] Made metadata reading in client a bit more resilient against errors --- src/octoprint/static/js/app/viewmodels/printerstate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/static/js/app/viewmodels/printerstate.js b/src/octoprint/static/js/app/viewmodels/printerstate.js index 09312c07..61e0f2c2 100644 --- a/src/octoprint/static/js/app/viewmodels/printerstate.js +++ b/src/octoprint/static/js/app/viewmodels/printerstate.js @@ -129,7 +129,7 @@ function PrinterStateViewModel(loginStateViewModel) { var i = 0; do { var key = "tool" + i; - if (data.filament[key].hasOwnProperty("length") && data.filament[key].length > 0) { + if (data.filament.hasOwnProperty(key) && data.filament[key].hasOwnProperty("length") && data.filament[key].length > 0) { result.push({ name: ko.observable("Tool " + i), data: ko.observable(data.filament[key]) From 157408b53ad2a7087cfbefe4fd77a9f7a6358b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 23 Mar 2015 10:08:16 +0100 Subject: [PATCH 5/7] Back ported some documentation from devel --- docs/api/datamodel.rst | 351 +++++++++++++++++++++++++++++++++++++++++ docs/api/index.rst | 1 + docs/conf.py | 6 + 3 files changed, 358 insertions(+) create mode 100644 docs/api/datamodel.rst diff --git a/docs/api/datamodel.rst b/docs/api/datamodel.rst new file mode 100644 index 00000000..538a8f9d --- /dev/null +++ b/docs/api/datamodel.rst @@ -0,0 +1,351 @@ +.. _sec-api-datamodel: + +***************** +Common data model +***************** + +.. contents:: + +.. _sec-api-datamodel-printer: + +Printer related +=============== + +.. _sec-api-datamodel-printer-state: + +Printer State +------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``text`` + - 1 + - String + - A textual representation of the current state of the printer, e.g. "Operational" or "Printing" + * - ``flags`` + - 1 + - Printer state flags + - A couple of boolean printer state flags + * - ``flags.operational`` + - 1 + - Boolean + - ``true`` if the printer is operational, ``false`` otherwise + * - ``flags.paused`` + - 1 + - Boolean + - ``true`` if the printer is currently paused, ``false`` otherwise + * - ``flags.printing`` + - 1 + - Boolean + - ``true`` if the printer is currently printing, ``false`` otherwise + * - ``flags.sdReady`` + - 1 + - Boolean + - ``true`` if the printer's SD card is available and initialized, ``false`` otherwise. This is redundant information + to :ref:`the SD State `. + * - ``flags.error`` + - 1 + - Boolean + - ``true`` if an unrecoverable error occurred, ``false`` otherwise + * - ``flags.ready`` + - 1 + - Boolean + - ``true`` if the printer is operational and no data is currently being streamed to SD, so ready to receive instructions + * - ``flags.closedOrError`` + - 1 + - Boolean + - ``true`` if the printer is disconnected (possibly due to an error), ``false`` otherwise + +.. _sec-api-datamodel-printer-tempdata: + +Temperature Data +---------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``actual`` + - 1 + - Number + - Current temperature + * - ``target`` + - 1 + - Number + - Target temperature, may be ``null`` if no target temperature is set. + * - ``offset`` + - 0..1 + - Number + - Currently configured temperature offset to apply, will be left out for historic temperature information. + +.. _sec-api-datamodel-printer-temphistory: + +Historic Temperature Data Point +------------------------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``time`` + - 1 + - Unix Timestamp + - Timestamp of this data point + * - ``tool{n}`` + - 0..* + - :ref:`Temperature Data ` + - Temperature stats for tool *n*. Enumeration starts at 0 for the first tool. Not included if querying only + bed state. + * - ``bed`` + - 0..* + - :ref:`Temperature Data ` + - Temperature stats for the printer's heated bed. Not included if querying only tool state. + +.. _sec-api-datamodel-printer-tempoffset: + +Temperature offset +------------------ + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``tool{n}`` + - 0..1 + - Number + - Temperature offset for tool *n*. Enumeration starts at 0 for the first tool. + * - ``bed`` + - 0..1 + - Number + - Temperature offset for the printer's heated bed. + + +.. _sec-api-datamodel-jobs: + +Job related +=========== + +.. _sec-api-datamodel-jobs-job: + +Job information +--------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``file`` + - 1 + - :ref:`File information (abridged) ` + - The file that is the target of the current print job + * - ``estimatedPrintTime`` + - 0..1 + - Integer + - The estimated print time for the file, in seconds. + * - ``lastPrintTime`` + - 0..1 + - Integer + - The print time of the last print of the file, in seconds. + * - ``filament`` + - 0..1 + - Object + - Information regarding the estimated filament usage of the print job + * - ``filament.length`` + - 0..1 + - Integer + - Length of filament used, in mm + * - ``filament.volume`` + - 0..1 + - Float + - Volume of filament used, in cm³ + +.. _sec-api-datamodel-jobs-progress: + +Progress information +-------------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``completion`` + - 1 + - Float + - Percentage of completion of the current print job + * - ``filepos`` + - 1 + - Integer + - Current position in the file being printed, in bytes from the beginning + * - ``printTime`` + - 1 + - Integer + - Time already spent printing, in seconds + * - ``printTimeLeft`` + - 1 + - Integer + - Estimate of time left to print, in seconds + +.. _sec-api-datamodel-files: + +File related +============ + +.. _sec-api-datamodel-files-file: + +File information +---------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``name`` + - 1 + - String + - The name of the file + * - ``size`` + - 0..1 + - Number + - The size of the file in bytes. Only available for ``local`` files. + * - ``date`` + - 0..1 + - Unix timestamp + - The timestamp when this file was uploaded. Only available for ``local`` files. + * - ``origin`` + - 1 + - String, either ``local`` or ``sdcard`` + - The origin of the file, ``local`` when stored in OctoPrint's ``uploads`` folder, ``sdcard`` when stored on the + printer's SD card (if available) + * - ``refs`` + - 0..1 + - :ref:`sec-api-datamodel-files-ref` + - References relevant to this file, left out in abridged version + * - ``gcodeAnalysis`` + - 0..1 + - :ref:`GCODE analysis information ` + - Information from the analysis of the GCODE file, if available. Left out in abridged version. + * - ``prints`` + - 0..1 + - :ref:`Print history ` + - Information regarding prints of this file, if available. Left out in abridged version. + +.. _sec-api-datamodel-files-gcodeanalysis: + +GCODE analysis information +-------------------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``estimatedPrintTime`` + - 0..1 + - Integer + - The estimated print time of the file, in seconds + * - ``filament`` + - 0..1 + - Object + - The estimated usage of filament + * - ``filament.length`` + - 0..1 + - Integer + - The length of filament used, in mm + * - ``filament.volume`` + - 0..1 + - Float + - The volume of filament used, in cm³ + + +.. _sec-api-datamodel-files-prints: + +Print history +------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``failure`` + - 1 + - Number + - The number of failed prints on record for the file + * - ``success`` + - 1 + - Number + - The number of successful prints on record for the file + * - ``last`` + - 0..1 + - Object + - Information regarding the last print on record for the file + * - ``last.date`` + - 1 + - Unix timestamp + - Timestamp when this file was printed last + * - ``last.success`` + - 1 + - Boolean + - Whether the last print on record was a success (``true``) or not (``false``) + +.. _sec-api-datamodel-files-ref: + +References +---------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``resource`` + - 1 + - URL + - The resource that represents the file (e.g. for issuing commands to or for deleting) + * - ``download`` + - 0..1 + - URL + - The download URL for the file + * - ``model`` + - 0..1 + - URL + - The model from which this file was generated (e.g. an STL, currently not used) diff --git a/docs/api/index.rst b/docs/api/index.rst index 92a81195..9de648c0 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -14,3 +14,4 @@ API Documentation printer.rst job.rst logs.rst + datamodel.rst \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 73af7be0..19736370 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,6 +12,12 @@ # serve to show the default. import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath('../src/')) + import octoprint._version from datetime import date From 809c452285b60cfabcfc34e62ac222183aab273f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 23 Mar 2015 10:43:42 +0100 Subject: [PATCH 6/7] Preparing release of 1.1.2 --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b48dc78..157ae80e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # OctoPrint Changelog -## 1.1.2 (Unreleased) +## 1.1.2 (2015-03-23) ### Improvements @@ -11,6 +11,8 @@ ### Bug Fixes +* [#539](https://github.com/foosel/OctoPrint/issues/539) - Limit maximum number of tools, sanity check tool numbers in + GCODE files against upper limit and refuse to create 10000 tools due to weird slicers. (backported from `devel`) * [#634](https://github.com/foosel/OctoPrint/pull/634) - Fixed missing `branch` fields in version dicts generated by versioneer * [#679](https://github.com/foosel/OctoPrint/issues/679) - Fix error where API state is requested and printer is offline @@ -24,6 +26,8 @@ * [unreported] & [#698](https://github.com/foosel/OctoPrint/issues/698) - Generated URLs now take X-Forwarded-Host header sent by proxies into account for included host and port, also fixed [#698](https://github.com/foosel/OctoPrint/issues/698) introduced by this +* [unreported] Fixed a bug causing gcodeInterpreter to hiccup on GCODES containing invalid coordinates such as Xnan or + Yinf (backported from `devel`) * Small fixes for timelapse creation: - [#344](https://github.com/foosel/OctoPrint/issues/344) - Made timelapses capable of coping with missing captures in between by decrementing the image counter again if there was an error fetching the latest image from the snapshot URL (backport of [1a7a468](https://github.com/foosel/OctoPrint/commit/1a7a468eb65fdf2a13b4c7a7723280e822c9c34b) From 7affce2f64ee9b294401b5b04925fe719b5714bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 23 Mar 2015 10:49:35 +0100 Subject: [PATCH 7/7] Forgot to fix the Commit link --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 157ae80e..5ca36496 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ - [unreported] Synchronize image counter decrementing as well as incrementing to prevent rare race conditions when generating the image file names -([Commits](https://github.com/foosel/OctoPrint/compare/1.1.1...master)) +([Commits](https://github.com/foosel/OctoPrint/compare/1.1.1...1.1.2)) ## 1.1.1 (2014-10-27)