Skip to content

Commit

Permalink
sai: refactor SAI to store its static vars in a class for easier clea…
Browse files Browse the repository at this point in the history
…nup.

Collectes scattered static variables into a single container class for
one-click reset of all internal state in saicanon. This includes some
cleanup of global variables in canon.hh that were either lazily
implemented (instead of a getter / setter) or not used except by
saicanon.
  • Loading branch information
robEllenberg committed Jun 28, 2019
1 parent 5802197 commit 8794b78
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 231 deletions.
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ HEADERS := \
emc/rs274ngc/interp_fwd.hh \
emc/rs274ngc/interp_base.hh \
emc/rs274ngc/rs274ngc.hh \
emc/rs274ngc/saicanon.hh \
hal/hal.h \
hal/hal_parport.h \
hal/drivers/mesa-hostmot2/hostmot2-serial.h \
Expand Down
7 changes: 3 additions & 4 deletions src/emc/nml_intf/canon.hh
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,8 @@ extern double GET_EXTERNAL_ORIGIN_Z();
// An empty string may be placed in filename.
extern void GET_EXTERNAL_PARAMETER_FILE_NAME(char *filename, int max_size);

extern void SET_PARAMETER_FILE_NAME(const char *name);

// returns the currently active plane
extern CANON_PLANE GET_EXTERNAL_PLANE();

Expand Down Expand Up @@ -935,10 +937,7 @@ extern double GET_EXTERNAL_ANALOG_INPUT(int index, double def);
// Returns the mask of axes present in the system
extern int GET_EXTERNAL_AXIS_MASK();

extern FILE *_outfile; /* where to print, set in main */
extern CANON_TOOL_TABLE _tools[]; /* in canon.cc */
extern int _pockets_max; /* in canon.cc */
extern char _parameter_file_name[]; /* in canon.cc */

#define PARAMETER_FILE_NAME_LENGTH 100

