Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #14 from forno/update-v1.2.3
Browse files Browse the repository at this point in the history
Update v1.2.3 with some optimization
  • Loading branch information
forno authored Nov 4, 2016
2 parents 9444e65 + 25a000d commit 95b4ce5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
45 changes: 23 additions & 22 deletions include/ics3/eepparam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace ics {
using type = uint16_t;
using size_type = std::size_t;
using TargetContainer = std::array<uint8_t, 64>;
using InvalidChecker = type (&)(type, type, type);
enum Flag : type {
REVERSE = 0x01,
FREE = 0x02,
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 95b4ce5

Please sign in to comment.