Merge branch 'master' of github.com:rscada/libmbus

This commit is contained in:
Robert Johansson
2012-07-25 00:04:16 +09:00
74 changed files with 2175 additions and 74535 deletions

View File

@ -65,3 +65,24 @@ mbus_serial_switch_baudrate_LDFLAGS = -L$(top_builddir)/mbus
mbus_serial_switch_baudrate_LDADD = -lmbus -lm
mbus_serial_switch_baudrate_SOURCES = mbus-serial-switch-baudrate.c
# man pages
dist_man_MANS = libmbus.1 \
mbus-tcp-scan.1 \
mbus-tcp-request-data.1 \
mbus-tcp-request-data-multi-reply.1 \
mbus-tcp-select-secondary.1 \
mbus-tcp-scan-secondary.1 \
mbus-serial-scan.1 \
mbus-serial-request-data.1 \
mbus-serial-request-data-multi-reply.1 \
mbus-serial-select-secondary.1 \
mbus-serial-scan-secondary.1 \
mbus-serial-switch-baudrate.1
.pod.1:
pod2man --release=$(VERSION) --center=$(PACKAGE) $< \
>.pod2man.tmp.$$$$ 2>/dev/null && mv -f .pod2man.tmp.$$$$ $@ || true
@if grep '\<POD ERRORS\>' $@ >/dev/null 2>&1; \
then \
echo "$@ has some POD errors!"; false; \
fi

139
bin/libmbus.pod Normal file
View File

@ -0,0 +1,139 @@
=head1 NAME
libmbus (utilities) - support utilities to the libmbus. libmbus is an open
source M-bus (Meter-Bus) library. The Meter-Bus is a standard for reading out
meter data from electricity meters, heat meters, gas meters, etc. The role
of the libmbus library is to decode/encode M-bus data, and to handle
the communication with M-Bus devices.
=head1 SYNOPSIS
B<mbus-serial-switch-baudrate> [-b BAUDRATE] device address target-baudrate
B<mbus-serial-scan> [-d] [-b BAUDRATE] device
B<mbus-tcp-scan> [-d] host port
B<mbus-serial-scan-secondary> [-d] [-b BAUDRATE] device [address-mask]
B<mbus-tcp-scan-secondary> host port [address-mask]
B<mbus-serial-request-data> [-d] [-b BAUDRATE] device mbus-address
B<mbus-tcp-request-data> [-d] host port mbus-address
B<mbus-serial-request-data-multi-reply> [-d] [-b BAUDRATE] device mbus-address
B<mbus-tcp-request-data-multi-reply> [-d] host port mbus-address
B<mbus-serial-select-secondary> [-b BAUDRATE] device secondary-mbus-address
B<mbus-tcp-select-secondary> host port secondary-mbus-address
=head1 DESCRIPTION
B<mbus-serial-switch-baudrate> - attempts to switch the communication speed of
the MBus device.
B<mbus-serial-scan>, B<mbus-tcp-scan> - sequentially scan for devices on MBus bus
using primary addresses.
B<mbus-serial-scan-secondary>, B<mbus-tcp-scan-secondary> - scan for devices on
MBus bus using secondary addresses. The scan is not sequential.
B<mbus-serial-request-data>, B<mbus-tcp-request-data> - read data from given device.
Supports both primary and secondary address types.
B<mbus-serial-request-data-multi-reply>, B<mbus-tcp-request-data-multi-reply> - read
data from given device supporting multi-telegram (up to 16 frames) reply. Can be also
used for single telegram as mbus-serial-request-data or mbus-tcp-request-data.
Supports both primary and secondary address types.
B<mbus-serial-select-secondary>, B<mbus-tcp-select-secondary> - perform single secondary
address select to check what device responds.
=head1 OPTIONS
There are following options/parameters:
=over 4
=item B<-b> I<BAUDRATE>
For serial communication, use given I<BAUDRATE> (integer in Bd). If not used then
default baudrate of 9600 will be used.
libmbus supports following baud rates: 300, 600, 1200, 2400, 4800, 9600, 19200,
38400.
Note that your MBus gateway and/or MBus device will most likely support only
a subset of these. The most commonlu used/supported rates are probably 9600, 2400
and 300.
=item B<-d>
Enable debugging messages.
=item B<device>
For serial communication, the serial device which represents the MBus (gateway).
Typically something like /dev/ttyS0, /dev/ttyUSB0, etc.
=item B<host>
For TCP communciation, the host which represents the MBus (gateway).
=item B<port>
For TCP communciation, the port on the host which represents the MBus (gateway).
=item B<address>
MBus device primary address. An integer between 1 and 250.
=item B<address-mask>
Address mask for secondary address scan - you can restrict the search by supplying
an optional address mask on the form 'FFFFFFFFFFFFFFFF' where F is a wildcard
character.
=item B<mbus-address>
MBus device address. Could be a primary address or a secondary address (sixteen
digit hexadecimal number).
The primary address should be an integer between 1 and 250 for addressing
individual devices. However the program does allow using any one byte number (i.e.
0 to 255) so that you can also use addresses reserved for physical or data link
layers management, secondary addressing, broadcasts, etc.
=item B<secondary-mbus-address>
MBus secondary address of the device. Sixteen digit hexadecimal number.
=item B<target-baudrate>
For serial communication, the baudrate to which the device should be switched.
=back
=head1 EXAMPLES
Scan for MBus devices on the serial port:
mbus-serial-scan -d -b 2400 /dev/ttyS0
Try to switch baud rate of a device on address 59 from 2400Bd to 9600Bd:
mbus-serial-switch-baudrate -b 2400 /dev/ttyUSB0 59 9600
Readout a MBus device on address 59 at 2400Bd:
mbus-serial-request-data-multi-reply -b 2400 /dev/ttyS0 59
=head1 SEE ALSO
S<http://www.rscada.se/libmbus> and S<http://www.m-bus.com>
=head1 AUTHORS
See S<http://www.rscada.se/libmbus> and S<https://github.com/rscada/libmbus>

