📄 interp_read.cc
字号:
1. The first character read is not f: NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. An f_number has already been inserted in the block: NCE_MULTIPLE_F_WORDS_ON_ONE_LINE 3. The f_number is negative: NCE_NEGATIVE_F_WORD_USEDSide effects: counter is reset to point to the first character following the f_number. The f_number is inserted in block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'f'. The function reads characterswhich tell how to set the f_number, up to the start of the next itemor the end of the line. This information is inserted in the block.The value may be a real number or something that evaluates to a realnumber, so read_real_value is used to read it. Parameters may beinvolved, so the parameters argument is required. The value is alwaysa feed rate.*/int Interp::read_f(char *line, //!< string: line of RS274 code being processed int *counter, //!< pointer to a counter for position on the line block_pointer block, //!< pointer to a block being filled from the line double *parameters) //!< array of system parameters { static char name[] = "read_f"; double value; int status; CHK((line[*counter] != 'f'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); *counter = (*counter + 1); CHK((block->f_number > -1.0), NCE_MULTIPLE_F_WORDS_ON_ONE_LINE); CHP(read_real_value(line, counter, &value, parameters)); CHK((value < 0.0), NCE_NEGATIVE_F_WORD_USED); block->f_number = value; return INTERP_OK;}/****************************************************************************//*! read_gReturned Value: int If read_real_value returns an error code, this returns that code. If any of the following errors occur, this returns the error code shown. Otherwise, it returns INTERP_OK. 1. The first character read is not g: NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. The value is negative: NCE_NEGATIVE_G_CODE_USED 3. The value differs from a number ending in an even tenth by more than 0.0001: NCE_G_CODE_OUT_OF_RANGE 4. The value is greater than 99.9: NCE_G_CODE_OUT_OF_RANGE 5. The value is not the number of a valid g code: NCE_UNKNOWN_G_CODE_USED 6. Another g code from the same modal group has already been inserted in the block: NCE_TWO_G_CODES_USED_FROM_SAME_MODAL_GROUPSide effects: counter is reset to the character following the end of the g_code. A g code is inserted as the value of the appropriate mode in the g_modes array in the block. The g code counter in the block is increased by 1.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'g', indicating a g_code. Thefunction reads characters which tell how to set the g_code.The RS274/NGC manual [NCMS, page 51] allows g_codes to be representedby expressions and provide [NCMS, 71 - 73] that a g_code must evaluateto to a number of the form XX.X (59.1, for example). The manual does notsay how close an expression must come to one of the allowed values forit to be legitimate. Is 59.099999 allowed to mean 59.1, for example?In the interpreter, we adopt the convention that the evaluated numberfor the g_code must be within 0.0001 of a value of the form XX.XTo simplify the handling of g_codes, we convert them to integers bymultiplying by 10 and rounding down or up if within 0.001 of aninteger. Other functions that deal with g_codes handle themsymbolically, however. The symbols are defined in rs274NGC.hhwhere G_1 is 10, G_83 is 830, etc.This allows any number of g_codes on one line, provided that no twoare in the same modal group.This allows G80 on the same line as one other g_code with the samemode. If this happens, the G80 is simply ignored.*/int Interp::read_g(char *line, //!< string: line of RS274/NGC code being processed int *counter, //!< pointer to a counter for position on the line block_pointer block, //!< pointer to a block being filled from the line double *parameters) //!< array of system parameters { static char name[] = "read_g"; double value_read; int value; int mode; int status; CHK((line[*counter] != 'g'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); *counter = (*counter + 1); CHP(read_real_value(line, counter, &value_read, parameters)); value_read = (10.0 * value_read); value = (int) floor(value_read); if ((value_read - value) > 0.999) value = (int) ceil(value_read); else if ((value_read - value) > 0.001) ERM(NCE_G_CODE_OUT_OF_RANGE); CHK((value > 999), NCE_G_CODE_OUT_OF_RANGE); CHK((value < 0), NCE_NEGATIVE_G_CODE_USED); mode = _gees[value]; CHK((mode == -1), NCE_UNKNOWN_G_CODE_USED); if ((value == G_80) && (block->g_modes[mode] != -1)); else { if (block->g_modes[mode] == G_80); else { CHK((block->g_modes[mode] != -1), NCE_TWO_G_CODES_USED_FROM_SAME_MODAL_GROUP); } block->g_modes[mode] = value; } return INTERP_OK;}/****************************************************************************//*! read_hReturned Value: int If read_integer_value returns an error code, this returns that code. If any of the following errors occur, this returns the error code shown. Otherwise, it returns INTERP_OK. 1. The first character read is not h: NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. An h_number has already been inserted in the block: NCE_MULTIPLE_H_WORDS_ON_ONE_LINE 3. The value is negative: NCE_NEGATIVE_H_WORD_TOOL_LENGTH_OFFSET_INDEX_USED 4. The value is greater than _setup.tool_max: NCE_TOOL_LENGTH_OFFSET_INDEX_TOO_BIGSide effects: counter is reset to the character following the h_number. An h_number is inserted in the block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'h', indicating a tool lengthoffset index. The function reads characters which give the (integer)value of the tool length offset index (not the actual distance of theoffset).*/int Interp::read_h(char *line, //!< string: line of RS274/NGC code being processed int *counter, //!< pointer to a counter for position on the line block_pointer block, //!< pointer to a block being filled from the line double *parameters) //!< array of system parameters { static char name[] = "read_h"; int value; int status; CHK((line[*counter] != 'h'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); *counter = (*counter + 1); CHK((block->h_number > -1), NCE_MULTIPLE_H_WORDS_ON_ONE_LINE); CHP(read_integer_value(line, counter, &value, parameters)); CHK((value < 0), NCE_NEGATIVE_H_WORD_TOOL_LENGTH_OFFSET_INDEX_USED); CHK((value > _setup.tool_max), NCE_TOOL_LENGTH_OFFSET_INDEX_TOO_BIG); block->h_number = value; return INTERP_OK;}/****************************************************************************//*! read_iReturned Value: int If read_real_value returns an error code, this returns that code. If any of the following errors occur, this returns the error code shown. Otherwise, it returns INTERP_OK. 1. The first character read is not i: NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. An i_coordinate has already been inserted in the block: NCE_MULTIPLE_I_WORDS_ON_ONE_LINESide effects: counter is reset. The i_flag in the block is turned on. An i_coordinate setting is inserted in the block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'i', indicating a i_coordinatesetting. The function reads characters which tell how to set thecoordinate, up to the start of the next item or the end of the line.This information is inserted in the block. The counter is then set topoint to the character following.The value may be a real number or something that evaluates to areal number, so read_real_value is used to read it. Parametersmay be involved.*/int Interp::read_i(char *line, //!< string: line of RS274 code being processed int *counter, //!< pointer to a counter for position on the line block_pointer block, //!< pointer to a block being filled from the line double *parameters) //!< array of system parameters { static char name[] = "read_i"; double value; int status; CHK((line[*counter] != 'i'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); *counter = (*counter + 1); CHK((block->i_flag != OFF), NCE_MULTIPLE_I_WORDS_ON_ONE_LINE); CHP(read_real_value(line, counter, &value, parameters)); block->i_flag = ON; block->i_number = value; return INTERP_OK;}/****************************************************************************//*! read_integer_unsignedReturned Value: int If any of the following errors occur, this returns the error shown. Otherwise, INTERP_OK is returned. 1. The first character is not a digit: NCE_BAD_FORMAT_UNSIGNED_INTEGER 2. sscanf fails: NCE_SSCANF_FAILEDSide effects: The number read from the line is put into what integer_ptr points at.Called by: read_line_numberThis reads an explicit unsigned (positive) integer from a string,starting from the position given by *counter. It expects to find oneor more digits. Any character other than a digit terminates readingthe integer. Note that if the first character is a sign (+ or -),an error will be reported (since a sign is not a digit).*/int Interp::read_integer_unsigned(char *line, //!< string: line of RS274 code being processed int *counter, //!< pointer to a counter for position on the line int *integer_ptr) //!< pointer to the value being read { static char name[] = "read_integer_unsigned"; int n; char c; for (n = *counter;; n++) { c = line[n]; if ((c < 48) || (c > 57)) break; } CHK((n == *counter), NCE_BAD_FORMAT_UNSIGNED_INTEGER); if (sscanf(line + *counter, "%d", integer_ptr) == 0) ERM(NCE_SSCANF_FAILED); *counter = n; return INTERP_OK;}/****************************************************************************//*! read_integer_valueReturned Value: int If read_real_value returns an error code, this returns that code. If any of the following errors occur, this returns the error code shown. Otherwise, it returns INTERP_OK. 1. The returned value is not close to an integer: NCE_NON_INTEGER_VALUE_FOR_INTEGERSide effects: The number read from the line is put into what integer_ptr points at.Called by: read_d read_l read_h read_m read_parameter read_parameter_setting read_tThis reads an integer (positive, negative or zero) from a string,starting from the position given by *counter. The value beingread may be written with a decimal point or it may be an expressioninvolving non-integers, as long as the result comes out within 0.0001of an integer.This proceeds by calling read_real_value and checking that it isclose to an integer, then returning the integer it is close to.*/int Interp::read_integer_value(char *line, //!< string: line of RS274/NGC code being processed int *counter, //!< pointer to a counter for position on the line int *integer_ptr, //!< pointer to the value being read double *parameters) //!< array of system parameters { static char name[] = "read_integer_value"; double float_value; int status; CHP(read_real_value(line, counter, &float_value, parameters)); *integer_ptr = (int) floor(float_value); if ((float_value - *integer_ptr) > 0.9999) { *integer_ptr = (int) ceil(float_value); } else if ((float_value - *integer_ptr) > 0.0001) ERM(NCE_NON_INTEGER_VALUE_FOR_INTEGER); return INTERP_OK;}/****************************************************************************//*! read_itemsReturned Value: int If read_line_number or read_one_item returns an error code, this returns that code. Otherwise, it returns INTERP_OK.Side effects: One line of RS274 code is read and data inserted into a block. The counter which is passed around among the readers is initialized. System parameters may be reset.Called by: parse_line*/int Interp::read_items(block_pointer block, //!< pointer to a block being filled from the line char *line, //!< string: line of RS274/NGC code being processed double *parameters) //!< array of system parameters { static char name[] = "read_items"; int counter; int length; int status; length = strlen(line); counter = 0; if (line[counter] == '/') /* skip the slash character if first */ counter++; if (line[counter] == 'o') /* Handle 'o' explicitly here. Default is to read letters via pointer calls to related reader functions. 'o' control lines have their own commands and command handlers. */ { CHP(read_o(line, &counter, block, parameters)); return INTERP_OK; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -