|
@@ -732,100 +732,103 @@ void get_command()
|
732
|
732
|
serial_char == '\r' ||
|
733
|
733
|
serial_count >= (MAX_CMD_SIZE - 1) )
|
734
|
734
|
{
|
735
|
|
- if(!serial_count) { //if empty line
|
736
|
|
- comment_mode = false; //for new command
|
|
735
|
+ // end of line == end of comment
|
|
736
|
+ comment_mode = false;
|
|
737
|
+
|
|
738
|
+ if(!serial_count) {
|
|
739
|
+ // short cut for empty lines
|
737
|
740
|
return;
|
738
|
741
|
}
|
739
|
742
|
cmdbuffer[bufindw][serial_count] = 0; //terminate string
|
740
|
|
- if(!comment_mode){
|
741
|
|
- fromsd[bufindw] = false;
|
742
|
|
- if(strchr(cmdbuffer[bufindw], 'N') != NULL)
|
|
743
|
+
|
|
744
|
+ fromsd[bufindw] = false;
|
|
745
|
+ if(strchr(cmdbuffer[bufindw], 'N') != NULL)
|
|
746
|
+ {
|
|
747
|
+ strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
|
|
748
|
+ gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
|
|
749
|
+ if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
|
|
750
|
+ SERIAL_ERROR_START;
|
|
751
|
+ SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
|
|
752
|
+ SERIAL_ERRORLN(gcode_LastN);
|
|
753
|
+ //Serial.println(gcode_N);
|
|
754
|
+ FlushSerialRequestResend();
|
|
755
|
+ serial_count = 0;
|
|
756
|
+ return;
|
|
757
|
+ }
|
|
758
|
+
|
|
759
|
+ if(strchr(cmdbuffer[bufindw], '*') != NULL)
|
743
|
760
|
{
|
744
|
|
- strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
|
745
|
|
- gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
|
746
|
|
- if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
|
747
|
|
- SERIAL_ERROR_START;
|
748
|
|
- SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
|
749
|
|
- SERIAL_ERRORLN(gcode_LastN);
|
750
|
|
- //Serial.println(gcode_N);
|
751
|
|
- FlushSerialRequestResend();
|
752
|
|
- serial_count = 0;
|
753
|
|
- return;
|
754
|
|
- }
|
|
761
|
+ byte checksum = 0;
|
|
762
|
+ byte count = 0;
|
|
763
|
+ while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
|
|
764
|
+ strchr_pointer = strchr(cmdbuffer[bufindw], '*');
|
755
|
765
|
|
756
|
|
- if(strchr(cmdbuffer[bufindw], '*') != NULL)
|
757
|
|
- {
|
758
|
|
- byte checksum = 0;
|
759
|
|
- byte count = 0;
|
760
|
|
- while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
|
761
|
|
- strchr_pointer = strchr(cmdbuffer[bufindw], '*');
|
762
|
|
-
|
763
|
|
- if( (int)(strtod(strchr_pointer + 1, NULL)) != checksum) {
|
764
|
|
- SERIAL_ERROR_START;
|
765
|
|
- SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
|
766
|
|
- SERIAL_ERRORLN(gcode_LastN);
|
767
|
|
- FlushSerialRequestResend();
|
768
|
|
- serial_count = 0;
|
769
|
|
- return;
|
770
|
|
- }
|
771
|
|
- //if no errors, continue parsing
|
772
|
|
- }
|
773
|
|
- else
|
774
|
|
- {
|
|
766
|
+ if( (int)(strtod(strchr_pointer + 1, NULL)) != checksum) {
|
775
|
767
|
SERIAL_ERROR_START;
|
776
|
|
- SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
|
|
768
|
+ SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
|
777
|
769
|
SERIAL_ERRORLN(gcode_LastN);
|
778
|
770
|
FlushSerialRequestResend();
|
779
|
771
|
serial_count = 0;
|
780
|
772
|
return;
|
781
|
773
|
}
|
782
|
|
-
|
783
|
|
- gcode_LastN = gcode_N;
|
784
|
774
|
//if no errors, continue parsing
|
785
|
775
|
}
|
786
|
|
- else // if we don't receive 'N' but still see '*'
|
|
776
|
+ else
|
787
|
777
|
{
|
788
|
|
- if((strchr(cmdbuffer[bufindw], '*') != NULL))
|
789
|
|
- {
|
790
|
|
- SERIAL_ERROR_START;
|
791
|
|
- SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
|
792
|
|
- SERIAL_ERRORLN(gcode_LastN);
|
793
|
|
- serial_count = 0;
|
794
|
|
- return;
|
795
|
|
- }
|
|
778
|
+ SERIAL_ERROR_START;
|
|
779
|
+ SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
|
|
780
|
+ SERIAL_ERRORLN(gcode_LastN);
|
|
781
|
+ FlushSerialRequestResend();
|
|
782
|
+ serial_count = 0;
|
|
783
|
+ return;
|
796
|
784
|
}
|
797
|
|
- if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
|
798
|
|
- strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
|
799
|
|
- switch((int)((strtod(strchr_pointer + 1, NULL)))){
|
800
|
|
- case 0:
|
801
|
|
- case 1:
|
802
|
|
- case 2:
|
803
|
|
- case 3:
|
804
|
|
- if (Stopped == true) {
|
805
|
|
- SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
|
806
|
|
- LCD_MESSAGEPGM(MSG_STOPPED);
|
807
|
|
- }
|
808
|
|
- break;
|
809
|
|
- default:
|
810
|
|
- break;
|
811
|
|
- }
|
812
|
785
|
|
|
786
|
+ gcode_LastN = gcode_N;
|
|
787
|
+ //if no errors, continue parsing
|
|
788
|
+ }
|
|
789
|
+ else // if we don't receive 'N' but still see '*'
|
|
790
|
+ {
|
|
791
|
+ if((strchr(cmdbuffer[bufindw], '*') != NULL))
|
|
792
|
+ {
|
|
793
|
+ SERIAL_ERROR_START;
|
|
794
|
+ SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
|
|
795
|
+ SERIAL_ERRORLN(gcode_LastN);
|
|
796
|
+ serial_count = 0;
|
|
797
|
+ return;
|
|
798
|
+ }
|
|
799
|
+ }
|
|
800
|
+ if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
|
|
801
|
+ strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
|
|
802
|
+ switch((int)((strtod(strchr_pointer + 1, NULL)))){
|
|
803
|
+ case 0:
|
|
804
|
+ case 1:
|
|
805
|
+ case 2:
|
|
806
|
+ case 3:
|
|
807
|
+ if (Stopped == true) {
|
|
808
|
+ SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
|
|
809
|
+ LCD_MESSAGEPGM(MSG_STOPPED);
|
|
810
|
+ }
|
|
811
|
+ break;
|
|
812
|
+ default:
|
|
813
|
+ break;
|
813
|
814
|
}
|
814
|
815
|
|
815
|
|
- //If command was e-stop process now
|
816
|
|
- if(strcmp(cmdbuffer[bufindw], "M112") == 0)
|
817
|
|
- kill();
|
818
|
|
-
|
819
|
|
- bufindw = (bufindw + 1)%BUFSIZE;
|
820
|
|
- buflen += 1;
|
821
|
816
|
}
|
|
817
|
+
|
|
818
|
+ //If command was e-stop process now
|
|
819
|
+ if(strcmp(cmdbuffer[bufindw], "M112") == 0)
|
|
820
|
+ kill();
|
|
821
|
+
|
|
822
|
+ bufindw = (bufindw + 1)%BUFSIZE;
|
|
823
|
+ buflen += 1;
|
|
824
|
+
|
822
|
825
|
serial_count = 0; //clear buffer
|
823
|
826
|
}
|
824
|
827
|
else if(serial_char == '\\') { //Handle escapes
|
825
|
828
|
|
826
|
829
|
if(MYSERIAL.available() > 0 && buflen < BUFSIZE) {
|
827
|
830
|
// if we have one more character, copy it over
|
828
|
|
- MYSERIAL.read();
|
|
831
|
+ serial_char = MYSERIAL.read();
|
829
|
832
|
cmdbuffer[bufindw][serial_count++] = serial_char;
|
830
|
833
|
}
|
831
|
834
|
|