formatting

This commit is contained in:
john30
2016-10-16 12:34:12 +02:00
parent 29bac4b0b9
commit 23d7318e0b
4 changed files with 273 additions and 273 deletions
+26 -26
View File
@@ -1,26 +1,26 @@
/* /*
* ebusd - daemon for communication with eBUS heating systems. * ebusd - daemon for communication with eBUS heating systems.
* Copyright (C) 2016 John Baier <ebusd@ebusd.eu> * Copyright (C) 2016 John Baier <ebusd@ebusd.eu>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "tem.h" #include "tem.h"
using namespace std; using namespace std;
bool libebus_contrib_register() { bool libebus_contrib_register() {
contrib_tem_register(); contrib_tem_register();
return true; return true;
} }
+35 -35
View File
@@ -1,35 +1,35 @@
/* /*
* ebusd - daemon for communication with eBUS heating systems. * ebusd - daemon for communication with eBUS heating systems.
* Copyright (C) 2016 John Baier <ebusd@ebusd.eu> * Copyright (C) 2016 John Baier <ebusd@ebusd.eu>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LIBEBUS_CONTRIB_H_ #ifndef LIBEBUS_CONTRIB_H_
#define LIBEBUS_CONTRIB_H_ #define LIBEBUS_CONTRIB_H_
/** @file contrib.h /** @file contrib.h
* Contributed sources that may be excluded from regular builds. * Contributed sources that may be excluded from regular builds.
* configure switch: --without-contrib * configure switch: --without-contrib
*/ */
using namespace std; using namespace std;
/** /**
* Registration function that is called once during initialization. * Registration function that is called once during initialization.
* @return true if registration was successful. * @return true if registration was successful.
*/ */
bool libebus_contrib_register(); bool libebus_contrib_register();
#endif // LIBEBUS_CONTRIB_H_ #endif // LIBEBUS_CONTRIB_H_
+138 -138
View File
@@ -1,138 +1,138 @@
/* /*
* ebusd - daemon for communication with eBUS heating systems. * ebusd - daemon for communication with eBUS heating systems.
* Copyright (C) 2016 John Baier <ebusd@ebusd.eu> * Copyright (C) 2016 John Baier <ebusd@ebusd.eu>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
#include "datatype.h" #include "datatype.h"
#include "tem.h" #include "tem.h"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <vector> #include <vector>
#include <cstring> #include <cstring>
#include <math.h> #include <math.h>
#include <typeinfo> #include <typeinfo>
using namespace std; using namespace std;
void contrib_tem_register() { void contrib_tem_register() {
DataTypeList::getInstance()->add(new TemParamDataType("TEM_P")); DataTypeList::getInstance()->add(new TemParamDataType("TEM_P"));
} }
result_t TemParamDataType::derive(int divisor, unsigned char bitCount, NumberDataType* &derived) result_t TemParamDataType::derive(int divisor, unsigned char bitCount, NumberDataType* &derived)
{ {
if (divisor == 0) { if (divisor == 0) {
divisor = 1; divisor = 1;
} }
if (divisor == 1 && bitCount == 16) { if (divisor == 1 && bitCount == 16) {
derived = this; derived = this;
return RESULT_OK; return RESULT_OK;
} }
return RESULT_ERR_INVALID_ARG; return RESULT_ERR_INVALID_ARG;
} }
result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster, result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length, const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat) ostringstream& output, OutputFormat outputFormat)
{ {
unsigned int value = 0; unsigned int value = 0;
result_t result = readRawValue(input, offset, length, value); result_t result = readRawValue(input, offset, length, value);
if (result != RESULT_OK) { if (result != RESULT_OK) {
return result; return result;
} }
if (value == m_replacement) { if (value == m_replacement) {
if (outputFormat & OF_JSON) { if (outputFormat & OF_JSON) {
output << "null"; output << "null";
} else { } else {
output << NULL_VALUE; output << NULL_VALUE;
} }
return RESULT_OK; return RESULT_OK;
} }
int grp = 0, num = 0; int grp = 0, num = 0;
if (isMaster) { if (isMaster) {
grp = (value & 0x1f); // grp in bits 0...5 grp = (value & 0x1f); // grp in bits 0...5
num = ((value >> 8) & 0x7f); // num in bits 8...13 num = ((value >> 8) & 0x7f); // num in bits 8...13
} else { } else {
grp = ((value >> 7) & 0x1f); // grp in bits 7...11 grp = ((value >> 7) & 0x1f); // grp in bits 7...11
num = (value & 0x7f); // num in bits 0...6 num = (value & 0x7f); // num in bits 0...6
} }
if (outputFormat & OF_JSON) { if (outputFormat & OF_JSON) {
output << '"'; output << '"';
} }
output << setfill('0') << setw(2) << dec << static_cast<int>(grp) << '-' << setw(3) << static_cast<int>(num); output << setfill('0') << setw(2) << dec << static_cast<int>(grp) << '-' << setw(3) << static_cast<int>(num);
if (outputFormat & OF_JSON) { if (outputFormat & OF_JSON) {
output << '"'; output << '"';
} }
output << setfill(' ') << setw(0); // reset output << setfill(' ') << setw(0); // reset
return RESULT_OK; return RESULT_OK;
} }
result_t TemParamDataType::writeSymbols(istringstream& input, result_t TemParamDataType::writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length, const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) SymbolString& output, const bool isMaster, unsigned char* usedLength)
{ {
unsigned int value; unsigned int value;
int grp, num; int grp, num;
string token; string token;
const char* str = input.str().c_str(); const char* str = input.str().c_str();
if (strcasecmp(str, NULL_VALUE) == 0) { if (strcasecmp(str, NULL_VALUE) == 0) {
value = m_replacement; // replacement value value = m_replacement; // replacement value
} else { } else {
if (input.eof() || !getline(input, token, '-')) { if (input.eof() || !getline(input, token, '-')) {
return RESULT_ERR_EOF; // incomplete return RESULT_ERR_EOF; // incomplete
} }
str = token.c_str(); str = token.c_str();
if (str == NULL || *str == 0) { if (str == NULL || *str == 0) {
return RESULT_ERR_EOF; // input too short return RESULT_ERR_EOF; // input too short
} }
char* strEnd = NULL; char* strEnd = NULL;
grp = (unsigned int)strtoul(str, &strEnd, 10); grp = (unsigned int)strtoul(str, &strEnd, 10);
if (strEnd == NULL || strEnd == str || *strEnd != 0) { if (strEnd == NULL || strEnd == str || *strEnd != 0) {
return RESULT_ERR_INVALID_NUM; // invalid value return RESULT_ERR_INVALID_NUM; // invalid value
} }
if (input.eof() || !getline(input, token, '-')) { if (input.eof() || !getline(input, token, '-')) {
return RESULT_ERR_EOF; // incomplete return RESULT_ERR_EOF; // incomplete
} }
str = token.c_str(); str = token.c_str();
if (str == NULL || *str == 0) { if (str == NULL || *str == 0) {
return RESULT_ERR_EOF; // input too short return RESULT_ERR_EOF; // input too short
} }
strEnd = NULL; strEnd = NULL;
num = (unsigned int)strtoul(str, &strEnd, 10); num = (unsigned int)strtoul(str, &strEnd, 10);
if (strEnd == NULL || strEnd == str || *strEnd != 0) { if (strEnd == NULL || strEnd == str || *strEnd != 0) {
return RESULT_ERR_INVALID_NUM; // invalid value return RESULT_ERR_INVALID_NUM; // invalid value
} }
if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) { if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range return RESULT_ERR_OUT_OF_RANGE; // value out of range
} }
if (isMaster) { if (isMaster) {
value = grp | (num<<8); // grp in bits 0...5, num in bits 8...13 value = grp | (num<<8); // grp in bits 0...5, num in bits 8...13
} else { } else {
value = (grp<<7) | num; // grp in bits 7...11, num in bits 0...6 value = (grp<<7) | num; // grp in bits 7...11, num in bits 0...6
} }
} }
if (value < getMinValue() || value > getMaxValue()) { if (value < getMinValue() || value > getMaxValue()) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range return RESULT_ERR_OUT_OF_RANGE; // value out of range
} }
return writeRawValue(value, offset, length, output, usedLength); return writeRawValue(value, offset, length, output, usedLength);
} }
+74 -74
View File
@@ -1,74 +1,74 @@
/* /*
* ebusd - daemon for communication with eBUS heating systems. * ebusd - daemon for communication with eBUS heating systems.
* Copyright (C) 2016 John Baier <ebusd@ebusd.eu> * Copyright (C) 2016 John Baier <ebusd@ebusd.eu>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LIBEBUS_CONTRIB_TEM_H_ #ifndef LIBEBUS_CONTRIB_TEM_H_
#define LIBEBUS_CONTRIB_TEM_H_ #define LIBEBUS_CONTRIB_TEM_H_
#include "symbol.h" #include "symbol.h"
#include "result.h" #include "result.h"
#include "datatype.h" #include "datatype.h"
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include <list> #include <list>
#include <map> #include <map>
/** @file tem.h /** @file tem.h
* Contributed data types for TEM devices not part of regular releases. * Contributed data types for TEM devices not part of regular releases.
*/ */
using namespace std; using namespace std;
/** /**
* A special variant of @a NumberDataType for TEM/Dungs ParamID in master/slave * A special variant of @a NumberDataType for TEM/Dungs ParamID in master/slave
* data. * data.
*/ */
class TemParamDataType : public NumberDataType class TemParamDataType : public NumberDataType
{ {
public: public:
/** /**
* Constructs a new instance. * Constructs a new instance.
* @param id the type identifier. * @param id the type identifier.
*/ */
TemParamDataType(const string id) TemParamDataType(const string id)
: NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0) {} : NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0) {}
// @copydoc // @copydoc
virtual result_t derive(int divisor, unsigned char bitCount, NumberDataType* &derived); virtual result_t derive(int divisor, unsigned char bitCount, NumberDataType* &derived);
// @copydoc // @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster, virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length, const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat); ostringstream& output, OutputFormat outputFormat);
// @copydoc // @copydoc
virtual result_t writeSymbols(istringstream& input, virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length, const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength); SymbolString& output, const bool isMaster, unsigned char* usedLength);
}; };
/** /**
* Registration function to be called once during initialization. * Registration function to be called once during initialization.
*/ */
void contrib_tem_register(); void contrib_tem_register();
#endif // LIBEBUS_CONTRIB_TEM_H_ #endif // LIBEBUS_CONTRIB_TEM_H_