From c7b4cbc45caad5d43156139b61a98520cd67b53f Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 18:45:02 +0900 Subject: [PATCH 01/18] Update variable with alias type --- src/ics3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ics3.cpp b/src/ics3.cpp index fc3a9f7..155419f 100644 --- a/src/ics3.cpp +++ b/src/ics3.cpp @@ -19,7 +19,7 @@ ics::ICS3::ICS3(const std::string& path, const Baudrate& baudrate) ics::Angle ics::ICS3::move(const ID& id, Angle angle) { static Core::Container tx(3), rx(6); // cache for runtime speed - const uint16_t send {angle.getRaw()}; + const auto send = angle.getRaw(); tx[0] = getCmd(0x80, id); tx[1] = 0x7F & (send >> 7); tx[2] = 0x7F & send; From 87f853d71001b8c91512fd6da9d2799b6b852581 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 18:48:24 +0900 Subject: [PATCH 02/18] Update non explicit return object --- src/ics3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ics3.cpp b/src/ics3.cpp index 155419f..de1fb21 100644 --- a/src/ics3.cpp +++ b/src/ics3.cpp @@ -69,7 +69,7 @@ ics::ID ics::ICS3::getID() { constexpr Core::IDContainerTx tx {0xFF, 0x00, 0x00, 0x00}; Core::IDContainerRx rx; core->communicateID(tx, rx); - return ID {static_cast(0x1F & rx[4])}; + return {static_cast(0x1F & rx[4])}; } void ics::ICS3::setID(const ID& id) { From 670c1bdb79ab32208437e473beef2c63378800c1 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 18:51:16 +0900 Subject: [PATCH 03/18] Update narrow return without static_cast --- include/ics3/angle.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ics3/angle.hpp b/include/ics3/angle.hpp index fe660cf..f4adae0 100644 --- a/include/ics3/angle.hpp +++ b/include/ics3/angle.hpp @@ -88,7 +88,7 @@ namespace ics { {} constexpr Angle::rawType Angle::castToRaw(type calibration, type angle) noexcept { - return static_cast((calibration * angle) + MID); + return (calibration * angle) + MID; } constexpr Angle::rawType Angle::checkInvalidAngle(rawType raw) { From a44df9ee1622b1c8d64b6f44e45c11b7a33bb9d9 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 18:55:14 +0900 Subject: [PATCH 04/18] Omit explicit --- include/ics3/angle.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ics3/angle.hpp b/include/ics3/angle.hpp index f4adae0..9195a46 100644 --- a/include/ics3/angle.hpp +++ b/include/ics3/angle.hpp @@ -28,7 +28,7 @@ namespace ics { constexpr rawType getRaw() const noexcept; void setRaw(rawType); private: - constexpr explicit Angle(type, type); + constexpr Angle(type, type); // non explicit, user cannot touch this static constexpr rawType castToRaw(type, type) noexcept; static constexpr rawType checkInvalidAngle(rawType); From ceeaa6c7f81634cca8e5cafc3304fd0aedeb7454 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 18:56:16 +0900 Subject: [PATCH 05/18] Update factory method with no explicit constructor --- include/ics3/angle.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ics3/angle.hpp b/include/ics3/angle.hpp index 9195a46..fbd56e0 100644 --- a/include/ics3/angle.hpp +++ b/include/ics3/angle.hpp @@ -37,19 +37,19 @@ namespace ics { }; constexpr Angle Angle::newDegree(type angle) { - return Angle {800.0 / 27.0, angle}; + return {800.0 / 27.0, angle}; } constexpr Angle Angle::newRadian(type angle) { - return Angle {16000.0 / 3.0 / PI, angle}; + return {16000.0 / 3.0 / PI, angle}; } constexpr Angle Angle::newSameUnit(const Angle& unit, type angle) { - return Angle {unit.rawCalibration, angle}; + return {unit.rawCalibration, angle}; } constexpr Angle Angle::newCalibration(type calibration, type angle) { - return Angle {calibration, angle}; + return {calibration, angle}; } inline Angle& Angle::operator=(const Angle& rhs) noexcept { From 99cb351b50ba92b2e9a5bbba4a2a90a2c8dfc2e7 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 18:57:21 +0900 Subject: [PATCH 06/18] Omit explicit --- include/ics3/baudrate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ics3/baudrate.hpp b/include/ics3/baudrate.hpp index 839a0f7..b05478e 100644 --- a/include/ics3/baudrate.hpp +++ b/include/ics3/baudrate.hpp @@ -14,7 +14,7 @@ namespace ics { constexpr operator type() const noexcept; constexpr speed_t getSpeed() const noexcept; private: - explicit constexpr Baudrate(type, speed_t) noexcept; + constexpr Baudrate(type, speed_t) noexcept; // non explicit, user cannot touch this const type romdata; const speed_t baudrate; From 16eb9f8d7b0829e7a977a231f6bd984bbd6a7870 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 18:57:52 +0900 Subject: [PATCH 07/18] Update factory method with no explicit constructor --- include/ics3/baudrate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ics3/baudrate.hpp b/include/ics3/baudrate.hpp index b05478e..3ec9822 100644 --- a/include/ics3/baudrate.hpp +++ b/include/ics3/baudrate.hpp @@ -21,7 +21,7 @@ namespace ics { }; constexpr Baudrate Baudrate::RATE115200() noexcept { - return Baudrate {10, B115200}; + return {10, B115200}; } constexpr Baudrate::type Baudrate::get() const noexcept { From dff2fb95bb054a47f56e7a4f4dc8e86b72443573 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:05:37 +0900 Subject: [PATCH 08/18] Omit explicit --- include/ics3/eepparam.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ics3/eepparam.hpp b/include/ics3/eepparam.hpp index e3023f8..cfc567d 100644 --- a/include/ics3/eepparam.hpp +++ b/include/ics3/eepparam.hpp @@ -48,7 +48,7 @@ namespace ics { void write(std::array&) const noexcept; void read(const std::array&); private: - constexpr explicit EepParam( + constexpr EepParam( // non explicit, user cannot touch this size_type, size_type, type, From 83287344605722b67acb80e217f6df4d2326993b Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:06:30 +0900 Subject: [PATCH 09/18] Update factory method with no explicit constructor --- include/ics3/eepparam.hpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/include/ics3/eepparam.hpp b/include/ics3/eepparam.hpp index cfc567d..9a0ed4c 100644 --- a/include/ics3/eepparam.hpp +++ b/include/ics3/eepparam.hpp @@ -70,79 +70,79 @@ namespace ics { }; constexpr EepParam EepParam::stretch(type data) { - return EepParam {2, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; + return {2, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; } constexpr EepParam EepParam::speed(type data) { - return EepParam {4, 2, 1, 127, &EepParam::checkInvalidRange, data}; + return {4, 2, 1, 127, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::punch(type data) { - return EepParam {6, 2, 0, 10, &EepParam::checkInvalidRange, data}; + return {6, 2, 0, 10, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::deadBand(type data) { - return EepParam {8, 2, 0, 5, &EepParam::checkInvalidRange, data}; + return {8, 2, 0, 5, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::dumping(type data) { - return EepParam {10, 2, 1, 255, &EepParam::checkInvalidRange, data}; + return {10, 2, 1, 255, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::selfTimer(type data) { - return EepParam {12, 2, 10, 255, &EepParam::checkInvalidRange, data}; + return {12, 2, 10, 255, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::flag(type data) { - return EepParam {14, 2, 0, 255, &EepParam::checkInvalidFlag, data}; + return {14, 2, 0, 255, &EepParam::checkInvalidFlag, data}; } constexpr EepParam EepParam::pulseMax(type data) { - return EepParam {16, 4, 3500, 11500, &EepParam::checkInvalidRange, data}; + return {16, 4, 3500, 11500, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::pulseMin(type data) { - return EepParam {20, 4, 3500, 11500, &EepParam::checkInvalidRange, data}; + return {20, 4, 3500, 11500, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::baudrate(type data) { - return EepParam {26, 2, 0, 10, &EepParam::checkInvalidBaudrate, data}; + return {26, 2, 0, 10, &EepParam::checkInvalidBaudrate, data}; } constexpr EepParam EepParam::temperature(type data) { - return EepParam {28, 2, 1, 127, &EepParam::checkInvalidRange, data}; + return {28, 2, 1, 127, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::current(type data) { - return EepParam {30, 2, 1, 63, &EepParam::checkInvalidRange, data}; + return {30, 2, 1, 63, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::response(type data) { - return EepParam {50, 2, 1, 5, &EepParam::checkInvalidRange, data}; + return {50, 2, 1, 5, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::userOffset(type data) { - return EepParam {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 EepParam {56, 2, 0, 31, &EepParam::checkInvalidRange, data}; + return {56, 2, 0, 31, &EepParam::checkInvalidRange, data}; } constexpr EepParam EepParam::strech1(type data) { - return EepParam {58, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; + return {58, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; } constexpr EepParam EepParam::strech2(type data) { - return EepParam {60, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; + return {60, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; } constexpr EepParam EepParam::strech3(type data) { - return EepParam {62, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; + return {62, 2, 2, 254, &EepParam::checkInvalidEvenRange, data}; } constexpr EepParam EepParam::newEepParam(const EepParam& paramType, type data) { - return EepParam {paramType.offset, paramType.length, paramType.min, paramType.max, paramType.setFunc, data}; + return {paramType.offset, paramType.length, paramType.min, paramType.max, paramType.setFunc, data}; } constexpr EepParam::type EepParam::get() const noexcept { From 6b8c524dec7bb0753e7abd57fc06227e3edaaa82 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:08:35 +0900 Subject: [PATCH 10/18] Omit explicit --- include/ics3/eeprom.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ics3/eeprom.hpp b/include/ics3/eeprom.hpp index 0069bed..f25087b 100644 --- a/include/ics3/eeprom.hpp +++ b/include/ics3/eeprom.hpp @@ -20,7 +20,7 @@ namespace ics { template void write(Iter&&) const; private: - explicit EepRom(const Container&); + EepRom(const Container&); // non explicit, user cannot touch this std::array data; }; From 4d94eb196772f22735104a73729527c6e0bd0864 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:10:12 +0900 Subject: [PATCH 11/18] Omit explicit --- include/ics3/parameter.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ics3/parameter.hpp b/include/ics3/parameter.hpp index 9f988cf..eac00db 100644 --- a/include/ics3/parameter.hpp +++ b/include/ics3/parameter.hpp @@ -19,7 +19,7 @@ namespace ics { Parameter& operator=(type); constexpr type getSubcommand() const noexcept; private: - explicit constexpr Parameter(type, type, type, type); + constexpr Parameter(type, type, type, type); // non explicit, user cannot touch this const type sc; const type min; From 1f29b40dceb1865705719e50483f79f20b244c52 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:10:41 +0900 Subject: [PATCH 12/18] Update factory method with no explicit constructor --- include/ics3/parameter.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/ics3/parameter.hpp b/include/ics3/parameter.hpp index eac00db..8f01289 100644 --- a/include/ics3/parameter.hpp +++ b/include/ics3/parameter.hpp @@ -28,23 +28,23 @@ namespace ics { }; constexpr Parameter Parameter::stretch(type data) { - return Parameter {0x01, 1, 127, data}; + return {0x01, 1, 127, data}; } constexpr Parameter Parameter::speed(type data) { - return Parameter {0x02, 1, 127, data}; + return {0x02, 1, 127, data}; } constexpr Parameter Parameter::current(type data) { - return Parameter {0x03, 0, 63, data}; + return {0x03, 0, 63, data}; } constexpr Parameter Parameter::temperature(type data) { - return Parameter {0x04, 1, 127, data}; + return {0x04, 1, 127, data}; } constexpr Parameter Parameter::newParameter(const Parameter& base, type data) { - return Parameter {base.sc, base.min, base.max, data}; + return {base.sc, base.min, base.max, data}; } constexpr Parameter::type Parameter::get() const noexcept { From ec8b3e065abe695e76992ef6d375f2acb46e5740 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:12:58 +0900 Subject: [PATCH 13/18] Update getRom with non explicit constructor --- src/ics3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ics3.cpp b/src/ics3.cpp index de1fb21..025be06 100644 --- a/src/ics3.cpp +++ b/src/ics3.cpp @@ -55,7 +55,7 @@ ics::EepRom ics::ICS3::getRom(const ID& id) { core->communicate(tx, rx); // throw std::runtime_error EepRom::Container romData; std::copy(rx.cbegin() + 4, rx.cend(), romData.begin()); - return EepRom {romData}; // need friend + return {romData}; // need friend } void ics::ICS3::setRom(const ID& id, const EepRom& rom) { From 640a2374abf798ec6f58fa8687c50d7ffd559559 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:28:18 +0900 Subject: [PATCH 14/18] Update order methos by get is forward, set is rear --- include/ics3/eepparam.hpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/include/ics3/eepparam.hpp b/include/ics3/eepparam.hpp index 9a0ed4c..db8288d 100644 --- a/include/ics3/eepparam.hpp +++ b/include/ics3/eepparam.hpp @@ -45,8 +45,8 @@ namespace ics { constexpr operator type() const noexcept; void set(type); EepParam& operator=(type); - void write(std::array&) const noexcept; void read(const std::array&); + void write(std::array&) const noexcept; private: constexpr EepParam( // non explicit, user cannot touch this size_type, @@ -162,14 +162,6 @@ namespace ics { return *this; } - inline void EepParam::write(std::array& dest) const noexcept { - type nowData {data}; - for (size_type i {offset + length - 1}; i >= offset; --i) { - dest[i] = nowData & mask; - nowData >>= byteSize; - } - } - inline void EepParam::read(const std::array& src) { type result {0}; const size_type loopend = offset + length; @@ -179,6 +171,15 @@ namespace ics { } set(result); // throw std::invalid_argument, std::out_of_range } + + inline void EepParam::write(std::array& dest) const noexcept { + type nowData {data}; + for (size_type i {offset + length - 1}; i >= offset; --i) { + dest[i] = nowData & mask; + nowData >>= byteSize; + } + } + constexpr EepParam::EepParam( size_type offset, size_type length, From 576f3fa73b63f13508ac8ff3d619a43ca29e9678 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:30:54 +0900 Subject: [PATCH 15/18] Update member with alias type --- include/ics3/eeprom.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ics3/eeprom.hpp b/include/ics3/eeprom.hpp index f25087b..a83222a 100644 --- a/include/ics3/eeprom.hpp +++ b/include/ics3/eeprom.hpp @@ -22,7 +22,7 @@ namespace ics { private: EepRom(const Container&); // non explicit, user cannot touch this - std::array data; + Container data; }; inline ics::EepParam ics::EepRom::get(EepParam type) const { From 54963feff403e312ca548bb76792be4fcf0b6960 Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:40:19 +0900 Subject: [PATCH 16/18] Add alias of EepParam target --- include/ics3/eepparam.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/ics3/eepparam.hpp b/include/ics3/eepparam.hpp index db8288d..a0dac83 100644 --- a/include/ics3/eepparam.hpp +++ b/include/ics3/eepparam.hpp @@ -11,6 +11,7 @@ namespace ics { public: using type = uint16_t; using size_type = std::size_t; + using TargetContainer = std::array; enum Flag : type { REVERSE = 0x01, FREE = 0x02, @@ -45,8 +46,8 @@ namespace ics { constexpr operator type() const noexcept; void set(type); EepParam& operator=(type); - void read(const std::array&); - void write(std::array&) const noexcept; + void read(const TargetContainer&); + void write(TargetContainer&) const noexcept; private: constexpr EepParam( // non explicit, user cannot touch this size_type, @@ -162,7 +163,7 @@ namespace ics { return *this; } - inline void EepParam::read(const std::array& src) { + inline void EepParam::read(const TargetContainer& src) { type result {0}; const size_type loopend = offset + length; for (size_type i {offset}; i < loopend; ++i) { @@ -172,7 +173,7 @@ namespace ics { set(result); // throw std::invalid_argument, std::out_of_range } - inline void EepParam::write(std::array& dest) const noexcept { + inline void EepParam::write(TargetContainer& dest) const noexcept { type nowData {data}; for (size_type i {offset + length - 1}; i >= offset; --i) { dest[i] = nowData & mask; From 535f8fd564ea639d09a0bc6f1e3230a5874fb72f Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:42:18 +0900 Subject: [PATCH 17/18] Update argument type for Core::value --- src/ics3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ics3.cpp b/src/ics3.cpp index 025be06..3ad01e5 100644 --- a/src/ics3.cpp +++ b/src/ics3.cpp @@ -9,7 +9,7 @@ static inline ics::Angle::rawType getReceiveAngle(const ics::Core::Container& rx return (rx[4] << 7) | rx[5]; } -static inline ics::Core::value getCmd(const int head, const ics::ID& id) { +static inline ics::Core::value getCmd(const ics::Core::value head, const ics::ID& id) { return head | id.get(); } From f338d0d45288966a1c08a2e6230f2666a206fb3a Mon Sep 17 00:00:00 2001 From: Doi Yusuke Date: Thu, 3 Nov 2016 19:55:36 +0900 Subject: [PATCH 18/18] Update v1.2.1 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3be58e8..e107882 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 0) +SET(PROJECT_VER_PATCH 1) SET(PROJECT_VER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}") SET(PROJECT_APIVER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")