Skip to content

Commit

Permalink
Fixed "888 88" bug when hitting backspace. Resolved ambigous "rm" com…
Browse files Browse the repository at this point in the history
…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
Paul Ring committed Oct 3, 2010
1 parent 03876f4 commit 4a1c0da
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 95 deletions.
Expand Up @@ -96,6 +96,7 @@
*
* @author Paul Ring - hexor@coolbox.se
* @version 1.1 - June, 2010
* @version 1.2 - October, 2010
*/

public class OpenLog {
Expand Down Expand Up @@ -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;}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4a1c0da

Please sign in to comment.