2014-05-05 12:50:13 -06:00
|
|
|
#include "Command.h"
|
|
|
|
|
2014-08-06 16:04:40 -06:00
|
|
|
const char axisCodes[3] = { 'X', 'Y', 'Z' };
|
2014-08-07 15:05:30 -06:00
|
|
|
const char axisSpeedCodes[3] = { 'A', 'B', 'C' };
|
2014-08-06 16:04:40 -06:00
|
|
|
const char speedCode = 'S';
|
|
|
|
const char parameterIdCode = 'P';
|
|
|
|
const char parameterValueCode = 'V';
|
2014-09-05 16:25:24 -06:00
|
|
|
const char parameterValue2Code= 'W';
|
|
|
|
const char elementCode = 'E';
|
|
|
|
const char timeCode = 'T';
|
|
|
|
const char modeCode = 'M';
|
2014-08-06 16:04:40 -06:00
|
|
|
|
2014-08-07 15:05:30 -06:00
|
|
|
double axisValue[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
long axisSpeedValue[3] = { 0, 0, 0 };
|
|
|
|
double speedValue = 0.0;
|
|
|
|
long parameterId = 0;
|
|
|
|
long parameterValue = 0;
|
2014-09-05 16:25:24 -06:00
|
|
|
long parameterValue2 = 0;
|
|
|
|
long element = 0;
|
|
|
|
long time = 0;
|
|
|
|
long mode = 0;
|
2014-08-06 16:04:40 -06:00
|
|
|
|
2014-05-05 16:15:58 -06:00
|
|
|
CommandCodeEnum commandCodeEnum = CODE_UNDEFINED;
|
2014-05-05 12:50:13 -06:00
|
|
|
|
|
|
|
Command::Command(String commandString) {
|
2015-02-01 13:58:01 -07:00
|
|
|
|
|
|
|
commandString = commandString + " ";
|
|
|
|
|
2014-05-05 12:50:13 -06:00
|
|
|
char charBuf[commandString.length()];
|
|
|
|
commandString.toCharArray(charBuf, commandString.length());
|
2014-05-05 16:15:58 -06:00
|
|
|
char* charPointer;
|
2014-05-15 11:44:28 -06:00
|
|
|
bool invalidCommand = false;
|
2014-05-05 12:50:13 -06:00
|
|
|
|
2014-05-05 16:15:58 -06:00
|
|
|
charPointer = strtok(charBuf, " ");
|
2014-05-05 12:50:13 -06:00
|
|
|
|
2014-07-23 01:46:21 -06:00
|
|
|
if (charPointer[0] == 'G' || charPointer[0] == 'F') {
|
2014-05-05 16:15:58 -06:00
|
|
|
commandCodeEnum = getGCodeEnum(charPointer);
|
2014-05-15 11:44:28 -06:00
|
|
|
} else {
|
|
|
|
invalidCommand = true;
|
|
|
|
return;
|
2014-05-05 16:15:58 -06:00
|
|
|
}
|
|
|
|
while (charPointer != NULL) {
|
|
|
|
getParameter(charPointer);
|
2016-09-09 11:18:16 -06:00
|
|
|
charPointer = strtok(NULL, " \r\n");
|
2014-05-05 16:15:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandCodeEnum Command::getGCodeEnum(char* code) {
|
2015-02-01 13:58:01 -07:00
|
|
|
|
|
|
|
|
2014-05-16 14:27:16 -06:00
|
|
|
if (strcmp(code, "G0") == 0 || strcmp(code, "G00") == 0) {
|
|
|
|
return G00;
|
2014-05-05 16:15:58 -06:00
|
|
|
}
|
2014-05-16 14:27:16 -06:00
|
|
|
if (strcmp(code, "G1") == 0 || strcmp(code, "G01") == 0) {
|
|
|
|
return G01;
|
2014-05-05 12:50:13 -06:00
|
|
|
}
|
2014-07-23 01:46:21 -06:00
|
|
|
//if (strcmp(code, "F3") == 0 || strcmp(code, "F03") == 0) {
|
|
|
|
// return F03;
|
|
|
|
//}
|
2014-10-12 15:57:07 -06:00
|
|
|
|
2014-07-23 01:46:21 -06:00
|
|
|
if (strcmp(code, "F11") == 0) {
|
|
|
|
return F11;
|
2014-05-05 16:15:58 -06:00
|
|
|
}
|
2014-07-23 01:46:21 -06:00
|
|
|
if (strcmp(code, "F12") == 0) {
|
|
|
|
return F12;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F13") == 0) {
|
|
|
|
return F13;
|
|
|
|
}
|
2014-10-12 15:57:07 -06:00
|
|
|
if (strcmp(code, "F14") == 0) {
|
|
|
|
return F14;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F15") == 0) {
|
|
|
|
return F15;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F16") == 0) {
|
|
|
|
return F16;
|
|
|
|
}
|
2014-07-23 01:46:21 -06:00
|
|
|
|
2014-08-06 16:04:40 -06:00
|
|
|
if (strcmp(code, "F20") == 0) {
|
|
|
|
return F20;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F21") == 0) {
|
|
|
|
return F21;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F22") == 0) {
|
|
|
|
return F22;
|
|
|
|
}
|
|
|
|
|
2014-09-04 15:10:47 -06:00
|
|
|
if (strcmp(code, "F31") == 0) {
|
|
|
|
return F31;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F32") == 0) {
|
|
|
|
return F32;
|
|
|
|
}
|
|
|
|
|
2014-09-05 16:25:24 -06:00
|
|
|
if (strcmp(code, "F41") == 0) {
|
|
|
|
return F41;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F42") == 0) {
|
|
|
|
return F42;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F43") == 0) {
|
|
|
|
return F43;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F44") == 0) {
|
|
|
|
return F44;
|
|
|
|
}
|
|
|
|
|
2014-11-04 15:14:35 -07:00
|
|
|
if (strcmp(code, "F61") == 0) {
|
|
|
|
return F61;
|
|
|
|
}
|
|
|
|
|
2014-07-23 01:46:21 -06:00
|
|
|
if (strcmp(code, "F81") == 0) {
|
|
|
|
return F81;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F82") == 0) {
|
|
|
|
return F82;
|
|
|
|
}
|
|
|
|
if (strcmp(code, "F83") == 0) {
|
|
|
|
return F83;
|
|
|
|
}
|
|
|
|
|
2014-05-05 16:15:58 -06:00
|
|
|
return CODE_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2014-07-01 05:00:03 -06:00
|
|
|
double minusNotAllowed(double value) {
|
|
|
|
if(value < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2014-05-05 16:15:58 -06:00
|
|
|
void Command::getParameter(char* charPointer) {
|
2014-09-05 16:25:24 -06:00
|
|
|
if (charPointer[0] == axisCodes[0] ){
|
|
|
|
axisValue[0] = atof(charPointer + 1 );
|
|
|
|
} else if (charPointer[0] == axisCodes[1] ){
|
|
|
|
axisValue[1] = atof(charPointer + 1 );
|
|
|
|
} else if (charPointer[0] == axisCodes[2] ){
|
|
|
|
axisValue[2] = atof(charPointer + 1 );
|
|
|
|
|
|
|
|
} else if (charPointer[0] == axisSpeedCodes[0] ){
|
|
|
|
axisSpeedValue[0] = atof(charPointer + 1 );
|
|
|
|
} else if (charPointer[0] == axisSpeedCodes[1] ){
|
|
|
|
axisSpeedValue[1] = atof(charPointer + 1 );
|
|
|
|
} else if (charPointer[0] == axisSpeedCodes[2] ){
|
|
|
|
axisSpeedValue[2] = atof(charPointer + 1 );
|
|
|
|
|
|
|
|
} else if (charPointer[0] == speedCode ){
|
|
|
|
speedValue = atof(charPointer + 1 );
|
|
|
|
} else if (charPointer[0] == parameterIdCode ){
|
|
|
|
parameterId = atof(charPointer + 1 );
|
|
|
|
} else if (charPointer[0] == parameterValueCode ){
|
|
|
|
parameterValue = atof(charPointer + 1 );
|
|
|
|
|
|
|
|
} else if (charPointer[0] == parameterValue2Code ){
|
|
|
|
parameterValue2 = atof(charPointer + 1 );
|
|
|
|
} else if (charPointer[0] == elementCode ){
|
|
|
|
element = atof(charPointer + 1 );
|
|
|
|
} else if (charPointer[0] == timeCode ){
|
|
|
|
time = atof(charPointer + 1 );
|
|
|
|
} else if (charPointer[0] == modeCode ){
|
|
|
|
mode = atof(charPointer + 1 );
|
2014-05-05 16:15:58 -06:00
|
|
|
}
|
2014-09-05 16:25:24 -06:00
|
|
|
|
2014-05-05 16:15:58 -06:00
|
|
|
}
|
2014-05-05 12:50:13 -06:00
|
|
|
|
2014-05-05 16:15:58 -06:00
|
|
|
void Command::print() {
|
2014-08-24 15:52:32 -06:00
|
|
|
Serial.print("R99 Command with code: ");
|
2014-07-23 15:58:39 -06:00
|
|
|
Serial.print(commandCodeEnum);
|
2014-08-24 15:52:32 -06:00
|
|
|
Serial.print(", X: ");
|
2014-05-05 16:15:58 -06:00
|
|
|
Serial.print(axisValue[0]);
|
2014-08-24 15:52:32 -06:00
|
|
|
Serial.print(", Y: ");
|
2014-05-05 16:15:58 -06:00
|
|
|
Serial.print(axisValue[1]);
|
2014-08-24 15:52:32 -06:00
|
|
|
Serial.print(", Z: ");
|
|
|
|
Serial.print(axisValue[2]);
|
|
|
|
Serial.print(", S: ");
|
|
|
|
Serial.print(speedValue);
|
|
|
|
Serial.print(", P: ");
|
|
|
|
Serial.print(parameterId);
|
|
|
|
Serial.print(", V: ");
|
|
|
|
Serial.print(parameterValue);
|
2014-09-05 16:25:24 -06:00
|
|
|
|
|
|
|
Serial.print(", W: ");
|
|
|
|
Serial.print(parameterValue2);
|
|
|
|
Serial.print(", T: ");
|
|
|
|
Serial.print(time);
|
|
|
|
Serial.print(", E: ");
|
|
|
|
Serial.print(element);
|
2014-09-06 16:29:29 -06:00
|
|
|
Serial.print(", M: ");
|
|
|
|
Serial.print(mode);
|
2016-09-09 11:18:16 -06:00
|
|
|
Serial.print("\r\n");
|
2014-05-05 12:50:13 -06:00
|
|
|
}
|
|
|
|
|
2014-05-15 11:44:28 -06:00
|
|
|
CommandCodeEnum Command::getCodeEnum() {
|
|
|
|
return commandCodeEnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Command::getX() {
|
|
|
|
return axisValue[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
double Command::getY() {
|
|
|
|
return axisValue[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
double Command::getZ() {
|
2014-05-16 14:27:16 -06:00
|
|
|
return axisValue[2];
|
2014-05-15 11:44:28 -06:00
|
|
|
}
|
|
|
|
|
2014-08-07 15:05:30 -06:00
|
|
|
long Command::getA() {
|
2015-06-24 14:58:45 -06:00
|
|
|
return axisSpeedValue[0];
|
2014-08-07 15:05:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
long Command::getB() {
|
2015-06-24 14:58:45 -06:00
|
|
|
return axisSpeedValue[1];
|
2014-08-07 15:05:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
long Command::getC() {
|
2015-06-24 14:58:45 -06:00
|
|
|
return axisSpeedValue[2];
|
2014-08-07 15:05:30 -06:00
|
|
|
}
|
|
|
|
|
2014-08-24 15:52:32 -06:00
|
|
|
long Command::getP() {
|
2014-08-06 16:04:40 -06:00
|
|
|
return parameterId;
|
|
|
|
}
|
|
|
|
|
2014-08-24 15:52:32 -06:00
|
|
|
long Command::getV() {
|
2014-08-06 16:04:40 -06:00
|
|
|
return parameterValue;
|
2014-05-28 17:02:22 -06:00
|
|
|
}
|
|
|
|
|
2014-09-05 16:25:24 -06:00
|
|
|
long Command::getW() {
|
|
|
|
return parameterValue2;
|
|
|
|
}
|
|
|
|
|
|
|
|
long Command::getT() {
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
long Command::getE() {
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2014-09-06 16:29:29 -06:00
|
|
|
long Command::getM() {
|
|
|
|
return mode;
|
|
|
|
}
|