From 4de9734f0a4a85f2d612c5ccf7797ade946b0e1b Mon Sep 17 00:00:00 2001 From: Stefan Andritoiu Date: Mon, 23 Nov 2015 18:18:39 +0200 Subject: [PATCH] hmtrp: Added functions that throw exceptions when failing to read from sensors, and added java exception handling. Signed-off-by: Stefan Andritoiu Signed-off-by: Mihai Tudor Panu --- src/hmtrp/hmtrp.cxx | 18 ++++++++++++++++++ src/hmtrp/hmtrp.h | 16 ++++++++++++++++ src/hmtrp/javaupm_hmtrp.i | 9 ++++++++- src/wt5001/wt5001.h | 2 +- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/hmtrp/hmtrp.cxx b/src/hmtrp/hmtrp.cxx index bb464b85..ca71c319 100644 --- a/src/hmtrp/hmtrp.cxx +++ b/src/hmtrp/hmtrp.cxx @@ -452,6 +452,15 @@ bool HMTRP::getRFSignalStrength(uint8_t *strength) return true; } +uint8_t HMTRP::getRFSignalStrength() +{ + uint8_t strength = 0; + if (!getRFSignalStrength(&strength)) + throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + + ": readData() failed"); + return strength; +} + bool HMTRP::getModSignalStrength(uint8_t *strength) { if (!strength) @@ -484,3 +493,12 @@ bool HMTRP::getModSignalStrength(uint8_t *strength) return true; } +uint8_t HMTRP::getModSignalStrength() +{ + uint8_t strength = 0; + if (!getModSignalStrength(&strength)) + throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + + ": readData() failed"); + return strength; +} + diff --git a/src/hmtrp/hmtrp.h b/src/hmtrp/hmtrp.h index 47d272e7..c091a8f0 100644 --- a/src/hmtrp/hmtrp.h +++ b/src/hmtrp/hmtrp.h @@ -235,6 +235,14 @@ namespace upm { */ bool getRFSignalStrength(uint8_t *strength); + /** + * Gets the RF signal strength + * + * @return Signal strength + * @throws std::runtime_error if reading from the sensor failed + */ + uint8_t getRFSignalStrength(); + /** * Gets the modulation signal strength. * @@ -243,6 +251,14 @@ namespace upm { */ bool getModSignalStrength(uint8_t *strength); + /** + * Gets the modulation signal strength. + * + * @return Signal strength + * @throws std::runtime_error if reading from the sensor failed + */ + uint8_t getModSignalStrength(); + private: mraa_uart_context m_uart; diff --git a/src/hmtrp/javaupm_hmtrp.i b/src/hmtrp/javaupm_hmtrp.i index 4e5cc780..2f38e060 100644 --- a/src/hmtrp/javaupm_hmtrp.i +++ b/src/hmtrp/javaupm_hmtrp.i @@ -3,6 +3,7 @@ %include "stdint.i" %include "typemaps.i" %include "../java_buffer.i" +%include "../java_exceptions.i" %apply uint32_t *OUTPUT { uint32_t *freq, uint32_t *dataRate }; %apply uint16_t *OUTPUT { uint16_t *rxBandwidth }; @@ -15,6 +16,12 @@ speed_t int_B9600 = B9600; %} +%ignore getRFSignalStrength(uint8_t *strength); +READDATA_EXCEPTION(getRFSignalStrength()) + +%ignore getModSignalStrength(uint8_t *strength); +READDATA_EXCEPTION(getModSignalStrength()) + %include "hmtrp.h" speed_t int_B9600 = B9600; @@ -27,4 +34,4 @@ speed_t int_B9600 = B9600; System.exit(1); } } -%} \ No newline at end of file +%} diff --git a/src/wt5001/wt5001.h b/src/wt5001/wt5001.h index 1603cef8..c21135ac 100644 --- a/src/wt5001/wt5001.h +++ b/src/wt5001/wt5001.h @@ -349,7 +349,7 @@ namespace upm { * @throws std::runtime_error if reading from the sensor failed */ uint16_t getCurrentFile(); - + /** * Gets the device date *