[Avrora] [Avrora 1.7.x] About c-print monitor-------Important

rodolfo de paz rodolfo.depaz at cit.ie
Tue Mar 31 11:13:14 PDT 2009


Hi,

I have uploaded the c code I have been using for the c-print monitor. If you update from cvs the file will be at:

avrora/src/avrora/monitors/AvroraPrint.h

With this code you do not even have to include the -VariableName option since by default Avrora looks for debugbuf1 which is the variable use here. I explained how to use it inside the file. I hope this is useful for all the people is asking how to use c-print. 

Please give me some feedback if you try it. You can see below the copy of the file.

cheers,
Rodolfo

/*
 * Copyright (c) 2009 Cork Institute of Technology, Ireland
 * 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 CORK INSTITUTE OF TECHNOLOGY 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
 * CORK INSTITUTE OF TECHNOLOGY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 * 
 * THE CORK INSTITUTE OF TECHNOLOGY 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 CORK INSTITUTE OF TECHNOLOGY HAS NO OBLIGATION 
 * TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 */                   

/* AvroraPrint.h
 *
 * This is the C code to print variables to the Avrora emulator
 *
 * How to use:
 *   (1) Include this file "AvroraPrintf.h" in your WSN application 
 *   (2) Send print statements like this:
 *	  
 *	  printChar('a');
 *
 *	  printInt8(44);
 *	  printInt16(3333);
 *	  printInt32(55556666);
 *
 *	  printStr("hello world");
 *
 *	  printHex8(0xFF);
 *        printHex16(0xFFFF);
 *	  printHex32(0xFFFFAAAA);
 *
 *	 (3) Compile and run the code with Avrora including the c-print option.
 *
 * Known bugs/limitations:
 *
 * 	 - If you include many print statements the emulator will slow down 
 * 	 - Print statements in arrow, without any operation in the middle, will 
 * 	 only print the last statement. I think this is because the memory location 
 * 	 is re-written before printing the value in Avrora. 	 
 * 
 * Notes:	 
 * 	
 * 	 - You can log the print statements to a file including the avrora
 * 	 option printlogfile="logfile.log". The saved file will be in the format
 * 	 logfile.log+nodeid 
 *
 *
 * @author AWS / Rodolfo De Paz http://www.aws.cit.ie/rodolfo
 * @contact avrora at lists.ucla.edu
 */
#define DEBUGBUF_SIZE 64
#include <stdarg.h>
char debugbuf1[DEBUGBUF_SIZE+1];
char *debugbuf;

#define printChar(__char) {	\
	init();	\
	debugbuf[0] = __char;	\
	debugbuf[1] = 0;		\
	vartype(2);	\
}
#define printInt8(__char) {	\
	init(); \
	debugbuf[0] = __char;	\
	debugbuf[1] = 0;		\
	vartype(3);			\
}
#define printInt16(__int) {	\
	init(); \
	debugbuf[0] = (uint8_t)(uint16_t)__int&0x00ff;	\
	debugbuf[1] = (uint8_t)((uint16_t)__int>>8)&0x00ff;		\
	vartype(3);		\
}
#define printInt32(__int) {	\
	init();\
	debugbuf[0] = (uint8_t)((uint32_t)__int)&0x00ff;	\
	debugbuf[1] = (uint8_t)((uint32_t)__int>>8)&0x00ff;	\
	debugbuf[2] = (uint8_t)((uint32_t)__int>>16)&0x00ff;	\
	debugbuf[3] = (uint8_t)((uint32_t)__int>>24)&0x00ff;	\
	vartype(5);		\
}
#define printStr(__str) { \
	init();	\
	strcpy(debugbuf, __str);	\
	vartype(2);	\
}
#define printHex8(__char) { \
	init(); \
	debugbuf[0] = __char;   \
	debugbuf[1] = 0;        \
	vartype(1);		\
}
#define printHex16(__int) { \
	init(); \
	debugbuf[0] = __int&0x00ff; \
	debugbuf[1] = (__int>>8)&0x00ff;     \
	vartype(1);		\
}
#define printHex32(__int) { \
	init();\
	debugbuf[0] = (uint8_t)((uint32_t)__int)&0x00ff; \
	debugbuf[1] = (uint8_t)((uint32_t)__int>>8)&0x00ff;    \
	debugbuf[2] = (uint8_t)((uint32_t)__int>>16)&0x00ff;   \
	debugbuf[3] = (uint8_t)((uint32_t)__int>>24)&0x00ff;   \
	vartype(4);	\
}
void init(){
	debugbuf = &debugbuf1[1];
}
void vartype(uint8_t a)
{
	debugbuf1[0] = a;
}



-----Original Message-----
From: avrora-bounces at lists.ucla.edu on behalf of John Regehr
Sent: Mon 30/03/2009 03:57
To: Mailing list for Avrora simulator users and developers.
Subject: Re: [Avrora] [Avrora 1.7.x] About c-print monitor-------Important
 
Below is some code that used to drive the print monitor.  However I just 
glanced at the code and Rodolfo has made some changes, so perhaps this no 
longer works.  Anyway, it should be a reasonable starting point.  If 
anyone wants to clean this up and document it a bit, I'd be happy to 
commit it into Avrora somewhere.

John Regehr


#include <stdint.h>
#include <string.h>

#define PRINT_BASE 4302
#define PRINT_MAX  50

static inline void avrora_print_hex_int16 (int16_t val)
{
   *((volatile unsigned char *)PRINT_BASE+2) = val & 0xff;
   *((volatile unsigned char *)PRINT_BASE+3) = (val >> 8) & 0xff;
   *((volatile unsigned char *)PRINT_BASE+0) = 0x1;
}

static inline void avrora_print_decimal_int16 (int16_t val)
{
   *((volatile unsigned char *)PRINT_BASE+2) = val & 0xff;
   *((volatile unsigned char *)PRINT_BASE+3) = (val >> 8) & 0xff;
   *((volatile unsigned char *)PRINT_BASE+0) = 0x3;
}

static inline void avrora_print_str (char *str)
{
   strncpy ((unsigned char *)PRINT_BASE+1, str, PRINT_MAX);
   *((volatile unsigned char *)PRINT_BASE) = 0x2;
}
_______________________________________________
Avrora mailing list
Avrora at lists.ucla.edu
http://lists.ucla.edu/cgi-bin/mailman/listinfo/avrora

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ucla.edu/pipermail/avrora/attachments/20090331/1e0a50e6/attachment.htm>


More information about the Avrora mailing list