46 #ifndef BUFFEREDASYNCSERIAL_H
47 #define BUFFEREDASYNCSERIAL_H
74 boost::asio::serial_port_base::parity opt_parity =
75 boost::asio::serial_port_base::parity ( boost::asio::serial_port_base::parity::
77 boost::asio::serial_port_base::character_size opt_csize =
78 boost::asio::serial_port_base::character_size ( 8 ),
79 boost::asio::serial_port_base::flow_control opt_flow =
80 boost::asio::serial_port_base::flow_control ( boost::asio::serial_port_base::flow_control::
82 boost::asio::serial_port_base::stop_bits opt_stop =
83 boost::asio::serial_port_base::stop_bits ( boost::asio::serial_port_base::stop_bits::
85 :
AsyncSerial ( devname, baud_rate, opt_parity, opt_csize, opt_flow, opt_stop )
96 size_t read (
char *data,
size_t size )
99 size_t result = std::min ( size,
readQueue.size ( ) );
101 std::vector < char >::iterator it =
readQueue.begin ( ) + result;
115 std::vector < char >result;
154 std::string result (
readQueue.begin ( ), it );
156 it += delim.size ( );
183 static std::vector < char >::iterator
findStringInVector ( std::vector < char >&v,
const std::string & s )
185 if ( s.size ( ) == 0 )
188 std::vector < char >::iterator it = v.begin ( );
192 std::vector < char >::iterator result = find ( it, v.end ( ), s[0] );
194 if ( result == v.end ( ) )
197 for (
size_t i = 0; i < s.size ( ); i++ )
199 std::vector < char >::iterator temp = result + i;
201 if ( temp == v.end ( ) )
219 #endif //BUFFEREDASYNCSERIAL_H
static std::vector< char >::iterator findStringInVector(std::vector< char > &v, const std::string &s)
BufferedAsyncSerial(const std::string &devname, unsigned int baud_rate, boost::asio::serial_port_base::parity opt_parity=boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none), boost::asio::serial_port_base::character_size opt_csize=boost::asio::serial_port_base::character_size(8), boost::asio::serial_port_base::flow_control opt_flow=boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none), boost::asio::serial_port_base::stop_bits opt_stop=boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one))
void readCallback(const char *data, size_t len)
Asyncronous serial class Asyncronous serial class. Intended to be a base class.
virtual ~BufferedAsyncSerial()
Asynchronous serial class w/ buffer Asynchronous serial class that sends data to buffer after reading...
std::string readStringUntil(const std::string delim="\n")
Class found to work with asyncronous Serial communications ()
void setReadCallback(const boost::function< void(const char *, size_t) > &callback)
std::vector< char > read()
std::vector< char > readQueue
boost::mutex readQueueMutex
size_t read(char *data, size_t size)