[Tinyos-commits] CVS: tinyos-1.x/tos/lib/VM/languages/tinysql lex.mll, 1.2, 1.3 sqlgen.ml, 1.5, 1.6 tinysql, 1.2, 1.3 TextLogger.java, 1.1, NONE parse.mli, 1.1, NONE tsqlcc, 1.1, NONE

David Gay idgay at users.sourceforge.net
Sat Oct 29 15:58:43 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/tinysql
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10151

Modified Files:
	lex.mll sqlgen.ml tinysql 
Removed Files:
	TextLogger.java parse.mli tsqlcc 
Log Message:
tinysql command
nicer error messages


Index: lex.mll
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/tinysql/lex.mll,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** lex.mll	23 Sep 2005 16:17:35 -0000	1.2
--- lex.mll	29 Oct 2005 22:58:41 -0000	1.3
***************
*** 1,27 ****
  {
  open Parse
  exception Eof
  }
  rule token = parse
      [' ' '\t' '\n']     { token lexbuf }     (* skip blanks *)
!   | ['0'-'9']+ as lxm { INT (int_of_string lxm) }
!   | "select"	   { SELECT }
!   | "where"	   { WHERE }
!   | "interval"	   { INTERVAL }
!   | "sample"' '+"period" { INTERVAL }
!   | ','		   { SCOMMA }
!   | '<'		   { SLT }
!   | "<="	   { SLE }
!   | '>'		   { SGT }
!   | ">="	   { SGE }
!   | '='		   { SEQ }
!   | "<>"	   { SNE }
!   | "and"	   { SAND }
!   | "or"	   { SOR }
!   | "not"	   { SNOT }
!   | '('		   { OPAREN }
!   | ')'		   { CPAREN }
!   | '['		   { OPAREN2 }
!   | ']'		   { CPAREN2 }
!   | ['A'-'Z' 'a'-'z']['A'-'Z' 'a'-'z' '0'-'9']* as id { ID id }
    | eof            { raise Eof }
--- 1,33 ----
  {
  open Parse
+ open Sql
  exception Eof
+ let lastpos = ref Lexing.dummy_pos
+ let lasttoken = ref ""
+ let savepos lb = 
+   lastpos := Lexing.lexeme_start_p lb;
+   lasttoken := Lexing.lexeme lb  
  }
  rule token = parse
      [' ' '\t' '\n']     { token lexbuf }     (* skip blanks *)
!   | ['0'-'9']+ as lxm { savepos lexbuf; INT (int_of_string lxm) }
!   | "select"	   { savepos lexbuf; SELECT }
!   | "where"	   { savepos lexbuf; WHERE }
!   | "interval"	   { savepos lexbuf; INTERVAL }
!   | "sample"' '+"period" { savepos lexbuf; INTERVAL }
!   | ','		   { savepos lexbuf; SCOMMA }
!   | '<'		   { savepos lexbuf; SLT }
!   | "<="	   { savepos lexbuf; SLE }
!   | '>'		   { savepos lexbuf; SGT }
!   | ">="	   { savepos lexbuf; SGE }
!   | '='		   { savepos lexbuf; SEQ }
!   | "<>"	   { savepos lexbuf; SNE }
!   | "and"	   { savepos lexbuf; SAND }
!   | "or"	   { savepos lexbuf; SOR }
!   | "not"	   { savepos lexbuf; SNOT }
!   | '('		   { savepos lexbuf; OPAREN }
!   | ')'		   { savepos lexbuf; CPAREN }
!   | '['		   { savepos lexbuf; OPAREN2 }
!   | ']'		   { savepos lexbuf; CPAREN2 }
!   | ['A'-'Z' 'a'-'z']['A'-'Z' 'a'-'z' '0'-'9']* as id { savepos lexbuf; ID id }
    | eof            { raise Eof }

Index: sqlgen.ml
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/tinysql/sqlgen.ml,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** sqlgen.ml	23 Sep 2005 16:17:35 -0000	1.5
--- sqlgen.ml	29 Oct 2005 22:58:41 -0000	1.6
***************
*** 271,274 ****
--- 271,283 ----
      count
  
