[Firebug-cvs] fireboard/beta/tools/src/xlisten Makefile,1.11,1.12 genc.pm,1.3,1.4 genpgsql.pm,1.1,1.
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2005-08-01 19:17:33
|
Update of /cvsroot/firebug/fireboard/beta/tools/src/xlisten In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3608/tools/src/xlisten Modified Files: Makefile genc.pm genpgsql.pm xpacket.c xsensors.h Log Message: Autogeneration tool chain works from mote-to-database now. Index: xpacket.c =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/xpacket.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** xpacket.c 1 Aug 2005 15:23:46 -0000 1.6 --- xpacket.c 1 Aug 2005 19:17:22 -0000 1.7 *************** *** 56,60 **** xtutorial_initialize(); /* From boards/xtutorial.c */ ! testlink_initialize(); } --- 56,60 ---- xtutorial_initialize(); /* From boards/xtutorial.c */ ! LinkMsgP_initialize(); } Index: xsensors.h =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/xsensors.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** xsensors.h 1 Aug 2005 15:26:07 -0000 1.7 --- xsensors.h 1 Aug 2005 19:17:22 -0000 1.8 *************** *** 230,234 **** void xtutorial_initialize(); /* From baords/xtutorial.c */ ! void testlink_initialize(); #endif /* __SENSORS_H__ */ --- 230,234 ---- void xtutorial_initialize(); /* From baords/xtutorial.c */ ! void LinkMsgP_initialize(); #endif /* __SENSORS_H__ */ Index: Makefile =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/Makefile,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Makefile 1 Aug 2005 15:27:33 -0000 1.11 --- Makefile 1 Aug 2005 19:17:21 -0000 1.12 *************** *** 17,21 **** 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 --- 17,21 ---- 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 Index: genpgsql.pm =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/genpgsql.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** genpgsql.pm 14 Jul 2005 16:50:57 -0000 1.1 --- genpgsql.pm 1 Aug 2005 19:17:22 -0000 1.2 *************** *** 44,48 **** if ($java_classname =~ /(.*)\.([^.]*)$/) { $package = $1; ! $java_classname = $2; } --- 44,48 ---- if ($java_classname =~ /(.*)\.([^.]*)$/) { $package = $1; ! $java_classname = $2."P"; } *************** *** 148,153 **** $acc = "UIntElement"; if ($bitlength < 8) { $jtype = "smallint"; } ! elsif ($bitlength < 16) { $jtype = "smallint"; } ! elsif ($bitlength < 32) { $jtype = "smallint"; } else { $jtype = "integer"; } } --- 148,153 ---- $acc = "UIntElement"; if ($bitlength < 8) { $jtype = "smallint"; } ! elsif ($bitlength < 16) { $jtype = "integer"; } ! elsif ($bitlength < 32) { $jtype = "integer"; } else { $jtype = "integer"; } } Index: genc.pm =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tools/src/xlisten/genc.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** genc.pm 30 Jul 2005 03:14:58 -0000 1.3 --- genc.pm 1 Aug 2005 19:17:22 -0000 1.4 *************** *** 34,131 **** - sub gen_insert_stmt () { - - my($fmtstr1) = $_[0]; - my($fmtstr); - - my ($tmp,$fmtstr); - - $i = 0; - $numfields = $#fields; - - print "static char insert_stmt[] = \"INSERT into $java_classname (\"\n"; - - 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; - - if ($i < $numfields) { - printf "\"$field,\"\n"; - } else { - printf "\"$field) values ("; - } - - $i++; - } - - $tmp = @format[$#format-1]; - $tmp =~ s/,//g; - $fmtstr = "@format[0..($#format-1)] $tmp"; - print "$fmtstr)\";\n\n\n"; - - - &gen_struct_array(); - - - - print "void\n$java_classname\_pg\_log(XbowSensorboardPacket * userdata) {\n"; - print "char pg_command[255];\n"; - print "$java_classname * data = ($java_classname*)userdata;\n"; - print "sprintf(pg_command,insert_stmt,\n"; - # traverse struct here. - $i = 0; - 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; - - if ($i < $numfields) { - print "data->$field,\n" - } else { - print "data->$field);\n"; - } - $i++; - } - - print "xdb_execute(pg_command);\n"; - - print "}\n"; - - } - - sub gen() { --- 34,37 ---- *************** *** 147,150 **** --- 53,57 ---- $package = $1; $java_classname = $2; + $structname = $java_classname."P"; } *************** *** 154,160 **** $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"; --- 61,68 ---- $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"; *************** *** 168,181 **** print "/** Private header is programmer specified for handling\n"; print " * conversion functions, etc.\n */\n"; ! print "//#include \"$java_classname\_private.h\"\n"; ! print "/** Not the best way to handle xbow dependencies. */\n"; print "#include \"../xdb.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; --- 76,96 ---- 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 "#include \"../xdb.h\"\n"; + print "#include \"../xsensors.h\"\n"; print $medskip; print "/** These need to be moved to a header file. */\n"; ! print "typedef struct _$structname $structname;\n"; ! print "//typedef struct _XbowSensorboardPacket XbowSensorboardPacket;\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; *************** *** 191,195 **** print $medskip; ! # print "struct _$java_classname {\n"; # for (@fields) { # ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; --- 106,110 ---- print $medskip; ! # print "struct _$structname {\n"; # for (@fields) { # ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; *************** *** 247,251 **** ## each member. print "void\n"; ! print "$java_classname\_cook\_packet($java_classname * userdata) {\n"; for (@fields) { ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; --- 162,166 ---- ## each member. print "void\n"; ! print "$structname\_cook\_packet($structname * userdata) {\n"; for (@fields) { ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; *************** *** 269,275 **** print " * necessary for processing.\n"; print " */\n"; ! print "$java_classname *\n $java_classname\_convert(char * data) {\n"; print " // Just to keep gcc happy.\n"; ! print " return ($java_classname*)data;\n"; print "}\n"; --- 184,190 ---- print " * necessary for processing.\n"; print " */\n"; ! print "$structname *\n $structname\_convert(char * data) {\n"; print " // Just to keep gcc happy.\n"; ! print " return ($structname*)data;\n"; print "}\n"; *************** *** 282,304 **** #&gen_cooked_with_tabs(); # 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"; --- 197,218 ---- #&gen_cooked_with_tabs(); + &gen_handler_table(); # print "package $package;\n\n" if $package; ! # print "public class $structname 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 "/** If incomplete types are used, we need to provide a way\n"; print " * to manage memory.\n"; print " */\n"; ! print "$structname *\n"; ! print "$structname\_new() {\n"; ! print " $structname * userdata = ($structname*)malloc(sizeof($structname));\n"; ! print " memset((void*)userdata,0xda,sizeof($structname));\n"; print " return userdata;\n"; print "}\n"; *************** *** 308,313 **** 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"; --- 222,227 ---- print "void\n"; ! print "$structname\_delete($structname * userdata) {\n"; ! print " memset((void*)userdata,0xdd,sizeof($structname));\n"; print " free(userdata);\n"; print "}\n"; *************** *** 315,323 **** } sub gen_cooked_with_tabs() { print "/** Print cooked with tabs. */\n"; ! print "void\n$java_classname\_print\_tabbed (XbowSensorboardPacket *packet) {\n\n"; ! print "$I$java_classname * userdata = ($java_classname*)packet->data;\n"; print "}\n\n"; } --- 229,334 ---- } + + + sub gen_insert_stmt () { + + my($fmtstr1) = $_[0]; + my($fmtstr); + + my ($tmp,$fmtstr); + + $i = 0; + $numfields = $#fields; + + print "static char insert_stmt[] = \"INSERT into $structname (\"\n"; + + 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; + + if ($i < $numfields) { + printf "\"$field,\"\n"; + } else { + printf "\"$field) values ("; + } + + $i++; + } + + $tmp = @format[$#format-1]; + $tmp =~ s/,//g; + $fmtstr = "@format[0..($#format-1)] $tmp"; + print "$fmtstr)\";\n\n\n"; + + + &gen_struct_array(); + + + + print "void\n$structname\_pg\_log(XbowSensorboardPacket * userdata) {\n"; + print "char pg_command[255];\n"; + print "$structname * data = ($structname*)userdata;\n"; + print "sprintf(pg_command,insert_stmt,\n"; + # traverse struct here. + $i = 0; + 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; + + if ($i < $numfields) { + print "data->$field,\n" + } else { + print "data->$field);\n"; + } + $i++; + } + + print "xdb_execute(pg_command);\n"; + + print "}\n"; + + } + + + sub gen_cooked_with_tabs() { print "/** Print cooked with tabs. */\n"; ! print "void\n$structname\_print\_tabbed (XbowSensorboardPacket *packet) {\n\n"; ! print "$I$structname * userdata = ($structname*)packet->data;\n"; print "}\n\n"; } *************** *** 327,342 **** print "/** Print the bytes of the packet. */\n"; ! print "void\n$java_classname\_print\_raw (XbowSensorboardPacket *packet) {\n\n"; ! # print "$I$java_classname * userdata = ($java_classname*)packet->data;\n"; print "}\n\n"; } sub gen_cooked_output() { print "/** Print cooked output. */\n"; ! print "void\n$java_classname\_print\_cooked (XbowSensorboardPacket * userdata) {\n\n"; ! print "$I$java_classname * data = ($java_classname*)userdata;\n"; for (@fields) { --- 338,376 ---- print "/** Print the bytes of the packet. */\n"; ! print "void\n$structname\_print\_raw (XbowSensorboardPacket *packet) {\n\n"; ! # print "$I$structname * userdata = ($structname*)packet->data;\n"; ! print " printf(\"$structname print raw.\\n\");\n"; print "}\n\n"; } + sub gen_handler_table() { + + print "XPacketHandler $structname\_packet\_handler = {\n"; + print "// This should be replaced with the AM_TYPE\n"; + print " $amtype,\n"; + print " \"\$Id$\",\n"; + print " $structname\_print\_raw,\n"; + print " $structname\_print\_cooked,\n"; + print " $structname\_print\_raw,\n"; + print " $structname\_print\_cooked,\n"; + print " $structname\_pg\_log,\n"; + print " {0}\n"; + print "};\n\n\n"; + + ### Add handler table to xlisten. + print "void\n$structname\_initialize() {\n"; + print "xpacket_add_type(&$structname\_packet\_handler);\n"; + print "}\n"; + + } + sub gen_cooked_output() { print "/** Print cooked output. */\n"; ! print "void\n$structname\_print\_cooked (XbowSensorboardPacket * userdata) {\n\n"; ! print "$I$structname * data = ($structname*)userdata;\n"; + print " printf(\"$structname print cooked:\\n\");\n"; for (@fields) { *************** *** 352,356 **** #push(@format, &formatstring($type, $bitlength, 0)); $field =~ s/\./_/g; ! print " printf(\"$field: ".&formatstring($type, $bitlength, 0)."\\n\",data->$field);\n"; } --- 386,390 ---- #push(@format, &formatstring($type, $bitlength, 0)); $field =~ s/\./_/g; ! print " printf(\"$I$field: ".&formatstring($type, $bitlength, 0)."\\n\",data->$field);\n"; } *************** *** 366,370 **** sub gen_struct() { ! print "struct _$java_classname {\n"; ## todo move this to sub print_msg_struct(). --- 400,404 ---- sub gen_struct() { ! print "struct _$structname {\n"; ## todo move this to sub print_msg_struct(). *************** *** 437,446 **** $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"; --- 471,480 ---- $field =~ s/\./_/g; print "void\n"; ! print "$structname\_set\_$field($structname * userdata, $ctype $field) {\n"; print " userdata->$field = $field;\n"; print "}\n\n"; #### Get methods print "$ctype\n"; ! print "$structname\_get\_$field($structname * userdata) {\n"; print " return userdata->$field;\n"; print "}\n\n"; |