Android Open Source - IntelligentCarForAndroid Feature Streamer






From Project

Back to project page IntelligentCarForAndroid.

License

The source code is released under:

Apache License

If you think the Android project IntelligentCarForAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.davidsingleton.nnrccar;
/*from  w  w w. j av a 2  s  .  co  m*/
import android.util.Log;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.net.InetSocketAddress;



/**
 * Connects to a Driver app server via TCP and streams features over the network.
 */
class FeatureStreamer {
  private Socket sock;
  private DataOutputStream dos;
  
  FeatureStreamer() {
  }
  
  void connect(String addr, int port) {
    try {
      sock = new Socket();
      sock.connect(new InetSocketAddress(addr, port), 5000);
      dos = new DataOutputStream(sock.getOutputStream());
        Log.w("tag", "SUCEESSS");

    } catch (UnknownHostException e) {
        Log.w("tag", "failllled");

        e.printStackTrace();
    } catch (IOException e) {
        Log.w("tag", "failllled IOOOOO");

        e.printStackTrace();
    }
  }
  
  void sendByteArray(byte[] send) throws IOException {
    if (dos != null) {
      dos.writeInt(send.length);
      dos.write(send, 0, send.length);
      dos.flush();
    }
  }
  
  void sendFeatures(int width, int height, byte[] send, float[] accelerometerFeatures) {
    try {
      if (dos != null) {
        dos.writeInt(width);
        dos.writeInt(height);
        dos.writeInt(accelerometerFeatures.length);
        dos.write(send, 0, send.length);
        for (int i = 0; i < accelerometerFeatures.length; i++) {
          dos.writeFloat(accelerometerFeatures[i]);
        }
        dos.flush();
      }
    } catch (IOException e) {
    }
  }

  void close() throws IOException {
    if (dos != null) {
      dos.close();
    }
    if (sock != null) {
      sock.close();
    }
  }
};




Java Source Code List

org.davidsingleton.core.Driver.java
org.davidsingleton.core.FeatureCallback.java
org.davidsingleton.core.FeatureFrame.java
org.davidsingleton.core.FeatureServer.java
org.davidsingleton.core.FeatureWriter.java
org.davidsingleton.core.NeuralNetwork.java
org.davidsingleton.core.Predictor.java
org.davidsingleton.nnrccar.FeatureStreamer.java
org.davidsingleton.nnrccar.NNRCCarActivity.java