Improved parsing of serial data and output

This commit is contained in:
adamdunkels 2009-02-08 19:38:22 +00:00
parent 54b4226f70
commit 0d1e7e9b32
2 changed files with 102 additions and 96 deletions

View File

@ -10,16 +10,6 @@ print_stats()
total_dups + " dups, " + total_dups + " dups, " +
(total_dups / nrNodes) + " dups/node, " + (total_dups / nrNodes) + " dups/node, " +
(total_hops / total_received) + " hops/message\n"); (total_hops / total_received) + " hops/message\n");
log.log("Received: ");
for(i = 1; i <= nrNodes; i++) {
log.log(count[i] + " ");
}
log.log("\n");
log.log("Hops: ");
for(i = 1; i <= nrNodes; i++) {
log.log(hops[i] + " ");
}
log.log("\n");
log.log("Seqnos: "); log.log("Seqnos: ");
for(i = 1; i <= nrNodes; i++) { for(i = 1; i <= nrNodes; i++) {
log.log(seqnos[i] + " "); log.log(seqnos[i] + " ");
@ -35,6 +25,16 @@ print_stats()
log.log(dups[i] + " "); log.log(dups[i] + " ");
} }
log.log("\n"); log.log("\n");
log.log("Hops: ");
for(i = 1; i <= nrNodes; i++) {
log.log(hops[i] + " ");
}
log.log("\n");
log.log("Received: ");
for(i = 1; i <= nrNodes; i++) {
log.log(count[i] + " ");
}
log.log("\n");
} }
/* Conf. */ /* Conf. */
@ -84,45 +84,48 @@ while(true) {
YIELD(); YIELD();
/* Count sensor data packets */ /* Count sensor data packets */
node_text = msg.split(" ")[4]; if(msg.startsWith("Sink")) {
seqno_text = msg.split(" ")[6]; node_text = msg.split(" ")[4];
hops_text = msg.split(" ")[8]; seqno_text = msg.split(" ")[6];
if(node_text) { hops_text = msg.split(" ")[8];
source = parseInt(node_text); if(node_text) {
seqno = parseInt(seqno_text); source = parseInt(node_text);
hop = parseInt(hops_text); seqno = parseInt(seqno_text);
count[source]++; hop = parseInt(hops_text);
hops[source] = hop; count[source]++;
seqno_gap = seqno - seqnos[source]; hops[source] = hop;
seqnos[source] = seqno; seqno_gap = seqno - seqnos[source];
seqnos[source] = seqno;
total_received++; total_received++;
total_hops += hop; total_hops += hop;
if(seqno_gap == 2) { if(seqno_gap == 2) {
total_lost += seqno_gap - 1; total_lost += seqno_gap - 1;
lost[source] += seqno_gap - 1; lost[source] += seqno_gap - 1;
} else if(seqno_gap == 0) { } else if(seqno_gap == 0) {
total_dups += 1; total_dups += 1;
dups[source] += 1; dups[source] += 1;
}
} }
} /* Fail if the sink has received more than 10 messages from any node. */
/* Fail if the sink has received more than 10 messages from any node. */ for(i = 1; i <= nrNodes; i++) {
for(i = 1; i <= nrNodes; i++) { if(count[i] > 10) {
if(count[i] > 10) { print_stats();
print_stats(); log.testFailed(); /* We are done! */
log.testFailed(); /* We are done! */ }
} }
}
/* Wait until the sink have received at least two messages from every node */ /* Wait until the sink have received at least two messages from every node */
for(i = 1; i <= nrNodes; i++) { for(i = 1; i <= nrNodes; i++) {
if(count[i] < 2) { if(count[i] < 2) {
break; break;
} }
if(i == nrNodes) { if(i == nrNodes) {
print_stats(); print_stats();
log.testOK(); log.testOK();
}
} }
print_stats();
} }
} }

View File

@ -10,16 +10,6 @@ print_stats()
total_dups + " dups, " + total_dups + " dups, " +
(total_dups / nrNodes) + " dups/node, " + (total_dups / nrNodes) + " dups/node, " +
(total_hops / total_received) + " hops/message\n"); (total_hops / total_received) + " hops/message\n");
log.log("Received: ");
for(i = 1; i <= nrNodes; i++) {
log.log(count[i] + " ");
}
log.log("\n");
log.log("Hops: ");
for(i = 1; i <= nrNodes; i++) {
log.log(hops[i] + " ");
}
log.log("\n");
log.log("Seqnos: "); log.log("Seqnos: ");
for(i = 1; i <= nrNodes; i++) { for(i = 1; i <= nrNodes; i++) {
log.log(seqnos[i] + " "); log.log(seqnos[i] + " ");
@ -35,6 +25,16 @@ print_stats()
log.log(dups[i] + " "); log.log(dups[i] + " ");
} }
log.log("\n"); log.log("\n");
log.log("Hops: ");
for(i = 1; i <= nrNodes; i++) {
log.log(hops[i] + " ");
}
log.log("\n");
log.log("Received: ");
for(i = 1; i <= nrNodes; i++) {
log.log(count[i] + " ");
}
log.log("\n");
} }
/* Conf. */ /* Conf. */
@ -84,45 +84,48 @@ while(true) {
YIELD(); YIELD();
/* Count sensor data packets */ /* Count sensor data packets */
node_text = msg.split(" ")[4]; if(msg.startsWith("Sink")) {
seqno_text = msg.split(" ")[6]; node_text = msg.split(" ")[4];
hops_text = msg.split(" ")[8]; seqno_text = msg.split(" ")[6];
if(node_text) { hops_text = msg.split(" ")[8];
source = parseInt(node_text); if(node_text) {
seqno = parseInt(seqno_text); source = parseInt(node_text);
hop = parseInt(hops_text); seqno = parseInt(seqno_text);
count[source]++; hop = parseInt(hops_text);
hops[source] = hop; count[source]++;
seqno_gap = seqno - seqnos[source]; hops[source] = hop;
seqnos[source] = seqno; seqno_gap = seqno - seqnos[source];
seqnos[source] = seqno;
total_received++; total_received++;
total_hops += hop; total_hops += hop;
if(seqno_gap == 2) { if(seqno_gap == 2) {
total_lost += seqno_gap - 1; total_lost += seqno_gap - 1;
lost[source] += seqno_gap - 1; lost[source] += seqno_gap - 1;
} else if(seqno_gap == 0) { } else if(seqno_gap == 0) {
total_dups += 1; total_dups += 1;
dups[source] += 1; dups[source] += 1;
}
} }
} /* Fail if the sink has received more than 10 messages from any node. */
/* Fail if the sink has received more than 10 messages from any node. */ for(i = 1; i <= nrNodes; i++) {
for(i = 1; i <= nrNodes; i++) { if(count[i] > 10) {
if(count[i] > 10) { print_stats();
print_stats(); log.testFailed(); /* We are done! */
log.testFailed(); /* We are done! */ }
} }
}
/* Wait until the sink have received at least two messages from every node */ /* Wait until the sink have received at least two messages from every node */
for(i = 1; i <= nrNodes; i++) { for(i = 1; i <= nrNodes; i++) {
if(count[i] < 2) { if(count[i] < 2) {
break; break;
} }
if(i == nrNodes) { if(i == nrNodes) {
print_stats(); print_stats();
log.testOK(); log.testOK();
}
} }
print_stats();
} }
} }