From 23d7318e0b947b1f6c567733d6c69fc4ae5fa739 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 16 Oct 2016 12:34:12 +0200 Subject: [PATCH] formatting --- src/lib/ebus/contrib/contrib.cpp | 52 +++--- src/lib/ebus/contrib/contrib.h | 70 ++++---- src/lib/ebus/contrib/tem.cpp | 276 +++++++++++++++---------------- src/lib/ebus/contrib/tem.h | 148 ++++++++--------- 4 files changed, 273 insertions(+), 273 deletions(-) diff --git a/src/lib/ebus/contrib/contrib.cpp b/src/lib/ebus/contrib/contrib.cpp index 1cab1dd6..5835e56b 100644 --- a/src/lib/ebus/contrib/contrib.cpp +++ b/src/lib/ebus/contrib/contrib.cpp @@ -1,26 +1,26 @@ -/* - * ebusd - daemon for communication with eBUS heating systems. - * Copyright (C) 2016 John Baier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "tem.h" - -using namespace std; - -bool libebus_contrib_register() { - contrib_tem_register(); - return true; -} +/* + * ebusd - daemon for communication with eBUS heating systems. + * Copyright (C) 2016 John Baier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "tem.h" + +using namespace std; + +bool libebus_contrib_register() { + contrib_tem_register(); + return true; +} diff --git a/src/lib/ebus/contrib/contrib.h b/src/lib/ebus/contrib/contrib.h index 6bf8c7ee..a7dc4d1b 100644 --- a/src/lib/ebus/contrib/contrib.h +++ b/src/lib/ebus/contrib/contrib.h @@ -1,35 +1,35 @@ -/* - * ebusd - daemon for communication with eBUS heating systems. - * Copyright (C) 2016 John Baier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBEBUS_CONTRIB_H_ -#define LIBEBUS_CONTRIB_H_ - -/** @file contrib.h - * Contributed sources that may be excluded from regular builds. - * configure switch: --without-contrib - */ - -using namespace std; - -/** - * Registration function that is called once during initialization. - * @return true if registration was successful. - */ -bool libebus_contrib_register(); - -#endif // LIBEBUS_CONTRIB_H_ +/* + * ebusd - daemon for communication with eBUS heating systems. + * Copyright (C) 2016 John Baier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LIBEBUS_CONTRIB_H_ +#define LIBEBUS_CONTRIB_H_ + +/** @file contrib.h + * Contributed sources that may be excluded from regular builds. + * configure switch: --without-contrib + */ + +using namespace std; + +/** + * Registration function that is called once during initialization. + * @return true if registration was successful. + */ +bool libebus_contrib_register(); + +#endif // LIBEBUS_CONTRIB_H_ diff --git a/src/lib/ebus/contrib/tem.cpp b/src/lib/ebus/contrib/tem.cpp index d384c9da..5c45da1c 100644 --- a/src/lib/ebus/contrib/tem.cpp +++ b/src/lib/ebus/contrib/tem.cpp @@ -1,138 +1,138 @@ -/* - * ebusd - daemon for communication with eBUS heating systems. - * Copyright (C) 2016 John Baier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "datatype.h" -#include "tem.h" -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -void contrib_tem_register() { - DataTypeList::getInstance()->add(new TemParamDataType("TEM_P")); -} - -result_t TemParamDataType::derive(int divisor, unsigned char bitCount, NumberDataType* &derived) -{ - if (divisor == 0) { - divisor = 1; - } - if (divisor == 1 && bitCount == 16) { - derived = this; - return RESULT_OK; - } - return RESULT_ERR_INVALID_ARG; -} - -result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster, - const unsigned char offset, const unsigned char length, - ostringstream& output, OutputFormat outputFormat) -{ - unsigned int value = 0; - - result_t result = readRawValue(input, offset, length, value); - if (result != RESULT_OK) { - return result; - } - - if (value == m_replacement) { - if (outputFormat & OF_JSON) { - output << "null"; - } else { - output << NULL_VALUE; - } - return RESULT_OK; - } - int grp = 0, num = 0; - if (isMaster) { - grp = (value & 0x1f); // grp in bits 0...5 - num = ((value >> 8) & 0x7f); // num in bits 8...13 - } else { - grp = ((value >> 7) & 0x1f); // grp in bits 7...11 - num = (value & 0x7f); // num in bits 0...6 - } - if (outputFormat & OF_JSON) { - output << '"'; - } - output << setfill('0') << setw(2) << dec << static_cast(grp) << '-' << setw(3) << static_cast(num); - if (outputFormat & OF_JSON) { - output << '"'; - } - output << setfill(' ') << setw(0); // reset - return RESULT_OK; -} - -result_t TemParamDataType::writeSymbols(istringstream& input, - const unsigned char offset, const unsigned char length, - SymbolString& output, const bool isMaster, unsigned char* usedLength) -{ - unsigned int value; - int grp, num; - string token; - - const char* str = input.str().c_str(); - if (strcasecmp(str, NULL_VALUE) == 0) { - value = m_replacement; // replacement value - } else { - if (input.eof() || !getline(input, token, '-')) { - return RESULT_ERR_EOF; // incomplete - } - str = token.c_str(); - if (str == NULL || *str == 0) { - return RESULT_ERR_EOF; // input too short - } - char* strEnd = NULL; - grp = (unsigned int)strtoul(str, &strEnd, 10); - if (strEnd == NULL || strEnd == str || *strEnd != 0) { - return RESULT_ERR_INVALID_NUM; // invalid value - } - if (input.eof() || !getline(input, token, '-')) { - return RESULT_ERR_EOF; // incomplete - } - str = token.c_str(); - if (str == NULL || *str == 0) { - return RESULT_ERR_EOF; // input too short - } - strEnd = NULL; - num = (unsigned int)strtoul(str, &strEnd, 10); - if (strEnd == NULL || strEnd == str || *strEnd != 0) { - return RESULT_ERR_INVALID_NUM; // invalid value - } - if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) { - return RESULT_ERR_OUT_OF_RANGE; // value out of range - } - if (isMaster) { - value = grp | (num<<8); // grp in bits 0...5, num in bits 8...13 - } else { - value = (grp<<7) | num; // grp in bits 7...11, num in bits 0...6 - } - } - if (value < getMinValue() || value > getMaxValue()) { - return RESULT_ERR_OUT_OF_RANGE; // value out of range - } - return writeRawValue(value, offset, length, output, usedLength); -} +/* + * ebusd - daemon for communication with eBUS heating systems. + * Copyright (C) 2016 John Baier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "datatype.h" +#include "tem.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void contrib_tem_register() { + DataTypeList::getInstance()->add(new TemParamDataType("TEM_P")); +} + +result_t TemParamDataType::derive(int divisor, unsigned char bitCount, NumberDataType* &derived) +{ + if (divisor == 0) { + divisor = 1; + } + if (divisor == 1 && bitCount == 16) { + derived = this; + return RESULT_OK; + } + return RESULT_ERR_INVALID_ARG; +} + +result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster, + const unsigned char offset, const unsigned char length, + ostringstream& output, OutputFormat outputFormat) +{ + unsigned int value = 0; + + result_t result = readRawValue(input, offset, length, value); + if (result != RESULT_OK) { + return result; + } + + if (value == m_replacement) { + if (outputFormat & OF_JSON) { + output << "null"; + } else { + output << NULL_VALUE; + } + return RESULT_OK; + } + int grp = 0, num = 0; + if (isMaster) { + grp = (value & 0x1f); // grp in bits 0...5 + num = ((value >> 8) & 0x7f); // num in bits 8...13 + } else { + grp = ((value >> 7) & 0x1f); // grp in bits 7...11 + num = (value & 0x7f); // num in bits 0...6 + } + if (outputFormat & OF_JSON) { + output << '"'; + } + output << setfill('0') << setw(2) << dec << static_cast(grp) << '-' << setw(3) << static_cast(num); + if (outputFormat & OF_JSON) { + output << '"'; + } + output << setfill(' ') << setw(0); // reset + return RESULT_OK; +} + +result_t TemParamDataType::writeSymbols(istringstream& input, + const unsigned char offset, const unsigned char length, + SymbolString& output, const bool isMaster, unsigned char* usedLength) +{ + unsigned int value; + int grp, num; + string token; + + const char* str = input.str().c_str(); + if (strcasecmp(str, NULL_VALUE) == 0) { + value = m_replacement; // replacement value + } else { + if (input.eof() || !getline(input, token, '-')) { + return RESULT_ERR_EOF; // incomplete + } + str = token.c_str(); + if (str == NULL || *str == 0) { + return RESULT_ERR_EOF; // input too short + } + char* strEnd = NULL; + grp = (unsigned int)strtoul(str, &strEnd, 10); + if (strEnd == NULL || strEnd == str || *strEnd != 0) { + return RESULT_ERR_INVALID_NUM; // invalid value + } + if (input.eof() || !getline(input, token, '-')) { + return RESULT_ERR_EOF; // incomplete + } + str = token.c_str(); + if (str == NULL || *str == 0) { + return RESULT_ERR_EOF; // input too short + } + strEnd = NULL; + num = (unsigned int)strtoul(str, &strEnd, 10); + if (strEnd == NULL || strEnd == str || *strEnd != 0) { + return RESULT_ERR_INVALID_NUM; // invalid value + } + if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) { + return RESULT_ERR_OUT_OF_RANGE; // value out of range + } + if (isMaster) { + value = grp | (num<<8); // grp in bits 0...5, num in bits 8...13 + } else { + value = (grp<<7) | num; // grp in bits 7...11, num in bits 0...6 + } + } + if (value < getMinValue() || value > getMaxValue()) { + return RESULT_ERR_OUT_OF_RANGE; // value out of range + } + return writeRawValue(value, offset, length, output, usedLength); +} diff --git a/src/lib/ebus/contrib/tem.h b/src/lib/ebus/contrib/tem.h index 789c7e4b..e9026f61 100644 --- a/src/lib/ebus/contrib/tem.h +++ b/src/lib/ebus/contrib/tem.h @@ -1,74 +1,74 @@ -/* - * ebusd - daemon for communication with eBUS heating systems. - * Copyright (C) 2016 John Baier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBEBUS_CONTRIB_TEM_H_ -#define LIBEBUS_CONTRIB_TEM_H_ - -#include "symbol.h" -#include "result.h" -#include "datatype.h" -#include -#include -#include -#include -#include -#include -#include - -/** @file tem.h - * Contributed data types for TEM devices not part of regular releases. - */ - -using namespace std; - -/** - * A special variant of @a NumberDataType for TEM/Dungs ParamID in master/slave - * data. - */ -class TemParamDataType : public NumberDataType -{ -public: - - /** - * Constructs a new instance. - * @param id the type identifier. - */ - TemParamDataType(const string id) - : NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0) {} - - // @copydoc - virtual result_t derive(int divisor, unsigned char bitCount, NumberDataType* &derived); - - // @copydoc - virtual result_t readSymbols(SymbolString& input, const bool isMaster, - const unsigned char offset, const unsigned char length, - ostringstream& output, OutputFormat outputFormat); - - // @copydoc - virtual result_t writeSymbols(istringstream& input, - const unsigned char offset, const unsigned char length, - SymbolString& output, const bool isMaster, unsigned char* usedLength); - -}; - -/** - * Registration function to be called once during initialization. - */ -void contrib_tem_register(); - -#endif // LIBEBUS_CONTRIB_TEM_H_ +/* + * ebusd - daemon for communication with eBUS heating systems. + * Copyright (C) 2016 John Baier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LIBEBUS_CONTRIB_TEM_H_ +#define LIBEBUS_CONTRIB_TEM_H_ + +#include "symbol.h" +#include "result.h" +#include "datatype.h" +#include +#include +#include +#include +#include +#include +#include + +/** @file tem.h + * Contributed data types for TEM devices not part of regular releases. + */ + +using namespace std; + +/** + * A special variant of @a NumberDataType for TEM/Dungs ParamID in master/slave + * data. + */ +class TemParamDataType : public NumberDataType +{ +public: + + /** + * Constructs a new instance. + * @param id the type identifier. + */ + TemParamDataType(const string id) + : NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0) {} + + // @copydoc + virtual result_t derive(int divisor, unsigned char bitCount, NumberDataType* &derived); + + // @copydoc + virtual result_t readSymbols(SymbolString& input, const bool isMaster, + const unsigned char offset, const unsigned char length, + ostringstream& output, OutputFormat outputFormat); + + // @copydoc + virtual result_t writeSymbols(istringstream& input, + const unsigned char offset, const unsigned char length, + SymbolString& output, const bool isMaster, unsigned char* usedLength); + +}; + +/** + * Registration function to be called once during initialization. + */ +void contrib_tem_register(); + +#endif // LIBEBUS_CONTRIB_TEM_H_