Skip to content

Commit

Permalink
ebusdump merged into ebusctl.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhu- committed Jun 26, 2014
1 parent c0b4ff0 commit 2291242
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 164 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
*.o
*.dirstamp
/ebusctl
/ebusdump
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
ebusd - ChangeLog
-----------------

2014-06-26 Roland Jax <[email protected]>
* ebusdump merged into ebusctl.

2014-06-25 Roland Jax <[email protected]>
* ebusctl added (includes ebusd_scan and ebusd_send)
* Version changed from 0.2.1 to 0.3.0
Expand Down
9 changes: 1 addition & 8 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
AM_CXXFLAGS = $(LIBEBUS_CFLAGS) -I$(top_srcdir)/lib -fpic -Wall -Wextra

bin_PROGRAMS = ebusd \
ebusctl \
ebusdump
ebusctl

ebusd_SOURCES = src/main.cpp \
src/baseloop.cpp \
Expand All @@ -31,9 +30,3 @@ ebusctl_SOURCES = tools/ebusctl.cpp \

ebusctl_LDADD = $(LIBEBUS_LIBS)


ebusdump_SOURCES = tools/ebusdump.cpp \
lib/appl.cpp

ebusdump_LDADD = $(LIBEBUS_LIBS)

3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
ebusd - NEWS
------------

2014-06-25 Roland Jax <[email protected]>
2014-06-26 Roland Jax <[email protected]>
* ebusctl added (includes ebusd_scan and ebusd_send)
* ebusdump merged into ebusctl.
* Version changed from 0.2.1 to 0.3.0

2014-06-03 Roland Jax <[email protected]>
Expand Down
3 changes: 1 addition & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ See ./ebusd -h
Tools
-----

ebusctl - client for ebusd.
ebusdump - send dump files (virtual serial device) to server for development.
ebusctl - client program for ebusd.


For usage and further information take a look on help page.
Expand Down
2 changes: 1 addition & 1 deletion lib/appl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void Appl::printArgs()
if (m_argTxt.size() != 0)
std::cerr << " " << m_argTxt;

std::cerr << std::endl << std::endl;
std::cerr << std::endl << std::endl << "Options:" << std::endl << std::endl;

