|
30 | 30 | #include "protocol.h" |
31 | 31 | #include "state_machine.h" |
32 | 32 |
|
| 33 | +#if NGC_PARAMETERS_ENABLE |
| 34 | +#include "ngc_params.h" |
| 35 | +#endif |
| 36 | + |
33 | 37 | #if NGC_EXPRESSIONS_ENABLE |
34 | 38 | #include "ngc_expr.h" |
35 | | -#include "ngc_params.h" |
36 | 39 | #include "ngc_flowctrl.h" |
| 40 | +#ifndef NGC_N_ASSIGN_PARAMETERS_PER_BLOCK |
| 41 | +#define NGC_N_ASSIGN_PARAMETERS_PER_BLOCK 10 |
| 42 | +#endif |
37 | 43 | #endif |
38 | 44 |
|
39 | 45 | // NOTE: Max line number is defined by the g-code standard to be 99999. It seems to be an |
@@ -497,134 +503,6 @@ void gc_output_message (char *message) |
497 | 503 | } |
498 | 504 | } |
499 | 505 |
|
500 | | -#if NGC_EXPRESSIONS_ENABLE |
501 | | - |
502 | | -#define NGC_N_ASSIGN_PARAMETERS_PER_BLOCK 10 |
503 | | - |
504 | | -static ngc_param_t ngc_params[NGC_N_ASSIGN_PARAMETERS_PER_BLOCK]; |
505 | | - |
506 | | -static int8_t get_format (char c, int8_t pos, uint8_t *decimals) |
507 | | -{ |
508 | | - static uint8_t d; |
509 | | - |
510 | | - // lcaps c? |
511 | | - |
512 | | - switch(pos) { |
513 | | - |
514 | | - case 1: |
515 | | - |
516 | | - switch(c) { |
517 | | - |
518 | | - case 'd': |
519 | | - *decimals = 0; |
520 | | - pos = -2; |
521 | | - break; |
522 | | - |
523 | | - case 'f': |
524 | | - *decimals = ngc_float_decimals(); |
525 | | - pos = -2; |
526 | | - break; |
527 | | - |
528 | | - case '.': |
529 | | - pos = 2; |
530 | | - break; |
531 | | - |
532 | | - default: |
533 | | - pos = 0; |
534 | | - break; |
535 | | - } |
536 | | - break; |
537 | | - |
538 | | - case 2: |
539 | | - if(c >= '0' && c <= '9') { |
540 | | - d = c - '0'; |
541 | | - pos = 3; |
542 | | - } else |
543 | | - pos = 0; |
544 | | - break; |
545 | | - |
546 | | - default: |
547 | | - if(c == 'f') { |
548 | | - *decimals = d; |
549 | | - pos = -4; |
550 | | - } else |
551 | | - pos = 0; |
552 | | - break; |
553 | | - } |
554 | | - |
555 | | - return pos; |
556 | | -} |
557 | | - |
558 | | -static void substitute_parameters (char *comment, char **message) |
559 | | -{ |
560 | | - size_t len = 0; |
561 | | - float value; |
562 | | - char *s, c; |
563 | | - uint_fast8_t char_counter = 0; |
564 | | - int8_t parse_format = 0; |
565 | | - uint8_t decimals = ngc_float_decimals(); // LinuxCNC is 1 (or l?) |
566 | | - |
567 | | - // Trim leading spaces |
568 | | - while(*comment == ' ') |
569 | | - comment++; |
570 | | - |
571 | | - // Calculate length of substituted string |
572 | | - while((c = comment[char_counter++])) { |
573 | | - if(parse_format) { |
574 | | - if((parse_format = get_format(c, parse_format, &decimals)) < 0) { |
575 | | - len -= parse_format; |
576 | | - parse_format = 0; |
577 | | - } |
578 | | - } else if(c == '%') |
579 | | - parse_format = 1; |
580 | | - else if(c == '#') { |
581 | | - char_counter--; |
582 | | - if(ngc_read_parameter(comment, &char_counter, &value, true) == Status_OK) |
583 | | - len += strlen(decimals ? ftoa(value, decimals) : trim_float(ftoa(value, decimals))); |
584 | | - else |
585 | | - len += 3; // "N/A" |
586 | | - } else |
587 | | - len++; |
588 | | - } |
589 | | - |
590 | | - // Perform substitution |
591 | | - if((s = *message = malloc(len + 1))) { |
592 | | - |
593 | | - char fmt[5] = {0}; |
594 | | - |
595 | | - *s = '\0'; |
596 | | - char_counter = 0; |
597 | | - |
598 | | - while((c = comment[char_counter++])) { |
599 | | - if(parse_format) { |
600 | | - fmt[parse_format] = c; |
601 | | - if((parse_format = get_format(c, parse_format, &decimals)) < 0) |
602 | | - parse_format = 0; |
603 | | - else if(parse_format == 0) { |
604 | | - strcat(s, fmt); |
605 | | - s = strchr(s, '\0'); |
606 | | - continue; |
607 | | - } |
608 | | - } else if(c == '%') { |
609 | | - parse_format = 1; |
610 | | - fmt[0] = c; |
611 | | - } else if(c == '#') { |
612 | | - char_counter--; |
613 | | - if(ngc_read_parameter(comment, &char_counter, &value, true) == Status_OK) |
614 | | - strcat(s, decimals ? ftoa(value, decimals) : trim_float(ftoa(value, decimals))); |
615 | | - else |
616 | | - strcat(s, "N/A"); |
617 | | - s = strchr(s, '\0'); |
618 | | - } else { |
619 | | - *s++ = c; |
620 | | - *s = '\0'; |
621 | | - } |
622 | | - } |
623 | | - } |
624 | | -} |
625 | | - |
626 | | -#endif // NGC_EXPRESSIONS_ENABLE |
627 | | - |
628 | 506 | #if NGC_PARAMETERS_ENABLE |
629 | 507 |
|
630 | 508 | static parameter_words_t g65_words = {0}; |
@@ -722,16 +600,16 @@ char *gc_normalize_block (char *block, char **message) |
722 | 600 | if(!strncmp(comment, "(DEBUG,", 7)) { // Debug message string substitution |
723 | 601 | if(settings.flags.ngc_debug_out) { |
724 | 602 | comment += 7; |
725 | | - substitute_parameters(comment, message); |
| 603 | + ngc_substitute_parameters(comment, message); |
726 | 604 | } |
727 | 605 | *comment = '\0'; // Do not generate grbl.on_gcode_comment event! |
728 | 606 | } else if(!strncmp(comment, "(PRINT,", 7)) { // Print message string substitution |
729 | 607 | comment += 7; |
730 | | - substitute_parameters(comment, message); |
| 608 | + ngc_substitute_parameters(comment, message); |
731 | 609 | *comment = '\0'; // Do not generate grbl.on_gcode_comment event! |
732 | 610 | } else if(!strncmp(comment, "(MSG,", 5)) { |
733 | 611 | comment += 5; |
734 | | - substitute_parameters(comment, message); |
| 612 | + ngc_substitute_parameters(comment, message); |
735 | 613 | } |
736 | 614 | } |
737 | 615 | #else |
@@ -844,6 +722,8 @@ status_code_t gc_execute_block (char *block) |
844 | 722 | .o = On |
845 | 723 | }; |
846 | 724 |
|
| 725 | + static ngc_param_t ngc_params[NGC_N_ASSIGN_PARAMETERS_PER_BLOCK]; |
| 726 | + |
847 | 727 | uint_fast8_t ngc_param_count = 0; |
848 | 728 |
|
849 | 729 | // NOTE: this array has to match the parameter_words_t order! |
@@ -1038,13 +918,17 @@ status_code_t gc_execute_block (char *block) |
1038 | 918 | } else |
1039 | 919 | FAIL(status); |
1040 | 920 | } else if(block[char_counter] == '<') { |
1041 | | - /* char o_label[NGC_MAX_PARAM_LENGTH + 1]; |
1042 | | - if((status = ngc_read_name(block, &char_counter, o_label)) != Status_OK) |
| 921 | +#if 0 |
| 922 | + char o_slabel[NGC_MAX_PARAM_LENGTH + 1]; |
| 923 | + if((status = ngc_read_name(block, &char_counter, o_slabel)) != Status_OK) |
1043 | 924 | FAIL(status); |
1044 | 925 | gc_block.words.o = On; |
1045 | | - gc_block.values.o = 0xFFFFFFFE; |
1046 | | - continue;*/ |
| 926 | + if(gc_block.values.o = string_register_set_name(o_slabel) == 0) |
| 927 | + FAIL(Status_FlowControlOutOfMemory); |
| 928 | + continue; |
| 929 | +#else |
1047 | 930 | FAIL(Status_GcodeUnsupportedCommand); // [For now...] |
| 931 | +#endif |
1048 | 932 | } |
1049 | 933 | } |
1050 | 934 |
|
|
0 commit comments