forked from grblHAL/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.c
2634 lines (2090 loc) · 81.1 KB
/
report.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
report.c - reporting and messaging methods
Part of grblHAL
Copyright (c) 2017-2024 Terje Io
Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC
grblHAL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
grblHAL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This file functions as the primary feedback interface for grblHAL. Any outgoing data, such
as the protocol status messages, feedback messages, and status reports, are stored here.
For the most part, these functions primarily are called from protocol.c methods. If a
different style feedback is desired (i.e. JSON), then a user can change these following
methods to accommodate their needs.
*/
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "hal.h"
#include "report.h"
#include "nvs_buffer.h"
#include "machine_limits.h"
#include "state_machine.h"
#include "canbus.h"
#include "regex.h"
#if ENABLE_SPINDLE_LINEARIZATION
#include <stdio.h>
#endif
static char buf[(STRLEN_COORDVALUE + 1) * N_AXIS];
static char *(*get_axis_values)(float *axis_values);
static char *(*get_axis_value)(float value);
static char *(*get_rate_value)(float value);
static uint8_t override_counter = 0; // Tracks when to add override data to status reports.
static uint8_t wco_counter = 0; // Tracks when to add work coordinate offset data to status reports.
static const char vbar[2] = { '|', '\0' };
// Append a number of strings to the static buffer
// NOTE: do NOT use for several int/float conversions as these share the same underlying buffer!
static char *appendbuf (int argc, ...)
{
char c, *s = buf, *arg;
va_list list;
va_start(list, argc);
while(argc--) {
arg = va_arg(list, char *);
do {
c = *s++ = *arg++;
} while(c);
s--;
}
va_end(list);
return buf;
}
static char *map_coord_system (coord_system_id_t id)
{
uint8_t g5x = id + 54;
strcpy(buf, uitoa((uint32_t)(g5x > 59 ? 59 : g5x)));
if(g5x > 59) {
strcat(buf, ".");
strcat(buf, uitoa((uint32_t)(g5x - 59)));
}
return buf;
}
// Convert axis position values to null terminated string (mm).
static char *get_axis_values_mm (float *axis_values)
{
uint_fast32_t idx;
buf[0] = '\0';
for (idx = 0; idx < N_AXIS; idx++) {
if(idx == X_AXIS && gc_state.modal.diameter_mode)
strcat(buf, ftoa(axis_values[idx] * 2.0f, N_DECIMAL_COORDVALUE_MM));
else
strcat(buf, ftoa(axis_values[idx], N_DECIMAL_COORDVALUE_MM));
if (idx < (N_AXIS - 1))
strcat(buf, ",");
}
return buf;
}
// Convert axis position values to null terminated string (inch).
static char *get_axis_values_inches (float *axis_values)
{
uint_fast32_t idx;
buf[0] = '\0';
for (idx = 0; idx < N_AXIS; idx++) {
if(idx == X_AXIS && gc_state.modal.diameter_mode)
strcat(buf, ftoa(axis_values[idx] * INCH_PER_MM * 2.0f, N_DECIMAL_COORDVALUE_INCH));
#if N_AXIS > 3
else if(idx > Z_AXIS && bit_istrue(settings.steppers.is_rotary.mask, bit(idx)))
strcat(buf, ftoa(axis_values[idx], N_DECIMAL_COORDVALUE_MM));
#endif
else
strcat(buf, ftoa(axis_values[idx] * INCH_PER_MM, N_DECIMAL_COORDVALUE_INCH));
if (idx < (N_AXIS - 1))
strcat(buf, ",");
}
return buf;
}
// Convert rate value to null terminated string (mm).
static char *get_axis_value_mm (float value)
{
return strcpy(buf, ftoa(value, N_DECIMAL_COORDVALUE_MM));
}
// Convert rate value to null terminated string (mm).
static char *get_axis_value_inches (float value)
{
return strcpy(buf, ftoa(value * INCH_PER_MM, N_DECIMAL_COORDVALUE_INCH));
}
// Convert rate value to null terminated string (mm).
static char *get_rate_value_mm (float value)
{
return uitoa((uint32_t)value);
}
// Convert rate value to null terminated string (mm).
static char *get_rate_value_inch (float value)
{
return uitoa((uint32_t)(value * INCH_PER_MM));
}
// Convert axes signals bits to string representation.
// NOTE: returns pointer to null terminator!
inline static char *axis_signals_tostring (char *buf, axes_signals_t signals)
{
uint_fast16_t idx = 0;
signals.mask &= AXES_BITMASK;
while(signals.mask) {
if(signals.mask & 0x01)
*buf++ = *axis_letter[idx];
idx++;
signals.mask >>= 1;
};
*buf = '\0';
return buf;
}
// Convert control signals bits to string representation.
// NOTE: returns pointer to null terminator!
inline static char *control_signals_tostring (char *buf, control_signals_t signals)
{
static const char signals_map[] = "RHSDLTEOFM Q P ";
char *map = (char *)signals_map;
if(!signals.deasserted)
while(signals.mask) {
if(signals.mask & 0x01) {
switch(*map) {
case ' ':
break;
case 'D':
if(hal.signals_cap.safety_door_ajar)
*buf++ = *map;
break;
default:
*buf++ = *map;
break;
}
}
map++;
signals.mask >>= 1;
}
*buf = '\0';
return buf;
}
void report_init (void)
{
get_axis_value = settings.flags.report_inches ? get_axis_value_inches : get_axis_value_mm;
get_axis_values = settings.flags.report_inches ? get_axis_values_inches : get_axis_values_mm;
get_rate_value = settings.flags.report_inches ? get_rate_value_inch : get_rate_value_mm;
}
// Handles the primary confirmation protocol response for streaming interfaces and human-feedback.
// For every incoming line, this method responds with an 'ok' for a successful command or an
// 'error:' to indicate some error event with the line or some critical system error during
// operation. Errors events can originate from the g-code parser, settings module, or asynchronously
// from a critical error, such as a triggered hard limit. Interface should always monitor for these
// responses.
static status_code_t report_status_message (status_code_t status_code)
{
switch(status_code) {
case Status_OK: // STATUS_OK
hal.stream.write("ok" ASCII_EOL);
break;
default:
hal.stream.write(appendbuf(3, "error:", uitoa((uint32_t)status_code), ASCII_EOL));
break;
}
return status_code;
}
// Prints alarm messages.
static alarm_code_t report_alarm_message (alarm_code_t alarm_code)
{
hal.stream.write_all(appendbuf(3, "ALARM:", uitoa((uint32_t)alarm_code), ASCII_EOL));
hal.delay_ms(100, NULL); // Force delay to ensure message clears output stream buffer.
return alarm_code;
}
// Prints feedback message, typically from gcode.
void report_message (const char *msg, message_type_t type)
{
if(hal.stream.is_connected()) {
hal.stream.write("[MSG:");
switch(type) {
case Message_Info:
hal.stream.write("Info: ");
break;
case Message_Warning:
hal.stream.write("Warning: ");
break;
case Message_Debug:
hal.stream.write("Debug: ");
break;
default:
break;
}
hal.stream.write(msg);
hal.stream.write("]" ASCII_EOL);
}
}
// Message helper to be run as foreground task
void report_plain (void *message)
{
report_message((char *)message, Message_Plain);
}
// Message helper to be run as foreground task
void report_info (void *message)
{
report_message((char *)message, Message_Info);
}
// Message helper to be run as foreground task
void report_warning (void *message)
{
report_message((char *)message, Message_Warning);
}
// Prints feedback messages. This serves as a centralized method to provide additional
// user feedback for things that are not of the status/alarm message protocol. These are
// messages such as setup warnings, switch toggling, and how to exit alarms.
// NOTE: For interfaces, messages are always placed within brackets. And if silent mode
// is installed, the message number codes are less than zero.
static message_code_t report_feedback_message (message_code_t id)
{
const message_t *msg = message_get(id);
report_message(msg ? msg->text : "", msg ? msg->type : Message_Plain);
if(id == Message_None && grbl.on_gcode_message)
grbl.on_gcode_message("");
return id;
}
// Welcome message
static void report_init_message (void)
{
override_counter = wco_counter = 0;
#if COMPATIBILITY_LEVEL == 0
hal.stream.write_all(ASCII_EOL "GrblHAL " GRBL_VERSION " ['$' or '$HELP' for help]" ASCII_EOL);
#else
hal.stream.write_all(ASCII_EOL "Grbl " GRBL_VERSION " ['$' for help]" ASCII_EOL);
#endif
}
// grblHAL help message
static void report_help_message (void)
{
hal.stream.write("[HLP:$$ $# $G $I $N $x=val $Nx=line $J=line $SLP $C $X $H $B ~ ! ? ctrl-x]" ASCII_EOL);
}
// Prints plugin info.
void report_plugin (const char *name, const char *version)
{
hal.stream.write("[PLUGIN:");
hal.stream.write(name);
hal.stream.write(" v");
hal.stream.write(version);
hal.stream.write("]" ASCII_EOL);
}
static bool report_group_settings (const setting_group_detail_t *groups, const uint_fast8_t n_groups, char *args)
{
bool found = false;
uint_fast8_t idx;
char c, *s, group[26];
for(idx = 0; idx < n_groups; idx++) {
s = group;
strncpy(group, groups[idx].name, sizeof(group) - 1);
// Uppercase group name
while((c = *s))
*s++ = CAPS(c);
if((found = matchhere(args, group))) {
hal.stream.write(ASCII_EOL "---- ");
hal.stream.write(groups[idx].name);
hal.stream.write(":" ASCII_EOL);
report_settings_details(SettingsFormat_HumanReadable, Setting_SettingsAll, groups[idx].id);
break;
}
}
return found;
}
status_code_t report_help (char *args)
{
// Strip leading spaces
while(*args == ' ')
args++;
if(*args == '\0') {
hal.stream.write("Help topics:" ASCII_EOL);
hal.stream.write(" Commands" ASCII_EOL);
hal.stream.write(" Settings" ASCII_EOL);
report_setting_group_details(false, " ");
} else {
char c, *s = args;
// Upper case argument
while((c = *s))
*s++ = CAPS(c);
if(matchhere(args, "COMMANDS")) {
if(grbl.on_report_command_help)
grbl.on_report_command_help();
} else if(matchhere(args, "SETTINGS"))
report_settings_details(SettingsFormat_HumanReadable, Setting_SettingsAll, Group_All);
else {
bool found = false;
setting_details_t *settings_info = settings_get_details();
found = report_group_settings(settings_info->groups, settings_info->n_groups, args);
if(!found && (settings_info = settings_info->next)) do {
if(settings_info->groups && (found = report_group_settings(settings_info->groups, settings_info->n_groups, args)))
break;
} while((settings_info = settings_info->next));
if(!found)
hal.stream.write( ASCII_EOL "N/A" ASCII_EOL);
}
}
return Status_OK;
}
// grblHAL settings print out.
static int cmp_settings (const void *a, const void *b)
{
return (*(setting_detail_t **)(a))->id - (*(setting_detail_t **)(b))->id;
}
static bool report_setting (const setting_detail_t *setting, uint_fast16_t offset, void *data)
{
appendbuf(3, "$", uitoa(setting->id + offset), "=");
char *value = setting_get_value(setting, offset);
if(value) {
hal.stream.write(buf);
hal.stream.write(value);
hal.stream.write(ASCII_EOL);
}
return true;
}
status_code_t report_grbl_setting (setting_id_t id, void *data)
{
status_code_t status = Status_OK;
const setting_detail_t *setting = setting_get_details(id, NULL);
if(setting)
grbl.report.setting(setting, id - setting->id, data);
else
status = Status_SettingDisabled;
return status;
}
static bool print_setting (const setting_detail_t *setting, uint_fast16_t offset, void *data)
{
if(setting->value != NULL)
grbl.report.setting(setting, offset, data);
else {
hal.stream.write("$");
hal.stream.write(uitoa(setting->id));
hal.stream.write("=N/A" ASCII_EOL);
}
return true;
}
void report_grbl_settings (bool all, void *data)
{
uint_fast16_t idx, n_settings = 0;
const setting_detail_t *setting;
setting_detail_t **all_settings, **psetting;
setting_details_t *details = settings_get_details();
do {
n_settings += details->n_settings;
} while((details = details->next));
details = settings_get_details();
if((all_settings = psetting = calloc(n_settings, sizeof(setting_detail_t *)))) {
n_settings = 0;
// Report core settings
for(idx = 0; idx < details->n_settings; idx++) {
setting = &details->settings[idx];
if((all || setting->type == Setting_IsLegacy || setting->type == Setting_IsLegacyFn) &&
(setting->is_available == NULL ||setting->is_available(setting))) {
*psetting++ = (setting_detail_t *)setting;
n_settings++;
}
}
// Report driver and plugin settings
if(all && (details = details->next)) do {
for(idx = 0; idx < details->n_settings; idx++) {
setting = &details->settings[idx];
if(setting->is_available == NULL ||setting->is_available(setting)) {
*psetting++ = (setting_detail_t *)setting;
n_settings++;
}
}
} while((details = details->next));
qsort(all_settings, n_settings, sizeof(setting_detail_t *), cmp_settings);
for(idx = 0; idx < n_settings; idx++)
settings_iterator(all_settings[idx], print_setting, data);
free(all_settings);
} else do {
for(idx = 0; idx < n_settings; idx++)
settings_iterator(&details->settings[idx], print_setting, data);
} while((details = details->next));
}
// Prints current probe parameters. Upon a probe command, these parameters are updated upon a
// successful probe or upon a failed probe with the G38.3 without errors command (if supported).
// These values are retained until grblHAL is power-cycled, whereby they will be re-zeroed.
void report_probe_parameters (void)
{
// Report in terms of machine position.
float print_position[N_AXIS];
system_convert_array_steps_to_mpos(print_position, sys.probe_position);
hal.stream.write("[PRB:");
hal.stream.write(get_axis_values(print_position));
hal.stream.write(sys.flags.probe_succeeded ? ":1" : ":0");
hal.stream.write("]" ASCII_EOL);
}
// Prints current home position in terms of machine position.
// Bitmask for homed axes attached.
void report_home_position (void)
{
hal.stream.write("[HOME:");
hal.stream.write(get_axis_values(sys.home_position));
hal.stream.write(":");
hal.stream.write(uitoa(sys.homed.mask));
hal.stream.write("]" ASCII_EOL);
}
// Prints current tool offsets.
void report_tool_offsets (void)
{
hal.stream.write("[TLO:");
#if TOOL_LENGTH_OFFSET_AXIS >= 0
hal.stream.write(get_axis_value(gc_state.tool_length_offset[TOOL_LENGTH_OFFSET_AXIS]));
#else
hal.stream.write(get_axis_values(gc_state.tool_length_offset));
#endif
hal.stream.write("]" ASCII_EOL);
}
#if NGC_PARAMETERS_ENABLE
// Prints NIST/LinuxCNC NGC parameter value
status_code_t report_ngc_parameter (ngc_param_id_t id)
{
float value;
hal.stream.write("[PARAM:");
hal.stream.write(uitoa(id));
if(ngc_param_get(id, &value)) {
hal.stream.write("=");
hal.stream.write(trim_float(ftoa(value, ngc_float_decimals())));
} else
hal.stream.write("=N/A");
hal.stream.write("]" ASCII_EOL);
return Status_OK;
}
// Prints named LinuxCNC NGC parameter value
status_code_t report_named_ngc_parameter (char *arg)
{
float value;
hal.stream.write("[PARAM:");
hal.stream.write(arg);
if(ngc_named_param_get(arg, &value)) {
hal.stream.write("=");
hal.stream.write(trim_float(ftoa(value, ngc_float_decimals())));
} else
hal.stream.write("=N/A");
hal.stream.write("]" ASCII_EOL);
return Status_OK;
}
#endif
// Prints grblHAL NGC parameters (coordinate offsets, probing, tool table)
void report_ngc_parameters (void)
{
uint_fast8_t idx;
float coord_data[N_AXIS];
if(gc_state.modal.scaling_active) {
hal.stream.write("[G51:");
hal.stream.write(get_axis_values(gc_get_scaling()));
hal.stream.write("]" ASCII_EOL);
}
for (idx = 0; idx < N_CoordinateSystems; idx++) {
if (!(settings_read_coord_data((coord_system_id_t)idx, &coord_data))) {
grbl.report.status_message(Status_SettingReadFail);
return;
}
hal.stream.write("[G");
switch (idx) {
case CoordinateSystem_G28:
hal.stream.write("28");
break;
case CoordinateSystem_G30:
hal.stream.write("30");
break;
case CoordinateSystem_G92:
break;
default: // G54-G59
hal.stream.write(map_coord_system((coord_system_id_t)idx));
break;
}
if(idx != CoordinateSystem_G92) {
hal.stream.write(":");
hal.stream.write(get_axis_values(coord_data));
hal.stream.write("]" ASCII_EOL);
}
}
// Print G92, G92.1 which are not persistent in memory
hal.stream.write("92:");
hal.stream.write(get_axis_values(gc_state.g92_coord_offset));
hal.stream.write("]" ASCII_EOL);
for (idx = 1; idx <= grbl.tool_table.n_tools; idx++) {
hal.stream.write("[T:");
hal.stream.write(uitoa((uint32_t)idx));
hal.stream.write("|");
hal.stream.write(get_axis_values(grbl.tool_table.tool[idx].offset));
hal.stream.write("|");
hal.stream.write(get_axis_value(grbl.tool_table.tool[idx].radius));
hal.stream.write("]" ASCII_EOL);
}
#if COMPATIBILITY_LEVEL < 10
if(settings.homing.flags.enabled)
report_home_position();
#endif
report_tool_offsets(); // Print tool length offset value.
report_probe_parameters(); // Print probe parameters. Not persistent in memory.
if(sys.tlo_reference_set.mask) { // Print tool length reference offset. Not persistent in memory.
plane_t plane;
gc_get_plane_data(&plane, gc_state.modal.plane_select);
hal.stream.write("[TLR:");
hal.stream.write(get_axis_value(sys.tlo_reference[plane.axis_linear] / settings.axis[plane.axis_linear].steps_per_mm));
hal.stream.write("]" ASCII_EOL);
}
if(grbl.on_report_ngc_parameters)
grbl.on_report_ngc_parameters();
}
static inline bool is_g92_active (void)
{
bool active = false;
uint_fast32_t idx = N_AXIS;
do {
idx--;
active = !(gc_state.g92_coord_offset[idx] == 0.0f || gc_state.g92_coord_offset[idx] == -0.0f);
} while(idx && !active);
return active;
}
// Print current gcode parser mode state
void report_gcode_modes (void)
{
hal.stream.write("[GC:G");
if (gc_state.modal.motion >= MotionMode_ProbeToward) {
hal.stream.write("38.");
hal.stream.write(uitoa((uint32_t)(gc_state.modal.motion - (MotionMode_ProbeToward - 2))));
} else
hal.stream.write(uitoa((uint32_t)gc_state.modal.motion));
hal.stream.write(" G");
hal.stream.write(map_coord_system(gc_state.modal.coord_system.id));
#if COMPATIBILITY_LEVEL < 10
if(is_g92_active())
hal.stream.write(" G92");
#endif
if(settings.mode == Mode_Lathe)
hal.stream.write(gc_state.modal.diameter_mode ? " G7" : " G8");
hal.stream.write(" G");
hal.stream.write(uitoa((uint32_t)(gc_state.modal.plane_select + 17)));
hal.stream.write(gc_state.modal.units_imperial ? " G20" : " G21");
hal.stream.write(gc_state.modal.distance_incremental ? " G91" : " G90");
hal.stream.write(" G");
hal.stream.write(uitoa((uint32_t)(93 + (gc_state.modal.feed_mode == FeedMode_UnitsPerRev ? 2 : gc_state.modal.feed_mode ^ 1))));
if(settings.mode == Mode_Lathe && gc_spindle_get()->cap.variable)
hal.stream.write(gc_state.modal.spindle.rpm_mode == SpindleSpeedMode_RPM ? " G97" : " G96");
#if COMPATIBILITY_LEVEL < 10
if(gc_state.modal.tool_offset_mode == ToolLengthOffset_Cancel)
hal.stream.write(" G49");
else {
hal.stream.write(" G43");
if(gc_state.modal.tool_offset_mode != ToolLengthOffset_Enable)
hal.stream.write(gc_state.modal.tool_offset_mode == ToolLengthOffset_EnableDynamic ? ".1" : ".2");
}
hal.stream.write(gc_state.modal.retract_mode == CCRetractMode_RPos ? " G99" : " G98");
if(gc_state.modal.scaling_active) {
hal.stream.write(" G51:");
axis_signals_tostring(buf, gc_get_g51_state());
hal.stream.write(buf);
} else
hal.stream.write(" G50");
#endif
if (gc_state.modal.program_flow) {
switch (gc_state.modal.program_flow) {
case ProgramFlow_Paused:
hal.stream.write(" M0");
break;
case ProgramFlow_OptionalStop:
hal.stream.write(" M1");
break;
case ProgramFlow_CompletedM2:
hal.stream.write(" M2");
break;
case ProgramFlow_CompletedM30:
hal.stream.write(" M30");
break;
case ProgramFlow_CompletedM60:
hal.stream.write(" M60");
break;
default:
break;
}
}
hal.stream.write(gc_state.modal.spindle.state.on ? (gc_state.modal.spindle.state.ccw ? " M4" : " M3") : " M5");
if(gc_state.tool_change)
hal.stream.write(" M6");
if (gc_state.modal.coolant.value) {
if (gc_state.modal.coolant.mist)
hal.stream.write(" M7");
if (gc_state.modal.coolant.flood)
hal.stream.write(" M8");
} else
hal.stream.write(" M9");
if (sys.override.control.feed_rate_disable)
hal.stream.write(" M50");
if (sys.override.control.spindle_rpm_disable)
hal.stream.write(" M51");
if (sys.override.control.feed_hold_disable)
hal.stream.write(" M53");
if (settings.parking.flags.enable_override_control && sys.override.control.parking_disable)
hal.stream.write(" M56");
hal.stream.write(appendbuf(2, " T", uitoa((uint32_t)gc_state.tool->tool_id)));
hal.stream.write(appendbuf(2, " F", get_rate_value(gc_state.feed_rate)));
if(gc_spindle_get()->cap.variable)
hal.stream.write(appendbuf(2, " S", ftoa(gc_state.spindle.rpm, N_DECIMAL_RPMVALUE)));
hal.stream.write("]" ASCII_EOL);
}
// Prints specified startup line
void report_startup_line (uint8_t n, char *line)
{
hal.stream.write(appendbuf(3, "$N", uitoa((uint32_t)n), "="));
hal.stream.write(line);
hal.stream.write(ASCII_EOL);
}
void report_execute_startup_message (char *line, status_code_t status_code)
{
hal.stream.write(">");
hal.stream.write(line);
hal.stream.write(":");
grbl.report.status_message(status_code);
}
// Prints build info line
void report_build_info (char *line, bool extended)
{
char buf[100];
hal.stream.write("[VER:" GRBL_VERSION ".");
hal.stream.write(uitoa(GRBL_BUILD));
hal.stream.write(":");
hal.stream.write(line);
hal.stream.write("]" ASCII_EOL);
#if COMPATIBILITY_LEVEL == 0
extended = true;
#endif
// Generate compile-time build option list
char *append = &buf[5];
spindle_ptrs_t *spindle = spindle_get(0);
strcpy(buf, "[OPT:");
if(spindle && spindle->cap.variable)
*append++ = 'V';
*append++ = 'N';
if(hal.coolant_cap.mist)
*append++ = 'M';
#if COREXY
*append++ = 'C';
#endif
if(settings.parking.flags.enabled)
*append++ = 'P';
if(settings.homing.flags.force_set_origin)
*append++ = 'Z';
if(settings.homing.flags.single_axis_commands)
*append++ = 'H';
if(settings.limits.flags.two_switches)
*append++ = 'T';
if(settings.probe.allow_feed_override)
*append++ = 'A';
if(spindle && !spindle->cap.direction) // NOTE: Shown when disabled.
*append++ = 'D';
if(settings.spindle.flags.enable_rpm_controlled)
*append++ = '0';
if(hal.driver_cap.software_debounce)
*append++ = 'S';
if(settings.parking.flags.enable_override_control)
*append++ = 'R';
if(!settings.homing.flags.init_lock)
*append++ = 'L';
if(hal.signals_cap.safety_door_ajar)
*append++ = '+';
#if !ENABLE_RESTORE_NVS_WIPE_ALL // NOTE: Shown when disabled.
*append++ = '*';
#endif
#if !ENABLE_RESTORE_NVS_DEFAULT_SETTINGS // NOTE: Shown when disabled.
*append++ = '$';
#endif
#if !ENABLE_RESTORE_NVS_CLEAR_PARAMETERS // NOTE: Shown when disabled.
*append++ = '#';
#endif
#if DISABLE_BUILD_INFO_WRITE_COMMAND // NOTE: Shown when disabled.
*append++ = 'I';
#endif
if(!settings.status_report.sync_on_wco_change) // NOTE: Shown when disabled.
*append++ = 'W';
if(hal.stepper.get_ganged)
*append++ = '2';
*append++ = ',';
*append = '\0';
hal.stream.write(buf);
// NOTE: Compiled values, like override increments/max/min values, may be added at some point later.
hal.stream.write(uitoa((uint32_t)plan_get_buffer_size()));
hal.stream.write(",");
hal.stream.write(uitoa(hal.rx_buffer_size));
if(extended) {
hal.stream.write(",");
hal.stream.write(uitoa((uint32_t)N_AXIS));
hal.stream.write(",");
hal.stream.write(uitoa(grbl.tool_table.n_tools));
}
hal.stream.write("]" ASCII_EOL);
if(extended) {
uint_fast8_t idx;
nvs_io_t *nvs = nvs_buffer_get_physical();
strcat(strcpy(buf, "[AXS:"), uitoa(N_AXIS));
append = &buf[6];
*append++ = ':';
for(idx = 0; idx < N_AXIS; idx++)
*append++ = *axis_letter[idx];
*append = '\0';
hal.stream.write(strcat(buf, "]" ASCII_EOL));
strcpy(buf, "[NEWOPT:ENUMS,RT");
strcat(buf, settings.flags.legacy_rt_commands ? "+," : "-,");
if(settings.homing.flags.enabled)
strcat(buf, "HOME,");
if(!hal.probe.get_state)
strcat(buf, "NOPROBE,");
else if(hal.signals_cap.probe_disconnected)
strcat(buf, "PC,");
if(hal.signals_cap.stop_disable)
strcat(buf, "OS,");
if(hal.signals_cap.block_delete)
strcat(buf, "BD,");
if(hal.signals_cap.e_stop)
strcat(buf, "ES,");
if(hal.driver_cap.mpg_mode)
strcat(buf, "MPG,");
#if LATHE_UVW_OPTION
strcat(buf, "LATHE,LATHEUVW,");
#else
if(settings.mode == Mode_Lathe)
strcat(buf, "LATHE,");
#endif
if(hal.driver_cap.laser_ppi_mode)
strcat(buf, "PPI,");
if(hal.reboot)
strcat(buf, "REBOOT,");
#if NGC_EXPRESSIONS_ENABLE
strcat(buf, "EXPR,");
#endif
if(hal.tool.change)
strcat(buf, hal.driver_cap.atc ? "ATC," : "TC,"); // Tool change supported (M6)
if(hal.driver_cap.spindle_sync)
strcat(buf, "SS,");
#ifndef NO_SETTINGS_DESCRIPTIONS
strcat(buf, "SED,");