ESP  0.1
The Example-based Sensor Predictions (ESP) system tries to bring machine learning to the maker community.
TcpOStream Class Reference

Send strings over a TCP socket based on pipeline predictions. More...

#include <ostream.h>

Inheritance diagram for TcpOStream:
OStreamVector OStream Stream

Public Member Functions

 TcpOStream (string server, int port)
 
 TcpOStream (string server, int port, std::map< uint32_t, string > tcp_stream_mapping)
 
 TcpOStream (string server, int port, uint32_t count,...)
 
virtual void onReceive (uint32_t label)
 
virtual void onReceive (vector< double > data)
 
bool start ()
 
- Public Member Functions inherited from Stream
 Stream ()
 
virtual void stop ()
 
void toggle ()
 
bool hasStarted ()
 

Additional Inherited Members

- Protected Attributes inherited from Stream
std::atomic_bool has_started_
 

Detailed Description

Send strings over a TCP socket based on pipeline predictions.

This class connects to a TCP server and sends it strings when predictions are made by the current machine learning pipeline. The TCP connection is only made once, when ESP first starts, and is not restored if the other side disconnects.

To use an TcpOStream instance in your application, pass it to useOutputStream() in your setup() function.

Examples:
user_accelerometer_gestures.cpp, user_accelerometer_poses.cpp, user_accelerometer_walk_detection.cpp, user_color_sensor.cpp, user_speaker.cpp, and user_touche.cpp.

Constructor & Destructor Documentation

TcpOStream::TcpOStream ( string  server,
int  port 
)
inline

Create a TCPOStream instance. This passes the predicted class labels directly to the TCP stream, as ASCII-formatted, newline-terminated strings (e.g. class label 1 will be sent as the string "1\n").

Parameters
serverthe hostname or IP address of the TCP server to connect to
portthe port of the TCP server to connect to
TcpOStream::TcpOStream ( string  server,
int  port,
std::map< uint32_t, string >  tcp_stream_mapping 
)
inline

Create a TCPOStream instance.

Parameters
serverthe hostname or IP address of the TCP server to connect to
portthe port of the TCP server to connect to : a map from predicted class labels to strings to send over the TCP connection. No delimiters or other characters are added to the strings specified, so, if they're required, be sure to include them in the provided strings. Note that 0 is a special GRT class label indicating no prediction, and will not trigger the sending of a string.
TcpOStream::TcpOStream ( string  server,
int  port,
uint32_t  count,
  ... 
)
inline

Create a TCPOStream instance.

Parameters
serverthe hostname or IP address of the TCP server to connect to
portthe port of the TCP server to connect to
countthe number of strings provided
...the strings to send over the TCP connection for each predicted class label. The first string provided corresponds to class label 1, the second to class label 2, etc. No delimiters or other characters are added to the strings specified, so, if they're required, be sure to include them in the provided strings.

Member Function Documentation

virtual void TcpOStream::onReceive ( uint32_t  label)
inlinevirtual

Implements OStream.

virtual void TcpOStream::onReceive ( vector< double >  data)
inlinevirtual

Implements OStreamVector.

bool TcpOStream::start ( )
virtual

Start the stream.

Reimplemented from Stream.


The documentation for this class was generated from the following files: