Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

v2.51 Improved command prompt parsing (now ignores '\n')

We now ignore the \n character when parsing characters from the command prompt. This makes it easier to create code on a microcontroller that correctly controls OpenLog. Previously, println or sprintf commands were adding a \n to the end of the string that would confuse OpenLog. One way around this if you have previous versions is this
 sprintf(buff, "new blah.txt\r");
 Serial.print(buff); //No println, use \r in string instead

Also - added a CommandTest sketch to demonstrate how you can control OpenLog from a microcontroller / automate the command prompt
  • Loading branch information...
commit 13b502bf2b8e1d978636f77826edec4abc338796 1 parent 8777803
@nseidle nseidle authored
View
90 OpenLog_CommandTest/OpenLog_CommandTest.pde
@@ -0,0 +1,90 @@
+/*
+ 6-1-2011
+ SparkFun Electronics 2011
+ Nathan Seidle
+
+ Controlling OpenLog command line from an Arduino
+
+ This example code assumes the OpenLog is set to operate in NewLog mode, meaning OpenLog should power
+ up and output '12<'. This code then sends the three escape characters and then sends the commands
+ to create a new random file called nate###.txt where ### is a random number from 0 to 999.
+
+ Be careful when sending commands to OpenLog. println() sends extra newline characters that
+ cause problems with the command parser. The new v2.51 ignores \n commands so it should be easier to
+ talk to on the command prompt level. This example code works with all OpenLog v2 and higher.
+
+ */
+
+char buff[50];
+int fileNumber;
+
+int statLED = 13;
+int resetOpenLog = 2;
+
+void setup() {
+ pinMode(statLED, OUTPUT);
+ pinMode(resetOpenLog, OUTPUT);
+
+ randomSeed(analogRead(0));
+ Serial.begin(115200);
+
+ //Reset OpenLog
+ digitalWrite(resetOpenLog, LOW);
+ delay(100);
+ digitalWrite(resetOpenLog, HIGH);
+
+ //Wait for OpenLog to respond with '<' to indicate it is alive and recording to a file
+ while(1) {
+ if(Serial.available())
+ if(Serial.read() == '<') break;
+ }
+
+ //Send three control z to enter OpenLog command mode
+ Serial.print(byte(26));
+ Serial.print(byte(26));
+ Serial.print(byte(26));
+
+ //Wait for OpenLog to respond with '>' to indicate we are in command mode
+ while(1) {
+ if(Serial.available())
+ if(Serial.read() == '>') break;
+ }
+
+ fileNumber = random(999); //Select a random file #, 0 to 999
+
+ //Send new (random from 0 to 999) file name
+
+ //Old way
+ sprintf(buff, "new nate%03d.txt\r", fileNumber);
+ Serial.print(buff); //\r in string + regular print works with older v2.5 Openlogs
+
+ //New way
+ //sprintf(buff, "new nate%03d.txt", fileNumber);
+ //Serial.println(buff); //regular println works with v2.51 and above
+
+
+ //Wait for OpenLog to return to waiting for a command
+ while(1) {
+ if(Serial.available())
+ if(Serial.read() == '>') break;
+ }
+
+ sprintf(buff, "append nate%03d.txt\r", fileNumber);
+ Serial.print(buff);
+
+ //Wait for OpenLog to indicate file is open and ready for writing
+ while(1) {
+ if(Serial.available())
+ if(Serial.read() == '<') break;
+ }
+}
+
+void loop() {
+ Serial.println("Yay!");
+ digitalWrite(13, HIGH);
+ delay(1000);
+ digitalWrite(13, LOW);
+ delay(1000);
+}
+
+
View
3,488 OpenLog_v2/OpenLog_v2.cpp.hex
1,733 additions, 1,755 deletions not shown
View
17 OpenLog_v2/OpenLog_v2.pde
@@ -204,6 +204,17 @@
Issuing 'reset' command causes OpenLog to reset and re-read the config file. This is important if you want to change the config file then restart.
Removed some of the extraneous prints from the help menu to save on space.
+
+
+ v2.51 Improved command prompt parsing (now ignores '\n')
+
+ We now ignore the \n character when parsing characters from the command prompt. This makes it easier to create code on a microcontroller that
+ correctly controls OpenLog. Previously, println or sprintf commands were adding a \n to the end of the string that would confuse OpenLog. One
+ way around this if you have previous versions is this
+ sprintf(buff, "new blah.txt\r");
+ Serial.print(buff); //No println, use \r in string instead
+
+ Also - added a CommandTest sketch to demonstrate how you can control OpenLog from a microcontroller / automate the command prompt
*/
@@ -1419,6 +1430,12 @@ uint8_t read_line(char* buffer, uint8_t buffer_length)
buffer[read_length] = '\0';
break;
}
+ else if (c == '\n') {
+ //Do nothing - ignore newlines
+ //This was added to v2.51 to make command line control easier from a micro
+ //You never know what fprintf or sprintf is going to throw at the buffer
+ //See issue 66: https://github.com/nseidle/OpenLog/issues/66
+ }
else {
buffer[read_length] = c;
++read_length;
View
4 README
@@ -23,4 +23,6 @@ v2.2 Modified append_file() to use a single buffer. Increased HardwareSerial.cpp
v2.21 ringp fork brought in. rm dir, cd .., and wildcards now work!
v2.3 Migrated to v10.10.10 of sdfatlib. Moved to inline RX interrupt and buffer.
v2.4 Merged ringp updates. Commands cd, rm, ls work again!
-v2.41 Power loss bug fixed. Adding support for 38400bps for testing with SparkFum 9DOF IMU logging.
+v2.41 Power loss bug fixed. Adding support for 38400bps for testing with SparkFum 9DOF IMU logging.
+v2.5 Added software reset command. Modified the read command to print extended ASCII characters.
+v2.51 Changed command prompt control to ignore \n for easier control from microcontroller.
Please sign in to comment.
Something went wrong with that request. Please try again.