+ let print_error () = 
+   let error_column = (!Lex.lastpos).Lexing.pos_cnum + 1 in
+     if String.length !Lex.lasttoken > 0 then
+       eprintf "syntax error near \"%s\" (column %d)\n" !Lex.lasttoken error_column
+     else
+       eprintf "syntax error near column %d\n" error_column;
+     exit 2
+ 
+ 
  let _ = 
    try
***************
*** 277,280 ****
          sqlprint result;
          sqlgen result
!   with Lex.Eof ->
!     print_string "oops"; exit 0
--- 286,289 ----
          sqlprint result;
          sqlgen result
!   with x ->
!     print_error ()

Index: tinysql
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/tinysql/tinysql,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** tinysql	29 Oct 2005 20:27:16 -0000	1.2
--- tinysql	29 Oct 2005 22:58:41 -0000	1.3
***************
*** 9,14 ****
      if (/^-/) {
  	if (/^-h$/ || /^--help$/) {
! 	    &usage();
! 	    exit 0;
  	}
      }
--- 9,13 ----
      if (/^-/) {
  	if (/^-h$/ || /^--help$/) {
! 	    usage();
  	}
      }
***************
*** 21,65 ****
  	}
  	else {
! 	    print "Ignoring extra argument $_\n";
  	}
      }
  }
  
  $tmpf = "/tmp/tinysql.$$";
  $qfile = "$ENV{HOME}/.tinysql_query";
  
  sub END {
!     print "exiting!\n";
  }
  
  if ($action eq "start") {
      $install = 1;
      $log = 1; 
  }
! 
! if ($action eq "log") {
      $display = 1;
      $log = 1;
  }
  
! if ($action eq "compile") {
!     system("echo \"$query\" | sqlgen | tee $tmpf");
!     system("mload -c $tmpf");
!     exit 0;
  }
  
! if ($action eq "install" || $install) {
!     system("echo \"$query\" | sqlgen > $qfile");
!     system("mload $qfile");
  }
  
! if ($action eq "display" || $display) {
      $query = current_query();
      print "#QUERY: $query\n" if $query;
      print "No active query\n" if !$query;
  
  if ($log) {
!     $query = current_query();
!     exit 1 if !$query;
  }
  
--- 20,102 ----
  	}
  	else {
! 	    usage();
  	}
      }
  }
  
+ usage() unless $action;
+ 
  $tmpf = "/tmp/tinysql.$$";
  $qfile = "$ENV{HOME}/.tinysql_query";
  
  sub END {
!     unlink $tmpf;
  }
  
  if ($action eq "start") {
      $install = 1;
+     $mote_install = 1;
      $log = 1; 
  }
! elsif ($action eq "log") {
      $display = 1;
      $log = 1;
  }
+ elsif ($action eq "compile") {
+     $compile = 1;
+ }
+ elsif ($action eq "install") {
+     $install = 1;
+     $mote_install = 1;
+ }
+ elsif ($action eq "reinstall") {
+     $mote_install = 1;
+     $display = 1;
+ }
+ elsif ($action eq "display") {
+     $display = 1;
+ }
+ elsif ($action eq "stop") {
+     $stop = 1;
+ }
+ else {
+     usage();
+ }
  
! if ($compile) {
!     exit 2 if system("echo \"$query\" | tinysqlcc > $tmpf");
!     system("cat $tmpf");
!     exit 2 if system("motlle-load -c $tmpf");
  }
  
! if ($install) {
!     exit 2 if system("echo \"$query\" | tinysqlcc > $qfile");
  }
  
! if ($display) {
      $query = current_query();
      print "#QUERY: $query\n" if $query;
      print "No active query\n" if !$query;
+ }
+ 
+ if ($mote_install) {
+     if (-f $qfile) {
+ 	exit 2 if system("motlle-load $qfile");
+     }
+     else {
+ 	exit 2;
+     }
+ }
  
  if ($log) {
!     $schema = current_schema();
!     print "#SCHEMA: $schema\n";
!     exit 1 if !$schema;
!     tsqllog($schema);
! }
! 
! if ($stop) {
!     unlink $qfile;
!     exit 2 if system("motlle-load -e \"led(0)\"");
  }
  
