Only report long lines in config if not truncating a comment
authorJim Morris <morris@wolfman.com>
Wed, 16 Apr 2014 08:30:06 +0000 (01:30 -0700)
committerJim Morris <morris@wolfman.com>
Wed, 16 Apr 2014 08:31:56 +0000 (01:31 -0700)
report the line number the long line is on
Add a DEFAULT_SERIAL_BAUD_RATE define to src/makefile to set the default baud rate used when config has not yet been loaded

src/libs/ConfigSources/FileConfigSource.cpp
src/libs/ConfigSources/FileConfigSource.h
src/libs/Kernel.cpp
src/makefile

index 66da9a9..ddc3864 100644 (file)
@@ -23,14 +23,18 @@ FileConfigSource::FileConfigSource(string config_file, const char *name)
     this->config_file_found = false;
 }
 
-bool FileConfigSource::readLine(string& line, FILE *fp)
+bool FileConfigSource::readLine(string& line, int lineno, FILE *fp)
 {
     char buf[132];
     char *l= fgets(buf, sizeof(buf)-1, fp);
     if(l != NULL) {
         if(buf[strlen(l)-1] != '\n') {
             // truncate long lines
-            printf("Truncated long line in: %s\n", config_file.c_str());
+            if(lineno != 0) {
+                // report if it is not truncating a comment
+                if(strchr(buf, '#') == NULL)
+                    printf("Truncated long line %d in: %s\n", lineno, config_file.c_str());
+            }
             // read until the next \n or eof
             int c;
             while((c=fgetc(fp)) != '\n' && c != EOF) /* discard */;
@@ -51,10 +55,11 @@ void FileConfigSource::transfer_values_to_cache( ConfigCache *cache )
     // Open the config file ( find it if we haven't already found it )
     FILE *lp = fopen(this->get_config_file().c_str(), "r");
 
+    int ln= 1;
     // For each line
     while(!feof(lp)) {
         string line;
-        if(readLine(line, lp)) {
+        if(readLine(line, ln++, lp)) {
             process_line_from_ascii_config(line, cache);
         }else break;
     }
@@ -85,7 +90,7 @@ bool FileConfigSource::write( string setting, string value )
         string line;
         fpos_t bol, eol;
         fgetpos( lp, &bol ); // get start of line
-        if(readLine(line, lp)) {
+        if(readLine(line, 0, lp)) {
             fgetpos( lp, &eol ); // get end of line
             if(!process_line_from_ascii_config(line, setting_checksums).empty()) {
                 // found it
@@ -136,7 +141,7 @@ string FileConfigSource::read( uint16_t check_sums[3] )
     // For each line
     while(!feof(lp)) {
         string line;
-         if(readLine(line, lp)) {
+         if(readLine(line, 0, lp)) {
             value = process_line_from_ascii_config(line, check_sums);
             if(!value.empty()) break; // found it
         }else break;
index 632c254..ab5ca82 100644 (file)
@@ -29,7 +29,7 @@ public:
     string get_config_file();
 
 private:
-    bool readLine(string& line, FILE *fp);
+    bool readLine(string& line, int lineno, FILE *fp);
     string config_file;         // Path to the config file
     bool   config_file_found;   // Wether or not the config file's location is known
 };
index 3676d9f..0d4eab5 100644 (file)
@@ -42,9 +42,9 @@ Kernel* Kernel::instance;
 Kernel::Kernel(){
     instance= this; // setup the Singleton instance of the kernel
 
-    // serial first at fixed baud rate (MRI_BAUD) so config can report errors to serial
+    // serial first at fixed baud rate (DEFAULT_SERIAL_BAUD_RATE) so config can report errors to serial
        // Set to UART0, this will be changed to use the same UART as MRI if it's enabled
-    this->serial = new SerialConsole(USBTX, USBRX, 115200);
+    this->serial = new SerialConsole(USBTX, USBRX, DEFAULT_SERIAL_BAUD_RATE);
 
     // Config next, but does not load cache yet
     this->config         = new Config();
@@ -52,7 +52,7 @@ Kernel::Kernel(){
     // Pre-load the config cache, do after setting up serial so we can report errors to serial
     this->config->config_cache_load();
 
-    // now config is loaded we can do normal setup for serial and the rest
+    // now config is loaded we can do normal setup for serial based on config
     delete this->serial;
     this->serial= NULL;
 
@@ -63,25 +63,26 @@ Kernel::Kernel(){
     // Configure UART depending on MRI config
     // Match up the SerialConsole to MRI UART. This makes it easy to use only one UART for both debug and actual commands.
     NVIC_SetPriorityGrouping(0);
-    if( MRI_ENABLE ) {
-        switch( __mriPlatform_CommUartIndex() ) {
-            case 0:
-                this->serial = new SerialConsole(USBTX, USBRX, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(9600)->as_number());
-                break;
-            case 1:
-                this->serial = new SerialConsole(  p13,   p14, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(9600)->as_number());
-                break;
-            case 2:
-                this->serial = new SerialConsole(  p28,   p27, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(9600)->as_number());
-                break;
-            case 3:
-                this->serial = new SerialConsole(   p9,   p10, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(9600)->as_number());
-                break;
-        }
-    }
 
+#if MRI_ENABLE != 0
+    switch( __mriPlatform_CommUartIndex() ) {
+        case 0:
+            this->serial = new SerialConsole(USBTX, USBRX, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(DEFAULT_SERIAL_BAUD_RATE)->as_number());
+            break;
+        case 1:
+            this->serial = new SerialConsole(  p13,   p14, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(DEFAULT_SERIAL_BAUD_RATE)->as_number());
+            break;
+        case 2:
+            this->serial = new SerialConsole(  p28,   p27, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(DEFAULT_SERIAL_BAUD_RATE)->as_number());
+            break;
+        case 3:
+            this->serial = new SerialConsole(   p9,   p10, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(DEFAULT_SERIAL_BAUD_RATE)->as_number());
+            break;
+    }
+#endif
+    // default
     if(this->serial == NULL) {
-        this->serial = new SerialConsole(USBTX, USBRX, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(9600)->as_number());
+        this->serial = new SerialConsole(USBTX, USBRX, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(DEFAULT_SERIAL_BAUD_RATE)->as_number());
     }
 
     this->add_module( this->config );
index 77988db..df7f9eb 100644 (file)
@@ -27,6 +27,10 @@ STACK_SIZE=3072
 # 0 if you don't want to break into GDB at startup.
 ENABLE_DEBUG_MONITOR?=0
 
+# this is the default UART baud rate used if it is not set in config
+# it is also the baud rate used to report any errors found while parsing the config file
+DEFAULT_SERIAL_BAUD_RATE?=9600
+
 ifeq "$(ENABLE_DEBUG_MONITOR)" "1"
 # Can add MRI_UART_BAUD=115200 to next line if GDB fails to connect to MRI.
 # Tends to happen on some Linux distros but not Windows and OS X.
@@ -46,8 +50,8 @@ else
 DEFINES += -D__GITVERSIONSTRING__=\"placeholder\"
 endif
 
-# use c++11 features for the checksums
-DEFINES += -DCHECKSUM_USE_CPP
+# use c++11 features for the checksums and set default baud rate for serial uart
+DEFINES += -DCHECKSUM_USE_CPP -DDEFAULT_SERIAL_BAUD_RATE=$(DEFAULT_SERIAL_BAUD_RATE)
 
 # add any modules that you do not want included in the build
 export EXCLUDED_MODULES = tools/touchprobe