mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
mhz16: Remove post-throw returns + small fixes
Removed the 'return false;' lines after throws since these are not needed and are generally flagged by static analysis tools. Also removed a EOL spaces and added initializers for member variables at declaration (since more than one constructor exists). Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
parent
dd73c4aa45
commit
17110d41d0
@ -41,7 +41,6 @@ MHZ16::MHZ16(int uart)
|
|||||||
{
|
{
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
": mraa_uart_init() failed");
|
": mraa_uart_init() failed");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This requires a recent MRAA (1/2015)
|
// This requires a recent MRAA (1/2015)
|
||||||
@ -51,17 +50,15 @@ MHZ16::MHZ16(int uart)
|
|||||||
{
|
{
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
": mraa_uart_get_dev_path() failed");
|
": mraa_uart_get_dev_path() failed");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// now open the tty
|
// now open the tty
|
||||||
if ( (m_ttyFd = open(devPath, O_RDWR)) == -1)
|
if ( (m_ttyFd = open(devPath, O_RDWR)) == -1)
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
": open of " +
|
": open of " +
|
||||||
string(devPath) + " failed: " +
|
string(devPath) + " failed: " +
|
||||||
string(strerror(errno)));
|
string(strerror(errno)));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +70,6 @@ MHZ16::MHZ16(const std::string& uart_raw)
|
|||||||
{
|
{
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
": mraa_uart_init_raw() failed");
|
": mraa_uart_init_raw() failed");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This requires a recent MRAA (1/2015)
|
// This requires a recent MRAA (1/2015)
|
||||||
@ -83,17 +79,15 @@ MHZ16::MHZ16(const std::string& uart_raw)
|
|||||||
{
|
{
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
": mraa_uart_get_dev_path() failed");
|
": mraa_uart_get_dev_path() failed");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// now open the tty
|
// now open the tty
|
||||||
if ( (m_ttyFd = open(devPath, O_RDWR)) == -1)
|
if ( (m_ttyFd = open(devPath, O_RDWR)) == -1)
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
": open of " +
|
": open of " +
|
||||||
string(devPath) + " failed: " +
|
string(devPath) + " failed: " +
|
||||||
string(strerror(errno)));
|
string(strerror(errno)));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,11 +115,11 @@ bool MHZ16::dataAvailable(unsigned int millis)
|
|||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
|
|
||||||
FD_SET(m_ttyFd, &readfds);
|
FD_SET(m_ttyFd, &readfds);
|
||||||
|
|
||||||
if (select(m_ttyFd + 1, &readfds, NULL, NULL, &timeout) > 0)
|
if (select(m_ttyFd + 1, &readfds, NULL, NULL, &timeout) > 0)
|
||||||
return true; // data is ready
|
return true; // data is ready
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MHZ16::readData(char *buffer, int len)
|
int MHZ16::readData(char *buffer, int len)
|
||||||
@ -143,7 +137,6 @@ int MHZ16::readData(char *buffer, int len)
|
|||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
": read() failed: " +
|
": read() failed: " +
|
||||||
string(strerror(errno)));
|
string(strerror(errno)));
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
@ -164,7 +157,6 @@ int MHZ16::writeData(char *buffer, int len)
|
|||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
": write() failed: " +
|
": write() failed: " +
|
||||||
string(strerror(errno)));
|
string(strerror(errno)));
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tcdrain(m_ttyFd);
|
tcdrain(m_ttyFd);
|
||||||
@ -176,7 +168,7 @@ bool MHZ16::setupTty(speed_t baud)
|
|||||||
{
|
{
|
||||||
if (m_ttyFd == -1)
|
if (m_ttyFd == -1)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
struct termios termio;
|
struct termios termio;
|
||||||
|
|
||||||
// get current modes
|
// get current modes
|
||||||
@ -196,7 +188,6 @@ bool MHZ16::setupTty(speed_t baud)
|
|||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
": tcsetattr() failed: " +
|
": tcsetattr() failed: " +
|
||||||
string(strerror(errno)));
|
string(strerror(errno)));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -208,16 +199,15 @@ bool MHZ16::verifyPacket(uint8_t *pkt, int len)
|
|||||||
{
|
{
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
": invalid packet header received");
|
": invalid packet header received");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MHZ16::getData()
|
bool MHZ16::getData()
|
||||||
{
|
{
|
||||||
// the query command
|
// the query command
|
||||||
const unsigned char cmd[9] =
|
const unsigned char cmd[9] =
|
||||||
{0xff, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
|
{0xff, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
|
||||||
|
|
||||||
writeData((char *)cmd, 9);
|
writeData((char *)cmd, 9);
|
||||||
@ -227,7 +217,6 @@ bool MHZ16::getData()
|
|||||||
{
|
{
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
": Timed out waiting for response");
|
": Timed out waiting for response");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the packet
|
// read the packet
|
||||||
@ -238,9 +227,8 @@ bool MHZ16::getData()
|
|||||||
{
|
{
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
": Invalid packet size read");
|
": Invalid packet size read");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// will throw an exception if it fails
|
// will throw an exception if it fails
|
||||||
verifyPacket(packet, sizeof(packet));
|
verifyPacket(packet, sizeof(packet));
|
||||||
|
|
||||||
@ -264,7 +252,7 @@ int MHZ16::getTemperature()
|
|||||||
void MHZ16::calibrateZeroPoint()
|
void MHZ16::calibrateZeroPoint()
|
||||||
{
|
{
|
||||||
// the query command
|
// the query command
|
||||||
const unsigned char cmd[9] =
|
const unsigned char cmd[9] =
|
||||||
{0xff, 0x01, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78};
|
{0xff, 0x01, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78};
|
||||||
|
|
||||||
writeData((char *)cmd, 9);
|
writeData((char *)cmd, 9);
|
||||||
|
@ -170,9 +170,9 @@ namespace upm {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mraa_uart_context m_uart;
|
mraa_uart_context m_uart;
|
||||||
int m_ttyFd;
|
int m_ttyFd = 0;
|
||||||
int gas;
|
int gas = 0;
|
||||||
int temp;
|
int temp = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user