[Firebug-cvs] fireboard/beta/tools/src/xlisten Makefile,1.1,1.2 xdb.c,1.1,1.2 xdb.h,1.1,1.2 xlisten.
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2005-05-19 20:04:21
|
Update of /cvsroot/firebug/fireboard/beta/tools/src/xlisten In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5174 Modified Files: Makefile xdb.c xdb.h xlisten.c xpacket.c xsensors.h xserial.c Log Message: Using xbow stable for this code. Index: xpacket.c =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/xpacket.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** xpacket.c 19 May 2005 19:58:17 -0000 1.1 --- xpacket.c 19 May 2005 20:04:08 -0000 1.2 *************** *** 12,19 **** #include "xsensors.h" static unsigned g_datastart = XPACKET_DATASTART; ! static XPacketHandler *g_packetTable[256]; /** --- 12,20 ---- #include "xsensors.h" + #include "xpacket.h" static unsigned g_datastart = XPACKET_DATASTART; ! static XPacketHandler *g_packetTable[512]; /** *************** *** 25,28 **** --- 26,35 ---- 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 */ *************** *** 41,44 **** --- 48,55 ---- 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 */ } *************** *** 135,138 **** --- 146,150 ---- case AMTYPE_XSENSOR: case AMTYPE_SURGE_MSG: + case AMTYPE_HEALTH: datastart = XPACKET_DATASTART_STANDARD; break; *************** *** 186,189 **** --- 198,213 ---- /** + * 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. * *************** *** 191,204 **** * @version 2004/9/27 mturon Intial version */ ! void xpacket_print_time() { char timestring[TIMESTRING_SIZE]; Timestamp *time_now = timestamp_new(); timestamp_get_string(time_now, timestring); ! printf("[%s]\n", timestring); timestamp_delete(time_now); } /** * Print out the version information for all the packet handlers. * --- 215,242 ---- * @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. * *************** *** 209,212 **** --- 247,251 ---- { int i = 256; + printf("XSensor boards\n"); while (--i >= 0) { if ((g_packetTable[i]) && (g_packetTable[i]->version)) *************** *** 214,226 **** g_packetTable[i]->type, g_packetTable[i]->version); } } ! XPacketHandler *xsensor_get_handler(uint8_t board_id) { ! int i = 256; while (--i >= 0) { ! if ((g_packetTable[i]) && ! (g_packetTable[i]->type == board_id)) ! return g_packetTable[i]; } return NULL; --- 253,273 ---- 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; *************** *** 232,236 **** switch (am_type) { - case AMTYPE_SURGE_MSG: case AMTYPE_XMULTIHOP: case AMTYPE_XUART: --- 279,282 ---- *************** *** 245,252 **** return NULL; } ! return xsensor_get_handler(packet->board_id); } ! case AMTYPE_MHOP_DEBUG: default: break; --- 291,301 ---- 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: break; *************** *** 394,408 **** void xpacket_export_parsed(unsigned char *tos_packet) { ! int i; ! uint16_t *packet = (uint16_t *)xpacket_get_sensor_data(tos_packet); if (xpacket_print_common((XbowSensorboardPacket *)packet)) return; ! packet += 2; // Ignore board_id and packet_id ! for (i=0; i<8; i++) { ! if (i>0) printf(","); ! printf("%d",packet[i]); } ! printf("\n"); } --- 443,466 ---- 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 ! ); ! ! // 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: xsensors.h =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/xsensors.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** xsensors.h 19 May 2005 19:58:17 -0000 1.1 --- xsensors.h 19 May 2005 20:04:08 -0000 1.2 *************** *** 48,51 **** --- 48,56 ---- XTYPE_MEP500, + // mote boards + XTYPE_MICA2 = 0x60, + XTYPE_MICA2DOT, + XTYPE_MICAZ, + // mica2 sensorboards XTYPE_MDA400 = 0x80, *************** *** 57,65 **** XTYPE_MTS420, XTYPE_MEP401, } XbowSensorboardType; typedef enum { AMTYPE_XUART = 0x00, ! AMTYPE_MHOP_DEBUG = 0x03, AMTYPE_SURGE_MSG = 0x11, AMTYPE_XDEBUG = 0x31, --- 62,76 ---- XTYPE_MTS420, XTYPE_MEP401, + XTYPE_XTUTORIAL = 0x88, + XTYPE_GGBACLTST, + + // mica2 integrated boards + XTYPE_MSP410 = 0xA0, + } XbowSensorboardType; typedef enum { AMTYPE_XUART = 0x00, ! AMTYPE_HEALTH = 0x03, AMTYPE_SURGE_MSG = 0x11, AMTYPE_XDEBUG = 0x31, *************** *** 107,110 **** --- 118,124 ---- #define XPACKET_DATASTART 12 //!< Default offset to data payload + #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, *************** *** 151,154 **** --- 165,169 ---- 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 (); *************** *** 173,176 **** --- 188,196 ---- 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. */ *************** *** 189,195 **** --- 209,220 ---- 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 */ #endif /* __SENSORS_H__ */ Index: xdb.c =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/xdb.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** xdb.c 19 May 2005 19:58:17 -0000 1.1 --- xdb.c 19 May 2005 20:04:08 -0000 1.2 *************** *** 85,100 **** { int errno = 0; PGconn *conn = xdb_connect(); PQsendQuery(conn, command); PGresult *res = PQgetResult(conn); ! printf("%s\n", command); ! while (res != NULL) { errno = PQresultStatus(res); if (errno > PGRES_COMMAND_OK) fprintf(stderr, "error: DATABASE command failed: %i\n", errno); - res = PQgetResult(conn); PQclear(res); } /* close the connection to the database and cleanup */ PQfinish(conn); --- 85,101 ---- { int errno = 0; + printf("%s\n", command); + PGconn *conn = xdb_connect(); PQsendQuery(conn, command); PGresult *res = PQgetResult(conn); ! if (res != NULL) { errno = PQresultStatus(res); if (errno > PGRES_COMMAND_OK) fprintf(stderr, "error: DATABASE command failed: %i\n", errno); PQclear(res); } + /* close the connection to the database and cleanup */ PQfinish(conn); Index: Makefile =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile 19 May 2005 19:58:17 -0000 1.1 --- Makefile 19 May 2005 20:04:08 -0000 1.2 *************** *** 1,32 **** ! # Makefile for xlisten # $Id$ ! ! CC = gcc ! ARMCC = arm-linux-gcc ! INCDIR = /usr/local/arm/3.3.2/pgsql/include ! LIBDIR = /usr/local/arm/3.3.2/pgsql/lib ! LFLAGS = -lpq -lm ! CFLAGS = -O2 -Wall -Wno-format ! ! # Main xlisten sources ! SRCS = xlisten.c xpacket.c xconvert.c xdb.c ! SRCS += xserial.c xsocket.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/surge.c ! ! # Add Mote Data Aquisition board support ! SRCS += boards/mda500.c boards/mda300.c ! ! SRCS += timestamp/timestamp.c ! ! all: xlisten ! ! xlisten: $(SRCS) ! $(CC) $(CFLAGS) -o $@ $(SRCS) $(LFLAGS) ! ! xlisten-arm: $(SRCS) ! $(ARMCC) -I$(INCDIR) $(CFLAGS) -o $@ $(SRCS) -L$(LIBDIR) $(LFLAGS) ! ! clean: ! rm -f *.o boards/*.o xlisten xlisten-arm xlisten.exe --- 1,43 ---- ! # Makefile for xlisten # $Id$ ! ! CC = gcc ! ARMCC = arm-linux-gcc ! INCDIR = /usr/local/arm/3.3.2/pgsql/include ! LIBDIR = /usr/local/arm/3.3.2/pgsql/lib ! LFLAGS = -lpq -lm ! CFLAGS = -O2 -Wall -Wno-format ! ! # Main xlisten sources ! SRCS = xlisten.c xpacket.c xconvert.c xdb.c ! SRCS += xserial.c xsocket.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 ! ! # 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 ! ! xlisten: $(SRCS) ! $(CC) $(CFLAGS) -o $@ $(SRCS) $(LFLAGS) ! ! xlisten-arm: $(SRCS) ! $(ARMCC) -I$(INCDIR) $(CFLAGS) -o $@ $(SRCS) -L$(LIBDIR) $(LFLAGS) ! ! clean: ! rm -f *.o boards/*.o xlisten xlisten-arm xlisten.exe Index: xserial.c =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/xserial.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** xserial.c 19 May 2005 19:58:17 -0000 1.1 --- xserial.c 19 May 2005 20:04:08 -0000 1.2 *************** *** 73,76 **** --- 73,77 ---- struct termios newtio; bzero(&newtio, sizeof(newtio)); + newtio.c_cc[VMIN] = 1; newtio.c_cflag = CS8 | CLOCAL | CREAD; newtio.c_iflag = IGNBRK | IGNPAR; Index: xlisten.c =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/xlisten.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** xlisten.c 19 May 2005 19:58:17 -0000 1.1 --- xlisten.c 19 May 2005 20:04:08 -0000 1.2 *************** *** 40,44 **** unsigned mode_version : 1; //!< print versions of all modules unsigned mode_header : 1; //!< user using custom packet header ! unsigned mode_socket : 1; //!< connect to a serial forwarder unsigned mode_framing : 2; //!< auto=0, framed=1, unframed=2 } bits; --- 40,45 ---- unsigned mode_version : 1; //!< print versions of all modules unsigned mode_header : 1; //!< user using custom packet header ! unsigned mode_socket : 1; //!< connect to a serial socket ! unsigned mode_sf : 1; //!< connect to a serial forwarder unsigned mode_framing : 2; //!< auto=0, framed=1, unframed=2 } bits; *************** *** 108,117 **** case 'x': switch (argv[argc][2]) { case 'r': g_params.bits.export_parsed = 1; break; - default: g_params.bits.export_cooked = 1; break; } ! break; ! case 'f': { switch (argv[argc][2]) { case '=': // specify arbitrary offset --- 109,119 ---- case 'x': switch (argv[argc][2]) { + case 'c': g_params.bits.export_cooked = 1; break; + default: case 'r': g_params.bits.export_parsed = 1; break; } ! break; ! case 'f': switch (argv[argc][2]) { case '=': // specify arbitrary offset *************** *** 121,138 **** case 'a': // automatic deframing g_params.bits.mode_framing = 0; ! break; case '0': case 'n': // assume no framing g_params.bits.mode_framing = 2; ! break; case '1': // force framing ! default: g_params.bits.mode_framing = 1; break; } break; ! } case 'w': --- 123,140 ---- case 'a': // automatic deframing g_params.bits.mode_framing = 0; ! break; case '0': case 'n': // assume no framing g_params.bits.mode_framing = 2; ! break; case '1': // force framing ! default: g_params.bits.mode_framing = 1; break; } break; ! case 'w': *************** *** 151,155 **** xpacket_set_start(offset); break; ! } case 'l': --- 153,157 ---- xpacket_set_start(offset); break; ! } case 'l': *************** *** 157,162 **** if (argv[argc][2] == '=') { xdb_set_table(argv[argc]+3); ! // xdb_create_table(argv[argc]+3); ! } case 'b': --- 159,164 ---- if (argv[argc][2] == '=') { xdb_set_table(argv[argc]+3); ! } ! break; case 'b': *************** *** 168,173 **** case 's': ! if (argv[argc][2] == '=') { ! xserial_set_device(argv[argc]+3); } break; --- 170,191 ---- case 's': ! switch (argv[argc][2]) { ! case '=': ! xserial_set_device(argv[argc]+3); ! break; ! ! case 'f': ! g_params.bits.mode_sf = 1; ! g_params.bits.mode_socket = 1; ! if (argv[argc][3] == '=') { ! server = argv[argc]+4; ! port = strchr(server, ':'); ! if (port) { ! *port++ = '\0'; ! xsocket_set_port(port); ! } ! xsocket_set_server(server); ! } ! break; } break; *************** *** 178,181 **** --- 196,200 ---- case 'i': + g_params.bits.mode_sf = 0; g_params.bits.mode_socket = 1; if (argv[argc][2] == '=') { *************** *** 235,254 **** "\nUsage: xlisten <-?|r|p|c|x|l|d|v|q> <-l=table>" "\n <-s=device> <-b=baud> <-i=server:port>" ! "\n -? = display help [help]" ! "\n -r = raw display of tos packets [raw]" ! "\n -a = ascii display of tos packets [ascii]" ! "\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 -l = log data to database or file [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 serial forwarder input [inet=host:port]" ! "\n -o = output (forward serial) to port [onet=port] -!TBA!-" ! "\n -h = specify header size [header=offset]" ! "\n -t = display time packet was received [timed]" ! "\n -q = quiet mode (suppress headers)" ! "\n -v = show version of all modules" "\n" ); --- 254,275 ---- "\nUsage: xlisten <-?|r|p|c|x|l|d|v|q> <-l=table>" "\n <-s=device> <-b=baud> <-i=server:port>" ! "\n -? = display help [help]" ! "\n -r = raw display of tos packets [raw]" ! "\n -a = ascii display of tos packets [ascii]" ! "\n -p = parse packet into raw sensor readings [parsed]" ! "\n -c = convert data to engineering units [cooked]" ! "\n -l = log data to database or file [logged]" ! "\n -xr = export raw readings in csv spreadsheet format [export]" ! "\n -xc = export cooked in csv spreadsheet format [export]" ! "\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 -f = specify framing (0=auto|1=on|2=off)" ! "\n -h = specify header size [header=offset]" ! "\n -t = display time packet was received [timed]" ! "\n -q = quiet mode (suppress headers)" ! "\n -v = show version of all modules" "\n" ); *************** *** 297,301 **** while (1) { ! length = xserial_port_read_packet(g_istream, buffer); if (length < XPACKET_MIN_SIZE) --- 318,328 ---- 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) *************** *** 308,312 **** if (g_params.bits.display_ascii) xpacket_print_ascii(buffer, length); ! xpacket_decode(buffer, length, g_params.bits.mode_framing); if (g_params.bits.display_parsed) xpacket_print_parsed(buffer); --- 335,340 ---- 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); *************** *** 339,349 **** @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 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] --- 367,378 ---- @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] *************** *** 367,370 **** --- 396,405 ---- 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: |