hmtrp: Added functions that throw exceptions when failing to read from sensors, and added java exception handling.

Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Stefan Andritoiu 2015-11-23 18:18:39 +02:00 committed by Mihai Tudor Panu
parent 9bfda4219d
commit 4de9734f0a
4 changed files with 43 additions and 2 deletions

View File

@ -452,6 +452,15 @@ bool HMTRP::getRFSignalStrength(uint8_t *strength)
return true; 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) bool HMTRP::getModSignalStrength(uint8_t *strength)
{ {
if (!strength) if (!strength)
@ -484,3 +493,12 @@ bool HMTRP::getModSignalStrength(uint8_t *strength)
return true; 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;
}

View File

@ -235,6 +235,14 @@ namespace upm {
*/ */
bool getRFSignalStrength(uint8_t *strength); 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. * Gets the modulation signal strength.
* *
@ -243,6 +251,14 @@ namespace upm {
*/ */
bool getModSignalStrength(uint8_t *strength); 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: private:
mraa_uart_context m_uart; mraa_uart_context m_uart;

View File

@ -3,6 +3,7 @@
%include "stdint.i" %include "stdint.i"
%include "typemaps.i" %include "typemaps.i"
%include "../java_buffer.i" %include "../java_buffer.i"
%include "../java_exceptions.i"
%apply uint32_t *OUTPUT { uint32_t *freq, uint32_t *dataRate }; %apply uint32_t *OUTPUT { uint32_t *freq, uint32_t *dataRate };
%apply uint16_t *OUTPUT { uint16_t *rxBandwidth }; %apply uint16_t *OUTPUT { uint16_t *rxBandwidth };
@ -15,6 +16,12 @@
speed_t int_B9600 = B9600; speed_t int_B9600 = B9600;
%} %}
%ignore getRFSignalStrength(uint8_t *strength);
READDATA_EXCEPTION(getRFSignalStrength())
%ignore getModSignalStrength(uint8_t *strength);
READDATA_EXCEPTION(getModSignalStrength())
%include "hmtrp.h" %include "hmtrp.h"
speed_t int_B9600 = B9600; speed_t int_B9600 = B9600;
@ -27,4 +34,4 @@ speed_t int_B9600 = B9600;
System.exit(1); System.exit(1);
} }
} }
%} %}

View File

@ -349,7 +349,7 @@ namespace upm {
* @throws std::runtime_error if reading from the sensor failed * @throws std::runtime_error if reading from the sensor failed
*/ */
uint16_t getCurrentFile(); uint16_t getCurrentFile();
/** /**
* Gets the device date * Gets the device date
* *