#include "mri.h"
#include "version.h"
#include "PublicDataRequest.h"
+#include "FileStream.h"
+#include "checksumm.h"
+#include "PublicData.h"
+#include "Gcode.h"
+
+#include "SimpleShell.h"
#include "modules/tools/temperaturecontrol/TemperatureControlPublicAccess.h"
#include "modules/robot/RobotPublicAccess.h"
+#include "NetworkPublicAccess.h"
+#include "platform_memory.h"
+
+#include "system_LPC17xx.h"
+#include "LPC17xx.h"
extern unsigned int g_maximumHeapAddress;
{CHECKSUM("dfu"), &SimpleShell::dfu_command},
{CHECKSUM("break"), &SimpleShell::break_command},
{CHECKSUM("help"), &SimpleShell::help_command},
+ {CHECKSUM("?"), &SimpleShell::help_command},
{CHECKSUM("version"), &SimpleShell::version_command},
{CHECKSUM("mem"), &SimpleShell::mem_command},
{CHECKSUM("get"), &SimpleShell::get_command},
{CHECKSUM("set_temp"), &SimpleShell::set_temp_command},
+ {CHECKSUM("net"), &SimpleShell::net_command},
+ {CHECKSUM("load"), &SimpleShell::load_command},
+ {CHECKSUM("save"), &SimpleShell::save_command},
// unknown command
{0, NULL}
};
// Adam Greens heap walk from http://mbed.org/forum/mbed/topic/2701/?page=4#comment-22556
-static void heapWalk(StreamOutput *stream, bool verbose)
+static uint32_t heapWalk(StreamOutput *stream, bool verbose)
{
uint32_t chunkNumber = 1;
// The __end__ linker symbol points to the beginning of the heap.
chunkNumber++;
}
stream->printf("Allocated: %lu, Free: %lu\r\n", usedSize, freeSize);
+ return freeSize;
}
void SimpleShell::on_module_loaded()
{
- this->current_path = "/";
this->register_for_event(ON_CONSOLE_LINE_RECEIVED);
- this->reset_delay_secs = 0;
+ this->register_for_event(ON_GCODE_RECEIVED);
+ this->register_for_event(ON_SECOND_TICK);
- this->register_for_event(ON_SECOND_TICK);
- this->register_for_event(ON_GCODE_RECEIVED);
+ this->reset_delay_secs = 0;
}
void SimpleShell::on_second_tick(void *)
gcode->stream->printf("Begin file list\r\n");
ls_command("/sd", gcode->stream);
gcode->stream->printf("End file list\r\n");
- }
- else if (gcode->m == 30) { // remove file
+
+ } else if (gcode->m == 30) { // remove file
gcode->mark_as_taken();
rm_command("/sd/" + args, gcode->stream);
+
+ }else if(gcode->m == 501) { // load config override
+ gcode->mark_as_taken();
+ 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
+ gcode->mark_as_taken();
+ if(args.empty()) {
+ save_command("/sd/config-override", gcode->stream);
+ }else{
+ save_command("/sd/config-override." + args, gcode->stream);
+ }
}
}
}
//new_message.stream->printf("Received %s\r\n", possible_command.c_str());
- // We don't compare to a string but to a checksum of that string, this saves some space in flash memory
unsigned short check_sum = get_checksum( possible_command.substr(0, possible_command.find_first_of(" \r\n")) ); // todo: put this method somewhere more convenient
// find command and execute it
parse_command(check_sum, get_arguments(possible_command), new_message.stream);
}
-// Convert a path indication ( absolute or relative ) into a path ( absolute )
-string SimpleShell::absolute_from_relative( string path )
-{
- if ( path[0] == '/' ) {
- return path;
- }
- if ( path[0] == '.' ) {
- return this->current_path;
- }
- return this->current_path + path;
-}
-
// Act upon an ls command
// Convert the first parameter into an absolute path, then list the files in that path
void SimpleShell::ls_command( string parameters, StreamOutput *stream )
{
- string folder = this->absolute_from_relative( parameters );
+ string folder = absolute_from_relative( parameters );
DIR *d;
struct dirent *p;
d = opendir(folder.c_str());
// Delete a file
void SimpleShell::rm_command( string parameters, StreamOutput *stream )
{
- const char *fn= this->absolute_from_relative(shift_parameter( parameters )).c_str();
+ const char *fn= absolute_from_relative(shift_parameter( parameters )).c_str();
int s = remove(fn);
if (s != 0) stream->printf("Could not delete %s \r\n", fn);
}
// Change current absolute path to provided path
void SimpleShell::cd_command( string parameters, StreamOutput *stream )
{
- string folder = this->absolute_from_relative( parameters );
- if ( folder[folder.length() - 1] != '/' ) {
- folder += "/";
- }
+ string folder = absolute_from_relative( parameters );
+
DIR *d;
d = opendir(folder.c_str());
if (d == NULL) {
stream->printf("Could not open directory %s \r\n", folder.c_str() );
} else {
- this->current_path = folder;
+ THEKERNEL->current_path = folder;
closedir(d);
}
}
// Responds with the present working directory
void SimpleShell::pwd_command( string parameters, StreamOutput *stream )
{
- stream->printf("%s\r\n", this->current_path.c_str());
+ stream->printf("%s\r\n", THEKERNEL->current_path.c_str());
}
// Output the contents of a file, first parameter is the filename, second is the limit ( in number of lines to output )
void SimpleShell::cat_command( string parameters, StreamOutput *stream )
{
-
// Get parameters ( filename and line limit )
- string filename = this->absolute_from_relative(shift_parameter( parameters ));
+ string filename = absolute_from_relative(shift_parameter( parameters ));
string limit_paramater = shift_parameter( parameters );
int limit = -1;
if ( limit_paramater != "" ) {
string buffer;
int c;
int newlines = 0;
-
+ int linecnt= 0;
// Print each line of the file
while ((c = fgetc (lp)) != EOF) {
buffer.append((char *)&c, 1);
- if ( char(c) == '\n' ) {
+ if ( char(c) == '\n' || ++linecnt > 80) {
newlines++;
stream->puts(buffer.c_str());
buffer.clear();
+ if(linecnt > 80) linecnt= 0;
}
if ( newlines == limit ) {
break;
}
+// loads the specified config-override file
+void SimpleShell::load_command( string parameters, StreamOutput *stream )
+{
+ // Get parameters ( filename )
+ string filename = absolute_from_relative(parameters);
+ if(filename == "/") {
+ filename = THEKERNEL->config_override_filename();
+ }
+
+ FILE *fp= fopen(filename.c_str(), "r");
+ if(fp != NULL) {
+ char buf[132];
+ stream->printf("Loading config override file: %s...\n", filename.c_str());
+ 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);
+ }
+ stream->printf("config override file executed\n");
+ fclose(fp);
+
+ }else{
+ stream->printf("File not found: %s\n", filename.c_str());
+ }
+}
+
+// saves the specified config-override file
+void SimpleShell::save_command( string parameters, StreamOutput *stream )
+{
+ // Get parameters ( filename )
+ string filename = absolute_from_relative(parameters);
+ if(filename == "/") {
+ filename = THEKERNEL->config_override_filename();
+ }
+
+ // replace stream with one that writes to config-override file
+ FileStream *gs = new FileStream(filename.c_str());
+ if(!gs->is_open()) {
+ stream->printf("Unable to open File %s for write\n", filename.c_str());
+ return;
+ }
+
+ // issue a M500 which will store values in the file stream
+ Gcode *gcode = new Gcode("M500", gs);
+ THEKERNEL->call_event(ON_GCODE_RECEIVED, gcode );
+ delete gs;
+ delete gcode;
+
+ stream->printf("Settings Stored to %s\r\n", filename.c_str());
+}
+
// show free memory
void SimpleShell::mem_command( string parameters, StreamOutput *stream)
{
unsigned long m = g_maximumHeapAddress - heap;
stream->printf("Unused Heap: %lu bytes\r\n", m);
- heapWalk(stream, verbose);
+ uint32_t f= heapWalk(stream, verbose);
+ stream->printf("Total Free RAM: %lu bytes\r\n", m + f);
+
+ stream->printf("Free AHB0: %lu, AHB1: %lu\r\n", AHB0.free(), AHB1.free());
+ if (verbose)
+ {
+ AHB0.debug(stream);
+ AHB1.debug(stream);
+ }
}
static uint32_t getDeviceType()
return result[1];
}
+// get network config
+void SimpleShell::net_command( string parameters, StreamOutput *stream)
+{
+ void *returned_data;
+ bool ok= THEKERNEL->public_data->get_value( network_checksum, get_ipconfig_checksum, &returned_data );
+ if(ok) {
+ char *str= (char *)returned_data;
+ stream->printf("%s\r\n", str);
+ free(str);
+
+ }else{
+ stream->printf("No network detected\n");
+ }
+}
+
// print out build version
void SimpleShell::version_command( string parameters, StreamOutput *stream)
{
if (what == get_temp_command_checksum) {
string type = shift_parameter( parameters );
- bool ok = this->kernel->public_data->get_value( temperature_control_checksum, get_checksum(type), current_temperature_checksum, &returned_data );
+ bool ok = THEKERNEL->public_data->get_value( temperature_control_checksum, get_checksum(type), current_temperature_checksum, &returned_data );
if (ok) {
struct pad_temperature temp = *static_cast<struct pad_temperature *>(returned_data);
}
} else if (what == get_pos_command_checksum) {
- bool ok = this->kernel->public_data->get_value( robot_checksum, current_position_checksum, &returned_data );
+ bool ok = THEKERNEL->public_data->get_value( robot_checksum, current_position_checksum, &returned_data );
if (ok) {
- double *pos = static_cast<double *>(returned_data);
+ float *pos = static_cast<float *>(returned_data);
stream->printf("Position X: %f, Y: %f, Z: %f\r\n", pos[0], pos[1], pos[2]);
} else {
{
string type = shift_parameter( parameters );
string temp = shift_parameter( parameters );
- double t = temp.empty() ? 0.0 : strtod(temp.c_str(), NULL);
- bool ok = this->kernel->public_data->set_value( temperature_control_checksum, get_checksum(type), &t );
+ float t = temp.empty() ? 0.0 : strtof(temp.c_str(), NULL);
+ bool ok = THEKERNEL->public_data->set_value( temperature_control_checksum, get_checksum(type), &t );
if (ok) {
stream->printf("%s temp set to: %3.1f\r\n", type.c_str(), t);
stream->printf("pwd\r\n");
stream->printf("cat file [limit]\r\n");
stream->printf("rm file\r\n");
- stream->printf("play file [-q]\r\n");
+ stream->printf("play file [-v]\r\n");
stream->printf("progress - shows progress of current play\r\n");
stream->printf("abort - abort currently playing file\r\n");
stream->printf("reset - reset smoothie\r\n");
stream->printf("get temp [bed|hotend]\r\n");
stream->printf("set_temp bed|hotend 185\r\n");
stream->printf("get pos\r\n");
+ stream->printf("net\r\n");
+ stream->printf("load [file] - loads a configuration override file from soecified name or config-override\r\n");
+ stream->printf("save [file] - saves a configuration override file as specified filename or as config-override\r\n");
}