2012-04-11 10:46:09 +09:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 2010, Raditex AB
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// rSCADA
|
|
|
|
// http://www.rSCADA.se
|
|
|
|
// info@rscada.se
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <mbus/mbus-protocol.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int fd, len;
|
|
|
|
u_char buf[1024];
|
|
|
|
mbus_frame reply;
|
|
|
|
mbus_frame_data frame_data;
|
2012-05-29 21:24:30 +02:00
|
|
|
char *xml_result = NULL;
|
2012-04-11 10:46:09 +09:00
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
2012-04-16 21:00:24 +02:00
|
|
|
fprintf(stderr, "usage: %s binary-file\n", argv[0]);
|
2012-04-12 00:38:00 +02:00
|
|
|
return 1;
|
2012-04-11 10:46:09 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((fd = open(argv[1], O_RDONLY, 0)) == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: failed to open '%s'", argv[0], argv[1]);
|
2012-04-12 00:38:00 +02:00
|
|
|
return 1;
|
2012-04-11 10:46:09 +09:00
|
|
|
}
|
|
|
|
|
2012-05-18 13:55:43 +02:00
|
|
|
memset(buf, 0, sizeof(buf));
|
2012-04-11 10:46:09 +09:00
|
|
|
len = read(fd, buf, sizeof(buf));
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
2012-05-18 13:55:43 +02:00
|
|
|
memset(&reply, 0, sizeof(reply));
|
|
|
|
memset(&frame_data, 0, sizeof(frame_data));
|
2012-04-11 10:46:09 +09:00
|
|
|
mbus_parse(&reply, buf, len);
|
|
|
|
mbus_frame_data_parse(&reply, &frame_data);
|
|
|
|
mbus_frame_print(&reply);
|
2012-05-29 21:24:30 +02:00
|
|
|
|
|
|
|
if ((xml_result = mbus_frame_data_xml(&frame_data)) == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to generate XML representation of MBUS frame: %s\n", mbus_error_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
printf("%s", xml_result);
|
|
|
|
free(xml_result);
|
|
|
|
|
2012-04-16 00:33:03 +02:00
|
|
|
return 0;
|
2012-04-11 10:46:09 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|