From 4fa7c680295a8cc10c5dcfa07447880a47961b9e Mon Sep 17 00:00:00 2001 From: klueska Date: Mon, 20 Aug 2007 06:08:29 +0000 Subject: [PATCH] Small changes to the application to make it line up with the newly created tutorial on using printf --- apps/tests/TestPrintf/Makefile | 5 +- apps/tests/TestPrintf/TestPrintfC.nc | 20 ++++--- tos/lib/printf/PrintfC.nc | 2 - tos/lib/printf/PrintfP.nc | 88 ++++++++++++++-------------- 4 files changed, 58 insertions(+), 57 deletions(-) diff --git a/apps/tests/TestPrintf/Makefile b/apps/tests/TestPrintf/Makefile index eb460329..a3b9020d 100644 --- a/apps/tests/TestPrintf/Makefile +++ b/apps/tests/TestPrintf/Makefile @@ -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) - diff --git a/apps/tests/TestPrintf/TestPrintfC.nc b/apps/tests/TestPrintf/TestPrintfC.nc index c9b07160..47fe191b 100644 --- a/apps/tests/TestPrintf/TestPrintfC.nc +++ b/apps/tests/TestPrintf/TestPrintfC.nc @@ -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(); diff --git a/tos/lib/printf/PrintfC.nc b/tos/lib/printf/PrintfC.nc index bd1ec635..a9a8b738 100644 --- a/tos/lib/printf/PrintfC.nc +++ b/tos/lib/printf/PrintfC.nc @@ -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; diff --git a/tos/lib/printf/PrintfP.nc b/tos/lib/printf/PrintfP.nc index c0b522a9..deda30c6 100644 --- a/tos/lib/printf/PrintfP.nc +++ b/tos/lib/printf/PrintfP.nc @@ -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; + } } } -- 2.39.2