Thread: [Firebug-cvs] fireboard/tools/src/xlisten Makefile, 1.1, 1.2 genc.pm, 1.4, 1.5 xlisten.c, 1.2, 1.3
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2006-07-10 17:18:18
|
Update of /cvsroot/firebug/fireboard/tools/src/xlisten In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv20227 Modified Files: Makefile genc.pm xlisten.c xpacket.c xsensors.h xserial.c Log Message: updating from beta. Index: xsensors.h =================================================================== RCS file: /cvsroot/firebug/fireboard/tools/src/xlisten/xsensors.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** xsensors.h 4 Aug 2004 01:56:13 -0000 1.2 --- xsensors.h 10 Jul 2006 17:18:15 -0000 1.3 *************** *** 15,18 **** --- 15,34 ---- #include <stdio.h> + #include <stdlib.h> + #include <string.h> + #include <unistd.h> + + #ifdef __arm__ + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + #endif + + #include "xdb.h" + #include "xconvert.h" + + #include "../../../fireworks/apps/TestLink/LinkMsg.h" + //#include "MultihopLinkEstimator.h" + /** *************** *** 28,31 **** --- 44,50 ---- */ typedef enum { + // surge packet + XTYPE_SURGE = 0x00, + // mica2dot sensorboards XTYPE_MDA500 = 0x01, *************** *** 33,36 **** --- 52,60 ---- XTYPE_MEP500, + // mote boards + XTYPE_MICA2 = 0x60, + XTYPE_MICA2DOT, + XTYPE_MICAZ, + // mica2 sensorboards XTYPE_MDA400 = 0x80, *************** *** 42,47 **** --- 66,89 ---- XTYPE_MTS420, XTYPE_MEP401, + XTYPE_XTUTORIAL = 0x88, + XTYPE_GGBACLTST, + + //XTYPE_TESTLINK = 0xfb, + // mica2 integrated boards + XTYPE_MSP410 = 0xA0, + } XbowSensorboardType; + typedef enum { + AMTYPE_XUART = 0x00, + AMTYPE_HEALTH = 0x03, + AMTYPE_SURGE_MSG = 0x11, + AMTYPE_XDEBUG = 0x31, + AMTYPE_XSENSOR = 0x32, + AMTYPE_XMULTIHOP = 0x33, + AMTYPE_MHOP_MSG = 0xFA, + //AMTYPE_FIREWORKS = 0xC7 + } XbowAMType; + /** * Reserves general packet types that xlisten handles for all sensorboards. *************** *** 51,54 **** --- 93,101 ---- typedef enum { // reserved packet ids + // reserved packet ids + XPACKET_ACK = 0x40, + XPACKET_W_ACK = 0x41, + XPACKET_NO_ACK = 0x42, + XPACKET_ESC = 0x7D, //!< Reserved for serial packetizer escape code. XPACKET_START = 0x7E, //!< Reserved for serial packetizer start code. *************** *** 58,83 **** /** Encodes sensor readings into the data payload of a TOS message. */ typedef struct { ! uint8_t sensorboard_id; ! uint8_t packet_id; ! uint8_t node_id; ! uint8_t reserved; ! uint16_t data[12]; ! uint8_t reserved2; } XbowSensorboardPacket; ! #define XPACKET_SIZE 36 #define XPACKET_GROUP 3 //!< offset to group id of TOS packet #define XPACKET_LENGTH 4 //!< offset to length of TOS packet ! #define XPACKET_DATASTART 5 //!< UART offset to data payload ! #define XPACKET_DATASTART_WIRELESS 5 //!< Wireless offset to data payload #define XPACKET_DATASTART_MULTIHOP 12 //!< Multihop offset to data payload /* Sensorboard data packet definitions */ ! void xpacket_print_raw (unsigned char *tos_packet); void xpacket_print_parsed (unsigned char *tos_packet); void xpacket_print_cooked (unsigned char *tos_packet); void xpacket_export_parsed (unsigned char *tos_packet); ! void xpacket_depacketize (unsigned char *tos_packet); void xpacket_set_start (unsigned offset); /* Serial port routines. */ --- 105,188 ---- /** Encodes sensor readings into the data payload of a TOS message. */ typedef struct { ! uint8_t board_id; //!< Unique sensorboard id ! uint8_t packet_id; //!< Unique packet type for sensorboard ! uint8_t node_id; //!< Id of originating node ! uint8_t parent; //!< Id of node's parent ! uint16_t data[12]; //!< Data payload defaults to 24 bytes ! uint8_t terminator; //!< Reserved for null terminator } XbowSensorboardPacket; ! ! #define XPACKET_MIN_SIZE 4 //!< minimum valid packet size ! ! ! #ifdef TELOS_MOTE ! #define XPACKET_TYPE 8 //!< telos offset to type of TOS packet ! #else ! #define XPACKET_TYPE 2 //!< mica2 offset to type of TOS packet ! #endif ! #define XPACKET_GROUP 3 //!< offset to group id of TOS packet #define XPACKET_LENGTH 4 //!< offset to length of TOS packet ! ! #define XPACKET_DATASTART_STANDARD 5 //!< Standard offset to data payload #define XPACKET_DATASTART_MULTIHOP 12 //!< Multihop offset to data payload + #define XPACKET_DATASTART 12 //!< Default offset to data payload + //#define XPACKET_DATASTART_FIREWORKS 10 //!< Offset to Fireworks data + //#define XPACKET_DATASTART_LINKEST 18 //!< Offset to Fireworks data + + #define XPACKET_BOARD_TABLE 0 //!< offset to XSensor board table + #define XPACKET_AM_TABLE 256 //!< offset to AM lookup table + + enum { + XPACKET_DECODE_MODE_AUTO = 0, + XPACKET_DECODE_MODE_FRAMED, + XPACKET_DECODE_MODE_UNFRAMED + }; + + // Much easier to change arguments. + typedef void (*PacketPrinter)(XbowSensorboardPacket *packet); + + typedef union XBoardFlags { + unsigned flat; + struct { + unsigned table_init : 1; //!< whether logging table is validated + }; + } XBoardFlags; + + typedef struct XPacketHandler { + uint8_t type; //!< sensorboard id + char * version; //!< CVS version string of boards source file + + PacketPrinter print_parsed; + PacketPrinter print_cooked; + PacketPrinter export_parsed; + PacketPrinter export_cooked; + PacketPrinter log_cooked; + + XBoardFlags flags; //!< flags for board specific management + } XPacketHandler; + + /* Linkage to main */ + int xmain_get_verbose (); /* Sensorboard data packet definitions */ ! void xpacket_print_raw (unsigned char *tos_packet, int len); ! void xpacket_print_ascii (unsigned char *tos_packet, int len); void xpacket_print_parsed (unsigned char *tos_packet); void xpacket_print_cooked (unsigned char *tos_packet); void xpacket_export_parsed (unsigned char *tos_packet); ! void xpacket_export_cooked (unsigned char *tos_packet); ! void xpacket_log_cooked (unsigned char *tos_packet); ! ! void xpacket_initialize (); ! void xpacket_decode (unsigned char *tos_packet, int len, int mode); ! void xpacket_add_type (XPacketHandler *handler); ! void xpacket_add_amtype (XPacketHandler *handler); ! void xpacket_print_output (unsigned out_flags, unsigned char *tos_packet); ! void xpacket_print_time (); ! void xpacket_print_versions(); void xpacket_set_start (unsigned offset); + int xpacket_get_start (); /* Serial port routines. */ *************** *** 85,134 **** int xserial_port_dump (); int xserial_port_sync_packet (int serline); ! int xserial_port_read_packet (int serline, unsigned char *buffer, int cnt); unsigned xserial_set_baudrate (unsigned baudrate); unsigned xserial_set_baud (const char *baud); void xserial_set_device (const char *device); - void xserial_set_verbose (int verbose); ! /* Sensorboard specific conversion routines. */ ! /* From boards/mda500.c */ ! void mda500_print_raw (XbowSensorboardPacket *packet); ! void mda500_print_cooked (XbowSensorboardPacket *packet); ! void mda400_print_raw (XbowSensorboardPacket *packet); ! void mda400_print_cooked (XbowSensorboardPacket *packet); ! /* From boards/mda300.c */ ! void mda300_print_raw (XbowSensorboardPacket *packet); ! void mda300_print_cooked (XbowSensorboardPacket *packet); ! /* From boards/mts300.c */ ! void mts300_print_raw (XbowSensorboardPacket *packet); ! void mts300_print_cooked (XbowSensorboardPacket *packet); ! void mts310_print_raw (XbowSensorboardPacket *packet); ! void mts310_print_cooked (XbowSensorboardPacket *packet); ! /* From boards/mts400.c */ ! void mts400_print_raw (XbowSensorboardPacket *packet); ! void mts400_print_cooked (XbowSensorboardPacket *packet); ! void mts420_print_raw (XbowSensorboardPacket *packet); ! void mts420_print_cooked (XbowSensorboardPacket *packet); ! /* From boards/mts510.c */ ! void mts510_print_raw (XbowSensorboardPacket *packet); ! void mts510_print_cooked (XbowSensorboardPacket *packet); ! /* From boards/mts101.c */ ! void mts101_print_raw (XbowSensorboardPacket *packet); ! void mts101_print_cooked (XbowSensorboardPacket *packet); ! /* From boards/mep500.c */ ! void mep500_print_raw (XbowSensorboardPacket *packet); ! void mep500_print_cooked (XbowSensorboardPacket *packet); ! /* From boards/mep401.c */ ! void mep401_print_raw (XbowSensorboardPacket *packet); ! void mep401_print_cooked (XbowSensorboardPacket *packet); #endif /* __SENSORS_H__ */ --- 190,237 ---- int xserial_port_dump (); int xserial_port_sync_packet (int serline); ! int xserial_port_read_packet (int serline, unsigned char *buffer); unsigned xserial_set_baudrate (unsigned baudrate); unsigned xserial_set_baud (const char *baud); void xserial_set_device (const char *device); ! /* Socket routines. */ ! int xsocket_port_open (); ! void xsocket_set_port (const char *port); ! unsigned xsocket_get_port (); ! void xsocket_set_server (const char *server); ! const char * xsocket_get_server (); ! int xsocket_read_packet (int serline, unsigned char *buffer); ! void mica2_initialize(); /* From boards/mica2.c */ ! void mica2dot_initialize(); /* From boards/mica2dot.c */ ! void micaz_initialize(); /* From boards/micaz.c */ ! /* Sensorboard specific conversion routines. */ ! void mda300_initialize(); /* From boards/mda300.c */ ! void mda400_initialize(); /* From boards/mda500.c */ ! void mda500_initialize(); /* From boards/mda500.c */ ! void mts300_initialize(); /* From boards/mts300.c */ ! void mts310_initialize(); /* From boards/mts300.c */ ! void mts400_initialize(); /* From boards/mts400.c */ ! void mts420_initialize(); /* From boards/mts400.c */ ! void fireboard_initialize(); /* From boards/mts400.c */ ! void mts510_initialize(); /* From boards/mts510.c */ ! void mts101_initialize(); /* From boards/mts101.c */ ! void mep500_initialize(); /* From boards/mep500.c */ ! void mep401_initialize(); /* From boards/mep401.c */ ! void ggbacltst_initialize(); /* From boards/ggbacltst.c */ ! void msp410_initialize(); /* From boards/msp410.c */ ! void surge_initialize(); /* From boards/surge.c */ ! void health_initialize(); /* From amtypes/health.c */ + void xtutorial_initialize(); /* From baords/xtutorial.c */ + + void ucb_initialize(); #endif /* __SENSORS_H__ */ Index: Makefile =================================================================== RCS file: /cvsroot/firebug/fireboard/tools/src/xlisten/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile 15 Jul 2004 17:03:39 -0000 1.1 --- Makefile 10 Jul 2006 17:18:15 -0000 1.2 *************** *** 1,21 **** ! CFLAGS = -Wall -O2 -Wno-format ! all: xlisten # Main xlisten sources ! SRCS = xlisten.c xserial.c xpacket.c # Add Mote Sensor board support SRCS += boards/mts300.c boards/mts400.c boards/mts510.c boards/mts101.c ! SRCS += boards/mep500.c boards/mep401.c timestamp.c # Add Mote Data Aquisition board support SRCS += boards/mda500.c boards/mda300.c xlisten: $(SRCS) ! gcc $(CFLAGS) -o $@ $(SRCS) ! clean: ! rm -rf *~ *.o *.exe *.stackdump --- 1,61 ---- ! # Makefile for xlisten # $Id$ ! CC = gcc ! ARMCC = arm-linux-gcc ! INCDIR = /usr/local/arm/3.4.1/pgsql/include ! LIBDIR = /usr/local/arm/3.4.1/pgsql/lib ! LFLAGS = -lpq -lm ! CFLAGS = -O2 -Wall -Wno-format # Main xlisten sources ! SRCS = xpacket.c xconvert.c xdb.c ! SRCS += xserial.c xsocket.c args.c # Add Mote Sensor board support SRCS += boards/mts300.c boards/mts400.c boards/mts510.c boards/mts101.c ! SRCS += boards/mep500.c boards/mep401.c boards/ggbacltst.c ! SRCS += boards/mica2.c boards/mica2dot.c boards/micaz.c boards/fireboard.c ! SRCS += boards/pg_test.c ! SRCS += boards/linkmsg.c #boards/testlink.c ! SRCS += boards/sirf_id2_1.c boards/sirf_id2_2.c ! SRCS += boards/sirf_id28_1.c boards/sirf_id28_2.c boards/sirf_id28_3.c ! SRCS += boards/LinkEstimatorMsg.c ! SRCS += boards/SurgeMsg.c ! ! SRCS += ucb/ucb.c ! ! INCLUDES = -I../../../tos/sensorboards/mts400/GPS ! INCLUDES += -I../../../apps/XSensorMTS400 ! INCLUDES += -I../../../fireworks/apps/MultihopLinkEstimator # Add Mote Data Aquisition board support SRCS += boards/mda500.c boards/mda300.c + # Add Mica2 integrated sensorboards + SRCS += boards/msp410.c + + # Add support for "virtual" board that XsensorTutorial + # uses during Training seminar + SRCS += boards/xtutorial.c + + # Add AM types + SRCS += amtypes/health.c amtypes/surge.c + + SRCS += timestamp/timestamp.c + + all: xlisten fbpacket xlisten-telos xlisten: $(SRCS) ! $(CC) $(CFLAGS) -o $@ xlisten.c $(SRCS) $(INCLUDES) $(LFLAGS) ! fbpacket: fbpacket.c ! $(CC) $(CFLAGS) -o $@ fbpacket.c $(SRCS) $(INCLUDES) $(LFLAGS) ! ! xlisten-telos: $(SRCS) ! $(CC) $(CFLAGS) -o $@ -DTELOS_MOTE xlisten.c $(SRCS) $(INCLUDES) $(LFLAGS) + xlisten-arm: $(SRCS) + $(ARMCC) -I$(INCDIR) $(INCLUDES) $(CFLAGS) -o $@ $(SRCS) -L$(LIBDIR) $(LFLAGS) + + clean: + rm -f *.o boards/*.o xlisten xlisten-arm xlisten.exe fbpacket.exe xlisten-telos.exe *~ *.bak Index: xlisten.c =================================================================== RCS file: /cvsroot/firebug/fireboard/tools/src/xlisten/xlisten.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** xlisten.c 4 Aug 2004 01:56:13 -0000 1.2 --- xlisten.c 10 Jul 2006 17:18:15 -0000 1.3 *************** *** 11,195 **** */ - #include <stdio.h> - #include <stdlib.h> - #include <signal.h> - #include <string.h> - #include "xsensors.h" ! #include "timestamp.h" ! ! ! FILE * logfile; ! char logfilename[256] = {0}; ! Timestamp * ts; const char *g_version = "$Id$"; - /** A structure to store parsed parameter flags. */ - typedef union { - unsigned flat; - - struct { - // output display options - unsigned display_raw : 1; //!< raw TOS packets - unsigned display_parsed : 1; //!< pull out sensor readings - unsigned display_cooked : 1; //!< convert to engineering units - unsigned export_parsed : 1; //!< output comma delimited fields - unsigned display_rsvd : 12; //!< pad first word for output options - - // modes of operation - unsigned display_help : 1; - unsigned display_baud : 1; //!< baud was set by user - unsigned mode_quiet : 1; //!< suppress headers - unsigned mode_wireless : 1; //!< use wireless network headers - unsigned mode_debug : 1; //!< debug serial port - } bits; - - struct { - unsigned short output; //!< must have at least one output option - unsigned short mode; - } options; - } s_params; - - /** A variable to store parsed parameter flags. */ - s_params g_params; - - - /** - * Shut down cleanly. - */ - void - catch_sigint(int signal) { - - if (logfile != NULL && logfile != stdout) { - fflush(logfile); - fclose(logfile); - } - exit(0); - } ! ! /** ! * Extracts command line options and sets flags internally. ! * ! * @param argc Argument count ! * @param argv Argument vector ! * ! * @author Martin Turon ! * ! * @version 2004/3/10 mturon Intial version ! * @n 2004/3/12 mturon Added -b,-s,-q,-x */ ! void parse_args(int argc, char **argv) ! { ! unsigned baudrate = 0; ! g_params.flat = 0; /* default to no params set */ ! ! while (argc) { ! if ((argv[argc]) && (*argv[argc] == '-')) { ! switch(argv[argc][1]) { ! case '?': ! g_params.bits.display_help = 1; ! break; ! ! case 'q': ! xserial_set_verbose(0); ! g_params.bits.mode_quiet = 1; ! break; ! ! case 'p': ! g_params.bits.display_parsed = 1; ! break; ! ! case 'r': ! g_params.bits.display_raw = 1; ! break; ! ! case 'c': ! g_params.bits.display_cooked = 1; ! break; ! ! case 'x': ! g_params.bits.export_parsed = 1; ! break; ! ! case 'w': ! g_params.bits.mode_wireless = 1; ! int offset = XPACKET_DATASTART_WIRELESS; ! if (argv[argc][2] == '=') ! offset = atoi(argv[argc]+3); ! xpacket_set_start(offset); ! break; ! ! case 'b': ! if (argv[argc][2] == '=') { ! baudrate = xserial_set_baud(argv[argc]+3); ! g_params.bits.display_baud = 1; ! } ! break; ! ! case 's': ! if (argv[argc][2] == '=') { ! xserial_set_device(argv[argc]+3); ! } ! break; ! ! case 'o': ! if (argv[argc][2] == '=') { ! strcpy(logfilename,argv[argc]+3); ! } ! break; ! ! case 'd': ! g_params.bits.mode_debug = 1; ! break; ! } ! } ! argc--; ! } ! ! if (!g_params.bits.mode_quiet) { ! // Summarize parameter settings ! printf("xlisten Ver:%s\n", g_version); ! printf("Using params: "); ! if (g_params.bits.display_help) printf("[help] "); ! if (g_params.bits.display_baud) printf("[baud=0x%04x] ", baudrate); ! if (g_params.bits.display_raw) printf("[raw] "); ! if (g_params.bits.display_parsed) printf("[parsed] "); ! if (g_params.bits.display_cooked) printf("[cooked] "); ! if (g_params.bits.export_parsed) printf("[export] "); ! if (g_params.bits.mode_wireless) printf("[wireless] "); ! if (g_params.bits.mode_debug) { ! printf("[debug - serial dump!] \n"); ! xserial_port_dump(); ! } ! printf("\n"); ! } - if (g_params.bits.display_help) { - printf( - "\nUsage: xlisten <-?|r|p|x|c|d|q> <-b=baud> <-s=device>" - "\n -? = display help [help]" - "\n -r = raw display of tos packets [raw]" - "\n -p = parse packet into raw sensor readings [parsed]" - "\n -x = export readings in csv spreadsheet format [export]" - "\n -c = convert data to engineering units [cooked]" - "\n -d = debug serial port by dumping bytes [debug]" - "\n -b = set the baudrate [baud=#|mica2|mica2dot]" - "\n -s = set serial port device [device=com1]" - "\n -w = read wireless network packets from TOSBase" - "\n -q = quiet mode (suppress headers)" - "\n" - ); - exit(0); - } ! /* Default to displaying packets as raw, parsed, and cooked. */ ! if (g_params.options.output == 0) { ! g_params.bits.display_raw = 1; ! g_params.bits.display_parsed = 1; ! g_params.bits.display_cooked = 1; ! } } --- 11,31 ---- */ #include "xsensors.h" ! #include "args.h" + /** It's OK to make this global. */ const char *g_version = "$Id$"; ! /** TODO: Set the name of the input stream in the argument ! * parsing code, but open it in main. */ ! int g_istream; //!< Handle of input stream ! int ! xmain_get_verbose(s_params * g_params) { ! return !g_params->bits.mode_quiet; } *************** *** 203,232 **** * @version 2004/3/10 mturon Intial version */ ! int main(int argc, char **argv) ! { ! parse_args(argc, argv); ! //char c; ! //int i, partial = 0; ! int serline; ! unsigned char buffer[64]; ! ts = timestamp_new(); ! if (*logfilename == 0) { ! logfile = stdout; } else { ! logfile = fopen(logfilename,"w"); } ! signal(SIGINT, catch_sigint); - serline = xserial_port_open(); while (1) { ! if (xserial_port_read_packet(serline, buffer, XPACKET_SIZE)) continue; // ignore patial packets and packetizer frame end ! //if (g_params.bits.display_raw) xpacket_print_raw(buffer); ! ! if (g_params.bits.mode_wireless) xpacket_depacketize(buffer); if (g_params.bits.display_parsed) xpacket_print_parsed(buffer); --- 39,86 ---- * @version 2004/3/10 mturon Intial version */ ! int ! main(int argc, char **argv) { ! int length; ! unsigned char buffer[255]; ! /* A variable to store parsed parameter flags. */ ! s_params g_params; ! parse_args(argc, argv, &g_params); ! /* Stream initialization */ ! // Set STDOUT and STDERR to be line buffered, so output is not delayed. ! setlinebuf(stdout); ! setlinebuf(stderr); ! if (g_params.bits.mode_socket) { ! g_istream = xsocket_port_open(); } else { ! g_istream = xserial_port_open(); } ! /* Each different sensor board has different packet ! * layouts, which are initialized in the following. ! */ ! xpacket_initialize(); while (1) { ! if (g_params.bits.mode_sf) { ! // Serial forwarder read ! length = xsocket_read_packet(g_istream, buffer); ! } else { ! // Serial read direct, or over socket (mib600) ! length = xserial_port_read_packet(g_istream, buffer); ! } ! ! if (length < XPACKET_MIN_SIZE) continue; // ignore patial packets and packetizer frame end ! if (g_params.bits.display_time) xpacket_print_time(); ! ! if (g_params.bits.display_raw) xpacket_print_raw(buffer, length); ! ! if (g_params.bits.display_ascii) xpacket_print_ascii(buffer, length); ! ! if (!g_params.bits.mode_sf) ! xpacket_decode(buffer, length, g_params.bits.mode_framing); if (g_params.bits.display_parsed) xpacket_print_parsed(buffer); *************** *** 234,240 **** if (g_params.bits.export_parsed) xpacket_export_parsed(buffer); if (g_params.bits.display_cooked) xpacket_print_cooked(buffer); - //if (g_params.bits.display_cooked) xpacket_print_tabbed(buffer); } } --- 88,99 ---- if (g_params.bits.export_parsed) xpacket_export_parsed(buffer); + if (g_params.bits.export_cooked) xpacket_export_cooked(buffer); + + if (g_params.bits.log_cooked) xpacket_log_cooked(buffer); + if (g_params.bits.display_cooked) xpacket_print_cooked(buffer); } + + } *************** *** 249,253 **** @section usage Usage ! Usage: xlisten <-?|r|p|x|c|d|q> <-b=baud> <-s=device> @n @n -? = display help [help] --- 108,112 ---- @section usage Usage ! Usage: xlisten <-?|r|p|c|x|l|d|v|q> <-b=baud> <-s=device> <-h=size> @n @n -? = display help [help] *************** *** 256,266 **** @n -x = export readings in csv spreadsheet format [export] @n -c = convert data to engineering units [cooked] @n -d = debug serial port by dumping bytes [debug] @n -b = set the baudrate [baud=#|mica2|mica2dot] @n -s = set serial port device [device=com1] ! @n -w = read wireless network packets from TOSBase @n -q = quiet mode (suppress headers) @n - @section params Parameters --- 115,130 ---- @n -x = export readings in csv spreadsheet format [export] @n -c = convert data to engineering units [cooked] + @n -t = display time packet was received [timed] + @n -a = ascii display of tos packets [ascii] + @n -l = log data to database [logged] @n -d = debug serial port by dumping bytes [debug] @n -b = set the baudrate [baud=#|mica2|mica2dot] @n -s = set serial port device [device=com1] ! @n -i = use socket input [inet=host:port] ! @n -sf = use serial forwarder input [inet=host:port] ! @n -h = specify size of TOS_msg header [header=size] ! @n -v = display complete version information for all modules [version] @n -q = quiet mode (suppress headers) @n @section params Parameters *************** *** 280,283 **** --- 144,153 ---- This flag gives the user the ability to specify which COM port or device xlisten should use. The default port is /dev/ttyS0 or the UNIX equivalent to COM1. The given port must be passed directly after the equals sign with no spaces, i.e. -s=com3. + @subsection internet -i=hostname:port [inet] + This flag tells xlisten to attach to a virtual serial connection over a TCP/IP internet socket. Specify the hostname and port to connect in the argument. The default hostname is localhost, and the default port 9001. The keyword 'mib600' can be passed as an alias to port 10002 when connecting to that hardware device. The hostname and port must be passed directly after the equals sign with no spaces with a optional colon inbetween, i.e. -i=remote, -i=10.1.1.1:9000, -i=mymib:mib600, -i=:9002, -i=localhost:9003, or -i=stargate.xbow.com. + + @subsection serial forwarder -sf=hostname:port [inet] + This flag tells xlisten to attach to a serial forwarder connection over a TCP/IP internet socket. The hostname and port arguments are the same as the -i flag. The -sf flag tells xlisten to specifically use the TinyOS serial forwarder protocol. + @subsection raw -r [raw] Raw mode displays the actual TOS packets as a sequence of bytes as seen coming over the serial line. Sample output follows: *************** *** 338,343 **** @n 6,194,516,413,335,288,301,287 ! @subsection wireless -w [wireless] ! Passing the wireless flag tells xlisten to use a different offset when parsing packets that are being forwarded by TOSBase. This flag is required to see parsed and cooked values from motes over a wireless network. @subsection debug -d [debug] --- 208,243 ---- @n 6,194,516,413,335,288,301,287 ! @subsection timed -t [timed] ! Displays the time at which the packet was received. ! ! @n $ xlisten -t ! @n [2004/09/29 10:24:29] ! @n [2004/09/29 10:36:57] ! ! @subsection ascii -a [ascii] ! Displays the raw packet contents as ASCII characters. ! ! @subsection logging -l [logged] ! Logs incoming readings to a Postgres database. Default connection settings are: server=localhost, port=5432, user=tele, pass=tiny. ! ! @subsection header -h=size [header] ! Passing the header flag tells xlisten to use a different offset when parsing packets that are being forwarded by TOSBase. Generally this flag is not required as xlisten autodetects the header size from the AM type. When this flag is passed all xlisten will assume all incoming packets have a data payload begining after the header size offset. ! ! @subsection versions -v [versions] ! Displays complete version information for all sensorboard decoding modules within xlisten. ! ! @n $ xlisten -v ! @n xlisten Ver: Id: xlisten.c,v 1.11 2004/08/04 21:06:41 mturon Exp ! @n 87: Id: mep401.c,v 1.10 2004/08/04 21:06:41 mturon Exp ! @n 86: Id: mts400.c,v 1.15 2004/08/04 21:06:41 husq Exp ! @n 85: Id: mts400.c,v 1.15 2004/08/04 21:06:41 mturon Exp ! @n 84: Id: mts300.c,v 1.14 2004/08/04 21:06:41 husq Exp ! @n 83: Id: mts300.c,v 1.14 2004/08/04 21:06:41 mturon Exp ! @n 82: Id: mts101.c,v 1.5 2004/08/04 21:06:41 husq Exp ! @n 81: Id: mda300.c,v 1.4 2004/08/04 17:15:22 jdprabhu Exp ! @n 80: Id: mda500.c,v 1.11 2004/08/04 21:06:41 husq Exp ! @n 03: Id: mep500.c,v 1.3 2004/08/04 21:06:41 mturon Exp ! @n 02: Id: mts510.c,v 1.6 2004/08/04 21:06:41 husq Exp ! @n 01: Id: mda500.c,v 1.11 2004/08/04 21:06:41 abroad Exp @subsection debug -d [debug] Index: xpacket.c =================================================================== RCS file: /cvsroot/firebug/fireboard/tools/src/xlisten/xpacket.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** xpacket.c 4 Aug 2004 01:56:13 -0000 1.5 --- xpacket.c 10 Jul 2006 17:18:15 -0000 1.6 *************** *** 12,18 **** --- 12,62 ---- #include "xsensors.h" + #include "xpacket.h" + + #include "ucb/ucb.h" static unsigned g_datastart = XPACKET_DATASTART; + static XPacketHandler *g_packetTable[512]; + + /** + * Adds all packet handlers for known sensorboards. + * + * @author Martin Turon + * @version 2004/7/28 mturon Intial version + */ + void xpacket_initialize() + { + health_initialize(); /* From amtypes/health.c */ + + mica2_initialize(); /* From boards/mica2.c */ + mica2dot_initialize(); /* From boards/mica2.c */ + micaz_initialize(); /* From boards/mica2.c */ + + surge_initialize(); /* From boards/surge.c */ + + mda300_initialize(); /* From boards/mda300.c */ + mda400_initialize(); /* From boards/mda500.c */ + mda500_initialize(); /* From boards/mda500.c */ + + mts300_initialize(); /* From boards/mts300.c */ + mts310_initialize(); /* From boards/mts300.c */ + + mts400_initialize(); /* From boards/mts400.c */ + //mts420_initialize(); /* From boards/mts400.c */ + + + mts510_initialize(); /* From boards/mts510.c */ + mts101_initialize(); /* From boards/mts101.c */ + mep500_initialize(); /* From boards/mep500.c */ + mep401_initialize(); /* From boards/mep401.c */ + ggbacltst_initialize(); /* From boards/ggbacltst.c */ + msp410_initialize(); /* From boards/msp410.c */ + + xtutorial_initialize(); /* From boards/xtutorial.c */ + + ucb_initialize(); + } + /** * Set the offset to the sensor data payload within the TOS packet. *************** *** 25,29 **** void xpacket_set_start(unsigned offset) { ! g_datastart = offset; } --- 69,78 ---- void xpacket_set_start(unsigned offset) { ! g_datastart = offset; ! } ! ! int xpacket_get_start() ! { ! return g_datastart; } *************** *** 34,51 **** * @version 2004/4/07 mturon Intial version */ ! void xpacket_depacketize(unsigned char *tos_packet) { ! int i = 0, o = 2; // index and offset ! while(i < XPACKET_SIZE) { ! // Handle escape characters ! if (tos_packet[o] == XPACKET_ESC) { ! tos_packet[i++] = tos_packet[++o] ^ 0x20; ! ++o; ! } else { ! tos_packet[i++] = tos_packet[o++]; ! } ! } } /** * Returns a pointer into the packet to the data payload. --- 83,136 ---- * @version 2004/4/07 mturon Intial version */ ! void xpacket_unframe(unsigned char *tos_packet, int len) { ! int i = 0, o = 2; // index and offset ! ! while(i < len) { ! // Handle escape characters ! if (tos_packet[o] == XPACKET_ESC) { ! tos_packet[i++] = tos_packet[++o] ^ 0x20; ! ++o; ! } else { ! tos_packet[i++] = tos_packet[o++]; ! } ! } ! } ! ! /** ! * Detects if incoming packet is UART framed and unframes if needed. ! * ! * @author Martin Turon ! * @version 2004/8/05 mturon Intial version ! */ ! void xpacket_decode(unsigned char *tos_packet, int len, int mode) ! { ! if (len < 2) return; ! ! switch (mode) { ! case 0: ! // Automatic detection of framing ! switch (tos_packet[1]) { ! // case AMTYPE_XUART: // temp hack for FEATURE_UART_DEBUG ! case XPACKET_ACK: ! case XPACKET_W_ACK: ! case XPACKET_NO_ACK: ! xpacket_unframe(tos_packet, len); ! break; ! } ! break; ! ! case 1: ! // Framed packet ! xpacket_unframe(tos_packet, len); ! break; ! ! default: ! // Unframed packet ! break; ! } } + /** * Returns a pointer into the packet to the data payload. *************** *** 58,230 **** XbowSensorboardPacket *xpacket_get_sensor_data(unsigned char *tos_packet) { ! return (XbowSensorboardPacket *)(tos_packet + g_datastart); } /** ! * Display a raw packet. * - * @param packet The TOS packet as raw bytes from the serial port - * * @author Martin Turon ! * @version 2004/3/10 mturon Intial version */ ! void xpacket_print_raw(unsigned char *packet) { ! int i, cnt = XPACKET_SIZE; ! for (i=0; i<cnt; i++) { ! printf("%02x", packet[i]); ! } ! printf("\n"); } /** ! * Display a parsed packet as exportable data -- comma delimited text. * - * @param packet The TOS packet as raw bytes from the serial port - * * @author Martin Turon ! * @version 2004/3/12 mturon Intial version */ ! void xpacket_export_parsed(unsigned char *tos_packet) { ! int i; ! uint16_t *packet = (uint16_t *)xpacket_get_sensor_data(tos_packet); ! packet += 2; // Ignore sensorboard_id and packet_id ! ! for (i=0; i<8; i++) { ! if (i>0) printf(","); ! printf("%d",packet[i]); ! } ! printf("\n"); } /** ! * Display a parsed packet as raw ADC values for each sensor on the board. * - * @param packet The TOS packet as raw bytes from the serial port - * * @author Martin Turon ! * @version 2004/3/10 mturon Intial version */ ! void xpacket_print_parsed(unsigned char *tos_packet) { ! XbowSensorboardPacket *packet = xpacket_get_sensor_data(tos_packet); ! ! switch(packet->packet_id) { ! case XPACKET_TEXT_MSG: ! packet->reserved2 = '\0'; ! printf("msg from id=%d: %s\n", packet->node_id, ! (char *)packet->data); ! return; ! } ! ! switch(packet->sensorboard_id) { ! case XTYPE_MDA500: ! mda500_print_raw(packet); ! break; ! ! case XTYPE_MDA400: ! mda400_print_raw(packet); ! break; ! ! case XTYPE_MDA300: ! mda300_print_raw(packet); ! break; ! ! case XTYPE_MTS300: ! mts300_print_raw(packet); ! break; ! ! case XTYPE_MTS310: ! mts310_print_raw(packet); ! break; ! case XTYPE_MTS400: ! mts400_print_raw(packet); ! break; ! case XTYPE_MTS420: ! mts420_print_raw(packet); ! break; - case XTYPE_MTS510: - mts510_print_raw(packet); - break; - - case XTYPE_MTS101: - mts101_print_raw(packet); - break; - - case XTYPE_MEP500: - mep500_print_raw(packet); - break; - - case XTYPE_MEP401: - mep401_print_raw(packet); - break; ! /* More sensor boards go here... */ ! } } ! // This typedef eventually gets moved to a header file. ! typedef struct _packetprinter Packetprinter; ! // Keep this as incomplete type to eliminate unnecessary ! // meddling. The definition can be expanded to ! // include more than cooked. Also, if the arguments change ! // to the print function, it's relatively easy to change. ! struct _packetprinter { ! unsigned int type; ! void (*print_cooked)(XbowSensorboardPacket * packet); ! }; ! // Add XTYPE and function for cooking up output anywhere ! // before the last {0,NULL} entry. You're done. ! Packetprinter packet_printer [] = { ! {XTYPE_MDA500,mda500_print_cooked}, ! {XTYPE_MDA400,mda400_print_cooked}, ! {XTYPE_MDA300,mda300_print_cooked}, ! {XTYPE_MTS300,mts300_print_cooked}, ! {XTYPE_MTS310,mts310_print_cooked}, ! {XTYPE_MTS400,mts400_print_cooked}, ! {XTYPE_MTS420,mts420_print_cooked}, ! {XTYPE_MTS510,mts510_print_cooked}, ! {XTYPE_MTS101,mts101_print_cooked}, ! {XTYPE_MEP500,mep500_print_cooked}, ! {XTYPE_MEP401,mep401_print_cooked}, ! {0 ,NULL} ! }; ! void xpacket_print_cooked_new(unsigned char *tos_packet) { ! XbowSensorboardPacket *packet = xpacket_get_sensor_data(tos_packet); ! unsigned int sensorboard_id = packet->sensorboard_id; ! int i = 0; ! ! switch(packet->packet_id) { ! case XPACKET_TEXT_MSG: ! packet->reserved2 = '\0'; ! printf("MSG from id=%d: %s\n\n", packet->node_id, ! (char*)packet->data); ! return; ! } ! ! // Since the array of printing functions is static ! // data declared above, the while loop has almost the ! // same overhead as the switchyard. ! while (packet_printer[i].type != 0) { ! if (packet_printer[i].type == sensorboard_id) { ! packet_printer[i].print_cooked(packet); ! return; ! } ! i++; ! } ! fprintf(stderr,"No print function defined for this sensor board.\n"); } --- 143,340 ---- XbowSensorboardPacket *xpacket_get_sensor_data(unsigned char *tos_packet) { ! int am_type = tos_packet[XPACKET_TYPE]; ! int datastart = g_datastart; ! ! if (datastart == XPACKET_DATASTART) { ! switch (am_type) { ! case AMTYPE_XUART: ! case AMTYPE_XSENSOR: ! case AMTYPE_SURGE_MSG: ! case AMTYPE_HEALTH: ! datastart = XPACKET_DATASTART_STANDARD; ! break; ! ! case AMTYPE_XDEBUG: ! case AMTYPE_XMULTIHOP: ! datastart = XPACKET_DATASTART_MULTIHOP; ! break; ! ! default: ! // Handle firebug AM_TYPES here? ! return NULL; ! } ! } ! ! return (XbowSensorboardPacket *)(tos_packet + datastart); } /** ! * Prints out standard packet types for all sensorboards. ! * @return true when packet is to be ignored * * @author Martin Turon ! * @version 2004/8/05 mturon Intial version */ ! int xpacket_print_common(XbowSensorboardPacket *packet) { ! if (!packet) return 1; ! ! switch(packet->packet_id) { ! case XPACKET_TEXT_MSG: ! packet->terminator = '\0'; ! printf("MSG from id=%d: %s\n\n", packet->node_id, ! (char *)packet->data); ! return 1; ! } ! ! return 0; } /** ! * Adds a packet handler for a given sensorboard. * * @author Martin Turon ! * @version 2004/7/28 mturon Intial version */ ! void xpacket_add_type(XPacketHandler *handler) { ! if (!handler) return; ! g_packetTable[handler->type] = handler; } /** ! * Adds a packet handler for the given AM packet type. * * @author Martin Turon ! * @version 2004/7/28 mturon Intial version */ ! void xpacket_add_amtype(XPacketHandler *handler) { ! if (!handler) return; ! g_packetTable[handler->type + XPACKET_AM_TABLE] = handler; ! } ! /** ! * Print out the timestamp of when the packet was heard. ! * ! * @author Martin Turon ! * @version 2004/9/27 mturon Intial version ! */ ! void xpacket_print_timestamp() ! { ! char timestring[TIMESTRING_SIZE]; ! Timestamp *time_now = timestamp_new(); ! timestamp_get_string(time_now, timestring); ! printf("%s", timestring); ! timestamp_delete(time_now); ! } ! /** ! * Print out the timestamp of when the packet was heard. ! * ! * @author Martin Turon ! * @version 2004/9/27 mturon Intial version ! */ ! void xpacket_print_time() ! { ! printf("["); ! xpacket_print_timestamp(); ! printf("]\n"); ! } ! /** ! * Print out the version information for all the packet handlers. ! * ! * @author Martin Turon ! * @version 2004/7/28 mturon Intial version ! */ ! void xpacket_print_versions() ! { ! int i = 256; ! printf("XSensor boards\n"); ! while (--i >= 0) { ! if ((g_packetTable[i]) && (g_packetTable[i]->version)) ! printf(" %02x: %s\n", ! g_packetTable[i]->type, g_packetTable[i]->version); ! } ! i = 512; ! printf("AM packet types\n"); ! while (--i >= XPACKET_AM_TABLE) { ! if ((g_packetTable[i]) && (g_packetTable[i]->version)) ! printf(" %02x: %s\n", ! g_packetTable[i]->type, g_packetTable[i]->version); ! } } + XPacketHandler *xsensor_get_handler(uint8_t type_id, int table) + { + int i = 256, entry; + while (--i >= 0) { + entry = table + i; + if (!(g_packetTable[entry])) continue; + if (g_packetTable[entry]->type == type_id) + return g_packetTable[entry]; + } + return NULL; + } ! XPacketHandler *xpacket_get_handler(char *tos_packet) ! { ! unsigned char am_type = tos_packet[XPACKET_TYPE]; ! switch (am_type) { ! case AMTYPE_XMULTIHOP: ! case AMTYPE_XUART: ! case AMTYPE_XDEBUG: ! case AMTYPE_XSENSOR: { ! XbowSensorboardPacket *packet; ! packet = xpacket_get_sensor_data(tos_packet); ! if (xpacket_print_common(packet)) { ! fprintf(stderr, ! "xpacket_get_handler error1: no packet handler for board id 0x%02x\n", ! packet->board_id); ! return NULL; ! } ! return xsensor_get_handler(packet->board_id, XPACKET_BOARD_TABLE); ! } + case AMTYPE_HEALTH: + case AMTYPE_SURGE_MSG: + return xsensor_get_handler(am_type, XPACKET_AM_TABLE); ! default: ! //Handle firebug AM_TYPES here. ! return (XPacketHandler*)fb_get_packet_handler(am_type); ! break; ! } ! fprintf(stderr, "xpacket_get_handler error2: no packet handler for tos type 0x%02x\n", ! am_type); + return NULL; + } ! /** ! * Display a parsed packet as raw ADC values for each sensor on the board. ! * ! * @param packet The TOS packet as raw bytes from the serial port ! * ! * @author Martin Turon ! * @version 2004/3/10 mturon Intial version ! */ ! void xpacket_print_parsed(unsigned char *tos_packet) { ! XPacketHandler *handler = xpacket_get_handler(tos_packet); ! if (!handler) return; ! XbowSensorboardPacket *packet = xpacket_get_sensor_data(tos_packet); ! if ((packet) && (handler->print_parsed)) { ! return handler->print_parsed(packet); ! } else { ! fprintf(stderr, "xpacket_print_parsed error: no packet handler for board id 0x%02x\n", ! packet->board_id); ! return; ! } } *************** *** 239,331 **** void xpacket_print_cooked(unsigned char *tos_packet) { ! XbowSensorboardPacket *packet = xpacket_get_sensor_data(tos_packet); ! ! switch(packet->packet_id) { ! case XPACKET_TEXT_MSG: ! packet->reserved2 = '\0'; ! printf("MSG from id=%d: %s\n\n", packet->node_id, ! (char *)packet->data); ! return; ! } ! ! switch(packet->sensorboard_id) { ! case XTYPE_MDA500: ! mda500_print_cooked(packet); ! break; ! ! case XTYPE_MDA400: ! mda400_print_cooked(packet); ! break; ! ! case XTYPE_MDA300: ! mda300_print_cooked(packet); ! break; ! ! case XTYPE_MTS300: ! mts300_print_cooked(packet); ! break; ! case XTYPE_MTS310: ! mts310_print_cooked(packet); ! break; ! case XTYPE_MTS400: ! mts400_print_cooked(packet); ! break; ! case XTYPE_MTS420: ! mts420_print_cooked(packet); ! break; ! case XTYPE_MTS510: ! mts510_print_cooked(packet); ! break; ! ! case XTYPE_MTS101: ! mts101_print_cooked(packet); ! break; ! ! case XTYPE_MEP500: ! mep500_print_cooked(packet); ! break; ! case XTYPE_MEP401: ! mep401_print_cooked(packet); ! break; ! /* More sensor boards go here... */ ! } } /** ! * Display a packet as cooked values in engineering units. * * @param packet The TOS packet as raw bytes from the serial port * * @author Martin Turon ! * @version 2004/3/11 mturon Intial version */ ! void xpacket_print_tabbed(unsigned char *tos_packet) { ! XbowSensorboardPacket *packet = xpacket_get_sensor_data(tos_packet); - /* - switch(packet->packet_id) { - case XPACKET_TEXT_MSG: - packet->reserved2 = '\0'; - printf("MSG from id=%d: %s\n\n", packet->node_id, - (char *)packet->data); - return; - } - */ ! switch(packet->sensorboard_id) { ! case XTYPE_MTS420: ! //mts420_print_cooked(packet); ! break; ! /* More sensor boards go here... */ ! } } --- 349,477 ---- void xpacket_print_cooked(unsigned char *tos_packet) { ! XPacketHandler *handler = xpacket_get_handler(tos_packet); ! if (!handler) return; ! XbowSensorboardPacket *packet = xpacket_get_sensor_data(tos_packet); ! if ((packet) && (handler->print_cooked)) { ! return handler->print_cooked(packet); ! } else { ! fprintf(stderr, "xpacket_print_cooked error: no packet handler for board id 0x%02x\n", ! packet->board_id); ! return; ! } ! } ! /** ! * Display a packet as cooked values in engineering units. ! * ! * @param packet The TOS packet as raw bytes from the serial port ! * ! * @author Martin Turon ! * @version 2004/3/11 mturon Intial version ! */ ! void xpacket_export_cooked(unsigned char *tos_packet) ! { ! XPacketHandler *handler = xpacket_get_handler(tos_packet); ! if (!handler) return; ! XbowSensorboardPacket *packet = xpacket_get_sensor_data(tos_packet); ! if ((packet) && (handler->export_cooked)) { ! return handler->export_cooked(packet); ! } else { ! fprintf(stderr, "xpacket_export_cooked error: no packet handler for board id 0x%02x\n", ! packet->board_id); ! return; ! } ! } ! /** ! * Log a packet as cooked values in engineering units into a database. ! * ! * @param packet The TOS packet as raw bytes from the serial port ! * ! * @author Martin Turon ! * @version 2004/7/28 mturon Intial version ! */ ! void xpacket_log_cooked(unsigned char *tos_packet) ! { ! XPacketHandler *handler = xpacket_get_handler(tos_packet); ! if (!handler) return; ! XbowSensorboardPacket *packet = xpacket_get_sensor_data(tos_packet); ! if ((packet) && (handler->log_cooked)) { ! return handler->log_cooked(packet); ! } else { ! fprintf(stderr, "xpacket_log_cooked error: no packet handler for board id 0x%02x\n", ! packet->board_id); ! return; ! } ! } ! /** ! * Display a packet as ascii. ! * ! * @param packet The TOS packet as raw bytes from the serial port ! * ! * @author Martin Turon ! * @version 2004/9/29 mturon Intial version ! */ ! void xpacket_print_ascii(unsigned char *packet, int len) ! { ! int i; ! for (i=0; i<len; i++) { ! printf("%c", packet[i]); ! } ! printf("\n", len); } /** ! * Display a raw packet. * * @param packet The TOS packet as raw bytes from the serial port * * @author Martin Turon ! * @version 2004/3/10 mturon Intial version */ ! void xpacket_print_raw(unsigned char *packet, int len) { ! int i; ! for (i=0; i<len; i++) { ! printf("%02x", packet[i]); ! } ! printf(" [%i]\n", len); ! } ! /** ! * Display a parsed packet as exportable data -- comma delimited text. ! * ! * @param packet The TOS packet as raw bytes from the serial port ! * ! * @author Martin Turon ! * @version 2004/7/28 mturon Intial version ! */ ! void xpacket_export_parsed(unsigned char *tos_packet) ! { ! int i=0; ! uint8_t *packet = (uint8_t *)xpacket_get_sensor_data(tos_packet); ! if (xpacket_print_common((XbowSensorboardPacket *)packet)) return; ! TosMsg *tosmsg = (TosMsg *)tos_packet; ! MultihopMsg *mhop = (MultihopMsg *)(tos_packet + sizeof(TosMsg)); ! xpacket_print_timestamp(); ! printf (", %u,%u,%u, %u,%u,%u, ", ! tosmsg->am_type, tosmsg->group, tosmsg->length, ! mhop->nodeid, mhop->seqno, mhop->hops ! ); ! ! packet = (uint8_t *)mhop; ! // i=2 --> skip board_id/packet_id, node/parent ! for (i=0; i<tosmsg->length; i++) { // include CRC ! printf("%u",packet[i]); ! printf(","); ! } ! // uint16_t crc = *(uint16_t *)((char *)mhop + tosmsg->length); ! // printf(" %u\n",crc); } Index: genc.pm =================================================================== RCS file: /cvsroot/firebug/fireboard/tools/src/xlisten/genc.pm,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** genc.pm 2 Aug 2004 23:07:01 -0000 1.4 --- genc.pm 10 Jul 2006 17:18:15 -0000 1.5 *************** *** 28,268 **** ## Parts of this code were written for the NSF_ITR funded ## firebug project. true; sub gen() { - my ($classname, @spec) = @_; ! require migdecode; ! &decode(@spec); ! &usage("no classname name specified") if !defined($java_classname); ! $java_extends = "net.tinyos.message.Message" if !defined($java_extends); ! # See if name has a package specifier ! if ($java_classname =~ /(.*)\.([^.]*)$/) { ! $package = $1; ! $java_classname = $2; ! } ! $I = " "; ! $smallskip = "\n\n"; ! $medskip = "\n\n\n\n"; ! $bigskip = "\n\n\n\n\n\n"; ! print "/**\n"; ! print " * This class is automatically generated by mig. DO NOT EDIT THIS FILE.\n"; ! print " * This code implements C interface to the '$java_classname'\n"; ! print " * message type.\n"; ! print " */\n\n"; ! print "#include <stdio.h>\n"; ! print "#include <stdlib.h>\n"; ! print "#include <memory.h>\n"; ! print $medskip; - print "/** Private header is programmer specified for handling\n"; - print " * conversion functions, etc.\n */\n"; - print "//#include \"$java_classname\_private.h\"\n"; ! print $medskip; ! print "/** These need to be moved to a header file. */\n"; ! print "typedef struct _$java_classname $java_classname;\n"; ! print "typedef struct _XbowSensorboardPacket XbowSensorboardPacket;\n"; ! print $smallskip; ! print "// This struct is defined to keep gcc happy while the module\n"; ! print "// is under development. At some point in the near future, a\n"; ! print "// a convention for passing arguments into the functions will\n"; ! print "// have to be defined.\n"; ! print "struct _XbowSensorboardPacket {\n"; ! print " unsigned char data[29];\n"; ! print "};\n"; ! print $medskip; ! # print "struct _$java_classname {\n"; ! # for (@fields) { ! # ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; ! # ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); ! # if ($field =~ /(.*)\.([^.]*)$/) { ! # $struct = $1; ! # $member = $2; ! # } ! # push(@format, &formatstring($type, $bitlength, 0)); ! # $field =~ s/\./_/g; ! # printf "$I$ctype $field;\n"; ! # } ! # print "};"; ! &gen_struct(); ! print $medskip; ! &gen_get_set(); ! print $medskip; ! ## Default behavior is to return the input as output. ! ## User is responsible for "cooking" the data. ! for (@fields) { ! ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; ! ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); ! $field =~ s/\./_/g; ! print "/** \@brief Default behavior is to return the input as output.\n"; ! print " * User is responsible for \"cooking\" the data.\n */\n"; ! print "static $ctype\n"; ! print "$field\_convert($ctype $field) {\n"; ! print " return $field;\n"; ! print "}\n\n"; ! } ! ## Function for cooking whole packet. Fields are ! ## by calling the individual "cook" functions for ! ## each member. ! print "void\n"; ! print "$java_classname\_cook\_packet($java_classname * userdata) {\n"; ! for (@fields) { ! ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; ! ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); ! $field =~ s/\./_/g; ! print " userdata->$field = $field\_convert(userdata->$field);\n"; ! } print "}\n\n"; - print $medskip; ! print "//Format string can be generated automatically,\n"; ! print "//then the delimiters added later: @format\n"; - print $medskip; - ## In the code for the xlisten boards, the conversions are - ## in the print statement. If the conversions were done - ## before the print statement, then the conversion function - ## becomes the only function needing to be stubbed. The - ## runtime differences are neglible. ! print "/** User has to fill in any conversion code\n"; ! print " * necessary for processing.\n"; ! print " */\n"; ! print "$java_classname * convert(char * data) {\n"; ! print " // Just to keep gcc happy.\n"; ! print " return ($java_classname*)data;\n"; ! print "}\n"; ! print $medskip; ! ## Start printing output functions. ! print "/** Print the bytes of the packet. */\n"; ! print "void $java_classname\_print\_raw (XbowSensorboardPacket *packet) {\n\n"; ! print "$I$java_classname * userdata = ($java_classname*)packet->data;\n"; ! print "}\n\n"; ! print "/** Print typed output. */\n"; ! print "void $java_classname\_print\_cooked (XbowSensorboardPacket *packet) {\n\n"; ! print "$I$java_classname * userdata = ($java_classname*)packet->data;\n"; ! print "}\n\n"; ! print "/** Print cooked with tabs. */\n"; ! print "void $java_classname\_print\_tabbed (XbowSensorboardPacket *packet) {\n\n"; ! print "$I$java_classname * userdata = ($java_classname*)packet->data;\n"; ! print "}\n\n"; ! # print "package $package;\n\n" if $package; - # print "public class $java_classname extends $java_extends {\n\n"; ! print "/** The default size of this message type in bytes. */\n"; ! print "static int DEFAULT_MESSAGE_SIZE = $size;\n\n"; ! print "/** The Active Message type associated with this message. */\n"; ! print "static int AM_TYPE = $amtype;\n\n"; - print "/** If incomplete types are used, we need to provide a way\n"; - print " * to manage memory.\n"; - print " */\n"; - print "$java_classname *\n"; - print "$java_classname\_new() {\n"; - print " $java_classname * userdata = ($java_classname*)malloc(sizeof($java_classname));\n"; - print " memset((void*)userdata,0xda,sizeof($java_classname));\n"; - print " return userdata;\n"; - print "}\n"; ! print $medskip; ! print "void\n"; ! print "$java_classname\_delete($java_classname * userdata) {\n"; ! print " memset((void*)userdata,0xdd,sizeof($java_classname));\n"; ! print " free(userdata);\n"; ! print "}\n"; } sub gen_struct() { ! print "struct _$java_classname {\n"; ! ## todo move this to sub print_msg_struct(). ! for (@fields) { ! ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; ! ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); ! # This is clunky but will work. A better way to do it would be to store ! # the nested struct internally in the field array somehow. ! # Maybe a perl guru can figure that out. ! # What needs to be done is to find one of these, then ! # store it until all the members written out, ! # then print it. ! if ($field =~ /(.*)\.([^.]*)$/) { ! $struct = $1; ! $member = $2; ! #print STDERR $struct;#.", "$member."\n"; ! } ! ## Gets an array of format specifiers useful in *print* functions ! ## in libc. the @format array can be passed ! push(@format, &formatstring($type, $bitlength, 0)); ! $field =~ s/\./_/g; ! printf "$I$ctype $field;\n"; ! } ! print "};"; } sub gen_get_set() { ! ## The get/set code is more to investigate the mechanics of ! ## the autogeneration of structs. It's probably more useful ! ## use the defined type directly, at least for now. ! ## ! ## todo move this to sub_get_set_methods() ! for (@fields) { ! ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; ! ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); ! $field =~ s/\./_/g; ! print "void\n"; ! print "$java_classname\_set\_$field($java_classname * userdata, $ctype $field) {\n"; ! print " userdata->$field = $field;\n"; ! print "}\n\n"; ! #### Get methods ! print "$ctype\n"; ! print "$java_classname\_get\_$field($java_classname * userdata) {\n"; ! print " return userdata->$field;\n"; ! print "}\n\n"; ! } } --- 28,497 ---- ## Parts of this code were written for the NSF_ITR funded ## firebug project. + ## + ## Code based on genjava.pm written by David Gay (?) + ## authors David Gay (? + others?), Dave Doolin true; + + + sub gen() { ! my %struct_hash; ! my ($tmp,$fmtstr); ! my ($classname, @spec) = @_; ! require migdecode; ! &decode(@spec); ! &usage("no classname name specified") if !defined($java_classname); ! $java_extends = "net.tinyos.message.Message" if !defined($java_extends); ! # See if name has a package specifier ! if ($java_classname =~ /(.*)\.([^.]*)$/) { ! $package = $1; ! $java_classname = $2; ! $structname = $java_classname."P"; ! } ! $I = " "; ! $smallskip = "\n\n"; ! $medskip = "\n\n\n\n"; ! $bigskip = "\n\n\n\n\n\n"; + print "/**\n"; + print " * This class is automatically generated by mig. DO NOT EDIT THIS FILE.\n"; + print " * This code implements C interface to the '$structname'\n"; + print " * message type.\n"; + print " */\n\n"; + print "#include <stdio.h>\n"; + print "#include <stdlib.h>\n"; + print "#include <memory.h>\n"; ! print $medskip; ! print "/** Private header is programmer specified for handling\n"; ! print " * conversion functions, etc.\n */\n"; ! print "//#include \"$structname\_private.h\"\n"; ! print "/** Not the best way to handle xbow dependencies. */\n"; ! print "#ifdef TELOS_MOTE\n"; ! print "#include \"../xdb.h\"\n"; ! print "#include \"../xsensors.h\"\n"; ! print "#endif\n"; ! print $medskip; ! print "/** These need to be moved to a header file. */\n"; ! print "typedef struct _$structname $structname;\n"; ! print "#ifndef TELOS_MOTE\n"; ! print "typedef struct _XbowSensorboardPacket XbowSensorboardPacket;\n"; ! print "#endif\n"; ! print $medskip + print "/** The Active Message type associated with this message. */\n"; + print "//static const int AM_TYPE = $amtype;\n\n"; + print "//#define AM_TYPE $amtype\n\n"; ! print $smallskip; ! print "// This struct is defined to keep gcc happy while the module\n"; ! print "// is under development. At some point in the near future, a\n"; ! print "// a convention for passing arguments into the functions will\n"; ! print "// have to be defined.\n"; ! print "struct _XbowSensorboardPacket {\n"; ! print " unsigned char data[29];\n"; ! print "};\n"; + print $medskip; + # print "struct _$structname {\n"; + # for (@fields) { + # ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; + # ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); + # if ($field =~ /(.*)\.([^.]*)$/) { + # $struct = $1; + # $member = $2; + # } + # push(@format, &formatstring($type, $bitlength, 0)); + # $field =~ s/\./_/g; + # printf "$I$ctype $field;\n"; + # } + # print "};"; ! ! ! print $medskip; ! ! ! &gen_struct(); ! print $medskip; ! ! &gen_get_set(); ! print $medskip; ! ! print "//Format string generated automatically,\n"; ! $tmp = @format[$#format-1]; ! $tmp =~ s/,//g; ! $fmtstr = "@format[0..($#format-1)] $tmp"; ! #print "Fmt: $fmtstr\n"; ! print "//static char formatstring[] = \"@format[0..($#format-1)] $tmp\";\n\n\n";... [truncated message content] |