]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Small changes to the application to make it line up with the newly created tutorial...
authorklueska <klueska>
Mon, 20 Aug 2007 06:08:29 +0000 (06:08 +0000)
committerklueska <klueska>
Mon, 20 Aug 2007 06:08:29 +0000 (06:08 +0000)
apps/tests/TestPrintf/Makefile
apps/tests/TestPrintf/TestPrintfC.nc
tos/lib/printf/PrintfC.nc
tos/lib/printf/PrintfP.nc

index eb460329a4c38c2536a70c9a576be0ced8f8f5b1..a3b9020dba4697a8c746ae1684897f21190babce 100644 (file)
@@ -7,7 +7,8 @@ BUILD_EXTRA_DEPS += PrintfMsg.class PrintfClient.class
        javac $<
 
 PrintfMsg.java: $(TOSDIR)/lib/printf/printf.h
-       mig java -target=$(PLATFORM) $(CFLAGS) -java-classname=PrintfMsg $(TOSDIR)/lib/printf/printf.h printf_msg -o $@
+       mig java -target=$(PLATFORM) $(CFLAGS) \
+               -java-classname=PrintfMsg \
+               $(TOSDIR)/lib/printf/printf.h printf_msg -o $@
 
 include $(MAKERULES)
-
index c9b0716076f99eaa0b08c87e388f54f4def5db75..47fe191bed1fb170210cb9262f2831b8573d07ec 100644 (file)
@@ -34,6 +34,7 @@
  * @date $Date$
  */
 
