made COOJA avoid guessing that the debug printouts are TinyOS if many SLIP chars in stream

This commit is contained in:
joxe 2010-05-09 19:45:57 +00:00
parent 6f66d36d67
commit ffdda2259f

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: SerialUI.java,v 1.4 2010/03/15 22:04:26 fros4943 Exp $ * $Id: SerialUI.java,v 1.5 2010/05/09 19:45:57 joxe Exp $
*/ */
package se.sics.cooja.dialogs; package se.sics.cooja.dialogs;
@ -62,6 +62,12 @@ import se.sics.cooja.plugins.SLIP;
public abstract class SerialUI extends Log implements SerialPort { public abstract class SerialUI extends Log implements SerialPort {
private static Logger logger = Logger.getLogger(SerialUI.class); private static Logger logger = Logger.getLogger(SerialUI.class);
private final static byte SLIP_END = (byte)0300;
private final static byte SLIP_ESC = (byte)0333;
private final static byte SLIP_ESC_END = (byte)0334;
private final static byte SLIP_ESC_ESC = (byte)0335;
private final static int MAX_LENGTH = 1024; private final static int MAX_LENGTH = 1024;
private String lastLogMessage = ""; private String lastLogMessage = "";
@ -278,7 +284,13 @@ public abstract class SerialUI extends Log implements SerialPort {
private int tosPos = 0; private int tosPos = 0;
private int tosLen = 0; private int tosLen = 0;
private int slipCounter = 0;
private int totalTOSChars = 0;
public void dataReceived(int data) { public void dataReceived(int data) {
if (data == SLIP_END || data == SLIP_ESC) {
slipCounter++;
}
if (tosMode) { if (tosMode) {
/* needs to add checks to CRC */ /* needs to add checks to CRC */
// System.out.println("Received: " + Integer.toString(data, 16) + " = " + (char) data + " tosPos: " + tosPos); // System.out.println("Received: " + Integer.toString(data, 16) + " = " + (char) data + " tosPos: " + tosPos);
@ -311,10 +323,15 @@ public abstract class SerialUI extends Log implements SerialPort {
} else { } else {
if (data == 0x7e) { if (data == 0x7e) {
tosChars++; tosChars++;
totalTOSChars++;
if (tosChars == 2) { if (tosChars == 2) {
if (totalTOSChars > slipCounter) {
tosMode = true; tosMode = true;
/* already read one char here */ /* already read one char here */
tosPos = 1; tosPos = 1;
} else {
tosChars = 0;
}
} }
} else { } else {
tosChars = 0; tosChars = 0;