Repetier-Firmware  0.91
src/ArduinoAVR/Repetier/gcode.h
Go to the documentation of this file.
00001 /*
00002     This file is part of Repetier-Firmware.
00003 
00004     Repetier-Firmware is free software: you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation, either version 3 of the License, or
00007     (at your option) any later version.
00008 
00009     Repetier-Firmware is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with Repetier-Firmware.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 */
00018 #ifndef _GCODE_H
00019 #define _GCODE_H
00020 
00021 #define MAX_CMD_SIZE 96
00022 class SDCard;
00023 class GCode   // 52 uint8_ts per command needed
00024 {
00025     unsigned int params;
00026     unsigned int params2;
00027 public:
00028     unsigned int N; // Line number
00029     unsigned int M;
00030     unsigned int G;
00031     float X;
00032     float Y;
00033     float Z;
00034     float E;
00035     float F;
00036     uint8_t T;
00037     long S;
00038     long P;
00039     float I;
00040     float J;
00041     float R;
00042     char *text; //text[17];
00043     inline bool hasM()
00044     {
00045         return ((params & 2)!=0);
00046     }
00047     inline bool hasN()
00048     {
00049         return ((params & 1)!=0);
00050     }
00051     inline bool hasG()
00052     {
00053         return ((params & 4)!=0);
00054     }
00055     inline bool hasX()
00056     {
00057         return ((params & 8)!=0);
00058     }
00059     inline bool hasY()
00060     {
00061         return ((params & 16)!=0);
00062     }
00063     inline bool hasZ()
00064     {
00065         return ((params & 32)!=0);
00066     }
00067     inline bool hasNoXYZ()
00068     {
00069         return ((params & 56)==0);
00070     }
00071     inline bool hasE()
00072     {
00073         return ((params & 64)!=0);
00074     }
00075     inline bool hasF()
00076     {
00077         return ((params & 256)!=0);
00078     }
00079     inline bool hasT()
00080     {
00081         return ((params & 512)!=0);
00082     }
00083     inline bool hasS()
00084     {
00085         return ((params & 1024)!=0);
00086     }
00087     inline bool hasP()
00088     {
00089         return ((params & 2048)!=0);
00090     }
00091     inline bool isV2()
00092     {
00093         return ((params & 4096)!=0);
00094     }
00095     inline bool hasString()
00096     {
00097         return ((params & 32768)!=0);
00098     }
00099     inline bool hasI()
00100     {
00101         return ((params2 & 1)!=0);
00102     }
00103     inline bool hasJ()
00104     {
00105         return ((params2 & 2)!=0);
00106     }
00107     inline bool hasR()
00108     {
00109         return ((params2 & 4)!=0);
00110     }
00111     inline long getS(long def)
00112     {
00113         return (hasS() ? S : def);
00114     }
00115     inline long getP(long def)
00116     {
00117         return (hasP() ? P : def);
00118     }
00119     inline void setFormatError() {
00120         params2 |= 32768;
00121     }
00122     inline bool hasFormatError() {
00123         return ((params2 & 32768)!=0);
00124     }
00125     void printCommand();
00126     bool parseBinary(uint8_t *buffer,bool fromSerial);
00127     bool parseAscii(char *line,bool fromSerial);
00128     void popCurrentCommand();
00129     void echoCommand();
00131     static GCode *peekCurrentCommand();
00133     static void readFromSerial();
00134     static void pushCommand();
00135     static void executeFString(FSTRINGPARAM(cmd));
00136     static uint8_t computeBinarySize(char *ptr);
00137 
00138     friend class SDCard;
00139     friend class UIDisplay;
00140 private:
00141     void debugCommandBuffer();
00142     void checkAndPushCommand();
00143     static void requestResend();
00144     inline float parseFloatValue(char *s)
00145     {
00146         char *endPtr;
00147         float f = (strtod(s, &endPtr));
00148         if(s == endPtr) setFormatError();
00149         return f;
00150     }
00151     inline long parseLongValue(char *s)
00152     {
00153         char *endPtr;
00154         long l = (strtol(s, &endPtr, 10));
00155         if(s == endPtr) setFormatError();
00156         return l;
00157     }
00158 
00159     static GCode commandsBuffered[GCODE_BUFFER_SIZE]; 
00160     static uint8_t bufferReadIndex; 
00161     static uint8_t bufferWriteIndex; 
00162     static uint8_t commandReceiving[MAX_CMD_SIZE]; 
00163     static uint8_t commandsReceivingWritePosition; 
00164     static uint8_t sendAsBinary; 
00165     static uint8_t wasLastCommandReceivedAsBinary; 
00166     static uint8_t commentDetected; 
00167     static uint8_t binaryCommandSize; 
00168     static bool waitUntilAllCommandsAreParsed; 
00169     static uint32_t lastLineNumber; 
00170     static uint32_t actLineNumber; 
00171     static int8_t waitingForResend; 
00172     static volatile uint8_t bufferLength; 
00173     static millis_t timeOfLastDataPacket; 
00174     static uint8_t formatErrors; 
00175 };
00176 
00177 
00178 #endif
00179 
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Defines