Skip to content

Commit

Permalink
attempt to make M501 use less stack.
Browse files Browse the repository at this point in the history
  refactor to where and when it is processed, and make it use on_gcode event
  • Loading branch information
wolfmanjm committed Apr 12, 2016
1 parent 693ab47 commit c0b50fa
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
3 changes: 1 addition & 2 deletions src/libs/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ string shift_parameter( string &parameters )
}

// Separate command from arguments
string get_arguments( string possible_command )
string get_arguments( const string& possible_command )
{
size_t beginning = possible_command.find_first_of(" ");
if( beginning == string::npos ) {
Expand Down Expand Up @@ -170,7 +170,6 @@ void system_reset( bool dfu )
}

// Convert a path indication ( absolute or relative ) into a path ( absolute )
// TODO: Combine with plan9 absolute_path, current_path as argument?
string absolute_from_relative( string path )
{
string cwd = THEKERNEL->current_path;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void get_checksums(uint16_t check_sums[], const string& key);

string shift_parameter( string &parameters );

string get_arguments( string possible_command );
string get_arguments( const string& possible_command );

bool file_exists( const string file_name );

Expand Down
14 changes: 14 additions & 0 deletions src/modules/communication/GcodeDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,19 @@ void GcodeDispatch::on_console_line_received(void *line)
new_message.stream->printf("Settings Stored to %s\r\nok\r\n", THEKERNEL->config_override_filename());
continue;

case 501: // load config override
case 504: // save to specific config override file
{
string arg= get_arguments(single_command + possible_command); // rest of line is filename
if(arg.empty()) arg= "/sd/config-override";
else arg= "/sd/config-override." + arg;
new_message.stream->printf("args: <%s>\n", arg.c_str());
SimpleShell::parse_command((gcode->m == 501) ? "load_command" : "save_command", arg, new_message.stream);
}
delete gcode;
new_message.stream->printf("ok\r\n");
return;

case 502: // M502 deletes config-override so everything defaults to what is in config
remove(THEKERNEL->config_override_filename());
delete gcode;
Expand All @@ -319,6 +332,7 @@ void GcodeDispatch::on_console_line_received(void *line)
gcode->add_nl= true;
break; // fall through to process by modules
}

}
}

Expand Down
15 changes: 8 additions & 7 deletions src/modules/tools/zprobe/DeltaGridStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,46 +173,46 @@ bool DeltaGridStrategy::load_grid(StreamOutput *stream)
{
FILE *fp = fopen(GRIDFILE, "r");
if(fp == NULL) {
if(stream != nullptr) stream->printf("error:Failed to open grid %s\n", GRIDFILE);
stream->printf("error:Failed to open grid %s\n", GRIDFILE);
return false;
}

uint8_t size;
float radius;

if(fread(&size, sizeof(uint8_t), 1, fp) != 1) {
if(stream != nullptr) stream->printf("error:Failed to read grid size\n");
stream->printf("error:Failed to read grid size\n");
fclose(fp);
return false;
}

if(size != grid_size) {
if(stream != nullptr) stream->printf("error:grid size is different read %d - config %d\n", size, grid_size);
stream->printf("error:grid size is different read %d - config %d\n", size, grid_size);
fclose(fp);
return false;
}

if(fread(&radius, sizeof(float), 1, fp) != 1) {
if(stream != nullptr) stream->printf("error:Failed to read grid radius\n");
stream->printf("error:Failed to read grid radius\n");
fclose(fp);
return false;
}

if(radius != grid_radius) {
if(stream != nullptr) stream->printf("warning:grid radius is different read %f - config %f, overriding config\n", radius, grid_radius);
stream->printf("warning:grid radius is different read %f - config %f, overriding config\n", radius, grid_radius);
grid_radius= radius;
}

for (int y = 0; y < grid_size; y++) {
for (int x = 0; x < grid_size; x++) {
if(fread(&grid[x + (grid_size*y)], sizeof(float), 1, fp) != 1) {
if(stream != nullptr) stream->printf("error:Failed to read grid\n");
stream->printf("error:Failed to read grid\n");
fclose(fp);
return false;
}
}
}
if(stream != nullptr) stream->printf("grid loaded from %s with radius %f and size %d\n", GRIDFILE, grid_radius, grid_size);
stream->printf("grid loaded, radius: %f, size: %d\n", grid_radius, grid_size);
fclose(fp);
return true;
}
Expand Down Expand Up @@ -335,6 +335,7 @@ bool DeltaGridStrategy::handleGcode(Gcode *gcode)
} else {
if(load_grid(gcode->stream)) setAdjustFunction(true);
}
return true;

} else if(gcode->m == 565) { // M565: Set Z probe offsets
float x = 0, y = 0, z = 0;
Expand Down
21 changes: 5 additions & 16 deletions src/modules/utils/simpleshell/SimpleShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,6 @@ void SimpleShell::on_gcode_received(void *argument)
} else if (gcode->m == 30) { // remove file
if(!args.empty() && !THEKERNEL->is_grbl_mode())
rm_command("/sd/" + args, gcode->stream);

} else if(gcode->m == 501) { // load config override
if(args.empty()) {
load_command("/sd/config-override", gcode->stream);
} else {
load_command("/sd/config-override." + args, gcode->stream);
}

} else if(gcode->m == 504) { // save to specific config override file
if(args.empty()) {
save_command("/sd/config-override", gcode->stream);
} else {
save_command("/sd/config-override." + args, gcode->stream);
}
}
}
}
Expand Down Expand Up @@ -517,8 +503,11 @@ void SimpleShell::load_command( string parameters, StreamOutput *stream )
while(fgets(buf, sizeof buf, fp) != NULL) {
stream->printf(" %s", buf);
if(buf[0] == ';') continue; // skip the comments
struct SerialMessage message = {&(StreamOutput::NullStream), buf};
THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message);
// NOTE only Gcodes and Mcodes can be in the config-override
Gcode *gcode = new Gcode(buf, &StreamOutput::NullStream);
THEKERNEL->call_event(ON_GCODE_RECEIVED, gcode);
delete gcode;
THEKERNEL->call_event(ON_IDLE);
}
stream->printf("config override file executed\n");
fclose(fp);
Expand Down

0 comments on commit c0b50fa

Please sign in to comment.