+#include "printf.h"
 module TestPrintfC {
   uses {
     interface Boot;  
@@ -44,24 +45,27 @@ module TestPrintfC {
 }
 implementation {
        
-  #define NUM_TIMES_TO_PRINT   100
+  #define NUM_TIMES_TO_PRINT   5
   uint16_t counter=0;
-  uint32_t dummyVar = 345678;
+  uint8_t dummyVar1 = 123;
+  uint16_t dummyVar2 = 12345;
+  uint32_t dummyVar3 = 1234567890;
 
   event void Boot.booted() {
     call PrintfControl.start();
   }
   
   event void PrintfControl.startDone(error_t error) {
-       printf("Hi my name is Kevin Klues and I am writing to you from my telos mote\n");
-       printf("Here is a uint8: %hd\n", 123);
-       printf("Here is a uint16: %d\n", 12345);
-       printf("Here is a uint32: %ld\n", 1234567890);
+       printf("Hi I am writing to you from my TinyOS application!!\n");
+       printf("Here is a uint8: %u\n", dummyVar1);
+       printf("Here is a uint16: %u\n", dummyVar2);
+       printf("Here is a uint32: %ld\n", dummyVar3);
        call PrintfFlush.flush();
   }
 
   event void PrintfControl.stopDone(error_t error) {
        counter = 0;
+    call Leds.led2Toggle();
        printf("This should not be printed...");
        call PrintfFlush.flush();
   }
@@ -73,8 +77,8 @@ implementation {
     }
     else if(counter == NUM_TIMES_TO_PRINT) {
       printf("This is a really short string...\n");
-      printf("I am generating this string to have just less than 250 characters since that is the limit of the size I put on my maximum buffer when I instantiated the PrintfC component.\n");
-      printf("Only part of this line should get printed because by writing this sentence, I go over my character limit that the internal Printf buffer can hold.  If I were to flush before trying to write this, or increase my buffer size when I instantiate my PrintfC component to 1000, we would see this line too\n");
+      printf("I am generating this string to have just less than 250\ncharacters since that is the limit of the size I put on my\nmaximum buffer when I instantiated the PrintfC component.\n");
+      printf("Only part of this line should get printed because by writing\nthis sentence, I go over my character limit that the internal Printf buffer can hold.\n");
       call PrintfFlush.flush();
     }
     else call PrintfControl.stop();
index bd1ec635b890fce1ea16ce201b9ea82d35b386fd..a9a8b7383dcf87eb90a03ceecdc2b74eb9cc4371 100644 (file)
@@ -51,12 +51,10 @@ implementation {
   components SerialActiveMessageC;
   components new SerialAMSenderC(AM_PRINTF_MSG);
   components PrintfP;
-  components LedsC;
 
   PrintfControl = PrintfP;
   PrintfFlush = PrintfP;
   
-  PrintfP.Leds -> LedsC;
   PrintfP.SerialControl -> SerialActiveMessageC;
   PrintfP.AMSend -> SerialAMSenderC;
   PrintfP.Packet -> SerialAMSenderC;
index c0b522a9ebff35c94d064158055299dbda1354ba..deda30c69a9a18d2e5a6dd38a4456bf5e8819831 100644 (file)
@@ -57,18 +57,17 @@ module PrintfP {
     interface PrintfFlush;
   }
   uses {
-       interface SplitControl as SerialControl;
-    interface Leds;
+    interface SplitControl as SerialControl;
     interface AMSend;
     interface Packet;
   }
 }
 implementation {
-       
+  
   enum {
-       S_STARTED,
-       S_STOPPED,
-       S_FLUSHING,
+    S_STARTED,
+    S_STOPPED,
+    S_FLUSHING,
   };
   
   message_t printfMsg;
@@ -86,7 +85,7 @@ implementation {
   void sendNext() {
     printf_msg_t* m = (printf_msg_t*)call Packet.getPayload(&printfMsg, NULL);
     length_to_send = (bytes_left_to_flush < sizeof(printf_msg_t)) ? bytes_left_to_flush : sizeof(printf_msg_t);
-    memset(m->buffer, 0, sizeof(m->buffer));
+    memset(m->buffer, 0, sizeof(printf_msg_t));
     memcpy(m->buffer, (uint8_t*)next_byte, length_to_send);
     if(call AMSend.send(AM_BROADCAST_ADDR, &printfMsg, sizeof(printf_msg_t)) != SUCCESS)
       post retrySend();  
@@ -97,24 +96,24 @@ implementation {
   }
 
   command error_t PrintfControl.start() {
-       if(state == S_STOPPED)
+    if(state == S_STOPPED)
       return call SerialControl.start();
     return FAIL;
   }
   
   command error_t PrintfControl.stop() {
-       if(state == S_STARTED)
+    if(state == S_STARTED)
       return call SerialControl.stop();
     return FAIL;
   }
 
   event void SerialControl.startDone(error_t error) {
-       if(error != SUCCESS) {
-         signal PrintfControl.startDone(error);
-         return;
-       }
+    if(error != SUCCESS) {
+      signal PrintfControl.startDone(error);
+      return;
+    }
 #ifdef _H_atmega128hardware_H
-       stdout = &atm128_stdout;
+    stdout = &atm128_stdout;
 #endif
     atomic {
       memset(buffer, 0, sizeof(buffer));
@@ -127,40 +126,40 @@ implementation {
   }
 
   event void SerialControl.stopDone(error_t error) {
-       if(error != SUCCESS) {
-         signal PrintfControl.stopDone(error);
-         return;
-       }
+    if(error != SUCCESS) {
+      signal PrintfControl.stopDone(error);
+      return;
+    }
     atomic state = S_STOPPED;
     signal PrintfControl.stopDone(error); 
   }
   
   command error_t PrintfFlush.flush() {
-       atomic {
-         if(state == S_STARTED && (next_byte > buffer)) {
-           state = S_FLUSHING;
-            bytes_left_to_flush = next_byte - buffer;
-           next_byte = buffer;
-         }
-         else return FAIL;
-       }
-       sendNext();
-       return SUCCESS;
+    atomic {
+      if(state == S_STARTED && (next_byte > buffer)) {
+        state = S_FLUSHING;
+        bytes_left_to_flush = next_byte - buffer;
+        next_byte = buffer;
+      }
+      else return FAIL;
+    }
+    sendNext();
+    return SUCCESS;
   }
     
   event void AMSend.sendDone(message_t* msg, error_t error) {    
-       if(error == SUCCESS) {
-         if(bytes_left_to_flush > 0)
-           sendNext();
-         else {
+    if(error == SUCCESS) {
+      if(bytes_left_to_flush > 0)
+        sendNext();
+      else {
         next_byte = buffer;
         bytes_left_to_flush = 0; 
-       length_to_send = 0;
+        length_to_send = 0;
         atomic state = S_STARTED;
-           signal PrintfFlush.flushDone(error);
-         }
-       }
-       else post retrySend();
+      signal PrintfFlush.flushDone(error);
+    }
+  }
+  else post retrySend();
   }
   
 #ifdef _H_msp430hardware_h
@@ -169,13 +168,12 @@ implementation {
 #ifdef _H_atmega128hardware_H
   int uart_putchar(char c, FILE *stream) __attribute__((noinline)) @C() @spontaneous() {
 #endif
-       atomic {
-         if(state == S_STARTED && ((next_byte-buffer+1) < PRINTF_BUFFER_SIZE)) {
-           *next_byte = c;
-           next_byte++;
-           return 0;
-         }
-         else return -1;
-       }
+    atomic {
+      if(state == S_STARTED && ((next_byte-buffer) < PRINTF_BUFFER_SIZE)) {
+        *(next_byte++) = c;
+        return 0;
+      }
+      else return -1;
+    }
   }
 }