2014-05-15 11:44:28 -06:00
|
|
|
/*
|
|
|
|
* GCodeProcessor.cpp
|
|
|
|
*
|
|
|
|
* Created on: 15 maj 2014
|
|
|
|
* Author: MattLech
|
2014-11-04 15:14:35 -07:00
|
|
|
* Author: Tim Evers
|
2014-05-15 11:44:28 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GCodeProcessor.h"
|
2016-10-02 15:43:39 -06:00
|
|
|
#include "CurrentState.h"
|
2014-05-15 11:44:28 -06:00
|
|
|
|
|
|
|
GCodeProcessor::GCodeProcessor() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GCodeProcessor::~GCodeProcessor() {
|
|
|
|
}
|
|
|
|
|
2014-05-16 14:27:16 -06:00
|
|
|
void GCodeProcessor::printCommandLog(Command* command) {
|
2016-12-03 13:58:27 -07:00
|
|
|
Serial.print("command == NULL: ");
|
|
|
|
Serial.println("\r\n");
|
2014-05-16 14:27:16 -06:00
|
|
|
}
|
|
|
|
|
2014-05-15 11:44:28 -06:00
|
|
|
int GCodeProcessor::execute(Command* command) {
|
2016-12-03 13:58:27 -07:00
|
|
|
|
|
|
|
int execution = 0;
|
|
|
|
|
2016-09-30 15:06:13 -06:00
|
|
|
long Q = command->getQ();
|
2016-10-02 15:43:39 -06:00
|
|
|
CurrentState::getInstance()->setQ(Q);
|
2016-09-30 15:06:13 -06:00
|
|
|
|
2017-04-15 15:32:01 -06:00
|
|
|
|
|
|
|
// Do not execute the command when the config complete parameter is not
|
|
|
|
// set by the raspberry pi and it's asked to do a move command
|
|
|
|
|
|
|
|
// Tim 2017-04-15 Disable until the raspberry code is ready
|
|
|
|
/*
|
2017-03-30 13:34:29 -06:00
|
|
|
if (ParameterList::getInstance()->getValue(PARAM_CONFIG_OK) != 1) {
|
2017-04-15 15:32:01 -06:00
|
|
|
if ( command->getCodeEnum() == G00 ||
|
2017-03-30 13:34:29 -06:00
|
|
|
command->getCodeEnum() == G01 ||
|
|
|
|
command->getCodeEnum() == F11 ||
|
|
|
|
command->getCodeEnum() == F12 ||
|
|
|
|
command->getCodeEnum() == F13 ||
|
|
|
|
command->getCodeEnum() == F14 ||
|
|
|
|
command->getCodeEnum() == F15 ||
|
|
|
|
command->getCodeEnum() == F16 ) {
|
|
|
|
|
|
|
|
Serial.print(COMM_REPORT_NO_CONFIG);
|
|
|
|
CurrentState::getInstance()->printQAndNewLine();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2017-04-15 15:32:01 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Return error when no command or invalid command is found
|
2017-03-27 13:58:25 -06:00
|
|
|
|
2016-12-03 13:58:27 -07:00
|
|
|
if(command == NULL) {
|
2014-05-16 14:27:16 -06:00
|
|
|
if(LOGGING) {
|
|
|
|
printCommandLog(command);
|
|
|
|
}
|
2014-05-15 11:44:28 -06:00
|
|
|
return -1;
|
|
|
|
}
|
2016-12-03 13:58:27 -07:00
|
|
|
|
|
|
|
if(command->getCodeEnum() == CODE_UNDEFINED) {
|
|
|
|
if(LOGGING) {
|
|
|
|
printCommandLog(command);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-04-15 15:32:01 -06:00
|
|
|
// Get the right handler for this command
|
|
|
|
|
2014-05-15 11:44:28 -06:00
|
|
|
GCodeHandler* handler = getGCodeHandler(command->getCodeEnum());
|
2016-12-03 13:58:27 -07:00
|
|
|
|
2014-05-15 11:44:28 -06:00
|
|
|
if(handler == NULL) {
|
2016-12-03 13:58:27 -07:00
|
|
|
Serial.println("R99 handler == NULL\r\n");
|
2014-05-15 11:44:28 -06:00
|
|
|
return -1;
|
|
|
|
}
|
2016-12-03 13:58:27 -07:00
|
|
|
|
2017-04-15 15:32:01 -06:00
|
|
|
// Execute te command, report start and end
|
|
|
|
|
2016-10-02 15:43:39 -06:00
|
|
|
Serial.print(COMM_REPORT_CMD_START);
|
|
|
|
CurrentState::getInstance()->printQAndNewLine();
|
2016-09-30 15:06:13 -06:00
|
|
|
|
2016-12-03 13:58:27 -07:00
|
|
|
execution = handler->execute(command);
|
2014-07-01 05:00:03 -06:00
|
|
|
if(execution == 0) {
|
2016-10-02 15:43:39 -06:00
|
|
|
Serial.print(COMM_REPORT_CMD_DONE);
|
|
|
|
CurrentState::getInstance()->printQAndNewLine();
|
2014-07-24 15:04:19 -06:00
|
|
|
} else {
|
2016-10-02 15:43:39 -06:00
|
|
|
Serial.print(COMM_REPORT_CMD_ERROR);
|
|
|
|
CurrentState::getInstance()->printQAndNewLine();
|
2014-07-01 05:00:03 -06:00
|
|
|
}
|
2016-10-02 15:43:39 -06:00
|
|
|
|
|
|
|
CurrentState::getInstance()->resetQ();
|
2014-07-01 05:00:03 -06:00
|
|
|
return execution;
|
2014-05-15 11:44:28 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
GCodeHandler* GCodeProcessor::getGCodeHandler(CommandCodeEnum codeEnum) {
|
2016-12-03 13:58:27 -07:00
|
|
|
|
|
|
|
GCodeHandler* handler = NULL;
|
|
|
|
|
2017-04-15 15:32:01 -06:00
|
|
|
// These are if statements so they can be disabled as test
|
|
|
|
// Usefull when running into memory issues again
|
|
|
|
|
|
|
|
|
2016-12-03 13:58:27 -07:00
|
|
|
if (codeEnum == G00) {handler = G00Handler::getInstance();}
|
|
|
|
|
|
|
|
if (codeEnum == G28) {handler = G28Handler::getInstance();}
|
|
|
|
|
|
|
|
if (codeEnum == F11) {handler = F11Handler::getInstance();}
|
|
|
|
if (codeEnum == F12) {handler = F12Handler::getInstance();}
|
|
|
|
if (codeEnum == F13) {handler = F13Handler::getInstance();}
|
|
|
|
|
|
|
|
if (codeEnum == F14) {handler = F14Handler::getInstance();}
|
|
|
|
if (codeEnum == F15) {handler = F15Handler::getInstance();}
|
|
|
|
if (codeEnum == F16) {handler = F16Handler::getInstance();}
|
|
|
|
|
|
|
|
if (codeEnum == F20) {handler = F20Handler::getInstance();}
|
|
|
|
if (codeEnum == F21) {handler = F21Handler::getInstance();}
|
|
|
|
if (codeEnum == F22) {handler = F22Handler::getInstance();}
|
|
|
|
|
|
|
|
// if (codeEnum == F31) {handler = F31Handler::getInstance();}
|
|
|
|
// if (codeEnum == F32) {handler = F32Handler::getInstance();}
|
|
|
|
|
|
|
|
if (codeEnum == F41) {handler = F41Handler::getInstance();}
|
|
|
|
if (codeEnum == F42) {handler = F42Handler::getInstance();}
|
|
|
|
if (codeEnum == F43) {handler = F43Handler::getInstance();}
|
|
|
|
if (codeEnum == F44) {handler = F44Handler::getInstance();}
|
|
|
|
|
2017-04-15 15:32:01 -06:00
|
|
|
if (codeEnum == F61) {handler = F61Handler::getInstance();}
|
2016-12-03 13:58:27 -07:00
|
|
|
|
|
|
|
if (codeEnum == F81) {handler = F81Handler::getInstance();}
|
|
|
|
if (codeEnum == F82) {handler = F82Handler::getInstance();}
|
|
|
|
if (codeEnum == F83) {handler = F83Handler::getInstance();}
|
2017-04-15 15:32:01 -06:00
|
|
|
if (codeEnum == F84) {handler = F84Handler::getInstance();}
|
2016-12-03 13:58:27 -07:00
|
|
|
|
|
|
|
|
|
|
|
return handler;
|
2014-05-15 11:44:28 -06:00
|
|
|
}
|
2014-05-16 14:27:16 -06:00
|
|
|
|
|
|
|
|