MSVC: Resolve warnings

v0.3.0-dev
Paul Hollinsky 2022-02-21 21:15:12 -05:00
parent 7aedb673fd
commit f37669139f
8 changed files with 68 additions and 57 deletions

View File

@ -142,7 +142,7 @@ static inline bool IdIsSlaveBRange1(size_t fullNetid)
return Within(fullNetid, PLASMA_SLAVE2_OFFSET, PLASMA_SLAVE2_OFFSET + PLASMA_SLAVE_NUM); return Within(fullNetid, PLASMA_SLAVE2_OFFSET, PLASMA_SLAVE2_OFFSET + PLASMA_SLAVE_NUM);
} }
static inline bool IdIsSlaveBRange2(unsigned int fullNetid) static inline bool IdIsSlaveBRange2(size_t fullNetid)
{ {
return Within(fullNetid, PLASMA_SLAVE2_OFFSET_RANGE2, PLASMA_SLAVE3_OFFSET_RANGE2); return Within(fullNetid, PLASMA_SLAVE2_OFFSET_RANGE2, PLASMA_SLAVE3_OFFSET_RANGE2);
} }
@ -168,7 +168,7 @@ static inline bool GetVnetNetid(size_t& netId, EPlasmaIonVnetChannel_t vnetSlot)
* the offset from PLASMA_SLAVE1_OFFSET2, return the vnet agnostic * the offset from PLASMA_SLAVE1_OFFSET2, return the vnet agnostic
* netid so caller can commonize handlers without caring about WHICH slave. * netid so caller can commonize handlers without caring about WHICH slave.
*/ */
static inline unsigned int OffsetToSimpleNetworkId(size_t offset) static inline size_t OffsetToSimpleNetworkId(size_t offset)
{ {
for (const auto& it : mp_netIDToVnetOffSet) for (const auto& it : mp_netIDToVnetOffSet)
{ {
@ -181,23 +181,13 @@ static inline unsigned int OffsetToSimpleNetworkId(size_t offset)
static inline size_t GetVnetAgnosticNetid(size_t fullNetid) static inline size_t GetVnetAgnosticNetid(size_t fullNetid)
{ {
if (IdIsSlaveARange1(fullNetid)) if (IdIsSlaveARange1(fullNetid))
{ return OffsetToSimpleNetworkId(fullNetid - PLASMA_SLAVE1_OFFSET);
unsigned int off = fullNetid - PLASMA_SLAVE1_OFFSET;
return OffsetToSimpleNetworkId(off);
}
else if (IdIsSlaveARange2(fullNetid)) else if (IdIsSlaveARange2(fullNetid))
{
return fullNetid - PLASMA_SLAVE1_OFFSET_RANGE2; return fullNetid - PLASMA_SLAVE1_OFFSET_RANGE2;
}
else if (IdIsSlaveBRange1(fullNetid)) else if (IdIsSlaveBRange1(fullNetid))
{ return OffsetToSimpleNetworkId(fullNetid - PLASMA_SLAVE2_OFFSET);
unsigned int off = fullNetid - PLASMA_SLAVE2_OFFSET;
return OffsetToSimpleNetworkId(off);
}
else if (IdIsSlaveBRange2(fullNetid)) else if (IdIsSlaveBRange2(fullNetid))
{
return fullNetid - PLASMA_SLAVE2_OFFSET_RANGE2; return fullNetid - PLASMA_SLAVE2_OFFSET_RANGE2;
}
return fullNetid; return fullNetid;
} }
@ -233,7 +223,7 @@ int LegacyDLLExport icsneoFindDevices(NeoDeviceEx* devs, int* devCount, unsigned
if (devTypes && devTypeCount) if (devTypes && devTypeCount)
{ {
for (auto j = 0; j < devTypeCount; j++) for (unsigned int j = 0; j < devTypeCount; j++)
{ {
if (foundDevices[i].DeviceType == devTypes[j]) if (foundDevices[i].DeviceType == devTypes[j])
{ {
@ -1094,7 +1084,8 @@ int LegacyDLLExport icsneoGetDLLFirmwareInfoEx(void* hObject, stAPIFirmwareInfo*
int LegacyDLLExport icsneoJ2534Cmd(void* hObject, unsigned char* CmdBuf, short Len, void* pVoid) int LegacyDLLExport icsneoJ2534Cmd(void* hObject, unsigned char* CmdBuf, short Len, void* pVoid)
{ {
uint64_t* pTmp = nullptr; uint64_t* pTmp = nullptr;
int iRetVal = 0, iNumBytes = 0, NetworkID; int iRetVal = 0, iNumBytes = 0;
uint16_t NetworkID = 0;
if (!icsneoValidateHObject(hObject)) if (!icsneoValidateHObject(hObject))
return false; return false;

View File

@ -11,19 +11,19 @@ static optional<uint8_t> CAN_DLCToLength(uint8_t length, bool fd) {
if (fd) { if (fd) {
switch(length) { switch(length) {
case 0x9: case 0x9:
return 12; return uint8_t(12);
case 0xa: case 0xa:
return 16; return uint8_t(16);
case 0xb: case 0xb:
return 20; return uint8_t(20);
case 0xc: case 0xc:
return 24; return uint8_t(24);
case 0xd: case 0xd:
return 32; return uint8_t(32);
case 0xe: case 0xe:
return 48; return uint8_t(48);
case 0xf: case 0xf:
return 64; return uint8_t(64);
} }
} }
@ -33,23 +33,23 @@ static optional<uint8_t> CAN_DLCToLength(uint8_t length, bool fd) {
static optional<uint8_t> CAN_LengthToDLC(size_t dataLength, bool fd) static optional<uint8_t> CAN_LengthToDLC(size_t dataLength, bool fd)
{ {
if (dataLength <= 8) if (dataLength <= 8)
return dataLength; return uint8_t(dataLength);
if (fd) { if (fd) {
if (dataLength <= 12) if (dataLength <= 12)
return 0x9; return uint8_t(0x9);
else if (dataLength <= 16) else if (dataLength <= 16)
return 0xA; return uint8_t(0xA);
else if (dataLength <= 20) else if (dataLength <= 20)
return 0xB; return uint8_t(0xB);
else if (dataLength <= 24) else if (dataLength <= 24)
return 0xC; return uint8_t(0xC);
else if (dataLength <= 32) else if (dataLength <= 32)
return 0xD; return uint8_t(0xD);
else if (dataLength <= 48) else if (dataLength <= 48)
return 0xE; return uint8_t(0xE);
else if (dataLength <= 64) else if (dataLength <= 64)
return 0xF; return uint8_t(0xF);
} }
return nullopt; return nullopt;
@ -161,7 +161,7 @@ bool HardwareCANPacket::EncodeFromMessage(const CANMessage& message, std::vector
// The only way this fails is if we're transmitting a DLC > 8 on standard CAN // The only way this fails is if we're transmitting a DLC > 8 on standard CAN
const uint8_t paddedLength = CAN_DLCToLength(*dlc, message.isCANFD).value_or(8); const uint8_t paddedLength = CAN_DLCToLength(*dlc, message.isCANFD).value_or(8);
const uint8_t paddingBytes = paddedLength - dataSize; const uint8_t paddingBytes = uint8_t(paddedLength - dataSize);
// Pre-allocate as much memory as we will possibly need for speed // Pre-allocate as much memory as we will possibly need for speed
result.reserve(16 + dataSize + paddingBytes); result.reserve(16 + dataSize + paddingBytes);

View File

@ -27,7 +27,7 @@ bool HardwareISO9141Packet::EncodeFromMessage(const ISO9141Message& message, std
const uint8_t maxSize = (firstPacket ? 9 : 12); const uint8_t maxSize = (firstPacket ? 9 : 12);
uint8_t currentSize = maxSize; uint8_t currentSize = maxSize;
if(bytesToSend - currentStart < maxSize) if(bytesToSend - currentStart < maxSize)
currentSize = bytesToSend - currentStart; currentSize = (uint8_t)(bytesToSend - currentStart);
packet.insert(packet.begin(), { packet.insert(packet.begin(), {
(uint8_t)Network::NetID::RED, // 0x0C for long message (uint8_t)Network::NetID::RED, // 0x0C for long message
@ -75,7 +75,7 @@ bool HardwareISO9141Packet::EncodeFromMessage(const ISO9141Message& message, std
} }
std::shared_ptr<ISO9141Message> HardwareISO9141Packet::Decoder::decodeToMessage(const std::vector<uint8_t>& bytestream) { std::shared_ptr<ISO9141Message> HardwareISO9141Packet::Decoder::decodeToMessage(const std::vector<uint8_t>& bytestream) {
const HardwareISO9141Packet* data = (const HardwareISO9141Packet*)bytestream.data(); const HardwareISO9141Packet& packet = *reinterpret_cast<const HardwareISO9141Packet*>(bytestream.data());
if(!mMsg) { if(!mMsg) {
mMsg = std::make_shared<ISO9141Message>(); mMsg = std::make_shared<ISO9141Message>();
@ -84,8 +84,8 @@ std::shared_ptr<ISO9141Message> HardwareISO9141Packet::Decoder::decodeToMessage(
mGotPackets++; mGotPackets++;
const bool morePacketsComing = data->c3.frm == 0; const bool morePacketsComing = packet.c3.frm == 0;
const uint8_t bytesInCurrentMessage = data->c3.len; const uint8_t bytesInCurrentMessage = packet.c3.len;
if(mMsg->data.size() + bytesInCurrentMessage > 500) { if(mMsg->data.size() + bytesInCurrentMessage > 500) {
mMsg.reset(); mMsg.reset();
return std::shared_ptr<ISO9141Message>(); return std::shared_ptr<ISO9141Message>();
@ -93,9 +93,9 @@ std::shared_ptr<ISO9141Message> HardwareISO9141Packet::Decoder::decodeToMessage(
// This timestamp is raw off the device (in timestampResolution increments) // This timestamp is raw off the device (in timestampResolution increments)
// Decoder will fix as it has information about the timestampResolution increments // Decoder will fix as it has information about the timestampResolution increments
mMsg->timestamp = data->timestamp.TS; mMsg->timestamp = packet.timestamp.TS;
auto* dataStart = data->data; auto* dataStart = packet.data;
if(mGotPackets == 1) { if(mGotPackets == 1) {
// Header // Header
if(bytesInCurrentMessage < 3) { if(bytesInCurrentMessage < 3) {
@ -103,31 +103,31 @@ std::shared_ptr<ISO9141Message> HardwareISO9141Packet::Decoder::decodeToMessage(
return std::shared_ptr<ISO9141Message>(); return std::shared_ptr<ISO9141Message>();
} }
std::copy(data->data, data->data + 3, mMsg->header.begin()); std::copy(packet.data, packet.data + 3, mMsg->header.begin());
dataStart += 3; dataStart += 3;
} }
// Data // Data
mMsg->data.insert(mMsg->data.end(), dataStart, data->data + (bytesInCurrentMessage > 8 ? 8 : bytesInCurrentMessage)); mMsg->data.insert(mMsg->data.end(), dataStart, packet.data + (bytesInCurrentMessage > 8 ? 8 : bytesInCurrentMessage));
if(bytesInCurrentMessage > 8) if(bytesInCurrentMessage > 8)
mMsg->data.push_back(data->c1.d8); mMsg->data.push_back(packet.c1.d8);
if(bytesInCurrentMessage > 9) if(bytesInCurrentMessage > 9)
mMsg->data.push_back(data->c2.d9); mMsg->data.push_back(packet.c2.d9);
if(bytesInCurrentMessage > 10) if(bytesInCurrentMessage > 10)
mMsg->data.push_back(data->c2.d10); mMsg->data.push_back(packet.c2.d10);
if(bytesInCurrentMessage > 11) if(bytesInCurrentMessage > 11)
mMsg->data.push_back(data->c3.d11); mMsg->data.push_back(packet.c3.d11);
if(morePacketsComing) if(morePacketsComing)
return std::shared_ptr<ISO9141Message>(); return std::shared_ptr<ISO9141Message>();
mMsg->transmitted = data->c1.tx; mMsg->transmitted = packet.c1.tx;
mMsg->isInit = data->c3.init; mMsg->isInit = packet.c3.init;
mMsg->framingError = data->c1.options & 0x1; mMsg->framingError = packet.c1.options & 0x1;
mMsg->overflowError = data->c1.options & 0x2; mMsg->overflowError = packet.c1.options & 0x2;
mMsg->parityError = data->c1.options & 0x4; mMsg->parityError = packet.c1.options & 0x4;
mMsg->rxTimeoutError = data->c1.options & 0x8; mMsg->rxTimeoutError = packet.c1.options & 0x8;
mMsg->description = data->stats; mMsg->description = packet.stats;
auto ret = mMsg; auto ret = mMsg;
mMsg.reset(); mMsg.reset();

View File

@ -692,7 +692,7 @@ int main() {
names.push_back("Ethernet (DoIP) Activation Line"); names.push_back("Ethernet (DoIP) Activation Line");
if(ethAct > 1) { if(ethAct > 1) {
names.back() += ' '; names.back() += ' ';
names.back() += i; names.back() += std::to_string(i);
} }
std::cout << '[' << options.back() << "] " << names.back(); std::cout << '[' << options.back() << "] " << names.back();
const auto val = selectedDevice->getDigitalIO(icsneo::IO::EthernetActivation, i); const auto val = selectedDevice->getDigitalIO(icsneo::IO::EthernetActivation, i);
@ -711,7 +711,7 @@ int main() {
names.push_back("USB Host Power"); names.push_back("USB Host Power");
if(usbHost > 1) { if(usbHost > 1) {
names.back() += ' '; names.back() += ' ';
names.back() += i; names.back() += std::to_string(i);
} }
std::cout << '[' << options.back() << "] " << names.back(); std::cout << '[' << options.back() << "] " << names.back();
const auto val = selectedDevice->getDigitalIO(icsneo::IO::USBHostPower, i); const auto val = selectedDevice->getDigitalIO(icsneo::IO::USBHostPower, i);

View File

@ -7,7 +7,8 @@
namespace icsneo { namespace icsneo {
static void AddBuiltInExtensionsTo([[maybe_unused]] const std::shared_ptr<icsneo::Device>& device) { static void AddBuiltInExtensionsTo(const std::shared_ptr<icsneo::Device>& device) {
(void)device; // [[maybe_unused]]
@LIBICSNEO_EXT_CODE@ @LIBICSNEO_EXT_CODE@
} }

View File

@ -10,6 +10,11 @@ namespace icsneo {
#endif #endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4201) // nameless struct/union
#endif
#pragma pack(push, 2) #pragma pack(push, 2)
typedef struct { typedef struct {
uint16_t perf_en; uint16_t perf_en;
@ -57,8 +62,7 @@ typedef struct {
ETHERNET_SETTINGS ethernet; ETHERNET_SETTINGS ethernet;
TIMESYNC_ICSHARDWARE_SETTINGS timeSync; TIMESYNC_ICSHARDWARE_SETTINGS timeSync;
STextAPISettings text_api; STextAPISettings text_api;
struct struct {
{
uint32_t disableUsbCheckOnBoot : 1; uint32_t disableUsbCheckOnBoot : 1;
uint32_t enableLatencyTest : 1; uint32_t enableLatencyTest : 1;
uint32_t busMessagesToAndroid : 1; uint32_t busMessagesToAndroid : 1;
@ -87,6 +91,10 @@ typedef struct {
} neovired2_status_t; } neovired2_status_t;
#pragma pack(pop) #pragma pack(pop)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#ifdef __cplusplus #ifdef __cplusplus
#include <iostream> #include <iostream>

View File

@ -46,6 +46,11 @@ typedef unsigned __int64 uint64_t;
#define IS_64BIT_SYSTEM #define IS_64BIT_SYSTEM
#endif #endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4201) // nameless struct/union
#endif
/* OpenPort "OpenType" Argument Constants -- deprecated, use OpenNeoDevice */ /* OpenPort "OpenType" Argument Constants -- deprecated, use OpenNeoDevice */
#define NEOVI_COMMTYPE_RS232 0 #define NEOVI_COMMTYPE_RS232 0
#define NEOVI_COMMTYPE_USB_BULK 1 #define NEOVI_COMMTYPE_USB_BULK 1
@ -2106,6 +2111,8 @@ typedef struct _stCM_ISO157652_RxMessage
{ {
uint16_t vs_netid; /* The netid of the message (determines which network to decode receives), not supported */ uint16_t vs_netid; /* The netid of the message (determines which network to decode receives), not supported */
uint8_t reservedPacking;
uint8_t padding; /* The padding byte to use to fill the unused portion of uint8_t padding; /* The padding byte to use to fill the unused portion of
* transmitted CAN frames (flow control), see paddingEnable. */ * transmitted CAN frames (flow control), see paddingEnable. */
@ -2495,4 +2502,8 @@ CHECK_STRUCT_SIZE(SRADMoon2Settings);
#endif /* INTREPID_NO_CHECK_STRUCT_SIZE */ #endif /* INTREPID_NO_CHECK_STRUCT_SIZE */
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif /* _ICSNVC40_H */ #endif /* _ICSNVC40_H */

View File

@ -557,7 +557,7 @@ TEST_F(EventManagerTest, GetSizeFilterTest) {
} }
// (Incorrectly) try to get settings type again. 5 {mismatch, warning} remaining. // (Incorrectly) try to get settings type again. 5 {mismatch, warning} remaining.
events = EventManager::GetInstance().get(-1, EventFilter(APIEvent::Type::SWCANSettingsNotAvailable)); events = EventManager::GetInstance().get(APIEvent::Type::SWCANSettingsNotAvailable);
EXPECT_EQ(events.size(), 0); EXPECT_EQ(events.size(), 0);
EXPECT_EQ(EventCount(), 5); EXPECT_EQ(EventCount(), 5);