[net2-wg] logger
Razvan Musaloiu-E.
razvanm at cs.jhu.edu
Thu Feb 12 17:45:33 PST 2009
Hi!
In case we have some time tomorrow to talk about the logging mechanism I
mention last time, the code can be found in the 'logger' head from here:
http://hinrg.cs.jhu.edu/git/?p=razvanm/tinyos-2.x.git
A sequence of commands to get it is this:
mkdir /tmp/tinyos2.x
git init
git fetch git://hinrg.cs.jhu.edu/git/razvanm/tinyos-2.x.git logger:logger
git checkout logger
I also attached a patch against the current CVS.
Here is also a summary of the changes:
apps/tests/TestLogger/Makefile | 4 +
apps/tests/TestLogger/README | 8 ++
apps/tests/TestLogger/TestLoggerApp.nc | 6 +
apps/tests/TestLogger/TestLoggerC.nc | 12 ++
apps/tests/TestLogger/TestLoggerP.nc | 29 +++++
apps/tests/TestLogger/tos-dump.py | 36 +++++++
tos/lib/logger/LoggerC.nc | 27 +++++
tos/lib/logger/LoggerP.nc | 179 ++++++++++++++++++++++++++++++++
tos/lib/logger/MainC.nc | 64 +++++++++++
tos/lib/logger/README | 6 +
tos/lib/logger/logger.h | 27 +++++
tos/platforms/telosa/GlobalsC.nc | 13 +++
tos/platforms/telosa/GlobalsP.nc | 11 ++
tos/types/Globals.h | 6 +
tos/types/logger.h | 12 ++
--
Razvan ME
-------------- next part --------------
diff --git a/apps/tests/TestLogger/Makefile b/apps/tests/TestLogger/Makefile
new file mode 100644
index 0000000..d149888
--- /dev/null
+++ b/apps/tests/TestLogger/Makefile
@@ -0,0 +1,4 @@
+COMPONENT=TestLoggerApp
+#CFLAGS+=-DTOSH_DATA_LENGTH=48
+CFLAGS += -I$(TOSDIR)/lib/logger
+include $(MAKERULES)
diff --git a/apps/tests/TestLogger/README b/apps/tests/TestLogger/README
new file mode 100644
index 0000000..2ac2b64
--- /dev/null
+++ b/apps/tests/TestLogger/README
@@ -0,0 +1,8 @@
+To enable all logger3 to logger6 the TOSH_DATA_LENGTH needs to be at
+least 48. This settings can be enabled from Makefile.
+
+By commenting out the 'CFLAGS += -I$(TOSDIR)/lib/logger' the logger
+can be completely disabled.
+
+tos-dump.py is a testing script that will decode and print the serial
+messages.
\ No newline at end of file
diff --git a/apps/tests/TestLogger/TestLoggerApp.nc b/apps/tests/TestLogger/TestLoggerApp.nc
new file mode 100644
index 0000000..d393eef
--- /dev/null
+++ b/apps/tests/TestLogger/TestLoggerApp.nc
@@ -0,0 +1,6 @@
+configuration TestLoggerApp { }
+
+implementation
+{
+ components TestLoggerC;
+}
diff --git a/apps/tests/TestLogger/TestLoggerC.nc b/apps/tests/TestLogger/TestLoggerC.nc
new file mode 100644
index 0000000..f771500
--- /dev/null
+++ b/apps/tests/TestLogger/TestLoggerC.nc
@@ -0,0 +1,12 @@
+configuration TestLoggerC { }
+
+implementation
+{
+ components MainC, NoLedsC, LedsC;
+ components new TimerMilliC() as Timer;
+ components TestLoggerP;
+
+ TestLoggerP.Boot -> MainC.Boot;
+ TestLoggerP.Leds -> NoLedsC;
+ TestLoggerP.Timer -> Timer;
+}
diff --git a/apps/tests/TestLogger/TestLoggerP.nc b/apps/tests/TestLogger/TestLoggerP.nc
new file mode 100644
index 0000000..9a8502b
--- /dev/null
+++ b/apps/tests/TestLogger/TestLoggerP.nc
@@ -0,0 +1,29 @@
+#include "logger.h"
+
+module TestLoggerP
+{
+ uses {
+ interface Boot;
+ interface Leds;
+ interface Timer<TMilli> as Timer;
+ }
+}
+
+implementation
+{
+ uint32_t i;
+
+ event void Boot.booted()
+ {
+ call Timer.startPeriodic(1024);
+ }
+
+ event void Timer.fired()
+ {
+ i++;
+ logger2("test", i, i);
+ i++;
+ logger3("test", i, i, i);
+ logger6("test", 1, 2, 3, 4, 5, 6);
+ }
+}
diff --git a/apps/tests/TestLogger/tos-dump.py b/apps/tests/TestLogger/tos-dump.py
new file mode 100755
index 0000000..021236a
--- /dev/null
+++ b/apps/tests/TestLogger/tos-dump.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import sys, time
+import tos
+
+class Logger(tos.Packet):
+ def __init__(self, payload = None):
+ tos.Packet.__init__(self,
+ [('timestamp', 'int', 4),
+ ('seqno', 'int', 4),
+ ('tag', 'string', 12),
+ ('arg1', 'int', 4),
+ ('arg2', 'int', 4),
+ ('arg3', 'int', 4),
+ ('arg4', 'int', 4),
+ ('arg5', 'int', 4),
+ ('arg6', 'int', 4)],
+ payload)
+
+
+if len(sys.argv) < 2:
+ print "Usage:", sys.argv[0], "serial@/dev/ttyUSB0:57600"
+ sys.exit()
+
+am = tos.AM()
+
+while True:
+ p = am.read()
+ if p:
+ ts = "%.4f" % time.time()
+ if p.type == 101:
+ logger = Logger(p.data)
+ print ts, ' '.join(map(str, logger.values()))
+ else:
+ print ts, p
+
diff --git a/tos/lib/logger/LoggerC.nc b/tos/lib/logger/LoggerC.nc
new file mode 100644
index 0000000..98ae76f
--- /dev/null
+++ b/tos/lib/logger/LoggerC.nc
@@ -0,0 +1,27 @@
+#include "Globals.h"
+#include "logger.h"
+
+configuration LoggerC
+{
+ provides interface Boot;
+ uses interface Boot as MainBoot @exactlyonce();
+}
+
+implementation
+{
+ components SerialActiveMessageC;
+ components new SerialAMSenderC(AM_LOGGER_MSG);
+ components new PoolC(message_t, LOGGER_BUFFER_PKTS);
+ components new QueueC(message_t*, LOGGER_BUFFER_PKTS);
+ components LoggerP;
+ components GlobalsC;
+
+ MainBoot = LoggerP.MainBoot;
+ Boot = LoggerP.Boot;
+
+ LoggerP.SerialSplitControl -> SerialActiveMessageC;
+ LoggerP.AMSend -> SerialAMSenderC;
+ LoggerP.Packet -> SerialAMSenderC;
+ LoggerP.Queue -> QueueC;
+ LoggerP.Pool -> PoolC;
+}
\ No newline at end of file
diff --git a/tos/lib/logger/LoggerP.nc b/tos/lib/logger/LoggerP.nc
new file mode 100644
index 0000000..52f9bab
--- /dev/null
+++ b/tos/lib/logger/LoggerP.nc
@@ -0,0 +1,179 @@
+module LoggerP
+{
+ provides interface Boot;
+ uses {
+ interface Boot as MainBoot;
+ interface SplitControl as SerialSplitControl;
+ interface AMSend;
+ interface Packet;
+ interface Pool<message_t>;
+ interface Queue<message_t*>;
+ }
+}
+
+implementation
+{
+ uint32_t seqno = 0;
+ bool booted = FALSE;
+
+ event void MainBoot.booted()
+ {
+ call SerialSplitControl.start();
+ }
+
+ event void SerialSplitControl.startDone(error_t error)
+ {
+ if (!booted) {
+ booted = TRUE;
+ signal Boot.booted();
+ }
+ }
+
+ event void SerialSplitControl.stopDone(error_t error) { }
+
+ void send(message_t *msg, uint8_t len)
+ {
+ error_t error;
+ error = call AMSend.send(AM_BROADCAST_ADDR, msg, len);
+ switch (error) {
+ case SUCCESS:
+ break;
+ case EBUSY:
+ call Packet.setPayloadLength(msg, len);
+ call Queue.enqueue(msg);
+ break;
+ default:
+ call Pool.put(msg);
+ }
+ }
+
+ event void AMSend.sendDone(message_t* msg, error_t error)
+ {
+ call Pool.put(msg);
+ if (!call Queue.empty()) {
+ msg = call Queue.dequeue();
+ send(msg, call Packet.payloadLength(msg));
+ }
+ }
+
+ inline logger_msg_t* init(message_t *msg, char *tag)
+ {
+ logger_msg_t *loggerMsg = call AMSend.getPayload(msg, sizeof(logger_msg_t));
+ loggerMsg->timestamp = getLocalTime();
+ loggerMsg->seqno = seqno++;
+ strncpy((char*)loggerMsg->tag, tag, sizeof(loggerMsg->tag));
+ return loggerMsg;
+ }
+
+ void logger(char *tag) @C() @spontaneous()
+ {
+ message_t *msg = call Pool.get();
+ logger_msg_t *loggerMsg;
+
+ if (msg == NULL) {
+ return;
+ }
+
+ loggerMsg = init(msg, tag);
+ send(msg, sizeof(logger_msg_t));
+ }
+
+ void logger1(char *tag, uint32_t arg1) @C() @spontaneous()
+ {
+ message_t *msg = call Pool.get();
+ logger_msg_t *loggerMsg;
+
+ if (msg == NULL) {
+ return;
+ }
+
+ loggerMsg = init(msg, tag);
+ loggerMsg->args[0] = arg1;
+ send(msg, sizeof(logger_msg_t) + sizeof(loggerMsg->args[0]));
+ }
+
+ void logger2(char *tag, uint32_t arg1, uint32_t arg2) @C() @spontaneous()
+ {
+ message_t *msg = call Pool.get();
+ logger_msg_t *loggerMsg;
+
+ if (msg == NULL) {
+ return;
+ }
+
+ loggerMsg = init(msg, tag);
+ loggerMsg->args[0] = arg1;
+ loggerMsg->args[1] = arg2;
+ send(msg, sizeof(logger_msg_t) + 2*sizeof(loggerMsg->args[0]));
+ }
+
+ void logger3(char *tag, uint32_t arg1, uint32_t arg2, uint32_t arg3) @C() @spontaneous()
+ {
+ message_t *msg = call Pool.get();
+ logger_msg_t *loggerMsg;
+
+ if (msg == NULL) {
+ return;
+ }
+
+ loggerMsg = init(msg, tag);
+ loggerMsg->args[0] = sizeof(logger_msg_t) + 3*sizeof(loggerMsg->args[0]);
+ loggerMsg->args[1] = call Pool.size();
+ loggerMsg->args[2] = arg3;
+ send(msg, sizeof(logger_msg_t) + 3*sizeof(loggerMsg->args[0]));
+ }
+
+ void logger4(char *tag, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4) @C() @spontaneous()
+ {
+ message_t *msg = call Pool.get();
+ logger_msg_t *loggerMsg;
+
+ if (msg == NULL) {
+ return;
+ }
+
+ loggerMsg = init(msg, tag);
+ loggerMsg->args[0] = arg1;
+ loggerMsg->args[1] = arg2;
+ loggerMsg->args[2] = arg3;
+ loggerMsg->args[3] = arg4;
+ send(msg, sizeof(logger_msg_t) + 4*sizeof(loggerMsg->args[0]));
+ }
+
+ void logger5(char *tag, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5) @C() @spontaneous()
+ {
+ message_t *msg = call Pool.get();
+ logger_msg_t *loggerMsg;
+
+ if (msg == NULL) {
+ return;
+ }
+
+ loggerMsg = init(msg, tag);
+ loggerMsg->args[0] = arg1;
+ loggerMsg->args[1] = arg2;
+ loggerMsg->args[2] = arg3;
+ loggerMsg->args[3] = arg4;
+ loggerMsg->args[4] = arg5;
+ send(msg, sizeof(logger_msg_t) + 5*sizeof(loggerMsg->args[0]));
+ }
+
+ void logger6(char *tag, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5, uint32_t arg6) @C() @spontaneous()
+ {
+ message_t *msg = call Pool.get();
+ logger_msg_t *loggerMsg;
+
+ if (msg == NULL) {
+ return;
+ }
+
+ loggerMsg = init(msg, tag);
+ loggerMsg->args[0] = arg1;
+ loggerMsg->args[1] = arg2;
+ loggerMsg->args[2] = arg3;
+ loggerMsg->args[3] = arg4;
+ loggerMsg->args[4] = arg5;
+ loggerMsg->args[5] = arg6;
+ send(msg, sizeof(logger_msg_t) + 6*sizeof(loggerMsg->args[0]));
+ }
+}
\ No newline at end of file
diff --git a/tos/lib/logger/MainC.nc b/tos/lib/logger/MainC.nc
new file mode 100644
index 0000000..2768f75
--- /dev/null
+++ b/tos/lib/logger/MainC.nc
@@ -0,0 +1,64 @@
+// $Id: MainC.nc,v 1.1 2008/06/12 12:33:47 klueska Exp $
+
+/* tab:4
+ * "Copyright (c) 2000-2003 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ * Copyright (c) 2002-2003 Intel Corporation
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached INTEL-LICENSE
+ * file. If you do not find these files, copies can be found by writing to
+ * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
+ * 94704. Attention: Intel License Inquiry.
+ *
+ * Date last modified: $Id: MainC.nc,v 1.1 2008/06/12 12:33:47 klueska Exp $
+ */
+
+/**
+ * MainC is the system interface the TinyOS boot sequence. It wires the
+ * boot sequence implementation to the scheduler and hardware resources.
+ *
+ * @author Philip Levis
+ * @author Kevin Klues
+ * @date August 6 2005
+ */
+
+#include "hardware.h"
+
+configuration MainC
+{
+ provides interface Boot;
+ uses interface Init as SoftwareInit;
+}
+
+implementation
+{
+ components PlatformC, RealMainP, TinySchedulerC;
+ components LoggerC;
+
+ RealMainP.Scheduler -> TinySchedulerC;
+ RealMainP.PlatformInit -> PlatformC;
+ LoggerC.MainBoot -> RealMainP;
+
+ // Export the SoftwareInit and Booted for applications
+ SoftwareInit = RealMainP.SoftwareInit;
+ Boot = LoggerC;
+}
+
diff --git a/tos/lib/logger/README b/tos/lib/logger/README
new file mode 100644
index 0000000..5ed5f26
--- /dev/null
+++ b/tos/lib/logger/README
@@ -0,0 +1,6 @@
+The only tunable thing is the number of packets to buffer. The default
+value is 5. It can be change to a value of x by adding
+-DLOGGER_BUFFER_PKTS=x to CFLAGS.
+
+For using logger6 the TOSH_DATA_LENGTH needs to be at least 48. The
+default value of 28 allows only logger, logger1 and logger2.
diff --git a/tos/lib/logger/logger.h b/tos/lib/logger/logger.h
new file mode 100644
index 0000000..eb82341
--- /dev/null
+++ b/tos/lib/logger/logger.h
@@ -0,0 +1,27 @@
+#ifndef LOGGER_H
+#define LOGGER_H
+
+#ifndef LOGGER_BUFFER_PKTS
+#define LOGGER_BUFFER_PKTS 5
+#endif
+
+enum {
+ AM_LOGGER_MSG = 101,
+};
+
+void logger(char *tag);
+void logger1(char *tag, uint32_t arg1);
+void logger2(char *tag, uint32_t arg1, uint32_t arg2);
+void logger3(char *tag, uint32_t arg1, uint32_t arg2, uint32_t arg3);
+void logger4(char *tag, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4);
+void logger5(char *tag, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5);
+void logger6(char *tag, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5, uint32_t arg6);
+
+typedef nx_struct logger_msg {
+ nx_uint32_t timestamp;
+ nx_uint32_t seqno;
+ nx_uint8_t tag[12];
+ nx_uint32_t args[0];
+} logger_msg_t;
+
+#endif
diff --git a/tos/platforms/telosa/GlobalsC.nc b/tos/platforms/telosa/GlobalsC.nc
new file mode 100644
index 0000000..911ec22
--- /dev/null
+++ b/tos/platforms/telosa/GlobalsC.nc
@@ -0,0 +1,13 @@
+configuration GlobalsC { }
+
+implementation
+{
+ components GlobalsP;
+ components new CounterToLocalTimeC(T32khz);
+ components new TransformCounterC(T32khz, uint32_t, T32khz, uint16_t, 0, uint32_t) as Transform;
+ components Msp430Counter32khzC;
+
+ CounterToLocalTimeC.Counter -> Transform;
+ Transform.CounterFrom -> Msp430Counter32khzC;
+ GlobalsP.LocalTime -> CounterToLocalTimeC;
+}
diff --git a/tos/platforms/telosa/GlobalsP.nc b/tos/platforms/telosa/GlobalsP.nc
new file mode 100644
index 0000000..1512175
--- /dev/null
+++ b/tos/platforms/telosa/GlobalsP.nc
@@ -0,0 +1,11 @@
+#include "Globals.h"
+
+module GlobalsP
+{
+ uses interface LocalTime<T32khz> as LocalTime;
+}
+
+implementation
+{
+ uint32_t getLocalTime() @C() { return call LocalTime.get(); }
+}
diff --git a/tos/types/Globals.h b/tos/types/Globals.h
new file mode 100644
index 0000000..e684366
--- /dev/null
+++ b/tos/types/Globals.h
@@ -0,0 +1,6 @@
+#ifndef GLOBALS_H
+#define GLOBALS_H
+
+uint32_t getLocalTime();
+
+#endif
diff --git a/tos/types/logger.h b/tos/types/logger.h
new file mode 100644
index 0000000..9f788fe
--- /dev/null
+++ b/tos/types/logger.h
@@ -0,0 +1,12 @@
+#ifndef LOGGER_H
+#define LOGGER_H
+
+#define logger(tag)
+#define logger1(tag, arg1)
+#define logger2(tag, arg1, arg2)
+#define logger3(tag, arg1, arg2, arg3)
+#define logger4(tag, arg1, arg2, arg3, arg4)
+#define logger5(tag, arg1, arg2, arg3, arg4, arg5)
+#define logger6(tag, arg1, arg2, arg3, arg4, arg5, arg6)
+
+#endif
More information about the net2-wg
mailing list