[Tinyos-commits] CVS: tinyos-1.x/tos/lib/VM/languages/tinysql Makefile.am, NONE, 1.1 .cvsignore, 1.1, 1.2 tinysql, 1.1, 1.2 Makefile, 1.1, NONE

David Gay idgay at users.sourceforge.net
Sat Oct 29 13:27:18 PDT 2005


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

Modified Files:
	.cvsignore tinysql 
Added Files:
	Makefile.am 
Removed Files:
	Makefile 
Log Message:
configure land - setup VM to have installable files (currently motlle and
tinysql support stuff)


--- NEW FILE: Makefile.am ---
AUTOMAKE_OPTIONS = foreign

bin_PROGRAMS = tinysqlcc$(EXEEXT)

bin_SCRIPTS = tinysql

tinysqlcc$(EXEEXT): lex.mll parse.mly sql.mli sqlgen.ml
	ocamlyacc parse.mly
	ocamllex lex.mll
	ocamlc -o $@ sql.mli parse.mli parse.ml lex.ml sqlgen.ml

Index: .cvsignore
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/tinysql/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** .cvsignore	11 Jan 2005 18:52:07 -0000	1.1
--- .cvsignore	29 Oct 2005 20:27:16 -0000	1.2
***************
*** 1,2 ****
--- 1,4 ----
+ Makefile
+ Makefile.in
  *.cm*
  lex.ml
***************
*** 4,5 ****
--- 6,8 ----
  parse.ml
  sqlgen
+ .deps

Index: tinysql
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/lib/VM/languages/tinysql/tinysql,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** tinysql	29 Oct 2005 17:24:23 -0000	1.1
--- tinysql	29 Oct 2005 20:27:16 -0000	1.2
***************
*** 1,3 ****
--- 1,8 ----
  #!/usr/bin/perl
+ 
+ use Socket;
+ 
+ $BROADCAST = 0xffff;
+ 
  for ($i = 0; $i <= $#ARGV; $i++) {
      $_ = $ARGV[$i];
***************
*** 21,27 ****
  }
  
! $tmpf = "xxx";
  $qfile = "$ENV{HOME}/.tinysql_query";
  
  if ($action eq "start") {
      $install = 1;
--- 26,36 ----
  }
  
! $tmpf = "/tmp/tinysql.$$";
  $qfile = "$ENV{HOME}/.tinysql_query";
  
+ sub END {
+     print "exiting!\n";
+ }
+ 
  if ($action eq "start") {
      $install = 1;
***************
*** 29,32 ****
--- 38,46 ----
  }
  
+ if ($action eq "log") {
+     $display = 1;
+     $log = 1;
+ }
+ 
  if ($action eq "compile") {
      system("echo \"$query\" | sqlgen | tee $tmpf");
***************
*** 40,53 ****
  }
  
! if ($action eq "log" || $log) {
!     open QUERY, $qfile or die;
!     while (<>) {
! 	if (m!^// SCHEMA: (.*)!) {
! 	    #@schema = split / /, $1;
! 	    $schema = $1;
! 	}
      }
      close QUERY;
!     die if !defined(@schema);
!     system("java TextLogger $schema");
  }
--- 54,239 ----
  }
  
! 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;
! }
! 
! exit 0;
! 
! sub usage {
!     print <<!
! Usage: tinysql start QUERY: install QUERY followed by log
!                install QUERY: install QUERY in the sensor network
!                reinstall: reinstall current query in the sensor network
!                log: display continuous results from current query
!                stop: stop current query in sensor network
!                display: display current query
!                check QUERY: verify syntax of QUERY
! 
!   QUERY is a TinySQL query
! 
!   start, install, reinstall, log and stop require that a serial forwarder,
!   talking to TinySQL mote 0 be running on the local host.
! 
!   Examples:
!     tinysql start "select id, light interval 10"
!     tinysql compile "oops"
! !;
!     exit 0;
! }
! 
! sub current_query {
!     my $schema;
! 
!     open QUERY, $qfile or return undef;
!     while (<QUERY>) {
! 	$schema = $1 if m!^// SCHEMA: (.*)!;
      }
      close QUERY;
!     return $schema;
! }
! 
! 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
! sub message {
!     my ($dest, $amid, @data) = @_;
!     my ($msg);
! 
!     return pack "vCCCC*", $dest, $amid, 0, $#data + 1, @data;
! }
! 
! sub unpack_message {
!     my ($msg) = @_;
! 
!     return unpack "vCCCC*", $msg;
! }
! 
! sub print_message {
!     my ($msg) = @_;
! 
!     for ($i = 0; $i < length $msg; $i++) {
! 	printf "%02x ", ord(substr($msg, $i, 1));
!     }
! }
!     
! 
! # Connect to a serial forwarder
! sub sf_connect {
!     my ($handle, $host, $port) = @_;
!     my ($lhost, $ptcp);
! 
!     $lhost = inet_aton($host) || die "can't lookup $host";
!     $ptcp = getprotobyname("tcp");
!     socket($handle, PF_INET, SOCK_STREAM, $ptcp) || die "SF socket";
!     connect($handle, sockaddr_in($port, $lhost)) || die "No serial forwarder at $host:$port";
!     # Send identifying string ('T', ' ' for original version)
!     sf_write($handle, "T ");
!     $s = sf_read($handle, 2);
!     die "Not a serial forwarder at $host:$port" unless
! 	substr($s, 0, 1) eq "T" && ord(substr($s, 1)) >= 32;
! }
! 
! # 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 {
+     my ($handle, $string) = @_;
+ 
+     while ($string ne "") {
+ 	$cnt = syswrite($handle, $string);
+ 	if (!$cnt) {
+ 	    print "write error $! $cnt\n";
+ 	    exit 2;
+ 	}
+ 	$string = substr($string, $cnt);
+     }
+ }
+ 
+ # Read n bytes from a handle, abort on error and timeout
+ sub sf_read {
+     my ($handle, $n, $timeout) = @_;
+     my ($s, $offset, $rin);
+ 
+     $offset = 0;
+     vec($rin, fileno($handle), 1) = 1;
+     while ($offset < $n) {
+ 	$cnt = select($rin, undef, undef, $timeout);
+ 	if (!$cnt) {
+ 	    print "read error: timeout\n";
+ 	    exit 2;
+ 	}
+ 	$cnt = sysread $handle, $s, $n, $offset;
+ 	if (!$cnt) {
+ 	    print "read error $cnt $!\n";
+ 	    exit 2;
+ 	}
+ 	$offset += $cnt;
+     }
+     return $s;
+ }
+ 
+ # Send a packet to a serial forwarder
+ sub sf_send {
+     my ($handle, $msg) = @_;
+ 
+     $msg = chr(length $msg) . $msg;
+     sf_write($handle, $msg);
+ }
+ 
+ # Receive a packet from a serial forwarder
+ sub sf_recv {
+     my ($handle, $timeout) = @_;
+     my ($s);
+ 
+     $len = ord(sf_read($handle, 1, $timeout));
+     $s = sf_read($handle, $len, $timeout);
+ 
+     # Set group id to 0 to simplify life
+     substr($s, 3, 1) = chr(0);
+ 
+     return $s;
+ }
+ 

--- Makefile DELETED ---



More information about the Tinyos-commits mailing list