renamed file to avoid merge problems

This commit is contained in:
Robert Johansson 2012-04-13 10:46:36 +09:00
commit 00731c93e4
17 changed files with 338 additions and 603 deletions

View File

@ -16,7 +16,8 @@ noinst_HEADERS =
bin_PROGRAMS = mbus-tcp-scan mbus-tcp-request-data mbus-tcp-request-data-multi-reply \
mbus-tcp-select-secondary mbus-tcp-scan-secondary \
mbus-serial-scan mbus-serial-request-data \
mbus-serial-select-secondary mbus-serial-scan-secondary
mbus-serial-select-secondary mbus-serial-scan-secondary \
mbus-serial-switch-baudrate
# tcp
mbus_tcp_scan_LDFLAGS = -L$(top_builddir)/mbus
@ -56,3 +57,7 @@ mbus_serial_scan_secondary_LDFLAGS = -L$(top_builddir)/mbus
mbus_serial_scan_secondary_LDADD = -lmbus
mbus_serial_scan_secondary_SOURCES = mbus-serial-scan-secondary.c
mbus_serial_switch_baudrate_LDFLAGS = -L$(top_builddir)/mbus
mbus_serial_switch_baudrate_LDADD = -lmbus
mbus_serial_switch_baudrate_SOURCES = mbus-serial-switch-baudrate.c

View File