***************
*** 67,71 ****
  
  sub usage {
!     print <<!
  Usage: tinysql start QUERY: install QUERY followed by log
                 install QUERY: install QUERY in the sensor network
--- 104,108 ----
  
  sub usage {
!     print <<EOF
  Usage: tinysql start QUERY: install QUERY followed by log
                 install QUERY: install QUERY in the sensor network
***************
*** 74,78 ****
                 stop: stop current query in sensor network
                 display: display current query
!                check QUERY: verify syntax of QUERY
  
    QUERY is a TinySQL query
--- 111,116 ----
                 stop: stop current query in sensor network
                 display: display current query
!                compile QUERY: just compile QUERY
!                               prints resulting motlle code
  
    QUERY is a TinySQL query
***************
*** 84,92 ****
      tinysql start "select id, light interval 10"
      tinysql compile "oops"
! !;
      exit 0;
  }
  
  sub current_query {
      my $schema;
  
--- 122,142 ----
      tinysql start "select id, light interval 10"
      tinysql compile "oops"
! EOF
! ;
      exit 0;
  }
  
  sub current_query {
+     my $query;
+ 
+     open QUERY, $qfile or return undef;
+     while (<QUERY>) {
+ 	$query = $1 if m!^// (SELECT .*)!;
+     }
+     close QUERY;
+     return $query;
+ }
+ 
+ sub current_schema {
      my $schema;
  
***************
*** 99,108 ****
  }
  
! sf_connect(BASE, "localhost", 9001);
! close(BASE);
  
! sub send_base { sf_send(BASE, $_[0]); }
! sub recv_base { return sf_recv(BASE, $_[0]); }
  
  
  # Build a TOSMsg in a perl string
--- 149,181 ----
  }
  
! sub tsqllog {
!     my ($schema) = @_;
!     my @schema = split / /, $schema;
  
!     sf_connect(BASE, "localhost", 9001);
!     for (;;) {
! 	my $packet = sf_recv(BASE, undef);
! 	my ($dest, $amid, $group, $length, $msg) = unpack_message $packet;
! 	my $offset;
  
+ 	if ($amid == 0x2b || $amid == 0x2c) {
+ 	    $offset = 12;
+ 	}
+ 	elsif ($amid == 0x2a) {
+ 	    $offset = 5;
+ 	}
+ 	else {
+ 	    next;
+ 	}
+ 	if (2 * ($#schema + 1) != $length - $offset) {
+ 	    print "#invalid packet\n";
+ 	    next;
+ 	}
+ 	my @fields = unpack ("v" x ($#schema + 1), substr $msg, $offset);
+ 	print join(" ", @fields);
+ 	print "\n";
+     }
+     close(BASE);
+ }
  
  # Build a TOSMsg in a perl string
***************
*** 145,182 ****
  }
  
- # Start a serial forwarder
- sub sf_start {
-     my ($port, $comm) = @_;
- 
-     $pid = fork();
-     die "can't fork" unless defined($pid);
- 
-     return $pid if $pid;
- 
-     exec "java net.tinyos.sf.SerialForwarder -comm $comm -port $port";
-     die "couldn't start serial forwarder";
- }
- 
- # Wait for a serial forwarder to start
- sub sf_wait {
-     my ($host, $port) = @_;
-     my ($lhost, $ptcp);
- 
-     $lhost = inet_aton($host) || die "can't lookup $host";
-     $ptcp = getprotobyname("tcp");
-     socket(TEMP, PF_INET, SOCK_STREAM, $ptcp) || die "SF socket";
-     $sin = sockaddr_in($port, $lhost);
- 
-     for ($tries = 0; $tries < 20; $tries++) {
- 	$sin = sockaddr_in($port, $lhost);
- 	if (connect(TEMP, $sin)) {
- 	    close(TEMP);
- 	    return;
- 	}
- 	sleep 1;
-     }
-     die "serial forwarder at $host:$port didn't show up\n";
- }
- 
  # Write a string to a handle, abort on error
  sub sf_write {
--- 218,221 ----

--- TextLogger.java DELETED ---

--- parse.mli DELETED ---

--- tsqlcc DELETED ---



More information about the Tinyos-commits mailing list