diff --git a/CMakeLists.txt b/CMakeLists.txt index 675e6a4..123dd25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(ics3 CXX) SET(PROJECT_VER_MAJOR 1) SET(PROJECT_VER_MINOR 2) -SET(PROJECT_VER_PATCH 2) +SET(PROJECT_VER_PATCH 3) SET(PROJECT_VER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}") SET(PROJECT_APIVER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}") diff --git a/include/ics3/eepparam.hpp b/include/ics3/eepparam.hpp index a0dac83..95bfd89 100644 --- a/include/ics3/eepparam.hpp +++ b/include/ics3/eepparam.hpp @@ -12,6 +12,7 @@ namespace ics { using type = uint16_t; using size_type = std::size_t; using TargetContainer = std::array; + using InvalidChecker = type (&)(type, type, type); enum Flag : type { REVERSE = 0x01, FREE = 0x02, @@ -54,7 +55,7 @@ namespace ics { size_type, type, type, - type (*)(type, type, type), + InvalidChecker, type); static constexpr type checkInvalidRange(type, type, type); static constexpr type checkInvalidEvenRange(type, type, type); @@ -66,80 +67,80 @@ namespace ics { const size_type length; const type min; const type max; - type (*const setFunc)(type, type, type); + InvalidChecker setFunc; type data; }; constexpr EepParam EepParam::stretch(type data) { - return {2, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; + return {2, 2, 2, 254, EepParam::checkInvalidEvenRange, data}; } constexpr EepParam EepParam::speed(type data) { - return {4, 2, 1, 127, &EepParam::checkInvalidRange, data}; + return {4, 2, 1, 127, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::punch(type data) { - return {6, 2, 0, 10, &EepParam::checkInvalidRange, data}; + return {6, 2, 0, 10, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::deadBand(type data) { - return {8, 2, 0, 5, &EepParam::checkInvalidRange, data}; + return {8, 2, 0, 5, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::dumping(type data) { - return {10, 2, 1, 255, &EepParam::checkInvalidRange, data}; + return {10, 2, 1, 255, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::selfTimer(type data) { - return {12, 2, 10, 255, &EepParam::checkInvalidRange, data}; + return {12, 2, 10, 255, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::flag(type data) { - return {14, 2, 0, 255, &EepParam::checkInvalidFlag, data}; + return {14, 2, 0, 255, EepParam::checkInvalidFlag, data}; } constexpr EepParam EepParam::pulseMax(type data) { - return {16, 4, 3500, 11500, &EepParam::checkInvalidRange, data}; + return {16, 4, 3500, 11500, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::pulseMin(type data) { - return {20, 4, 3500, 11500, &EepParam::checkInvalidRange, data}; + return {20, 4, 3500, 11500, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::baudrate(type data) { - return {26, 2, 0, 10, &EepParam::checkInvalidBaudrate, data}; + return {26, 2, 0, 10, EepParam::checkInvalidBaudrate, data}; } constexpr EepParam EepParam::temperature(type data) { - return {28, 2, 1, 127, &EepParam::checkInvalidRange, data}; + return {28, 2, 1, 127, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::current(type data) { - return {30, 2, 1, 63, &EepParam::checkInvalidRange, data}; + return {30, 2, 1, 63, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::response(type data) { - return {50, 2, 1, 5, &EepParam::checkInvalidRange, data}; + return {50, 2, 1, 5, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::userOffset(type data) { - return {52, 2, 0x81, 127, &EepParam::checkInvalidOffset, data}; // 0x81 is -127 on uint8_t type + return {52, 2, 0x81, 127, EepParam::checkInvalidOffset, data}; // 0x81 is -127 on uint8_t type } constexpr EepParam EepParam::id(type data) { - return {56, 2, 0, 31, &EepParam::checkInvalidRange, data}; + return {56, 2, 0, 31, EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::strech1(type data) { - return {58, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; + return {58, 2, 2, 254, EepParam::checkInvalidEvenRange, data}; } constexpr EepParam EepParam::strech2(type data) { - return {60, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; + return {60, 2, 2, 254, EepParam::checkInvalidEvenRange, data}; } constexpr EepParam EepParam::strech3(type data) { - return {62, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; + return {62, 2, 2, 254, EepParam::checkInvalidEvenRange, data}; } constexpr EepParam EepParam::newEepParam(const EepParam& paramType, type data) { @@ -155,7 +156,7 @@ namespace ics { } inline void EepParam::set(type input) { - data = (*setFunc)(input, min, max); // throw std::invalid_argument, std::out_of_range + data = setFunc(input, min, max); // throw std::invalid_argument, std::out_of_range } inline EepParam& EepParam::operator=(type input) { @@ -186,7 +187,7 @@ namespace ics { size_type length, type min, type max, - type (*setFunc)(type, type, type), + InvalidChecker setFunc, type data) : offset(offset), length(length), diff --git a/src/core.cpp b/src/core.cpp index f034707..f114a9e 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -18,7 +18,7 @@ ics::Core::Core(const std::string& path, speed_t baudrate) throw std::invalid_argument {"Not tty device"}; if (tcgetattr(fd, &oldTio) < 0) throw std::runtime_error {"Cannot setup tty"}; - auto newTio = getTermios(); + auto&& newTio = getTermios(); // forward reference if (cfsetispeed(&newTio, baudrate) < 0) throw std::runtime_error {"Cannot set baudrate"}; if (cfsetospeed(&newTio, baudrate) < 0) @@ -66,7 +66,7 @@ void ics::Core::communicate(const Container& tx, Container& rx) { write(fd, tx.data(), tx.size()); // send for (auto& receive : rx) read(fd, &receive, 1); // receive // check section - auto receive = rx.cbegin(); + auto&& receive = rx.cbegin(); for (const auto& send : tx) { if (send != *receive) { std::stringstream ss; @@ -82,7 +82,7 @@ void ics::Core::communicateID(const IDContainerTx& tx, IDContainerRx& rx) { write(fd, tx.data(), tx.size()); // send for (auto& receive : rx) read(fd, &receive, 1); // receive // check section - auto receive = rx.cbegin(); + auto&& receive = rx.cbegin(); for (const auto& send : tx) { if (send != *receive) { std::stringstream ss;