file struturce changed.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
AM_CXXFLAGS = -fpic \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-I$(top_srcdir)/src/lib/ebus
|
||||
|
||||
noinst_PROGRAMS = test_port \
|
||||
test_symbol \
|
||||
test_data \
|
||||
test_bus \
|
||||
test_commands \
|
||||
test_configfile \
|
||||
test_decode \
|
||||
test_encode
|
||||
|
||||
test_port_SOURCES = test_port.cpp
|
||||
test_port_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a
|
||||
|
||||
test_symbol_SOURCES = test_symbol.cpp
|
||||
test_symbol_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a
|
||||
|
||||
test_data_SOURCES = test_data.cpp
|
||||
test_data_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a
|
||||
|
||||
test_bus_SOURCES = test_bus.cpp
|
||||
test_bus_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a
|
||||
|
||||
test_commands_SOURCES = test_commands.cpp
|
||||
test_commands_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a
|
||||
|
||||
test_configfile_SOURCES = test_configfile.cpp
|
||||
test_configfile_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a
|
||||
|
||||
test_decode_SOURCES = test_decode.cpp
|
||||
test_decode_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a
|
||||
|
||||
test_encode_SOURCES = test_encode.cpp
|
||||
test_encode_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a
|
||||
|
||||
distclean-local:
|
||||
-rm -f Makefile.in
|
||||
-rm -rf .libs
|
||||
@@ -0,0 +1,4 @@
|
||||
# type;class;cmd;comment;QQ;ZZ;PBSB;NN;D1D2D3;elements;sub;part;position;datatype;factor;unit;valid;comment;sub;part;position;datatype;factor;unit;valid;comment;sub;part;position;datatype;factor;unit;valid;comment;sub;part;position;datatype;factor;unit;valid;comment
|
||||
c;broad;date_time_temp;Datum, Uhrzeit und Aussentempertur;;FE;0700;9;-;4;temp;md;1,2;d2b;1.0;°C;-;Temperatur;day;md;8;bdy;-;-;-;Wochentag;date;md;6,7,9;bda;-;-;-;Datum;time;md;5,4,3;bti;-;-;-;Uhrzeit
|
||||
g;ci;Password;Kennwort;;15;B509;3;0D2C00;4;pin1;sd;1;uch;-;-;-;Pin 1;pin2;sd;2;uch;-;-;-;Pin 2;pin3;sd;3;uch;-;-;-;Pin 3;pin4;sd;4;uch;-;-;-;Pin 4
|
||||
s;vwxmk;DesiredTemp;Solltemperatur;;50;B509;4;0E3200;1;-;sd;1;d1c;1.0;°C;-;-;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
|
||||
*
|
||||
* This file is part of ebusd.
|
||||
*
|
||||
* ebusd 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.
|
||||
*
|
||||
* ebusd 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 ebusd. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include "bus.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace libebus;
|
||||
|
||||
int main ()
|
||||
{
|
||||
Bus bus("/dev/ttyUSB0", true, 15000, "/tmp/dump_bus.bin", 100, false);
|
||||
|
||||
bus.connect();
|
||||
|
||||
if (bus.isConnected() == true)
|
||||
std::cout << "connect successful." << std::endl;
|
||||
|
||||
int cout = 0;
|
||||
|
||||
while (cout++ < 1000) {
|
||||
if (bus.isConnected() == true) {
|
||||
bus.printBytes();
|
||||
} else {
|
||||
sleep(5);
|
||||
bus.connect();
|
||||
|
||||
if (bus.isConnected() == false)
|
||||
std::cout << "can't open /dev/ttyUSB0" << std::endl;
|
||||
else
|
||||
std::cout << "reconnect successful." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
bus.disconnect();
|
||||
|
||||
if (bus.isConnected() == false)
|
||||
std::cout << "disconnect successful." << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
|
||||
*
|
||||
* This file is part of ebusd.
|
||||
*
|
||||
* ebusd 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.
|
||||
*
|
||||
* ebusd 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 ebusd. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include "configfile.h"
|
||||
#include "commands.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using namespace libebus;
|
||||
|
||||
// will be part of cfg csv class
|
||||
void readCSV(std::istream& is, Commands& commands){
|
||||
std::string line;
|
||||
|
||||
// read lines
|
||||
while (std::getline(is, line) != 0) {
|
||||
std::vector<std::string> row;
|
||||
std::string column;
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
|
||||
std::istringstream stream(line);
|
||||
|
||||
// walk through columns
|
||||
while (std::getline(stream, column, ';') != 0) {
|
||||
row.push_back(column);
|
||||
count++;
|
||||
}
|
||||
|
||||
commands.addCommand(row);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Commands* commands = ConfigCommands("test", CSV).getCommands();
|
||||
std::cout << "Commands: " << commands->sizeCmdDB() << std::endl;
|
||||
|
||||
//~ std::string data("g ci password pin1");
|
||||
std::string data("s vwxmk DesiredTemp");
|
||||
|
||||
int index = commands->findCommand(data);
|
||||
std::cout << "found at index: " << index << std::endl;
|
||||
|
||||
// prepare data
|
||||
std::string token;
|
||||
std::istringstream stream(data);
|
||||
std::vector<std::string> cmd;
|
||||
|
||||
// split stream
|
||||
while (std::getline(stream, token, ' ') != 0)
|
||||
cmd.push_back(token);
|
||||
|
||||
//~ Command* command = new Command(index, (*commands)[index], "ff15b509030d2c0035000401000000cf00");
|
||||
Command* command = new Command(index, (*commands)[index], "19.0");
|
||||
|
||||
//~ std::string result = command->calcResult(cmd);
|
||||
std::string result = command->calcData();
|
||||
std::cout << "result: " << result << std::endl;
|
||||
|
||||
delete command;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
|
||||
*
|
||||
* This file is part of ebusd.
|
||||
*
|
||||
* ebusd 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.
|
||||
*
|
||||
* ebusd 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 ebusd. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include "configfile.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using namespace libebus;
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
std::string dir("test");
|
||||
ConfigCommands config(dir, CSV);
|
||||
|
||||
Commands* commands = config.getCommands();
|
||||
|
||||
std::cout << "size: " << commands->sizeCmdDB() << std::endl;
|
||||
|
||||
commands->findCommand("g ci Password");
|
||||
|
||||
std::cout << (*commands)[0][0] << std::endl;
|
||||
|
||||
delete commands;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (C) John Baier 2014 <ebusd@johnm.de>
|
||||
*
|
||||
* This file is part of libebus.
|
||||
*
|
||||
* libebus 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.
|
||||
*
|
||||
* libebus 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 libebus. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include "data.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace libebus;
|
||||
|
||||
int main ()
|
||||
{
|
||||
std::string checks[][4] = {
|
||||
//name;position(s);type;factor;unit;comment
|
||||
// {"temp;1;d2b;;°C;Aussentemperatur","temp=18.004 °C [Aussentemperatur]","10fe070009019258042126100714cc", "00"},
|
||||
// {"zeit;1;ttm;2;Uhr;","zeit=22:40 Uhr","10feffff0188", "00"},
|
||||
{"x;1-10;hex","53 70 65 69 63 68 65 72 20 20", "10fe07000a53706569636865722020", "00"},
|
||||
{"x;1;bti","21:04:58","10fe070009580421", "00"},
|
||||
{"x;1;bda","26.10.2014","10fe07000926100714", "00"},
|
||||
{"x;1-3;bda","26.10.2014","10fe070003261014", "00"},
|
||||
{"x;1;hdy","Sun","10fe07000307", "00"},
|
||||
{"x;1;bdy","Sun","10fe07000306", "00"},
|
||||
{"x;1;d2b","18.004","10fe0700090112", "00"},
|
||||
{"x;1;d2c","288.062","10fe0700090112", "00"},
|
||||
{"x;1;ttm","22:40","10feffff0188", "00"},
|
||||
{"x;1;bcd","26","10feffff0126", "00"},
|
||||
{"x;1;bcd","-","10feffff01ff", "00"},
|
||||
{"x;1;uch","38","10feffff0126", "00"},
|
||||
{"x;1;sch","-90","10feffff01a6", "00"},
|
||||
{"x;1;d1b","-90","10feffff01a6", "00"},
|
||||
{"x;1;d1c","19.500","10feffff0127", "00"},
|
||||
{"x;1;uin","38","10feffff022600", "00"},
|
||||
{"x;1;sin","-90","10feffff02a6ff", "00"},
|
||||
{"x;1;ulg","38","10feffff0426000000", "00"},
|
||||
{"x;1;slg","-90","10feffff04a6ffffff", "00"},
|
||||
{"x;1;flt","-0.090","10feffff02a6ff", "00"},
|
||||
{"x;1-9;str","hallo Du!","10feffff0868616c6c6f20447521", "00"},
|
||||
{"x;1-9;str","hallo Du ","10feffff0868616c6c6f20447520", "00"},
|
||||
{"new;1;uch;1=test,2=high,3=off,4=on","on","10feffff0104", "00"},
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(checks)/sizeof(checks[0]); i++) {
|
||||
std::istringstream isstr(checks[i][0]);
|
||||
std::string expectStr = checks[i][1];
|
||||
SymbolString mstr = SymbolString(checks[i][2], false);
|
||||
SymbolString sstr = SymbolString(checks[i][3], false);
|
||||
std::string item;
|
||||
std::vector<std::string> entries;
|
||||
|
||||
while (std::getline(isstr, item, ';') != 0)
|
||||
entries.push_back(item);
|
||||
|
||||
std::vector<std::string>::iterator it = entries.begin();
|
||||
DataField* field = DataField::create(mstr[1], false, it, entries.end());
|
||||
|
||||
if (field == NULL) {
|
||||
std::cout << "create \"" << checks[i][0] << "\" invalid: null" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "create \"" << checks[i][0] << "\" successful" << std::endl;
|
||||
|
||||
|
||||
std::string gotStr = field->read(mstr, sstr);
|
||||
|
||||
if (strcasecmp(gotStr.c_str(), expectStr.c_str()) == 0)
|
||||
std::cout << "read successful: " << gotStr << std::endl;
|
||||
else
|
||||
std::cout << "read invalid: got " << gotStr
|
||||
<< ", expected " << expectStr << std::endl;
|
||||
|
||||
SymbolString writeMstr = SymbolString(mstr.getDataStr().substr(0, 10), false);
|
||||
SymbolString writeSstr = SymbolString(sstr.getDataStr().substr(0, 2), false);
|
||||
if (field->write(gotStr, writeMstr, writeSstr) == false)
|
||||
std::cout << "write failed" << std::endl;
|
||||
else {
|
||||
if (mstr == writeMstr && sstr == writeSstr)
|
||||
std::cout << "write successful" << std::endl;
|
||||
else {
|
||||
std::cout << "write invalid: ";
|
||||
if (mstr == writeMstr)
|
||||
std::cout << "master OK";
|
||||
else
|
||||
std::cout << "master got " << writeMstr.getDataStr() << ", expected " << mstr.getDataStr();
|
||||
|
||||
if (sstr == writeSstr)
|
||||
std::cout << ", slave OK";
|
||||
else
|
||||
std::cout << ", slave got " << writeSstr.getDataStr() << ", expected " << sstr.getDataStr();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
delete field;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
|
||||
*
|
||||
* This file is part of ebusd.
|
||||
*
|
||||
* ebusd 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.
|
||||
*
|
||||
* ebusd 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 ebusd. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include "decode.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
using namespace libebus;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
Decode* help_dec = NULL;
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
// HEX
|
||||
{
|
||||
const char* hex[] = {"53706569636865722020"};
|
||||
for (size_t i = 0; i < sizeof(hex)/sizeof(hex[0]); i++) {
|
||||
help_dec = new DecodeHEX(hex[i]);
|
||||
std::cout << "DecodeHEX: " << std::setw(20) << hex[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// UCH
|
||||
{
|
||||
const char* uch[] = {"00", "01", "7f", "80", "fe", "ff", "a1"};
|
||||
for (size_t i = 0; i < sizeof(uch)/sizeof(uch[0]); i++) {
|
||||
help_dec = new DecodeUCH(uch[i], "1.0");
|
||||
std::cout << "DecodeUCH: " << std::setw(20) << uch[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// SCH
|
||||
{
|
||||
const char* sch[] = {"00", "01", "7f", "80", "fe", "ff", "a1"};
|
||||
for (size_t i = 0; i < sizeof(sch)/sizeof(sch[0]); i++) {
|
||||
help_dec = new DecodeSCH(sch[i], "1.0");
|
||||
std::cout << "DecodeSCH: " << std::setw(20) << sch[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// UIN
|
||||
{
|
||||
const char* uin[] = {"0000", "0001", "7fff", "8000", "fffe", "ffff", "a1b2"};
|
||||
for (size_t i = 0; i < sizeof(uin)/sizeof(uin[0]); i++) {
|
||||
help_dec = new DecodeUIN(uin[i], "1.0");
|
||||
std::cout << "DecodeUIN: " << std::setw(20) << uin[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// SIN
|
||||
{
|
||||
const char* sin[] = {"0000", "0001", "7fff", "8000", "fffe", "ffff", "a1b2"};
|
||||
for (size_t i = 0; i < sizeof(sin)/sizeof(sin[0]); i++) {
|
||||
help_dec = new DecodeSIN(sin[i], "1.0");
|
||||
std::cout << "DecodeSIN: " << std::setw(20) << sin[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// ULG
|
||||
{
|
||||
const char* ulg[] = {"00000000", "00000001", "7fffffff", "80000000", "fffffffe", "ffffffff", "a1b2c3d4"};
|
||||
for (size_t i = 0; i < sizeof(ulg)/sizeof(ulg[0]); i++) {
|
||||
help_dec = new DecodeULG(ulg[i], "1.0");
|
||||
std::cout << "DecodeULG: " << std::setw(20) << ulg[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// SLG
|
||||
{
|
||||
const char* slg[] = {"00000000", "00000001", "7fffffff", "80000000", "fffffffe", "ffffffff", "a1b2c3d4"};
|
||||
for (size_t i = 0; i < sizeof(slg)/sizeof(slg[0]); i++) {
|
||||
help_dec = new DecodeSLG(slg[i], "1.0");
|
||||
std::cout << "DecodeSLG: " << std::setw(20) << slg[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// FLT
|
||||
{
|
||||
const char* flt[] = {"0000", "081b", "2532", "2689", "0851"};
|
||||
for (size_t i = 0; i < sizeof(flt)/sizeof(flt[0]); i++) {
|
||||
help_dec = new DecodeFLT(flt[i], "1.0");
|
||||
std::cout << "DecodeFLT: " << std::setw(20) << flt[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// STR
|
||||
{
|
||||
const char* str[] = {"53706569636865722020", "5644363030" };
|
||||
for (size_t i = 0; i < sizeof(str)/sizeof(str[0]); i++) {
|
||||
help_dec = new DecodeSTR(str[i]);
|
||||
std::cout << "DecodeSTR: " << std::setw(20) << str[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// BCD
|
||||
{
|
||||
const char* bcd[] = {"00", "01", "02", "03", "12", "99"};
|
||||
for (size_t i = 0; i < sizeof(bcd)/sizeof(bcd[0]); i++) {
|
||||
help_dec = new DecodeBCD(bcd[i], "1.0");
|
||||
std::cout << "DecodeBCD: " << std::setw(20) << bcd[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// D1B
|
||||
{
|
||||
const char* d1b[] = {"00", "01", "7f", "81", "80"};
|
||||
for (size_t i = 0; i < sizeof(d1b)/sizeof(d1b[0]); i++) {
|
||||
help_dec = new DecodeD1B(d1b[i], "1.0");
|
||||
std::cout << "DecodeD1B: " << std::setw(20) << d1b[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// D1C
|
||||
{
|
||||
const char* d1c[] = {"00", "64", "c8"};
|
||||
for (size_t i = 0; i < sizeof(d1c)/sizeof(d1c[0]); i++) {
|
||||
help_dec = new DecodeD1C(d1c[i], "1.0");
|
||||
std::cout << "DecodeD1C: " << std::setw(20) << d1c[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// D2B
|
||||
{
|
||||
const char* d2b[] = {"0000", "0100", "ffff", "00ff", "0080", "0180", "ff7f"};
|
||||
for (size_t i = 0; i < sizeof(d2b)/sizeof(d2b[0]); i++) {
|
||||
help_dec = new DecodeD2B(d2b[i], "1.0");
|
||||
std::cout << "DecodeD2B: " << std::setw(20) << d2b[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// D2C
|
||||
{
|
||||
const char* d2c[] = {"0000", "0100", "ffff", "f0ff", "0080", "0180", "ff7f"};
|
||||
for (size_t i = 0; i < sizeof(d2c)/sizeof(d2c[0]); i++) {
|
||||
help_dec = new DecodeD2C(d2c[i], "1.0");
|
||||
std::cout << "DecodeD2C: " << std::setw(20) << d2c[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// BDA
|
||||
{
|
||||
const char* bda[] = {"171113", "220901"};
|
||||
for (size_t i = 0; i < sizeof(bda)/sizeof(bda[0]); i++) {
|
||||
help_dec = new DecodeBDA(bda[i]);
|
||||
std::cout << "DecodeBDA: " << std::setw(20) << bda[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// HDA
|
||||
{
|
||||
const char* hda[] = {"010101", "1f0c1b"};
|
||||
for (size_t i = 0; i < sizeof(hda)/sizeof(hda[0]); i++) {
|
||||
help_dec = new DecodeHDA(hda[i]);
|
||||
std::cout << "DecodeHDA: " << std::setw(20) << hda[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// BTI
|
||||
{
|
||||
const char* bti[] = {"010101", "174209", "235959"};
|
||||
for (size_t i = 0; i < sizeof(bti)/sizeof(bti[0]); i++) {
|
||||
help_dec = new DecodeBTI(bti[i]);
|
||||
std::cout << "DecodeBTI: " << std::setw(20) << bti[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// HTI
|
||||
{
|
||||
const char* hti[] = {"010101", "112a09", "173b3b"};
|
||||
for (size_t i = 0; i < sizeof(hti)/sizeof(hti[0]); i++) {
|
||||
help_dec = new DecodeHTI(hti[i]);
|
||||
std::cout << "DecodeHTI: " << std::setw(20) << hti[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// BDY
|
||||
{
|
||||
const char* bdy[] = {"01", "03", "06", "07"};
|
||||
for (size_t i = 0; i < sizeof(bdy)/sizeof(bdy[0]); i++) {
|
||||
help_dec = new DecodeBDY(bdy[i]);
|
||||
std::cout << "DecodeBDY: " << std::setw(20) << bdy[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// HDY
|
||||
{
|
||||
const char* hdy[] = {"01", "03", "07", "08"};
|
||||
for (size_t i = 0; i < sizeof(hdy)/sizeof(hdy[0]); i++) {
|
||||
help_dec = new DecodeHDY(hdy[i]);
|
||||
std::cout << "DecodeHDY: " << std::setw(20) << hdy[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// TTM
|
||||
{
|
||||
const char* ttm[] = {"00", "23", "4f", "90"};
|
||||
for (size_t i = 0; i < sizeof(ttm)/sizeof(ttm[0]); i++) {
|
||||
help_dec = new DecodeTTM(ttm[i]);
|
||||
std::cout << "DecodeTTM: " << std::setw(20) << ttm[i] << " = " << help_dec->decode() << std::endl;
|
||||
|
||||
delete help_dec;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
|
||||
*
|
||||
* This file is part of ebusd.
|
||||
*
|
||||
* ebusd 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.
|
||||
*
|
||||
* ebusd 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 ebusd. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include "encode.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
using namespace libebus;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
Encode* help_enc = NULL;
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
// HEX
|
||||
{
|
||||
const char* hex[] = {"53 70 65 69 63 68 65 72 20 20"};
|
||||
for (size_t i = 0; i < sizeof(hex)/sizeof(hex[0]); i++) {
|
||||
help_enc = new EncodeHEX(hex[i]);
|
||||
std::cout << "EncodeHEX: " << std::setw(20) << hex[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// UCH
|
||||
{
|
||||
const char* uch[] = {"0", "1", "127", "128", "254", "255", "161"};
|
||||
for (size_t i = 0; i < sizeof(uch)/sizeof(uch[0]); i++) {
|
||||
help_enc = new EncodeUCH(uch[i], "1.0");
|
||||
std::cout << "EncodeUCH: " << std::setw(20) << uch[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// SCH
|
||||
{
|
||||
const char* sch[] = {"0", "1", "127", "-128", "-2", "-1", "-95"};
|
||||
for (size_t i = 0; i < sizeof(sch)/sizeof(sch[0]); i++) {
|
||||
help_enc = new EncodeSCH(sch[i], "1.0");
|
||||
std::cout << "EncodeSCH: " << std::setw(20) << sch[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// UIN
|
||||
{
|
||||
const char* uin[] = {"0", "1", "32767", "32768", "65534", "65535", "41394"};
|
||||
for (size_t i = 0; i < sizeof(uin)/sizeof(uin[0]); i++) {
|
||||
help_enc = new EncodeUIN(uin[i], "1.0");
|
||||
std::cout << "EncodeUIN: " << std::setw(20) << uin[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// SIN
|
||||
{
|
||||
const char* sin[] = {"0", "1", "32767", "-32768", "-2", "-1", "-24142"};
|
||||
for (size_t i = 0; i < sizeof(sin)/sizeof(sin[0]); i++) {
|
||||
help_enc = new EncodeSIN(sin[i], "1.0");
|
||||
std::cout << "EncodeSIN: " << std::setw(20) << sin[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// ULG
|
||||
{
|
||||
const char* ulg[] = {"0", "1", "2147483647", "2147483648", "4294967294", "4294967295", "2712847316"};
|
||||
for (size_t i = 0; i < sizeof(ulg)/sizeof(ulg[0]); i++) {
|
||||
help_enc = new EncodeULG(ulg[i], "1.0");
|
||||
std::cout << "EncodeULG: " << std::setw(20) << ulg[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// SLG
|
||||
{
|
||||
const char* slg[] = {"0", "1", "2147483647", "-2147483648", "-2", "-1", "-1582119980"};
|
||||
for (size_t i = 0; i < sizeof(slg)/sizeof(slg[0]); i++) {
|
||||
help_enc = new EncodeSLG(slg[i], "1.0");
|
||||
std::cout << "EncodeSLG: " << std::setw(20) << slg[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// FLT
|
||||
{
|
||||
const char* flt[] = {"0.000", "2.075", "9.522", "9.865", "2.129"};
|
||||
for (size_t i = 0; i < sizeof(flt)/sizeof(flt[0]); i++) {
|
||||
help_enc = new EncodeFLT(flt[i], "1.0");
|
||||
std::cout << "EncodeFLT: " << std::setw(20) << flt[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// STR
|
||||
{
|
||||
const char* str[] = {"Speicher ", "VD600" };
|
||||
for (size_t i = 0; i < sizeof(str)/sizeof(str[0]); i++) {
|
||||
help_enc = new EncodeSTR(str[i]);
|
||||
std::cout << "EncodeSTR: " << std::setw(20) << str[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// BCD
|
||||
{
|
||||
const char* bcd[] = {"0", "1", "2", "3", "12", "99"};
|
||||
for (size_t i = 0; i < sizeof(bcd)/sizeof(bcd[0]); i++) {
|
||||
help_enc = new EncodeBCD(bcd[i], "1.0");
|
||||
std::cout << "EncodeBCD: " << std::setw(20) << bcd[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// D1B
|
||||
{
|
||||
const char* d1b[] = {"00", "01", "127", "-127", "-128"};
|
||||
for (size_t i = 0; i < sizeof(d1b)/sizeof(d1b[0]); i++) {
|
||||
help_enc = new EncodeD1B(d1b[i], "1.0");
|
||||
std::cout << "EncodeD1B: " << std::setw(20) << d1b[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// D1C
|
||||
{
|
||||
const char* d1c[] = {"0", "50", "100"};
|
||||
for (size_t i = 0; i < sizeof(d1c)/sizeof(d1c[0]); i++) {
|
||||
help_enc = new EncodeD1C(d1c[i], "1.0");
|
||||
std::cout << "EncodeD1C: " << std::setw(20) << d1c[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// D2B
|
||||
{
|
||||
const char* d2b[] = {"0", "0.00390625", "-0.00390625", "-1", "-128", "-127.99609375", "127.99609375"};
|
||||
for (size_t i = 0; i < sizeof(d2b)/sizeof(d2b[0]); i++) {
|
||||
help_enc = new EncodeD2B(d2b[i], "1.0");
|
||||
std::cout << "EncodeD2B: " << std::setw(20) << d2b[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// D2C
|
||||
{
|
||||
const char* d2c[] = {"0", "0.0625", "-0.0625", "-1", "-2048", "-2047.9375", "2047.9375"};
|
||||
for (size_t i = 0; i < sizeof(d2c)/sizeof(d2c[0]); i++) {
|
||||
help_enc = new EncodeD2C(d2c[i], "1.0");
|
||||
std::cout << "EncodeD2C: " << std::setw(20) << d2c[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// BDA
|
||||
{
|
||||
const char* bda[] = {"17.11.2013", "22.09.2001"};
|
||||
for (size_t i = 0; i < sizeof(bda)/sizeof(bda[0]); i++) {
|
||||
help_enc = new EncodeBDA(bda[i]);
|
||||
std::cout << "EncodeBDA: " << std::setw(20) << bda[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// HDA
|
||||
{
|
||||
const char* hda[] = {"01.01.2001", "31.12.2027"};
|
||||
for (size_t i = 0; i < sizeof(hda)/sizeof(hda[0]); i++) {
|
||||
help_enc = new EncodeHDA(hda[i]);
|
||||
std::cout << "EncodeHDA: " << std::setw(20) << hda[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// BTI
|
||||
{
|
||||
const char* bti[] = {"01:01:01", "17:42:09", "23:59:59"};
|
||||
for (size_t i = 0; i < sizeof(bti)/sizeof(bti[0]); i++) {
|
||||
help_enc = new EncodeBTI(bti[i]);
|
||||
std::cout << "EncodeBTI: " << std::setw(20) << bti[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// HTI
|
||||
{
|
||||
const char* hti[] = {"01:01:01", "17:42:09", "23:59:59"};
|
||||
for (size_t i = 0; i < sizeof(hti)/sizeof(hti[0]); i++) {
|
||||
help_enc = new EncodeHTI(hti[i]);
|
||||
std::cout << "EncodeHTI: " << std::setw(20) << hti[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// BDY
|
||||
{
|
||||
const char* bdy[] = {"Tue", "Thu", "Sun", "Err"};
|
||||
for (size_t i = 0; i < sizeof(bdy)/sizeof(bdy[0]); i++) {
|
||||
help_enc = new EncodeBDY(bdy[i]);
|
||||
std::cout << "EncodeBDY: " << std::setw(20) << bdy[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
// HDY
|
||||
{
|
||||
const char* hdy[] = {"Mon", "Wed", "Sun", "Err"};
|
||||
for (size_t i = 0; i < sizeof(hdy)/sizeof(hdy[0]); i++) {
|
||||
help_enc = new EncodeHDY(hdy[i]);
|
||||
std::cout << "EncodeHDY: " << std::setw(20) << hdy[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// TTM
|
||||
{
|
||||
const char* ttm[] = {"00:00", "05:50", "13:10", "24:00"};
|
||||
for (size_t i = 0; i < sizeof(ttm)/sizeof(ttm[0]); i++) {
|
||||
help_enc = new EncodeTTM(ttm[i]);
|
||||
std::cout << "EncodeTTM: " << std::setw(20) << ttm[i] << " = " << help_enc->encode() << std::endl;
|
||||
|
||||
delete help_enc;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
|
||||
*
|
||||
* This file is part of ebusd.
|
||||
*
|
||||
* ebusd 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.
|
||||
*
|
||||
* ebusd 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 ebusd. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include "port.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace libebus;
|
||||
|
||||
int main ()
|
||||
{
|
||||
std::string dev("/dev/ttyUSB20");
|
||||
Port port(dev, true);
|
||||
|
||||
port.open();
|
||||
|
||||
if(port.isOpen() == true)
|
||||
std::cout << "openPort successful." << std::endl;
|
||||
|
||||
int count = 0;
|
||||
|
||||
while (1) {
|
||||
ssize_t bytes_read;
|
||||
unsigned char byte = 0;
|
||||
bytes_read = port.recv(0);
|
||||
|
||||
for (int i = 0; i < bytes_read; i++)
|
||||
byte = port.byte();
|
||||
std::cout << std::hex << std::setw(2) << std::setfill('0')
|
||||
<< static_cast<unsigned>(byte) << std::endl;
|
||||
|
||||
bytes_read = 0;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
port.close();
|
||||
|
||||
if(port.isOpen() == false)
|
||||
std::cout << "closePort successful." << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) John Baier 2014 <ebusd@johnm.de>
|
||||
*
|
||||
* This file is part of ebusd.
|
||||
*
|
||||
* ebusd 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.
|
||||
*
|
||||
* ebusd 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 ebusd. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include "symbol.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace libebus;
|
||||
|
||||
int main ()
|
||||
{
|
||||
SymbolString sstr = SymbolString("10feb5050427a915aa");
|
||||
|
||||
std::string gotStr = sstr.getDataStr(false), expectStr = "10feb5050427a90015a90177";
|
||||
|
||||
if (strcasecmp(gotStr.c_str(), expectStr.c_str()) == 0)
|
||||
std::cout << "ctor escaped successful." << std::endl;
|
||||
else
|
||||
std::cout << "ctor escaped invalid: got " << gotStr
|
||||
<< ", expected " << expectStr << std::endl;
|
||||
|
||||
unsigned char gotCrc = sstr.getCRC(), expectCrc = 0x77;
|
||||
|
||||
if (gotCrc == expectCrc)
|
||||
std::cout << "CRC successful." << std::endl;
|
||||
else
|
||||
std::cout << "CRC invalid: got 0x"
|
||||
<< std::nouppercase << std::setw(2) << std::hex
|
||||
<< std::setfill('0') << static_cast<unsigned>(gotCrc)
|
||||
<< ", expected 0x"
|
||||
<< std::nouppercase << std::setw(2) << std::hex
|
||||
<< std::setfill('0') << static_cast<unsigned>(expectCrc)
|
||||
<< std::endl;
|
||||
|
||||
gotStr = sstr.getDataStr(), expectStr = "10feb5050427a915aa77";
|
||||
|
||||
if (strcasecmp(gotStr.c_str(), expectStr.c_str()) == 0)
|
||||
std::cout << "unescape successful." << std::endl;
|
||||
else
|
||||
std::cout << "unescape invalid: got " << gotStr
|
||||
<< ", expected " << expectStr << std::endl;
|
||||
|
||||
sstr = SymbolString("10feb5050427a90015a90177", true);
|
||||
|
||||
gotStr = sstr.getDataStr();
|
||||
|
||||
if (strcasecmp(gotStr.c_str(), expectStr.c_str()) == 0)
|
||||
std::cout << "ctor unescaped successful." << std::endl;
|
||||
else
|
||||
std::cout << "ctor unescaped invalid: got " << gotStr
|
||||
<< ", expected " << expectStr << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user