Initial commit on github.

This commit is contained in:
Roland Jax
2013-11-14 21:15:14 +01:00
parent 36fc9f23c2
commit 916ec20456
37 changed files with 8561 additions and 2 deletions
+17
View File
@@ -0,0 +1,17 @@
bin_PROGRAMS = ebus_send check csv
ebus_send_SOURCES = ebus_send.c
ebus_send_LDADD = $(top_srcdir)/lib/libebus.a $(top_srcdir)/lib/liblog.a
ebus_send_CFLAGS = -I$(top_srcdir)/lib
check_SOURCES = check.c
check_LDADD = $(top_srcdir)/lib/libebus.a $(top_srcdir)/lib/liblog.a
check_CFLAGS = -I$(top_srcdir)/lib
csv_SOURCES = csv.c
csv_LDADD = $(top_srcdir)/lib/libebus.a $(top_srcdir)/lib/liblog.a
csv_CFLAGS = -I$(top_srcdir)/lib
distclean-local:
-rm -f Makefile.in
+107
View File
@@ -0,0 +1,107 @@
/*
* Copyright (C) Roland Jax 2012-2013 <roland.jax@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 /* HAVE_CONFIG_H */
#include <stdio.h>
#include <string.h>
#include "ebus-decode.h"
int main() {
int i, j, end, ret;
int bcd, d1b, data[SERIAL_BUFSIZE + 1];
float d1c, d2b, d2c;
char byte;
unsigned char hex, tmp, crc, crc_calc[2] ;
tmp = 0;
end = 0;
do {
i = 0;
printf("Input: ");
while ((byte = fgetc(stdin)) != EOF) {
if (byte == '\n') {
break;
}
if (byte == 'q') {
end = 1;
break;
}
if (i < sizeof(data)) {
ret = eb_htoi(&byte);
if (ret != -1) {
data[i] = ret;
i++;
}
} else {
break;
}
}
if (!end) {
for (j = 0; j < i; j += 2) {
bcd = 0;
d1b = 0;
ret = 0;
d1c = 0.0;
d2b = 0.0;
d2c = 0.0;
hex = (unsigned char) (data[j]*16 + data[j+1]);
ret = eb_bcd_to_int(hex, &bcd);
ret = eb_d1b_to_int(hex, &d1b);
ret = eb_d1c_to_float(hex, &d1c);
printf("hex %02x ->\tbcd: %3d\td1b: %4d"
"\td1c: %5.1f", hex, bcd, d1b, d1c);
if (j == 2) {
ret = eb_d2b_to_float(tmp, hex, &d2b);
ret = eb_d2c_to_float(tmp, hex, &d2c);
crc_calc[0] = tmp;
crc_calc[1] = hex;
crc = eb_calc_crc(crc_calc,2);
printf("\td2b: %10.5f\td2c: %12.6f"
"\tcrc: %02x\n", d2b, d2c, crc);
}
else {
tmp = hex;
printf("\n");
}
}
}
} while (end == 0);
return 0;
}
+223
View File
@@ -0,0 +1,223 @@
/*
* Copyright (C) Roland Jax 2012-2013 <roland.jax@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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <dirent.h>
#include <ctype.h>
#include "log.h"
#include "ebus-cmd.h"
#include "ebus-bus.h"
/* global variables */
const char *progname;
static const char *cfgdir = NULL;
static int all = NO;
static int cyc = NO;
static int detail = NO;
static int get = NO;
static int set = NO;
static char loglevel[] = {"ALL"};
void
usage()
{
fprintf(stdout, "\nUsage: %s [OPTION] cfgdir\n\n"
" -a --all print ALL\n"
" -c --cyc print CYC\n"
" -d --detail print DETAIL\n"
" -g --get print GET\n"
" -s --set print SET\n"
" -h --help print this message.\n"
"\n",
progname);
}
void
cmdline(int *argc, char ***argv)
{
static struct option opts[] = {
{"all", no_argument, NULL, 'a'},
{"cyc", no_argument, NULL, 'c'},
{"detail", no_argument, NULL, 'd'},
{"get", no_argument, NULL, 'g'},
{"set", no_argument, NULL, 's'},
{"help", no_argument, NULL, 'h'},
{NULL, no_argument, NULL, 0 },
};
for (;;) {
int i;
i = getopt_long(*argc, *argv, "acdgsh", opts, NULL);
if (i == -1) {
*argc = optind;
break;
}
switch (i) {
case 'a':
cyc = YES;
get = YES;
set = YES;
break;
case 'c':
cyc = YES;
break;
case 'd':
detail = YES;
break;
case 'g':
get = YES;
break;
case 's':
set = YES;
break;
case 'h':
default:
usage();
exit(EXIT_FAILURE);
break;
}
}
}
int
main(int argc, char *argv[])
{
/* set progname */
progname = (const char *)strrchr(argv[0], '/');
progname = progname ? (progname + 1) : argv[0];
cmdline(&argc, &argv);
cfgdir = argv[argc];
/* open log */
log_level(loglevel);
log_open("", 1);
if (cfgdir)
eb_cmd_dir_read(cfgdir, "csv");
else
usage();
if (cyc)
eb_cmd_print("cyc", all, detail);
if (get)
eb_cmd_print("get", all, detail);
if (set)
eb_cmd_print("set", all, detail);
//~ Master Slave
//~ const unsigned char tmp[] = {'\x10','\x08','\xb5','\x10','\x09','\x00','\x02','\x40','\x00',
//~ '\x00','\x00','\x00','\x00','\x02','\x15','\x00','\x00','\x00','\x00'};
//~ '\x00','\x00','\x00','\x00','\x02','\x15','\xff','\x00','\x00','\x00'};
//~ '\x00','\x00','\x00','\x00','\x02','\x15','\x00','\x01','\x02','\x99','\x00'};
//~ '\x00','\x00','\x00','\x00','\x02','\x15','\x00','\x02','\xe2','\x67','\x41','\x00'};
//~ char cmd[] = "cyc ms test ma";
//~ char cmd[] = "cyc ms test sd";
//~ char cmd[] = "cyc ms test sa";
//~ char cmd[] = "cyc ms test md";
//~ char cmd[] = "cyc ms test";
//~ const unsigned char tmp[] = {'\x10','\x08','\xb5','\x09','\x03','\x29','\x0f','\x00','\x56','\x00',
//~ '\x05','\x0f','\x00','\xa9','\x01','\x00','\x00','\x86','\x00'};
//~ char cmd[] = "cyc mv brine_in";
//~ const unsigned char tmp[] = {'\xff','\x08','\xb5','\x11','\x01','\x01','\x2d','\x00','\x09','\x62',
//~ '\xff','\x00','\x80','\x00','\x54','\x00','\x00','\xff','\x23','\x00'};
//~ char cmd[] = "cyc burner temps";
//~ char cmd[] = "cyc burner temps_raw";
// 31835
//~ const unsigned char tmp[] = {'\xff','\x08','\xb5','\x09','\x03','\x0d','\xbc','\x00','\x12',
//~ '\x00','\x04','\x5b','\x7c','\x00','\x00','\x75','\x00'};
//~
//~
//~ char cmd[] = "cyc ms test";
//~ Master Master
//~ 10 03 05 07 09 bb 06 2e 02 00 80 ff 6e ff 8f 00
//~ const unsigned char tmp[] = {'\x10','\x03','\x05','\x07','\x09','\xbb','\x06','\x1b','\x02','\x00',
//~ '\x80','\xff','\x6e','\xff','\xf2','\x00'};
//~ const unsigned char tmp[] = {'\x10','\x23','\xb5','\x04','\x01','\x31','\xf6','\x00'};
//~ const unsigned char tmp[] = {'\x10','\x23','\xb5','\x04','\x01','\x31','\xf6','\xff'};
//~ char cmd[] = "cyc mm test test";
//~ char cmd[] = "cyc mm test stat";
//~ char cmd[] = "cyc mm test";
//~ Broadcast
//~ const unsigned char tmp[] = {'\x10','\xfe','\xb5','\x16','\x08','\x00','\x02','\x23','\x16','\x28','\x02','\x04','\x13','\x92'};
//~ char cmd[] = "cyc broad date_time day";
//~ char cmd[] = "cyc broad date_time";
//~ 10 46 11 2e 03 00 02 11 02
//~ const unsigned char tmp[] = {'\x10','\x46','\x11','\x2e','\x03','\x00','\x02','\x11','\x02'};
//~ char cmd[] = "cyc broad 1";
//###############################################################
//~ const int tmplen = sizeof(tmp) / sizeof(unsigned char);
//~ char data[CMD_DATA_SIZE], tcpbuf[CMD_DATA_SIZE];
//~ memset(data, '\0', sizeof(data));
//~ memset(tcpbuf, '\0', sizeof(tcpbuf));
//~ int id, tcpbuflen;
//~
//~ fprintf(stdout, "Test command >%s<\n", cmd);
//~ eb_print_hex(tmp, tmplen);
//~
//~ eb_cyc_data_process(tmp, tmplen);
//~
//~ id = eb_cmd_search_com_cyc(&tmp[1], tmplen - 1);
//~
//~ eb_execute(id, data, tcpbuf, &tcpbuflen);
//~
//~ fprintf(stdout, "tcpbuf: %s tcpbuflen: %d\n", tcpbuf, tcpbuflen);
//###############################################################
//~ unsigned long val;
//~ eb_print_hex(&tmp[11], 4);
//~ fprintf(stdout, "%d %d %d %d\n", tmp[11], (tmp[12] << 8), (tmp[13] << 16), (tmp[14] << 24));
//~ fprintf(stdout, "%d\n", tmp[11] + (tmp[12] << 8) + (tmp[13] << 16) + (tmp[14] << 24));
//###############################################################
eb_cmd_dir_free();
return 0;
}
+278
View File
@@ -0,0 +1,278 @@
/*
* Copyright (C) Roland Jax 2012-2013 <roland.jax@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 /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <time.h>
#include <sys/time.h>
#include <ctype.h>
#include "ebus-decode.h"
#include "ebus-bus.h"
static int serialfd = -1;
static const char *device = SERIAL_DEVICE;
static const char *progname;
static int type = EBUS_MSG_MASTER_SLAVE;
static int prompt = NO;
void
print_msg(const char *pre, const unsigned char *buf, int buflen,
const char *post)
{
int i;
fprintf(stdout, "%s", pre);
for (i = 0; i < buflen; i++)
fprintf(stdout, " %02x", buf[i]);
fprintf(stdout, "%s\n", post);
}
void
usage()
{
fprintf(stdout, "\nUsage: %s [OPTION] <ZZ PB SB NN DBx>\n\n"
" <ZZ PB SB NN DBx> spaces within message be removed.\n\n"
" -a --address set bus address. (%02x)\n"
" -d --device use a specified serial device. (%s)\n"
" -p --prompt stay on input prompt.\n"
" -r --retry max retry getting bus. (%d)\n"
" -s --skip skipped ACK bytes after get-bus error. (%d)\n"
" -t --type message type. (%d)\n"
" 1 = Broadcast, 2 = Master-Master, 3 = Master-Slave\n"
" -w --wait wait time for QQ compare. (~%d usec)\n"
" -h --help print this message.\n"
"\n",
progname,
EBUS_QQ,
device,
EBUS_GET_RETRY,
EBUS_SKIP_ACK,
type,
EBUS_MAX_WAIT);
}
void
cmdline(int *argc, char ***argv)
{
static struct option opts[] = {
{"address", required_argument, NULL, 'a'},
{"device", required_argument, NULL, 'd'},
{"prompt", no_argument, NULL, 'p'},
{"retry", required_argument, NULL, 'r'},
{"skip", required_argument, NULL, 's'},
{"type", required_argument, NULL, 't'},
{"wait", required_argument, NULL, 'w'},
{"help", no_argument, NULL, 'h'},
{NULL, no_argument, NULL, 0 },
};
for (;;) {
int i;
i = getopt_long(*argc, *argv, "a:d:pr:s:t:w:h", opts, NULL);
if (i == -1) {
*argc = optind;
break;
}
switch (i) {
case 'a':
if (isxdigit(*optarg) && strlen(optarg) == 2) {
int tmp;
tmp = (eb_htoi(&optarg[0])) * 16 +
(eb_htoi(&optarg[1]));
eb_set_qq((unsigned char) tmp);
}
break;
case 'd':
device = optarg;
break;
case 'p':
prompt = YES;
break;
case 'r':
if (isdigit(*optarg)) {
eb_set_get_retry(atoi(optarg));
}
break;
case 's':
if (isdigit(*optarg)) {
eb_set_skip_ack(atoi(optarg));
}
break;
case 't':
if (isdigit(*optarg))
type = atoi(optarg);
break;
case 'w':
if (isdigit(*optarg)) {
eb_set_max_wait(atol(optarg));
}
break;
case 'h':
default:
usage();
exit(EXIT_FAILURE);
break;
}
}
}
int
main(int argc, char *argv[])
{
int i, j, k, end, ret, val, max_argc, buslen;
int in[SERIAL_BUFSIZE + 1];
char byte;
unsigned char msg[SERIAL_BUFSIZE + 1], bus[TMP_BUFSIZE];
progname = (const char *)strrchr(argv[0], '/');
progname = progname ? (progname + 1) : argv[0];
max_argc = argc;
cmdline(&argc, &argv);
val = 0;
if (prompt) {
end = 0;
do {
byte = '\0';
i = 0;
printf("msg: ");
while ((byte = fgetc(stdin)) != EOF) {
if (byte == '\n')
break;
if (byte == 'q') {
end = 1;
break;
}
if (i < sizeof(in)) {
ret = eb_htoi(&byte);
if (ret != -1) {
in[i] = ret;
i++;
}
} else {
break;
}
}
if (!end && i > 0) {
memset(msg, '\0', sizeof(msg));
memset(bus, '\0', sizeof(bus));
for (j = 0, k = 0; j < i; j += 2, k++)
msg[k] = (unsigned char)
(in[j]*16 + in[j+1]);
ret = eb_serial_open(device, &serialfd);
if (ret < 0)
fprintf(stdout, "Error open %s.\n", device);
if (ret == 0) {
ret = eb_send_data(msg, k, type, bus, &buslen);
if (ret == 0) {
fprintf(stdout, "res:");
eb_print_result();
}
}
ret = eb_serial_close();
if (ret < 0)
fprintf(stdout, "Error close %s.\n", device);
}
} while (end == 0);
} else {
memset(in, '\0', sizeof(in));
k = 0;
i = 0;
for (k = argc; k < max_argc; k++) {
j = 0;
while (argv[k][j] != '\0') {
byte = argv[k][j];
if (i < sizeof(in)) {
ret = eb_htoi(&byte);
if (ret != -1) {
in[i] = ret;
i++;
}
}
j++;
}
}
memset(bus, '\0', sizeof(bus));
memset(msg, '\0', sizeof(msg));
for (j = 0, k = 0; j < i; j += 2, k++)
msg[k] = (unsigned char) (in[j]*16 + in[j+1]);
if (k > 0) {
ret = eb_serial_open(device, &serialfd);
if (ret < 0)
fprintf(stdout, "Error open %s.\n", device);
if (ret == 0) {
ret = eb_send_data(msg, k, type, bus, &buslen);
val = ret;
if (ret == 0) {
if (type == EBUS_MSG_MASTER_SLAVE)
eb_print_result();
if (type == EBUS_MSG_MASTER_MASTER)
fprintf(stdout, " %d\n", ret);
}
}
ret = eb_serial_close();
if (ret < 0)
fprintf(stdout, "Error close %s.\n", device);
}
}
return val;
}