View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -79,7 +79,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
printf("Failed to setup connection to M-bus gateway\n");
return 1;

View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -31,6 +31,9 @@ main(int argc, char **argv)
char *device, *addr_str, *xml_result;
int address, baudrate = 9600;
memset((void *)&reply, 0, sizeof(mbus_frame));
memset((void *)&reply_data, 0, sizeof(mbus_frame_data));
if (argc == 3)
{
@ -132,7 +135,7 @@ main(int argc, char **argv)
}
}
if (mbus_recv_frame(handle, &reply) != 0)
if (mbus_recv_frame(handle, &reply) != MBUS_RECV_RESULT_OK)
{
fprintf(stderr, "Failed to receive M-Bus response frame.\n");
return 1;

View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -50,8 +50,8 @@ main(int argc, char **argv)
}
else if (argc == 4 && strcmp(argv[1], "-d") == 0)
{
device = argv[1];
addr_mask = strdup(argv[2]);
device = argv[2];
addr_mask = strdup(argv[3]);
debug = 1;
}
else if (argc == 4 && strcmp(argv[1], "-b") == 0)
@ -108,7 +108,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
printf("Failed to setup connection to M-bus gateway\n");
return 1;

2
bin/mbus-serial-scan.1 Normal file
View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -103,7 +103,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
if (ret == -3)
if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
continue;
}
@ -111,7 +111,7 @@ main(int argc, char **argv)
if (debug)
printf("\n");
if (ret == -2)
if (ret == MBUS_RECV_RESULT_INVALID)
{
/* check for more data (collision) */
mbus_purge_frames(handle);

View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -79,13 +79,13 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
if (ret == -3)
if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
printf("No reply from device with secondary address %s: %s\n", argv[2], mbus_error_str());
return 1;
}
if (ret == -2)
if (ret == MBUS_RECV_RESULT_INVALID)
{
printf("Invalid reply from %s: The address address probably match more than one device: %s\n", argv[2], mbus_error_str());
return 1;
@ -99,7 +99,7 @@ main(int argc, char **argv)
return 1;
}
if (mbus_recv_frame(handle, &reply) != 0)
if (mbus_recv_frame(handle, &reply) != MBUS_RECV_RESULT_OK)
{
printf("Failed to recieve reply from selected secondary device: %s\n", mbus_error_str());
return 1;

View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -78,7 +78,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
if (ret == -3)
if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
printf("No reply from device\n");
return 1;

View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -117,7 +117,7 @@ main(int argc, char **argv)
}
}
if (mbus_recv_frame(handle, &reply) != 0)
if (mbus_recv_frame(handle, &reply) != MBUS_RECV_RESULT_OK)
{
fprintf(stderr, "Failed to receive M-Bus response frame: %s\n", mbus_error_str());
return 1;

View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -91,7 +91,6 @@ main(int argc, char **argv)
}
(void) mbus_recv_frame(handle, &reply);
sleep(1);
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
frame->address = MBUS_ADDRESS_BROADCAST_NOREPLY;
@ -104,7 +103,6 @@ main(int argc, char **argv)
}
(void) mbus_recv_frame(handle, &reply);
sleep(1);
mbus_scan_2nd_address_range(handle, 0, addr_mask);

2
bin/mbus-tcp-scan.1 Normal file
View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -86,7 +86,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
if (ret == -3)
if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
continue;
}
@ -94,7 +94,7 @@ main(int argc, char **argv)
if (debug)
printf("\n");
if (ret == -2)
if (ret == MBUS_RECV_RESULT_INVALID)
{
/* check for more data (collision) */
mbus_purge_frames(handle);

View File

@ -0,0 +1,2 @@
.so man1/libmbus.1

View File

@ -65,13 +65,13 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
if (ret == -3)
if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
printf("No reply from device with secondary address %s: %s\n", argv[3], mbus_error_str());
return 1;
}
if (ret == -2)
if (ret == MBUS_RECV_RESULT_INVALID)
{
printf("Invalid reply from %s: The address address probably match more than one device: %s\n", argv[3], mbus_error_str());
return 1;
@ -85,7 +85,7 @@ main(int argc, char **argv)
return 1;
}
if (mbus_recv_frame(handle, &reply) != 0)
if (mbus_recv_frame(handle, &reply) != MBUS_RECV_RESULT_OK)
{
printf("Failed to recieve reply from selected secondary device: %s\n", mbus_error_str());
return 1;