changeset 330:7ac6b8846eea

- some fixes for server code - don't turn off bluetooth in avr code
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jun 2012 22:32:49 +0800
parents 740438e21ea0
children 5de3fc71ce48
files main.c server/ts.py server/utils.py
diffstat 3 files changed, 45 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Mon Jun 04 23:50:42 2012 +0800
+++ b/main.c	Wed Jun 06 22:32:49 2012 +0800
@@ -57,6 +57,7 @@
 
 int uart_putchar(char c, FILE *stream);
 static void long_delay(int ms);
+static void blink();
 
 static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
         _FDEV_SETUP_WRITE);
@@ -138,7 +139,7 @@
     }
     else
     {
-        PORT_SHDN |= _BV(PIN_SHDN);
+        //PORT_SHDN |= _BV(PIN_SHDN);
     }
 }
 
@@ -181,11 +182,13 @@
 static void 
 uart_off()
 {
+#if 0
     // Turn of interrupts and disable tx/rx
     UCSR0B = 0;
 
     // Power reduction register
     //PRR |= _BV(PRUSART0);
+#endif
 }
 
 int 
@@ -463,6 +466,20 @@
 ISR(INT0_vect)
 {
 	need_comms = 1;
+    blink();
+    _delay_ms(100);
+    blink();
+    _delay_ms(100);
+    blink();
+    _delay_ms(100);
+    blink();
+    _delay_ms(100);
+    blink();
+    _delay_ms(100);
+    blink();
+    _delay_ms(100);
+    blink();
+    _delay_ms(100);
 }
 
 
@@ -652,6 +669,7 @@
 do_comms()
 {
 	// turn on bluetooth
+    set_aux_power(1);
     uart_on();
 	
 	// write sd card here? same 3.3v regulator...
--- a/server/ts.py	Mon Jun 04 23:50:42 2012 +0800
+++ b/server/ts.py	Wed Jun 06 22:32:49 2012 +0800
@@ -5,6 +5,8 @@
 # time that the bluetooth takes to get going?
 EXTRA_WAKEUP = 0
 
+FETCH_TRIES = 3
+
 # avoid turning off the bluetooth etc.
 TESTING = True
 
@@ -25,11 +27,14 @@
     if lightblue:
         s = lightblue.socket()
         s.connect((addr, 1))
+        s.settimeout(3)
     else:
         s = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
         s.connect((addr, 1))
 
-    s.setnonblocking(True)
+    s.setblocking(False)
+
+    time.sleep(30)
 
     return s
 
@@ -53,6 +58,7 @@
 
 @retry()
 def fetch(sock):
+    print "fetch"
     sock.send("fetch\n")
 
     crc = 0
@@ -65,7 +71,7 @@
     crc = crc16(l, crc)
     lines.append(l)
 
-    while true:
+    while True:
         l = readline(sock)
 
         crc = crc16(l, crc)
@@ -75,6 +81,8 @@
 
         lines.append(l)
 
+    print lines
+
     l = readline(sock)
     recv_crc = None
     try:
@@ -139,7 +147,7 @@
 def sleep_for(secs):
     until = monotonic_time() + secs
     while True:
-        length = until < monotonic_time()
+        length = until - monotonic_time()
         if length <= 0:
             return
         time.sleep(length)
--- a/server/utils.py	Mon Jun 04 23:50:42 2012 +0800
+++ b/server/utils.py	Wed Jun 06 22:32:49 2012 +0800
@@ -4,6 +4,12 @@
 import time
 import select
 
+lightblue = None
+try:
+    import lightblue
+except ImportError:
+    pass
+
 DEFAULT_TRIES = 3
 READLINE_SELECT_TIMEOUT = 20
 
@@ -57,13 +63,17 @@
 def readline(sock):
     timeout = READLINE_SELECT_TIMEOUT
     buf = ''
-    while true:
-        (rlist, wlist, xlist) = select.select([sock], [], [], timeout)
-        if sock not in rlist:
-            # hit timeout
-            return None
+    while True:
+        if not lightblue:
+            (rlist, wlist, xlist) = select.select([sock], [], [], timeout)
+            if sock not in rlist:
+                # hit timeout
+                return None
 
         c = sock.recv(1)
+        if c == '':
+            # lightblue timeout
+            return None
         if c == '\r':
             continue