public class

NetworkVehicleInterface

extends BytestreamDataSource
implements VehicleInterface
java.lang.Object
   ↳ com.openxc.sources.BaseVehicleDataSource
     ↳ com.openxc.sources.ContextualVehicleDataSource
       ↳ com.openxc.sources.BytestreamDataSource
         ↳ com.openxc.interfaces.network.NetworkVehicleInterface

Class Overview

A vehicle data source reading measurements from an OpenXC network device. This class looks for a network device and expects to read OpenXC-compatible, newline separated JSON messages.

Summary

[Expand]
Inherited Constants
From class com.openxc.sources.BytestreamDataSource
[Expand]
Inherited Fields
From class com.openxc.sources.BytestreamDataSource
Public Constructors
NetworkVehicleInterface(SourceCallback callback, Context context, URI uri)
Construct an instance of NetworkVehicleInterface with a receiver callback and custom device URI.
NetworkVehicleInterface(Context context, URI uri)
NetworkVehicleInterface(Context context, String uriString)
Public Methods
boolean isConnected()
Return true if the data source is actively connected to its target, be it a USB endpoint, a Bluetooth channel, a trace file, etc.
boolean setResource(String otherResource)
Change the resource used by the instance to connect to the interface, restarting any neccessary services.
String toString()
static boolean validateResource(String uriString)
Return true if the address and port are valid.
Protected Methods
void connect()
Initiate a connection to the vehicle interface.
void disconnect()
Perform any cleanup necessary to disconnect from the interface.
String getTag()
Return a string suitable as a tag for logging.
int read(byte[] bytes)
Read data from the source into the given array.
synchronized boolean write(byte[] bytes)
Writes given data to the socket.
[Expand]
Inherited Methods
From class com.openxc.sources.BytestreamDataSource
From class com.openxc.sources.ContextualVehicleDataSource
From class com.openxc.sources.BaseVehicleDataSource
From class java.lang.Object
From interface com.openxc.DataPipeline.Operator
From interface com.openxc.interfaces.VehicleInterface
From interface com.openxc.sinks.VehicleDataSink
From interface com.openxc.sources.VehicleDataSource
From interface java.lang.Runnable

Public Constructors

public NetworkVehicleInterface (SourceCallback callback, Context context, URI uri)

Construct an instance of NetworkVehicleInterface with a receiver callback and custom device URI. If the device cannot be found at initialization, the object will block waiting for a signal to check again.

Parameters
callback An object implementing the SourceCallback that should receive data as it is received and parsed.
context The Activity or Service context, used to get access to the Android NetworkManager.
uri The network host's address.
Throws
DataSourceException If no connection could be established

public NetworkVehicleInterface (Context context, URI uri)

public NetworkVehicleInterface (Context context, String uriString)

Public Methods

public boolean isConnected ()

Return true if the data source is actively connected to its target, be it a USB endpoint, a Bluetooth channel, a trace file, etc. The source is capable of providing new vehicle data. Returns true if connected, false otherwise.

public boolean setResource (String otherResource)

Change the resource used by the instance to connect to the interface, restarting any neccessary services.

Parameters
otherResource The new resource to use for the interface.
Returns
  • true if the resource was different and the interface was restarted.

public String toString ()

public static boolean validateResource (String uriString)

Return true if the address and port are valid.

Returns
  • true if the address and port are valid.

Protected Methods

protected void connect ()

Initiate a connection to the vehicle interface.

protected void disconnect ()

Perform any cleanup necessary to disconnect from the interface.

protected String getTag ()

Return a string suitable as a tag for logging.

protected int read (byte[] bytes)

Read data from the source into the given array. No more than bytes.length bytes will be read, and there is no guarantee that any bytes will be read at all.

Parameters
bytes the destination array for bytes from the data source.
Returns
  • the number of bytes that were actually copied into bytes.
Throws
IOException

protected synchronized boolean write (byte[] bytes)

Writes given data to the socket.

Parameters
bytes data to write to the socket.
Returns
  • true if the data was written successfully.