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 */;
// 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;
}
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
// 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;
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
};
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();
// 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;
// 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 );
# 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.
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