Exemplo n.º 1
0
 public BRCache(
     String serverAddress,
     boolean useArchive,
     int numCacheFrames,
     int numArchiveFrames,
     boolean newArchive,
     int debugI) {
   debug = debugI;
   // create source connection
   try {
     String mode = "none";
     if (useArchive) {
       if (newArchive) mode = "create";
       else mode = "append";
     }
     source = new Source(numCacheFrames, mode, numArchiveFrames);
     source.OpenRBNBConnection(serverAddress, cacheName);
     cacheName = source.GetClientName();
     if (debug > 2) System.err.println("BRCache source: " + source);
   } catch (Exception e) {
     System.err.println("Exception creating cache: " + e.getMessage());
     e.printStackTrace();
     RBNBProcess.exit(0);
   }
   if (debug > 0) System.err.println("Started BRCache...");
 }
Exemplo n.º 2
0
 /** Connect to the RBNB * */
 public void connect() {
   if (connected) return;
   try {
     // Create a source and connect:
     if (archiveSize > 0) source = new Source(cacheSize, "append", archiveSize);
     else source = new Source(cacheSize, "append", 0);
     System.out.println(getServer());
     // source.OpenRBNBConnection(getServer(),rbnbSourceName);
     source.OpenRBNBConnection("128.180.53.5:3333", rbnbSourceName);
     connected = true;
     System.out.println(
         "Connecting to SCRAMNetSource with..."
             + "\n RBNB Server = "
             + getServer()
             + "\n RBNB Cache Size = "
             + cacheSize
             + "\n RBNB Archive Size = "
             + archiveSize
             + "\n RBNB Source name = "
             + rbnbSourceName
             + "\n Number of channels = "
             + rbnbChannelNames.length
             + "\n Delay between frames = "
             + ((float) delay / 1000F)
             + "s"
             + "\n RBNB Frame Size = "
             + (rbnbChannelNames.length * 4 * 1000 / delay)
             + " bytes");
   } catch (SAPIException se) {
     se.printStackTrace();
   }
 }
Exemplo n.º 3
0
  /** @param args the command line arguments */
  @SuppressWarnings("static-access")
  public static void main(String[] args) {
    String hostname = "localhost:3333";
    String portName = "/dev/tty.KeySerial1";
    String srcName = "ADXL-RBNB Accelerometer";
    String[] chanNames = {"X", "Y"};
    int[] chanIdx = {0, 1};
    double[] vals = {0, 0};
    String unitsMetadata = "units=G,scale=1,offset=0";
    Source source;
    ChannelMap cmap;
    int cacheSize = 10240; // ! @todo parse from command line
    int archiveSize = cacheSize * 10; // ! @todo parse from command line
    int idx;
    int chanCount = 2;
    ADXL chip;

    // Setup interrupt handler
    DoHook();

    System.out.println("Opening serial port");
    chip = new ADXL();
    if (chip.initialize(portName) == 0) {
      portConnected = true;
      System.out.println("Serial port initialized OK");
    } else {
      System.out.println("Error opening serial port");
      return;
    }

    // RBNB connection setup
    try {
      System.out.println("Opening connection to RBNB on " + hostname);
      // Create both a source and a sink, connect both:
      source = new Source(cacheSize, "append", archiveSize);
      source.OpenRBNBConnection(hostname, srcName);
      DTconnected = true;

      System.out.println("OK.");

      // Setup channel map - names of channels, units
      cmap = new ChannelMap();
      for (idx = 0; idx < chanCount; idx++) {
        chanIdx[idx] = cmap.Add(chanNames[idx]);

        // Hardwired units (G) for all three sources
        cmap.PutUserInfo(chanIdx[idx], unitsMetadata);

        // Not sure if we still need the MIME type or not
        cmap.PutMime(chanIdx[idx], "application/octet-stream");
      }
      source.Register(cmap);
      source.Flush(cmap);
    } // We don't distinguish between errors in setup phase, just bail out
    catch (SAPIException se) {
      System.out.println("Error on Turbine - not connected");
      DTconnected = false;
      return;
    }

    // ********************************************************************
    // Main data loop: read, scale, write.
    try {
      System.out.println("Turbine connected, running. Press control-c to end");

      // Loop - runs until control-c or error.
      do {
        for (idx = 0; idx < chanCount; idx++) chanIdx[idx] = cmap.Add(chanNames[idx]);

        // Read the data from the accelerometer
        vals = chip.chipRead();

        // Timestamp all channels with client-side time
        cmap.PutTimeAuto("timeofday");

        for (idx = 0; idx < chanCount; idx++) {
          double valBuf[] = {vals[idx]};
          cmap.PutDataAsFloat64(cmap.GetIndex(chanNames[idx]), valBuf);
        }

        source.Flush(cmap);

        cmap.Clear();

        Thread.sleep(20);
      } while (!ctrlC);
    } catch (SAPIException mse) {
      System.out.println("Error saving data!");
      mse.printStackTrace();
    } catch (InterruptedException ie) {
      System.out.println("Interrupted, exiting.");
    }

    // Shutdown and exit
    if (portConnected) {
      chip.closePort(chip.serialPort);
    }
    if (DTconnected) {
      System.out.println("Closing RBNB connection");

      // Tell RBNB to keep the data once we close
      source.Detach();

      source.CloseRBNBConnection();
    }
    System.out.println("Done, exiting.");

    return;
  }