def _open(self): # Fix this hard coded path for detecting the usb moubt # use dmesg maybe mp = devices.get_mount_points() # last device mounted path if mp and len(mp) > 0: dev = mp[len(mp)-1][1] else: dev = 'sda1' mountpath = os.path.join(dev, 'arduino') #'{device}/arduino/'.format(device=dev) mount = os.path.join(mountpath, 'mount.txt') upodfile = os.path.join(mountpath, self.filename) if not os.path.exists(mount): return None exists = os.path.exists(upodfile) stream = open(upodfile, 'a') writer = csv.writer(stream) # write header if it's a new file if not exists: writer.writerow(self.header) return stream
def _open(self): # Fix this hard coded path for detecting the usb moubt # use dmesg maybe mp = devices.get_mount_points() # last device mounted path if mp and len(mp) > 0: dev = mp[len(mp) - 1][1] else: dev = 'sda1' mountpath = os.path.join( dev, 'arduino') #'{device}/arduino/'.format(device=dev) mount = os.path.join(mountpath, 'mount.txt') print 'mount:', mount upodfile = os.path.join(mountpath, self.filename) if not os.path.exists(mount): print 'no file' return None exists = os.path.exists(upodfile) stream = open(upodfile, 'a') writer = csv.writer(stream) # write header if it's a new file if not exists: writer.writerow(self.header) return stream
def main(*argv): # set the current thread id threading.current_thread().name = 'Server-Thread' # install signal handler signal.signal(signal.SIGINT, signal_handler) # log.info('Installed signal handler') # setup event for thread synchronization event = threading.Event() # get communication channel to ATMega channel = bridgeclient() # setup data processing thread processor = DataProcessor(name='DataProcessor-Thread', event=event, bridge=channel) processor.start() # log.info('Launched Data processor thread') if not channel: # log.critical('unable to setup bridgeclient to ATMega!') return # TODO: Explore BridgeClient code # Performance: keep the socket open while subsequent get(...) operations # By default BridgeClient open socket at begin of get(...) and closes after get(...) channel.should_close_at_function_end = False last_seen = '' # Get data from the Tx-channel and post it the queue while True: try: data = channel.get('TX-channel') mp = devices.get_mount_points() status = 'F' if len(mp) > 0: status = 'T' channel.put('status', status) # Time stamp is a part of data contract between # ATMega and Atheros. This makes sure that data # is different from that of previous data # Prevent duplicate data read on the bridgeclient before it's refeshed if data == last_seen: continue queue.put(data) last_seen = data event.set() except Exception, e: # log.exception(e) # log.warning('Continue by ignoring the above exception!') # try to re-initialize the ATMega communication channel channel = bridgeclient() processor.channel = channel time.sleep(.7)