//this->kernel->serial->printf("ERROR: configuration key not found\r\n");
}
-string FileConfigSource::read( vector<uint16_t> check_sums ){}
+// Return the value for a specific checksum
+string FileConfigSource::read( vector<uint16_t> check_sums ){
+
+ string value = "";
+
+ if( this->has_config_file() == false ){return value;}
+ // Open the config file ( find it if we haven't already found it )
+ FILE *lp = fopen(this->get_config_file().c_str(), "r");
+ string buffer;
+ int c;
+ // For each line
+ do {
+ c = fgetc (lp);
+ if (c == '\n' || c == EOF){
+ // We have a new line
+ if( buffer[0] == '#' ){ buffer.clear(); continue; } // Ignore comments
+ if( buffer.length() < 3 ){ buffer.clear(); continue; } //Ignore empty lines
+ size_t begin_key = buffer.find_first_not_of(" ");
+ size_t begin_value = buffer.find_first_not_of(" ", buffer.find_first_of(" ", begin_key));
+ string key = buffer.substr(begin_key, buffer.find_first_of(" ", begin_key) - begin_key).append(" ");
+ vector<uint16_t> line_checksums = get_checksums(key);
+
+ if(check_sums == line_checksums){
+ value = buffer.substr(begin_value, buffer.find_first_of("\r\n# ", begin_value+1)-begin_value);
+ break;
+ }
+
+ buffer.clear();
+ }else{
+ buffer += c;
+ }
+ } while (c != EOF);
+ fclose(lp);
+
+ return value;
+}
// Return wether or not we have a readable config file
bool FileConfigSource::has_config_file(){