Beispiel #1
0
def toplevel():
    # configure syslog
    syslog.openlog(ident="blue-raven", logoption=syslog.LOG_PID)
    syslog.syslog(syslog.LOG_INFO, 'starting up')

    # Allocate an element that broadcasts raw Rainforest packets
    usb = usbio.USBIO()
    
    # Allocate an element that collects bits of XML until a complete XML
    # fragment (<tag>...</tag>) has been assembled.  Then broadcast the
    # fragment as a single message to its listeners.
    rfc = raven_fragment_collector.RavenFragmentCollector()
    
    # Wrap the XML fragments in a format understood by the weMonitor API
    wmf = we_monitor_formatter.WeMonitorFormatter()
    
    # Allocate an element that POSTs XML fragments to the weMonitor 
    # Rainforest API
    wmw = we_monitor_writer.WeMonitorWriter()
    
    # For debugging, allocate an element that simply echos its input
    # to stdout.
    # ech = echo.Echo()
    
    # String the elements together and start the reader thread.
    usb.attach(rfc).attach(wmf).attach(wmw) # .attach(ech)

    # If you prefer to see the raw XML as it arrives from the USB
    # device. comment out the above line and uncomment this line.
    # usb.attach(rfc).attach(ech).attach(wmf).attach(wmw)

    # Sending an 'initialize' message causes the RAVEn to synchronize its
    # XML output -- without that, it sends an arbitrary number of partial
    # packets and lots of nulls.  (The initialize message also elicits an
    # "Unknown command" response, but that appears to be benign.)
    usb.update(commands.initialize())
    
    # Start the reader thread
    syslog.syslog(syslog.LOG_INFO, 'launching reader thread')
    usb.start()
    # Send a GET_DEVICE_INFO message to get a DeviceInfo response.
    time.sleep(1)
    usb.update(commands.get_device_info())
    
    # Should never get here...
    usb.thread.join()
Beispiel #2
0
print("writing XML output to " + sys.argv[1])

# Allocate an element that collects bits of XML until a complete XML
# fragment (<tag>...</tag>) has been assembled.  Then broadcast the
# fragment as a single message to its listeners.
fw = file_writer.FileWriter(sys.argv[1])

# For debugging, allocate an element that simply echos its input
# to stdout.
ech = echo.Echo()

# String the elements together and start the reader thread.
usb.attach(fw).attach(ech)

# Sending an 'initialize' message causes the RAVEn to synchronize its
# XML output -- without that, it sends an arbitrary number of partial
# packets and lots of nulls.  (The initialize message also elicits an
# "Unknown command" response, but that appears to be benign.)
usb.update(commands.initialize())

# Start the reader thread
usb.start()

# Send a GET_DEVICE_INFO message to get a DeviceInfo response.
time.sleep(1)
usb.update(commands.get_device_info())

# Should never get here...
usb.thread.join()