Permalink
Browse files

Fixed "888 88" bug when hitting backspace. Resolved ambigous "rm" com…

…mand, new "rm" implementation. New commands: pwd (print working directory), echo <on>|<off>. Fixed bug when using "size", leaking file handle. Removed too_many_arguments_error() in order to free up memory.
  • Loading branch information...
1 parent 03876f4 commit 4a1c0da2386db63195fe0a6cc3055386945e0ffe Paul Ring committed Oct 3, 2010
@@ -96,6 +96,7 @@
*
* @author Paul Ring - hexor@coolbox.se
* @version 1.1 - June, 2010
+ * @version 1.2 - October, 2010
*/
public class OpenLog {
@@ -212,9 +213,15 @@ private boolean escapeCharAck() {
// According to the documentation we have to send
// the escape character several times (default is 3) in order to abort if in
// logging mode
- for (int i = 0; i < 10; i++) {
+ int i = 0;
+ for (i = 0; i < 10; i++) {
txUart.sendByte(EscChar);
CPU.delay(500);
+ }
+
+ for (i = 0; i < 10; i++) {
+ txUart.sendByte(CR);
+ CPU.delay(500);
while (rxUart.byteAvailable()) {
if ((char)rxUart.receiveByte() == shellReady ) {return true;}
}
@@ -275,8 +282,8 @@ private boolean fwrite(String fileName,
// Send Ctrl+Z to escape from append mode
escapeCharAck();
} else {
- // Send a single LF ('\n') to exit from write mode
- txUart.sendByte(LF);
+ // Send a single CR ('\r') to exit from write mode
+ txUart.sendByte(CR);
}
// We should be alive now
return openLogAlive();
@@ -289,26 +296,32 @@ private boolean openLogExecute(String command, StringBuffer reply, char promptCh
if (reply != null)
buff = reply;
+ // Clear the UART
+ while (rxUart.byteAvailable())
+ rxUart.receiveByte();
+
// Send message
buff.clear();
buff.append(command);
+ buff.append(CR);
txUart.sendString(buff.toString());
- txUart.sendByte('\n');
buff.clear();
int count = 0;
- boolean endTokenFound = false;
int capacity = buff.capacity();
opBuffer.clear();
// Give the module some time to respond
// Collect the return value and the result
timer.mark();
while (!timer.timeout(10000) && !rxUart.byteAvailable()) {CPU.delay(10);}
- while (rxUart.byteAvailable() && !endTokenFound) {
- char ch = (char)rxUart.receiveByte();
- if ((ch != (char)EscChar) && (ch != 0) && (count < capacity)) {
+ while (true) {
+ char ch = 0;
+ if (rxUart.byteAvailable())
+ ch = (char)rxUart.receiveByte();
+
+ if ((ch != (char)EscChar) && ((ch != 0) && (ch != -1)) && (count < capacity)) {
buff.append(ch);
count++;
} else if (ch == (char)EscChar) {
@@ -515,7 +528,8 @@ public boolean writeFile(String fileName,
int openLogInit = 0;
while (!(success = fwrite(fileName, fileData, append))) {
- if (openLogInit++ > 2) { break; }; // Made 2 tries and still the problem is not fixed
+ CPU.delay(5000);
+ if (openLogInit++ > 1) { break; }; // Made 2 tries and still the problem is not fixed
}
return success;
@@ -593,6 +607,8 @@ public FileInfo fileSize(String fileName) {
opBuffer.clear();
for (int i = 0; i < length; i++) {
char ch = tempBuffer.charAt(i);
+ if ((ch == CR) || (ch == LF)) // Skip '\n' and '\r'
+ continue;
if (!isNumeric(ch)) { // enough here, we are not excepting anything more
break;
}
@@ -612,12 +628,14 @@ public FileInfo fileSize(String fileName) {
}
public boolean openLogRestart() {
-
// Hardware reset according to OpenLog documentation
CPU.writePin(resetPin, false);
delay(0);
CPU.writePin(resetPin, true);
- delay(8); // Give the OpenLog some time to initialize itself
+ delay(6); // Give the OpenLog some time to initialize itself
+ //CPU.writePin(this.resetPin, false);
+ //CPU.delay(1000);
+ //CPU.writePin(this.resetPin, true);
// Send escape char in case it enters append mode
escapeCharAck();
@@ -654,10 +672,10 @@ public boolean openLogInit() {
return false;
// Turn off the binary mode
- opBuffer.clear();
- opBuffer.append("binary off");
- if (!openLogExecute(opBuffer.toString(), null, shellReady))
- return false;
+// opBuffer.clear();
+// opBuffer.append("binary off");
+// if (!openLogExecute(opBuffer.toString(), null, shellReady))
+// return false;
return true;
}
Oops, something went wrong.

0 comments on commit 4a1c0da

Please sign in to comment.