command 'feed' moved from ebusctl into ebusfeed;tools directory created.

This commit is contained in:
Roland Jax
2014-11-24 15:52:31 +01:00
parent b07a6930fd
commit 972277d68d
9 changed files with 255 additions and 152 deletions
+23
View File
@@ -0,0 +1,23 @@
AM_CXXFLAGS = -fpic \
-Wall \
-Wextra \
-I$(top_srcdir)/src/lib/utils \
-I$(top_srcdir)/src/lib/ebus
bin_PROGRAMS = ebusctl \
ebusfeed
ebusctl_SOURCES = ebusctl.cpp
ebusctl_LDADD = $(top_srcdir)/src/lib/utils/libutils.a \
$(top_srcdir)/src/lib/ebus/libebus.a
ebusfeed_SOURCES = ebusfeed.cpp
ebusfeed_LDADD = $(top_srcdir)/src/lib/utils/libutils.a \
$(top_srcdir)/src/lib/ebus/libebus.a
distclean-local:
-rm -f Makefile.in
-rm -rf .libs
+92
View File
@@ -0,0 +1,92 @@
/*
* 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/.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "appl.h"
#include "port.h"
#include "decode.h"
#include "tcpsocket.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <unistd.h>
using namespace std;
Appl& A = Appl::Instance(true, true);
void define_args()
{
A.setVersion("ebusctl is part of """PACKAGE_STRING"");
A.addText(" 'ebusctl' is a tcp socket client for ebusd.\n\n"
"Command: 'help' show available ebusd commands.\n\n"
"Options:\n");
A.addOption("server", "s", OptVal("localhost"), dt_string, ot_mandatory,
"name or ip (localhost)");
A.addOption("port", "p", OptVal(8888), dt_int, ot_mandatory,
"port (8888)");
}
int main(int argc, char* argv[])
{
// define arguments and application variables
define_args();
// parse arguments
A.parseArgs(argc, argv);
TCPClient* client = new TCPClient();
TCPSocket* socket = client->connect(A.getOptVal<const char*>("server"), A.getOptVal<int>("port"));
if (socket != NULL) {
// build message
string message(A.getCommand());
for (int i = 0; i < A.numArgs(); i++) {
message += " ";
message += A.getArg(i);
}
socket->send(message.c_str(), message.size());
char data[1024];
size_t datalen;
datalen = socket->recv(data, sizeof(data)-1);
data[datalen] = '\0';
cout << data;
delete socket;
}
else
cout << "error connecting to " << A.getOptVal<const char*>("server")
<< ":" << A.getOptVal<int>("port") << endl;
delete client;
return 0;
}
+101
View File
@@ -0,0 +1,101 @@
/*
* 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/.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "appl.h"
#include "port.h"
#include "decode.h"
#include "tcpsocket.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <unistd.h>
using namespace std;
Appl& A = Appl::Instance(true);
void define_args()
{
A.setVersion("ebusfeed is part of """PACKAGE_STRING"");
A.addText(" 'ebusfeed' sends a raw dump file to a local serial device (pts)\n\n"
" Usage: 1. 'socat -d -d pty,raw,echo=0 pty,raw,echo=0'\n"
" 2. create symbol links to appropriate devices\n"
" for example: 'ln -s /dev/pts/2 /dev/ttyUSB60'\n"
" 'ln -s /dev/pts/3 /dev/ttyUSB20'\n"
" 3. start ebusd: 'ebusd -f -d /dev/ttyUSB20'\n"
" 4. start ebusfeed: 'ebusfeed /path/to/raw_file'\n\n"
"Command: '/path/to/raw_file'\n\n"
"Options:\n");
A.addOption("device", "d", OptVal("/dev/ttyUSB60"), dt_string, ot_mandatory,
"virtual serial device (/dev/ttyUSB60)");
A.addOption("time", "t", OptVal(10000), dt_long, ot_mandatory,
"delay between 2 bytes in 'us' (10000)");
}
int main(int argc, char* argv[])
{
// define arguments and application variables
define_args();
// parse arguments
A.parseArgs(argc, argv);
string dev(A.getOptVal<const char*>("device"));
Port port(dev, true);
port.open();
if(port.isOpen() == true) {
cout << "openPort successful." << endl;
fstream file(A.getCommand().c_str(), ios::in | ios::binary);
if (file.is_open() == true) {
while (file.eof() == false) {
unsigned char byte = file.get();
cout << hex << setw(2) << setfill('0')
<< static_cast<unsigned>(byte) << endl;
port.send(&byte, 1);
usleep(A.getOptVal<long>("time"));
}
file.close();
}
else
cout << "error opening file " << A.getOptVal<const char*>("file") << endl;
port.close();
if(port.isOpen() == false)
cout << "closePort successful." << endl;
} else
cout << "error opening device " << A.getOptVal<const char*>("device") << endl;
return 0;
}