@ -24,7 +24,7 @@ int
main(int argc, char **argv)
{
char *device, *addr_mask;
int address, baudrate = 9600;
int baudrate = 9600;
mbus_handle *handle = NULL;
if (argc == 2)

View File

@ -27,7 +27,7 @@ main(int argc, char **argv)
mbus_handle *handle;
mbus_frame reply;
char *device, *addr;
int address, ret, baudrate = 9600;
int ret, baudrate = 9600;
if (argc == 3)
{

View File

@ -0,0 +1,90 @@
//------------------------------------------------------------------------------
// Copyright (C) 2010-2012, Robert Johansson and contributors, Raditex AB
// All rights reserved.
//
// rSCADA
// http://www.rSCADA.se
// info@rscada.se
//
// Contributors:
// Large parts of this file was contributed by Stefan Wahren.
//
//------------------------------------------------------------------------------
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <mbus/mbus.h>
//------------------------------------------------------------------------------
// Execution starts here:
//------------------------------------------------------------------------------
int
main(int argc, char **argv)
{
mbus_handle *handle;
mbus_frame reply;
char *device;
int address, ret;
int source_baudrate = 9600, target_baudrate;
if (argc == 4)
{
device = argv[1];
address = atoi(argv[2]);
target_baudrate = atoi(argv[3]);
}
else if (argc == 6 && strcmp(argv[1], "-b") == 0)
{
source_baudrate = atoi(argv[2]);
device = argv[3];
address = atoi(argv[4]);
target_baudrate = atoi(argv[5]);
}
else
{
fprintf(stderr, "usage: %s device address target-baudrate\n", argv[0]);
return 0;
}
if ((handle = mbus_connect_serial(device)) == NULL)
{
printf("Failed to setup connection to M-bus device: %s\n", mbus_error_str());
return 1;
}
if (mbus_serial_set_baudrate(handle->m_serial_handle, source_baudrate) == -1)
{
printf("Failed to set baud rate.\n");
return 1;
}
if (mbus_send_switch_baudrate_frame(handle, address, target_baudrate) == -1)
{
printf("Failed to send switch baudrate frame: %s\n", mbus_error_str());
return 1;
}
ret = mbus_recv_frame(handle, &reply);
if (ret == -1)
{
printf("No reply from device\n");
return 1;
}
if (mbus_frame_type(&reply) != MBUS_FRAME_TYPE_ACK)
{
printf("Unknown reply:\n");
mbus_frame_print(&reply);
}
mbus_disconnect(handle);
return 0;
}

View File

@ -110,8 +110,13 @@ main(int argc, char **argv)
*/
// instead of the send and recv, use this sendrecv function that
<<<<<<< HEAD
// takes care of the possibility of multi-telegram replies
if (mbus_sendrecv_request(handle, address, &reply) == -1)
=======
// takes care of the possibility of multi-telegram replies (limit = 16 frames)
if (mbus_sendrecv_request(handle, address, &reply, 16) == -1)
>>>>>>> 58c2bbe2338cc1c5e30fa4cb1d52f5cb56ae9801
{
fprintf(stderr, "Failed to send/receive M-Bus request.\n");
return 1;

View File

@ -27,7 +27,7 @@ int
main(int argc, char **argv)
{
char *host, *addr_mask;
int port, address;
int port;
if (argc != 4 && argc != 3)
{

View File

@ -27,7 +27,7 @@ main(int argc, char **argv)
mbus_handle *handle;
mbus_frame reply;
char *host, *addr;
int port, address, ret;
int port, ret;
if (argc != 4)
{

View File

@ -1255,6 +1255,70 @@ mbus_send_select_frame(mbus_handle * handle, const char *secondary_addr_str)
return 0;
}
//------------------------------------------------------------------------------
// send a user data packet from master to slave: the packet let the
// adressed slave(s) switch to the given baudrate
//------------------------------------------------------------------------------
int
mbus_send_switch_baudrate_frame(mbus_handle * handle, int address, int baudrate)
{
int retval = 0;
int control_information = 0;
mbus_frame *frame;
switch (baudrate)
{
case 300:
control_information = MBUS_CONTROL_INFO_SET_BAUDRATE_300;
break;
case 600:
control_information = MBUS_CONTROL_INFO_SET_BAUDRATE_600;
break;
case 1200:
control_information = MBUS_CONTROL_INFO_SET_BAUDRATE_1200;
break;
case 2400:
control_information = MBUS_CONTROL_INFO_SET_BAUDRATE_2400;
break;
case 4800:
control_information = MBUS_CONTROL_INFO_SET_BAUDRATE_4800;
break;
case 9600:
control_information = MBUS_CONTROL_INFO_SET_BAUDRATE_9600;
break;
case 19200:
control_information = MBUS_CONTROL_INFO_SET_BAUDRATE_19200;
break;
case 38400:
control_information = MBUS_CONTROL_INFO_SET_BAUDRATE_38400;
break;
default:
MBUS_ERROR("%s: invalid baudrate %d\n", __PRETTY_FUNCTION__, baudrate);
return -1;
}
frame = mbus_frame_new(MBUS_FRAME_TYPE_CONTROL);
if (frame == NULL)
{
MBUS_ERROR("%s: failed to allocate mbus frame.\n", __PRETTY_FUNCTION__);
return -1;
}
frame->control = MBUS_CONTROL_MASK_SND_UD | MBUS_CONTROL_MASK_DIR_M2S;
frame->address = address;
frame->control_information = control_information;
if (mbus_send_frame(handle, frame) == -1)
{
MBUS_ERROR("%s: failed to send mbus frame.\n", __PRETTY_FUNCTION__);
retval = -1;
}
mbus_frame_free(frame);
return retval;
}
//------------------------------------------------------------------------------
// send a request packet to from master to slave
//------------------------------------------------------------------------------
@ -1290,11 +1354,12 @@ mbus_send_request_frame(mbus_handle * handle, int address)
// from the slave.
//------------------------------------------------------------------------------
int
mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply)
mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply, int max_frames)
{
int retval = 0, more_frames = 1;
mbus_frame_data reply_data;
mbus_frame *frame, *next_frame;
int frame_count = 0;
frame = mbus_frame_new(MBUS_FRAME_TYPE_SHORT);
@ -1313,6 +1378,7 @@ mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply)
if (mbus_send_frame(handle, frame) == -1)
{
MBUS_ERROR("%s: failed to send mbus frame.\n", __PRETTY_FUNCTION__);
mbus_frame_free(frame);
retval = -1;
}
@ -1324,13 +1390,23 @@ mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply)
while (more_frames)
{
frame_count++;
if ((max_frames > 0) &&
(frame_count > max_frames))
{
// only readout max_frames
break;
}
if (debug)
printf("%s: debug: recieving response frame\n", __PRETTY_FUNCTION__);
printf("%s: debug: receiving response frame #%d\n", __PRETTY_FUNCTION__, frame_count);
if (mbus_recv_frame(handle, next_frame) == -1)
{
MBUS_ERROR("%s: Failed to receive M-Bus response frame.\n", __PRETTY_FUNCTION__);
return 1;
retval = 1;
break;
}
//
@ -1340,7 +1416,8 @@ mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply)
if (mbus_frame_data_parse(next_frame, &reply_data) == -1)
{
MBUS_ERROR("%s: M-bus data parse error.\n", __PRETTY_FUNCTION__);
return 1;
retval = 1;
break;
}
//
@ -1356,28 +1433,25 @@ mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply)
}
else
{
int more_frames = 0;
mbus_data_record *record;
more_frames = 0;
// loop through records and look for DIF = 0x1F (probably only
// necessary to check the last record?)
for (record = reply_data.data_var.record; record; record = record->next)
{
if (record->drh.dib.dif == 0x1F)
if (reply_data.data_var.more_records_follow)
{
if (debug)
printf("%s: debug: expecting more frames\n", __PRETTY_FUNCTION__);
more_frames = 1; // yes, more records follow
break;
}
more_frames = 1;
// allocate new frame and increment next_frame pointer
next_frame->next = mbus_frame_new(MBUS_FRAME_TYPE_ANY);
if (next_frame->next == NULL)
{
MBUS_ERROR("%s: failed to allocate mbus frame.\n", __PRETTY_FUNCTION__);
retval = -1;
more_frames = 0;
}
if (more_frames)
{
// allocate new frame and increment next_frame pointer
next_frame->next = mbus_frame_new(0);
next_frame = next_frame->next;
// need to send a new request and receive another reply
@ -1391,6 +1465,7 @@ mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply)
{
MBUS_ERROR("%s: failed to send mbus frame.\n", __PRETTY_FUNCTION__);
retval = -1;
more_frames = 0;
}
}
else

View File

@ -186,6 +186,17 @@ int mbus_send_frame(mbus_handle * handle, mbus_frame *frame);
*/
int mbus_send_select_frame(mbus_handle * handle, const char *secondary_addr_str);
/**
* Sends switch baudrate frame using "unified" handle
*
* @param handle Initialized handle
* @param address Address (0-255)
* @param baudrate Baudrate (300,600,1200,2400,4800,9600,19200,38400)
*
* @return Zero when successful.
*/
int mbus_send_switch_baudrate_frame(mbus_handle * handle, int address, int baudrate);
/**
* Sends request frame to given slave using "unified" handle
*
@ -194,18 +205,30 @@ int mbus_send_select_frame(mbus_handle * handle, const char *secondary_addr_str)
*
* @return Zero when successful.
*/
int mbus_send_data_request_frame(mbus_handle * handle, int address);
int mbus_send_request_frame(mbus_handle * handle, int address);
/**
* Sends a request and read replies until no more records available.
* Sends a request and read replies until no more records available
* or limit is reached.
*
* @param handle Initialized handle
* @param address Address (0-255)
* @param reply pointer to an mbus frame for the reply
* @param max_frames limit of frames to readout (0 = no limit)
*
* @return Zero when successful.
*/
int mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply);
int mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply, int max_frames);
/**
* Sends ping frame to given slave using "unified" handle
*
* @param handle Initialized handle
* @param address Address (0-255)
*
* @return Zero when successful.
*/
int mbus_send_ping_frame(mbus_handle *handle, int address);
/**
* Probe/address slave by secondary address using "unified" handle

View File

@ -1,4 +1,3 @@
//------------------------------------------------------------------------------
// Copyright (C) 2010-2011, Robert Johansson, Raditex AB
// All rights reserved.
@ -364,7 +363,7 @@ mbus_frame_verify(mbus_frame *frame)
int
mbus_data_bcd_encode(u_char *bcd_data, size_t bcd_data_size, int value)
{
int val = 0, v0, v1, v2, x1, x2;
int v0, v1, v2, x1, x2;
size_t i;
v2 = value;
@ -467,18 +466,9 @@ mbus_data_long_long_decode(u_char *int_data, size_t int_data_size)
{
for (i = int_data_size; i > 0; i--)
{
if (int_data_size == 6)
{
printf("%s: %lld %02X\n", __PRETTY_FUNCTION__, val, int_data[i-1]);
}
val = (val << 8) + int_data[i-1];
}
if (int_data_size == 6)
{
printf("%s: %lld\n", __PRETTY_FUNCTION__, val);
}
return val;
}
@ -493,7 +483,7 @@ mbus_data_long_long_decode(u_char *int_data, size_t int_data_size)
int
mbus_data_int_encode(u_char *int_data, size_t int_data_size, int value)
{
int val = 0, i;
int i;
if (int_data)
{
@ -572,6 +562,33 @@ mbus_data_str_decode(u_char *dst, const u_char *src, size_t len)
}
}
//------------------------------------------------------------------------------
///
/// Decode binary data.
///
//------------------------------------------------------------------------------
void
mbus_data_bin_decode(u_char *dst, const u_char *src, size_t len, size_t max_len)
{
size_t i, pos;
i = 0;
pos = 0;
while((i < len) && ((pos+3) < max_len)) {
pos += snprintf(&dst[pos], max_len - pos, "%.2X ", src[i]);
i++;
}
if (pos > 0)
{
// remove last space
pos--;
}
dst[pos] = '\0';
}
//------------------------------------------------------------------------------
///
/// Decode time data (usable for type f = 4 bytes or type g = 2 bytes)
@ -1732,7 +1749,7 @@ mbus_vib_unit_lookup(mbus_value_information_block *vib)
const char *
mbus_data_record_decode(mbus_data_record *record)
{
static char buff[256];
static char buff[768];
u_char vif, vife;
// ignore extension bit
@ -1742,7 +1759,6 @@ mbus_data_record_decode(mbus_data_record *record)
if (record)
{
int val;
long val2;
float val3;
long long val4;
struct tm time;
@ -1916,7 +1932,7 @@ mbus_data_record_decode(mbus_data_record *record)
case 0x0F: // special functions
snprintf(buff, sizeof(buff), "Special functions");
mbus_data_bin_decode(buff, record->data, record->data_len, sizeof(buff));
break;
case 0x0D: // variable length
@ -1962,7 +1978,7 @@ mbus_data_record_unit(mbus_data_record *record)
const char *
mbus_data_record_value(mbus_data_record *record)
{
static char buff[128];
static char buff[768];
if (record)
{
@ -2218,6 +2234,7 @@ mbus_data_variable_parse(mbus_frame *frame, mbus_data_variable *data)
{
// parse header
data->nrecords = 0;
data->more_records_follow = 0;
i = sizeof(mbus_data_variable_header);
if(frame->data_size < i)
return -1;
@ -2242,6 +2259,11 @@ mbus_data_variable_parse(mbus_frame *frame, mbus_data_variable *data)
if (record->drh.dib.dif == 0x0F || record->drh.dib.dif == 0x1F)
{
if ((record->drh.dib.dif & 0xFF) == 0x1F)
{
data->more_records_follow = 1;
}
i++;
// just copy the remaining data as it is vendor specific
record->data_len = frame->data_size - i;
@ -2479,7 +2501,7 @@ int
mbus_frame_internal_pack(mbus_frame *frame, mbus_frame_data *frame_data)
{
mbus_data_record *record;
int i, j;
int j;
if (frame == NULL || frame_data == NULL)
return -1;
@ -2577,6 +2599,14 @@ mbus_frame_internal_pack(mbus_frame *frame, mbus_frame_data *frame_data)
//
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Switch parse debugging
//------------------------------------------------------------------------------
void
mbus_parse_set_debug(int debug)
{
parse_debug = debug;
}
//------------------------------------------------------------------------------
/// Dump frame in HEX on standard output
@ -2664,7 +2694,7 @@ int
mbus_data_variable_print(mbus_data_variable *data)
{
mbus_data_record *record;
size_t i, j;
size_t j;
if (data)
{
@ -2687,6 +2717,11 @@ mbus_data_variable_print(mbus_data_variable *data)
printf("%.2X ", record->data[j]);
}
printf("\n");
if (record->drh.dib.dif == 0x1F)
{
printf("%s: More records follow in next telegram\n", __PRETTY_FUNCTION__);
}
continue;
}
@ -2803,7 +2838,7 @@ char *
mbus_data_variable_header_xml(mbus_data_variable_header *header)
{
static char buff[8192];
char str_encoded[256];
char str_encoded[768];
size_t len = 0;
int val;
@ -2841,7 +2876,7 @@ mbus_data_variable_xml(mbus_data_variable *data)
{
mbus_data_record *record;
static char buff[8192];
char str_encoded[256];
char str_encoded[768];
size_t len = 0;
size_t i;
@ -2853,33 +2888,29 @@ mbus_data_variable_xml(mbus_data_variable *data)
for (record = data->record, i = 0; record; record = record->next, i++)
{
len += snprintf(&buff[len], sizeof(buff) - len, " <DataRecord id=\"%zd\">\n", i);
if (record->drh.dib.dif == 0x0F) //MBUS_DIB_DIF_VENDOR_SPECIFIC)
{
len += snprintf(&buff[len], sizeof(buff) - len, " <DataRecord id=\"%zd\">\n", i);
len += snprintf(&buff[len], sizeof(buff) - len, " <Function>Manufacturer specific</Function>\n");
len += snprintf(&buff[len], sizeof(buff) - len, " </DataRecord>\n\n");
}
else if (record->drh.dib.dif == 0x1F)
{
len += snprintf(&buff[len], sizeof(buff) - len, " <DataRecord id=\"%zd\">\n", i);
len += snprintf(&buff[len], sizeof(buff) - len, " <Function>More records follow</Function>\n");
len += snprintf(&buff[len], sizeof(buff) - len, " </DataRecord>\n\n");
}
else
{
len += snprintf(&buff[len], sizeof(buff) - len, " <DataRecord id=\"%zd\">\n", i);
mbus_str_xml_encode(str_encoded, mbus_data_record_function(record), sizeof(str_encoded));
len += snprintf(&buff[len], sizeof(buff) - len, " <Function>%s</Function>\n", str_encoded);
mbus_str_xml_encode(str_encoded, mbus_data_record_unit(record), sizeof(str_encoded));
len += snprintf(&buff[len], sizeof(buff) - len, " <Unit>%s</Unit>\n", str_encoded);
}
mbus_str_xml_encode(str_encoded, mbus_data_record_value(record), sizeof(str_encoded));
len += snprintf(&buff[len], sizeof(buff) - len, " <Value>%s</Value>\n", str_encoded);
len += snprintf(&buff[len], sizeof(buff) - len, " </DataRecord>\n\n");
}
}
len += snprintf(&buff[len], sizeof(buff) - len, "</MBusData>\n");

View File

@ -177,6 +177,8 @@ typedef struct _mbus_data_variable {
u_char *data;
size_t data_len;
u_char more_records_follow;
// are these needed/used?
u_char mdh;
u_char *mfg_data;
@ -501,6 +503,8 @@ char *mbus_error_str();
void mbus_error_str_set(char *message);
void mbus_error_reset();
void mbus_parse_set_debug(int debug);
//
// data encode/decode functions
//
@ -521,6 +525,8 @@ void mbus_data_tm_decode(struct tm *t, u_char *t_data, size_t t_data_size);
void mbus_data_str_decode(u_char *dst, const u_char *src, size_t len);
void mbus_data_bin_decode(u_char *dst, const u_char *src, size_t len, size_t max_len);
const char *mbus_data_fixed_medium(mbus_data_fixed *data);
const char *mbus_data_fixed_unit(int medium_unit_byte);
const char *mbus_data_variable_medium_lookup(u_char medium);

View File

@ -1 +0,0 @@
# dummy

View File

@ -1 +0,0 @@
# dummy

View File

@ -1 +0,0 @@
# dummy

View File

@ -1,518 +0,0 @@
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# test/Makefile. Generated from Makefile.in by configure.
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
# Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
pkgdatadir = $(datadir)/mbus
pkgincludedir = $(includedir)/mbus
pkglibdir = $(libdir)/mbus
pkglibexecdir = $(libexecdir)/mbus
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = x86_64-unknown-linux-gnu
host_triplet = x86_64-unknown-linux-gnu
noinst_PROGRAMS = mbus_unit_test1$(EXEEXT) mbus_parse$(EXEEXT) \
mbus_parse_hex$(EXEEXT)
subdir = test
DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
PROGRAMS = $(noinst_PROGRAMS)
am_mbus_parse_OBJECTS = mbus_parse.$(OBJEXT)
mbus_parse_OBJECTS = $(am_mbus_parse_OBJECTS)
mbus_parse_DEPENDENCIES =
mbus_parse_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(mbus_parse_LDFLAGS) $(LDFLAGS) -o $@
am_mbus_parse_hex_OBJECTS = mbus_parse_hex.$(OBJEXT)
mbus_parse_hex_OBJECTS = $(am_mbus_parse_hex_OBJECTS)
mbus_parse_hex_DEPENDENCIES =
mbus_parse_hex_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(mbus_parse_hex_LDFLAGS) $(LDFLAGS) -o $@
am_mbus_unit_test1_OBJECTS = mbus_unit_test1.$(OBJEXT)
mbus_unit_test1_OBJECTS = $(am_mbus_unit_test1_OBJECTS)
mbus_unit_test1_DEPENDENCIES =
mbus_unit_test1_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(mbus_unit_test1_LDFLAGS) $(LDFLAGS) -o $@
DEFAULT_INCLUDES = -I. -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(mbus_parse_SOURCES) $(mbus_parse_hex_SOURCES) \
$(mbus_unit_test1_SOURCES)
DIST_SOURCES = $(mbus_parse_SOURCES) $(mbus_parse_hex_SOURCES) \
$(mbus_unit_test1_SOURCES)
HEADERS = $(noinst_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = ${SHELL} /home/rob/github/libmbus/missing --run aclocal-1.11
AMTAR = ${SHELL} /home/rob/github/libmbus/missing --run tar
AR = ar
AUTOCONF = ${SHELL} /home/rob/github/libmbus/missing --run autoconf
AUTOHEADER = ${SHELL} /home/rob/github/libmbus/missing --run autoheader
AUTOMAKE = ${SHELL} /home/rob/github/libmbus/missing --run automake-1.11
AWK = mawk
CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
CPP = gcc -E
CPPFLAGS =
CYGPATH_W = echo
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
DLLTOOL = false
DSYMUTIL =
DUMPBIN =
ECHO_C =
ECHO_N = -n
ECHO_T =
EGREP = /bin/grep -E
EXEEXT =
FGREP = /bin/grep -F
GREP = /bin/grep
INSTALL = /usr/bin/install -c
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_STRIP_PROGRAM = $(install_sh) -c -s
LD = /usr/bin/ld -m elf_x86_64
LDFLAGS = -version-info 0:7:0
LIBOBJS =
LIBS =
LIBTOOL = $(SHELL) $(top_builddir)/libtool
LIPO =
LN_S = ln -s
LTLIBOBJS =
MAKEINFO = ${SHELL} /home/rob/github/libmbus/missing --run makeinfo
MANIFEST_TOOL = :
MKDIR_P = /bin/mkdir -p
NM = /usr/bin/nm -B
NMEDIT =
OBJDUMP = objdump
OBJEXT = o
OTOOL =
OTOOL64 =
# ------------------------------------------------------------------------------
# Copyright (C) 2010, Raditex AB
# All rights reserved.
#
# rSCADA
# http://www.rSCADA.se
# info@rscada.se
#
# ------------------------------------------------------------------------------
PACKAGE = mbus
PACKAGE_BUGREPORT = info@rscada.se
PACKAGE_NAME = mbus
PACKAGE_STRING = mbus 0.7.0
PACKAGE_TARNAME = mbus
PACKAGE_URL = http://www.rscada.se/libmbus/
PACKAGE_VERSION = 0.7.0
PATH_SEPARATOR = :
RANLIB = ranlib
SED = /bin/sed
SET_MAKE =
SHELL = /bin/bash
STRIP = strip
VERSION = 0.7.0
abs_builddir = /home/rob/github/libmbus/test
abs_srcdir = /home/rob/github/libmbus/test
abs_top_builddir = /home/rob/github/libmbus
abs_top_srcdir = /home/rob/github/libmbus
ac_ct_AR = ar
ac_ct_CC = gcc
ac_ct_DUMPBIN =
am__include = include
am__leading_dot = .
am__quote =
am__tar = ${AMTAR} chof - "$$tardir"
am__untar = ${AMTAR} xf -
bindir = ${exec_prefix}/bin
build = x86_64-unknown-linux-gnu
build_alias =
build_cpu = x86_64
build_os = linux-gnu
build_vendor = unknown
builddir = .
datadir = ${datarootdir}
datarootdir = ${prefix}/share
docdir = ${datarootdir}/doc/${PACKAGE_TARNAME}
dvidir = ${docdir}
exec_prefix = ${prefix}
host = x86_64-unknown-linux-gnu
host_alias =
host_cpu = x86_64
host_os = linux-gnu
host_vendor = unknown
htmldir = ${docdir}
includedir = ${prefix}/include
infodir = ${datarootdir}/info
install_sh = ${SHELL} /home/rob/github/libmbus/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localedir = ${datarootdir}/locale
localstatedir = ${prefix}/var
mandir = ${datarootdir}/man
mkdir_p = /bin/mkdir -p
oldincludedir = /usr/include
pdfdir = ${docdir}
prefix = /usr/local
program_transform_name = s,x,x,
psdir = ${docdir}
sbindir = ${exec_prefix}/sbin
sharedstatedir = ${prefix}/com
srcdir = .
sysconfdir = ${prefix}/etc
target_alias =
top_build_prefix = ../
top_builddir = ..
top_srcdir = ..
AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/mbus
noinst_HEADERS =
mbus_unit_test1_LDFLAGS = -L$(top_builddir)/mbus
mbus_unit_test1_LDADD = -lmbus -lcunit -lncurses
mbus_unit_test1_SOURCES = mbus_unit_test1.c
mbus_parse_LDFLAGS = -L$(top_builddir)/mbus
mbus_parse_LDADD = -lmbus
mbus_parse_SOURCES = mbus_parse.c
mbus_parse_hex_LDFLAGS = -L$(top_builddir)/mbus
mbus_parse_hex_LDADD = -lmbus
mbus_parse_hex_SOURCES = mbus_parse_hex.c
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign test/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign test/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
clean-noinstPROGRAMS:
@list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
echo " rm -f" $$list; \
rm -f $$list || exit $$?; \
test -n "$(EXEEXT)" || exit 0; \
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
echo " rm -f" $$list; \
rm -f $$list
mbus_parse$(EXEEXT): $(mbus_parse_OBJECTS) $(mbus_parse_DEPENDENCIES)
@rm -f mbus_parse$(EXEEXT)
$(mbus_parse_LINK) $(mbus_parse_OBJECTS) $(mbus_parse_LDADD) $(LIBS)
mbus_parse_hex$(EXEEXT): $(mbus_parse_hex_OBJECTS) $(mbus_parse_hex_DEPENDENCIES)
@rm -f mbus_parse_hex$(EXEEXT)
$(mbus_parse_hex_LINK) $(mbus_parse_hex_OBJECTS) $(mbus_parse_hex_LDADD) $(LIBS)
mbus_unit_test1$(EXEEXT): $(mbus_unit_test1_OBJECTS) $(mbus_unit_test1_DEPENDENCIES)
@rm -f mbus_unit_test1$(EXEEXT)
$(mbus_unit_test1_LINK) $(mbus_unit_test1_OBJECTS) $(mbus_unit_test1_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
include ./$(DEPDIR)/mbus_parse.Po
include ./$(DEPDIR)/mbus_parse_hex.Po
include ./$(DEPDIR)/mbus_unit_test1.Po
.c.o:
$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
# source='$<' object='$@' libtool=no \
# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \
# $(COMPILE) -c $<
.c.obj:
$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
# source='$<' object='$@' libtool=no \
# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \
# $(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
# source='$<' object='$@' libtool=yes \
# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \
# $(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
set x; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$@" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(PROGRAMS) $(HEADERS)
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am:
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am:
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libtool clean-noinstPROGRAMS ctags distclean \
distclean-compile distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am install-man \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
pdf pdf-am ps ps-am tags uninstall uninstall-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@ -32,13 +32,13 @@ main(int argc, char *argv[])
if (argc != 2)
{
fprintf(stderr, "%s binary-file\n", argv[0]);
return -1;
return 1;
}
if ((fd = open(argv[1], O_RDONLY, 0)) == -1)
{
fprintf(stderr, "%s: failed to open '%s'", argv[0], argv[1]);
return -1;
return 1;
}
bzero(buf, sizeof(buf));

View File

@ -24,7 +24,7 @@
int
main(int argc, char *argv[])
{
int fd, len, i;
int fd, len, i, result;
u_char raw_buff[4096], buff[4096], *ptr, *endptr;
mbus_frame reply;
mbus_frame_data frame_data;
@ -63,9 +63,30 @@ main(int argc, char *argv[])
bzero(&reply, sizeof(reply));
bzero(&frame_data, sizeof(frame_data));
mbus_parse(&reply, buff, i);
//mbus_parse_set_debug(1);
result = mbus_parse(&reply, buff, i);
if (result < 0)
{
fprintf(stderr, "mbus_parse: %s\n", mbus_error_str());
return -1;
}
else if (result > 0)
{
fprintf(stderr, "mbus_parse: need %d more bytes\n", result);
return -1;
}
result = mbus_frame_data_parse(&reply, &frame_data);
if (result != 0)
{
mbus_frame_print(&reply);
fprintf(stderr, "mbus_frame_data_parse: %s\n", mbus_error_str());
return 1;
}
mbus_frame_data_parse(&reply, &frame_data);
//mbus_frame_print(&reply);
//mbus_frame_data_print(&frame_data);
printf("%s", mbus_frame_data_xml(&frame_data));