⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs274ngc_pre.cc

📁 Source code for an Numeric Cmputer
💻 CC
📖 第 1 页 / 共 3 页
字号:
/********************************************************************* Description: rs274ngc_pre.cc**   Derived from a work by Thomas Kramer** Author:* License: GPL Version 2* System: Linux*    * Copyright (c) 2004 All rights reserved.** Last change:* $Revision: 1.26 $* $Author: alex_joni $* $Date: 2006/03/20 21:15:40 $********************************************************************//* rs274ngc.ccThis rs274ngc.cc file contains the source code for (1) the kernel ofseveral rs274ngc interpreters and (2) two of the four sets of interfacefunctions declared in canon.hh:1. interface functions to call to tell the interpreter what to do.   These all return a status value.2. interface functions to call to get information from the interpreter.Kernel functions call each other. A few kernel functions are called byinterface functions.Interface function names all begin with "Interp::".Error handling is by returning a status value of either a non-errorcode (INTERP_OK, INTERP_EXIT, etc.) or some specific error codefrom each function where there is a possibility of error.  If an erroroccurs, processing is always stopped, and control is passed back upthrough the function call hierarchy to an interface function; theerror code is also passed back up. The stack of functions called isalso recorded. The external program calling an interface function maythen handle the error further as it sees fit.Since returned values are usually used as just described to handle thepossibility of errors, an alternative method of passing calculatedvalues is required. In general, if function A needs a value forvariable V calculated by function B, this is handled by passing apointer to V from A to B, and B calculates and sets V.There are a lot of functions named read_XXXX. All such functions readcharacters from a string using a counter. They all reset the counterto point at the character in the string following the last one used bythe function. The counter is passed around from function to functionby using pointers to it. The first character read by each of thesefunctions is expected to be a member of some set of characters (oftena specific character), and each function checks the first character.This version of the interpreter not saving input lines. A list of alllines will be needed in future versions to implement loops, andprobably for other purposes.This version does not use any additional memory as it runs. Nomemory is allocated by the source code.This version does not suppress superfluous commands, such as a commandto start the spindle when the spindle is already turning, or a commandto turn on flood coolant, when flood coolant is already on.  When theinterpreter is being used for direct control of the machining center,suppressing superfluous commands might confuse the user and could bedangerous, but when it is used to translate from one file to another,suppression can produce more concise output. Future versions mightinclude an option for suppressing superfluous commands.****************************************************************************/#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <ctype.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/time.h>#include <time.h>#include <unistd.h>#include "inifile.hh"		// INIFILE#include "rs274ngc.hh"#include "rs274ngc_return.hh"//#include "rs274ngc_errors.cc"#include "units.h"extern char * _rs274ngc_errors[];#define LOG_FILE "/dev/null"void Interp::doLog(char *fmt, ...){    struct timeval tv;    struct tm *tm;    va_list ap;    va_start(ap, fmt);    if(log_file == NULL)    {       log_file = fopen(LOG_FILE, "a");    }    if(log_file == NULL)    {         fprintf(stderr, "(%d)Unable to open log file:%s\n",                  getpid(), LOG_FILE);    }    gettimeofday(&tv, NULL);    tm = localtime(&tv.tv_sec);    fprintf(log_file, "%04d%02d%02d-%02d:%02d:%02d.%03ld ",	    tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,	    tm->tm_hour, tm->tm_min, tm->tm_sec,	    tv.tv_usec/1000);    vfprintf(log_file, fmt, ap);    fflush(log_file);    va_end(ap);}/****************************************************************************//*The functions in this section of this file are functions forexternal programs to call to tell the rs274ngc interpreterwhat to do. They are declared in rs274ngc.hh.*//***********************************************************************//*! Interp::closeReturned Value: int (INTERP_OK)Side Effects:   The NC-code file is closed if open.   The _setup world model is reset.Called By: external programs*/int Interp::close(){  if (_setup.file_pointer != NULL) {    fclose(_setup.file_pointer);    _setup.file_pointer = NULL;  }  reset();  return INTERP_OK;}/***********************************************************************//*! Interp::executeReturned Value: int)   If execute_block returns INTERP_EXIT, this returns that.   If execute_block returns INTERP_EXECUTE_FINISH, this returns that.   If execute_block returns an error code, this returns that code.   Otherwise, this returns INTERP_OK.Side Effects:   Calls to canonical machining commands are made.   The interpreter variables are changed.   At the end of the program, the file is closed.   If using a file, the active G codes and M codes are updated.Called By: external programsThis executes a previously parsed block.*/int Interp::execute(const char *command){  static char name[] = "Interp::execute";  int status;  int n;  if (NULL != command) {    status = read(command);    if (status != INTERP_OK) {      return status;    }  }  // process control functions -- will skip if skipping  if (_setup.block1.o_number != 0)    {      CHP(convert_control_functions(&(_setup.block1), &_setup));      return INTERP_OK;    }  // skip if skipping  if(_setup.skipping_o)    {      logDebug("skipping to line: %d", _setup.skipping_o);      return INTERP_OK;    }  for (n = 0; n < _setup.parameter_occurrence; n++)  {  // copy parameter settings from parameter buffer into parameter table    _setup.parameters[_setup.parameter_numbers[n]]      = _setup.parameter_values[n];  }  if (_setup.line_length != 0) {        /* line not blank */    status = execute_block(&(_setup.block1), &_setup);    write_g_codes(&(_setup.block1), &_setup);    write_m_codes(&(_setup.block1), &_setup);    write_settings(&_setup);    if ((status != INTERP_OK) &&        (status != INTERP_EXECUTE_FINISH) && (status != INTERP_EXIT))      ERP(status);  } else                        /* blank line is OK */    status = INTERP_OK;  return status;}/***********************************************************************//*! Interp::exitReturned Value: int (INTERP_OK)Side Effects: See belowCalled By: external programsThe system parameters are saved to a file and some parts of the worldmodel are reset. If GET_EXTERNAL_PARAMETER_FILE_NAME provides anon-empty file name, that name is used for the file that iswritten. Otherwise, the default parameter file name is used.*/int Interp::exit(){  char file_name[LINELEN];  GET_EXTERNAL_PARAMETER_FILE_NAME(file_name, (LINELEN - 1));  save_parameters(((file_name[0] ==                             0) ?                            RS274NGC_PARAMETER_FILE_NAME_DEFAULT :                            file_name), _setup.parameters);  reset();  return INTERP_OK;}/***********************************************************************//*! rs274_ngc_initReturned Value: int   If any of the following errors occur, this returns the error code shown.   Otherwise, this returns INTERP_OK.   1. Interp::restore_parameters returns an error code.   2. Parameter 5220, the work coordinate system index, is not in the range      1 to 9: NCE_COORDINATE_SYSTEM_INDEX_PARAMETER_5220_OUT_OF_RANGESide Effects:   Many values in the _setup structure are reset.   A USE_LENGTH_UNITS canonical command call is made.   A SET_FEED_REFERENCE canonical command call is made.   A SET_ORIGIN_OFFSETS canonical command call is made.   An INIT_CANON call is made.Called By: external programsCurrently we are running only in CANON_XYZ feed_reference mode.  Thereis no command regarding feed_reference in the rs274 language (weshould try to get one added). The initialization routine, therefore,always calls SET_FEED_REFERENCE(CANON_XYZ).*/int Interp::init(){  static char name[] = "Interp::init";  int k;                        // starting index in parameters of origin offsets  int status;  char filename[LINELEN];  double *pars;                 // short name for _setup.parameters  INIT_CANON();  _setup.length_units = GET_EXTERNAL_LENGTH_UNIT_TYPE();  USE_LENGTH_UNITS(_setup.length_units);  GET_EXTERNAL_PARAMETER_FILE_NAME(filename, LINELEN);  if (filename[0] == 0)    strcpy(filename, RS274NGC_PARAMETER_FILE_NAME_DEFAULT);  CHP(restore_parameters(filename));  pars = _setup.parameters;  _setup.origin_index = (int) (pars[5220] + 0.0001);  CHK(((_setup.origin_index < 1) || (_setup.origin_index > 9)),      NCE_COORDINATE_SYSTEM_INDEX_PARAMETER_5220_OUT_OF_RANGE);  k = (5200 + (_setup.origin_index * 20));  SET_ORIGIN_OFFSETS(USER_TO_PROGRAM_LEN(pars[k + 1] + pars[5211]),                     USER_TO_PROGRAM_LEN(pars[k + 2] + pars[5212]),                      USER_TO_PROGRAM_LEN(pars[k + 3] + pars[5213]),                     USER_TO_PROGRAM_ANG(pars[k + 4] + pars[5214]),                     USER_TO_PROGRAM_ANG(pars[k + 5] + pars[5215]),                     USER_TO_PROGRAM_ANG(pars[k + 6] + pars[5216]));  SET_FEED_REFERENCE(CANON_XYZ);  _setup.AA_axis_offset = USER_TO_PROGRAM_ANG(pars[5214]);//_setup.Aa_current set in Interp::synch  _setup.AA_origin_offset = USER_TO_PROGRAM_ANG(pars[k + 4]);  _setup.BB_axis_offset = USER_TO_PROGRAM_ANG(pars[5215]);//_setup.Bb_current set in Interp::synch  _setup.BB_origin_offset = USER_TO_PROGRAM_ANG(pars[k + 5]);  _setup.CC_axis_offset = USER_TO_PROGRAM_ANG(pars[5216]);//_setup.Cc_current set in Interp::synch  _setup.CC_origin_offset = USER_TO_PROGRAM_ANG(pars[k + 6]);//_setup.active_g_codes initialized below//_setup.active_m_codes initialized below//_setup.active_settings initialized below  _setup.axis_offset_x = USER_TO_PROGRAM_LEN(pars[5211]);  _setup.axis_offset_y = USER_TO_PROGRAM_LEN(pars[5212]);  _setup.axis_offset_z = USER_TO_PROGRAM_LEN(pars[5213]);//_setup.block1 does not need initialization  _setup.blocktext[0] = 0;//_setup.current_slot set in Interp::synch//_setup.current_x set in Interp::synch//_setup.current_y set in Interp::synch//_setup.current_z set in Interp::synch  _setup.cutter_comp_side = OFF;//_setup.cycle values do not need initialization  _setup.distance_mode = MODE_ABSOLUTE;  _setup.feed_mode = UNITS_PER_MINUTE;  _setup.feed_override = ON;//_setup.feed_rate set in Interp::synch  _setup.filename[0] = 0;  _setup.file_pointer = NULL;//_setup.flood set in Interp::synch  _setup.length_offset_index = 1;//_setup.length_units set in Interp::synch  _setup.line_length = 0;  _setup.linetext[0] = 0;//_setup.mist set in Interp::synch  _setup.motion_mode = G_80;//_setup.origin_index set above  _setup.origin_offset_x = USER_TO_PROGRAM_LEN(pars[k + 1]);  _setup.origin_offset_y = USER_TO_PROGRAM_LEN(pars[k + 2]);  _setup.origin_offset_z = USER_TO_PROGRAM_LEN(pars[k + 3]);//_setup.parameters set above//_setup.parameter_occurrence does not need initialization//_setup.parameter_numbers does not need initialization//_setup.parameter_values does not need initialization//_setup.percent_flag does not need initialization//_setup.plane set in Interp::synch  _setup.probe_flag = OFF;  _setup.program_x = UNKNOWN;   /* for cutter comp */  _setup.program_y = UNKNOWN;   /* for cutter comp *///_setup.retract_mode does not need initialization//_setup.selected_tool_slot set in Interp::synch  _setup.sequence_number = 0;   /*DOES THIS NEED TO BE AT TOP? *///_setup.speed set in Interp::synch  _setup.speed_feed_mode = CANON_INDEPENDENT;  _setup.speed_override = ON;//_setup.spindle_turning set in Interp::synch//_setup.stack does not need initialization//_setup.stack_index does not need initialization  _setup.tool_length_offset = 0.0;//_setup.tool_max set in Interp::synch//_setup.tool_table set in Interp::synch  _setup.tool_table_index = 1;//_setup.traverse_rate set in Interp::synch  write_g_codes((block_pointer) NULL, &_setup);  write_m_codes((block_pointer) NULL, &_setup);  write_settings(&_setup);  // initialization stuff for subroutines and control structures  _setup.call_level = 0;  _setup.defining_sub = 0;  _setup.skipping_o = 0;  _setup.oword_labels = 0;  // Synch rest of settings to external world  synch();  return INTERP_OK;}/***********************************************************************//*! Interp::load_tool_tableReturned Value: int

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -