smoothie port to mbed online compiler (smoothieware.org)
For documentation, license, ..., please check http://smoothieware.org/
This version has been tested with a 3 axis machine
modules/utils/configurator/Configurator.cpp@0:31e91bb0ef3c, 2012-07-31 (annotated)
- Committer:
- scachat
- Date:
- Tue Jul 31 21:11:18 2012 +0000
- Revision:
- 0:31e91bb0ef3c
smoothie port to mbed online compiler
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
scachat | 0:31e91bb0ef3c | 1 | /* |
scachat | 0:31e91bb0ef3c | 2 | This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl). |
scachat | 0:31e91bb0ef3c | 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. |
scachat | 0:31e91bb0ef3c | 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. |
scachat | 0:31e91bb0ef3c | 5 | You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. |
scachat | 0:31e91bb0ef3c | 6 | */ |
scachat | 0:31e91bb0ef3c | 7 | |
scachat | 0:31e91bb0ef3c | 8 | |
scachat | 0:31e91bb0ef3c | 9 | #include "libs/Kernel.h" |
scachat | 0:31e91bb0ef3c | 10 | #include "Configurator.h" |
scachat | 0:31e91bb0ef3c | 11 | #include "libs/nuts_bolts.h" |
scachat | 0:31e91bb0ef3c | 12 | #include "libs/utils.h" |
scachat | 0:31e91bb0ef3c | 13 | #include "libs/SerialMessage.h" |
scachat | 0:31e91bb0ef3c | 14 | #include "libs/StreamOutput.h" |
scachat | 0:31e91bb0ef3c | 15 | |
scachat | 0:31e91bb0ef3c | 16 | |
scachat | 0:31e91bb0ef3c | 17 | void Configurator::on_module_loaded(){ |
scachat | 0:31e91bb0ef3c | 18 | this->register_for_event(ON_CONSOLE_LINE_RECEIVED); |
scachat | 0:31e91bb0ef3c | 19 | // this->register_for_event(ON_GCODE_EXECUTE); |
scachat | 0:31e91bb0ef3c | 20 | // this->register_for_event(ON_MAIN_LOOP); |
scachat | 0:31e91bb0ef3c | 21 | } |
scachat | 0:31e91bb0ef3c | 22 | |
scachat | 0:31e91bb0ef3c | 23 | // When a new line is received, check if it is a command, and if it is, act upon it |
scachat | 0:31e91bb0ef3c | 24 | void Configurator::on_console_line_received( void* argument ){ |
scachat | 0:31e91bb0ef3c | 25 | SerialMessage new_message = *static_cast<SerialMessage*>(argument); |
scachat | 0:31e91bb0ef3c | 26 | string possible_command = new_message.message; |
scachat | 0:31e91bb0ef3c | 27 | |
scachat | 0:31e91bb0ef3c | 28 | // We don't compare to a string but to a checksum of that string, this saves some space in flash memory |
scachat | 0:31e91bb0ef3c | 29 | uint16_t check_sum = get_checksum( possible_command.substr(0,possible_command.find_first_of(" \r\n")) ); // todo: put this method somewhere more convenient |
scachat | 0:31e91bb0ef3c | 30 | |
scachat | 0:31e91bb0ef3c | 31 | // Act depending on command |
scachat | 0:31e91bb0ef3c | 32 | switch( check_sum ){ |
scachat | 0:31e91bb0ef3c | 33 | case config_get_command_checksum: this->config_get_command( get_arguments(possible_command), new_message.stream ); break; |
scachat | 0:31e91bb0ef3c | 34 | case config_set_command_checksum: this->config_set_command( get_arguments(possible_command), new_message.stream ); break; |
scachat | 0:31e91bb0ef3c | 35 | case config_load_command_checksum: this->config_load_command( get_arguments(possible_command), new_message.stream ); break; |
scachat | 0:31e91bb0ef3c | 36 | } |
scachat | 0:31e91bb0ef3c | 37 | } |
scachat | 0:31e91bb0ef3c | 38 | |
scachat | 0:31e91bb0ef3c | 39 | // Process and respond to eeprom gcodes (M50x) |
scachat | 0:31e91bb0ef3c | 40 | void Configurator::on_gcode_execute(void* argument){ |
scachat | 0:31e91bb0ef3c | 41 | Gcode* gcode = static_cast<Gcode*>(argument); |
scachat | 0:31e91bb0ef3c | 42 | if( gcode->has_letter('G') ){ |
scachat | 0:31e91bb0ef3c | 43 | int code = gcode->get_value('G'); |
scachat | 0:31e91bb0ef3c | 44 | switch( code ){ |
scachat | 0:31e91bb0ef3c | 45 | } |
scachat | 0:31e91bb0ef3c | 46 | } |
scachat | 0:31e91bb0ef3c | 47 | else if( gcode->has_letter('M') ){ |
scachat | 0:31e91bb0ef3c | 48 | int code = gcode->get_value('M'); |
scachat | 0:31e91bb0ef3c | 49 | switch( code ){ |
scachat | 0:31e91bb0ef3c | 50 | } |
scachat | 0:31e91bb0ef3c | 51 | } |
scachat | 0:31e91bb0ef3c | 52 | } |
scachat | 0:31e91bb0ef3c | 53 | |
scachat | 0:31e91bb0ef3c | 54 | void Configurator::on_main_loop(void* argument){} |
scachat | 0:31e91bb0ef3c | 55 | |
scachat | 0:31e91bb0ef3c | 56 | // Output a ConfigValue from the specified ConfigSource to the stream |
scachat | 0:31e91bb0ef3c | 57 | void Configurator::config_get_command( string parameters, StreamOutput* stream ){ |
scachat | 0:31e91bb0ef3c | 58 | string source = shift_parameter(parameters); |
scachat | 0:31e91bb0ef3c | 59 | string setting = shift_parameter(parameters); |
scachat | 0:31e91bb0ef3c | 60 | if (setting == "") { // output live setting |
scachat | 0:31e91bb0ef3c | 61 | setting = source; |
scachat | 0:31e91bb0ef3c | 62 | source = ""; |
scachat | 0:31e91bb0ef3c | 63 | vector<uint16_t> setting_checksums = get_checksums( setting ); |
scachat | 0:31e91bb0ef3c | 64 | ConfigValue* cv = this->kernel->config->value(setting_checksums); |
scachat | 0:31e91bb0ef3c | 65 | string value = ""; |
scachat | 0:31e91bb0ef3c | 66 | if(cv->found){ value = cv->as_string(); } |
scachat | 0:31e91bb0ef3c | 67 | stream->printf( "live: %s is set to %s\r\n", setting.c_str(), value.c_str() ); |
scachat | 0:31e91bb0ef3c | 68 | } else { // output setting from specified source |
scachat | 0:31e91bb0ef3c | 69 | uint16_t source_checksum = get_checksum( source ); |
scachat | 0:31e91bb0ef3c | 70 | vector<uint16_t> setting_checksums = get_checksums( setting ); |
scachat | 0:31e91bb0ef3c | 71 | for(int i=0; i < this->kernel->config->config_sources.size(); i++){ |
scachat | 0:31e91bb0ef3c | 72 | if( this->kernel->config->config_sources[i]->is_named(source_checksum) ){ |
scachat | 0:31e91bb0ef3c | 73 | string value = this->kernel->config->config_sources[i]->read(setting_checksums); |
scachat | 0:31e91bb0ef3c | 74 | stream->printf( "%s: %s is set to %s\r\n", source.c_str(), setting.c_str(), value.c_str() ); |
scachat | 0:31e91bb0ef3c | 75 | break; |
scachat | 0:31e91bb0ef3c | 76 | } |
scachat | 0:31e91bb0ef3c | 77 | } |
scachat | 0:31e91bb0ef3c | 78 | } |
scachat | 0:31e91bb0ef3c | 79 | } |
scachat | 0:31e91bb0ef3c | 80 | |
scachat | 0:31e91bb0ef3c | 81 | // Write the specified setting to the specified ConfigSource |
scachat | 0:31e91bb0ef3c | 82 | void Configurator::config_set_command( string parameters, StreamOutput* stream ){ |
scachat | 0:31e91bb0ef3c | 83 | string source = shift_parameter(parameters); |
scachat | 0:31e91bb0ef3c | 84 | string setting = shift_parameter(parameters); |
scachat | 0:31e91bb0ef3c | 85 | string value = shift_parameter(parameters); |
scachat | 0:31e91bb0ef3c | 86 | if (value == "") { |
scachat | 0:31e91bb0ef3c | 87 | value = setting; |
scachat | 0:31e91bb0ef3c | 88 | setting = source; |
scachat | 0:31e91bb0ef3c | 89 | source = ""; |
scachat | 0:31e91bb0ef3c | 90 | this->kernel->config->set_string(setting, value); |
scachat | 0:31e91bb0ef3c | 91 | stream->printf( "live: %s has been set to %s\r\n", setting.c_str(), value.c_str() ); |
scachat | 0:31e91bb0ef3c | 92 | } else { |
scachat | 0:31e91bb0ef3c | 93 | uint16_t source_checksum = get_checksum(source); |
scachat | 0:31e91bb0ef3c | 94 | for(int i=0; i < this->kernel->config->config_sources.size(); i++){ |
scachat | 0:31e91bb0ef3c | 95 | if( this->kernel->config->config_sources[i]->is_named(source_checksum) ){ |
scachat | 0:31e91bb0ef3c | 96 | this->kernel->config->config_sources[i]->write(setting, value); |
scachat | 0:31e91bb0ef3c | 97 | stream->printf( "%s: %s has been set to %s\r\n", source.c_str(), setting.c_str(), value.c_str() ); |
scachat | 0:31e91bb0ef3c | 98 | break; |
scachat | 0:31e91bb0ef3c | 99 | } |
scachat | 0:31e91bb0ef3c | 100 | } |
scachat | 0:31e91bb0ef3c | 101 | } |
scachat | 0:31e91bb0ef3c | 102 | } |
scachat | 0:31e91bb0ef3c | 103 | |
scachat | 0:31e91bb0ef3c | 104 | // Reload config values from the specified ConfigSource |
scachat | 0:31e91bb0ef3c | 105 | void Configurator::config_load_command( string parameters, StreamOutput* stream ){ |
scachat | 0:31e91bb0ef3c | 106 | string source = shift_parameter(parameters); |
scachat | 0:31e91bb0ef3c | 107 | if(source == ""){ |
scachat | 0:31e91bb0ef3c | 108 | this->kernel->config->config_cache_load(); |
scachat | 0:31e91bb0ef3c | 109 | this->kernel->call_event(ON_CONFIG_RELOAD); |
scachat | 0:31e91bb0ef3c | 110 | stream->printf( "Reloaded settings\r\n" ); |
scachat | 0:31e91bb0ef3c | 111 | } else if(file_exists(source)){ |
scachat | 0:31e91bb0ef3c | 112 | FileConfigSource fcs(source); |
scachat | 0:31e91bb0ef3c | 113 | fcs.transfer_values_to_cache(&this->kernel->config->config_cache); |
scachat | 0:31e91bb0ef3c | 114 | this->kernel->call_event(ON_CONFIG_RELOAD); |
scachat | 0:31e91bb0ef3c | 115 | stream->printf( "Loaded settings from %s\r\n", source.c_str() ); |
scachat | 0:31e91bb0ef3c | 116 | } else { |
scachat | 0:31e91bb0ef3c | 117 | uint16_t source_checksum = get_checksum(source); |
scachat | 0:31e91bb0ef3c | 118 | for(int i=0; i < this->kernel->config->config_sources.size(); i++){ |
scachat | 0:31e91bb0ef3c | 119 | if( this->kernel->config->config_sources[i]->is_named(source_checksum) ){ |
scachat | 0:31e91bb0ef3c | 120 | this->kernel->config->config_sources[i]->transfer_values_to_cache(&this->kernel->config->config_cache); |
scachat | 0:31e91bb0ef3c | 121 | this->kernel->call_event(ON_CONFIG_RELOAD); |
scachat | 0:31e91bb0ef3c | 122 | stream->printf( "Loaded settings from %s\r\n", source.c_str() ); |
scachat | 0:31e91bb0ef3c | 123 | break; |
scachat | 0:31e91bb0ef3c | 124 | } |
scachat | 0:31e91bb0ef3c | 125 | } |
scachat | 0:31e91bb0ef3c | 126 | } |
scachat | 0:31e91bb0ef3c | 127 | } |
scachat | 0:31e91bb0ef3c | 128 |