From 82954d9190938c33f91e2b03c81c2f964cc427ce Mon Sep 17 00:00:00 2001 From: Kyle Schwarz Date: Mon, 20 Sep 2021 21:31:13 -0400 Subject: [PATCH 01/26] Build: Associate libusb include dir with icsneocpp If an external project links to the icsneocpp target and libusb has been installed in a non-standard location, the build will fail to find libusb.h because LIBUSB_INCLUDE_DIR is not associated with the target. Closes #57 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cc3dcc..d03bef2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,6 +203,7 @@ target_include_directories(icsneocpp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${LIBICSNEO_EXTENSION_INCLUDE_PATHS} + ${LIBUSB_INCLUDE_DIR} ) set_property(TARGET icsneocpp PROPERTY POSITION_INDEPENDENT_CODE ON) target_compile_features(icsneocpp PUBLIC cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums) @@ -220,7 +221,6 @@ if(NOT WIN32) set(FTDIPP OFF CACHE INTERNAL "") set(FTDI_EEPROM OFF CACHE INTERNAL "") add_subdirectory(third-party/libftdi) - include_directories(${LIBUSB_INCLUDE_DIR}) endif(NOT WIN32) # winpcap From c5314884ce88b04df3b11e304e940708d29f8a15 Mon Sep 17 00:00:00 2001 From: Kyle Schwarz Date: Mon, 20 Sep 2021 21:38:34 -0400 Subject: [PATCH 02/26] Build: Associate pcap include dir with icsneocpp If an external project links to the icsneocpp target and pcap has been installed in a non-standard location, the build will fail to find pcap.h because PCAP_INCLUDE_DIR is not associated with the target. Closes #58 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d03bef2..6c7d1e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,6 +289,7 @@ if(NOT WIN32) target_link_libraries(icsneocpp PUBLIC ftdi1-static) target_link_libraries(icsneocpp PUBLIC ${CMAKE_THREAD_LIBS_INIT}) find_package(PCAP REQUIRED) + target_include_directories(icsneocpp PUBLIC ${PCAP_INCLUDE_DIR}) target_link_libraries(icsneocpp PUBLIC ${PCAP_LIBRARY}) endif() From 719dbcefc8f098e9acda575a2026c0a86c173a05 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Thu, 23 Sep 2021 21:29:15 -0400 Subject: [PATCH 03/26] EthernetPacketizer: Coalesce small PC-to-device packets --- CMakeLists.txt | 32 ++- communication/ethernetpacketizer.cpp | 64 +++-- .../icsneo/communication/ethernetpacketizer.h | 8 +- test/ethernetpacketizertest.cpp | 253 ++++++++++++++++++ 4 files changed, 320 insertions(+), 37 deletions(-) create mode 100644 test/ethernetpacketizertest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c7d1e7..551b558 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,24 +297,30 @@ endif() if(LIBICSNEO_BUILD_TESTS) if(WIN32) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - endif() + endif() + + if (NOT TARGET gtest) + add_subdirectory(third-party/googletest-master) + endif() - add_subdirectory(third-party/googletest-master) - if (CMAKE_VERSION VERSION_LESS 2.8.11) include_directories("${gtest_SOURCE_DIR}/include") endif() - - add_executable(runTests test/main.cpp test/eventmanagertest.cpp) - - target_link_libraries(runTests gtest gtest_main) - target_link_libraries(runTests icsneocpp) - - target_include_directories(runTests PUBLIC ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) - + + add_executable(libicsneo-tests + test/main.cpp + test/eventmanagertest.cpp + test/ethernetpacketizertest.cpp + ) + + target_link_libraries(libicsneo-tests gtest gtest_main) + target_link_libraries(libicsneo-tests icsneocpp) + + target_include_directories(libicsneo-tests PUBLIC ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) + enable_testing() - - add_test(NAME testSuite COMMAND runTests) + + add_test(NAME libicsneo-test-suite COMMAND libicsneo-tests) endif() set(CPACK_PROJECT_NAME ${PROJECT_NAME}) diff --git a/communication/ethernetpacketizer.cpp b/communication/ethernetpacketizer.cpp index 5f06198..78578a0 100644 --- a/communication/ethernetpacketizer.cpp +++ b/communication/ethernetpacketizer.cpp @@ -2,41 +2,61 @@ #include #include #include +#include using namespace icsneo; -#define MAX_PACKET_LEN (1490) // MTU - overhead - +const size_t EthernetPacketizer::MaxPacketLength = 1490; // MTU - overhead static const uint8_t BROADCAST_MAC[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; -void EthernetPacketizer::inputDown(std::vector bytes) { - EthernetPacket sendPacket; - std::copy(std::begin(hostMAC), std::end(hostMAC), std::begin(sendPacket.srcMAC)); - std::copy(std::begin(deviceMAC), std::end(deviceMAC), std::begin(sendPacket.destMAC)); +EthernetPacketizer::EthernetPacket& EthernetPacketizer::newSendPacket(bool first) { + processedDownPackets.emplace_back(); + EthernetPacket& ret = processedDownPackets.back(); + if(first) { + ret.packetNumber = sequenceDown++; + } else { + ret.firstPiece = false; + if(processedDownPackets.size() > 1) + ret.packetNumber = (processedDownPackets.rbegin() + 1)->packetNumber; + else + assert(false); // This should never be called with !first if there are no packets in the queue + } + std::copy(std::begin(hostMAC), std::end(hostMAC), std::begin(ret.srcMAC)); + std::copy(std::begin(deviceMAC), std::end(deviceMAC), std::begin(ret.destMAC)); + return ret; +} - sendPacket.packetNumber = sequenceDown++; - sendPacket.payload = std::move(bytes); +void EthernetPacketizer::inputDown(std::vector bytes, bool first) { + EthernetPacket* sendPacket = nullptr; + if(first && !processedDownPackets.empty()) { + // We have some packets already, let's see if we can add this to the last one + if(processedDownPackets.back().payload.size() + bytes.size() <= MaxPacketLength) + sendPacket = &processedDownPackets.back(); + } + + if(sendPacket == nullptr) + sendPacket = &newSendPacket(first); + + if(sendPacket->payload.empty()) + sendPacket->payload = std::move(bytes); + else + sendPacket->payload.insert(sendPacket->payload.end(), bytes.begin(), bytes.end()); // Split packets larger than MTU std::vector extraData; - if(sendPacket.payload.size() > MAX_PACKET_LEN) { - extraData.insert(extraData.end(), sendPacket.payload.begin() + MAX_PACKET_LEN, sendPacket.payload.end()); - sendPacket.payload.resize(MAX_PACKET_LEN); - sendPacket.lastPiece = false; - } - - processedDownPackets.push_back(sendPacket.getBytestream()); - - if(!extraData.empty()) { - sendPacket.payload = std::move(extraData); - sendPacket.firstPiece = false; - sendPacket.lastPiece = true; - processedDownPackets.push_back(sendPacket.getBytestream()); + if(sendPacket->payload.size() > MaxPacketLength) { + extraData.insert(extraData.end(), sendPacket->payload.begin() + MaxPacketLength, sendPacket->payload.end()); + sendPacket->payload.resize(MaxPacketLength); + sendPacket->lastPiece = false; + inputDown(std::move(extraData), false); } } std::vector< std::vector > EthernetPacketizer::outputDown() { - std::vector< std::vector > ret = std::move(processedDownPackets); + std::vector< std::vector > ret; + ret.reserve(processedDownPackets.size()); + for(auto&& packet : std::move(processedDownPackets)) + ret.push_back(packet.getBytestream()); processedDownPackets.clear(); return ret; } diff --git a/include/icsneo/communication/ethernetpacketizer.h b/include/icsneo/communication/ethernetpacketizer.h index c14bcc3..bdc343d 100644 --- a/include/icsneo/communication/ethernetpacketizer.h +++ b/include/icsneo/communication/ethernetpacketizer.h @@ -18,6 +18,8 @@ namespace icsneo { */ class EthernetPacketizer { public: + static const size_t MaxPacketLength; + EthernetPacketizer(device_eventhandler_t report) : report(report) {} /** @@ -25,7 +27,7 @@ public: * outputDown to get the results. Passing in multiple * packets may result in better packing. */ - void inputDown(std::vector bytes); + void inputDown(std::vector bytes, bool first = true); std::vector< std::vector > outputDown(); /** @@ -66,9 +68,11 @@ private: uint16_t sequenceDown = 0; std::vector processedUpBytes; - std::vector< std::vector > processedDownPackets; + std::vector processedDownPackets; device_eventhandler_t report; + + EthernetPacket& newSendPacket(bool first); }; } diff --git a/test/ethernetpacketizertest.cpp b/test/ethernetpacketizertest.cpp new file mode 100644 index 0000000..a2b2853 --- /dev/null +++ b/test/ethernetpacketizertest.cpp @@ -0,0 +1,253 @@ +#include "icsneo/communication/ethernetpacketizer.h" +#include "icsneo/platform/optional.h" +#include "gtest/gtest.h" + +using namespace icsneo; + +#define MAC_SIZE (6) +static const uint8_t correctDeviceMAC[MAC_SIZE] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; +static const uint8_t correctHostMAC[MAC_SIZE] = {0x12, 0x23, 0x34, 0x45, 0x56, 0x67}; + +class EthernetPacketizerTest : public ::testing::Test { +protected: + // Start with a clean instance of eventmanager for every test + void SetUp() override { + onError = [](APIEvent::Type, APIEvent::Severity) { + // Unless caught by the test, the packetizer should not throw errors + EXPECT_TRUE(false); + }; + packetizer.emplace([this](APIEvent::Type t, APIEvent::Severity s) { + onError(t, s); + }); + memcpy(packetizer->deviceMAC, correctDeviceMAC, MAC_SIZE); + memcpy(packetizer->hostMAC, correctHostMAC, MAC_SIZE); + } + + void TearDown() override { + packetizer.reset(); + } + + optional packetizer; + device_eventhandler_t onError; +}; + +TEST_F(EthernetPacketizerTest, DownSmallSinglePacket) +{ + packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); + const auto output = packetizer->outputDown(); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output.front(), std::vector({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0x09, 0x00, // 9 bytes + 0x00, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 + })); +} + +TEST_F(EthernetPacketizerTest, DownSmallMultiplePackets) +{ + packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); + packetizer->inputDown({ 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee }); + const auto output = packetizer->outputDown(); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output.front(), std::vector({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0x12, 0x00, // 18 bytes + 0x00, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, + 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee + })); +} + +TEST_F(EthernetPacketizerTest, DownSmallMultiplePacketsOverflow) +{ + packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); + packetizer->inputDown({ 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee }); + packetizer->inputDown(std::vector(1480)); // Near the max + const auto output = packetizer->outputDown(); + ASSERT_EQ(output.size(), 2); + EXPECT_EQ(output.front(), std::vector({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0x12, 0x00, // 18 bytes + 0x00, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, + 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee + })); + std::vector bigOutput({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0xc8, 0x05, // 1480 bytes + 0x01, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + }); + bigOutput.resize(1480 + 24); + EXPECT_EQ(output.back().size(), bigOutput.size()); + EXPECT_EQ(output.back(), bigOutput); +} + +TEST_F(EthernetPacketizerTest, DownOverflowSmallMultiplePackets) +{ + packetizer->inputDown(std::vector(1486)); // Near the max, not enough room for the next packet + packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); + packetizer->inputDown({ 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee }); + const auto output = packetizer->outputDown(); + ASSERT_EQ(output.size(), 2); + std::vector bigOutput({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0xce, 0x05, // 1486 bytes + 0x00, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + }); + bigOutput.resize(1486 + 24); + EXPECT_EQ(output.front().size(), bigOutput.size()); + EXPECT_EQ(output.front(), bigOutput); + EXPECT_EQ(output.back(), std::vector({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0x12, 0x00, // 18 bytes + 0x01, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, + 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee + })); +} + +TEST_F(EthernetPacketizerTest, DownBigSmallSmall) +{ + packetizer->inputDown(std::vector(1480)); // Near the max, enough room for the next packet + packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); + packetizer->inputDown({ 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee }); // Not enough room for this one + const auto output = packetizer->outputDown(); + ASSERT_EQ(output.size(), 2); + std::vector bigOutput({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0xd1, 0x05, // 1486 bytes + 0x00, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + }); + bigOutput.resize(1480 + 24); + bigOutput.insert(bigOutput.end(), { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); + EXPECT_EQ(output.front().size(), bigOutput.size()); + EXPECT_EQ(output.front(), bigOutput); + EXPECT_EQ(output.back(), std::vector({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0x9, 0x00, // 9 bytes + 0x01, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee + })); +} + +TEST_F(EthernetPacketizerTest, DownJumboSmallSmall) +{ + packetizer->inputDown(std::vector(3000)); // Two full packets plus 20 bytes + packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); + packetizer->inputDown({ 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee }); + const auto output = packetizer->outputDown(); + ASSERT_EQ(output.size(), 3); + std::vector bigOutput({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0xd2, 0x05, // 1490 bytes + 0x00, 0x00, // packet number + 0x01, 0x01, // first piece, version 1 + }); + bigOutput.resize(1490 + 24); // Full packet + EXPECT_EQ(output.front(), bigOutput); + std::vector bigOutput2({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0xd2, 0x05, // 1490 bytes + 0x00, 0x00, // packet number + 0x00, 0x01, // mid piece, version 1 + }); + bigOutput2.resize(1490 + 24); // Full packet + EXPECT_EQ(output[1], bigOutput2); + EXPECT_EQ(output.back(), std::vector({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0x26, 0x00, // 38 bytes + 0x00, 0x00, // packet number + 0x02, 0x01, // last piece, version 1 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, + 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee + })); +} + +TEST_F(EthernetPacketizerTest, PacketNumberIncrement) +{ + packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); + auto output = packetizer->outputDown(); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output.front(), std::vector({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0x09, 0x00, // 9 bytes + 0x00, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 + })); + + packetizer->inputDown({ 0x12, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); + output = packetizer->outputDown(); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output.front(), std::vector({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0x09, 0x00, // 9 bytes + 0x01, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + 0x12, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 + })); + + packetizer->inputDown({ 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); + output = packetizer->outputDown(); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output.front(), std::vector({ + 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, + 0xca, 0xb1, + 0xaa, 0xaa, 0x55, 0x55, + 0x09, 0x00, // 9 bytes + 0x02, 0x00, // packet number + 0x03, 0x01, // first and last piece, version 1 + 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 + })); +} \ No newline at end of file From a1a544045b2616f98235d9fef308a6a2aff05077 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Thu, 23 Sep 2021 21:30:48 -0400 Subject: [PATCH 04/26] Ethernet Comm Devices: Disable unnecessary align16bit --- include/icsneo/device/tree/neovifire2/neovifire2eth.h | 5 +++++ include/icsneo/device/tree/neovired2/neovired2.h | 5 +++++ include/icsneo/device/tree/valuecan4/valuecan4-2eleth.h | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/include/icsneo/device/tree/neovifire2/neovifire2eth.h b/include/icsneo/device/tree/neovifire2/neovifire2eth.h index 7771c37..4fbb4fa 100644 --- a/include/icsneo/device/tree/neovifire2/neovifire2eth.h +++ b/include/icsneo/device/tree/neovifire2/neovifire2eth.h @@ -57,6 +57,11 @@ protected: // TODO Check firmware version, old firmwares will reset Ethernet settings on settings send ssettings.readonly = true; } + + void setupPacketizer(Packetizer& packetizer) override { + NeoVIFIRE2::setupPacketizer(packetizer); + packetizer.align16bit = false; + } }; } diff --git a/include/icsneo/device/tree/neovired2/neovired2.h b/include/icsneo/device/tree/neovired2/neovired2.h index fdb9df7..769962e 100644 --- a/include/icsneo/device/tree/neovired2/neovired2.h +++ b/include/icsneo/device/tree/neovired2/neovired2.h @@ -77,6 +77,11 @@ protected: encoder.supportCANFD = true; } + void setupPacketizer(Packetizer& packetizer) override { + Device::setupPacketizer(packetizer); + packetizer.align16bit = false; + } + virtual void setupSupportedRXNetworks(std::vector& rxNetworks) override { for(auto& netid : GetSupportedNetworks()) rxNetworks.emplace_back(netid); diff --git a/include/icsneo/device/tree/valuecan4/valuecan4-2eleth.h b/include/icsneo/device/tree/valuecan4/valuecan4-2eleth.h index 9560fcf..89eca4a 100644 --- a/include/icsneo/device/tree/valuecan4/valuecan4-2eleth.h +++ b/include/icsneo/device/tree/valuecan4/valuecan4-2eleth.h @@ -48,6 +48,12 @@ public: bool currentDriverSupportsDFU() const override { return false; } +protected: + void setupPacketizer(Packetizer& packetizer) override { + ValueCAN4_2EL::setupPacketizer(packetizer); + packetizer.align16bit = false; + } + private: ValueCAN4_2EL_ETH(neodevice_t neodevice) : ValueCAN4_2EL(neodevice) { initialize(); From 51626b9e6303da86bbd1237f757ffcfe3b6abc06 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Thu, 23 Sep 2021 21:31:59 -0400 Subject: [PATCH 05/26] POSIX: PCAP: Use EthernetPacketizer --- include/icsneo/platform/posix/pcap.h | 23 +----- platform/posix/pcap.cpp | 118 ++++++--------------------- 2 files changed, 25 insertions(+), 116 deletions(-) diff --git a/include/icsneo/platform/posix/pcap.h b/include/icsneo/platform/posix/pcap.h index e221c68..8981fcf 100644 --- a/include/icsneo/platform/posix/pcap.h +++ b/include/icsneo/platform/posix/pcap.h @@ -5,6 +5,7 @@ #include "icsneo/device/neodevice.h" #include "icsneo/communication/driver.h" +#include "icsneo/communication/ethernetpacketizer.h" #include "icsneo/api/eventmanager.h" #include #include @@ -32,6 +33,7 @@ private: neodevice_t& device; uint8_t deviceMAC[6]; bool openable = true; + EthernetPacketizer ethPacketizer; void readTask(); void writeTask(); @@ -47,27 +49,6 @@ private: }; static std::vector knownInterfaces; NetworkInterface iface; - - class EthernetPacket { - public: // Don't worry about endian when setting fields, this is all taken care of in getBytestream - EthernetPacket() {}; - EthernetPacket(const std::vector& bytestream); - EthernetPacket(const uint8_t* data, size_t size); - int loadBytestream(const std::vector& bytestream); - std::vector getBytestream() const; - uint8_t errorWhileDecodingFromBytestream = 0; // Not part of final bytestream, only for checking the result of the constructor - uint8_t destMAC[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - uint8_t srcMAC[6] = { 0x00, 0xFC, 0x70, 0xFF, 0xFF, 0xFF }; - uint16_t etherType = 0xCAB1; // Big endian, Should be 0xCAB1 or 0xCAB2 - uint32_t icsEthernetHeader = 0xAAAA5555; // Big endian, Should be 0xAAAA5555 - // At this point in the packet, there is a 16-bit payload size, little endian - // This is calculated from payload size in getBytestream - uint16_t packetNumber = 0; - bool firstPiece = true; // These booleans make up a 16-bit bitfield, packetInfo - bool lastPiece = true; - bool bufferHalfFull = false; - std::vector payload; - }; }; } diff --git a/platform/posix/pcap.cpp b/platform/posix/pcap.cpp index 969b57a..468dce1 100644 --- a/platform/posix/pcap.cpp +++ b/platform/posix/pcap.cpp @@ -124,7 +124,7 @@ std::vector PCAP::FindAll() { pcap_setnonblock(iface.fp, 1, errbuf); - EthernetPacket requestPacket; + EthernetPacketizer::EthernetPacket requestPacket; memcpy(requestPacket.srcMAC, iface.macAddress, sizeof(requestPacket.srcMAC)); requestPacket.payload.reserve(4); requestPacket.payload = { @@ -153,7 +153,7 @@ std::vector PCAP::FindAll() { if(res == 0) continue; // Keep waiting for that packet - EthernetPacket packet(data, header->caplen); + EthernetPacketizer::EthernetPacket packet(data, header->caplen); // Is this an ICS response packet (0xCAB2) from an ICS MAC, either to broadcast or directly to us? if(packet.etherType == 0xCAB2 && packet.srcMAC[0] == 0x00 && packet.srcMAC[1] == 0xFC && packet.srcMAC[2] == 0x70 && ( memcmp(packet.destMAC, iface.macAddress, sizeof(packet.destMAC)) == 0 || @@ -201,7 +201,7 @@ bool PCAP::IsHandleValid(neodevice_handle_t handle) { return (netifIndex < knownInterfaces.size()); } -PCAP::PCAP(device_eventhandler_t err, neodevice_t& forDevice) : Driver(err), device(forDevice) { +PCAP::PCAP(device_eventhandler_t err, neodevice_t& forDevice) : Driver(err), device(forDevice), ethPacketizer(err) { if(IsHandleValid(device.handle)) { iface = knownInterfaces[(device.handle >> 24) & 0xFF]; iface.fp = nullptr; // We're going to open our own connection to the interface. This should already be nullptr but just in case. @@ -212,6 +212,8 @@ PCAP::PCAP(device_eventhandler_t err, neodevice_t& forDevice) : Driver(err), dev deviceMAC[3] = (device.handle >> 16) & 0xFF; deviceMAC[4] = (device.handle >> 8) & 0xFF; deviceMAC[5] = device.handle & 0xFF; + memcpy(ethPacketizer.deviceMAC, deviceMAC, 6); + memcpy(ethPacketizer.hostMAC, iface.macAddress, 6); } else { openable = false; } @@ -277,110 +279,36 @@ void PCAP::readTask() { EventManager::GetInstance().downgradeErrorsOnCurrentThread(); while (!closing) { pcap_dispatch(iface.fp, -1, [](uint8_t* obj, const struct pcap_pkthdr* header, const uint8_t* data) { - PCAP* driver = (PCAP*)obj; - EthernetPacket packet(data, header->caplen); - - if(packet.etherType != 0xCAB2) - return; // Not a packet to host - - if(memcmp(packet.destMAC, driver->iface.macAddress, sizeof(packet.destMAC)) != 0 && - memcmp(packet.destMAC, BROADCAST_MAC, sizeof(packet.destMAC)) != 0 && - memcmp(packet.destMAC, ICS_UNSET_MAC, sizeof(packet.destMAC)) != 0) - return; // Packet is not addressed to us or broadcast - - if(memcmp(packet.srcMAC, driver->deviceMAC, sizeof(driver->deviceMAC)) != 0) - return; // Not a packet from the device we're concerned with - - driver->readQueue.enqueue_bulk(packet.payload.data(), packet.payload.size()); + PCAP* driver = reinterpret_cast(obj); + if(driver->ethPacketizer.inputUp({data, data + header->caplen})) { + const auto bytes = driver->ethPacketizer.outputUp(); + driver->readQueue.enqueue_bulk(bytes.data(), bytes.size()); + } }, (uint8_t*)this); } } void PCAP::writeTask() { WriteOperation writeOp; - uint16_t sequence = 0; - EthernetPacket sendPacket; EventManager::GetInstance().downgradeErrorsOnCurrentThread(); - - // Set MAC address of packet - memcpy(sendPacket.srcMAC, iface.macAddress, sizeof(sendPacket.srcMAC)); - memcpy(sendPacket.destMAC, deviceMAC, sizeof(deviceMAC)); while(!closing) { if(!writeQueue.wait_dequeue_timed(writeOp, std::chrono::milliseconds(100))) continue; - sendPacket.packetNumber = sequence++; - sendPacket.payload = std::move(writeOp.bytes); - auto bs = sendPacket.getBytestream(); - if(!closing) - pcap_sendpacket(iface.fp, bs.data(), (int)bs.size()); + // If we have a bunch of small packets to send, try to pack them into a packet + // We use the average packet size to determine if we're likely to have enough room + size_t bytesPushed = 0; + size_t packetsPushed = 0; + do { + packetsPushed++; + bytesPushed += writeOp.bytes.size(); + ethPacketizer.inputDown(std::move(writeOp.bytes)); + } while(bytesPushed < (EthernetPacketizer::MaxPacketLength - (bytesPushed / packetsPushed * 2)) && writeQueue.try_dequeue(writeOp)); + + for(const auto& packet : ethPacketizer.outputDown()) { + pcap_sendpacket(iface.fp, packet.data(), (int)packet.size()); + } // TODO Handle packet send errors } } - -PCAP::EthernetPacket::EthernetPacket(const std::vector& bytestream) { - loadBytestream(bytestream); -} - -PCAP::EthernetPacket::EthernetPacket(const uint8_t* data, size_t size) { - std::vector bs(size); - for(size_t i = 0; i < size; i++) - bs[i] = data[i]; - loadBytestream(bs); -} - -int PCAP::EthernetPacket::loadBytestream(const std::vector& bytestream) { - errorWhileDecodingFromBytestream = 0; - for(size_t i = 0; i < 6; i++) - destMAC[i] = bytestream[i]; - for(size_t i = 0; i < 6; i++) - srcMAC[i] = bytestream[i + 6]; - etherType = (bytestream[12] << 8) | bytestream[13]; - icsEthernetHeader = (bytestream[14] << 24) | (bytestream[15] << 16) | (bytestream[16] << 8) | bytestream[17]; - uint16_t payloadSize = bytestream[18] | (bytestream[19] << 8); - packetNumber = bytestream[20] | (bytestream[21] << 8); - uint16_t packetInfo = bytestream[22] | (bytestream[23] << 8); - firstPiece = packetInfo & 1; - lastPiece = (packetInfo >> 1) & 1; - bufferHalfFull = (packetInfo >> 2) & 2; - payload = std::vector(bytestream.begin() + 24, bytestream.end()); - size_t payloadActualSize = payload.size(); - if(payloadActualSize < payloadSize) - errorWhileDecodingFromBytestream = 1; - payload.resize(payloadSize); - return errorWhileDecodingFromBytestream; -} - -std::vector PCAP::EthernetPacket::getBytestream() const { - size_t payloadSize = payload.size(); - std::vector bytestream; - bytestream.reserve(6 + 6 + 2 + 4 + 2 + 2 + 2 + payloadSize); - for(size_t i = 0; i < 6; i++) - bytestream.push_back(destMAC[i]); - for(size_t i = 0; i < 6; i++) - bytestream.push_back(srcMAC[i]); - // EtherType should be put into the bytestream as big endian - bytestream.push_back((uint8_t)(etherType >> 8)); - bytestream.push_back((uint8_t)(etherType)); - // Our Ethernet header should be put into the bytestream as big endian - bytestream.push_back((uint8_t)(icsEthernetHeader >> 24)); - bytestream.push_back((uint8_t)(icsEthernetHeader >> 16)); - bytestream.push_back((uint8_t)(icsEthernetHeader >> 8)); - bytestream.push_back((uint8_t)(icsEthernetHeader)); - // The payload size comes next, it's little endian - bytestream.push_back((uint8_t)(payloadSize)); - bytestream.push_back((uint8_t)(payloadSize >> 8)); - // Packet number is little endian - bytestream.push_back((uint8_t)(packetNumber)); - bytestream.push_back((uint8_t)(packetNumber >> 8)); - // Packet info gets assembled into a bitfield - uint16_t packetInfo = 0; - packetInfo |= firstPiece & 1; - packetInfo |= (lastPiece & 1) << 1; - packetInfo |= (bufferHalfFull & 1) << 2; - bytestream.push_back((uint8_t)(packetInfo)); - bytestream.push_back((uint8_t)(packetInfo >> 8)); - bytestream.insert(bytestream.end(), payload.begin(), payload.end()); - return bytestream; -} \ No newline at end of file From 181223375a0cc02fc2c0aa71cbcc30f2c709e081 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 16 Nov 2021 19:27:38 -0500 Subject: [PATCH 06/26] ValueCAN 4 Industrial: Disable 16-bit alignment over Ethernet This is a continuation of a1a544045b2616f98235d9fef308a6a2aff05077 --- .../icsneo/device/tree/valuecan4/valuecan4industrialeth.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/icsneo/device/tree/valuecan4/valuecan4industrialeth.h b/include/icsneo/device/tree/valuecan4/valuecan4industrialeth.h index bc7aa8c..c107bb1 100644 --- a/include/icsneo/device/tree/valuecan4/valuecan4industrialeth.h +++ b/include/icsneo/device/tree/valuecan4/valuecan4industrialeth.h @@ -59,6 +59,11 @@ public: bool currentDriverSupportsDFU() const override { return false; } protected: + void setupPacketizer(Packetizer& packetizer) override { + ValueCAN4Industrial::setupPacketizer(packetizer); + packetizer.align16bit = false; + } + virtual void setupSupportedRXNetworks(std::vector& rxNetworks) override { for(auto& netid : GetSupportedNetworks()) rxNetworks.emplace_back(netid); From 9d5bad94d4718c75f9c7f16d43c103f134efea01 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 16 Nov 2021 19:35:20 -0500 Subject: [PATCH 07/26] Encoder: Add 1 to host-to-device long format packets Vehicle Spy 3 does this, it's a long-standing firmware idiosyncrasy. Due to the way the device handles packets, this didn't cause a loss of communication, only a "host to device byte" app error under certain circumstances. --- communication/encoder.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/communication/encoder.cpp b/communication/encoder.cpp index b1d8e20..3c92c27 100644 --- a/communication/encoder.cpp +++ b/communication/encoder.cpp @@ -109,9 +109,10 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector& result, if(shortFormat) { buffer.insert(buffer.begin(), (uint8_t(buffer.size()) << 4) | uint8_t(message->network.getNetID())); } else { - // Size in long format is the size of the entire packet + // Size for the host-to-device long format is the size of the entire packet + 1 // So +1 for AA header, +1 for short format header, +2 for long format size, and +2 for long format NetID - uint16_t size = uint16_t(buffer.size()) + 1 + 1 + 2 + 2; + // Then an extra +1, due to a firmware idiosyncrasy + uint16_t size = uint16_t(buffer.size()) + 1 + 1 + 2 + 2 + 1; buffer.insert(buffer.begin(), { (uint8_t)Network::NetID::RED, // 0x0C for long message (uint8_t)size, // Size, little endian 16-bit From d097fb9a744f1ca6b6d0f4796e1f2677abe53ec5 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 16 Nov 2021 19:48:55 -0500 Subject: [PATCH 08/26] CANPacket: Remove unused byte from datastream --- communication/packet/canpacket.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/communication/packet/canpacket.cpp b/communication/packet/canpacket.cpp index c20a3d9..39a878a 100644 --- a/communication/packet/canpacket.cpp +++ b/communication/packet/canpacket.cpp @@ -198,7 +198,7 @@ bool HardwareCANPacket::EncodeFromMessage(const CANMessage& message, std::vector } // Pre-allocate as much memory as we will possibly need for speed - result.reserve(17 + dataSize + paddingBytes); + result.reserve(16 + dataSize + paddingBytes); result.push_back(0 /* byte count here later */ << 4 | (uint8_t(message.network.getNetID()) & 0xF)); @@ -247,7 +247,6 @@ bool HardwareCANPacket::EncodeFromMessage(const CANMessage& message, std::vector // Now finally the payload result.insert(result.end(), message.data.begin(), message.data.end()); result.resize(result.size() + paddingBytes); - result.push_back(0); // Fill in the length byte from earlier result[0] |= result.size() << 4; From 714db03a0564a32122dff66a89fed2e3fc3abfeb Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 16 Nov 2021 19:49:08 -0500 Subject: [PATCH 09/26] CMake: Set CXX_STANDARD to C++11 if not set elsewhere We need at least C++11. If we're statically compiling into an application, we want to be using the same CXX_STANDARD as it for ABI compatibility (particularly with icsneo::optional), hence having the check around it. --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 551b558..ef3a579 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,9 @@ option(LIBICSNEO_BUILD_ICSNEOC_STATIC "Build static C library" ON) option(LIBICSNEO_BUILD_ICSNEOLEGACY "Build icsnVC40 compatibility library" ON) set(LIBICSNEO_NPCAP_INCLUDE_DIR "" CACHE STRING "Npcap include directory; set to build with Npcap") -set(CMAKE_CXX_STANDARD_REQUIRED 11) +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) +endif() include(GNUInstallDirs) From 0ce7326b8352a3b95eaab7e1e299daf109d2b418 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Fri, 4 Feb 2022 01:14:08 -0500 Subject: [PATCH 10/26] Windows: PCAP: Fix a race which could cause transmit delays If you had a chain of packets being sent all at once, the latter section of packets could be delayed, theoretically infinitely. If queue1 was filled and enqueued for transmit, then queue2 had packets enqueued in it while queue1 was still transmitting, we'd try to fill queue2 further rather than waiting for queue1's transmit to finish. However, in that case, we wouldn't check if we could transmit queue2 again until the next packet. If the user application was waiting for the response from something in queue2 before pushing more packets, it could hang indefinitely. This also fixes a subtle bug where hitting the "not safe to try to fit any more packets in this queue" limit would cause a packet to drop, as it would be dequeued and then tossed. Closes GH-42 --- platform/windows/pcap.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/platform/windows/pcap.cpp b/platform/windows/pcap.cpp index c8a65b1..f5de8b4 100644 --- a/platform/windows/pcap.cpp +++ b/platform/windows/pcap.cpp @@ -285,26 +285,34 @@ void PCAP::writeTask() { pcap_send_queue* queue1 = pcap.sendqueue_alloc(128000); pcap_send_queue* queue2 = pcap.sendqueue_alloc(128000); pcap_send_queue* queue = queue1; - std::vector extraData; while(!closing) { - if(!writeQueue.wait_dequeue_timed(writeOp, std::chrono::milliseconds(100))) - continue; + // Potentially, we added frames to a second queue faster than the other thread was able to hand the first + // off to the kernel. In that case, wait for a minimal amount of time before checking whether we can + // transmit it again. + if(writeQueue.wait_dequeue_timed(writeOp, std::chrono::milliseconds(queue->len ? 1 : 100))) { + unsigned int i = 0; + do { + ethPacketizer.inputDown(std::move(writeOp.bytes)); + if(i++ >= (queue->maxlen - queue->len) / 1518 / 3) + break; // Not safe to try to fit any more packets in this queue, let it transmit and come around again + } while(writeQueue.try_dequeue(writeOp)); - unsigned int i = 0; - do { - ethPacketizer.inputDown(std::move(writeOp.bytes)); - } while(writeQueue.try_dequeue(writeOp) && i++ < (queue->maxlen - queue->len) / 1518 / 3); - - for(const auto& data : ethPacketizer.outputDown()) { - pcap_pkthdr header = {}; - header.caplen = header.len = bpf_u_int32(data.size()); - if(pcap.sendqueue_queue(queue, &header, data.data()) == -1) - report(APIEvent::Type::FailedToWrite, APIEvent::Severity::EventWarning); + for(const auto& data : ethPacketizer.outputDown()) { + pcap_pkthdr header = {}; + header.caplen = header.len = bpf_u_int32(data.size()); + if(pcap.sendqueue_queue(queue, &header, data.data()) != 0) + report(APIEvent::Type::FailedToWrite, APIEvent::Severity::EventWarning); + } } std::unique_lock lk(transmitQueueMutex); - if(!transmitQueue || queue->len + (1518*2) >= queue->maxlen) { // Checking if we want to swap sendqueues with the transmitTask + // Check if we want to transmit our current queue + // If we're not currently transmitting a queue, let this one transmit immediately for good latency + // If our queue is full and we're transmitting the other, we can't accept any more packets out of the writeQueue + // In that case we're putting as many packets into the driver as possible, so wait for it to be free + // This puts the backpressure on the writeQueue + if(queue->len && (!transmitQueue || queue->len + (1518*2) >= queue->maxlen)) { if(transmitQueue) // Need to wait for the queue to become available transmitQueueCV.wait(lk, [this] { return !transmitQueue; }); From d35653e3d09e95a72a1690faa0066ee144ee806e Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 14 Feb 2022 19:24:46 -0500 Subject: [PATCH 11/26] Windows: PCAP: Fix WinPCAP loading Used when LIBICSNEO_NPCAP_INCLUDE_DIR is not defined --- platform/windows/internal/pcapdll.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/windows/internal/pcapdll.cpp b/platform/windows/internal/pcapdll.cpp index 80a6223..02672f0 100644 --- a/platform/windows/internal/pcapdll.cpp +++ b/platform/windows/internal/pcapdll.cpp @@ -28,19 +28,21 @@ bool PCAPDLL::ok() const PCAPDLL::PCAPDLL() { +#ifdef NPCAP // Use -DLIBICSNEO_NPCAP_INCLUDE_DIR when configuring, point towards the npcap includes DLL_DIRECTORY_COOKIE cookie = 0; -#ifdef NPCAP TCHAR dllPath[512] = { 0 }; int len = GetSystemDirectory(dllPath, 480); // be safe if (len) { _tcscat_s(dllPath, 512, TEXT("\\Npcap")); cookie = AddDllDirectory(dllPath); } -#endif dll = LoadLibraryEx(TEXT("wpcap.dll"), nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS); if (cookie) RemoveDllDirectory(cookie); +#else // Otherwise we'll use WinPCAP, or npcap in compatibility mode + dll = LoadLibrary(TEXT("wpcap.dll")); +#endif if(dll == NULL) { closeDLL(); From be219288dc03f6612b9d62e0f2c33ddf7d06d303 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 21 Feb 2022 20:13:28 -0500 Subject: [PATCH 12/26] CI: Add Windows --- .gitlab-ci.yml | 27 +++++++++++++++++++++++++++ ci/build-windows.bat | 12 ++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 ci/build-windows.bat diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..391effc --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,27 @@ +stages: + - build + - test + +build windows/x64: + stage: build + script: + - CMD.EXE /C ci\build-windows.bat + artifacts: + when: always + paths: + - build + expire_in: 3 days + tags: + - icsneo-windows + +test windows/x64: + stage: test + script: + - CMD.EXE /C build\libicsneo-tests.exe + dependencies: + - build windows/x64 + needs: + - build windows/x64 + tags: + - icsneo-windows + timeout: 3m diff --git a/ci/build-windows.bat b/ci/build-windows.bat new file mode 100644 index 0000000..5871e98 --- /dev/null +++ b/ci/build-windows.bat @@ -0,0 +1,12 @@ +call "%VCVARS64%" + +REM clean intermediate directories +rmdir /s /q build +mkdir build + +REM build +cd build +cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBICSNEO_BUILD_TESTS=ON .. +if %errorlevel% neq 0 exit /b %errorlevel% +cmake --build . +if %errorlevel% neq 0 exit /b %errorlevel% From 6fa469de5f47a5626ac89b6ca58160a25de5387b Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 21 Feb 2022 20:26:57 -0500 Subject: [PATCH 13/26] Tests: Spaces to Tabs --- test/eventmanagertest.cpp | 792 +++++++++++++++++++------------------- test/main.cpp | 4 +- 2 files changed, 398 insertions(+), 398 deletions(-) diff --git a/test/eventmanagertest.cpp b/test/eventmanagertest.cpp index 4e5223c..0adfb15 100644 --- a/test/eventmanagertest.cpp +++ b/test/eventmanagertest.cpp @@ -9,10 +9,10 @@ using namespace icsneo; class EventManagerTest : public ::testing::Test { protected: - // Start with a clean instance of eventmanager for every test - void SetUp() override { - EventManager::GetInstance().ResetInstance(); - } + // Start with a clean instance of eventmanager for every test + void SetUp() override { + EventManager::GetInstance().ResetInstance(); + } }; /** @@ -21,68 +21,68 @@ protected: * Each callback also flushes the event buffer upon call. */ TEST_F(EventManagerTest, MultithreadedEventCallbacksTest) { - int callCounter = 0; - std::mutex mutex; + int callCounter = 0; + std::mutex mutex; - std::thread t1([&callCounter, &mutex]() { - // increments counter when baudrate events show up - int id1 = EventManager::GetInstance().addEventCallback(EventCallback([&callCounter, &mutex](std::shared_ptr){ - std::lock_guard lk(mutex); - callCounter++; - EventManager::GetInstance().get(); - }, EventFilter(APIEvent::Type::BaudrateNotFound))); + std::thread t1([&callCounter, &mutex]() { + // increments counter when baudrate events show up + int id1 = EventManager::GetInstance().addEventCallback(EventCallback([&callCounter, &mutex](std::shared_ptr){ + std::lock_guard lk(mutex); + callCounter++; + EventManager::GetInstance().get(); + }, EventFilter(APIEvent::Type::BaudrateNotFound))); - // shouldn't add anything - EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::EventWarning)); + // shouldn't add anything + EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::EventWarning)); - // should add 1 - EventManager::GetInstance().add(APIEvent(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventWarning)); + // should add 1 + EventManager::GetInstance().add(APIEvent(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventWarning)); - EventManager::GetInstance().removeEventCallback(id1); + EventManager::GetInstance().removeEventCallback(id1); - }); + }); - std::thread t2([&callCounter, &mutex]() { - // increments counter when infos show up - int id2 = EventManager::GetInstance().addEventCallback(EventCallback([&callCounter, &mutex](std::shared_ptr) { - std::lock_guard lk(mutex); - callCounter++; - EventManager::GetInstance().get(); - }, EventFilter(APIEvent::Severity::EventInfo))); + std::thread t2([&callCounter, &mutex]() { + // increments counter when infos show up + int id2 = EventManager::GetInstance().addEventCallback(EventCallback([&callCounter, &mutex](std::shared_ptr) { + std::lock_guard lk(mutex); + callCounter++; + EventManager::GetInstance().get(); + }, EventFilter(APIEvent::Severity::EventInfo))); - // shouldn't add anything - EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::EventWarning)); + // shouldn't add anything + EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::EventWarning)); - // should add 1 - EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::EventInfo)); + // should add 1 + EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::EventInfo)); - EventManager::GetInstance().removeEventCallback(id2); - }); + EventManager::GetInstance().removeEventCallback(id2); + }); - t1.join(); - t2.join(); + t1.join(); + t2.join(); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(EventCount(), 0); - EXPECT_EQ(callCounter, 2); + EXPECT_EQ(callCounter, 2); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 1); + EXPECT_EQ(EventCount(), 1); - EXPECT_EQ(callCounter, 2); + EXPECT_EQ(callCounter, 2); } /** * Tests behavior of adding and removing multiple event callbacks on a single thread. */ TEST_F(EventManagerTest, SingleThreadEventCallbacksTest) { - int callCounter = 0; + int callCounter = 0; // increments counter when baudrate events show up - int id1 = EventManager::GetInstance().addEventCallback(EventCallback([&callCounter](std::shared_ptr){ - callCounter++; - }, EventFilter(APIEvent::Type::BaudrateNotFound))); + int id1 = EventManager::GetInstance().addEventCallback(EventCallback([&callCounter](std::shared_ptr){ + callCounter++; + }, EventFilter(APIEvent::Type::BaudrateNotFound))); // increments counter when infos show up int id2 = EventManager::GetInstance().addEventCallback(EventCallback([&callCounter](std::shared_ptr) { @@ -95,7 +95,7 @@ TEST_F(EventManagerTest, SingleThreadEventCallbacksTest) { EXPECT_EQ(callCounter, 0); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventWarning)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventWarning)); EXPECT_EQ(callCounter, 1); @@ -117,31 +117,31 @@ TEST_F(EventManagerTest, SingleThreadEventCallbacksTest) { EXPECT_EQ(callCounter, 5); - // increments counter when device currently open shows up + // increments counter when device currently open shows up int id3 = EventManager::GetInstance().addEventCallback(EventCallback([&callCounter](std::shared_ptr) { callCounter++; }, EventFilter(APIEvent::Type::DeviceCurrentlyOpen))); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyOpen, APIEvent::Severity::EventInfo)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyOpen, APIEvent::Severity::EventInfo)); EXPECT_EQ(callCounter, 6); - EXPECT_EQ(EventManager::GetInstance().removeEventCallback(id2), false); + EXPECT_EQ(EventManager::GetInstance().removeEventCallback(id2), false); EXPECT_EQ(EventManager::GetInstance().removeEventCallback(id1), true); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo)); - EXPECT_EQ(callCounter, 6); + EXPECT_EQ(callCounter, 6); EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyOpen, APIEvent::Severity::EventInfo)); EXPECT_EQ(callCounter, 7); - EXPECT_EQ(EventManager::GetInstance().removeEventCallback(id3), true); + EXPECT_EQ(EventManager::GetInstance().removeEventCallback(id3), true); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyOpen, APIEvent::Severity::EventInfo)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyOpen, APIEvent::Severity::EventInfo)); - EXPECT_EQ(callCounter, 7); + EXPECT_EQ(callCounter, 7); } /** @@ -210,110 +210,110 @@ TEST_F(EventManagerTest, ErrorDowngradingTest) { */ TEST_F(EventManagerTest, MultithreadedTest) { - // Check that main thread has no errors - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); + // Check that main thread has no errors + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); - // Adds 500 {OutputTruncated, Warning} and 500 {OutputTruncated, Info} - // Adds and checks errors as well. - std::thread t1( []() { - for(int i = 0; i < 500; i++) { - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventInfo)); - } + // Adds 500 {OutputTruncated, Warning} and 500 {OutputTruncated, Info} + // Adds and checks errors as well. + std::thread t1( []() { + for(int i = 0; i < 500; i++) { + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventInfo)); + } - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::BufferInsufficient, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::BufferInsufficient, APIEvent::Severity::Error)); - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::BufferInsufficient); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::BufferInsufficient); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::OutputTruncated); - }); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::OutputTruncated); + }); - // Check that main thread has no errors - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); + // Check that main thread has no errors + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); - // Adds 500 {CANFDNotSupported, Warning} and 500 {CANFDSettingsNotAvailable, Info} - // Adds and checks errors as well. - std::thread t2( []() { - for(int i = 0; i < 500; i++) { - EventManager::GetInstance().add(APIEvent(APIEvent::Type::CANFDNotSupported, APIEvent::Severity::EventWarning)); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::CANFDSettingsNotAvailable, APIEvent::Severity::EventInfo)); - } + // Adds 500 {CANFDNotSupported, Warning} and 500 {CANFDSettingsNotAvailable, Info} + // Adds and checks errors as well. + std::thread t2( []() { + for(int i = 0; i < 500; i++) { + EventManager::GetInstance().add(APIEvent(APIEvent::Type::CANFDNotSupported, APIEvent::Severity::EventWarning)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::CANFDSettingsNotAvailable, APIEvent::Severity::EventInfo)); + } - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error)); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyOffline, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyOffline, APIEvent::Severity::Error)); - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::DeviceCurrentlyOffline); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::DeviceCurrentlyOffline); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyOnline, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::DeviceCurrentlyOnline, APIEvent::Severity::Error)); - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::DeviceCurrentlyOnline); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::DeviceCurrentlyOnline); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error)); - }); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error)); + }); - // Check that main thread has no errors - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); + // Check that main thread has no errors + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); - // Adds 500 {CANFDNotSupported, Warning} and 500 {FailedToWrite, Info} - // Adds and checks errors as well. - std::thread t3( []() { - for(int i = 0; i < 500; i++) { - EventManager::GetInstance().add(APIEvent(APIEvent::Type::CANFDNotSupported, APIEvent::Severity::EventWarning)); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::FailedToWrite, APIEvent::Severity::EventInfo)); - } + // Adds 500 {CANFDNotSupported, Warning} and 500 {FailedToWrite, Info} + // Adds and checks errors as well. + std::thread t3( []() { + for(int i = 0; i < 500; i++) { + EventManager::GetInstance().add(APIEvent(APIEvent::Type::CANFDNotSupported, APIEvent::Severity::EventWarning)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::FailedToWrite, APIEvent::Severity::EventInfo)); + } - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::NoSerialNumber, APIEvent::Severity::Error)); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::SettingsChecksumError, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::NoSerialNumber, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::SettingsChecksumError, APIEvent::Severity::Error)); - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::SettingsChecksumError); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::SettingsChecksumError); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::Error)); - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::SWCANSettingsNotAvailable); - }); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::SWCANSettingsNotAvailable); + }); - // Check that main thread has no errors - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); + // Check that main thread has no errors + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); - // Wait for threads to finish - t1.join(); - t2.join(); - t3.join(); + // Wait for threads to finish + t1.join(); + t2.join(); + t3.join(); - // Check that main thread has no errors - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); + // Check that main thread has no errors + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); - // Should be 500 {OutputTruncated, Warning}, 500 {OutputTruncated, Info}, 1000 {CANFDNotSupported, Warning}, 500 {CANFDSettingsNotAvailable, Info}, 500 {FailedToWrite, Info} - EXPECT_EQ(EventCount(), 3000); + // Should be 500 {OutputTruncated, Warning}, 500 {OutputTruncated, Info}, 1000 {CANFDNotSupported, Warning}, 500 {CANFDSettingsNotAvailable, Info}, 500 {FailedToWrite, Info} + EXPECT_EQ(EventCount(), 3000); - auto events = GetEvents(EventFilter(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); - EXPECT_EQ(EventCount(), 2500); - EXPECT_EQ(events.size(), 500); + auto events = GetEvents(EventFilter(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); + EXPECT_EQ(EventCount(), 2500); + EXPECT_EQ(events.size(), 500); - events = GetEvents(EventFilter(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 2000); - EXPECT_EQ(events.size(), 500); + events = GetEvents(EventFilter(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventInfo)); + EXPECT_EQ(EventCount(), 2000); + EXPECT_EQ(events.size(), 500); - events = GetEvents(EventFilter(APIEvent::Type::CANFDNotSupported, APIEvent::Severity::EventWarning)); - EXPECT_EQ(EventCount(), 1000); - EXPECT_EQ(events.size(), 1000); + events = GetEvents(EventFilter(APIEvent::Type::CANFDNotSupported, APIEvent::Severity::EventWarning)); + EXPECT_EQ(EventCount(), 1000); + EXPECT_EQ(events.size(), 1000); - events = GetEvents(EventFilter(APIEvent::Type::CANFDSettingsNotAvailable, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 500); - EXPECT_EQ(events.size(), 500); + events = GetEvents(EventFilter(APIEvent::Type::CANFDSettingsNotAvailable, APIEvent::Severity::EventInfo)); + EXPECT_EQ(EventCount(), 500); + EXPECT_EQ(events.size(), 500); - events = GetEvents(EventFilter(APIEvent::Type::FailedToWrite, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 0); - EXPECT_EQ(events.size(), 500); + events = GetEvents(EventFilter(APIEvent::Type::FailedToWrite, APIEvent::Severity::EventInfo)); + EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(events.size(), 500); } /** @@ -321,67 +321,67 @@ TEST_F(EventManagerTest, MultithreadedTest) { * Checks that EventCount() updates accordingly, even when overflowing (trying to add 11000 events when the limit is 10000) */ TEST_F(EventManagerTest, CountTest) { - // Add an error event, should not go into events list. - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); - EXPECT_EQ(EventCount(), 0); + // Add an error event, should not go into events list. + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); + EXPECT_EQ(EventCount(), 0); - // Adds actual event - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); + // Adds actual event + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); - // Manually tries to add some TooManyEvents, these should not be added. - EventManager::GetInstance().add(APIEvent(APIEvent::Type::TooManyEvents, APIEvent::Severity::EventWarning)); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::TooManyEvents, APIEvent::Severity::EventInfo)); + // Manually tries to add some TooManyEvents, these should not be added. + EventManager::GetInstance().add(APIEvent(APIEvent::Type::TooManyEvents, APIEvent::Severity::EventWarning)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::TooManyEvents, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 1); + EXPECT_EQ(EventCount(), 1); - // Add another actual event - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 2); + // Add another actual event + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventInfo)); + EXPECT_EQ(EventCount(), 2); - // Take all info events (1) - GetEvents(EventFilter(APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 1); + // Take all info events (1) + GetEvents(EventFilter(APIEvent::Severity::EventInfo)); + EXPECT_EQ(EventCount(), 1); - // Take all events - GetEvents(); - EXPECT_EQ(EventCount(), 0); + // Take all events + GetEvents(); + EXPECT_EQ(EventCount(), 0); - // default limit is 10000 - for(int i = 0; i < 11000; i++) - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); + // default limit is 10000 + for(int i = 0; i < 11000; i++) + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); - EXPECT_EQ(EventCount(), 10000); + EXPECT_EQ(EventCount(), 10000); } /** * Checks that the default get() clears out and returns all events. */ TEST_F(EventManagerTest, GetDefaultTest) { - for(int i = 0; i < 5; i++) { - EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning); - EventManager::GetInstance().add(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::EventInfo); + for(int i = 0; i < 5; i++) { + EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning); + EventManager::GetInstance().add(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::EventInfo); - // errors should not go in events - EventManager::GetInstance().add(APIEvent::Type::SettingsVersionError, APIEvent::Severity::Error); - } + // errors should not go in events + EventManager::GetInstance().add(APIEvent::Type::SettingsVersionError, APIEvent::Severity::Error); + } - auto events = EventManager::GetInstance().get(); + auto events = EventManager::GetInstance().get(); - EXPECT_EQ(events.size(), 10); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(events.size(), 10); + EXPECT_EQ(EventCount(), 0); - for(int i = 0; i < 5; i++) { - EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::UnexpectedNetworkType); - EXPECT_EQ(events.at(2 * i).getSeverity(), APIEvent::Severity::EventWarning); + for(int i = 0; i < 5; i++) { + EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::UnexpectedNetworkType); + EXPECT_EQ(events.at(2 * i).getSeverity(), APIEvent::Severity::EventWarning); - EXPECT_EQ(events.at(2 * i + 1).getType(), APIEvent::Type::SWCANSettingsNotAvailable); - EXPECT_EQ(events.at(2 * i + 1).getSeverity(), APIEvent::Severity::EventInfo); - } + EXPECT_EQ(events.at(2 * i + 1).getType(), APIEvent::Type::SWCANSettingsNotAvailable); + EXPECT_EQ(events.at(2 * i + 1).getSeverity(), APIEvent::Severity::EventInfo); + } - // Check getting when 0 events exist doesn't break - events = EventManager::GetInstance().get(); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 0); + // Check getting when 0 events exist doesn't break + events = EventManager::GetInstance().get(); + EXPECT_EQ(events.size(), 0); + EXPECT_EQ(EventCount(), 0); } /** @@ -389,216 +389,216 @@ TEST_F(EventManagerTest, GetDefaultTest) { */ TEST_F(EventManagerTest, GetSizeTest) { - // Add 10 events - for(int i = 0; i < 5; i++) { - EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning); - EventManager::GetInstance().add(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::EventInfo); + // Add 10 events + for(int i = 0; i < 5; i++) { + EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning); + EventManager::GetInstance().add(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::EventInfo); - // errors should not go in events - EventManager::GetInstance().add(APIEvent::Type::SettingsVersionError, APIEvent::Severity::Error); - } + // errors should not go in events + EventManager::GetInstance().add(APIEvent::Type::SettingsVersionError, APIEvent::Severity::Error); + } - // Take 3 events, 7 left - auto events = EventManager::GetInstance().get(3); + // Take 3 events, 7 left + auto events = EventManager::GetInstance().get(3); - EXPECT_EQ(events.size(), 3); - EXPECT_EQ(EventCount(), 7); + EXPECT_EQ(events.size(), 3); + EXPECT_EQ(EventCount(), 7); - EXPECT_EQ(events.at(0).getType(), APIEvent::Type::UnexpectedNetworkType); - EXPECT_EQ(events.at(0).getSeverity(), APIEvent::Severity::EventWarning); - EXPECT_EQ(events.at(1).getType(), APIEvent::Type::SWCANSettingsNotAvailable); - EXPECT_EQ(events.at(1).getSeverity(), APIEvent::Severity::EventInfo); - EXPECT_EQ(events.at(2).getType(), APIEvent::Type::UnexpectedNetworkType); - EXPECT_EQ(events.at(2).getSeverity(), APIEvent::Severity::EventWarning); + EXPECT_EQ(events.at(0).getType(), APIEvent::Type::UnexpectedNetworkType); + EXPECT_EQ(events.at(0).getSeverity(), APIEvent::Severity::EventWarning); + EXPECT_EQ(events.at(1).getType(), APIEvent::Type::SWCANSettingsNotAvailable); + EXPECT_EQ(events.at(1).getSeverity(), APIEvent::Severity::EventInfo); + EXPECT_EQ(events.at(2).getType(), APIEvent::Type::UnexpectedNetworkType); + EXPECT_EQ(events.at(2).getSeverity(), APIEvent::Severity::EventWarning); - // Take 1 event, 6 left - events = EventManager::GetInstance().get(1); + // Take 1 event, 6 left + events = EventManager::GetInstance().get(1); - EXPECT_EQ(events.size(), 1); - EXPECT_EQ(EventCount(), 6); + EXPECT_EQ(events.size(), 1); + EXPECT_EQ(EventCount(), 6); - EXPECT_EQ(events.at(0).getType(), APIEvent::Type::SWCANSettingsNotAvailable); - EXPECT_EQ(events.at(0).getSeverity(), APIEvent::Severity::EventInfo); + EXPECT_EQ(events.at(0).getType(), APIEvent::Type::SWCANSettingsNotAvailable); + EXPECT_EQ(events.at(0).getSeverity(), APIEvent::Severity::EventInfo); - // Try to take 8 events, should actually take the 6 remaining. 0 left. - events = EventManager::GetInstance().get(8); - EXPECT_EQ(events.size(), 6); - EXPECT_EQ(EventCount(), 0); + // Try to take 8 events, should actually take the 6 remaining. 0 left. + events = EventManager::GetInstance().get(8); + EXPECT_EQ(events.size(), 6); + EXPECT_EQ(EventCount(), 0); - for(int i = 0; i < 3; i++) { - EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::UnexpectedNetworkType); - EXPECT_EQ(events.at(2 * i).getSeverity(), APIEvent::Severity::EventWarning); + for(int i = 0; i < 3; i++) { + EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::UnexpectedNetworkType); + EXPECT_EQ(events.at(2 * i).getSeverity(), APIEvent::Severity::EventWarning); - EXPECT_EQ(events.at(2 * i + 1).getType(), APIEvent::Type::SWCANSettingsNotAvailable); - EXPECT_EQ(events.at(2 * i + 1).getSeverity(), APIEvent::Severity::EventInfo); - } + EXPECT_EQ(events.at(2 * i + 1).getType(), APIEvent::Type::SWCANSettingsNotAvailable); + EXPECT_EQ(events.at(2 * i + 1).getSeverity(), APIEvent::Severity::EventInfo); + } - // Check getting when 0 events exist doesn't break - events = EventManager::GetInstance().get(5); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 0); + // Check getting when 0 events exist doesn't break + events = EventManager::GetInstance().get(5); + EXPECT_EQ(events.size(), 0); + EXPECT_EQ(EventCount(), 0); } /** * Checks that get() with a filter param only flushes and returns the events matching the filter. */ TEST_F(EventManagerTest, GetFilterTest) { - // Add 20 events - for(int i = 0; i < 5; i++) { - // {network, warning}, {settings, info}, {network, info}, {mismatch, warning} - EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning); - EventManager::GetInstance().add(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::EventInfo); - EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventInfo); - EventManager::GetInstance().add(APIEvent::Type::SettingsStructureMismatch, APIEvent::Severity::EventWarning); + // Add 20 events + for(int i = 0; i < 5; i++) { + // {network, warning}, {settings, info}, {network, info}, {mismatch, warning} + EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning); + EventManager::GetInstance().add(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::EventInfo); + EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventInfo); + EventManager::GetInstance().add(APIEvent::Type::SettingsStructureMismatch, APIEvent::Severity::EventWarning); - // errors should not go in events - EventManager::GetInstance().add(APIEvent::Type::SettingsVersionError, APIEvent::Severity::Error); - } + // errors should not go in events + EventManager::GetInstance().add(APIEvent::Type::SettingsVersionError, APIEvent::Severity::Error); + } - // Get all 5 {network, warning}. 15 left. - auto events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); + // Get all 5 {network, warning}. 15 left. + auto events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); - EXPECT_EQ(events.size(), 5); - EXPECT_EQ(EventCount(), 15); + EXPECT_EQ(events.size(), 5); + EXPECT_EQ(EventCount(), 15); - for(APIEvent event : events) { - EXPECT_EQ(event.getType(), APIEvent::Type::UnexpectedNetworkType); - EXPECT_EQ(event.getSeverity(), APIEvent::Severity::EventWarning); - } + for(APIEvent event : events) { + EXPECT_EQ(event.getType(), APIEvent::Type::UnexpectedNetworkType); + EXPECT_EQ(event.getSeverity(), APIEvent::Severity::EventWarning); + } - // Get all 10 infos. 5 {mismatch, warning} remaining. - events = EventManager::GetInstance().get(EventFilter(APIEvent::Severity::EventInfo)); + // Get all 10 infos. 5 {mismatch, warning} remaining. + events = EventManager::GetInstance().get(EventFilter(APIEvent::Severity::EventInfo)); - EXPECT_EQ(events.size(), 10); - EXPECT_EQ(EventCount(), 5); + EXPECT_EQ(events.size(), 10); + EXPECT_EQ(EventCount(), 5); - for(int i = 0; i < 5; i++) { - EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::SWCANSettingsNotAvailable); - EXPECT_EQ(events.at(2 * i).getSeverity(), APIEvent::Severity::EventInfo); + for(int i = 0; i < 5; i++) { + EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::SWCANSettingsNotAvailable); + EXPECT_EQ(events.at(2 * i).getSeverity(), APIEvent::Severity::EventInfo); - EXPECT_EQ(events.at(2 * i + 1).getType(), APIEvent::Type::UnexpectedNetworkType); - EXPECT_EQ(events.at(2 * i + 1).getSeverity(), APIEvent::Severity::EventInfo); - } + EXPECT_EQ(events.at(2 * i + 1).getType(), APIEvent::Type::UnexpectedNetworkType); + EXPECT_EQ(events.at(2 * i + 1).getSeverity(), APIEvent::Severity::EventInfo); + } - // (Incorrectly) try to get settings type again. 5 {mismatch, warning} remaining. - events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::SWCANSettingsNotAvailable)); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 5); + // (Incorrectly) try to get settings type again. 5 {mismatch, warning} remaining. + events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::SWCANSettingsNotAvailable)); + EXPECT_EQ(events.size(), 0); + EXPECT_EQ(EventCount(), 5); - // Get the 5 {mismatch, warning} remaining. - events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::SettingsStructureMismatch)); - EXPECT_EQ(events.size(), 5); - EXPECT_EQ(EventCount(), 0); + // Get the 5 {mismatch, warning} remaining. + events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::SettingsStructureMismatch)); + EXPECT_EQ(events.size(), 5); + EXPECT_EQ(EventCount(), 0); - for(APIEvent event : events) { - EXPECT_EQ(event.getType(), APIEvent::Type::SettingsStructureMismatch); - EXPECT_EQ(event.getSeverity(), APIEvent::Severity::EventWarning); - } + for(APIEvent event : events) { + EXPECT_EQ(event.getType(), APIEvent::Type::SettingsStructureMismatch); + EXPECT_EQ(event.getSeverity(), APIEvent::Severity::EventWarning); + } - // Check getting when 0 events exist doesn't break - events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 0); + // Check getting when 0 events exist doesn't break + events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); + EXPECT_EQ(events.size(), 0); + EXPECT_EQ(EventCount(), 0); } /** * Checks that get() with both a size and filter param only flushes and returns the desired amount of events matching the filter. */ TEST_F(EventManagerTest, GetSizeFilterTest) { - // Add 20 events - for(int i = 0; i < 5; i++) { - // {network, warning}, {settings, info}, {network, info}, {mismatch, warning} - EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning); - EventManager::GetInstance().add(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::EventInfo); - EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventInfo); - EventManager::GetInstance().add(APIEvent::Type::SettingsStructureMismatch, APIEvent::Severity::EventWarning); + // Add 20 events + for(int i = 0; i < 5; i++) { + // {network, warning}, {settings, info}, {network, info}, {mismatch, warning} + EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning); + EventManager::GetInstance().add(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::EventInfo); + EventManager::GetInstance().add(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventInfo); + EventManager::GetInstance().add(APIEvent::Type::SettingsStructureMismatch, APIEvent::Severity::EventWarning); - // errors should not go in events - EventManager::GetInstance().add(APIEvent::Type::SettingsVersionError, APIEvent::Severity::Error); - } + // errors should not go in events + EventManager::GetInstance().add(APIEvent::Type::SettingsVersionError, APIEvent::Severity::Error); + } - // Get all 5 {network, warning}. 15 left. - auto events = EventManager::GetInstance().get(6, EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); + // Get all 5 {network, warning}. 15 left. + auto events = EventManager::GetInstance().get(6, EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); - EXPECT_EQ(events.size(), 5); - EXPECT_EQ(EventCount(), 15); + EXPECT_EQ(events.size(), 5); + EXPECT_EQ(EventCount(), 15); - for(APIEvent event : events) { - EXPECT_EQ(event.getType(), APIEvent::Type::UnexpectedNetworkType); - EXPECT_EQ(event.getSeverity(), APIEvent::Severity::EventWarning); - } + for(APIEvent event : events) { + EXPECT_EQ(event.getType(), APIEvent::Type::UnexpectedNetworkType); + EXPECT_EQ(event.getSeverity(), APIEvent::Severity::EventWarning); + } - // Get 6 infos. 4 infos and 5 {mismatch, warning} remaining. - events = EventManager::GetInstance().get(6, EventFilter(APIEvent::Severity::EventInfo)); + // Get 6 infos. 4 infos and 5 {mismatch, warning} remaining. + events = EventManager::GetInstance().get(6, EventFilter(APIEvent::Severity::EventInfo)); - EXPECT_EQ(events.size(), 6); - EXPECT_EQ(EventCount(), 9); + EXPECT_EQ(events.size(), 6); + EXPECT_EQ(EventCount(), 9); - for(int i = 0; i < 3; i++) { - EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::SWCANSettingsNotAvailable); - EXPECT_EQ(events.at(2 * i).getSeverity(), APIEvent::Severity::EventInfo); + for(int i = 0; i < 3; i++) { + EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::SWCANSettingsNotAvailable); + EXPECT_EQ(events.at(2 * i).getSeverity(), APIEvent::Severity::EventInfo); - EXPECT_EQ(events.at(2 * i + 1).getType(), APIEvent::Type::UnexpectedNetworkType); - EXPECT_EQ(events.at(2 * i + 1).getSeverity(), APIEvent::Severity::EventInfo); - } + EXPECT_EQ(events.at(2 * i + 1).getType(), APIEvent::Type::UnexpectedNetworkType); + EXPECT_EQ(events.at(2 * i + 1).getSeverity(), APIEvent::Severity::EventInfo); + } - // Get 4 remaining infos. 5 {mismatch, warning} remaining. - events = EventManager::GetInstance().get(4, EventFilter(APIEvent::Severity::EventInfo)); + // Get 4 remaining infos. 5 {mismatch, warning} remaining. + events = EventManager::GetInstance().get(4, EventFilter(APIEvent::Severity::EventInfo)); - EXPECT_EQ(events.size(), 4); - EXPECT_EQ(EventCount(), 5); + EXPECT_EQ(events.size(), 4); + EXPECT_EQ(EventCount(), 5); - for(int i = 0; i < 2; i++) { - EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::SWCANSettingsNotAvailable); - EXPECT_EQ(events.at(2 * i).getSeverity(), APIEvent::Severity::EventInfo); + for(int i = 0; i < 2; i++) { + EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::SWCANSettingsNotAvailable); + EXPECT_EQ(events.at(2 * i).getSeverity(), APIEvent::Severity::EventInfo); - EXPECT_EQ(events.at(2 * i + 1).getType(), APIEvent::Type::UnexpectedNetworkType); - EXPECT_EQ(events.at(2 * i + 1).getSeverity(), APIEvent::Severity::EventInfo); - } + EXPECT_EQ(events.at(2 * i + 1).getType(), APIEvent::Type::UnexpectedNetworkType); + EXPECT_EQ(events.at(2 * i + 1).getSeverity(), APIEvent::Severity::EventInfo); + } - // (Incorrectly) try to get settings type again. 5 {mismatch, warning} remaining. - events = EventManager::GetInstance().get(-1, EventFilter(APIEvent::Type::SWCANSettingsNotAvailable)); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 5); + // (Incorrectly) try to get settings type again. 5 {mismatch, warning} remaining. + events = EventManager::GetInstance().get(-1, EventFilter(APIEvent::Type::SWCANSettingsNotAvailable)); + EXPECT_EQ(events.size(), 0); + EXPECT_EQ(EventCount(), 5); - // Get the 5 {mismatch, warning} remaining. - events = EventManager::GetInstance().get(5, EventFilter(APIEvent::Type::SettingsStructureMismatch)); - EXPECT_EQ(events.size(), 5); - EXPECT_EQ(EventCount(), 0); + // Get the 5 {mismatch, warning} remaining. + events = EventManager::GetInstance().get(5, EventFilter(APIEvent::Type::SettingsStructureMismatch)); + EXPECT_EQ(events.size(), 5); + EXPECT_EQ(EventCount(), 0); - for(APIEvent event : events) { - EXPECT_EQ(event.getType(), APIEvent::Type::SettingsStructureMismatch); - EXPECT_EQ(event.getSeverity(), APIEvent::Severity::EventWarning); - } + for(APIEvent event : events) { + EXPECT_EQ(event.getType(), APIEvent::Type::SettingsStructureMismatch); + EXPECT_EQ(event.getSeverity(), APIEvent::Severity::EventWarning); + } - // Check getting when 0 events exist doesn't break - events = EventManager::GetInstance().get(2, EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 0); + // Check getting when 0 events exist doesn't break + events = EventManager::GetInstance().get(2, EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); + EXPECT_EQ(events.size(), 0); + EXPECT_EQ(EventCount(), 0); } /** * Checks that adding 1 error and calling GetLastError() twice will first return the error then return a NoErrorFound info message. Singlethreaded. */ TEST_F(EventManagerTest, GetLastErrorSingleTest) { - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::OutputTruncated); - auto err = GetLastError(); - EXPECT_EQ(err.getType(), APIEvent::Type::NoErrorFound); - EXPECT_EQ(err.getSeverity(), APIEvent::Severity::EventInfo); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::OutputTruncated); + auto err = GetLastError(); + EXPECT_EQ(err.getType(), APIEvent::Type::NoErrorFound); + EXPECT_EQ(err.getSeverity(), APIEvent::Severity::EventInfo); } /** * Checks that adding multiple errors and calling GetLastError() twice will first return the last error then return a NoErrorFound info message. Singlethreaded. */ TEST_F(EventManagerTest, GetLastErrorMultipleTest) { - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error)); - EventManager::GetInstance().add(APIEvent(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error)); - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::SettingsNotAvailable); - auto err = GetLastError(); - EXPECT_EQ(err.getType(), APIEvent::Type::NoErrorFound); - EXPECT_EQ(err.getSeverity(), APIEvent::Severity::EventInfo); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error)); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::SettingsNotAvailable); + auto err = GetLastError(); + EXPECT_EQ(err.getType(), APIEvent::Type::NoErrorFound); + EXPECT_EQ(err.getSeverity(), APIEvent::Severity::EventInfo); } /** @@ -607,32 +607,32 @@ TEST_F(EventManagerTest, GetLastErrorMultipleTest) { */ TEST_F(EventManagerTest, TestAddWarningsOverflow) { - // space for 49 normal events, 1 reserved for TooManyEvents - SetEventLimit(50); + // space for 49 normal events, 1 reserved for TooManyEvents + SetEventLimit(50); - // 3 of these - for(int i = 0; i < 3; i++) - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); + // 3 of these + for(int i = 0; i < 3; i++) + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); - // 1 info - EventManager::GetInstance().add(APIEvent(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::EventInfo)); + // 1 info + EventManager::GetInstance().add(APIEvent(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::EventInfo)); - // 48 of these - for(int i = 0; i < 48; i++) - EventManager::GetInstance().add(APIEvent(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::EventWarning)); + // 48 of these + for(int i = 0; i < 48; i++) + EventManager::GetInstance().add(APIEvent(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::EventWarning)); - auto events = GetEvents(); + auto events = GetEvents(); - EXPECT_EQ(events.at(0).getType(), APIEvent::Type::SWCANSettingsNotAvailable); - EXPECT_EQ(events.at(0).getSeverity(), APIEvent::Severity::EventInfo); + EXPECT_EQ(events.at(0).getType(), APIEvent::Type::SWCANSettingsNotAvailable); + EXPECT_EQ(events.at(0).getSeverity(), APIEvent::Severity::EventInfo); - for(int i = 1; i < 49; i++) { - EXPECT_EQ(events.at(i).getType(), APIEvent::Type::ParameterOutOfRange); - EXPECT_EQ(events.at(i).getSeverity(), APIEvent::Severity::EventWarning); - } + for(int i = 1; i < 49; i++) { + EXPECT_EQ(events.at(i).getType(), APIEvent::Type::ParameterOutOfRange); + EXPECT_EQ(events.at(i).getSeverity(), APIEvent::Severity::EventWarning); + } - EXPECT_EQ(events.at(49).getType(), APIEvent::Type::TooManyEvents); - EXPECT_EQ(events.at(49).getSeverity(), APIEvent::Severity::EventWarning); + EXPECT_EQ(events.at(49).getType(), APIEvent::Type::TooManyEvents); + EXPECT_EQ(events.at(49).getSeverity(), APIEvent::Severity::EventWarning); } /** @@ -641,109 +641,109 @@ TEST_F(EventManagerTest, TestAddWarningsOverflow) { */ TEST_F(EventManagerTest, TestAddWarningsInfoOverflow) { - // space for 49 normal events, 1 reserved for TooManyEvents - SetEventLimit(50); + // space for 49 normal events, 1 reserved for TooManyEvents + SetEventLimit(50); - // Event list filling: 1 warning, 3 info, 47 warning. - // Expect to see: 2 info, 47 warning, 1 TooManyEvents + // Event list filling: 1 warning, 3 info, 47 warning. + // Expect to see: 2 info, 47 warning, 1 TooManyEvents - EventManager::GetInstance().add(APIEvent(APIEvent::Type::SettingsVersionError, APIEvent::Severity::EventWarning)); + EventManager::GetInstance().add(APIEvent(APIEvent::Type::SettingsVersionError, APIEvent::Severity::EventWarning)); - // 3 of these - for(int i = 0; i < 3; i++) - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventInfo)); + // 3 of these + for(int i = 0; i < 3; i++) + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventInfo)); - // 47 of these - for(int i = 0; i < 47; i++) - EventManager::GetInstance().add(APIEvent(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::EventWarning)); + // 47 of these + for(int i = 0; i < 47; i++) + EventManager::GetInstance().add(APIEvent(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::EventWarning)); - auto events = GetEvents(); + auto events = GetEvents(); - for(int i = 0; i < 2; i++) { - EXPECT_EQ(events.at(i).getType(), APIEvent::Type::OutputTruncated); - } + for(int i = 0; i < 2; i++) { + EXPECT_EQ(events.at(i).getType(), APIEvent::Type::OutputTruncated); + } - for(int i = 2; i < 49; i++) - EXPECT_EQ(events.at(i).getType(), APIEvent::Type::ParameterOutOfRange); + for(int i = 2; i < 49; i++) + EXPECT_EQ(events.at(i).getType(), APIEvent::Type::ParameterOutOfRange); - EXPECT_EQ(events.at(49).getType(), APIEvent::Type::TooManyEvents); + EXPECT_EQ(events.at(49).getType(), APIEvent::Type::TooManyEvents); } /** * Checks that discarding with no params flushes every event. */ TEST_F(EventManagerTest, DiscardDefault) { - for(int i = 0; i < 3000; i++) { - EventManager::GetInstance().add(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo); - EventManager::GetInstance().add(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventWarning); - EventManager::GetInstance().add(APIEvent::Type::BufferInsufficient, APIEvent::Severity::EventWarning); - } + for(int i = 0; i < 3000; i++) { + EventManager::GetInstance().add(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo); + EventManager::GetInstance().add(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventWarning); + EventManager::GetInstance().add(APIEvent::Type::BufferInsufficient, APIEvent::Severity::EventWarning); + } - EXPECT_EQ(EventCount(), 9000); + EXPECT_EQ(EventCount(), 9000); - DiscardEvents(); + DiscardEvents(); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(EventCount(), 0); } /** * Checks that discarding with a filter only flushes events matching the filter. */ TEST_F(EventManagerTest, DiscardFilter) { - for(int i = 0; i < 3000; i++) { - EventManager::GetInstance().add(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo); - EventManager::GetInstance().add(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventWarning); - EventManager::GetInstance().add(APIEvent::Type::BufferInsufficient, APIEvent::Severity::EventWarning); - } + for(int i = 0; i < 3000; i++) { + EventManager::GetInstance().add(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo); + EventManager::GetInstance().add(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventWarning); + EventManager::GetInstance().add(APIEvent::Type::BufferInsufficient, APIEvent::Severity::EventWarning); + } - EXPECT_EQ(EventCount(), 9000); + EXPECT_EQ(EventCount(), 9000); - DiscardEvents(EventFilter(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo)); + DiscardEvents(EventFilter(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 6000); + EXPECT_EQ(EventCount(), 6000); - DiscardEvents(EventFilter(APIEvent::Type::BufferInsufficient, APIEvent::Severity::EventInfo)); + DiscardEvents(EventFilter(APIEvent::Type::BufferInsufficient, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 6000); + EXPECT_EQ(EventCount(), 6000); - DiscardEvents(EventFilter(APIEvent::Severity::EventWarning)); + DiscardEvents(EventFilter(APIEvent::Severity::EventWarning)); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(EventCount(), 0); } /** * Checks setting the event limit when truncating is not required, when the new limit is < 10, and when the new limit < num events. */ TEST_F(EventManagerTest, SetEventLimitTest) { - // Test if event limit too low to be set - EventManager::GetInstance().setEventLimit(9); - EXPECT_EQ(GetEventLimit(), 10000); - EXPECT_EQ(GetLastError().getType(), APIEvent::Type::ParameterOutOfRange); + // Test if event limit too low to be set + EventManager::GetInstance().setEventLimit(9); + EXPECT_EQ(GetEventLimit(), 10000); + EXPECT_EQ(GetLastError().getType(), APIEvent::Type::ParameterOutOfRange); - // Test truncating existing list when new limit set - for(int i = 0; i < 9001; i++) - EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); + // Test truncating existing list when new limit set + for(int i = 0; i < 9001; i++) + EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); - EXPECT_EQ(EventCount(), 9001); + EXPECT_EQ(EventCount(), 9001); - // Sets new limit to be exactly full. - SetEventLimit(9002); - EXPECT_EQ(GetEventLimit(), 9002); - EXPECT_EQ(EventCount(), 9001); + // Sets new limit to be exactly full. + SetEventLimit(9002); + EXPECT_EQ(GetEventLimit(), 9002); + EXPECT_EQ(EventCount(), 9001); - // 1 overflowed. - SetEventLimit(9001); - EXPECT_EQ(GetEventLimit(), 9001); - EXPECT_EQ(EventCount(), 9001); + // 1 overflowed. + SetEventLimit(9001); + EXPECT_EQ(GetEventLimit(), 9001); + EXPECT_EQ(EventCount(), 9001); - // Truncate a lot - SetEventLimit(5000); - EXPECT_EQ(GetEventLimit(), 5000); - EXPECT_EQ(EventCount(), 5000); + // Truncate a lot + SetEventLimit(5000); + EXPECT_EQ(GetEventLimit(), 5000); + EXPECT_EQ(EventCount(), 5000); - auto events = GetEvents(); - for(int i = 0; i < 4998; i++) { - EXPECT_EQ(events.at(i).getType(), APIEvent::Type::OutputTruncated); - } - EXPECT_EQ(events.at(4999).getType(), APIEvent::Type::TooManyEvents); + auto events = GetEvents(); + for(int i = 0; i < 4998; i++) { + EXPECT_EQ(events.at(i).getType(), APIEvent::Type::OutputTruncated); + } + EXPECT_EQ(events.at(4999).getType(), APIEvent::Type::TooManyEvents); } \ No newline at end of file diff --git a/test/main.cpp b/test/main.cpp index 8401258..a99181d 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,6 +1,6 @@ #include "gtest/gtest.h" int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } \ No newline at end of file From b019c20ad000d4f8bc1e3d600359939f51153a74 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 21 Feb 2022 20:53:42 -0500 Subject: [PATCH 14/26] Legacy: Prevent incorrect access to NetID maps --- api/icsneolegacy/icsneolegacy.cpp | 75 +++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index 3d96e78..1c71622 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -27,8 +27,28 @@ using namespace icsneo; typedef uint64_t legacymaphandle_t; static std::map neodevices; -static std::map mp_netIDToVnetOffSet = {{NETID_HSCAN, 1}, {NETID_MSCAN, 2}, {NETID_HSCAN2, 18}, {NETID_HSCAN3, 19}, {NETID_HSCAN4, 32}, {NETID_HSCAN5, 33}, {NETID_HSCAN6, 47}, {NETID_HSCAN7, 48}}; -static std::map mp_HWnetIDToCMnetID = {{NETID_HSCAN, 0}, {NETID_MSCAN, 1}, {NETID_HSCAN2, 5}, {NETID_HSCAN3, 8}, {NETID_HSCAN4, 14}, {NETID_HSCAN5, 15}, {NETID_HSCAN6, 32}, {NETID_HSCAN7, 33}}; +static const std::map mp_netIDToVnetOffSet = { + {NETID_HSCAN, 1}, + {NETID_MSCAN, 2}, + {NETID_HSCAN2, 18}, + {NETID_HSCAN3, 19}, + {NETID_HSCAN4, 32}, + {NETID_HSCAN5, 33}, + {NETID_HSCAN6, 47}, + {NETID_HSCAN7, 48}, +}; + +static const std::map mp_HWnetIDToCMnetID = { + {NETID_HSCAN, 0}, + {NETID_MSCAN, 1}, + {NETID_HSCAN2, 5}, + {NETID_HSCAN3, 8}, + {NETID_HSCAN4, 14}, + {NETID_HSCAN5, 15}, + {NETID_HSCAN6, 32}, + {NETID_HSCAN7, 33}, +}; + static unsigned long vnet_table[] = {0, PLASMA_SLAVE1_OFFSET, PLASMA_SLAVE2_OFFSET}; static NeoDevice OldNeoDeviceFromNew(const neodevice_t *newnd) @@ -119,10 +139,14 @@ static inline bool IdIsSlaveBRange2(unsigned int fullNetid) static inline unsigned int GetVnetNetid(size_t simpleNetId, EPlasmaIonVnetChannel_t vnetSlot) { - if (vnetSlot == 0 || vnetSlot > 3) + if (vnetSlot == 0 || vnetSlot >= sizeof(vnet_table)/sizeof(vnet_table[0])) return simpleNetId; - return mp_netIDToVnetOffSet[simpleNetId] + vnet_table[vnetSlot]; + const auto offset = mp_netIDToVnetOffSet.find(simpleNetId); + if (offset == mp_netIDToVnetOffSet.end()) + return simpleNetId; + + return offset->second + vnet_table[vnetSlot]; } /** @@ -1107,10 +1131,25 @@ int LegacyDLLExport icsneoJ2534Cmd(void *hObject, unsigned char *CmdBuf, short L case NEODEVICE_ION: //FIRE2 VNETS SFire2Settings Cs; iNumBytes = sizeof(Cs); - if (!!icsneoGetFire2Settings(hObject, &Cs, iNumBytes)) - (Cs.termination_enables & (1ull << mp_HWnetIDToCMnetID[GetVnetAgnosticNetid(NetworkID)])) ? *pTmp = 3 /*Termination ON*/ : *pTmp = 0 /*Termination OFF*/; + if (icsneoGetFire2Settings(hObject, &Cs, iNumBytes)) + { + const auto cmId = mp_HWnetIDToCMnetID.find(GetVnetAgnosticNetid(NetworkID)); + if (cmId != mp_HWnetIDToCMnetID.end()) + { + if (Cs.termination_enables & (1ull << cmId->second)) + *pTmp = 3; // Termination ON + else + *pTmp = 0; // Termination OFF + } + else + { + iRetVal = 0; + } + } else + { iRetVal = 0; + } break; } break; @@ -1130,14 +1169,24 @@ int LegacyDLLExport icsneoJ2534Cmd(void *hObject, unsigned char *CmdBuf, short L iNumBytes = sizeof(Cs); if (icsneoGetFire2Settings(hObject, &Cs, iNumBytes)) { - unsigned long long CoremininetID = mp_HWnetIDToCMnetID[GetVnetAgnosticNetid(NetworkID)]; - - if (*pTmp == 3) /*Termination ON*/ - Cs.termination_enables |= (1ull << CoremininetID); - else /*Termination OFF*/ - Cs.termination_enables &= ~(1ull << CoremininetID); + const auto cmId = mp_HWnetIDToCMnetID.find(GetVnetAgnosticNetid(NetworkID)); + if (cmId != mp_HWnetIDToCMnetID.end()) + { + if (*pTmp == 3) /*Termination ON*/ + Cs.termination_enables |= (1ull << cmId->second); + else /*Termination OFF*/ + Cs.termination_enables &= ~(1ull << cmId->second); - iRetVal = icsneoSetFire2Settings(hObject, &Cs, iNumBytes, 1 /* ConfigurationOptionDoNotSaveToEEPROM */); + iRetVal = icsneoSetFire2Settings(hObject, &Cs, iNumBytes, 1 /* ConfigurationOptionDoNotSaveToEEPROM */); + } + else + { + iRetVal = 0; + } + } + else + { + iRetVal = 0; } break; } From e22f70a35a2bd690e2262810195a4bafef63c9fe Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 21 Feb 2022 20:56:27 -0500 Subject: [PATCH 15/26] Legacy: Correct Ethernet message translation * Fixes NetIDs over 255 * Fixes data lengths over 255 * Avoids writing unexpected messages to client --- api/icsneolegacy/icsneolegacy.cpp | 42 ++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index 1c71622..65bf017 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -63,33 +63,40 @@ static NeoDevice OldNeoDeviceFromNew(const neodevice_t *newnd) return oldnd; } -static void NeoMessageToSpyMessage(const neodevice_t *device, const neomessage_t &newmsg, icsSpyMessage &oldmsg) +static bool NeoMessageToSpyMessage(const neodevice_t* device, const neomessage_t& newmsg, icsSpyMessage& oldmsg) { memset(&oldmsg, 0, sizeof(icsSpyMessage)); - oldmsg.NumberBytesData = (uint8_t)std::min(newmsg.length, (size_t)255); - oldmsg.NumberBytesHeader = 4; - oldmsg.ExtraDataPtr = (void*)newmsg.data; - oldmsg.ExtraDataPtrEnabled = newmsg.length > 8 ? 1 : 0; - memcpy(oldmsg.Data, newmsg.data, std::min(newmsg.length, (size_t)8)); - oldmsg.ArbIDOrHeader = *(uint32_t *)newmsg.header; - oldmsg.NetworkID = (uint8_t)newmsg.netid; // Note: NetID remapping from the original API is not supported - oldmsg.DescriptionID = newmsg.description; - oldmsg.StatusBitField = newmsg.status.statusBitfield[0]; - oldmsg.StatusBitField2 = newmsg.status.statusBitfield[1]; - oldmsg.StatusBitField3 = newmsg.status.statusBitfield[2]; - oldmsg.StatusBitField4 = newmsg.status.statusBitfield[3]; + switch (Network::Type(newmsg.type)) { case Network::Type::CAN: case Network::Type::SWCAN: case Network::Type::LSFTCAN: oldmsg.Protocol = newmsg.status.canfdFDF ? SPY_PROTOCOL_CANFD : SPY_PROTOCOL_CAN; + oldmsg.NumberBytesData = static_cast(std::min(newmsg.length, (size_t)255)); + oldmsg.NumberBytesHeader = 4; break; case Network::Type::Ethernet: oldmsg.Protocol = SPY_PROTOCOL_ETHERNET; + oldmsg.NumberBytesData = static_cast(newmsg.length & 0xFF); + oldmsg.NumberBytesHeader = static_cast(newmsg.length >> 8); break; + default: + return false; } + oldmsg.ExtraDataPtr = (void*)newmsg.data; + oldmsg.ExtraDataPtrEnabled = newmsg.length > 8 ? 1 : 0; + memcpy(oldmsg.Data, newmsg.data, std::min(newmsg.length, (size_t)8)); + oldmsg.ArbIDOrHeader = *reinterpret_cast(newmsg.header); + oldmsg.NetworkID = static_cast(newmsg.netid); // Note: NetID remapping from the original API is not supported + oldmsg.NetworkID2 = static_cast(newmsg.netid >> 8); + oldmsg.DescriptionID = newmsg.description; + oldmsg.StatusBitField = newmsg.status.statusBitfield[0]; + oldmsg.StatusBitField2 = newmsg.status.statusBitfield[1]; + oldmsg.StatusBitField3 = newmsg.status.statusBitfield[2]; + oldmsg.StatusBitField4 = newmsg.status.statusBitfield[3]; + // Timestamp - epoch = 1/1/2007 - 25ns per tick most of the time uint64_t t = newmsg.timestamp; uint16_t res = 0; @@ -110,6 +117,8 @@ static void NeoMessageToSpyMessage(const neodevice_t *device, const neomessage_t oldmsg.TimeStampHardwareID = HARDWARE_TIMESTAMP_ID_NONE; } } + + return true; } static inline bool Within(size_t value, size_t min, size_t max) @@ -356,11 +365,14 @@ int LegacyDLLExport icsneoGetMessages(void *hObject, icsSpyMessage *pMsg, int *p if (!icsneo_getMessages(device, messages, &messageCount, 0)) return false; - *pNumberOfMessages = (int)messageCount; + *pNumberOfMessages = 0; *pNumberOfErrors = 0; for (size_t i = 0; i < messageCount; i++) - NeoMessageToSpyMessage(device, messages[i], pMsg[i]); + { + if (NeoMessageToSpyMessage(device, messages[i], pMsg[*pNumberOfMessages])) + (*pNumberOfMessages)++; + } return true; } From 0219eccc94169d71bac690aac504a3be1fb65d54 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 21 Feb 2022 20:56:49 -0500 Subject: [PATCH 16/26] Legacy: Formatting --- api/icsneolegacy/icsneolegacy.cpp | 300 +++++++++++++++--------------- 1 file changed, 155 insertions(+), 145 deletions(-) diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index 65bf017..6599f30 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -51,14 +51,15 @@ static const std::map mp_HWnetIDToCMnetID = { static unsigned long vnet_table[] = {0, PLASMA_SLAVE1_OFFSET, PLASMA_SLAVE2_OFFSET}; -static NeoDevice OldNeoDeviceFromNew(const neodevice_t *newnd) +static NeoDevice OldNeoDeviceFromNew(const neodevice_t* newnd) { NeoDevice oldnd = {0}; oldnd.DeviceType = newnd->type; oldnd.SerialNumber = icsneo_serialStringToNum(newnd->serial); oldnd.NumberOfClients = 0; oldnd.MaxAllowedClients = 1; - static_assert(sizeof(neodevice_handle_t) == sizeof(oldnd.Handle), "neodevice_handle_t size must be sizeof(int) for compatibility reasons"); + static_assert(sizeof(neodevice_handle_t) == sizeof(oldnd.Handle), + "neodevice_handle_t size must be sizeof(int) for compatibility reasons"); oldnd.Handle = newnd->handle; return oldnd; } @@ -197,7 +198,8 @@ static inline unsigned int GetVnetAgnosticNetid(size_t fullNetid) } //Basic Functions -int LegacyDLLExport icsneoFindDevices(NeoDeviceEx *devs, int *devCount, unsigned int *devTypes, unsigned int devTypeCount, POptionsFindNeoEx *POptionsFindNeoEx, unsigned int *zero) +int LegacyDLLExport icsneoFindDevices(NeoDeviceEx* devs, int* devCount, unsigned int* devTypes, unsigned int devTypeCount, + POptionsFindNeoEx* POptionsFindNeoEx, unsigned int* zero) { if (!devs || !devCount) return 0; @@ -246,7 +248,7 @@ int LegacyDLLExport icsneoFindDevices(NeoDeviceEx *devs, int *devCount, unsigned return 1; // If the function succeeds but no devices are found 1 will still be returned and devCount will equal 0 } -int LegacyDLLExport icsneoFindNeoDevices(unsigned long DeviceTypes, NeoDevice *pNeoDevice, int *pNumDevices) +int LegacyDLLExport icsneoFindNeoDevices(unsigned long DeviceTypes, NeoDevice* pNeoDevice, int* pNumDevices) { constexpr size_t MAX_DEVICES = 255; size_t count = MAX_DEVICES; @@ -280,7 +282,7 @@ int LegacyDLLExport icsneoFindNeoDevices(unsigned long DeviceTypes, NeoDevice *p return 1; } -int LegacyDLLExport icsneoOpenNeoDevice(NeoDevice *pNeoDevice, void **hObject, unsigned char *bNetworkIDs, int bConfigRead, int bSyncToPC) +int LegacyDLLExport icsneoOpenNeoDevice(NeoDevice* pNeoDevice, void** hObject, unsigned char* bNetworkIDs, int bConfigRead, int bSyncToPC) { if (pNeoDevice == nullptr || hObject == nullptr) return false; @@ -331,35 +333,35 @@ int LegacyDLLExport icsneoOpenDevice( return icsneo_setPollingMessageLimit(device, 20000) && icsneo_enableMessagePolling(device) && icsneo_goOnline(device); } -int LegacyDLLExport icsneoClosePort(void *hObject, int *pNumberOfErrors) +int LegacyDLLExport icsneoClosePort(void* hObject, int* pNumberOfErrors) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); return icsneo_closeDevice(device); } // Memory is now managed automatically, this function is unneeded -void LegacyDLLExport icsneoFreeObject(void *hObject) +void LegacyDLLExport icsneoFreeObject(void* hObject) { (void)hObject; return; } -int LegacyDLLExport icsneoSerialNumberToString(unsigned long serial, char *data, unsigned long data_size) +int LegacyDLLExport icsneoSerialNumberToString(unsigned long serial, char* data, unsigned long data_size) { size_t length = (size_t)data_size; return icsneo_serialNumToString((uint32_t)serial, data, &length); } //Message Functions -int LegacyDLLExport icsneoGetMessages(void *hObject, icsSpyMessage *pMsg, int *pNumberOfMessages, int *pNumberOfErrors) +int LegacyDLLExport icsneoGetMessages(void* hObject, icsSpyMessage* pMsg, int* pNumberOfMessages, int* pNumberOfErrors) { static neomessage_t messages[20000]; if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); size_t messageCount = 20000; if (!icsneo_getMessages(device, messages, &messageCount, 0)) @@ -377,16 +379,17 @@ int LegacyDLLExport icsneoGetMessages(void *hObject, icsSpyMessage *pMsg, int *p return true; } -int LegacyDLLExport icsneoTxMessages(void *hObject, icsSpyMessage *pMsg, int lNetworkID, int lNumMessages) +int LegacyDLLExport icsneoTxMessages(void* hObject, icsSpyMessage* pMsg, int lNetworkID, int lNumMessages) { return icsneoTxMessagesEx(hObject, pMsg, lNetworkID, lNumMessages, nullptr, 0); } -int LegacyDLLExport icsneoTxMessagesEx(void *hObject, icsSpyMessage *pMsg, unsigned int lNetworkID, unsigned int lNumMessages, unsigned int *NumTxed, unsigned int zero2) +int LegacyDLLExport icsneoTxMessagesEx(void* hObject, icsSpyMessage* pMsg, unsigned int lNetworkID, unsigned int lNumMessages, + unsigned int* NumTxed, unsigned int zero2) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); neomessage_t newmsg; unsigned int temp = 0; if (NumTxed == nullptr) @@ -394,7 +397,7 @@ int LegacyDLLExport icsneoTxMessagesEx(void *hObject, icsSpyMessage *pMsg, unsig *NumTxed = 0; for (unsigned int i = 0; i < lNumMessages; i++) { - const icsSpyMessage &oldmsg = pMsg[i]; + const icsSpyMessage& oldmsg = pMsg[i]; newmsg = {}; newmsg.netid = (uint16_t)lNetworkID; newmsg.description = oldmsg.DescriptionID; @@ -413,13 +416,13 @@ int LegacyDLLExport icsneoTxMessagesEx(void *hObject, icsSpyMessage *pMsg, unsig newmsg.status.statusBitfield[3] = oldmsg.StatusBitField4; if (oldmsg.Protocol == SPY_PROTOCOL_CANFD) newmsg.status.canfdFDF = true; - if (icsneo_transmit(device, &newmsg)) + if (icsneo_transmit(device, reinterpret_cast(&newmsg))) (*NumTxed)++; } return lNumMessages == *NumTxed; } -int LegacyDLLExport icsneoEnableNetworkRXQueue(void *hObject, int iEnable) +int LegacyDLLExport icsneoEnableNetworkRXQueue(void* hObject, int iEnable) { // TODO Implement return false; @@ -428,7 +431,7 @@ int LegacyDLLExport icsneoEnableNetworkRXQueue(void *hObject, int iEnable) int LegacyDLLExport icsneoGetTimeStampForMsg(void* hObject, icsSpyMessage* pMsg, double* pTimeStamp) { if(!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); uint16_t resolution = 0; if (!icsneo_getTimestampResolution(device, &resolution)) @@ -448,240 +451,245 @@ int LegacyDLLExport icsneoGetTimeStampForMsg(void* hObject, icsSpyMessage* pMsg, return true; } -void LegacyDLLExport icsneoGetISO15765Status(void *hObject, int lNetwork, int lClearTxStatus, int lClearRxStatus, int *lTxStatus, int *lRxStatus) +void LegacyDLLExport icsneoGetISO15765Status(void* hObject, int lNetwork, int lClearTxStatus, int lClearRxStatus, + int* lTxStatus, int* lRxStatus) { // TODO Implement return; } -void LegacyDLLExport icsneoSetISO15765RxParameters(void *hObject, int lNetwork, int lEnable, spyFilterLong *pFF_CFMsgFilter, icsSpyMessage *pTxMsg, - int lCFTimeOutMs, int lFlowCBlockSize, int lUsesExtendedAddressing, int lUseHardwareIfPresent) +void LegacyDLLExport icsneoSetISO15765RxParameters(void* hObject, int lNetwork, int lEnable, spyFilterLong* pFF_CFMsgFilter, + icsSpyMessage* pTxMsg, int lCFTimeOutMs, int lFlowCBlockSize, int lUsesExtendedAddressing, int lUseHardwareIfPresent) { // TODO Implement return; } //Device Functions -int LegacyDLLExport icsneoGetConfiguration(void *hObject, unsigned char *pData, int *lNumBytes) +int LegacyDLLExport icsneoGetConfiguration(void* hObject, unsigned char* pData, int* lNumBytes) { // 2G devices are not supported in the new API return false; } -int LegacyDLLExport icsneoSendConfiguration(void *hObject, unsigned char *pData, int lNumBytes) +int LegacyDLLExport icsneoSendConfiguration(void* hObject, unsigned char* pData, int lNumBytes) { // 2G devices are not supported in the new API return false; } -int LegacyDLLExport icsneoGetFireSettings(void *hObject, SFireSettings *pSettings, int iNumBytes) +int LegacyDLLExport icsneoGetFireSettings(void* hObject, SFireSettings* pSettings, int iNumBytes) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); return !!(icsneo_settingsReadStructure(device, pSettings, iNumBytes) + 1); } -int LegacyDLLExport icsneoSetFireSettings(void *hObject, SFireSettings *pSettings, int iNumBytes, int bSaveToEEPROM) +int LegacyDLLExport icsneoSetFireSettings(void* hObject, SFireSettings* pSettings, int iNumBytes, int bSaveToEEPROM) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (bSaveToEEPROM) return icsneo_settingsApplyStructure(device, pSettings, iNumBytes); return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes); } -int LegacyDLLExport icsneoGetVCAN3Settings(void *hObject, SVCAN3Settings *pSettings, int iNumBytes) +int LegacyDLLExport icsneoGetVCAN3Settings(void* hObject, SVCAN3Settings* pSettings, int iNumBytes) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); return !!(icsneo_settingsReadStructure(device, pSettings, iNumBytes) + 1); } -int LegacyDLLExport icsneoSetVCAN3Settings(void *hObject, SVCAN3Settings *pSettings, int iNumBytes, int bSaveToEEPROM) +int LegacyDLLExport icsneoSetVCAN3Settings(void* hObject, SVCAN3Settings* pSettings, int iNumBytes, int bSaveToEEPROM) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (bSaveToEEPROM) return icsneo_settingsApplyStructure(device, pSettings, iNumBytes); return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes); } -int LegacyDLLExport icsneoGetFire2Settings(void *hObject, SFire2Settings *pSettings, int iNumBytes) +int LegacyDLLExport icsneoGetFire2Settings(void* hObject, SFire2Settings* pSettings, int iNumBytes) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); return !!(icsneo_settingsReadStructure(device, pSettings, iNumBytes) + 1); } -int LegacyDLLExport icsneoSetFire2Settings(void *hObject, SFire2Settings *pSettings, int iNumBytes, int bSaveToEEPROM) +int LegacyDLLExport icsneoSetFire2Settings(void* hObject, SFire2Settings* pSettings, int iNumBytes, int bSaveToEEPROM) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (bSaveToEEPROM) return icsneo_settingsApplyStructure(device, pSettings, iNumBytes); return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes); } -int LegacyDLLExport icsneoGetVCANRFSettings(void *hObject, SVCANRFSettings *pSettings, int iNumBytes) +int LegacyDLLExport icsneoGetVCANRFSettings(void* hObject, SVCANRFSettings* pSettings, int iNumBytes) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); return !!(icsneo_settingsReadStructure(device, pSettings, iNumBytes) + 1); } -int LegacyDLLExport icsneoSetVCANRFSettings(void *hObject, SVCANRFSettings *pSettings, int iNumBytes, int bSaveToEEPROM) +int LegacyDLLExport icsneoSetVCANRFSettings(void* hObject, SVCANRFSettings* pSettings, int iNumBytes, int bSaveToEEPROM) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (bSaveToEEPROM) return icsneo_settingsApplyStructure(device, pSettings, iNumBytes); return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes); } -int LegacyDLLExport icsneoGetVCAN412Settings(void *hObject, SVCAN412Settings *pSettings, int iNumBytes) +int LegacyDLLExport icsneoGetVCAN412Settings(void* hObject, SVCAN412Settings* pSettings, int iNumBytes) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); return !!(icsneo_settingsReadStructure(device, pSettings, iNumBytes) + 1); } -int LegacyDLLExport icsneoSetVCAN412Settings(void *hObject, SVCAN412Settings *pSettings, int iNumBytes, int bSaveToEEPROM) +int LegacyDLLExport icsneoSetVCAN412Settings(void* hObject, SVCAN412Settings* pSettings, int iNumBytes, int bSaveToEEPROM) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (bSaveToEEPROM) return icsneo_settingsApplyStructure(device, pSettings, iNumBytes); return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes); } -int LegacyDLLExport icsneoGetRADGalaxySettings(void *hObject, SRADGalaxySettings *pSettings, int iNumBytes) +int LegacyDLLExport icsneoGetRADGalaxySettings(void* hObject, SRADGalaxySettings* pSettings, int iNumBytes) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); return !!(icsneo_settingsReadStructure(device, pSettings, iNumBytes) + 1); } -int LegacyDLLExport icsneoSetRADGalaxySettings(void *hObject, SRADGalaxySettings *pSettings, int iNumBytes, int bSaveToEEPROM) +int LegacyDLLExport icsneoSetRADGalaxySettings(void* hObject, SRADGalaxySettings* pSettings, int iNumBytes, int bSaveToEEPROM) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (bSaveToEEPROM) return icsneo_settingsApplyStructure(device, pSettings, iNumBytes); return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes); } -int LegacyDLLExport icsneoGetRADStar2Settings(void *hObject, SRADStar2Settings *pSettings, int iNumBytes) +int LegacyDLLExport icsneoGetRADStar2Settings(void* hObject, SRADStar2Settings* pSettings, int iNumBytes) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); return !!(icsneo_settingsReadStructure(device, pSettings, iNumBytes) + 1); } -int LegacyDLLExport icsneoSetRADStar2Settings(void *hObject, SRADStar2Settings *pSettings, int iNumBytes, int bSaveToEEPROM) +int LegacyDLLExport icsneoSetRADStar2Settings(void* hObject, SRADStar2Settings* pSettings, int iNumBytes, int bSaveToEEPROM) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (bSaveToEEPROM) return icsneo_settingsApplyStructure(device, pSettings, iNumBytes); return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes); } -int LegacyDLLExport icsneoSetBitRate(void *hObject, int BitRate, int NetworkID) +int LegacyDLLExport icsneoSetBitRate(void* hObject, int BitRate, int NetworkID) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (!icsneo_setBaudrate(device, (uint16_t)NetworkID, BitRate)) return false; return icsneo_settingsApply(device); } -int LegacyDLLExport icsneoSetFDBitRate(void* hObject, int BitRate, int NetworkID) { - if(!icsneoValidateHObject(hObject)) - return false; - neodevice_t* device = (neodevice_t*)hObject; - if(!icsneo_setFDBaudrate(device, (uint16_t)NetworkID, BitRate)) - return false; - return icsneo_settingsApply(device); +int LegacyDLLExport icsneoSetFDBitRate(void* hObject, int BitRate, int NetworkID) +{ + if(!icsneoValidateHObject(hObject)) + return false; + neodevice_t* device = reinterpret_cast(hObject); + if(!icsneo_setFDBaudrate(device, (uint16_t)NetworkID, BitRate)) + return false; + return icsneo_settingsApply(device); } -int LegacyDLLExport icsneoGetDeviceParameters(void* hObject, char* pParameter, char* pValues, short ValuesLength) { - // TODO Implement - return false; -} - -int LegacyDLLExport icsneoSetDeviceParameters(void *hObject, char *pParmValue, int *pErrorIndex, int bSaveToEEPROM) +int LegacyDLLExport icsneoGetDeviceParameters(void* hObject, char* pParameter, char* pValues, short ValuesLength) { // TODO Implement return false; } -//Error Functions -int LegacyDLLExport icsneoGetLastAPIError(void *hObject, unsigned long *pErrorNumber) +int LegacyDLLExport icsneoSetDeviceParameters(void* hObject, char* pParmValue, int* pErrorIndex, int bSaveToEEPROM) { // TODO Implement return false; } -int LegacyDLLExport icsneoGetErrorMessages(void *hObject, int *pErrorMsgs, int *pNumberOfErrors) +// Error Functions +int LegacyDLLExport icsneoGetLastAPIError(void* hObject, unsigned long* pErrorNumber) { // TODO Implement return false; } -int LegacyDLLExport icsneoGetErrorInfo(int lErrorNumber, TCHAR *szErrorDescriptionShort, TCHAR *szErrorDescriptionLong, int *lMaxLengthShort, int *lMaxLengthLong, int *lErrorSeverity, int *lRestartNeeded) +int LegacyDLLExport icsneoGetErrorMessages(void* hObject, int* pErrorMsgs, int* pNumberOfErrors) +{ + // TODO Implement + return false; +} + +int LegacyDLLExport icsneoGetErrorInfo(int lErrorNumber, TCHAR* szErrorDescriptionShort, TCHAR* szErrorDescriptionLong, + int* lMaxLengthShort, int* lMaxLengthLong, int* lErrorSeverity, int* lRestartNeeded) { // TODO Implement return false; } //ISO15765-2 Functions -int LegacyDLLExport icsneoISO15765_EnableNetworks(void *hObject, unsigned long ulNetworks) +int LegacyDLLExport icsneoISO15765_EnableNetworks(void* hObject, unsigned long ulNetworks) { // TODO Implement return false; } -int LegacyDLLExport icsneoISO15765_DisableNetworks(void *hObject) +int LegacyDLLExport icsneoISO15765_DisableNetworks(void* hObject) { // TODO Implement return false; } -int LegacyDLLExport icsneoISO15765_TransmitMessage(void *hObject, unsigned long ulNetworkID, stCM_ISO157652_TxMessage *pMsg, unsigned long ulBlockingTimeout) +int LegacyDLLExport icsneoISO15765_TransmitMessage(void* hObject, unsigned long ulNetworkID, stCM_ISO157652_TxMessage* pMsg, + unsigned long ulBlockingTimeout) { // TODO Implement return false; } -int LegacyDLLExport icsneoISO15765_ReceiveMessage(void *hObject, int ulNetworkID, stCM_ISO157652_RxMessage *pMsg) +int LegacyDLLExport icsneoISO15765_ReceiveMessage(void* hObject, int ulNetworkID, stCM_ISO157652_RxMessage* pMsg) { // TODO Implement return false; } //General Utility Functions -int LegacyDLLExport icsneoValidateHObject(void *hObject) +int LegacyDLLExport icsneoValidateHObject(void* hObject) { for (auto it = neodevices.begin(); it != neodevices.end(); it++) { if (&it->second == hObject) { - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (icsneo_isValidNeoDevice(device)) return true; } @@ -695,11 +703,11 @@ int LegacyDLLExport icsneoGetDLLVersion(void) return 804; } -int LegacyDLLExport icsneoGetSerialNumber(void *hObject, unsigned int *iSerialNumber) +int LegacyDLLExport icsneoGetSerialNumber(void* hObject, unsigned int* iSerialNumber) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); *iSerialNumber = icsneo_serialStringToNum(device->serial); return true; } @@ -708,7 +716,7 @@ int LegacyDLLExport icsneoEnableDOIPLine(void* hObject, bool enable) { if(!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); return icsneo_setDigitalIO(device, ICSNEO_IO_ETH_ACTIVATION, 1, enable); } @@ -718,91 +726,93 @@ int LegacyDLLExport icsneoStartSockServer(void* hObject, int iPort) return false; } -int LegacyDLLExport icsneoStopSockServer(void *hObject) +int LegacyDLLExport icsneoStopSockServer(void* hObject) { // TODO Implement return false; } //CoreMini Script functions -int LegacyDLLExport icsneoScriptStart(void *hObject, int iLocation) +int LegacyDLLExport icsneoScriptStart(void* hObject, int iLocation) { // TODO Implement return false; } -int LegacyDLLExport icsneoScriptStop(void *hObject) +int LegacyDLLExport icsneoScriptStop(void* hObject) { // TODO Implement return false; } -int LegacyDLLExport icsneoScriptLoad(void *hObject, const unsigned char *bin, unsigned long len_bytes, int iLocation) +int LegacyDLLExport icsneoScriptLoad(void* hObject, const unsigned char* bin, unsigned long len_bytes, int iLocation) { // TODO Implement return false; } -int LegacyDLLExport icsneoScriptClear(void *hObject, int iLocation) +int LegacyDLLExport icsneoScriptClear(void* hObject, int iLocation) { // TODO Implement return false; } -int LegacyDLLExport icsneoScriptStartFBlock(void *hObject, unsigned int fb_index) +int LegacyDLLExport icsneoScriptStartFBlock(void* hObject, unsigned int fb_index) { // TODO Implement return false; } -int LegacyDLLExport icsneoScriptGetFBlockStatus(void *hObject, unsigned int fb_index, int *piRunStatus) +int LegacyDLLExport icsneoScriptGetFBlockStatus(void* hObject, unsigned int fb_index, int* piRunStatus) { // TODO Implement return false; } -int LegacyDLLExport icsneoScriptStopFBlock(void *hObject, unsigned int fb_index) +int LegacyDLLExport icsneoScriptStopFBlock(void* hObject, unsigned int fb_index) { // TODO Implement return false; } -int LegacyDLLExport icsneoScriptGetScriptStatus(void *hObject, int *piStatus) +int LegacyDLLExport icsneoScriptGetScriptStatus(void* hObject, int* piStatus) { // TODO Implement return false; } -int LegacyDLLExport icsneoScriptReadAppSignal(void *hObject, unsigned int iIndex, double *dValue) +int LegacyDLLExport icsneoScriptReadAppSignal(void* hObject, unsigned int iIndex, double* dValue) { // TODO Implement return false; } -int LegacyDLLExport icsneoScriptWriteAppSignal(void *hObject, unsigned int iIndex, double dValue) +int LegacyDLLExport icsneoScriptWriteAppSignal(void* hObject, unsigned int iIndex, double dValue) { // TODO Implement return false; } //Deprecated (but still suppored in the DLL) -int LegacyDLLExport icsneoOpenPortEx(void *lPortNumber, int lPortType, int lDriverType, int lIPAddressMSB, int lIPAddressLSBOrBaudRate, int bConfigRead, unsigned char *bNetworkID, int *hObject) +int LegacyDLLExport icsneoOpenPortEx(void* lPortNumber, int lPortType, int lDriverType, int lIPAddressMSB, + int lIPAddressLSBOrBaudRate, int bConfigRead, unsigned char* bNetworkID, int* hObject) { // TODO Implement return false; } -int LegacyDLLExport icsneoOpenPort(int lPortNumber, int lPortType, int lDriverType, unsigned char *bNetworkID, unsigned char *bSCPIDs, int *hObject) +int LegacyDLLExport icsneoOpenPort(int lPortNumber, int lPortType, int lDriverType, unsigned char *bNetworkID, + unsigned char* bSCPIDs, int* hObject) { // TODO Implement return false; } -int LegacyDLLExport icsneoEnableNetworkCom(void *hObject, int Enable) +int LegacyDLLExport icsneoEnableNetworkCom(void* hObject, int Enable) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (Enable) return icsneo_goOnline(device); @@ -810,42 +820,44 @@ int LegacyDLLExport icsneoEnableNetworkCom(void *hObject, int Enable) return icsneo_goOffline(device); } -int LegacyDLLExport icsneoFindAllCOMDevices(int lDriverType, int lGetSerialNumbers, int lStopAtFirst, int lUSBCommOnly, int *p_lDeviceTypes, int *p_lComPorts, int *p_lSerialNumbers, int *lNumDevices) +int LegacyDLLExport icsneoFindAllCOMDevices(int lDriverType, int lGetSerialNumbers, int lStopAtFirst, int lUSBCommOnly, + int* p_lDeviceTypes, int* p_lComPorts, int* p_lSerialNumbers, int* lNumDevices) { // TODO Implement return false; } -int LegacyDLLExport icsneoOpenNeoDeviceByChannels(NeoDevice *pNeoDevice, void **hObject, unsigned char *uChannels, int iSize, int bConfigRead, int iOptions) +int LegacyDLLExport icsneoOpenNeoDeviceByChannels(NeoDevice* pNeoDevice, void** hObject, unsigned char* uChannels, int iSize, + int bConfigRead, int iOptions) { // TODO Implement return false; } -int LegacyDLLExport icsneoGetVCAN4Settings(void *hObject, SVCAN4Settings *pSettings, int iNumBytes) +int LegacyDLLExport icsneoGetVCAN4Settings(void* hObject, SVCAN4Settings* pSettings, int iNumBytes) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes); } -int LegacyDLLExport icsneoSetVCAN4Settings(void *hObject, SVCAN4Settings *pSettings, int iNumBytes, int bSaveToEEPROM) +int LegacyDLLExport icsneoSetVCAN4Settings(void* hObject, SVCAN4Settings* pSettings, int iNumBytes, int bSaveToEEPROM) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (bSaveToEEPROM) return icsneo_settingsApplyStructure(device, pSettings, iNumBytes); return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes); } -int LegacyDLLExport icsneoGetDeviceSettingsType(void *hObject, EPlasmaIonVnetChannel_t vnetSlot, EDeviceSettingsType *pDeviceSettingsType) +int LegacyDLLExport icsneoGetDeviceSettingsType(void* hObject, EPlasmaIonVnetChannel_t vnetSlot, EDeviceSettingsType* pDeviceSettingsType) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); unsigned long ulDeviceType = device->type; @@ -906,12 +918,13 @@ int LegacyDLLExport icsneoGetDeviceSettingsType(void *hObject, EPlasmaIonVnetCha return 1; } -int LegacyDLLExport icsneoSetDeviceSettings(void* hObject, SDeviceSettings* pSettings, int iNumBytes, int bSaveToEEPROM, EPlasmaIonVnetChannel_t vnetSlot) +int LegacyDLLExport icsneoSetDeviceSettings(void* hObject, SDeviceSettings* pSettings, int iNumBytes, int bSaveToEEPROM, + EPlasmaIonVnetChannel_t vnetSlot) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); const size_t offset = size_t(&pSettings->Settings) - size_t(pSettings); @@ -926,7 +939,7 @@ int LegacyDLLExport icsneoGetDeviceSettings(void* hObject, SDeviceSettings* pSet if (!icsneoValidateHObject(hObject)) return false; - neodevice_t* device = (neodevice_t*)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (icsneoGetDeviceSettingsType(hObject, vnetSlot, &pSettings->DeviceSettingType) == 0) return false; @@ -935,11 +948,11 @@ int LegacyDLLExport icsneoGetDeviceSettings(void* hObject, SDeviceSettings* pSet return !!icsneo_settingsReadStructure(device, &pSettings->Settings, iNumBytes - offset); } -int LegacyDLLExport icsneoSetBitRateEx(void *hObject, unsigned long BitRate, int NetworkID, int iOptions) +int LegacyDLLExport icsneoSetBitRateEx(void* hObject, unsigned long BitRate, int NetworkID, int iOptions) { if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); if (!icsneo_setBaudrate(device, (uint16_t)NetworkID, BitRate)) return false; @@ -951,17 +964,17 @@ int LegacyDLLExport icsneoSetBitRateEx(void *hObject, unsigned long BitRate, int return icsneo_settingsApplyTemporary(device); } -int LegacyDLLExport icsneoEnableNetworkComEx(void *hObject, int iEnable, int iNetId) +int LegacyDLLExport icsneoEnableNetworkComEx(void* hObject, int iEnable, int iNetId) { return icsneoEnableNetworkCom(hObject, iEnable); } -int LegacyDLLExport icsneoForceFirmwareUpdate(void *hObject) +int LegacyDLLExport icsneoForceFirmwareUpdate(void* hObject) { return false; } -int LegacyDLLExport icsneoGetHWFirmwareInfo(void *hObject, stAPIFirmwareInfo *pInfo) +int LegacyDLLExport icsneoGetHWFirmwareInfo(void* hObject, stAPIFirmwareInfo *pInfo) { return false; } @@ -1036,45 +1049,45 @@ int LegacyDLLExport icsneoSetCANParametersPhilipsSJA1000(void* hObject, return false; } -int LegacyDLLExport icsneoEnableBitSmash(void *hObject, - int netId, - unsigned int numWaitBits, - unsigned int numSmashBits, - unsigned int numFrames, - unsigned int timeout_ms, - unsigned int optionBits, - unsigned int numArbIds, - unsigned int arbIds[MAX_BIT_SMASH_ARBIDS]) +int LegacyDLLExport icsneoEnableBitSmash(void* hObject, + int netId, + unsigned int numWaitBits, + unsigned int numSmashBits, + unsigned int numFrames, + unsigned int timeout_ms, + unsigned int optionBits, + unsigned int numArbIds, + unsigned int arbIds[MAX_BIT_SMASH_ARBIDS]) { return false; } -int LegacyDLLExport icsneoDisableBitSmash(void *hObject, unsigned int reservedZero) +int LegacyDLLExport icsneoDisableBitSmash(void* hObject, unsigned int reservedZero) { return false; } -int LegacyDLLExport icsneoSendHWTimeRequest(void *hObject) +int LegacyDLLExport icsneoSendHWTimeRequest(void* hObject) { return false; } -int LegacyDLLExport icsneoReceiveHWTimeResponse(void *hObject, double *TimeHardware, unsigned long TimeOut) +int LegacyDLLExport icsneoReceiveHWTimeResponse(void* hObject, double* TimeHardware, unsigned long TimeOut) { return false; } -int LegacyDLLExport icsneoGetDLLFirmwareInfo(void *hObject, stAPIFirmwareInfo *pInfo) +int LegacyDLLExport icsneoGetDLLFirmwareInfo(void* hObject, stAPIFirmwareInfo* pInfo) { return false; } -int LegacyDLLExport icsneoGetDLLFirmwareInfoEx(void *hObject, stAPIFirmwareInfo *pInfo, EPlasmaIonVnetChannel_t vnetSlot) +int LegacyDLLExport icsneoGetDLLFirmwareInfoEx(void* hObject, stAPIFirmwareInfo* pInfo, EPlasmaIonVnetChannel_t vnetSlot) { return false; } -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; int iRetVal = 0, iNumBytes = 0, NetworkID; @@ -1082,7 +1095,7 @@ int LegacyDLLExport icsneoJ2534Cmd(void *hObject, unsigned char *CmdBuf, short L if (!icsneoValidateHObject(hObject)) return false; - neodevice_t *device = (neodevice_t *)hObject; + neodevice_t* device = reinterpret_cast(hObject); switch (*CmdBuf) { @@ -1210,64 +1223,61 @@ int LegacyDLLExport icsneoJ2534Cmd(void *hObject, unsigned char *CmdBuf, short L return iRetVal; } -int LegacyDLLExport icsneoSendRawCmds(void *hObject, icsneoVICommand *pCmdMsgs, int lNumOfCmds) +int LegacyDLLExport icsneoSendRawCmds(void* hObject, icsneoVICommand* pCmdMsgs, int lNumOfCmds) { return false; } -int LegacyDLLExport icsneoEnableBusVoltageMonitor(void *hObject, unsigned int enable, unsigned int reserved) +int LegacyDLLExport icsneoEnableBusVoltageMonitor(void* hObject, unsigned int enable, unsigned int reserved) { return false; } -int LegacyDLLExport icsneoISO15765_TransmitMessageEx(void *hObject, - unsigned long ulNetworkID, - ISO15765_2015_TxMessage *pMsg, - unsigned long ulBlockingTimeout) +int LegacyDLLExport icsneoISO15765_TransmitMessageEx(void* hObject, + unsigned long ulNetworkID, + ISO15765_2015_TxMessage* pMsg, + unsigned long ulBlockingTimeout) { return false; } -int LegacyDLLExport icsneoGetBusVoltage(void *hObject, unsigned long *pVBusVoltage, unsigned int reserved) +int LegacyDLLExport icsneoGetBusVoltage(void* hObject, unsigned long* pVBusVoltage, unsigned int reserved) { return false; } -int LegacyDLLExport icsneoOpenRemoteNeoDevice(const char *pIPAddress, - NeoDevice *pNeoDevice, - void **hObject, - unsigned char *bNetworkIDs, - int iOptions) +int LegacyDLLExport icsneoOpenRemoteNeoDevice(const char* pIPAddress, NeoDevice* pNeoDevice, void** hObject, + unsigned char* bNetworkIDs, int iOptions) { return false; } -int LegacyDLLExport icsneoFindRemoteNeoDevices(const char *pIPAddress, NeoDevice *pNeoDevice, int *pNumDevices) +int LegacyDLLExport icsneoFindRemoteNeoDevices(const char* pIPAddress, NeoDevice* pNeoDevice, int* pNumDevices) { return false; } -int LegacyDLLExport icsneoFirmwareUpdateRequired(void *hObject) +int LegacyDLLExport icsneoFirmwareUpdateRequired(void* hObject) { return false; } -void LegacyDLLExport icsneoGetDLLVersionEx(unsigned long *dwMSVersion, unsigned long *dwLSVersion) +void LegacyDLLExport icsneoGetDLLVersionEx(unsigned long* dwMSVersion, unsigned long* dwLSVersion) { return; } -int LegacyDLLExport icsneoGetNetidforSlaveVNETs(size_t *NetworkIndex, EPlasmaIonVnetChannel_t vnetSlot) +int LegacyDLLExport icsneoGetNetidforSlaveVNETs(size_t* NetworkIndex, EPlasmaIonVnetChannel_t vnetSlot) { return GetVnetNetid(*NetworkIndex, vnetSlot); } -int LegacyDLLExport icsneoGetVnetSimpleNetid(size_t *FullNetID) +int LegacyDLLExport icsneoGetVnetSimpleNetid(size_t* FullNetID) { return GetVnetAgnosticNetid(*FullNetID); } -int LegacyDLLExport icsneoSerialNumberFromString(unsigned long *serial, char *data) +int LegacyDLLExport icsneoSerialNumberFromString(unsigned long* serial, char* data) { if (serial == nullptr) return false; @@ -1276,7 +1286,7 @@ int LegacyDLLExport icsneoSerialNumberFromString(unsigned long *serial, char *da return false; } -int LegacyDLLExport icsneoGetMiniportAdapterInfo(void *hObject, NETWORK_ADAPTER_INFO *aInfo) +int LegacyDLLExport icsneoGetMiniportAdapterInfo(void* hObject, NETWORK_ADAPTER_INFO* aInfo) { return false; } From c3469f5fb6c7db2da54281eb8ddb463a3d1295ae Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 21 Feb 2022 21:05:01 -0500 Subject: [PATCH 17/26] Legacy: Fix icsneoGetNetidforSlaveVNETs The NetID is written to the out* parameter, not returned. --- api/icsneolegacy/icsneolegacy.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index 6599f30..bb482ec 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -147,16 +147,20 @@ static inline bool IdIsSlaveBRange2(unsigned int fullNetid) return Within(fullNetid, PLASMA_SLAVE2_OFFSET_RANGE2, PLASMA_SLAVE3_OFFSET_RANGE2); } -static inline unsigned int GetVnetNetid(size_t simpleNetId, EPlasmaIonVnetChannel_t vnetSlot) +static inline bool GetVnetNetid(size_t& netId, EPlasmaIonVnetChannel_t vnetSlot) { - if (vnetSlot == 0 || vnetSlot >= sizeof(vnet_table)/sizeof(vnet_table[0])) - return simpleNetId; + if (vnetSlot == 0) + return true; - const auto offset = mp_netIDToVnetOffSet.find(simpleNetId); + if (vnetSlot >= sizeof(vnet_table)/sizeof(vnet_table[0])) + return false; + + const auto offset = mp_netIDToVnetOffSet.find(netId); if (offset == mp_netIDToVnetOffSet.end()) - return simpleNetId; + return false; - return offset->second + vnet_table[vnetSlot]; + netId = offset->second + vnet_table[vnetSlot]; + return true; } /** From 111d377d4a55d7fc8f3632104f25e5e2e59c8df4 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 21 Feb 2022 21:06:14 -0500 Subject: [PATCH 18/26] Legacy: Fix icsneoGetVnetSimpleNetid The NetID is written to the out* parameter, not returned. --- api/icsneolegacy/icsneolegacy.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index bb482ec..cf29e7b 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -178,7 +178,7 @@ static inline unsigned int OffsetToSimpleNetworkId(size_t offset) return NETID_DEVICE; } -static inline unsigned int GetVnetAgnosticNetid(size_t fullNetid) +static inline size_t GetVnetAgnosticNetid(size_t fullNetid) { if (IdIsSlaveARange1(fullNetid)) { @@ -1278,7 +1278,8 @@ int LegacyDLLExport icsneoGetNetidforSlaveVNETs(size_t* NetworkIndex, EPlasmaIon int LegacyDLLExport icsneoGetVnetSimpleNetid(size_t* FullNetID) { - return GetVnetAgnosticNetid(*FullNetID); + *FullNetID = GetVnetAgnosticNetid(*FullNetID); + return true; } int LegacyDLLExport icsneoSerialNumberFromString(unsigned long* serial, char* data) From c620b2ee8b3380ebe81672b1bc8b270155afcb64 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 21 Feb 2022 21:15:12 -0500 Subject: [PATCH 19/26] MSVC: Resolve warnings --- api/icsneolegacy/icsneolegacy.cpp | 23 ++++------- communication/packet/canpacket.cpp | 14 +++---- communication/packet/iso9141packet.cpp | 38 +++++++++---------- .../interactive/src/InteractiveExample.cpp | 4 +- .../device/extensions/builtin.h.template | 3 +- .../device/tree/neovired2/neovired2settings.h | 12 +++++- include/icsneo/icsnVC40.h | 11 ++++++ test/eventmanagertest.cpp | 2 +- 8 files changed, 59 insertions(+), 48 deletions(-) diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index cf29e7b..9e70bce 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -142,7 +142,7 @@ static inline bool IdIsSlaveBRange1(size_t fullNetid) 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); } @@ -168,7 +168,7 @@ static inline bool GetVnetNetid(size_t& netId, EPlasmaIonVnetChannel_t vnetSlot) * the offset from PLASMA_SLAVE1_OFFSET2, return the vnet agnostic * 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) { @@ -181,23 +181,13 @@ static inline unsigned int OffsetToSimpleNetworkId(size_t offset) static inline size_t GetVnetAgnosticNetid(size_t fullNetid) { if (IdIsSlaveARange1(fullNetid)) - { - unsigned int off = fullNetid - PLASMA_SLAVE1_OFFSET; - return OffsetToSimpleNetworkId(off); - } + return OffsetToSimpleNetworkId(fullNetid - PLASMA_SLAVE1_OFFSET); else if (IdIsSlaveARange2(fullNetid)) - { return fullNetid - PLASMA_SLAVE1_OFFSET_RANGE2; - } else if (IdIsSlaveBRange1(fullNetid)) - { - unsigned int off = fullNetid - PLASMA_SLAVE2_OFFSET; - return OffsetToSimpleNetworkId(off); - } + return OffsetToSimpleNetworkId(fullNetid - PLASMA_SLAVE2_OFFSET); else if (IdIsSlaveBRange2(fullNetid)) - { return fullNetid - PLASMA_SLAVE2_OFFSET_RANGE2; - } return fullNetid; } @@ -233,7 +223,7 @@ int LegacyDLLExport icsneoFindDevices(NeoDeviceEx* devs, int* devCount, unsigned if (devTypes && devTypeCount) { - for (auto j = 0; j < devTypeCount; j++) + for (unsigned int j = 0; j < devTypeCount; 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) { uint64_t* pTmp = nullptr; - int iRetVal = 0, iNumBytes = 0, NetworkID; + int iRetVal = 0, iNumBytes = 0; + uint16_t NetworkID = 0; if (!icsneoValidateHObject(hObject)) return false; diff --git a/communication/packet/canpacket.cpp b/communication/packet/canpacket.cpp index 39a878a..c9d6bcd 100644 --- a/communication/packet/canpacket.cpp +++ b/communication/packet/canpacket.cpp @@ -9,19 +9,19 @@ static optional CANFD_DLCToLength(uint8_t length) { switch(length) { case 0x9: - return 12; + return uint8_t(12); case 0xa: - return 16; + return uint8_t(16); case 0xb: - return 20; + return uint8_t(20); case 0xc: - return 24; + return uint8_t(24); case 0xd: - return 32; + return uint8_t(32); case 0xe: - return 48; + return uint8_t(48); case 0xf: - return 64; + return uint8_t(64); } return nullopt; } diff --git a/communication/packet/iso9141packet.cpp b/communication/packet/iso9141packet.cpp index 2904ae9..7a6506d 100644 --- a/communication/packet/iso9141packet.cpp +++ b/communication/packet/iso9141packet.cpp @@ -27,7 +27,7 @@ bool HardwareISO9141Packet::EncodeFromMessage(const ISO9141Message& message, std const uint8_t maxSize = (firstPacket ? 9 : 12); uint8_t currentSize = maxSize; if(bytesToSend - currentStart < maxSize) - currentSize = bytesToSend - currentStart; + currentSize = (uint8_t)(bytesToSend - currentStart); packet.insert(packet.begin(), { (uint8_t)Network::NetID::RED, // 0x0C for long message @@ -75,7 +75,7 @@ bool HardwareISO9141Packet::EncodeFromMessage(const ISO9141Message& message, std } std::shared_ptr HardwareISO9141Packet::Decoder::decodeToMessage(const std::vector& bytestream) { - const HardwareISO9141Packet* data = (const HardwareISO9141Packet*)bytestream.data(); + const HardwareISO9141Packet& packet = *reinterpret_cast(bytestream.data()); if(!mMsg) { mMsg = std::make_shared(); @@ -84,8 +84,8 @@ std::shared_ptr HardwareISO9141Packet::Decoder::decodeToMessage( mGotPackets++; - const bool morePacketsComing = data->c3.frm == 0; - const uint8_t bytesInCurrentMessage = data->c3.len; + const bool morePacketsComing = packet.c3.frm == 0; + const uint8_t bytesInCurrentMessage = packet.c3.len; if(mMsg->data.size() + bytesInCurrentMessage > 500) { mMsg.reset(); return std::shared_ptr(); @@ -93,9 +93,9 @@ std::shared_ptr HardwareISO9141Packet::Decoder::decodeToMessage( // This timestamp is raw off the device (in 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) { // Header if(bytesInCurrentMessage < 3) { @@ -103,31 +103,31 @@ std::shared_ptr HardwareISO9141Packet::Decoder::decodeToMessage( return std::shared_ptr(); } - std::copy(data->data, data->data + 3, mMsg->header.begin()); + std::copy(packet.data, packet.data + 3, mMsg->header.begin()); dataStart += 3; } // 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) - mMsg->data.push_back(data->c1.d8); + mMsg->data.push_back(packet.c1.d8); if(bytesInCurrentMessage > 9) - mMsg->data.push_back(data->c2.d9); + mMsg->data.push_back(packet.c2.d9); if(bytesInCurrentMessage > 10) - mMsg->data.push_back(data->c2.d10); + mMsg->data.push_back(packet.c2.d10); if(bytesInCurrentMessage > 11) - mMsg->data.push_back(data->c3.d11); + mMsg->data.push_back(packet.c3.d11); if(morePacketsComing) return std::shared_ptr(); - mMsg->transmitted = data->c1.tx; - mMsg->isInit = data->c3.init; - mMsg->framingError = data->c1.options & 0x1; - mMsg->overflowError = data->c1.options & 0x2; - mMsg->parityError = data->c1.options & 0x4; - mMsg->rxTimeoutError = data->c1.options & 0x8; - mMsg->description = data->stats; + mMsg->transmitted = packet.c1.tx; + mMsg->isInit = packet.c3.init; + mMsg->framingError = packet.c1.options & 0x1; + mMsg->overflowError = packet.c1.options & 0x2; + mMsg->parityError = packet.c1.options & 0x4; + mMsg->rxTimeoutError = packet.c1.options & 0x8; + mMsg->description = packet.stats; auto ret = mMsg; mMsg.reset(); diff --git a/examples/cpp/interactive/src/InteractiveExample.cpp b/examples/cpp/interactive/src/InteractiveExample.cpp index add2a84..016c670 100644 --- a/examples/cpp/interactive/src/InteractiveExample.cpp +++ b/examples/cpp/interactive/src/InteractiveExample.cpp @@ -636,7 +636,7 @@ int main() { names.push_back("Ethernet (DoIP) Activation Line"); if(ethAct > 1) { names.back() += ' '; - names.back() += i; + names.back() += std::to_string(i); } std::cout << '[' << options.back() << "] " << names.back(); const auto val = selectedDevice->getDigitalIO(icsneo::IO::EthernetActivation, i); @@ -655,7 +655,7 @@ int main() { names.push_back("USB Host Power"); if(usbHost > 1) { names.back() += ' '; - names.back() += i; + names.back() += std::to_string(i); } std::cout << '[' << options.back() << "] " << names.back(); const auto val = selectedDevice->getDigitalIO(icsneo::IO::USBHostPower, i); diff --git a/include/icsneo/device/extensions/builtin.h.template b/include/icsneo/device/extensions/builtin.h.template index 985983a..b752fcd 100644 --- a/include/icsneo/device/extensions/builtin.h.template +++ b/include/icsneo/device/extensions/builtin.h.template @@ -7,7 +7,8 @@ namespace icsneo { -static void AddBuiltInExtensionsTo([[maybe_unused]] const std::shared_ptr& device) { +static void AddBuiltInExtensionsTo(const std::shared_ptr& device) { + (void)device; // [[maybe_unused]] @LIBICSNEO_EXT_CODE@ } diff --git a/include/icsneo/device/tree/neovired2/neovired2settings.h b/include/icsneo/device/tree/neovired2/neovired2settings.h index 416d54d..0bb0213 100644 --- a/include/icsneo/device/tree/neovired2/neovired2settings.h +++ b/include/icsneo/device/tree/neovired2/neovired2settings.h @@ -10,6 +10,11 @@ namespace icsneo { #endif +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4201) // nameless struct/union +#endif + #pragma pack(push, 2) typedef struct { uint16_t perf_en; @@ -57,8 +62,7 @@ typedef struct { ETHERNET_SETTINGS ethernet; TIMESYNC_ICSHARDWARE_SETTINGS timeSync; STextAPISettings text_api; - struct - { + struct { uint32_t disableUsbCheckOnBoot : 1; uint32_t enableLatencyTest : 1; uint32_t busMessagesToAndroid : 1; @@ -87,6 +91,10 @@ typedef struct { } neovired2_status_t; #pragma pack(pop) +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #ifdef __cplusplus #include diff --git a/include/icsneo/icsnVC40.h b/include/icsneo/icsnVC40.h index 97416d6..cf71821 100644 --- a/include/icsneo/icsnVC40.h +++ b/include/icsneo/icsnVC40.h @@ -46,6 +46,11 @@ typedef unsigned __int64 uint64_t; #define IS_64BIT_SYSTEM #endif +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4201) // nameless struct/union +#endif + /* OpenPort "OpenType" Argument Constants -- deprecated, use OpenNeoDevice */ #define NEOVI_COMMTYPE_RS232 0 #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 */ + uint8_t reservedPacking; + uint8_t padding; /* The padding byte to use to fill the unused portion of * transmitted CAN frames (flow control), see paddingEnable. */ @@ -2495,4 +2502,8 @@ CHECK_STRUCT_SIZE(SRADMoon2Settings); #endif /* INTREPID_NO_CHECK_STRUCT_SIZE */ +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif /* _ICSNVC40_H */ diff --git a/test/eventmanagertest.cpp b/test/eventmanagertest.cpp index 0adfb15..6c4bf3d 100644 --- a/test/eventmanagertest.cpp +++ b/test/eventmanagertest.cpp @@ -557,7 +557,7 @@ TEST_F(EventManagerTest, GetSizeFilterTest) { } // (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(EventCount(), 5); From c451fc2b7c5006149e65c5f98d6174ac86f78f8b Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 21 Feb 2022 21:23:58 -0500 Subject: [PATCH 20/26] CI: Warnings are errors --- .gitlab-ci.yml | 2 +- ci/build-windows.bat | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 391effc..4348590 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,7 +17,7 @@ build windows/x64: test windows/x64: stage: test script: - - CMD.EXE /C build\libicsneo-tests.exe + - build\libicsneo-tests.exe dependencies: - build windows/x64 needs: diff --git a/ci/build-windows.bat b/ci/build-windows.bat index 5871e98..1a4e614 100644 --- a/ci/build-windows.bat +++ b/ci/build-windows.bat @@ -6,6 +6,7 @@ mkdir build REM build cd build +set CXXFLAGS=/WX cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBICSNEO_BUILD_TESTS=ON .. if %errorlevel% neq 0 exit /b %errorlevel% cmake --build . From 28d3730375538e53965e4ff6d9f286046fbe702e Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 22 Feb 2022 10:24:13 -0500 Subject: [PATCH 21/26] Windows: Disable unaligned on x86 Closes GH-44 --- include/icsneo/platform/unaligned.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/icsneo/platform/unaligned.h b/include/icsneo/platform/unaligned.h index 34c5663..a2f13c1 100644 --- a/include/icsneo/platform/unaligned.h +++ b/include/icsneo/platform/unaligned.h @@ -1,7 +1,7 @@ #ifndef __UNALIGNED_H_ #define __UNALIGNED_H_ -#if defined(_MSC_VER) +#if defined(_MSC_VER) && !defined(_M_IX86) #define ICSNEO_UNALIGNED(x) __unaligned x #else #define ICSNEO_UNALIGNED(x) x From b177617940f3dd90776f834075c0c7557edb2ea6 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 22 Feb 2022 10:31:46 -0500 Subject: [PATCH 22/26] CI: Add Windows 32-bit --- .gitlab-ci.yml | 26 +++++++++++++++++++++++++- ci/build-windows.bat | 2 -- ci/build-windows32.bat | 2 ++ ci/build-windows64.bat | 2 ++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 ci/build-windows32.bat create mode 100644 ci/build-windows64.bat diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4348590..6674a83 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ stages: build windows/x64: stage: build script: - - CMD.EXE /C ci\build-windows.bat + - CMD.EXE /C ci\build-windows64.bat artifacts: when: always paths: @@ -25,3 +25,27 @@ test windows/x64: tags: - icsneo-windows timeout: 3m + +build windows/x86: + stage: build + script: + - CMD.EXE /C ci\build-windows32.bat + artifacts: + when: always + paths: + - build + expire_in: 3 days + tags: + - icsneo-windows + +test windows/x86: + stage: test + script: + - build\libicsneo-tests.exe + dependencies: + - build windows/x86 + needs: + - build windows/x86 + tags: + - icsneo-windows + timeout: 3m \ No newline at end of file diff --git a/ci/build-windows.bat b/ci/build-windows.bat index 1a4e614..8532140 100644 --- a/ci/build-windows.bat +++ b/ci/build-windows.bat @@ -1,5 +1,3 @@ -call "%VCVARS64%" - REM clean intermediate directories rmdir /s /q build mkdir build diff --git a/ci/build-windows32.bat b/ci/build-windows32.bat new file mode 100644 index 0000000..6ef26b4 --- /dev/null +++ b/ci/build-windows32.bat @@ -0,0 +1,2 @@ +call "%VCVARS32%" +call "ci\build-windows.bat" diff --git a/ci/build-windows64.bat b/ci/build-windows64.bat new file mode 100644 index 0000000..f25aec4 --- /dev/null +++ b/ci/build-windows64.bat @@ -0,0 +1,2 @@ +call "%VCVARS64%" +call "ci\build-windows.bat" From 733312628c0874ba948c69caa124cb0388ccf8b9 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 22 Feb 2022 10:37:37 -0500 Subject: [PATCH 23/26] CI: Also set warnings as errors in C code --- ci/build-windows.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/build-windows.bat b/ci/build-windows.bat index 8532140..5451d07 100644 --- a/ci/build-windows.bat +++ b/ci/build-windows.bat @@ -4,6 +4,7 @@ mkdir build REM build cd build +set CFLAGS=/WX set CXXFLAGS=/WX cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBICSNEO_BUILD_TESTS=ON .. if %errorlevel% neq 0 exit /b %errorlevel% From 95de93aa8474ce33cbcbc00b2314ebdbc671a115 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 22 Feb 2022 10:46:27 -0500 Subject: [PATCH 24/26] Examples: C Interactive: Resolve warnings --- examples/c/interactive/src/main.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/c/interactive/src/main.c b/examples/c/interactive/src/main.c index e1f458c..6b45f23 100644 --- a/examples/c/interactive/src/main.c +++ b/examples/c/interactive/src/main.c @@ -30,13 +30,13 @@ void printAllDevices() { if(numDevices == 0) { printf("No devices found! Please scan for new devices.\n"); } - for(int i = 0; i < numDevices; i++) { + for(size_t i = 0; i < numDevices; i++) { char productDescription[ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION] = { 0 }; size_t descriptionLength = ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION; // Updates productDescription and descriptionLength for each device if(icsneo_describeDevice(devices + i, productDescription, &descriptionLength)) { - printf("[%d] %s\tConnected: ", i + 1, productDescription); + printf("[%zd] %s\tConnected: ", i + 1, productDescription); if(icsneo_isOpen(devices + i)) { printf("Yes\t"); } else printf("No\t"); @@ -52,7 +52,7 @@ void printAllDevices() { } else printf("Off\n"); } else { - printf("Description for device %d not available!\n", i + 1); + printf("Description for device %zd not available!\n", i + 1); } } } @@ -66,7 +66,7 @@ size_t scanNewDevices() { size_t numNewDevices = 99; icsneo_findAllDevices(newDevices, &numNewDevices); - for(int i = 0; i < numNewDevices; ++i) { + for(size_t i = 0; i < numNewDevices; ++i) { devices[numDevices + i] = newDevices[i]; } numDevices += numNewDevices; @@ -112,7 +112,7 @@ void printAPIEvents() { printf("Event 0x%u: %s\n", events[0].eventNumber, events[0].description); } else { printf("%d API events found!\n", (int) eventCount); - for(int i = 0; i < eventCount; ++i) { + for(size_t i = 0; i < eventCount; ++i) { printf("Event 0x%u: %s\n", events[i].eventNumber, events[i].description); } } @@ -134,7 +134,7 @@ void printDeviceEvents(neodevice_t* device) { printf("Event 0x%x: %s\n", events[0].eventNumber, events[0].description); } else { printf("%d device events found!\n", (int) eventCount); - for(int i = 0; i < eventCount; ++i) { + for(size_t i = 0; i < eventCount; ++i) { printf("Event 0x%x: %s\n", events[i].eventNumber, events[i].description); } } @@ -196,10 +196,14 @@ const neodevice_t* selectDevice() { printAllDevices(); printf("\n"); - int selectedDeviceNum = 10; + size_t selectedDeviceNum = 10; while(selectedDeviceNum > numDevices) { char deviceSelection = getCharInput(9, '1', '2', '3', '4', '5', '6', '7', '8', '9'); + if(deviceSelection < '0') { + printf("Selected device out of range!\n"); + continue; + } selectedDeviceNum = deviceSelection - '0'; if(selectedDeviceNum > numDevices) { printf("Selected device out of range!\n"); @@ -301,7 +305,7 @@ int main() { // Shifts everything after the removed device 1 index to the left bool startResizing = false; - for(int i = 0; i < numDevices; ++i) { + for(size_t i = 0; i < numDevices; ++i) { if(selectedDevice == devices + i) startResizing = true; if(startResizing) From 2c282fe396a732b56c4e30b980ec07828c49ec64 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 22 Feb 2022 10:46:30 -0500 Subject: [PATCH 25/26] Tests: Resolve MSVC x86 warnings --- test/ethernetpacketizertest.cpp | 18 ++-- test/eventmanagertest.cpp | 146 ++++++++++++++++---------------- 2 files changed, 82 insertions(+), 82 deletions(-) diff --git a/test/ethernetpacketizertest.cpp b/test/ethernetpacketizertest.cpp index a2b2853..47bc266 100644 --- a/test/ethernetpacketizertest.cpp +++ b/test/ethernetpacketizertest.cpp @@ -35,7 +35,7 @@ TEST_F(EthernetPacketizerTest, DownSmallSinglePacket) { packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); const auto output = packetizer->outputDown(); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), 1u); EXPECT_EQ(output.front(), std::vector({ 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, @@ -53,7 +53,7 @@ TEST_F(EthernetPacketizerTest, DownSmallMultiplePackets) packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); packetizer->inputDown({ 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee }); const auto output = packetizer->outputDown(); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), 1u); EXPECT_EQ(output.front(), std::vector({ 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, @@ -73,7 +73,7 @@ TEST_F(EthernetPacketizerTest, DownSmallMultiplePacketsOverflow) packetizer->inputDown({ 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee }); packetizer->inputDown(std::vector(1480)); // Near the max const auto output = packetizer->outputDown(); - ASSERT_EQ(output.size(), 2); + ASSERT_EQ(output.size(), 2u); EXPECT_EQ(output.front(), std::vector({ 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, @@ -105,7 +105,7 @@ TEST_F(EthernetPacketizerTest, DownOverflowSmallMultiplePackets) packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); packetizer->inputDown({ 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee }); const auto output = packetizer->outputDown(); - ASSERT_EQ(output.size(), 2); + ASSERT_EQ(output.size(), 2u); std::vector bigOutput({ 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, @@ -137,7 +137,7 @@ TEST_F(EthernetPacketizerTest, DownBigSmallSmall) packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); packetizer->inputDown({ 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee }); // Not enough room for this one const auto output = packetizer->outputDown(); - ASSERT_EQ(output.size(), 2); + ASSERT_EQ(output.size(), 2u); std::vector bigOutput({ 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, @@ -169,7 +169,7 @@ TEST_F(EthernetPacketizerTest, DownJumboSmallSmall) packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); packetizer->inputDown({ 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee, 0xc0, 0xff, 0xee }); const auto output = packetizer->outputDown(); - ASSERT_EQ(output.size(), 3); + ASSERT_EQ(output.size(), 3u); std::vector bigOutput({ 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, @@ -211,7 +211,7 @@ TEST_F(EthernetPacketizerTest, PacketNumberIncrement) { packetizer->inputDown({ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); auto output = packetizer->outputDown(); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), 1u); EXPECT_EQ(output.front(), std::vector({ 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, @@ -225,7 +225,7 @@ TEST_F(EthernetPacketizerTest, PacketNumberIncrement) packetizer->inputDown({ 0x12, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); output = packetizer->outputDown(); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), 1u); EXPECT_EQ(output.front(), std::vector({ 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, @@ -239,7 +239,7 @@ TEST_F(EthernetPacketizerTest, PacketNumberIncrement) packetizer->inputDown({ 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }); output = packetizer->outputDown(); - ASSERT_EQ(output.size(), 1); + ASSERT_EQ(output.size(), 1u); EXPECT_EQ(output.front(), std::vector({ 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, diff --git a/test/eventmanagertest.cpp b/test/eventmanagertest.cpp index 6c4bf3d..3f58468 100644 --- a/test/eventmanagertest.cpp +++ b/test/eventmanagertest.cpp @@ -62,13 +62,13 @@ TEST_F(EventManagerTest, MultithreadedEventCallbacksTest) { t1.join(); t2.join(); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(EventCount(), 0u); EXPECT_EQ(callCounter, 2); EventManager::GetInstance().add(APIEvent(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 1); + EXPECT_EQ(EventCount(), 1u); EXPECT_EQ(callCounter, 2); } @@ -293,27 +293,27 @@ TEST_F(EventManagerTest, MultithreadedTest) { EXPECT_EQ(GetLastError().getType(), APIEvent::Type::NoErrorFound); // Should be 500 {OutputTruncated, Warning}, 500 {OutputTruncated, Info}, 1000 {CANFDNotSupported, Warning}, 500 {CANFDSettingsNotAvailable, Info}, 500 {FailedToWrite, Info} - EXPECT_EQ(EventCount(), 3000); + EXPECT_EQ(EventCount(), 3000u); auto events = GetEvents(EventFilter(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); - EXPECT_EQ(EventCount(), 2500); - EXPECT_EQ(events.size(), 500); + EXPECT_EQ(EventCount(), 2500u); + EXPECT_EQ(events.size(), 500u); events = GetEvents(EventFilter(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 2000); - EXPECT_EQ(events.size(), 500); + EXPECT_EQ(EventCount(), 2000u); + EXPECT_EQ(events.size(), 500u); events = GetEvents(EventFilter(APIEvent::Type::CANFDNotSupported, APIEvent::Severity::EventWarning)); - EXPECT_EQ(EventCount(), 1000); - EXPECT_EQ(events.size(), 1000); + EXPECT_EQ(EventCount(), 1000u); + EXPECT_EQ(events.size(), 1000u); events = GetEvents(EventFilter(APIEvent::Type::CANFDSettingsNotAvailable, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 500); - EXPECT_EQ(events.size(), 500); + EXPECT_EQ(EventCount(), 500u); + EXPECT_EQ(events.size(), 500u); events = GetEvents(EventFilter(APIEvent::Type::FailedToWrite, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 0); - EXPECT_EQ(events.size(), 500); + EXPECT_EQ(EventCount(), 0u); + EXPECT_EQ(events.size(), 500u); } /** @@ -323,7 +323,7 @@ TEST_F(EventManagerTest, MultithreadedTest) { TEST_F(EventManagerTest, CountTest) { // Add an error event, should not go into events list. EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::Error)); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(EventCount(), 0u); // Adds actual event EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); @@ -332,25 +332,25 @@ TEST_F(EventManagerTest, CountTest) { EventManager::GetInstance().add(APIEvent(APIEvent::Type::TooManyEvents, APIEvent::Severity::EventWarning)); EventManager::GetInstance().add(APIEvent(APIEvent::Type::TooManyEvents, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 1); + EXPECT_EQ(EventCount(), 1u); // Add another actual event EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 2); + EXPECT_EQ(EventCount(), 2u); // Take all info events (1) GetEvents(EventFilter(APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 1); + EXPECT_EQ(EventCount(), 1u); // Take all events GetEvents(); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(EventCount(), 0u); // default limit is 10000 for(int i = 0; i < 11000; i++) EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); - EXPECT_EQ(EventCount(), 10000); + EXPECT_EQ(EventCount(), 10000u); } /** @@ -367,8 +367,8 @@ TEST_F(EventManagerTest, GetDefaultTest) { auto events = EventManager::GetInstance().get(); - EXPECT_EQ(events.size(), 10); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(events.size(), 10u); + EXPECT_EQ(EventCount(), 0u); for(int i = 0; i < 5; i++) { EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::UnexpectedNetworkType); @@ -380,8 +380,8 @@ TEST_F(EventManagerTest, GetDefaultTest) { // Check getting when 0 events exist doesn't break events = EventManager::GetInstance().get(); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(events.size(), 0u); + EXPECT_EQ(EventCount(), 0u); } /** @@ -401,8 +401,8 @@ TEST_F(EventManagerTest, GetSizeTest) { // Take 3 events, 7 left auto events = EventManager::GetInstance().get(3); - EXPECT_EQ(events.size(), 3); - EXPECT_EQ(EventCount(), 7); + EXPECT_EQ(events.size(), 3u); + EXPECT_EQ(EventCount(), 7u); EXPECT_EQ(events.at(0).getType(), APIEvent::Type::UnexpectedNetworkType); EXPECT_EQ(events.at(0).getSeverity(), APIEvent::Severity::EventWarning); @@ -414,16 +414,16 @@ TEST_F(EventManagerTest, GetSizeTest) { // Take 1 event, 6 left events = EventManager::GetInstance().get(1); - EXPECT_EQ(events.size(), 1); - EXPECT_EQ(EventCount(), 6); + EXPECT_EQ(events.size(), 1u); + EXPECT_EQ(EventCount(), 6u); EXPECT_EQ(events.at(0).getType(), APIEvent::Type::SWCANSettingsNotAvailable); EXPECT_EQ(events.at(0).getSeverity(), APIEvent::Severity::EventInfo); // Try to take 8 events, should actually take the 6 remaining. 0 left. events = EventManager::GetInstance().get(8); - EXPECT_EQ(events.size(), 6); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(events.size(), 6u); + EXPECT_EQ(EventCount(), 0u); for(int i = 0; i < 3; i++) { EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::UnexpectedNetworkType); @@ -435,8 +435,8 @@ TEST_F(EventManagerTest, GetSizeTest) { // Check getting when 0 events exist doesn't break events = EventManager::GetInstance().get(5); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(events.size(), 0u); + EXPECT_EQ(EventCount(), 0u); } /** @@ -458,8 +458,8 @@ TEST_F(EventManagerTest, GetFilterTest) { // Get all 5 {network, warning}. 15 left. auto events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); - EXPECT_EQ(events.size(), 5); - EXPECT_EQ(EventCount(), 15); + EXPECT_EQ(events.size(), 5u); + EXPECT_EQ(EventCount(), 15u); for(APIEvent event : events) { EXPECT_EQ(event.getType(), APIEvent::Type::UnexpectedNetworkType); @@ -469,8 +469,8 @@ TEST_F(EventManagerTest, GetFilterTest) { // Get all 10 infos. 5 {mismatch, warning} remaining. events = EventManager::GetInstance().get(EventFilter(APIEvent::Severity::EventInfo)); - EXPECT_EQ(events.size(), 10); - EXPECT_EQ(EventCount(), 5); + EXPECT_EQ(events.size(), 10u); + EXPECT_EQ(EventCount(), 5u); for(int i = 0; i < 5; i++) { EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::SWCANSettingsNotAvailable); @@ -482,13 +482,13 @@ TEST_F(EventManagerTest, GetFilterTest) { // (Incorrectly) try to get settings type again. 5 {mismatch, warning} remaining. events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::SWCANSettingsNotAvailable)); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 5); + EXPECT_EQ(events.size(), 0u); + EXPECT_EQ(EventCount(), 5u); // Get the 5 {mismatch, warning} remaining. events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::SettingsStructureMismatch)); - EXPECT_EQ(events.size(), 5); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(events.size(), 5u); + EXPECT_EQ(EventCount(), 0u); for(APIEvent event : events) { EXPECT_EQ(event.getType(), APIEvent::Type::SettingsStructureMismatch); @@ -497,8 +497,8 @@ TEST_F(EventManagerTest, GetFilterTest) { // Check getting when 0 events exist doesn't break events = EventManager::GetInstance().get(EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(events.size(), 0u); + EXPECT_EQ(EventCount(), 0u); } /** @@ -520,8 +520,8 @@ TEST_F(EventManagerTest, GetSizeFilterTest) { // Get all 5 {network, warning}. 15 left. auto events = EventManager::GetInstance().get(6, EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); - EXPECT_EQ(events.size(), 5); - EXPECT_EQ(EventCount(), 15); + EXPECT_EQ(events.size(), 5u); + EXPECT_EQ(EventCount(), 15u); for(APIEvent event : events) { EXPECT_EQ(event.getType(), APIEvent::Type::UnexpectedNetworkType); @@ -531,8 +531,8 @@ TEST_F(EventManagerTest, GetSizeFilterTest) { // Get 6 infos. 4 infos and 5 {mismatch, warning} remaining. events = EventManager::GetInstance().get(6, EventFilter(APIEvent::Severity::EventInfo)); - EXPECT_EQ(events.size(), 6); - EXPECT_EQ(EventCount(), 9); + EXPECT_EQ(events.size(), 6u); + EXPECT_EQ(EventCount(), 9u); for(int i = 0; i < 3; i++) { EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::SWCANSettingsNotAvailable); @@ -545,8 +545,8 @@ TEST_F(EventManagerTest, GetSizeFilterTest) { // Get 4 remaining infos. 5 {mismatch, warning} remaining. events = EventManager::GetInstance().get(4, EventFilter(APIEvent::Severity::EventInfo)); - EXPECT_EQ(events.size(), 4); - EXPECT_EQ(EventCount(), 5); + EXPECT_EQ(events.size(), 4u); + EXPECT_EQ(EventCount(), 5u); for(int i = 0; i < 2; i++) { EXPECT_EQ(events.at(2 * i).getType(), APIEvent::Type::SWCANSettingsNotAvailable); @@ -558,13 +558,13 @@ TEST_F(EventManagerTest, GetSizeFilterTest) { // (Incorrectly) try to get settings type again. 5 {mismatch, warning} remaining. events = EventManager::GetInstance().get(APIEvent::Type::SWCANSettingsNotAvailable); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 5); + EXPECT_EQ(events.size(), 0u); + EXPECT_EQ(EventCount(), 5u); // Get the 5 {mismatch, warning} remaining. events = EventManager::GetInstance().get(5, EventFilter(APIEvent::Type::SettingsStructureMismatch)); - EXPECT_EQ(events.size(), 5); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(events.size(), 5u); + EXPECT_EQ(EventCount(), 0u); for(APIEvent event : events) { EXPECT_EQ(event.getType(), APIEvent::Type::SettingsStructureMismatch); @@ -573,8 +573,8 @@ TEST_F(EventManagerTest, GetSizeFilterTest) { // Check getting when 0 events exist doesn't break events = EventManager::GetInstance().get(2, EventFilter(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::EventWarning)); - EXPECT_EQ(events.size(), 0); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(events.size(), 0u); + EXPECT_EQ(EventCount(), 0u); } /** @@ -608,7 +608,7 @@ TEST_F(EventManagerTest, GetLastErrorMultipleTest) { TEST_F(EventManagerTest, TestAddWarningsOverflow) { // space for 49 normal events, 1 reserved for TooManyEvents - SetEventLimit(50); + SetEventLimit(50u); // 3 of these for(int i = 0; i < 3; i++) @@ -642,7 +642,7 @@ TEST_F(EventManagerTest, TestAddWarningsOverflow) { TEST_F(EventManagerTest, TestAddWarningsInfoOverflow) { // space for 49 normal events, 1 reserved for TooManyEvents - SetEventLimit(50); + SetEventLimit(50u); // Event list filling: 1 warning, 3 info, 47 warning. // Expect to see: 2 info, 47 warning, 1 TooManyEvents @@ -679,11 +679,11 @@ TEST_F(EventManagerTest, DiscardDefault) { EventManager::GetInstance().add(APIEvent::Type::BufferInsufficient, APIEvent::Severity::EventWarning); } - EXPECT_EQ(EventCount(), 9000); + EXPECT_EQ(EventCount(), 9000u); DiscardEvents(); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(EventCount(), 0u); } /** @@ -696,19 +696,19 @@ TEST_F(EventManagerTest, DiscardFilter) { EventManager::GetInstance().add(APIEvent::Type::BufferInsufficient, APIEvent::Severity::EventWarning); } - EXPECT_EQ(EventCount(), 9000); + EXPECT_EQ(EventCount(), 9000u); DiscardEvents(EventFilter(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 6000); + EXPECT_EQ(EventCount(), 6000u); DiscardEvents(EventFilter(APIEvent::Type::BufferInsufficient, APIEvent::Severity::EventInfo)); - EXPECT_EQ(EventCount(), 6000); + EXPECT_EQ(EventCount(), 6000u); DiscardEvents(EventFilter(APIEvent::Severity::EventWarning)); - EXPECT_EQ(EventCount(), 0); + EXPECT_EQ(EventCount(), 0u); } /** @@ -716,30 +716,30 @@ TEST_F(EventManagerTest, DiscardFilter) { */ TEST_F(EventManagerTest, SetEventLimitTest) { // Test if event limit too low to be set - EventManager::GetInstance().setEventLimit(9); - EXPECT_EQ(GetEventLimit(), 10000); + EventManager::GetInstance().setEventLimit(9u); + EXPECT_EQ(GetEventLimit(), 10000u); EXPECT_EQ(GetLastError().getType(), APIEvent::Type::ParameterOutOfRange); // Test truncating existing list when new limit set for(int i = 0; i < 9001; i++) EventManager::GetInstance().add(APIEvent(APIEvent::Type::OutputTruncated, APIEvent::Severity::EventWarning)); - EXPECT_EQ(EventCount(), 9001); + EXPECT_EQ(EventCount(), 9001u); // Sets new limit to be exactly full. - SetEventLimit(9002); - EXPECT_EQ(GetEventLimit(), 9002); - EXPECT_EQ(EventCount(), 9001); + SetEventLimit(9002u); + EXPECT_EQ(GetEventLimit(), 9002u); + EXPECT_EQ(EventCount(), 9001u); // 1 overflowed. - SetEventLimit(9001); - EXPECT_EQ(GetEventLimit(), 9001); - EXPECT_EQ(EventCount(), 9001); + SetEventLimit(9001u); + EXPECT_EQ(GetEventLimit(), 9001u); + EXPECT_EQ(EventCount(), 9001u); // Truncate a lot - SetEventLimit(5000); - EXPECT_EQ(GetEventLimit(), 5000); - EXPECT_EQ(EventCount(), 5000); + SetEventLimit(5000u); + EXPECT_EQ(GetEventLimit(), 5000u); + EXPECT_EQ(EventCount(), 5000u); auto events = GetEvents(); for(int i = 0; i < 4998; i++) { From f1d9be1a81d758d9184d3be2d704b6be81e14ac4 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Thu, 24 Feb 2022 16:03:02 -0500 Subject: [PATCH 26/26] Build: Don't add libusb include until after libftdi This fixes GH-46 and a regression caused by 82954d9 where the project would fail to build until configured a second time on Unix-y platforms. LibFTDI adds libusb, so we need to make sure that's included first. Windows does not use libusb so it does not need the include directory. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef3a579..e9fc2fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,7 +205,6 @@ target_include_directories(icsneocpp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${LIBICSNEO_EXTENSION_INCLUDE_PATHS} - ${LIBUSB_INCLUDE_DIR} ) set_property(TARGET icsneocpp PROPERTY POSITION_INDEPENDENT_CODE ON) target_compile_features(icsneocpp PUBLIC cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums) @@ -223,6 +222,7 @@ if(NOT WIN32) set(FTDIPP OFF CACHE INTERNAL "") set(FTDI_EEPROM OFF CACHE INTERNAL "") add_subdirectory(third-party/libftdi) + target_include_directories(icsneocpp PRIVATE ${LIBUSB_INCLUDE_DIR}) endif(NOT WIN32) # winpcap