for (a_it = m_args.begin(); a_it < m_args.end(); a_it++) {
const char* c = (strlen(a_it->shortname) == 1) ? a_it->shortname : " ";
Expand Down
152 changes: 101 additions & 51 deletions tools/ebusctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
#include "appl.h"
#include "tcpsocket.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <unistd.h>

using namespace libebus;

Expand All @@ -33,10 +36,24 @@ void define_args()
{
A.addArgs("COMMAND {ARGS...}\n\n"
" local commands:\n"
" 'scan' scans the bus and identifies the participant\n\n"
" 'scan' scans the bus and identifies the participants\n\n"
" 'feed' sends a dump file to a local virtual serial device\n"
" (hint: socat -d -d pty,raw,echo=0 pty,raw,echo=0)\n\n"
" remote commands:\n"
" send 'help' to server", 1);

A.addItem("p_device", Appl::Param("/dev/ttyUSB60"), "d", "device",
"virtual serial device (/dev/ttyUSB60)",
Appl::type_string, Appl::opt_mandatory);

A.addItem("p_file", Appl::Param(""), "f", "file",
"dump file with raw data",
Appl::type_string, Appl::opt_mandatory);

A.addItem("p_time", Appl::Param(10000), "t", "time",
"delay between 2 bytes in 'us' (10000)\n",
Appl::type_long, Appl::opt_mandatory);

A.addItem("p_server", Appl::Param("localhost"), "s", "server",
"name or ip (localhost)",
Appl::type_string, Appl::opt_mandatory);
Expand Down Expand Up @@ -163,78 +180,111 @@ int main(int argc, char* argv[])
exit(EXIT_SUCCESS);
}

addManufacturer();
if (strcasecmp(A.getArg(0).c_str(), "feed") == 0) {
std::string dev(A.getParam<const char*>("p_device"));
Port port(dev, true);

port.open();
if(port.isOpen() == true)
std::cout << "openPort successful." << std::endl;

std::fstream file(A.getParam<const char*>("p_file"), std::ios::in | std::ios::binary);

if(file.is_open() == true) {

TCPClient* client = new TCPClient();
TCPSocket* socket = client->connect(A.getParam<const char*>("p_server"), A.getParam<int>("p_port"));
while (file.eof() == false) {
unsigned char byte = file.get();
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<unsigned>(byte) << std::endl;

if (socket != NULL) {
if (strcasecmp(A.getArg(0).c_str(), "scan") != 0) {
// build message
std::string message(A.getArg(0));
for (size_t i = 1; i < A.numArg(); i++) {
message += " ";
message += A.getArg(i);
port.send(&byte, 1);
usleep(A.getParam<long>("p_time"));
}

socket->send(message.c_str(), message.size());
file.close();
}

char data[1024];
size_t datalen;
port.close();
if(port.isOpen() == false)
std::cout << "closePort successful." << std::endl;

datalen = socket->recv(data, sizeof(data)-1);
data[datalen] = '\0';
} else {

std::cout << data;
} else {
// send command to all slaves
for (size_t i = 0; i < s.size(); i++) {
// build message
std::string message("hex ms ");
message += s[i];
message += "070400";
TCPClient* client = new TCPClient();
TCPSocket* socket = client->connect(A.getParam<const char*>("p_server"), A.getParam<int>("p_port"));

socket->send(message.c_str(), message.size());
if (socket != NULL) {

char data[256];
size_t datalen;
if (strcasecmp(A.getArg(0).c_str(), "scan") == 0) {
addManufacturer();

datalen = socket->recv(data, sizeof(data)-1);
data[datalen] = '\0';
// send command to all slaves
for (size_t i = 0; i < s.size(); i++) {
// build message
std::string message("hex ms ");
message += s[i];
message += "070400";

socket->send(message.c_str(), message.size());

// decode answer
if (strncmp(&data[0], "-", 1) != 0) {
std::string item(data);
char data[1024];
size_t datalen;

std::ostringstream ident;
Decode* help = NULL;
datalen = socket->recv(data, sizeof(data)-1);
data[datalen] = '\0';

help = new DecodeSTR(item.substr(18,10));
ident << help->decode();
delete help;
// decode answer
if (strncmp(&data[0], "-", 1) != 0) {
std::string item(data);

std::cout << s[i] << ": '" << manufacturer.find(item.substr(16,2))->second
<< "' ident: '" << std::setw(5) << std::setfill(' ') << ident.str()
<< "' sw: '" << item.substr(28,2)
<< "." << item.substr(30,2)
<< "' hw: '" << item.substr(32,2)
<< "." << item.substr(34,2)
<< "'";
std::ostringstream ident;
Decode* help = NULL;

if (item.substr(16,2) == "b5")
scanVaillant(socket, s[i]);
help = new DecodeSTR(item.substr(18,10));
ident << help->decode();
delete help;

std::cout << std::endl;
std::cout << s[i] << ": '" << manufacturer.find(item.substr(16,2))->second
<< "' ident: '" << std::setw(5) << std::setfill(' ') << ident.str()
<< "' sw: '" << item.substr(28,2)
<< "." << item.substr(30,2)
<< "' hw: '" << item.substr(32,2)
<< "." << item.substr(34,2)
<< "'";

if (item.substr(16,2) == "b5")
scanVaillant(socket, s[i]);

std::cout << std::endl;
}

sleep(2);
}
} else {
// build message
std::string message(A.getArg(0));
for (size_t i = 1; i < A.numArg(); i++) {
message += " ";
message += A.getArg(i);
}

sleep(2);
socket->send(message.c_str(), message.size());

char data[1024];
size_t datalen;

datalen = socket->recv(data, sizeof(data)-1);
data[datalen] = '\0';

std::cout << data;
}

delete socket;
}

delete socket;
}
delete client;

delete client;
}

return 0;

Expand Down
100 changes: 0 additions & 100 deletions tools/ebusdump.cpp

This file was deleted.

0 comments on commit 2291242

Please sign in to comment.