#include "nuts_bolts.h"
#include <ctype.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "errors.h"
#include "settings.h"
#include "ngc_expr.h"
#include "ngc_params.h"
Macros | |
#define | MAX_STACK 7 |
Enumerations | |
enum | ngc_binary_op_t { NGCBinaryOp_NoOp = 0 , NGCBinaryOp_DividedBy , NGCBinaryOp_Modulo , NGCBinaryOp_Power , NGCBinaryOp_Times , NGCBinaryOp_Binary2 = NGCBinaryOp_Times , NGCBinaryOp_And2 , NGCBinaryOp_ExclusiveOR , NGCBinaryOp_Minus , NGCBinaryOp_NotExclusiveOR , NGCBinaryOp_Plus , NGCBinaryOp_RightBracket , NGCBinaryOp_RelationalFirst , NGCBinaryOp_LT = NGCBinaryOp_RelationalFirst , NGCBinaryOp_EQ , NGCBinaryOp_NE , NGCBinaryOp_LE , NGCBinaryOp_GE , NGCBinaryOp_GT , NGCBinaryOp_RelationalLast = NGCBinaryOp_GT } |
enum | ngc_unary_op_t { NGCUnaryOp_ABS = 1 , NGCUnaryOp_ACOS , NGCUnaryOp_ASIN , NGCUnaryOp_ATAN , NGCUnaryOp_COS , NGCUnaryOp_EXP , NGCUnaryOp_FIX , NGCUnaryOp_FUP , NGCUnaryOp_LN , NGCUnaryOp_Round , NGCUnaryOp_SIN , NGCUnaryOp_SQRT , NGCUnaryOp_TAN , NGCUnaryOp_Exists , NGCUnaryOp_Parameter } |
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_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_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_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_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_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... | |
#define MAX_STACK 7 |
enum ngc_binary_op_t |
enum ngc_unary_op_t |
status_code_t ngc_eval_expression | ( | char * | line, |
uint_fast8_t * | pos, | ||
float * | value | ||
) |
Evaluate expression and set result if successful.
line | pointer to RS274/NGC code (block). |
pos | offset into line where expression starts. |
value | pointer to float where result is to be stored. |
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.
comment | pointer to the comment string. |
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).
line | pointer to RS274/NGC code (block). |
pos | offset into line where expression starts. |
value | pointer to integer where result is to be stored. |
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.
line | pointer to RS274/NGC code (block). |
pos | offset into line where expression starts. |
value | pointer to integer where result is to be stored. |
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.
line | pointer to RS274/NGC code (block). |
pos | offset into line where expression starts. |
buffer | pointer to a character buffer for the name. |
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
and mean the same thing (the value of the parameter whose number is stored in parameter 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.
line | pointer to RS274/NGC code (block). |
pos | offset into line where expression starts. |
value | pointer to float where result is to be stored. |
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.
line | pointer to RS274/NGC code (block). |
pos | offset into line where expression starts. |
value | pointer to float where result is to be stored. |
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.
line | pointer to the original string. |