Add compiler flags '-Wall -Wextra -Wpedantic'

Fix warnings as a result.

Signed-off-by: Jacob Perron <jacobmperron@gmail.com>
This commit is contained in:
Jacob Perron 2019-08-30 00:53:13 -07:00 committed by Jacob Perron
parent c1c0ce6ea9
commit dce7336bbe
7 changed files with 25 additions and 30 deletions

View file

@ -8,6 +8,8 @@
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 2.8.12)
project(libcreate) project(libcreate)
add_compile_options(-Wall -Wextra -Wpedantic)
set(PACKAGE_VERSION 1.6.1) set(PACKAGE_VERSION 1.6.1)
option(LIBCREATE_BUILD_TESTS "Enable the build of tests." ON) option(LIBCREATE_BUILD_TESTS "Enable the build of tests." ON)

View file

@ -181,7 +181,7 @@ namespace create {
OC_SENSORS= 142, OC_SENSORS= 142,
OC_QUERY_LIST=149, OC_QUERY_LIST=149,
OC_STREAM = 148, OC_STREAM = 148,
OC_TOGGLE_STREAM = 150, OC_TOGGLE_STREAM = 150
}; };
enum BAUDCODE { enum BAUDCODE {

View file

@ -55,13 +55,13 @@ namespace create {
while (a < -PI) a += TWO_PI; while (a < -PI) a += TWO_PI;
while (a > PI) a -= TWO_PI; while (a > PI) a -= TWO_PI;
return a; return a;
}; }
typedef unsigned long long timestamp_t; typedef unsigned long long timestamp_t;
/** Get a timestamp for the current time in micro-seconds. /** Get a timestamp for the current time in micro-seconds.
*/ */
static timestamp_t getTimestamp() { inline timestamp_t getTimestamp() {
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
return now.tv_usec + (timestamp_t) now.tv_sec * 1000000; return now.tv_usec + (timestamp_t) now.tv_sec * 1000000;

View file

@ -64,15 +64,15 @@ namespace create {
} }
Create::Matrix Create::addMatrices(const Matrix &A, const Matrix &B) const { Create::Matrix Create::addMatrices(const Matrix &A, const Matrix &B) const {
int rows = A.size1(); size_t rows = A.size1();
int cols = A.size2(); size_t cols = A.size2();
assert(rows == B.size1()); assert(rows == B.size1());
assert(cols == B.size2()); assert(cols == B.size2());
Matrix C(rows, cols); Matrix C(rows, cols);
for (int i = 0; i < rows; i++) { for (size_t i = 0u; i < rows; i++) {
for (int j = 0; j < cols; j++) { for (size_t j = 0u; j < cols; j++) {
const float a = A(i, j); const float a = A(i, j);
const float b = B(i, j); const float b = B(i, j);
if (util::willFloatOverflow(a, b)) { if (util::willFloatOverflow(a, b)) {
@ -345,8 +345,8 @@ namespace create {
bool Create::setDate(const DayOfWeek& day, const uint8_t& hour, const uint8_t& min) const { bool Create::setDate(const DayOfWeek& day, const uint8_t& hour, const uint8_t& min) const {
if (day < 0 || day > 6 || if (day < 0 || day > 6 ||
hour < 0 || hour > 23 || hour > 23 ||
min < 0 || min > 59) min > 59)
return false; return false;
uint8_t cmd[4] = { OC_DATE, day, hour, min }; uint8_t cmd[4] = { OC_DATE, day, hour, min };
@ -362,7 +362,7 @@ namespace create {
int16_t radius_mm = roundf(radius * 1000); int16_t radius_mm = roundf(radius * 1000);
// Bound radius if not a special case // Bound radius if not a special case
if (radius_mm != 32768 && radius_mm != 32767 && if (radius_mm != -32768 && radius_mm != 32767 &&
radius_mm != -1 && radius_mm != 1) { radius_mm != -1 && radius_mm != 1) {
BOUND(radius_mm, -util::MAX_RADIUS * 1000, util::MAX_RADIUS * 1000); BOUND(radius_mm, -util::MAX_RADIUS * 1000, util::MAX_RADIUS * 1000);
} }
@ -561,7 +561,7 @@ namespace create {
const float* durations) const { const float* durations) const {
int i, j; int i, j;
uint8_t duration; uint8_t duration;
uint8_t cmd[2 * songLength + 3]; std::vector<uint8_t> cmd(2 * songLength + 3);
cmd[0] = OC_SONG; cmd[0] = OC_SONG;
cmd[1] = songNumber; cmd[1] = songNumber;
cmd[2] = songLength; cmd[2] = songLength;
@ -575,11 +575,11 @@ namespace create {
j++; j++;
} }
return serial->send(cmd, 2 * songLength + 3); return serial->send(cmd.data(), cmd.size());
} }
bool Create::playSong(const uint8_t& songNumber) const { bool Create::playSong(const uint8_t& songNumber) const {
if (songNumber < 0 || songNumber > 4) if (songNumber > 4)
return false; return false;
uint8_t cmd[2] = { OC_PLAY, songNumber }; uint8_t cmd[2] = { OC_PLAY, songNumber };
return serial->send(cmd, 2); return serial->send(cmd, 2);
@ -754,7 +754,6 @@ namespace create {
ChargingState Create::getChargingState() const { ChargingState Create::getChargingState() const {
if (data->isValidPacketID(ID_CHARGE_STATE)) { if (data->isValidPacketID(ID_CHARGE_STATE)) {
uint8_t chargeState = GET_DATA(ID_CHARGE_STATE); uint8_t chargeState = GET_DATA(ID_CHARGE_STATE);
assert(chargeState >= 0);
assert(chargeState <= 5); assert(chargeState <= 5);
return (ChargingState) chargeState; return (ChargingState) chargeState;
} }

View file

@ -3,10 +3,10 @@
namespace create { namespace create {
Packet::Packet(const uint8_t& numBytes, const std::string& comment) : Packet::Packet(const uint8_t& numBytes, const std::string& comment) :
nbytes(numBytes),
info(comment),
data(0), data(0),
tmpData(0) { } tmpData(0),
nbytes(numBytes),
info(comment) { }
Packet::~Packet() { } Packet::~Packet() { }

View file

@ -6,11 +6,11 @@
namespace create { namespace create {
Serial::Serial(boost::shared_ptr<Data> d) : Serial::Serial(boost::shared_ptr<Data> d) :
data(d),
port(io),
signals(io, SIGINT, SIGTERM), signals(io, SIGINT, SIGTERM),
isReading(false), port(io),
dataReady(false), dataReady(false),
isReading(false),
data(d),
corruptPackets(0), corruptPackets(0),
totalPackets(0) { totalPackets(0) {
} }

View file

@ -10,19 +10,13 @@ namespace create {
bool SerialStream::startSensorStream() { bool SerialStream::startSensorStream() {
// Request from Create that we want a stream containing all packets // Request from Create that we want a stream containing all packets
uint8_t numPackets = data->getNumPackets(); const uint8_t numPackets = data->getNumPackets();
std::vector<uint8_t> packetIDs = data->getPacketIDs(); std::vector<uint8_t> packetIDs = data->getPacketIDs();
uint8_t streamReq[2 + numPackets]; packetIDs.insert(packetIDs.begin(), numPackets);
streamReq[0] = OC_STREAM; packetIDs.insert(packetIDs.begin(), OC_STREAM);
streamReq[1] = numPackets;
int i = 2;
for (std::vector<uint8_t>::iterator it = packetIDs.begin(); it != packetIDs.end(); ++it) {
streamReq[i] = *it;
i++;
}
// Start streaming data // Start streaming data
send(streamReq, 2 + numPackets); send(packetIDs.data(), packetIDs.size());
expectedNumBytes = data->getTotalDataBytes() + numPackets; expectedNumBytes = data->getTotalDataBytes() + numPackets;