Merge remote-tracking branch 'upstream/edge' into upstreamedge
[clinton/Smoothieware.git] / src / modules / utils / simpleshell / SimpleShell.cpp
CommitLineData
58baeec1
MM
1/*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
cd011f58
AW
6*/
7
8
0325af12 9#include "SimpleShell.h"
ba8da804 10#include "libs/Kernel.h"
0325af12
AW
11#include "libs/nuts_bolts.h"
12#include "libs/utils.h"
423df6df 13#include "libs/SerialMessage.h"
838b33b4 14#include "libs/StreamOutput.h"
3fceb8eb 15#include "modules/robot/Conveyor.h"
172d42d9 16#include "DirHandle.h"
0f0b1656 17#include "mri.h"
582559c6 18#include "version.h"
8293d443 19#include "PublicDataRequest.h"
4fed9ba1 20#include "AppendFileStream.h"
618c9b0f 21#include "FileStream.h"
61134a65
JM
22#include "checksumm.h"
23#include "PublicData.h"
24#include "Gcode.h"
3680d806 25//#include "StepTicker.h"
61134a65 26
47339e4a 27#include "modules/tools/temperaturecontrol/TemperatureControlPublicAccess.h"
5647f709 28#include "modules/robot/RobotPublicAccess.h"
d4ee6ee2 29#include "NetworkPublicAccess.h"
a200fc31 30#include "platform_memory.h"
ae91dea4 31#include "SwitchPublicAccess.h"
3704585b 32#include "SDFAT.h"
47339e4a 33
61134a65
JM
34#include "system_LPC17xx.h"
35#include "LPC17xx.h"
36
6187a020
JM
37extern unsigned int g_maximumHeapAddress;
38
ecc610a4
JM
39#include <malloc.h>
40#include <mri.h>
41#include <stdio.h>
42#include <stdint.h>
43
44extern "C" uint32_t __end__;
45extern "C" uint32_t __malloc_free_list;
46extern "C" uint32_t _sbrk(int size);
47
9e403697 48// command lookup table
7e81f138
JM
49const SimpleShell::ptentry_t SimpleShell::commands_table[] = {
50 {"ls", SimpleShell::ls_command},
51 {"cd", SimpleShell::cd_command},
52 {"pwd", SimpleShell::pwd_command},
53 {"cat", SimpleShell::cat_command},
54 {"rm", SimpleShell::rm_command},
6d877d9b
JM
55 {"mv", SimpleShell::mv_command},
56 {"upload", SimpleShell::upload_command},
7e81f138
JM
57 {"reset", SimpleShell::reset_command},
58 {"dfu", SimpleShell::dfu_command},
59 {"break", SimpleShell::break_command},
60 {"help", SimpleShell::help_command},
61 {"?", SimpleShell::help_command},
62 {"version", SimpleShell::version_command},
63 {"mem", SimpleShell::mem_command},
64 {"get", SimpleShell::get_command},
65 {"set_temp", SimpleShell::set_temp_command},
ae91dea4 66 {"switch", SimpleShell::switch_command},
7e81f138
JM
67 {"net", SimpleShell::net_command},
68 {"load", SimpleShell::load_command},
69 {"save", SimpleShell::save_command},
6d877d9b 70 {"remount", SimpleShell::remount_command},
9e403697
JM
71
72 // unknown command
7e81f138 73 {NULL, NULL}
9e403697 74};
ecc610a4 75
6d877d9b 76int SimpleShell::reset_delay_secs = 0;
7e81f138 77
ecc610a4 78// Adam Greens heap walk from http://mbed.org/forum/mbed/topic/2701/?page=4#comment-22556
0c683b26 79static uint32_t heapWalk(StreamOutput *stream, bool verbose)
ecc610a4
JM
80{
81 uint32_t chunkNumber = 1;
82 // The __end__ linker symbol points to the beginning of the heap.
83 uint32_t chunkCurr = (uint32_t)&__end__;
84 // __malloc_free_list is the head pointer to newlib-nano's link list of free chunks.
85 uint32_t freeCurr = __malloc_free_list;
86 // Calling _sbrk() with 0 reserves no more memory but it returns the current top of heap.
87 uint32_t heapEnd = _sbrk(0);
88 // accumulate totals
9e403697
JM
89 uint32_t freeSize = 0;
90 uint32_t usedSize = 0;
ecc610a4
JM
91
92 stream->printf("Used Heap Size: %lu\n", heapEnd - chunkCurr);
93
94 // Walk through the chunks until we hit the end of the heap.
9e403697 95 while (chunkCurr < heapEnd) {
ecc610a4
JM
96 // Assume the chunk is in use. Will update later.
97 int isChunkFree = 0;
98 // The first 32-bit word in a chunk is the size of the allocation. newlib-nano over allocates by 8 bytes.
99 // 4 bytes for this 32-bit chunk size and another 4 bytes to allow for 8 byte-alignment of returned pointer.
9e403697 100 uint32_t chunkSize = *(uint32_t *)chunkCurr;
ecc610a4
JM
101 // The start of the next chunk is right after the end of this one.
102 uint32_t chunkNext = chunkCurr + chunkSize;
103
104 // The free list is sorted by address.
105 // Check to see if we have found the next free chunk in the heap.
9e403697 106 if (chunkCurr == freeCurr) {
ecc610a4
JM
107 // Chunk is free so flag it as such.
108 isChunkFree = 1;
109 // The second 32-bit word in a free chunk is a pointer to the next free chunk (again sorted by address).
9e403697 110 freeCurr = *(uint32_t *)(freeCurr + 4);
ecc610a4
JM
111 }
112
113 // Skip past the 32-bit size field in the chunk header.
114 chunkCurr += 4;
115 // 8-byte align the data pointer.
116 chunkCurr = (chunkCurr + 7) & ~7;
117 // newlib-nano over allocates by 8 bytes, 4 bytes for the 32-bit chunk size and another 4 bytes to allow for 8
118 // byte-alignment of the returned pointer.
119 chunkSize -= 8;
9e403697 120 if (verbose)
ecc610a4
JM
121 stream->printf(" Chunk: %lu Address: 0x%08lX Size: %lu %s\n", chunkNumber, chunkCurr, chunkSize, isChunkFree ? "CHUNK FREE" : "");
122
9e403697 123 if (isChunkFree) freeSize += chunkSize;
ecc610a4
JM
124 else usedSize += chunkSize;
125
126 chunkCurr = chunkNext;
127 chunkNumber++;
128 }
129 stream->printf("Allocated: %lu, Free: %lu\r\n", usedSize, freeSize);
0c683b26 130 return freeSize;
ecc610a4
JM
131}
132
133
9e403697
JM
134void SimpleShell::on_module_loaded()
135{
0325af12 136 this->register_for_event(ON_CONSOLE_LINE_RECEIVED);
48afc62a 137 this->register_for_event(ON_GCODE_RECEIVED);
138 this->register_for_event(ON_SECOND_TICK);
c4e56997 139
7e81f138 140 reset_delay_secs = 0;
ead17727
JM
141}
142
9e403697
JM
143void SimpleShell::on_second_tick(void *)
144{
ead17727 145 // we are timing out for the reset
7e81f138
JM
146 if (reset_delay_secs > 0) {
147 if (--reset_delay_secs == 0) {
ead17727
JM
148 system_reset(false);
149 }
150 }
0325af12
AW
151}
152
9e403697
JM
153void SimpleShell::on_gcode_received(void *argument)
154{
155 Gcode *gcode = static_cast<Gcode *>(argument);
6d877d9b 156 string args = get_arguments(gcode->get_command());
c4e56997
JM
157
158 if (gcode->has_m) {
159 if (gcode->m == 20) { // list sd card
160 gcode->mark_as_taken();
161 gcode->stream->printf("Begin file list\r\n");
162 ls_command("/sd", gcode->stream);
163 gcode->stream->printf("End file list\r\n");
d4ee6ee2
JM
164
165 } else if (gcode->m == 30) { // remove file
3a238fdc
CG
166 gcode->mark_as_taken();
167 rm_command("/sd/" + args, gcode->stream);
618c9b0f 168
6d877d9b 169 } else if(gcode->m == 501) { // load config override
618c9b0f
JM
170 gcode->mark_as_taken();
171 if(args.empty()) {
172 load_command("/sd/config-override", gcode->stream);
6d877d9b 173 } else {
618c9b0f
JM
174 load_command("/sd/config-override." + args, gcode->stream);
175 }
176
6d877d9b 177 } else if(gcode->m == 504) { // save to specific config override file
618c9b0f
JM
178 gcode->mark_as_taken();
179 if(args.empty()) {
180 save_command("/sd/config-override", gcode->stream);
6d877d9b 181 } else {
618c9b0f
JM
182 save_command("/sd/config-override." + args, gcode->stream);
183 }
3a238fdc 184 }
c4e56997
JM
185 }
186}
187
7e81f138 188bool SimpleShell::parse_command(const char *cmd, string args, StreamOutput *stream)
9e403697 189{
7e81f138
JM
190 for (const ptentry_t *p = commands_table; p->command != NULL; ++p) {
191 if (strncasecmp(cmd, p->command, strlen(p->command)) == 0) {
192 p->func(args, stream);
9e403697
JM
193 return true;
194 }
195 }
196
197 return false;
198}
199
0325af12 200// When a new line is received, check if it is a command, and if it is, act upon it
9e403697
JM
201void SimpleShell::on_console_line_received( void *argument )
202{
203 SerialMessage new_message = *static_cast<SerialMessage *>(argument);
7f613782 204
7e81f138
JM
205 // ignore comments and blank lines and if this is a G code then also ignore it
206 char first_char = new_message.message[0];
207 if(strchr(";( \n\rGMTN", first_char) != NULL) return;
7f613782 208
b6c86164 209 string possible_command = new_message.message;
0325af12 210
3add9a23 211 //new_message.stream->printf("Received %s\r\n", possible_command.c_str());
7e81f138 212 string cmd = shift_parameter(possible_command);
6187a020 213
9e403697 214 // find command and execute it
7e81f138 215 parse_command(cmd.c_str(), possible_command, new_message.stream);
0325af12
AW
216}
217
0325af12
AW
218// Act upon an ls command
219// Convert the first parameter into an absolute path, then list the files in that path
9e403697
JM
220void SimpleShell::ls_command( string parameters, StreamOutput *stream )
221{
3579deea
JM
222 string path, opts;
223 while(!parameters.empty()) {
6d877d9b 224 string s = shift_parameter( parameters );
3579deea
JM
225 if(s.front() == '-') {
226 opts.append(s);
227 } else {
6d877d9b
JM
228 path = s;
229 if(!parameters.empty()) {
3579deea
JM
230 path.append(" ");
231 path.append(parameters);
232 }
233 break;
234 }
235 }
b557a801 236
6d877d9b 237 path = absolute_from_relative(path);
3579deea 238
9e403697
JM
239 DIR *d;
240 struct dirent *p;
3579deea 241 d = opendir(path.c_str());
9e403697
JM
242 if (d != NULL) {
243 while ((p = readdir(d)) != NULL) {
3579deea 244 stream->printf("%s", lc(string(p->d_name)).c_str());
6d877d9b 245 if(p->d_isdir) {
3579deea 246 stream->printf("/");
6d877d9b 247 } else if(opts.find("-s", 0, 2) != string::npos) {
3579deea
JM
248 stream->printf(" %d", p->d_fsize);
249 }
250 stream->printf("\r\n");
9e403697 251 }
ed7c5844 252 closedir(d);
0325af12 253 } else {
3579deea 254 stream->printf("Could not open directory %s\r\n", path.c_str());
0325af12
AW
255 }
256}
257
3704585b 258extern SDFAT mounter;
259
260void SimpleShell::remount_command( string parameters, StreamOutput *stream )
261{
262 mounter.remount();
48afc62a 263 stream->printf("remounted\r\n");
12fb447a 264}
3704585b 265
9e403697
JM
266// Delete a file
267void SimpleShell::rm_command( string parameters, StreamOutput *stream )
268{
6d877d9b 269 const char *fn = absolute_from_relative(shift_parameter( parameters )).c_str();
9e403697
JM
270 int s = remove(fn);
271 if (s != 0) stream->printf("Could not delete %s \r\n", fn);
272}
273
6d877d9b
JM
274// Rename a file
275void SimpleShell::mv_command( string parameters, StreamOutput *stream )
276{
277 string from = absolute_from_relative(shift_parameter( parameters ));
278 string to = shift_parameter(parameters);
279 int s = rename(from.c_str(), to.c_str());
280 if (s != 0) stream->printf("Could not rename %s to %s\r\n", from.c_str(), to.c_str());
281 else stream->printf("renamed %s to %s\r\n", from.c_str(), to.c_str());
282}
283
0325af12 284// Change current absolute path to provided path
9e403697
JM
285void SimpleShell::cd_command( string parameters, StreamOutput *stream )
286{
75f4581c 287 string folder = absolute_from_relative( parameters );
6bcd4886 288
0325af12 289 DIR *d;
0325af12 290 d = opendir(folder.c_str());
9e403697 291 if (d == NULL) {
58baeec1 292 stream->printf("Could not open directory %s \r\n", folder.c_str() );
9e403697 293 } else {
75f4581c 294 THEKERNEL->current_path = folder;
ed7c5844 295 closedir(d);
0325af12
AW
296 }
297}
298
b7250484 299// Responds with the present working directory
9e403697
JM
300void SimpleShell::pwd_command( string parameters, StreamOutput *stream )
301{
75f4581c 302 stream->printf("%s\r\n", THEKERNEL->current_path.c_str());
b7250484
L
303}
304
0325af12 305// Output the contents of a file, first parameter is the filename, second is the limit ( in number of lines to output )
9e403697
JM
306void SimpleShell::cat_command( string parameters, StreamOutput *stream )
307{
58baeec1 308 // Get parameters ( filename and line limit )
75f4581c 309 string filename = absolute_from_relative(shift_parameter( parameters ));
0325af12
AW
310 string limit_paramater = shift_parameter( parameters );
311 int limit = -1;
9e403697
JM
312 if ( limit_paramater != "" ) {
313 char *e = NULL;
f7e6f459
MM
314 limit = strtol(limit_paramater.c_str(), &e, 10);
315 if (e <= limit_paramater.c_str())
316 limit = -1;
317 }
58baeec1
MM
318
319 // Open file
0325af12 320 FILE *lp = fopen(filename.c_str(), "r");
9e403697 321 if (lp == NULL) {
58baeec1
MM
322 stream->printf("File not found: %s\r\n", filename.c_str());
323 return;
9ed670c5 324 }
0325af12
AW
325 string buffer;
326 int c;
58baeec1 327 int newlines = 0;
6d877d9b 328 int linecnt = 0;
0325af12 329 // Print each line of the file
9e403697 330 while ((c = fgetc (lp)) != EOF) {
58baeec1 331 buffer.append((char *)&c, 1);
dfb15d68 332 if ( char(c) == '\n' || ++linecnt > 80) {
58baeec1 333 newlines++;
d728799b 334 stream->puts(buffer.c_str());
58baeec1 335 buffer.clear();
6d877d9b 336 if(linecnt > 80) linecnt = 0;
68b7afb4 337 }
9e403697
JM
338 if ( newlines == limit ) {
339 break;
340 }
58baeec1 341 };
0325af12 342 fclose(lp);
6d877d9b
JM
343}
344
345void SimpleShell::upload_command( string parameters, StreamOutput *stream )
346{
347 // this needs to be a hack. it needs to read direct from serial and not allow on_main_loop run until done
348 // NOTE this will block all operation until the upload is complete, so do not do while printing
349 if(!THEKERNEL->conveyor->is_queue_empty()) {
350 stream->printf("upload not allowed while printing or busy\n");
351 return;
352 }
353
354 // open file to upload to
355 string upload_filename = absolute_from_relative( parameters );
356 FILE *fd = fopen(upload_filename.c_str(), "w");
357 if(fd != NULL) {
358 stream->printf("uploading to file: %s, send control-D or control-Z to finish\r\n", upload_filename.c_str());
359 } else {
360 stream->printf("failed to open file: %s.\r\n", upload_filename.c_str());
361 return;
362 }
0325af12 363
6d877d9b
JM
364 int cnt = 0;
365 bool uploading = true;
366 while(uploading) {
367 if(!stream->ready()) {
368 // we need to kick things or they die
369 THEKERNEL->call_event(ON_IDLE);
370 continue;
371 }
372
373 char c = stream->_getc();
374 if( c == 4 || c == 26) { // ctrl-D or ctrl-Z
375 uploading = false;
376 // close file
377 fclose(fd);
378 stream->printf("uploaded %d bytes\n", cnt);
379 return;
380
381 } else {
382 // write character to file
383 cnt++;
384 if(fputc(c, fd) != c) {
385 // error writing to file
386 stream->printf("error writing to file. ignoring all characters until EOF\r\n");
387 fclose(fd);
388 fd = NULL;
389 uploading= false;
390
391 } else {
392 if ((cnt%400) == 0) {
393 // HACK ALERT to get around fwrite corruption close and re open for append
394 fclose(fd);
395 fd = fopen(upload_filename.c_str(), "a");
396 }
397 }
398 }
399 }
400 // we got an error so ignore everything until EOF
401 char c;
402 do {
403 if(stream->ready()) {
404 c= stream->_getc();
405 }else{
406 THEKERNEL->call_event(ON_IDLE);
407 c= 0;
408 }
409 } while(c != 4 && c != 26);
0325af12
AW
410}
411
618c9b0f
JM
412// loads the specified config-override file
413void SimpleShell::load_command( string parameters, StreamOutput *stream )
414{
415 // Get parameters ( filename )
75f4581c 416 string filename = absolute_from_relative(parameters);
618c9b0f
JM
417 if(filename == "/") {
418 filename = THEKERNEL->config_override_filename();
419 }
420
6d877d9b 421 FILE *fp = fopen(filename.c_str(), "r");
618c9b0f
JM
422 if(fp != NULL) {
423 char buf[132];
424 stream->printf("Loading config override file: %s...\n", filename.c_str());
425 while(fgets(buf, sizeof buf, fp) != NULL) {
426 stream->printf(" %s", buf);
427 if(buf[0] == ';') continue; // skip the comments
6d877d9b 428 struct SerialMessage message = {&(StreamOutput::NullStream), buf};
618c9b0f
JM
429 THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message);
430 }
431 stream->printf("config override file executed\n");
432 fclose(fp);
433
6d877d9b 434 } else {
618c9b0f
JM
435 stream->printf("File not found: %s\n", filename.c_str());
436 }
437}
438
439// saves the specified config-override file
440void SimpleShell::save_command( string parameters, StreamOutput *stream )
441{
442 // Get parameters ( filename )
75f4581c 443 string filename = absolute_from_relative(parameters);
618c9b0f
JM
444 if(filename == "/") {
445 filename = THEKERNEL->config_override_filename();
446 }
447
797b4403 448 remove(filename.c_str());
618c9b0f 449 // replace stream with one that writes to config-override file
4fed9ba1
JM
450 AppendFileStream *gs = new AppendFileStream(filename.c_str());
451 // if(!gs->is_open()) {
452 // stream->printf("Unable to open File %s for write\n", filename.c_str());
453 // return;
454 // }
618c9b0f
JM
455
456 // issue a M500 which will store values in the file stream
457 Gcode *gcode = new Gcode("M500", gs);
458 THEKERNEL->call_event(ON_GCODE_RECEIVED, gcode );
459 delete gs;
460 delete gcode;
461
462 stream->printf("Settings Stored to %s\r\n", filename.c_str());
463}
464
6187a020 465// show free memory
9e403697
JM
466void SimpleShell::mem_command( string parameters, StreamOutput *stream)
467{
468 bool verbose = shift_parameter( parameters ).find_first_of("Vv") != string::npos ;
469 unsigned long heap = (unsigned long)_sbrk(0);
470 unsigned long m = g_maximumHeapAddress - heap;
ecc610a4
JM
471 stream->printf("Unused Heap: %lu bytes\r\n", m);
472
6d877d9b 473 uint32_t f = heapWalk(stream, verbose);
0c683b26 474 stream->printf("Total Free RAM: %lu bytes\r\n", m + f);
a200fc31 475
0c683b26 476 stream->printf("Free AHB0: %lu, AHB1: %lu\r\n", AHB0.free(), AHB1.free());
6d877d9b 477 if (verbose) {
1803076a
MM
478 AHB0.debug(stream);
479 AHB1.debug(stream);
480 }
6187a020
JM
481}
482
9e403697
JM
483static uint32_t getDeviceType()
484{
485#define IAP_LOCATION 0x1FFF1FF1
01f35bcc
JM
486 uint32_t command[1];
487 uint32_t result[5];
9e403697 488 typedef void (*IAP)(uint32_t *, uint32_t *);
01f35bcc
JM
489 IAP iap = (IAP) IAP_LOCATION;
490
491 __disable_irq();
492
493 command[0] = 54;
494 iap(command, result);
495
496 __enable_irq();
497
498 return result[1];
499}
500
d4ee6ee2
JM
501// get network config
502void SimpleShell::net_command( string parameters, StreamOutput *stream)
503{
504 void *returned_data;
6d877d9b 505 bool ok = PublicData::get_value( network_checksum, get_ipconfig_checksum, &returned_data );
d4ee6ee2 506 if(ok) {
6d877d9b 507 char *str = (char *)returned_data;
d4ee6ee2
JM
508 stream->printf("%s\r\n", str);
509 free(str);
510
6d877d9b 511 } else {
d4ee6ee2
JM
512 stream->printf("No network detected\n");
513 }
514}
515
582559c6 516// print out build version
9e403697
JM
517void SimpleShell::version_command( string parameters, StreamOutput *stream)
518{
582559c6 519 Version vers;
9e403697
JM
520 uint32_t dev = getDeviceType();
521 const char *mcu = (dev & 0x00100000) ? "LPC1769" : "LPC1768";
01f35bcc 522 stream->printf("Build version: %s, Build date: %s, MCU: %s, System Clock: %ldMHz\r\n", vers.get_build(), vers.get_build_date(), mcu, SystemCoreClock / 1000000);
582559c6
JM
523}
524
77983aa1 525// Reset the system
9e403697
JM
526void SimpleShell::reset_command( string parameters, StreamOutput *stream)
527{
ead17727 528 stream->printf("Smoothie out. Peace. Rebooting in 5 seconds...\r\n");
7e81f138 529 reset_delay_secs = 5; // reboot in 5 seconds
2742fca9
JM
530}
531
532// go into dfu boot mode
9e403697
JM
533void SimpleShell::dfu_command( string parameters, StreamOutput *stream)
534{
ed7c5844
JM
535 stream->printf("Entering boot mode...\r\n");
536 system_reset(true);
77983aa1
L
537}
538
0f0b1656 539// Break out into the MRI debugging system
9e403697
JM
540void SimpleShell::break_command( string parameters, StreamOutput *stream)
541{
0f0b1656
L
542 stream->printf("Entering MRI debug mode...\r\n");
543 __debugbreak();
544}
545
8293d443 546// used to test out the get public data events
9e403697
JM
547void SimpleShell::get_command( string parameters, StreamOutput *stream)
548{
7e81f138 549 string what = shift_parameter( parameters );
b55cfff1 550 void *returned_data;
c4e56997 551
7e81f138 552 if (what == "temp") {
9e403697 553 string type = shift_parameter( parameters );
75e6428d 554 bool ok = PublicData::get_value( temperature_control_checksum, get_checksum(type), current_temperature_checksum, &returned_data );
b55cfff1 555
9e403697
JM
556 if (ok) {
557 struct pad_temperature temp = *static_cast<struct pad_temperature *>(returned_data);
b55cfff1 558 stream->printf("%s temp: %f/%f @%d\r\n", type.c_str(), temp.current_temperature, temp.target_temperature, temp.pwm);
9e403697 559 } else {
b55cfff1
JM
560 stream->printf("%s is not a known temperature device\r\n", type.c_str());
561 }
c4e56997 562
7e81f138 563 } else if (what == "pos") {
75e6428d 564 bool ok = PublicData::get_value( robot_checksum, current_position_checksum, &returned_data );
b55cfff1 565
9e403697 566 if (ok) {
1ad23cd3 567 float *pos = static_cast<float *>(returned_data);
b55cfff1 568 stream->printf("Position X: %f, Y: %f, Z: %f\r\n", pos[0], pos[1], pos[2]);
c4e56997 569
9e403697 570 } else {
b55cfff1
JM
571 stream->printf("get pos command failed\r\n");
572 }
573 }
8293d443
JM
574}
575
77047e76 576// used to test out the get public data events
9e403697
JM
577void SimpleShell::set_temp_command( string parameters, StreamOutput *stream)
578{
579 string type = shift_parameter( parameters );
580 string temp = shift_parameter( parameters );
04211969 581 float t = temp.empty() ? 0.0 : strtof(temp.c_str(), NULL);
75e6428d 582 bool ok = PublicData::set_value( temperature_control_checksum, get_checksum(type), &t );
991d98cc 583
9e403697 584 if (ok) {
991d98cc 585 stream->printf("%s temp set to: %3.1f\r\n", type.c_str(), t);
9e403697 586 } else {
991d98cc
JM
587 stream->printf("%s is not a known temperature device\r\n", type.c_str());
588 }
77047e76
JM
589}
590
ae91dea4
JM
591// used to test out the get public data events for switch
592void SimpleShell::switch_command( string parameters, StreamOutput *stream)
593{
594 string type = shift_parameter( parameters );
595 string value = shift_parameter( parameters );
6d877d9b 596 bool ok = false;
ae91dea4 597 if(value == "on" || value == "off") {
6d877d9b 598 bool b = value == "on";
ae91dea4 599 ok = PublicData::set_value( switch_checksum, get_checksum(type), state_checksum, &b );
6d877d9b 600 } else {
ae91dea4
JM
601 float v = strtof(value.c_str(), NULL);
602 ok = PublicData::set_value( switch_checksum, get_checksum(type), value_checksum, &v );
603 }
604 if (ok) {
605 stream->printf("switch %s set to: %s\r\n", type.c_str(), value.c_str());
606 } else {
607 stream->printf("%s is not a known switch device\r\n", type.c_str());
608 }
609}
610
9e403697
JM
611void SimpleShell::help_command( string parameters, StreamOutput *stream )
612{
ed7c5844 613 stream->printf("Commands:\r\n");
582559c6 614 stream->printf("version\r\n");
ecc610a4 615 stream->printf("mem [-v]\r\n");
3579deea 616 stream->printf("ls [-s] [folder]\r\n");
ed7c5844 617 stream->printf("cd folder\r\n");
c4e56997 618 stream->printf("pwd\r\n");
ed7c5844 619 stream->printf("cat file [limit]\r\n");
9e403697 620 stream->printf("rm file\r\n");
6d877d9b 621 stream->printf("mv file newfile\r\n");
12fb447a 622 stream->printf("remount\r\n");
4eb0e279 623 stream->printf("play file [-v]\r\n");
ed7c5844
JM
624 stream->printf("progress - shows progress of current play\r\n");
625 stream->printf("abort - abort currently playing file\r\n");
c4e56997
JM
626 stream->printf("reset - reset smoothie\r\n");
627 stream->printf("dfu - enter dfu boot loader\r\n");
628 stream->printf("break - break into debugger\r\n");
ed7c5844
JM
629 stream->printf("config-get [<configuration_source>] <configuration_setting>\r\n");
630 stream->printf("config-set [<configuration_source>] <configuration_setting> <value>\r\n");
5647f709 631 stream->printf("get temp [bed|hotend]\r\n");
991d98cc 632 stream->printf("set_temp bed|hotend 185\r\n");
b55cfff1 633 stream->printf("get pos\r\n");
d4ee6ee2 634 stream->printf("net\r\n");
618c9b0f
JM
635 stream->printf("load [file] - loads a configuration override file from soecified name or config-override\r\n");
636 stream->printf("save [file] - saves a configuration override file as specified filename or as config-override\r\n");
235a7435
JM
637}
638