#define USER_DEFINED_FUNCTION_NUM 100
Expand Down
1 change: 1 addition & 0 deletions src/emc/rs274ngc/canonmodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ BOOST_PYTHON_MODULE(emccanon) {
def("GET_EXTERNAL_MIST",&GET_EXTERNAL_MIST);
def("GET_EXTERNAL_MOTION_CONTROL_MODE",&GET_EXTERNAL_MOTION_CONTROL_MODE);
def("GET_EXTERNAL_MOTION_CONTROL_TOLERANCE",&GET_EXTERNAL_MOTION_CONTROL_TOLERANCE);
def("SET_PARAMETER_FILE_NAME",&SET_PARAMETER_FILE_NAME);
def("GET_EXTERNAL_PARAMETER_FILE_NAME",&GET_EXTERNAL_PARAMETER_FILE_NAME);
def("GET_EXTERNAL_PLANE",&GET_EXTERNAL_PLANE);
def("GET_EXTERNAL_POCKETS_MAX",&GET_EXTERNAL_POCKETS_MAX);
Expand Down
6 changes: 6 additions & 0 deletions src/emc/rs274ngc/gcodemodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ double GET_EXTERNAL_POSITION_U() { return _pos_u; }
double GET_EXTERNAL_POSITION_V() { return _pos_v; }
double GET_EXTERNAL_POSITION_W() { return _pos_w; }
void INIT_CANON() {}

void SET_PARAMETER_FILE_NAME(const char *name)
{
strncpy(_parameter_file_name, name, PARAMETER_FILE_NAME_LENGTH);
}

void GET_EXTERNAL_PARAMETER_FILE_NAME(char *name, int max_size) {
PyObject *result = PyObject_GetAttrString(callback, "parameter_file");
if(!result) { name[0] = 0; return; }
Expand Down
17 changes: 9 additions & 8 deletions src/emc/rs274ngc/rs274ngc_pre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2364,20 +2364,21 @@ int Interp::ini_load(const char *filename)
logDebug("Opened inifile:%s:", filename);


char parameter_file_name[LINELEN]={};
if (NULL != (inistring = inifile.Find("PARAMETER_FILE", "RS274NGC"))) {
// found it
strncpy(_parameter_file_name, inistring, LINELEN);
if (_parameter_file_name[LINELEN-1] != '\0') {
strncpy(parameter_file_name, inistring, LINELEN);

if (parameter_file_name[LINELEN-1] != '\0') {
logDebug("%s:[RS274NGC]PARAMETER_FILE is too long (max len %d)", filename, LINELEN-1);
inifile.Close();
_parameter_file_name[0] = '\0';
return -1;
} else {
logDebug("found PARAMETER_FILE:%s:", parameter_file_name);
}
logDebug("found PARAMETER_FILE:%s:", _parameter_file_name);
} else {
// not found, leave RS274NGC_PARAMETER_FILE alone
// not found, leave RS274NGC_PARAMETER_FILE alone
logDebug("did not find PARAMETER_FILE");
}
SET_PARAMETER_FILE_NAME(parameter_file_name);
CHKS(strlen(parameter_file_name) > 0, _("Parameter file name is missing"));

// close it
inifile.Close();
Expand Down
8 changes: 8 additions & 0 deletions src/emc/sai/Submakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ SAISRCS := $(addprefix emc/sai/, saicanon.cc driver.cc dummyemcstat.cc) \
emc/rs274ngc/tool_parse.cc emc/task/taskmodule.cc emc/task/taskclass.cc
USERSRCS += $(SAISRCS)

INCLUDES += emc/sai

../bin/rs274: $(call TOOBJS, $(SAISRCS)) ../lib/librs274.so.0 ../lib/liblinuxcnc.a ../lib/libnml.so.0 \
../lib/liblinuxcnchal.so.0 ../lib/liblinuxcncini.so.0 ../lib/libpyplugin.so.0
$(ECHO) Linking $(notdir $@)
$(Q)$(CXX) $(LDFLAGS) -o $@ $^ $(ULFLAGS) $(BOOST_PYTHON_LIBS) -l$(LIBPYTHON) $(READLINE_LIBS)

$(patsubst ./emc/sai/%,../include/%,$(wildcard ./emc/sai/*.h)): ../include/%.h: ./emc/sai/%.h
cp $^ $@
$(patsubst ./emc/sai/%,../include/%,$(wildcard ./emc/sai/*.hh)): ../include/%.hh: ./emc/sai/%.hh
cp $^ $@

8 changes: 5 additions & 3 deletions src/emc/sai/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <glob.h>
#include <wordexp.h>

#include <saicanon.hh>

InterpBase *pinterp;
#define interp_new (*pinterp)
const char *prompt = "READ => ";
Expand Down Expand Up @@ -334,7 +336,7 @@ int read_tool_file( /* ARGUMENTS */
tool_file_name = buffer;
}

return loadToolTable(tool_file_name, _tools, 0, 0);
return loadToolTable(tool_file_name, _sai._tools, 0, 0);
}

/************************************************************************/
Expand Down Expand Up @@ -552,7 +554,7 @@ int main (int argc, char ** argv)
block_delete = OFF;
print_stack = OFF;
tool_flag = 0;
strcpy(_parameter_file_name, default_name);
SET_PARAMETER_FILE_NAME(default_name);
_outfile = stdout; /* may be reset below */
go_flag = 0;

Expand All @@ -563,7 +565,7 @@ int main (int argc, char ** argv)
switch(c) {
case 'p': interp = optarg; break;
case 't': read_tool_file(optarg); tool_flag=1; break;
case 'v': strcpy(_parameter_file_name, optarg); break;
case 'v': SET_PARAMETER_FILE_NAME(optarg); break;
case 'b': block_delete = (block_delete == OFF) ? ON : OFF; break;
case 's': print_stack = (print_stack == OFF) ? ON : OFF; break;
case 'n': do_next = atoi(optarg); break;
Expand Down
Loading

0 comments on commit 8794b78

Please sign in to comment.