From: <adr...@us...> - 2010-07-31 17:04:21
|
Revision: 3670 http://reprap.svn.sourceforge.net/reprap/?rev=3670&view=rev Author: adrian-bowyer Date: 2010-07-31 17:04:15 +0000 (Sat, 31 Jul 2010) Log Message: ----------- Working on tidying the error flagging between the machine and the host software. Don't check this revision out - it has bugs. Modified Paths: -------------- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.pde trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/cartesian_dda.h trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.h trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.pde trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/intercom.pde trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde 2010-07-31 17:03:28 UTC (rev 3669) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde 2010-07-31 17:04:15 UTC (rev 3670) @@ -4,6 +4,7 @@ #include "WProgram.h" #include "vectors.h" #include "configuration.h" +#include "hostcom.h" #include "intercom.h" #include "pins.h" #include "Temperature.h" @@ -43,11 +44,7 @@ extruder* ex[EXTRUDER_COUNT]; byte extruder_in_use = 0; -// Text placed in this (terminated with 0) will be transmitted back to the host -// along with the next G Code acknowledgement. -char debugstring[COMMAND_SIZE]; - // Old Mothers... #if MOTHERBOARD == 1 @@ -98,6 +95,8 @@ #endif +hostcom talkToHost; + // Each entry in the buffer is an instance of cartesian_dda. cartesian_dda* cdda[BUFFER_SIZE]; @@ -144,7 +143,6 @@ setupTimerInterrupt(); interruptBlink = 0; pinMode(DEBUG_PIN, OUTPUT); - debugstring[0] = 0; led = false; setupGcodeProcessor(); @@ -170,9 +168,7 @@ init_process_string(); - - Serial.begin(HOST_BAUD); - Serial.println("start"); + talkToHost.start(); #if MOTHERBOARD == 2 pinMode(PS_ON_PIN, OUTPUT); // add to run G3 as built by makerbot @@ -192,17 +188,14 @@ void shutdown() { - // No more stepping + // No more stepping or other interrupts - disableTimerInterrupt(); + cli(); // Delete everything in the ring buffer cancelAndClearQueue(); - // LED off - - digitalWrite(DEBUG_PIN, 0); // Motors off @@ -216,7 +209,21 @@ for(byte i = 0; i < EXTRUDER_COUNT; i++) ex[i]->shutdown(); + +// If we run the bed, turn it off. + +#if MOTHERBOARD != 2 + heatedBed.shutdown(); +#endif + +// int a=50; +// while(a--) {blink(); delay(50);} + // LED off + + digitalWrite(DEBUG_PIN, 0); + + // Till the end of time... for(;;); Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.pde =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.pde 2010-07-31 17:03:28 UTC (rev 3669) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.pde 2010-07-31 17:04:15 UTC (rev 3670) @@ -121,12 +121,12 @@ } } -// TODO: Should use debugstring[] +// This is a fatal error - something is wrong with the heater. void bed::temperatureError() { - Serial.print("E: "); - Serial.println(getTemperature()); + sprintf(talkToHost.string(), "Bed temperature not rising - hard fault."); + talkToHost.setFatal(); } #endif Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/cartesian_dda.h =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/cartesian_dda.h 2010-07-31 17:03:28 UTC (rev 3669) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/cartesian_dda.h 2010-07-31 17:04:15 UTC (rev 3670) @@ -131,21 +131,18 @@ inline void cartesian_dda::do_x_step() { digitalWrite(X_STEP_PIN, HIGH); - //delayMicrosecondsInterruptible(5); digitalWrite(X_STEP_PIN, LOW); } inline void cartesian_dda::do_y_step() { digitalWrite(Y_STEP_PIN, HIGH); - //delayMicrosecondsInterruptible(5); digitalWrite(Y_STEP_PIN, LOW); } inline void cartesian_dda::do_z_step() { digitalWrite(Z_STEP_PIN, HIGH); - //delayMicrosecondsInterruptible(5); digitalWrite(Z_STEP_PIN, LOW); } @@ -176,7 +173,6 @@ //stop us if we're home and still going lower #if ENDSTOPS_MIN_ENABLED == 1 -//#if X_MIN_PIN >= 0 #if X_ENDSTOP_INVERTING if(!dir && !digitalRead(X_MIN_PIN) ) return false; @@ -184,13 +180,11 @@ if(!dir && digitalRead(X_MIN_PIN) ) return false; #endif -//#endif #endif //stop us if we're at max and still going higher #if ENDSTOPS_MAX_ENABLED == 1 -//#if X_MAX_PIN >= 0 #if X_ENDSTOP_INVERTING if(dir && !digitalRead(X_MAX_PIN) ) return false; @@ -198,7 +192,6 @@ if(!dir && digitalRead(X_MAX_PIN) ) return false; #endif -//#endif #endif // All OK - we can step @@ -216,7 +209,6 @@ //stop us if we're home and still going lower #if ENDSTOPS_MIN_ENABLED == 1 -//#if Y_MIN_PIN >= 0 #if Y_ENDSTOP_INVERTING if(!dir && !digitalRead(Y_MIN_PIN) ) return false; @@ -224,13 +216,11 @@ if(!dir && digitalRead(Y_MIN_PIN) ) return false; #endif -//#endif #endif //stop us if we're at max and still going higher #if ENDSTOPS_MAX_ENABLED == 1 -//#if Y_MAX_PIN >= 0 #if Y_ENDSTOP_INVERTING if(dir && !digitalRead(Y_MAX_PIN) ) return false; @@ -238,7 +228,6 @@ if(!dir && digitalRead(Y_MAX_PIN) ) return false; #endif -//#endif #endif // All OK - we can step @@ -256,7 +245,6 @@ //stop us if we're home and still going lower #if ENDSTOPS_MIN_ENABLED == 1 -//#if Z_MIN_PIN >= 0 #if Z_ENDSTOP_INVERTING if(!dir && !digitalRead(Z_MIN_PIN) ) return false; @@ -264,13 +252,11 @@ if(!dir && digitalRead(Z_MIN_PIN) ) return false; #endif -//#endif #endif //stop us if we're at max and still going higher #if ENDSTOPS_MAX_ENABLED == 1 -//#if Z_MAX_PIN >= 0 #if Z_ENDSTOP_INVERTING if(dir && !digitalRead(Z_MAX_PIN) ) return false; @@ -278,7 +264,6 @@ if(!dir && digitalRead(Z_MAX_PIN) ) return false; #endif -//#endif #endif // All OK - we can step Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.h =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.h 2010-07-31 17:03:28 UTC (rev 3669) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.h 2010-07-31 17:04:15 UTC (rev 3670) @@ -413,7 +413,6 @@ inline void extruder::sStep() { digitalWrite(motor_step_pin, HIGH); - //delayMicrosecondsInterruptible(5); digitalWrite(motor_step_pin, LOW); } Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.pde =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.pde 2010-07-31 17:03:28 UTC (rev 3669) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.pde 2010-07-31 17:04:15 UTC (rev 3670) @@ -74,12 +74,12 @@ } } -// TODO: Should use debugstring[] +// This is a fatal error - something is wrong with the heater. void extruder::temperatureError() { - Serial.print("E: "); - Serial.println(getTemperature()); + sprintf(talkToHost.string(), "Extruder temperature not rising - hard fault."); + talkToHost.setFatal(); } /*************************************************************************************************************************** Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/intercom.pde =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/intercom.pde 2010-07-31 17:03:28 UTC (rev 3669) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/intercom.pde 2010-07-31 17:04:15 UTC (rev 3670) @@ -419,7 +419,7 @@ { outPointer = 0; #if RS485_MASTER == 1 - strcpy(debugstring, "E1"); + sprintf(talkToHost.string(), "intercom::outputBufferOverflow()"); #endif } @@ -430,7 +430,7 @@ { resetInput(); #if RS485_MASTER == 1 - strcpy(debugstring, "E2"); + sprintf(talkToHost.string(), "intercom::inputBufferOverflow()"); #endif } @@ -440,7 +440,7 @@ void intercom::talkCollision() { #if RS485_MASTER == 1 - strcpy(debugstring, "E3"); + sprintf(talkToHost.string(), "intercom::talkCollision()"); #endif } @@ -450,7 +450,7 @@ void intercom::listenCollision() { #if RS485_MASTER == 1 - strcpy(debugstring, "E4"); + sprintf(talkToHost.string(), "intercom::listenCollision()"); #endif } @@ -459,7 +459,7 @@ void intercom::queueCollision() { #if RS485_MASTER == 1 - strcpy(debugstring, "E5"); + sprintf(talkToHost.string(), "intercom::queueCollision()"); #endif } @@ -468,7 +468,7 @@ void intercom::corrupt() { #if RS485_MASTER == 1 - strcpy(debugstring, "E6"); + sprintf(talkToHost.string(), "intercom::corrupt()"); #endif } @@ -479,7 +479,7 @@ { state = RS485_TALK_TIMEOUT; #if RS485_MASTER == 1 - strcpy(debugstring, "E7"); + sprintf(talkToHost.string(), "intercom::talkTimeout()"); #endif } @@ -489,7 +489,7 @@ { state = RS485_LISTEN_TIMEOUT; #if RS485_MASTER == 1 - strcpy(debugstring, "E8"); + sprintf(talkToHost.string(), "intercom::listenTimeout()"); #endif } @@ -498,14 +498,14 @@ void intercom::waitTimeout() { #if RS485_MASTER == 1 - strcpy(debugstring, "E9"); + sprintf(talkToHost.string(), "intercom::waitTimeout()"); #endif } void intercom::queueError() { #if RS485_MASTER == 1 - strcpy(debugstring, "EA"); + sprintf(talkToHost.string(), "intercom::queueError()"); #endif } @@ -513,7 +513,7 @@ void intercom::waitError() { #if RS485_MASTER == 1 - strcpy(debugstring, "EB"); + sprintf(talkToHost.string(), "intercom::waitError()"); #endif } @@ -521,8 +521,7 @@ void intercom::checksumError() { #if RS485_MASTER == 1 - strcpy(debugstring, "EC "); - strcat(debugstring, inBuffer); + sprintf(talkToHost.string(), "intercom::checksumError(): %s", inBuffer); #endif } @@ -530,8 +529,7 @@ void intercom::ackError() { #if RS485_MASTER == 1 - strcpy(debugstring, "ED "); - strcat(debugstring, inBuffer); + sprintf(talkToHost.string(), "intercom::ackError(): %s", inBuffer); #endif } Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde 2010-07-31 17:03:28 UTC (rev 3669) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde 2010-07-31 17:04:15 UTC (rev 3670) @@ -83,7 +83,7 @@ byte serial_count = 0; boolean comment = false; // Serial error buffer -char seBuffer[100]; +//char seBuffer[100]; FloatPoint fp; FloatPoint sp; @@ -222,10 +222,8 @@ cmdbuffer[serial_count] = 0; if(SendDebug & DEBUG_ECHO) - { - Serial.print("Echo:"); - Serial.println(cmdbuffer); - } + sprintf(talkToHost.string(), "Echo: %s", cmdbuffer); + //process our command! process_string(cmdbuffer, serial_count); @@ -234,13 +232,16 @@ // Say we're ready for the next one - if(debugstring[0] != 0 && (SendDebug & DEBUG_INFO)) + talkToHost.sendMessage(SendDebug & DEBUG_INFO); + + /* if(debugstring[0] != 0 && (SendDebug & DEBUG_INFO)) { Serial.print("ok "); Serial.println(debugstring); debugstring[0] = 0; } else Serial.println("ok"); +*/ } } @@ -314,31 +315,16 @@ if(SendDebug & DEBUG_ERRORS) { if(gc.seen & GCODE_CHECKSUM) - { - Serial.print("Serial Error: checksum without line number. Checksum: "); - Serial.flush(); - itoa(gc.Checksum, seBuffer, 10); - Serial.print(seBuffer); - Serial.flush(); - Serial.print(", line received: "); - Serial.println(instruction); - } else - { - Serial.print("Serial Error: line number without checksum. Linenumber: "); - Serial.flush(); - ltoa(gc.LastLineNrRecieved+1, seBuffer, 10); - Serial.print(seBuffer); - Serial.flush(); - Serial.print(", line received: "); - Serial.println(instruction); - } + sprintf(talkToHost.string(), "Serial Error: checksum without line number. Checksum: %d, line received: %s", gc.Checksum, instruction); + else + sprintf(talkToHost.string(), "Serial Error: line number without checksum. Linenumber: %d, line received: %s", gc.N, instruction); } - FlushSerialRequestResend(); + talkToHost.setResend(gc.LastLineNrRecieved+1); return; } // Check checksum of this string. Flush buffers and re-request line of error is found if(gc.seen & GCODE_CHECKSUM) // if we recieved a line nr, we know we also recieved a Checksum, so check it - { + { // Calc checksum. byte checksum = 0; byte count=0; @@ -346,48 +332,21 @@ checksum = checksum^instruction[count++]; // Check checksum. if(gc.Checksum != (int)checksum) - { + { if(SendDebug & DEBUG_ERRORS) - { - Serial.print("Serial Error: checksum mismatch. Remote ("); - Serial.flush(); - itoa(gc.Checksum, seBuffer, 10); - Serial.print(seBuffer); - Serial.flush(); - Serial.print(") not equal to local ("); - Serial.flush(); - itoa((int)checksum, seBuffer, 10); - Serial.print(seBuffer); - Serial.flush(); - Serial.print("), line received: "); - Serial.flush(); - Serial.println(instruction); - } - FlushSerialRequestResend(); + sprintf(talkToHost.string(), "Serial Error: checksum mismatch. Remote (%d) not equal to local (%d), line received: %s", gc.Checksum, (int)checksum, instruction); + talkToHost.setResend(gc.LastLineNrRecieved+1); return; - } + } // Check that this lineNr is LastLineNrRecieved+1. If not, flush if(!( (bool)(gc.seen & GCODE_M) && gc.M == 110)) // unless this is a reset-lineNr command if(gc.N != gc.LastLineNrRecieved+1) - { + { if(SendDebug & DEBUG_ERRORS) - { - Serial.print("Serial Error: Linenumber ("); - Serial.flush(); - itoa(gc.N, seBuffer, 10); - Serial.print(seBuffer); - Serial.flush(); - Serial.print(") is not last + 1 ("); - Serial.flush(); - itoa(gc.LastLineNrRecieved+1, seBuffer, 10); - Serial.print(seBuffer); - Serial.flush(); - Serial.print("), line received: "); - Serial.println(instruction); - } - FlushSerialRequestResend(); + sprintf(talkToHost.string(), "Serial Error: Linenumber (%d) is not last + 1 (%d), line received: %s", gc.N, gc.LastLineNrRecieved+1, instruction); + talkToHost.setResend(gc.LastLineNrRecieved+1); return; - } + } //If we reach this point, communication is a succes, update our "last good line nr" and continue gc.LastLineNrRecieved = gc.N; } @@ -532,11 +491,8 @@ default: if(SendDebug & DEBUG_ERRORS) - { - Serial.print("huh? G"); - Serial.println(gc.G, DEC); - FlushSerialRequestResend(); - } + sprintf(talkToHost.string(), "Dud G code: G%d", gc.G); + talkToHost.setResend(gc.LastLineNrRecieved+1); } } @@ -595,16 +551,12 @@ //custom code for temperature reading case 105: - Serial.print("T:"); - Serial.print(ex[extruder_in_use]->getTemperature()); + talkToHost.setETemp(ex[extruder_in_use]->getTemperature()); #if MOTHERBOARD == 2 - Serial.print(" B:"); - Serial.println(ex[0]->getBedTemperature()); + talkToHost.setBTemp(ex[0]->getBedTemperature()); #else - Serial.print(" B:"); - Serial.println(heatedBed.getTemperature()); // TODO: bed temp needed + talkToHost.setBTemp(heatedBed.getTemperature()); #endif - break; //turn fan on @@ -626,22 +578,13 @@ // Starting a new print, reset the gc.LastLineNrRecieved counter case 110: if (gc.seen & GCODE_N) - { gc.LastLineNrRecieved = gc.N; - if(SendDebug & DEBUG_INFO) - Serial.println("DEBUG:LineNr set"); - } break; case 111: SendDebug = gc.S; break; case 112: // STOP! - { - int a=50; - while(a--) - {blink(); delay(50);} - } - cancelAndClearQueue(); + shutdown(); break; // If there's an S field, use that to set the PWM, otherwise use the pot. @@ -657,14 +600,7 @@ //custom code for returning current coordinates case 114: - Serial.print("C: X"); - Serial.print(where_i_am.x); - Serial.print(" Y"); - Serial.print(where_i_am.y); - Serial.print(" Z"); - Serial.print(where_i_am.z); - Serial.print(" E"); - Serial.println(where_i_am.e); + talkToHost.setCoords(where_i_am); break; @@ -691,8 +627,7 @@ { #if MOTHERBOARD == 2 ex[0]->setBedTemperature((int)gc.S); -#endif -#if MOTHERBOARD == 3 +#else heatedBed.setTemperature((int)gc.S); #endif } @@ -706,11 +641,8 @@ default: if(SendDebug & DEBUG_ERRORS) - { - Serial.print("Huh? M"); - Serial.println(gc.M, DEC); - FlushSerialRequestResend(); - } + sprintf(talkToHost.string(), "Dud M code: M%d", gc.M); + talkToHost.setResend(gc.LastLineNrRecieved+1); } @@ -793,6 +725,7 @@ gc.LastLineNrRecieved = -1; } +/* void FlushSerialRequestResend() { Serial.flush(); @@ -800,4 +733,4 @@ ltoa(gc.LastLineNrRecieved+1, seBuffer+7, 10); Serial.println(seBuffer); } - +*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |