diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index aed911a..22fcfd8 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -12,7 +12,7 @@ pybind11_add_module(icsneopy icsneopy/communication/network.cpp icsneopy/communication/message/message.cpp icsneopy/communication/message/canmessage.cpp - icsneopy/communication/message/canerrorcountmessage.cpp + icsneopy/communication/message/canerrormessage.cpp icsneopy/communication/message/ethernetmessage.cpp icsneopy/communication/message/linmessage.cpp icsneopy/communication/message/tc10statusmessage.cpp diff --git a/bindings/python/icsneopy/communication/message/canerrorcountmessage.cpp b/bindings/python/icsneopy/communication/message/canerrorcountmessage.cpp deleted file mode 100644 index 5742ca8..0000000 --- a/bindings/python/icsneopy/communication/message/canerrorcountmessage.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include - -#include "icsneo/communication/message/canerrorcountmessage.h" - -namespace icsneo { - -void init_canerrorcountmessage(pybind11::module_& m) { - pybind11::class_, Message>(m, "CANErrorCountMessage") - .def_readonly("network", &CANErrorCountMessage::network) - .def_readonly("transmitErrorCount", &CANErrorCountMessage::transmitErrorCount) - .def_readonly("receiveErrorCount", &CANErrorCountMessage::receiveErrorCount) - .def_readonly("busOff", &CANErrorCountMessage::busOff); -} - -} // namespace icsneo - diff --git a/bindings/python/icsneopy/communication/message/canerrormessage.cpp b/bindings/python/icsneopy/communication/message/canerrormessage.cpp new file mode 100644 index 0000000..329da23 --- /dev/null +++ b/bindings/python/icsneopy/communication/message/canerrormessage.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +#include "icsneo/communication/message/canerrormessage.h" + +namespace icsneo { + +void init_errorcodes(pybind11::module_& m) { + pybind11::enum_(m, "CANErrorCode") + .value("NoError", CANErrorCode::NoError) + .value("StuffError", CANErrorCode::StuffError) + .value("FormError", CANErrorCode::FormError) + .value("AckError", CANErrorCode::AckError) + .value("Bit1Error", CANErrorCode::Bit1Error) + .value("Bit0Error", CANErrorCode::Bit0Error) + .value("CRCError", CANErrorCode::CRCError) + .value("NoChange", CANErrorCode::NoChange); +} + +void init_canerrormessage(pybind11::module_& m) { + init_errorcodes(m); + pybind11::class_, Message>(m, "CANErrorMessage") + .def_readonly("network", &CANErrorMessage::network) + .def_readonly("transmitErrorCount", &CANErrorMessage::transmitErrorCount) + .def_readonly("receiveErrorCount", &CANErrorMessage::receiveErrorCount) + .def_readonly("busOff", &CANErrorMessage::busOff) + .def_readonly("errorPassive", &CANErrorMessage::errorPassive) + .def_readonly("errorWarn", &CANErrorMessage::errorWarn) + .def_readonly("dataErrorCode", &CANErrorMessage::dataErrorCode) + .def_readonly("errorCode", &CANErrorMessage::errorCode); + + + m.attr("CANErrorCountMessage") = m.attr("CANErrorMessage"); +} + +} // namespace icsneo + diff --git a/bindings/python/icsneopy/communication/message/message.cpp b/bindings/python/icsneopy/communication/message/message.cpp index 0fc73cc..5fef94e 100644 --- a/bindings/python/icsneopy/communication/message/message.cpp +++ b/bindings/python/icsneopy/communication/message/message.cpp @@ -11,6 +11,7 @@ void init_message(pybind11::module_& m) { pybind11::enum_(message, "Type") .value("Frame", Message::Type::Frame) .value("CANErrorCount", Message::Type::CANErrorCount) + .value("CANError", Message::Type::CANError) .value("LINHeaderOnly", Message::Type::LINHeaderOnly) .value("LINBreak", Message::Type::LINBreak) .value("Invalid", Message::Type::Invalid) diff --git a/bindings/python/icsneopy/icsneocpp.cpp b/bindings/python/icsneopy/icsneocpp.cpp index 97b0316..bfc72d5 100644 --- a/bindings/python/icsneopy/icsneocpp.cpp +++ b/bindings/python/icsneopy/icsneocpp.cpp @@ -13,7 +13,7 @@ void init_network(pybind11::module_&); void init_devicetype(pybind11::module_&); void init_message(pybind11::module_&); void init_canmessage(pybind11::module_&); -void init_canerrorcountmessage(pybind11::module_&); +void init_canerrormessage(pybind11::module_&); void init_ethernetmessage(pybind11::module_&); void init_linmessage(pybind11::module_&); void init_tc10statusmessage(pybind11::module_&); @@ -38,7 +38,7 @@ PYBIND11_MODULE(icsneopy, m) { init_network(m); init_message(m); init_canmessage(m); - init_canerrorcountmessage(m); + init_canerrormessage(m); init_ethernetmessage(m); init_linmessage(m); init_tc10statusmessage(m); diff --git a/communication/decoder.cpp b/communication/decoder.cpp index c7b1fdb..101777f 100644 --- a/communication/decoder.cpp +++ b/communication/decoder.cpp @@ -3,7 +3,7 @@ #include "icsneo/communication/message/serialnumbermessage.h" #include "icsneo/communication/message/resetstatusmessage.h" #include "icsneo/communication/message/readsettingsmessage.h" -#include "icsneo/communication/message/canerrorcountmessage.h" +#include "icsneo/communication/message/canerrormessage.h" #include "icsneo/communication/message/neoreadmemorysdmessage.h" #include "icsneo/communication/message/flashmemorymessage.h" #include "icsneo/communication/message/extendedresponsemessage.h" @@ -95,7 +95,7 @@ bool Decoder::decode(std::shared_ptr& result, const std::shared_ptr(result.get()); + CANErrorMessage& can = *static_cast(result.get()); can.network = packet->network; break; } diff --git a/communication/message/neomessage.cpp b/communication/message/neomessage.cpp index bbab488..08fdfdd 100644 --- a/communication/message/neomessage.cpp +++ b/communication/message/neomessage.cpp @@ -1,7 +1,7 @@ #include "icsneo/communication/message/neomessage.h" #include "icsneo/communication/message/canmessage.h" #include "icsneo/communication/message/ethernetmessage.h" -#include "icsneo/communication/message/canerrorcountmessage.h" +#include "icsneo/communication/message/canerrormessage.h" #include "icsneo/communication/message/linmessage.h" using namespace icsneo; @@ -104,7 +104,7 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr message) { } case Message::Type::CANErrorCount: { neomessage_can_error_t& canerror = *(neomessage_can_error_t*)&neomsg; - auto canerrormsg = std::static_pointer_cast(message); + auto canerrormsg = std::static_pointer_cast(message); canerror.transmitErrorCount = canerrormsg->transmitErrorCount; canerror.receiveErrorCount = canerrormsg->receiveErrorCount; canerror.status.canBusOff = canerrormsg->busOff; diff --git a/communication/packet/canpacket.cpp b/communication/packet/canpacket.cpp index ed3c753..0601df8 100644 --- a/communication/packet/canpacket.cpp +++ b/communication/packet/canpacket.cpp @@ -1,5 +1,5 @@ #include "icsneo/communication/packet/canpacket.h" -#include "icsneo/communication/message/canerrorcountmessage.h" +#include "icsneo/communication/message/canerrormessage.h" using namespace icsneo; @@ -53,16 +53,18 @@ static std::optional CAN_LengthToDLC(size_t dataLength, bool fd) return std::nullopt; } - std::shared_ptr HardwareCANPacket::DecodeToMessage(const std::vector& bytestream) { const HardwareCANPacket* data = (const HardwareCANPacket*)bytestream.data(); - - if(data->dlc.RB1) { // Change counts reporting - - const bool busOff = data->data[0] & 0b00100000; - - auto msg = std::make_shared(data->data[2], data->data[1], busOff); - + const HardwareCANErrorPacket* errPacket = (const HardwareCANErrorPacket*)bytestream.data(); + if(errPacket->ERROR_INDICATOR) { + auto msg = std::make_shared(); + msg->receiveErrorCount = errPacket->REC; + msg->transmitErrorCount = errPacket->TEC; + msg->errorWarn = HardwareCANErrorPacket::GetErrorWarn(errPacket->flags); + msg->errorPassive = HardwareCANErrorPacket::GetErrorPassive(errPacket->flags); + msg->busOff = HardwareCANErrorPacket::GetBusOff(errPacket->flags); + msg->errorCode = (CANErrorCode)errPacket->error_code; + msg->dataErrorCode = (CANErrorCode)errPacket->brs_data_error_code; // This timestamp is raw off the device (in timestampResolution increments) // Decoder will fix as it has information about the timestampResolution increments msg->timestamp = data->timestamp.TS; diff --git a/device/device.cpp b/device/device.cpp index 8ab668f..351044d 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -814,12 +814,7 @@ std::shared_ptr Device::getHardwareInfo(std::chrono::milliseconds report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error); return nullptr; } - - if(!isOnline()) { - report(APIEvent::Type::DeviceCurrentlyOffline, APIEvent::Severity::Error); - return nullptr; - } - + auto filter = std::make_shared(Message::Type::HardwareInfo); auto response = com->waitForMessageSync([this]() { diff --git a/examples/cpp/interactive/src/InteractiveExample.cpp b/examples/cpp/interactive/src/InteractiveExample.cpp index 4ee446b..fc2628e 100644 --- a/examples/cpp/interactive/src/InteractiveExample.cpp +++ b/examples/cpp/interactive/src/InteractiveExample.cpp @@ -267,7 +267,7 @@ void printMessage(const std::shared_ptr& message) { } // end of icsneo::Message::Type::Frame case icsneo::Message::Type::CANErrorCount: { // A message of type CANErrorCount is guaranteed to be a CANErrorCount, so we can static cast safely - auto cec = std::static_pointer_cast(message); + auto cec = std::static_pointer_cast(message); std::cout << "\t\t" << cec->network << " error counts changed, REC=" << cec->receiveErrorCount << " TEC=" << cec->transmitErrorCount << " (" << (cec->busOff ? "" : "Not ") << "Bus Off)" << std::endl; break; diff --git a/examples/cpp/simple/src/SimpleExample.cpp b/examples/cpp/simple/src/SimpleExample.cpp index 4cbe49d..adc92f5 100644 --- a/examples/cpp/simple/src/SimpleExample.cpp +++ b/examples/cpp/simple/src/SimpleExample.cpp @@ -252,7 +252,7 @@ int main() { } // end of icsneo::Message::Type::Frame case icsneo::Message::Type::CANErrorCount: { // A message of type CANErrorCount is guaranteed to be a CANErrorCount, so we can static cast safely - auto cec = std::static_pointer_cast(message); + auto cec = std::static_pointer_cast(message); // Print the error counts std::cout << "\t\t" << cec->network << " error counts changed, REC=" << std::to_string(cec->receiveErrorCount) diff --git a/include/icsneo/communication/message/canerrorcountmessage.h b/include/icsneo/communication/message/canerrorcountmessage.h deleted file mode 100644 index b40f459..0000000 --- a/include/icsneo/communication/message/canerrorcountmessage.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __CANERRORCOUNTMESSAGE_H_ -#define __CANERRORCOUNTMESSAGE_H_ - -#ifdef __cplusplus - -#include "icsneo/communication/message/message.h" - -namespace icsneo { - -class CANErrorCountMessage : public Message { -public: - CANErrorCountMessage(uint8_t tec, uint8_t rec, bool busOffFlag) - : Message(Message::Type::CANErrorCount), transmitErrorCount(tec), receiveErrorCount(rec), busOff(busOffFlag){} - - Network network; - uint8_t transmitErrorCount; - uint8_t receiveErrorCount; - bool busOff; -}; - -} - -#endif // __cplusplus - -#endif \ No newline at end of file diff --git a/include/icsneo/communication/message/canerrormessage.h b/include/icsneo/communication/message/canerrormessage.h new file mode 100644 index 0000000..43bf157 --- /dev/null +++ b/include/icsneo/communication/message/canerrormessage.h @@ -0,0 +1,40 @@ +#ifndef __CANERRORMESSAGE_H_ +#define __CANERRORMESSAGE_H_ + +#ifdef __cplusplus + +#include "icsneo/communication/message/message.h" + +namespace icsneo { + +enum class CANErrorCode : uint8_t +{ + NoError = 0, + StuffError = 1, + FormError = 2, + AckError = 3, + Bit1Error = 4, + Bit0Error = 5, + CRCError = 6, + NoChange = 7 +}; +class CANErrorMessage : public Message { +public: + CANErrorMessage() : Message(Type::CANError) {} + Network network; + uint8_t transmitErrorCount; + uint8_t receiveErrorCount; + bool busOff; + bool errorPassive; + bool errorWarn; + CANErrorCode dataErrorCode; + CANErrorCode errorCode; +}; + +using CANErrorCountMessage = CANErrorMessage; + +} + +#endif // __cplusplus + +#endif \ No newline at end of file diff --git a/include/icsneo/communication/message/message.h b/include/icsneo/communication/message/message.h index 440ab33..27f79c5 100644 --- a/include/icsneo/communication/message/message.h +++ b/include/icsneo/communication/message/message.h @@ -17,6 +17,7 @@ public: Frame = 0, CANErrorCount = 0x100, + CANError = 0x100, LINHeaderOnly = 0x200, LINBreak = 0x201, diff --git a/include/icsneo/communication/packet/canpacket.h b/include/icsneo/communication/packet/canpacket.h index 8d0c64a..ede29cc 100644 --- a/include/icsneo/communication/packet/canpacket.h +++ b/include/icsneo/communication/packet/canpacket.h @@ -13,6 +13,7 @@ namespace icsneo { typedef uint16_t icscm_bitfield; +#pragma pack(push,2) struct HardwareCANPacket { static std::shared_ptr DecodeToMessage(const std::vector& bytestream); static bool EncodeFromMessage(const CANMessage& message, std::vector& bytestream, const device_eventhandler_t& report); @@ -50,6 +51,28 @@ struct HardwareCANPacket { uint64_t IsExtended : 1; } timestamp; }; +struct HardwareCANErrorPacket { + uint8_t error_code; + uint8_t brs_data_error_code; + + uint16_t reserved; + + uint16_t DLC : 4; + uint16_t : 4; + uint16_t ERROR_INDICATOR : 1; + uint16_t : 7; + + uint8_t flags; + uint8_t REC; + uint8_t TEC; + + static bool GetErrorWarn(uint8_t flags) { return flags & 0b0000'0001; } + static bool GetErrorPassive(uint8_t flags) { return flags & 0b0000'1000; } + static bool GetBusOff(uint8_t flags) { return flags & 0b0010'0000; } +}; + + +#pragma pack(pop) } diff --git a/include/icsneo/icsneocpp.h b/include/icsneo/icsneocpp.h index 62134fc..cad9ca1 100644 --- a/include/icsneo/icsneocpp.h +++ b/include/icsneo/icsneocpp.h @@ -14,7 +14,7 @@ #include "icsneo/communication/message/ethernetmessage.h" #include "icsneo/communication/message/flexray/flexraymessage.h" #include "icsneo/communication/message/iso9141message.h" -#include "icsneo/communication/message/canerrorcountmessage.h" +#include "icsneo/communication/message/canerrormessage.h" #include "icsneo/communication/message/ethphymessage.h" #include "icsneo/communication/message/i2cmessage.h" #include "icsneo/communication/message/a2bmessage.h" diff --git a/third-party/winpcap/include/pcap-stdinc.h b/third-party/winpcap/include/pcap-stdinc.h index 1171865..edb8817 100644 --- a/third-party/winpcap/include/pcap-stdinc.h +++ b/third-party/winpcap/include/pcap-stdinc.h @@ -55,7 +55,7 @@ #include #ifndef __MINGW32__ -#include "IP6_misc.h" +#include "ip6_misc.h" #endif #define caddr_t char*