diff --git a/core/driver/sockcanpp/.clang-format b/core/driver/sockcanpp/.clang-format new file mode 100644 index 0000000..e69de29 diff --git a/core/driver/sockcanpp/CanDriver.cpp b/core/driver/sockcanpp/CanDriver.cpp index 17efd91..6335cbb 100644 --- a/core/driver/sockcanpp/CanDriver.cpp +++ b/core/driver/sockcanpp/CanDriver.cpp @@ -77,7 +77,6 @@ namespace sockcanpp { const int32_t CanDriver::CAN_SOCK_RAW = CAN_RAW; const int32_t CanDriver::CAN_SOCK_SEVEN = 7; -#pragma region Object Construction CanDriver::CanDriver(string canInterface, int32_t canProtocol, const CanId defaultSenderId): CanDriver(canInterface, canProtocol, 0 /* match all */, defaultSenderId) {} @@ -85,9 +84,7 @@ namespace sockcanpp { _defaultSenderId(defaultSenderId), _canProtocol(canProtocol), _canInterface(canInterface), _canFilterMask(filterMask), _socketFd(-1) { initialiseSocketCan(); } -#pragma endregion -#pragma region I / O /** * @brief Blocks until one or more CAN messages appear on the bus, or until the timeout runs out. * @@ -229,13 +226,11 @@ namespace sockcanpp { _canFilterMask = mask; } -#pragma endregion ////////////////////////////////////// // PROTECTED IMPLEMENTATION // ////////////////////////////////////// -#pragma region Socket Management /** * @brief Initialises the underlying CAN socket. @@ -290,6 +285,5 @@ namespace sockcanpp { _socketFd = -1; } -#pragma endregion } // namespace sockcanpp diff --git a/core/driver/sockcanpp/CanId.hpp b/core/driver/sockcanpp/CanId.hpp index d2f8a47..dcff2d7 100644 --- a/core/driver/sockcanpp/CanId.hpp +++ b/core/driver/sockcanpp/CanId.hpp @@ -68,14 +68,12 @@ namespace sockcanpp { public: // +++ Operators +++ -#pragma region "Implicit Cast Operators" operator int16_t() const { return isStandardFrameId() ? (int16_t)_identifier : throw system_error(error_code(0xbad1d, generic_category()), "INVALID CAST: ID is extended or invalid!"); } operator uint16_t() const { return isStandardFrameId() ? (uint16_t)_identifier : throw system_error(error_code(0xbad1d, generic_category()), "INVALID CAST: ID is extended or invalid!"); } operator int32_t() const { return _identifier; } operator uint32_t() const { return _identifier; } -#pragma endregion -#pragma region "Bitwise Operators" + CanId operator &(CanId& x) const { return _identifier & x._identifier; } CanId operator &(const CanId x) const { return _identifier & x._identifier; } CanId operator &(const int16_t x) const { return _identifier & x; } @@ -93,45 +91,41 @@ namespace sockcanpp { CanId operator |(const uint32_t x) const { return _identifier | x; } CanId operator |(const int64_t x) const { return _identifier | x; } CanId operator |(const uint64_t x) const { return _identifier | x; } -#pragma endregion -#pragma region "Comparison Operators" bool operator ==(CanId& x) const { return _identifier == x._identifier; } bool operator ==(const CanId& x) const { return _identifier == x._identifier; } - bool operator ==(const int16_t x) const { return _identifier == x; } - bool operator ==(const uint16_t x) const { return _identifier == x; } - bool operator ==(const int32_t x) const { return _identifier == x; } - bool operator ==(const uint32_t x) const { return _identifier == x; } - bool operator ==(const int64_t x) const { return (x > UINT32_MAX || x < INT32_MIN) ? false : x == _identifier; } - bool operator ==(const uint64_t x) const { return x > UINT32_MAX ? false : x == _identifier; } + bool operator ==(const int16_t x) const { return int16_t (_identifier) == x; } + bool operator ==(const uint16_t x) const { return uint16_t (_identifier) == x; } + bool operator ==(const int32_t x) const { return int32_t (_identifier) == x; } + bool operator ==(const uint32_t x) const { return uint32_t (_identifier) == x; } + bool operator ==(const int64_t x) const { return (x > UINT32_MAX || x < INT32_MIN) ? false : x == int64_t(_identifier); } + bool operator ==(const uint64_t x) const { return x > UINT32_MAX ? false : x == uint64_t(_identifier); } bool operator !=(CanId& x) const { return _identifier != x._identifier; } bool operator !=(const CanId& x) const { return _identifier != x._identifier; } - bool operator !=(const int16_t x) const { return _identifier != x; } - bool operator !=(const uint16_t x) const { return _identifier != x; } - bool operator !=(const int32_t x) const { return _identifier != x; } - bool operator !=(const uint32_t x) const { return _identifier != x; } + bool operator !=(const int16_t x) const { return int16_t(_identifier) != x; } + bool operator !=(const uint16_t x) const { return uint16_t(_identifier) != x; } + bool operator !=(const int32_t x) const { return int32_t(_identifier) != x; } + bool operator !=(const uint32_t x) const { return uint32_t(_identifier) != x; } bool operator !=(const int64_t x) const { return (x > UINT32_MAX || x < INT32_MIN) ? false : x != _identifier; } bool operator !=(const uint64_t x) const { return x > UINT32_MAX ? false : x != _identifier; } bool operator <(CanId& x) const { return x._identifier < _identifier; } - bool operator <(int32_t x) const { return x < _identifier; } - bool operator <(uint32_t x) const { return x < _identifier; } - bool operator <(int16_t x) const { return x < _identifier; } - bool operator <(uint16_t x) const { return x < _identifier; } + bool operator <(int32_t x) const { return x < int32_t(_identifier); } + bool operator <(uint32_t x) const { return x < uint32_t(_identifier); } + bool operator <(int16_t x) const { return x < int16_t(_identifier); } + bool operator <(uint16_t x) const { return x < uint16_t(_identifier); } bool operator <=(CanId& x) const { return x._identifier <= _identifier; } bool operator >(CanId& x) const { return x._identifier > _identifier; } - bool operator >(int32_t x) const { return x > _identifier; } - bool operator >(uint32_t x) const { return x > _identifier; } - bool operator >(int16_t x) const { return x > _identifier; } - bool operator >(uint16_t x) const { return x > _identifier; } + bool operator >(int32_t x) const { return x > int32_t(_identifier); } + bool operator >(uint32_t x) const { return x > uint32_t(_identifier); } + bool operator >(int16_t x) const { return x > int16_t(_identifier); } + bool operator >(uint16_t x) const { return x > uint16_t(_identifier); } bool operator >=(CanId& x) const { return x._identifier >= _identifier; } bool operator <(const CanId& x) const { return x._identifier < _identifier; } bool operator <=(const CanId& x) const { return x._identifier <= _identifier; } bool operator >(const CanId& x) const { return x._identifier > _identifier; } bool operator >=(const CanId& x) const { return x._identifier >= _identifier; } -#pragma endregion -#pragma region "Assignment Operators" CanId operator =(const int32_t val) { uint32_t tmpVal = val; auto tmp = (isValidIdentifier(tmpVal) ? CanId(val) : throw system_error(error_code(0x5421, generic_category()), "INVALID CAST: ID is extended or invalid!")); @@ -144,9 +138,7 @@ namespace sockcanpp { } CanId operator =(const int64_t val) { return operator =((int32_t)val); } -#pragma endregion -#pragma region "Arithmetic Operators" CanId operator +(CanId& x) const { return _identifier + x._identifier; } CanId operator +(const CanId& x) const { return _identifier + x._identifier; } CanId operator +(const int16_t x) const { return _identifier + x; } @@ -164,7 +156,6 @@ namespace sockcanpp { CanId operator -(const uint32_t x) const { return _identifier - x; } CanId operator -(const int64_t x) const { return _identifier - x; } CanId operator -(const uint64_t x) const { return _identifier - x; } -#pragma endregion public: // +++ Validity Checks +++ /**