Disconnect from serial cleanly on SIGINT

Send the STOP opcode before exiting the program to ensure the robot is not left in a state that could potentially drain the battery.

Signed-off-by: Jacob Perron <jacobmperron@gmail.com>
This commit is contained in:
Jacob Perron 2019-08-27 00:11:29 -07:00 committed by Jacob Perron
parent 04ab2ccd80
commit f5044c7ec8
3 changed files with 17 additions and 3 deletions

View file

@ -51,6 +51,7 @@ namespace create {
protected:
boost::asio::io_service io;
boost::asio::signal_set signals;
boost::asio::serial_port port;
private:
@ -62,7 +63,6 @@ namespace create {
bool firstRead;
uint8_t byteRead;
// Callback executed when data arrives from Create
void onData(const boost::system::error_code& e, const std::size_t& size);
// Callback to execute once data arrives
@ -80,6 +80,7 @@ namespace create {
virtual bool startSensorStream() = 0;
virtual void processByte(uint8_t byteRead) = 0;
void signalHandler(const boost::system::error_code& error, int signal_number);
// Notifies main thread that data is fresh and makes the user callback
void notifyDataReady();