Resolve Linux build issues and warnings

pull/4/head
Paul Hollinsky 2018-10-17 15:13:28 -04:00
parent ae5646dd78
commit 4426334f3f
5 changed files with 41 additions and 36 deletions

View File

@ -58,6 +58,7 @@ add_library(icsneocpp
api/icsneocpp/icsneocpp.cpp api/icsneocpp/icsneocpp.cpp
${SRC_FILES} ${SRC_FILES}
) )
set_property(TARGET icsneocpp PROPERTY POSITION_INDEPENDENT_CODE ON)
add_library(icsneoc SHARED api/icsneoc/icsneoc.cpp) add_library(icsneoc SHARED api/icsneoc/icsneoc.cpp)
target_link_libraries(icsneoc icsneocpp) target_link_libraries(icsneoc icsneocpp)

View File

@ -10,6 +10,7 @@
#include "communication/include/network.h" #include "communication/include/network.h"
#include <map> #include <map>
#include <algorithm>
using namespace icsneo; using namespace icsneo;
@ -112,10 +113,10 @@ int icsneoGetMessages(void* hObject, icsSpyMessage* pMsg, int* pNumberOfMessages
for(size_t i = 0; i < messageCount; i++) { for(size_t i = 0; i < messageCount; i++) {
icsSpyMessage& oldmsg = pMsg[i]; icsSpyMessage& oldmsg = pMsg[i];
neomessage_t& newmsg = messages[i]; neomessage_t& newmsg = messages[i];
oldmsg.NumberBytesData = (uint8_t)min(newmsg.length, 255); oldmsg.NumberBytesData = (uint8_t)std::min(newmsg.length, (size_t)255);
oldmsg.NumberBytesHeader = 4; oldmsg.NumberBytesHeader = 4;
oldmsg.ExtraDataPtr = (void*)newmsg.data; oldmsg.ExtraDataPtr = (void*)newmsg.data;
memcpy(oldmsg.Data, newmsg.data, min(newmsg.length, 8)); memcpy(oldmsg.Data, newmsg.data, std::min(newmsg.length, (size_t)8));
oldmsg.ArbIDOrHeader = *(uint32_t*)newmsg.header; oldmsg.ArbIDOrHeader = *(uint32_t*)newmsg.header;
oldmsg.ExtraDataPtrEnabled = newmsg.length > 8; oldmsg.ExtraDataPtrEnabled = newmsg.length > 8;
oldmsg.NetworkID = newmsg.netid; oldmsg.NetworkID = newmsg.netid;

View File

@ -102,6 +102,7 @@ typedef struct {
uint8_t type; uint8_t type;
uint8_t reserved[9]; uint8_t reserved[9];
} neomessage_t; } neomessage_t;
// Any time you add another neomessage_*_t type, make sure to add it to the static_asserts below!
typedef struct { typedef struct {
neomessage_statusbitfield_t status; neomessage_statusbitfield_t status;
@ -113,13 +114,14 @@ typedef struct {
uint8_t type; uint8_t type;
char reserved[9]; char reserved[9];
} neomessage_can_t; } neomessage_can_t;
static_assert(sizeof(neomessage_can_t) == sizeof(neomessage_t), "All types of neomessage_t must be the same size!");
#pragma pack(pop) #pragma pack(pop)
#ifdef __cplusplus #ifdef __cplusplus
#include "communication/message/include/message.h" #include "communication/message/include/message.h"
static_assert(sizeof(neomessage_can_t) == sizeof(neomessage_t), "All types of neomessage_t must be the same size!");
namespace icsneo { namespace icsneo {
neomessage_t CreateNeoMessage(const Message& message); neomessage_t CreateNeoMessage(const Message& message);

View File

@ -7,7 +7,7 @@ neomessage_t icsneo::CreateNeoMessage(const Message& message) {
// This function is not responsible for storing the message! // This function is not responsible for storing the message!
// Keep the shared_ptr around for the lifetime of the data access // Keep the shared_ptr around for the lifetime of the data access
const auto type = message.network.getType(); const auto type = message.network.getType();
neomessage_t neomsg = { 0 }; // Clear out the memory neomessage_t neomsg = {}; // Clear out the memory
neomsg.netid = (uint32_t)message.network.getNetID(); neomsg.netid = (uint32_t)message.network.getNetID();
neomsg.type = (uint8_t)type; neomsg.type = (uint8_t)type;
neomsg.length = message.data.size(); neomsg.length = message.data.size();

View File

@ -45,43 +45,44 @@ uint16_t IDeviceSettings::CalculateGSChecksum(const std::vector<uint8_t>& settin
bool IDeviceSettings::refresh(bool ignoreChecksum) { bool IDeviceSettings::refresh(bool ignoreChecksum) {
std::vector<uint8_t> rxSettings; std::vector<uint8_t> rxSettings;
bool ret = com->getSettingsSync(rxSettings); bool ret = com->getSettingsSync(rxSettings);
if(ret) { if(!ret)
if(rxSettings.size() < 6) // We need to at least have the header of GLOBAL_SETTINGS return false;
return false;
constexpr size_t gs_size = 3 * sizeof(uint16_t); if(rxSettings.size() < 6) // We need to at least have the header of GLOBAL_SETTINGS
size_t rxLen = rxSettings.size() - gs_size; return false;
uint16_t gs_version = rxSettings[0] | (rxSettings[1] << 8); constexpr size_t gs_size = 3 * sizeof(uint16_t);
uint16_t gs_len = rxSettings[2] | (rxSettings[3] << 8); size_t rxLen = rxSettings.size() - gs_size;
uint16_t gs_chksum = rxSettings[4] | (rxSettings[5] << 8);
rxSettings.erase(rxSettings.begin(), rxSettings.begin() + gs_size);
if(gs_version != 5) { uint16_t gs_version = rxSettings[0] | (rxSettings[1] << 8);
std::cout << "gs_version was " << gs_version << " instead of 5.\nPlease update your firmware." << std::endl; uint16_t gs_len = rxSettings[2] | (rxSettings[3] << 8);
return false; uint16_t gs_chksum = rxSettings[4] | (rxSettings[5] << 8);
} rxSettings.erase(rxSettings.begin(), rxSettings.begin() + gs_size);
if(rxLen != gs_len) { if(gs_version != 5) {
std::cout << "rxLen was " << rxLen << " and gs_len was " << gs_len << " while reading settings" << std::endl; std::cout << "gs_version was " << gs_version << " instead of 5.\nPlease update your firmware." << std::endl;
return false; return false;
}
if(!ignoreChecksum && gs_chksum != CalculateGSChecksum(rxSettings)) {
std::cout << "Checksum mismatch while reading settings" << std::endl;
return false;
}
settings = std::move(rxSettings);
settingsLoaded = true;
if(settings.size() != structSize) {
std::cout << "Settings size was " << settings.size() << " bytes but it should be " << structSize << " bytes for this device" << std::endl;
settingsLoaded = false;
}
return settingsLoaded;
} }
if(rxLen != gs_len) {
std::cout << "rxLen was " << rxLen << " and gs_len was " << gs_len << " while reading settings" << std::endl;
return false;
}
if(!ignoreChecksum && gs_chksum != CalculateGSChecksum(rxSettings)) {
std::cout << "Checksum mismatch while reading settings" << std::endl;
return false;
}
settings = std::move(rxSettings);
settingsLoaded = true;
if(settings.size() != structSize) {
std::cout << "Settings size was " << settings.size() << " bytes but it should be " << structSize << " bytes for this device" << std::endl;
settingsLoaded = false;
}
return settingsLoaded;
} }
bool IDeviceSettings::apply(bool temporary) { bool IDeviceSettings::apply(bool temporary) {