Commits

Anonymous committed 282eb6a

Add start/stop time to log. Fix enable for gyro. Kill logging properly.

  • Participants
  • Parent commits 3817382

Comments (0)

Files changed (1)

File sensors/SensorTag.py

         if not self.gatttool:
             self.error = "ERROR: gatttool must be installed.\n"
         self.tags = dict()
-        self.SENSORS = "sensors/SENSORS"
+        self.SENSORS = os.getcwd() + "/sensors/SENSORS"
+        self.log = ""
 
     def get_error(self):
         return self.error    
             timestamp = str(time())[0:-3]
             log_file = os.getcwd() + '/log/' + timestamp + '.run' 
             log = open(log_file,"w+")
+            self.log = log
             log.write("STARTING RUN @" + timestamp)
             subprocess.call([self.hciconfig,"hci0","reset"]) 
             for sensor in sensors:
                 sensor = sensor.rstrip()
-                log_name = os.getcwd() + '/log/' + sensor + '.data'
+                log_name = os.getcwd() + "/log/" + sensor + "_" + timestamp + ".data"
                 connection = pexpect.spawn('/bin/bash -c "gatttool -b ' + \
                     sensor + ' -I | tee ' + log_name + '"')
                 connection.logfile = log
                 self.tags[sensor] = connection
             sensors.close()
         except IOError:
-            print "ERROR: Static Sensor Tag file does not exist."
-            exit(-1)
+            self.error = "ERROR: Static Sensor Tag file does not exist."
     
     def enable(self):
         enable_accelerometer = '31 01'
         stream_accelerometer = '2E 0100'
         enable_magnetomer = '44 01'
         stream_magnetomer = '41 0100'
-        enable_gyroscope = '5B 01'
-        stream_gyroscope = '58 0700'
+        enable_gyroscope = '5B 07'
+        stream_gyroscope = '58 0100'
         for tag in self.tags.values():
             tag.sendline('char-write-cmd ' + enable_accelerometer) 
             tag.expect('\r\n')
             tag.expect('\r\n')
             tag.sendline('char-write-cmd ' + stream_gyroscope) 
             tag.expect('\r\n')
+        start_timestamp = str(time())[0:-3]
+        self.log.write("ENABLED @" + start_timestamp)
 
     def disable(self):
         disable_accelerometer = '31 00'
             tag.sendline('char-write-cmd ' + stream_gyroscope) 
             tag.expect('\r\n')
             tag.__del__()
+        stop_timestamp = str(time())[0:-3]
+        self.log.write("DISABLED @" + stop_timestamp)
+        subprocess.call(["sudo","pkill","tee"])