report error message when a command was not taken
authorDaniel Dumitru <dandumit@gmail.com>
Sat, 4 May 2013 07:52:47 +0000 (10:52 +0300)
committerDaniel Dumitru <dandumit@gmail.com>
Sat, 4 May 2013 07:52:47 +0000 (10:52 +0300)
adds a method to GCode object to flag when object was taken by a module

12 files changed:
ConfigSamples/Smoothieboard/config
src/libs/SlowTicker.cpp
src/modules/communication/GcodeDispatch.cpp
src/modules/communication/GcodeDispatch.h
src/modules/communication/utils/Gcode.cpp
src/modules/communication/utils/Gcode.h
src/modules/robot/Robot.cpp
src/modules/robot/Stepper.cpp
src/modules/tools/endstops/Endstops.cpp
src/modules/tools/extruder/Extruder.cpp
src/modules/tools/switch/Switch.cpp
src/modules/tools/temperaturecontrol/TemperatureControl.cpp

index 73ff969..5d47008 100644 (file)
@@ -132,3 +132,6 @@ panel.encoder_b_pin                          0.17!            #
 
 # Only needed on a smoothieboard
 currentcontrol_module_enable                 true             #
+
+return_error_on_unhandled_gcode              true             #
+
index 36519ae..3e110d0 100644 (file)
@@ -153,6 +153,7 @@ void SlowTicker::on_gcode_execute(void* argument){
 
     if (gcode->has_g){
         if (gcode->g == 4){
+            gcode->mark_as_taken();
             bool updated = false;
             if (gcode->has_letter('P')) {
                 updated = true;
index 731a8a4..4ac2c30 100644 (file)
@@ -20,6 +20,11 @@ GcodeDispatch::GcodeDispatch(){}
 
 // Called when the module has just been loaded
 void GcodeDispatch::on_module_loaded() {
+    if( this->kernel->config->value( return_error_on_unhandled_gcode_checksum )->by_default(false)->as_bool() == false )
+        return_error_on_unhandled_gcode = false;
+    else 
+        return_error_on_unhandled_gcode = true;
+
     this->register_for_event(ON_CONSOLE_LINE_RECEIVED);
     currentline = -1;
 }
@@ -100,7 +105,10 @@ void GcodeDispatch::on_console_line_received(void * line){
                 this->kernel->call_event(ON_GCODE_RECEIVED, gcode );
                 if (gcode->add_nl)
                     new_message.stream->printf("\r\n");
-                new_message.stream->printf("ok\r\n");
+                if ( return_error_on_unhandled_gcode == true && gcode->accepted_by_module == false)
+                    new_message.stream->printf("error: Command hasn't been processed.\r\n");
+                else
+                    new_message.stream->printf("ok\r\n");
 
                 delete gcode;
             
index 6292ffd..0c4ceb9 100644 (file)
@@ -15,6 +15,7 @@ using std::string;
 #include "utils/Gcode.h"
 
 #include "libs/StreamOutput.h"
+#define return_error_on_unhandled_gcode_checksum    CHECKSUM("return_error_on_unhandled_gcode")
 
 class GcodeDispatch : public Module {
     public:
@@ -22,6 +23,7 @@ class GcodeDispatch : public Module {
         
         virtual void on_module_loaded();
         virtual void on_console_line_received(void* line);
+        bool return_error_on_unhandled_gcode;
     private:
         int currentline;
 };
index 9481bd3..1979934 100644 (file)
@@ -19,6 +19,7 @@ using std::string;
 Gcode::Gcode(const string& command, StreamOutput* stream) : command(command), m(0), g(0), add_nl(false), stream(stream) {
     prepare_cached_values();
     this->millimeters_of_travel = 0L;
+    this->accepted_by_module=false;
 }
 
 Gcode::Gcode(const Gcode& to_copy){
@@ -30,6 +31,7 @@ Gcode::Gcode(const Gcode& to_copy){
     this->g                     = to_copy.g;
     this->add_nl                = to_copy.add_nl;
     this->stream                = to_copy.stream;
+    this->accepted_by_module=false;
 }
 
 Gcode& Gcode::operator= (const Gcode& to_copy){
@@ -43,6 +45,7 @@ Gcode& Gcode::operator= (const Gcode& to_copy){
         this->add_nl                = to_copy.add_nl;
         this->stream                = to_copy.stream;
     }
+    this->accepted_by_module=false;
     return *this;
 }
 
@@ -116,3 +119,7 @@ void Gcode::prepare_cached_values(){
         this->has_m = false;
     }
 }
+
+void Gcode::mark_as_taken(){
+    this->accepted_by_module = true;
+}
\ No newline at end of file
index 0edfbc1..0cf2172 100644 (file)
@@ -29,6 +29,7 @@ class Gcode {
 
         int    get_num_args();
         void   prepare_cached_values();
+        void   mark_as_taken();
 
         string command;
         double millimeters_of_travel;
@@ -41,6 +42,7 @@ class Gcode {
         bool add_nl;
         StreamOutput* stream;
 
+        bool accepted_by_module;
 
 };
 #endif
index 1ea77eb..e6b9b18 100644 (file)
@@ -115,17 +115,17 @@ void Robot::on_gcode_received(void * argument){
    //G-letter Gcodes are mostly what the Robot module is interrested in, other modules also catch the gcode event and do stuff accordingly
     if( gcode->has_g){
         switch( gcode->g ){
-            case 0:  this->motion_mode = MOTION_MODE_SEEK; break;
-            case 1:  this->motion_mode = MOTION_MODE_LINEAR; break;
-            case 2:  this->motion_mode = MOTION_MODE_CW_ARC; break;
-            case 3:  this->motion_mode = MOTION_MODE_CCW_ARC; break;
-            case 17: this->select_plane(X_AXIS, Y_AXIS, Z_AXIS); break;
-            case 18: this->select_plane(X_AXIS, Z_AXIS, Y_AXIS); break;
-            case 19: this->select_plane(Y_AXIS, Z_AXIS, X_AXIS); break;
-            case 20: this->inch_mode = true; break;
-            case 21: this->inch_mode = false; break;
-            case 90: this->absolute_mode = true; break;
-            case 91: this->absolute_mode = false; break;
+            case 0:  this->motion_mode = MOTION_MODE_SEEK; gcode->mark_as_taken(); break;
+            case 1:  this->motion_mode = MOTION_MODE_LINEAR; gcode->mark_as_taken();  break;
+            case 2:  this->motion_mode = MOTION_MODE_CW_ARC; gcode->mark_as_taken();  break;
+            case 3:  this->motion_mode = MOTION_MODE_CCW_ARC; gcode->mark_as_taken();  break;
+            case 17: this->select_plane(X_AXIS, Y_AXIS, Z_AXIS); gcode->mark_as_taken();  break;
+            case 18: this->select_plane(X_AXIS, Z_AXIS, Y_AXIS); gcode->mark_as_taken();  break;
+            case 19: this->select_plane(Y_AXIS, Z_AXIS, X_AXIS); gcode->mark_as_taken();  break;
+            case 20: this->inch_mode = true; gcode->mark_as_taken();  break;
+            case 21: this->inch_mode = false; gcode->mark_as_taken();  break;
+            case 90: this->absolute_mode = true; gcode->mark_as_taken();  break;
+            case 91: this->absolute_mode = false; gcode->mark_as_taken();  break;
             case 92: {
                 if(gcode->get_num_args() == 0){
                     clear_vector(this->last_milestone);
@@ -137,6 +137,7 @@ void Robot::on_gcode_received(void * argument){
                 }
                 memcpy(this->current_position, this->last_milestone, sizeof(double)*3); // current_position[] = last_milestone[];
                 this->arm_solution->millimeters_to_steps(this->current_position, this->kernel->planner->position);
+                gcode->mark_as_taken();
                 return; // TODO: Wait until queue empty
            }
        }
@@ -158,14 +159,17 @@ void Robot::on_gcode_received(void * argument){
                 this->arm_solution->millimeters_to_steps(this->current_position, this->kernel->planner->position);
                 gcode->stream->printf("X:%g Y:%g Z:%g F:%g ", steps[0], steps[1], steps[2], seconds_per_minute);
                 gcode->add_nl = true;
+                gcode->mark_as_taken();
                 return;
             case 114: gcode->stream->printf("C: X:%1.3f Y:%1.3f Z:%1.3f ",
                                                  from_millimeters(this->current_position[0]),
                                                  from_millimeters(this->current_position[1]),
                                                  from_millimeters(this->current_position[2]));
                 gcode->add_nl = true;
+                gcode->mark_as_taken();
                 return;
             case 220: // M220 - speed override percentage
+                gcode->mark_as_taken();
                 if (gcode->has_letter('S'))
                 {
                     double factor = gcode->get_value('S');
index fe346ce..d6725f1 100644 (file)
@@ -89,9 +89,11 @@ void Stepper::on_gcode_execute(void* argument){
     if( gcode->has_m){
         if( gcode->m == 17 ){
             this->turn_enable_pins_on();
+            gcode->mark_as_taken();
         }
         if( gcode->m == 84 || gcode->m == 18 ){
             this->turn_enable_pins_off();
+            gcode->mark_as_taken();
         }
     }
 }
index 2fea0f1..506bfa0 100644 (file)
@@ -109,6 +109,7 @@ void Endstops::on_gcode_received(void* argument)
     {
         if( gcode->g == 28 )
         {
+            gcode->mark_as_taken();
             // G28 is received, we have homing to do
 
             // First wait for the queue to be empty
@@ -193,6 +194,7 @@ void Endstops::on_gcode_received(void* argument)
         switch(gcode->m){
             case 119:
                 gcode->stream->printf("X min:%d max:%d Y min:%d max:%d Z min:%d max:%d\n", this->pins[0].get(), this->pins[3].get(), this->pins[1].get(), this->pins[4].get(), this->pins[2].get(), this->pins[5].get() );
+                gcode->mark_as_taken();
                 break;
         }
     }
index 8ac4e32..ebf8f45 100644 (file)
@@ -100,6 +100,7 @@ void Extruder::on_gcode_received(void *argument){
         if (gcode->m == 114){
             gcode->stream->printf("E:%4.1f ", this->current_position);
             gcode->add_nl = true;
+            gcode->mark_as_taken();
         }
         if (gcode->m == 92 ){
             double spm = this->steps_per_millimeter;
@@ -107,11 +108,13 @@ void Extruder::on_gcode_received(void *argument){
                 spm = gcode->get_value('E');
             gcode->stream->printf("E:%g ", spm);
             gcode->add_nl = true;
+            gcode->mark_as_taken();
         }
     }
 
     // Gcodes to pass along to on_gcode_execute
     if( ( gcode->has_m && ( gcode->m == 82 || gcode->m == 83 || gcode->m == 84 || gcode->m == 92 ) ) || ( gcode->has_g && gcode->g == 92 && gcode->has_letter('E') ) || ( gcode->has_g && ( gcode->g == 90 || gcode->g == 91 ) ) ){
+        gcode->mark_as_taken();
         if( this->kernel->conveyor->queue.size() == 0 ){
             this->kernel->call_event(ON_GCODE_EXECUTE, gcode );
         }else{
@@ -178,6 +181,7 @@ void Extruder::on_gcode_execute(void* argument){
     if( gcode->has_g ){
         // G92: Reset extruder position
         if( gcode->g == 92 ){
+            gcode->mark_as_taken();
             if( gcode->has_letter('E') ){
                 this->current_position = gcode->get_value('E');
                 this->target_position  = this->current_position;
index 3aae715..443f180 100644 (file)
@@ -48,6 +48,7 @@ void Switch::on_gcode_received(void* argument){
     Gcode* gcode = static_cast<Gcode*>(argument);
     // Add the gcode to the queue ourselves if we need it
     if( gcode->has_m && ( gcode->m == this->on_m_code || gcode->m == this->off_m_code ) ){
+        gcode->mark_as_taken();
         if( this->kernel->conveyor->queue.size() == 0 ){
             this->kernel->call_event(ON_GCODE_EXECUTE, gcode );
         }else{
index 1c56728..07b3fec 100644 (file)
@@ -128,6 +128,7 @@ void TemperatureControl::on_gcode_received(void* argument){
         }
         if (gcode->m == 301)
         {
+            gcode->mark_as_taken();
             if (gcode->has_letter('S') && (gcode->get_value('S') == this->pool_index))
             {
                 if (gcode->has_letter('P'))
@@ -143,6 +144,7 @@ void TemperatureControl::on_gcode_received(void* argument){
         }
         if (gcode->m == 303)
         {
+            gcode->mark_as_taken();
             if (gcode->has_letter('S') && (gcode->get_value('S') == this->pool_index))
             {
                 double target = 150.0;
@@ -188,6 +190,7 @@ void TemperatureControl::on_gcode_execute(void* argument){
 
                 if( gcode->m == this->set_and_wait_m_code)
                 {
+                    gcode->mark_as_taken();
                     this->kernel->pauser->take();
                     this->waiting = true;
                 }