grblHAL core  20250320
ngc_expr.h File Reference

Go to the source code of this file.

Functions

status_code_t ngc_read_name (char *line, uint_fast8_t *pos, char *buffer)
 Reads the name of a parameter out of the line starting at the index given by the pos offset. More...
 
status_code_t ngc_read_real_value (char *line, uint_fast8_t *pos, float *value)
 Reads a real value out of the line, starting at the index given by the pos offset. The value may be a number, a parameter value, a unary function, or an expression. It calls one of four other readers, depending upon the first character. More...
 
status_code_t ngc_read_integer_value (char *line, uint_fast8_t *pos, int32_t *value)
 Reads an integer (positive, negative or zero) out of the line, starting at the index given by the pos offset. The value being read may be written with a decimal point or it may be an expression involving non-integers, as long as the result comes out within 0.0001 of an integer. More...
 
status_code_t ngc_read_integer_unsigned (char *line, uint_fast8_t *pos, uint32_t *value)
 Reads explicit unsigned (positive) integer out of the line, starting at the index given by the pos offset. It expects to find one or more digits. Any character other than a digit terminates reading the integer. Note that if the first character is a sign (+ or -), an error will be reported (since a sign is not a digit). More...
 
status_code_t ngc_read_parameter (char *line, uint_fast8_t *pos, float *value, bool check)
 Reads the value out of a parameter of the line, starting at the index given by the pos offset. More...
 
status_code_t ngc_eval_expression (char *line, uint_fast8_t *pos, float *value)
 Evaluate expression and set result if successful. More...
 
char * ngc_substitute_parameters (char *line)
 Substitute references to parameters in a string with their values. More...
 
char * ngc_process_comment (char *comment)
 Process gcode comment string. Returns string with substituted parameter references if starts with DEBUG, or PRINT, NULL if not. More...
 

Function Documentation

◆ ngc_eval_expression()

status_code_t ngc_eval_expression ( char *  line,
uint_fast8_t *  pos,
float *  value 
)

Evaluate expression and set result if successful.

Parameters
linepointer to RS274/NGC code (block).
posoffset into line where expression starts.
valuepointer to float where result is to be stored.
Returns
Status_OK enum value if evaluated without error, appropriate status_code_t enum value if not.

◆ ngc_process_comment()

char* ngc_process_comment ( char *  comment)

Process gcode comment string. Returns string with substituted parameter references if starts with DEBUG, or PRINT, NULL if not.

NOTE: The returned string must be freed by the caller.

Parameters
commentpointer to the comment string.
Returns
pointer to the resulting string on success, NULL on failure.

◆ ngc_read_integer_unsigned()

status_code_t ngc_read_integer_unsigned ( char *  line,
uint_fast8_t *  pos,
uint32_t *  value 
)

Reads explicit unsigned (positive) integer out of the line, starting at the index given by the pos offset. It expects to find one or more digits. Any character other than a digit terminates reading the integer. Note that if the first character is a sign (+ or -), an error will be reported (since a sign is not a digit).

Parameters
linepointer to RS274/NGC code (block).
posoffset into line where expression starts.
valuepointer to integer where result is to be stored.
Returns
Status_OK enum value if processed without error, appropriate status_code_t enum value if not.

◆ ngc_read_integer_value()

status_code_t ngc_read_integer_value ( char *  line,
uint_fast8_t *  pos,
int32_t *  value 
)

Reads an integer (positive, negative or zero) out of the line, starting at the index given by the pos offset. The value being read may be written with a decimal point or it may be an expression involving non-integers, as long as the result comes out within 0.0001 of an integer.

This proceeds by calling read_real_value and checking that it is close to an integer, then returning the integer it is close to.

Parameters
linepointer to RS274/NGC code (block).
posoffset into line where expression starts.
valuepointer to integer where result is to be stored.
Returns
Status_OK enum value if processed without error, appropriate status_code_t enum value if not.

◆ ngc_read_name()

status_code_t ngc_read_name ( char *  line,
uint_fast8_t *  pos,
char *  buffer 
)

Reads the name of a parameter out of the line starting at the index given by the pos offset.

Parameters
linepointer to RS274/NGC code (block).
posoffset into line where expression starts.
bufferpointer to a character buffer for the name.
Returns
Status_OK enum value if processed without error, appropriate status_code_t enum value if not.

◆ ngc_read_parameter()

status_code_t ngc_read_parameter ( char *  line,
uint_fast8_t *  pos,
float *  value,
bool  check 
)

Reads the value out of a parameter of the line, starting at the index given by the pos offset.

According to the RS274/NGC manual [NCMS, p. 62], the characters following

may be any "parameter expression". Thus, the following are legal

and mean the same thing (the value of the parameter whose number is stored in parameter 2):

2

#[#2]

Parameter setting is done in parallel, not sequentially. For example if #1 is 5 before the line "#1=10 #2=#1" is read, then after the line is is executed, #1 is 10 and #2 is 5. If parameter setting were done sequentially, the value of #2 would be 10 after the line was executed.

Parameters
linepointer to RS274/NGC code (block).
posoffset into line where expression starts.
valuepointer to float where result is to be stored.
Returns
Status_OK enum value if processed without error, appropriate status_code_t enum value if not.

◆ ngc_read_real_value()

status_code_t ngc_read_real_value ( char *  line,
uint_fast8_t *  pos,
float *  value 
)

Reads a real value out of the line, starting at the index given by the pos offset. The value may be a number, a parameter value, a unary function, or an expression. It calls one of four other readers, depending upon the first character.

Parameters
linepointer to RS274/NGC code (block).
posoffset into line where expression starts.
valuepointer to float where result is to be stored.
Returns
Status_OK enum value if processed without error, appropriate status_code_t enum value if not.

◆ ngc_substitute_parameters()

char* ngc_substitute_parameters ( char *  line)

Substitute references to parameters in a string with their values.

NOTE: The returned string must be freed by the caller.

Parameters
linepointer to the original string.
Returns
pointer to the resulting string on success, NULL on failure.