From da2b2264b381e53b01a45e08e82d984c4430286c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 7 Jun 2013 17:40:10 +0200 Subject: Bridge: now processes start can be checked for errors --- libraries/Bridge/Bridge.cpp | 9 +++++---- libraries/Bridge/Bridge.h | 2 +- libraries/Bridge/Process.cpp | 6 ++++-- libraries/Bridge/Process.h | 2 ++ 4 files changed, 12 insertions(+), 7 deletions(-) (limited to 'libraries/Bridge') diff --git a/libraries/Bridge/Bridge.cpp b/libraries/Bridge/Bridge.cpp index a653b12..928479c 100644 --- a/libraries/Bridge/Bridge.cpp +++ b/libraries/Bridge/Bridge.cpp @@ -55,11 +55,12 @@ void BridgeClass::begin() { transfer(cmd, 2); } -uint8_t BridgeClass::runCommand(String &command) { +uint8_t BridgeClass::runCommand(String &command, uint8_t &err) { uint8_t cmd[] = {'R'}; - uint8_t res[1]; - transfer(cmd, 1, (uint8_t*)command.c_str(), command.length(), res, 1); - return res[0]; + uint8_t res[2]; + transfer(cmd, 1, (uint8_t*)command.c_str(), command.length(), res, 2); + err = res[0]; + return res[1]; } bool BridgeClass::commandIsRunning(uint8_t handle) { diff --git a/libraries/Bridge/Bridge.h b/libraries/Bridge/Bridge.h index 6043e15..6e54bbd 100644 --- a/libraries/Bridge/Bridge.h +++ b/libraries/Bridge/Bridge.h @@ -28,7 +28,7 @@ public: void begin(); // Methods to handle processes on the linux side - uint8_t runCommand(String &command); + uint8_t runCommand(String &command, uint8_t &err); bool commandIsRunning(uint8_t handle); unsigned int commandExitValue(uint8_t handle); void cleanCommand(uint8_t handle); diff --git a/libraries/Bridge/Process.cpp b/libraries/Bridge/Process.cpp index 7265119..59fe2b7 100644 --- a/libraries/Bridge/Process.cpp +++ b/libraries/Bridge/Process.cpp @@ -85,11 +85,13 @@ void Process::addParameter(String ¶m) { } void Process::runAsynchronously() { - handle = bridge.runCommand(*cmdline); + uint8_t err; + handle = bridge.runCommand(*cmdline, err); delete cmdline; cmdline = NULL; - started = true; + if (err==0) + started = true; } boolean Process::running() { diff --git a/libraries/Bridge/Process.h b/libraries/Bridge/Process.h index b48e046..ac22b15 100644 --- a/libraries/Bridge/Process.h +++ b/libraries/Bridge/Process.h @@ -39,6 +39,8 @@ public: unsigned int exitValue(); void close(); + operator bool () { return started; } + // Stream methods // (read from process stdout) int available(); -- cgit v1.2.3-18-g5258