diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d39531..4375539 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 4) +SET(PROJECT_VER_PATCH 5) 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/core.hpp b/include/core.hpp index 95a89b6..937fbfa 100644 --- a/include/core.hpp +++ b/include/core.hpp @@ -1,10 +1,36 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef LIBICS3_ICS3_CORE_H_ #define LIBICS3_ICS3_CORE_H_ -#include #include -#include #include +#include +#include #include namespace ics { @@ -25,7 +51,7 @@ namespace ics { void communicate(const Container&, Container&); void communicateID(const IDContainerTx&, IDContainerRx&); private: - void closeThis() noexcept; + void closeThis() const noexcept; static termios getTermios() noexcept; diff --git a/include/ics3/angle.hpp b/include/ics3/angle.hpp index fbd56e0..8533a8c 100644 --- a/include/ics3/angle.hpp +++ b/include/ics3/angle.hpp @@ -1,3 +1,29 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef LIBICS3_ICS3_ANGLE_H_ #define LIBICS3_ICS3_ANGLE_H_ @@ -6,7 +32,7 @@ namespace ics { class ICS3; class Angle { - friend ICS3; // for touch setRaw + friend ICS3; // for touch rawData public: using rawType = uint16_t; using type = double; @@ -30,7 +56,7 @@ namespace ics { private: constexpr Angle(type, type); // non explicit, user cannot touch this static constexpr rawType castToRaw(type, type) noexcept; - static constexpr rawType checkInvalidAngle(rawType); + static constexpr rawType checkValidAngle(rawType); rawType rawData; const type rawCalibration; @@ -79,11 +105,11 @@ namespace ics { } inline void Angle::setRaw(rawType raw) { - rawData = checkInvalidAngle(raw); // throw std::out_of_range + rawData = checkValidAngle(raw); // throw std::out_of_range } constexpr Angle::Angle(type calibration, type angle) - : rawData {checkInvalidAngle(castToRaw(calibration, angle))}, // throw std::out_of_range + : rawData {checkValidAngle(castToRaw(calibration, angle))}, // throw std::out_of_range rawCalibration {calibration} {} @@ -91,8 +117,8 @@ namespace ics { return (calibration * angle) + MID; } - constexpr Angle::rawType Angle::checkInvalidAngle(rawType raw) { - return checkInvalidRange(raw, MIN, MAX); + constexpr Angle::rawType Angle::checkValidAngle(rawType raw) { + return checkValidRange(raw, MIN, MAX); } } diff --git a/include/ics3/baudrate.hpp b/include/ics3/baudrate.hpp index 3ec9822..dcc96e6 100644 --- a/include/ics3/baudrate.hpp +++ b/include/ics3/baudrate.hpp @@ -1,3 +1,29 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef LIBICS3_ICS3_BAUDRATE_H_ #define LIBICS3_ICS3_BAUDRATE_H_ diff --git a/include/ics3/check_invalid.hpp b/include/ics3/check_invalid.hpp index 8c058e7..acedbbc 100644 --- a/include/ics3/check_invalid.hpp +++ b/include/ics3/check_invalid.hpp @@ -1,3 +1,29 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef LIBICS3_ICS3_CHECK_INVALID_H_ #define LIBICS3_ICS3_CHECK_INVALID_H_ @@ -5,7 +31,7 @@ namespace ics { template - constexpr T checkInvalidRange(T input, const T min, const T max) { + constexpr T checkValidRange(const T input, const T min, const T max) { return input < min ? throw std::out_of_range {"Too small argument"} : max < input ? throw std::out_of_range {"Too big argument"} : input; diff --git a/include/ics3/eepparam.hpp b/include/ics3/eepparam.hpp index 0db67a0..ce02297 100644 --- a/include/ics3/eepparam.hpp +++ b/include/ics3/eepparam.hpp @@ -1,8 +1,34 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef LIBICS3_ICS3_EEPPARAM_H_ #define LIBICS3_ICS3_EEPPARAM_H_ -#include"ics3/check_invalid.hpp" #include"ics3/baudrate.hpp" +#include"ics3/check_invalid.hpp" #include @@ -12,7 +38,7 @@ namespace ics { using type = uint16_t; using TargetContainer = std::array; using size_type = TargetContainer::size_type; - using InvalidChecker = type (&)(type, type, type); + using ValidChecker = type (&)(type, type, type); enum Flag : type { REVERSE = 0x01, FREE = 0x02, @@ -55,92 +81,92 @@ namespace ics { size_type, type, type, - InvalidChecker, + ValidChecker, type); - static constexpr type checkInvalidRange(type, type, type); - static constexpr type checkInvalidEvenRange(type, type, type); - static constexpr type checkInvalidFlag(type, type, type); - static constexpr type checkInvalidBaudrate(type, type, type); - static constexpr type checkInvalidOffset(type, type, type); + static constexpr type checkValidRange(type, type, type); + static constexpr type checkValidEvenRange(type, type, type); + static constexpr type checkValidFlag(type, type, type); + static constexpr type checkValidBaudrate(type, type, type); + static constexpr type checkValidOffset(type, type, type); const size_type offset; const size_type length; const type min; const type max; - InvalidChecker setFunc; + ValidChecker setFunc; type data; }; constexpr EepParam EepParam::stretch(type data) { - return {2, 2, 2, 254, EepParam::checkInvalidEvenRange, data}; + return {2, 2, 2, 254, EepParam::checkValidEvenRange, data}; } constexpr EepParam EepParam::speed(type data) { - return {4, 2, 1, 127, EepParam::checkInvalidRange, data}; + return {4, 2, 1, 127, EepParam::checkValidRange, data}; } constexpr EepParam EepParam::punch(type data) { - return {6, 2, 0, 10, EepParam::checkInvalidRange, data}; + return {6, 2, 0, 10, EepParam::checkValidRange, data}; } constexpr EepParam EepParam::deadBand(type data) { - return {8, 2, 0, 5, EepParam::checkInvalidRange, data}; + return {8, 2, 0, 5, EepParam::checkValidRange, data}; } constexpr EepParam EepParam::dumping(type data) { - return {10, 2, 1, 255, EepParam::checkInvalidRange, data}; + return {10, 2, 1, 255, EepParam::checkValidRange, data}; } constexpr EepParam EepParam::selfTimer(type data) { - return {12, 2, 10, 255, EepParam::checkInvalidRange, data}; + return {12, 2, 10, 255, EepParam::checkValidRange, data}; } constexpr EepParam EepParam::flag(type data) { - return {14, 2, 0, 255, EepParam::checkInvalidFlag, data}; + return {14, 2, 0, 255, EepParam::checkValidFlag, data}; } constexpr EepParam EepParam::pulseMax(type data) { - return {16, 4, 3500, 11500, EepParam::checkInvalidRange, data}; + return {16, 4, 3500, 11500, EepParam::checkValidRange, data}; } constexpr EepParam EepParam::pulseMin(type data) { - return {20, 4, 3500, 11500, EepParam::checkInvalidRange, data}; + return {20, 4, 3500, 11500, EepParam::checkValidRange, data}; } constexpr EepParam EepParam::baudrate(type data) { - return {26, 2, 0, 10, EepParam::checkInvalidBaudrate, data}; + return {26, 2, 0, 10, EepParam::checkValidBaudrate, data}; } constexpr EepParam EepParam::temperature(type data) { - return {28, 2, 1, 127, EepParam::checkInvalidRange, data}; + return {28, 2, 1, 127, EepParam::checkValidRange, data}; } constexpr EepParam EepParam::current(type data) { - return {30, 2, 1, 63, EepParam::checkInvalidRange, data}; + return {30, 2, 1, 63, EepParam::checkValidRange, data}; } constexpr EepParam EepParam::response(type data) { - return {50, 2, 1, 5, EepParam::checkInvalidRange, data}; + return {50, 2, 1, 5, EepParam::checkValidRange, 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::checkValidOffset, 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::checkValidRange, data}; } constexpr EepParam EepParam::strech1(type data) { - return {58, 2, 2, 254, EepParam::checkInvalidEvenRange, data}; + return {58, 2, 2, 254, EepParam::checkValidEvenRange, data}; } constexpr EepParam EepParam::strech2(type data) { - return {60, 2, 2, 254, EepParam::checkInvalidEvenRange, data}; + return {60, 2, 2, 254, EepParam::checkValidEvenRange, data}; } constexpr EepParam EepParam::strech3(type data) { - return {62, 2, 2, 254, EepParam::checkInvalidEvenRange, data}; + return {62, 2, 2, 254, EepParam::checkValidEvenRange, data}; } constexpr EepParam EepParam::newEepParam(const EepParam& paramType, type data) { @@ -187,7 +213,7 @@ namespace ics { size_type length, type min, type max, - InvalidChecker setFunc, + ValidChecker setFunc, type data) : offset(offset), length(length), @@ -197,30 +223,30 @@ namespace ics { data(setFunc(data, min, max)) // throw std::invalid_argument, std::out_of_range {} - constexpr EepParam::type EepParam::checkInvalidRange(type input, type min, type max) { - return ics::checkInvalidRange(input, min, max); + constexpr EepParam::type EepParam::checkValidRange(type input, type min, type max) { + return ics::checkValidRange(input, min, max); } - constexpr EepParam::type EepParam::checkInvalidEvenRange(type input, type min, type max) { + constexpr EepParam::type EepParam::checkValidEvenRange(type input, type min, type max) { return input % 2 ? throw std::out_of_range {"Must even value"} : - checkInvalidRange(input, min, max); // throw std::out_of_range + checkValidRange(input, min, max); // throw std::out_of_range } - constexpr EepParam::type EepParam::checkInvalidFlag(type input, type, type) { + constexpr EepParam::type EepParam::checkValidFlag(type input, type, type) { return !(input & 0x04) ? throw std::invalid_argument {"Eepparam(flag): Must up bits 0x04"} : ~(input | ~0x60) ? throw std::invalid_argument {"Eepparam(flag): Must down bits 0x60"} : input; } - constexpr EepParam::type EepParam::checkInvalidBaudrate(type input, type, type) { + constexpr EepParam::type EepParam::checkValidBaudrate(type input, type, type) { return input == Baudrate::RATE115200().get() ? input : //input == Baudrate::RATE625000().get() ? input : //input == Baudrate::RATE1250000().get() ? input : throw std::invalid_argument {"baudrate not exist"}; } - constexpr EepParam::type EepParam::checkInvalidOffset(type input, type min, type max) { + constexpr EepParam::type EepParam::checkValidOffset(type input, type min, type max) { return input < max ? input : // this min < 0; min value is 0 min < input ? input : // this min < 0; input must is bigger than min. throw std::out_of_range {"Eeprom(offset): range over"}; // min < input < max is failed diff --git a/include/ics3/eeprom.hpp b/include/ics3/eeprom.hpp index 8661932..5142943 100644 --- a/include/ics3/eeprom.hpp +++ b/include/ics3/eeprom.hpp @@ -1,3 +1,29 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef LIBICS3_ICS3_EEPROM_H_ #define LIBICS3_ICS3_EEPROM_H_ diff --git a/include/ics3/ics b/include/ics3/ics index 194bc9e..29f448d 100644 --- a/include/ics3/ics +++ b/include/ics3/ics @@ -1,3 +1,29 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef LIBICS3_ICS3_ICS_H_ #define LIBICS3_ICS3_ICS_H_ diff --git a/include/ics3/ics3.hpp b/include/ics3/ics3.hpp index 7ba8392..f3b7cfa 100644 --- a/include/ics3/ics3.hpp +++ b/include/ics3/ics3.hpp @@ -1,11 +1,37 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef LIBICS3_ICS3_ICS3_H_ #define LIBICS3_ICS3_ICS3_H_ #include"ics3/angle.hpp" #include"ics3/baudrate.hpp" -#include #include +#include namespace ics { // Forward declaration diff --git a/include/ics3/id.hpp b/include/ics3/id.hpp index f9650a0..37b3d18 100644 --- a/include/ics3/id.hpp +++ b/include/ics3/id.hpp @@ -1,3 +1,29 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef LIBICS3_ICS3_ID_H_ #define LIBICS3_ICS3_ID_H_ diff --git a/include/ics3/parameter.hpp b/include/ics3/parameter.hpp index 8f01289..3e868c1 100644 --- a/include/ics3/parameter.hpp +++ b/include/ics3/parameter.hpp @@ -1,3 +1,29 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef LIBICS3_ICS3_PARAMETER_H_ #define LIBICS3_ICS3_PARAMETER_H_ @@ -56,7 +82,7 @@ namespace ics { } inline void Parameter::set(type input) { - data = checkInvalidRange(input, min, max); + data = checkValidRange(input, min, max); } inline Parameter& Parameter::operator=(type rhs) { @@ -72,7 +98,7 @@ namespace ics { : sc {sc}, min {min}, max {max}, - data {checkInvalidRange(defaultData, min, max)} + data {checkValidRange(defaultData, min, max)} {} } diff --git a/script/setup.sh b/script/setup.sh index 916fe9a..1cd0b17 100755 --- a/script/setup.sh +++ b/script/setup.sh @@ -1,3 +1,70 @@ +#!/bin/sh + +# BSD 2-Clause License +# +# Copyright (c) 2016, Doi Yusuke +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +invalidPID(){ + [ $1 -lt 1 ] && return 0 + [ $1 -lt 3 ] && return 1 + [ $1 -lt 6 ] && return 0 + [ $1 -lt 9 ] && return 1 + return 0 +} +if [ $# -gt 0 ]; then + expr $1 + 1 > /dev/null 2>&1 + inputCheck=$? +else + inputCheck=5 +fi +if [ $inputCheck -gt 1 ]; then + echo "Please select your device" + echo "1. ICS USB ADAPTER" + echo "2. SERIAL USB ADAPTER" + echo "3~5: nothing" + echo "6. ICS USB ADAPTER HS" + echo "7. SERIAL USB ADAPTER HS" + echo "8. DUAl USB ADAPTER HS" + read onePID + expr $onePID + 1 > /dev/null 2>&1 + INTCHECK=$? + if [ $INTCHECK -gt 1 ]; then + echo "Invalid argument" + return 1 +fi +else + onePID=$1 +fi +if invalidPID $onePID; then + echo "Out of range" + return 1 +fi +sudo modprobe ftdi-sio +sudo chmod 666 /sys/bus/usb-serial/drivers/ftdi_sio/new_id +echo 165c 000$onePID > /sys/bus/usb-serial/drivers/ftdi_sio/new_id +echo "ttyUSB{x} created : {x} is number." invalidPID(){ [ $1 -lt 1 ] && return 0 [ $1 -lt 3 ] && return 1 diff --git a/src/core.cpp b/src/core.cpp index f114a9e..6244ae1 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -1,11 +1,37 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #include"core.hpp" #include -#include +#include // for error massage +#include // for cashe +#include // for memset #include // for open FLAGS #include // for tty checks -#include // for memset -#include // for cashe ics::Core::Core(const std::string& path, speed_t baudrate) : fd {open(path.c_str(), O_RDWR | O_NOCTTY)}, @@ -18,7 +44,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(); // forward reference + auto newTio = getTermios(); // forward reference if (cfsetispeed(&newTio, baudrate) < 0) throw std::runtime_error {"Cannot set baudrate"}; if (cfsetospeed(&newTio, baudrate) < 0) @@ -44,10 +70,12 @@ ics::Core::Core(Core&& rhs) noexcept } ics::Core& ics::Core::operator=(Core&& rhs) noexcept { - closeThis(); - fd = rhs.fd; - oldTio = rhs.oldTio; - rhs.fd = -1; + if (fd != rhs.fd) { + closeThis(); + fd = rhs.fd; + oldTio = rhs.oldTio; + rhs.fd = -1; + } return *this; } @@ -66,7 +94,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 +110,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; @@ -94,7 +122,7 @@ void ics::Core::communicateID(const IDContainerTx& tx, IDContainerRx& rx) { if ((tx[0] & 0xE0) != (*receive & 0xE0)) throw std::runtime_error {"Receive failed: invalid target data"}; } -void ics::Core::closeThis() noexcept { +void ics::Core::closeThis() const noexcept { tcsetattr(fd, TCSANOW, &oldTio); close(fd); } diff --git a/src/ics3.cpp b/src/ics3.cpp index 864b031..dc0a5cb 100644 --- a/src/ics3.cpp +++ b/src/ics3.cpp @@ -1,20 +1,46 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #include"ics3/ics3.hpp" #include"core.hpp" #include"ics3/eeprom.hpp" -#include"ics3/parameter.hpp" #include"ics3/id.hpp" +#include"ics3/parameter.hpp" static inline ics::Angle::rawType getReceiveAngle(const ics::Core::Container& rx) noexcept { return (rx[4] << 7) | rx[5]; } -static inline ics::Core::value_type getCmd(const ics::Core::value_type head, const ics::ID& id) { +static inline ics::Core::value_type getCmd(const ics::Core::value_type head, const ics::ID& id) noexcept { return head | id.get(); } ics::ICS3::ICS3(const std::string& path, const Baudrate& baudrate) -: core {Core::getCore(path, baudrate.getSpeed())} +: core {Core::getCore(path, baudrate.getSpeed())} // throw std::invalid_argument, std::runtime_error {} ics::Angle ics::ICS3::move(const ID& id, Angle angle) { @@ -29,8 +55,8 @@ ics::Angle ics::ICS3::move(const ID& id, Angle angle) { } ics::Angle ics::ICS3::free(const ID& id, Angle unit) { - static Core::Container tx(3), rx(6); // cache for runtime speed - tx[0] = getCmd(0x80, id); // tx[1] == tx[2] == 0 + const Core::Container tx {getCmd(0x80, id), 0x00, 0x00}; + Core::Container rx(6); core->communicate(tx, rx); // throw std::runtime_error unit.rawData = getReceiveAngle(rx); // avoid invalid check. need friend return unit; diff --git a/src/test.cpp b/src/test.cpp index e995fa7..1d146e9 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -1,3 +1,29 @@ +/* BSD 2-Clause License + +Copyright (c) 2016, Doi Yusuke +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #include "ics3/ics" #include