config_file_found = false;
}
+void Config::on_module_loaded(){
+ this->register_for_event(ON_CONSOLE_LINE_RECEIVED);
+}
+
+// When a new line is received, check if it is a command, and if it is, act upon it
+void Config::on_console_line_received( void* argument ){
+ string possible_command = *static_cast<string*>(argument);
+
+ // 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
+ this->kernel->serial->printf("checksum>%u\r\n", check_sum);
+
+ // Act depending on command
+ switch( check_sum ){
+ //case config-get_checksum: this-> ; break;
+ }
+}
+
+
// Get a value from the configuration as a string
// Because we don't like to waste space in Flash with lengthy config parameter names, we take a checksum instead so that the name does not have to be stored
// See get_checksum
printf("ERROR: configuration key not found\r\n");
}
+// Get a value from the file as a number
double Config::get(uint16_t check_sum){
return atof(this->get_string( check_sum ).c_str());
}
-
-
+// Get the filename for the config file
string Config::get_config_file(){
if( this->config_file_found ){ return this->config_file; }
this->try_config_file("/local/config");
}
}
-void Config::try_config_file(string candidate){
+// Tool function for get_config_file
+inline void Config::try_config_file(string candidate){
FILE *lp = fopen(candidate.c_str(), "r");
if(lp){ this->config_file_found = true; this->config_file = candidate; }
fclose(lp);
#include <string>
using std::string;
+#define config_get_checksum 46310
+#define config_set_checksum 55538
+#define config_load_checksum 3143
+
class Config : public Module {
public:
Config();
+
+ void on_module_loaded();
+ void on_console_line_received( void* argument );
string get_string(uint16_t check_sum);
double get(uint16_t check_sum);
string get_config_file();
parameters = parameters.substr(beginning+1, parameters.size());
return temp;
}
+
+// Separate command from arguments
+string get_arguments( string possible_command ){
+ size_t beginning = possible_command.find_first_of(" ");
+ if( beginning == string::npos ){ return ""; }
+ return possible_command.substr( beginning+1, possible_command.size() - beginning);
+}
+
+
+
string shift_parameter( string ¶meters );
+string get_arguments( string possible_command );
+
// Act depending on command
switch( check_sum ){
- case ls_command_checksum : this->ls_command( this->get_arguments(possible_command)); break;
- case cd_command_checksum : this->cd_command( this->get_arguments(possible_command)); break;
- case cat_command_checksum : this->cat_command(this->get_arguments(possible_command)); break;
+ case ls_command_checksum : this->ls_command( get_arguments(possible_command)); break;
+ case cd_command_checksum : this->cd_command( get_arguments(possible_command)); break;
+ case cat_command_checksum : this->cat_command(get_arguments(possible_command)); break;
}
}
-// Separate command from arguments
-string SimpleShell::get_arguments( string possible_command ){
- size_t beginning = possible_command.find_first_of(" ");
- if( beginning == string::npos ){ return ""; }
- return possible_command.substr( beginning+1, possible_command.size() - beginning);
-}
-
// Convert a path indication ( absolute or relative ) into a path ( absolute )
string SimpleShell::absolute_from_relative( string path ){
if( path[0] == '/' ){ return path; }
void on_module_loaded();
void on_console_line_received( void* argument );
- string get_arguments( string possible_command );
string absolute_from_relative( string path );
void ls_command( string parameters );
void cd_command( string parameters );