Merge pull request #57 from lategoodbye/master

New option for normalized output, new test frames, unit fix
This commit is contained in:
Robert Johansson 2013-08-03 19:35:59 -07:00
commit 84ffacadff
7 changed files with 69 additions and 33 deletions

View File

@ -2072,6 +2072,11 @@ mbus_vib_unit_lookup(mbus_value_information_block *vib)
// E000 1101
snprintf(buff, sizeof(buff), "Software version");
}
else if (vib->vife[0] == 0x16)
{
// VIFE = E001 0110 Password
snprintf(buff, sizeof(buff), "Password");
}
else if (vib->vife[0] == 0x17 || vib->vife[0] == 0x97)
{
// VIFE = E001 0111 Error flags
@ -2082,11 +2087,6 @@ mbus_vib_unit_lookup(mbus_value_information_block *vib)
// VIFE = E001 0000 Customer location
snprintf(buff, sizeof(buff), "Customer location");
}
else if (vib->vife[0] == 0x0C)
{
// E000 1100 Model / Version
snprintf(buff, sizeof(buff), "Model / Version");
}
else if (vib->vife[0] == 0x11)
{
// VIFE = E001 0001 Customer
@ -2102,16 +2102,6 @@ mbus_vib_unit_lookup(mbus_value_information_block *vib)
// VIFE = E001 1011 Digital input (binary)
snprintf(buff, sizeof(buff), "Digital input (binary)");
}
else if (vib->vife[0] == 0x09)
{
// VIFE = E001 0110 Password
snprintf(buff, sizeof(buff), "Password");
}
else if (vib->vife[0] == 0x0B)
{
// VIFE = E000 1011 Parameter set identification
snprintf(buff, sizeof(buff), "Parameter set identification");
}
else if ((vib->vife[0] & 0x70) == 0x40)
{
// VIFE = E100 nnnn 10^(nnnn-9) V
@ -2131,7 +2121,7 @@ mbus_vib_unit_lookup(mbus_value_information_block *vib)
}
else
{
snprintf(buff, sizeof(buff), "Unrecongized VIF extension: 0x%.2x", vib->vife[0]);
snprintf(buff, sizeof(buff), "Unrecognized VIF extension: 0x%.2x", vib->vife[0]);
}
return buff;
}

View File

@ -33,6 +33,10 @@ if [ ! -d "$directory" ]; then
fi
for hexfile in "$directory"/*.hex; do
if [ ! -f "$hexfile" ]; then
continue
fi
filename=`basename $hexfile .hex`
# Parse hex file and write XML in file

View File

@ -12,32 +12,50 @@
#include <stdio.h>
#include <string.h>
#include <mbus/mbus-protocol.h>
#include <mbus/mbus.h>
int
main(int argc, char *argv[])
{
FILE *fp = NULL;
size_t buff_len, len;
int normalized = 0;
unsigned char buf[1024];
mbus_frame reply;
mbus_frame_data frame_data;
char *xml_result = NULL;
char *xml_result = NULL, *file = NULL;
if (argc != 2)
if (argc == 3 && strcmp(argv[1], "-n") == 0)
{
fprintf(stderr, "usage: %s binary-file\n", argv[0]);
file = argv[2];
normalized = 1;
}
else if (argc == 2)
{
file = argv[1];
}
else
{
fprintf(stderr, "usage: %s [-n] binary-file\n", argv[0]);
fprintf(stderr, " optional flag -n for normalized values\n");
return 1;
}
if ((fp = fopen(argv[1], "r")) == NULL)
if ((fp = fopen(file, "r")) == NULL)
{
fprintf(stderr, "%s: failed to open '%s'\n", argv[0], argv[1]);
fprintf(stderr, "%s: failed to open '%s'\n", argv[0], file);
return 1;
}
memset(buf, 0, sizeof(buf));
len = fread(buf, 1, sizeof(buf), fp);
if (ferror(fp) != 0)
{
fprintf(stderr, "%s: failed to read '%s'\n", argv[0], file);
return 1;
}
fclose(fp);
memset(&reply, 0, sizeof(reply));
@ -46,7 +64,9 @@ main(int argc, char *argv[])
mbus_frame_data_parse(&reply, &frame_data);
mbus_frame_print(&reply);
if ((xml_result = mbus_frame_data_xml(&frame_data)) == NULL)
xml_result = normalized ? mbus_frame_data_xml_normalized(&frame_data) : mbus_frame_data_xml(&frame_data);
if (xml_result == NULL)
{
fprintf(stderr, "Failed to generate XML representation of MBUS frame: %s\n", mbus_error_str());
return 1;

View File

@ -12,33 +12,50 @@
#include <stdio.h>
#include <string.h>
#include <mbus/mbus-protocol.h>
#include <mbus/mbus.h>
int
main(int argc, char *argv[])
{
FILE *fp = NULL;
size_t buff_len, len;
int result;
int result, normalized = 0;
unsigned char raw_buff[4096], buff[4096];
mbus_frame reply;
mbus_frame_data frame_data;
char *xml_result = NULL;
char *xml_result = NULL, *file = NULL;
if (argc != 2)
if (argc == 3 && strcmp(argv[1], "-n") == 0)
{
fprintf(stderr, "usage: %s hex-file\n", argv[0]);
file = argv[2];
normalized = 1;
}
else if (argc == 2)
{
file = argv[1];
}
else
{
fprintf(stderr, "usage: %s [-n] hex-file\n", argv[0]);
fprintf(stderr, " optional flag -n for normalized values\n");
return 1;
}
if ((fp = fopen(argv[1], "r")) == NULL)
if ((fp = fopen(file, "r")) == NULL)
{
fprintf(stderr, "%s: failed to open '%s'\n", argv[0], argv[1]);
fprintf(stderr, "%s: failed to open '%s'\n", argv[0], file);
return 1;
}
memset(raw_buff, 0, sizeof(raw_buff));
len = fread(raw_buff, 1, sizeof(raw_buff), fp);
if (ferror(fp) != 0)
{
fprintf(stderr, "%s: failed to read '%s'\n", argv[0], file);
return 1;
}
fclose(fp);
buff_len = mbus_hex2bin(buff,sizeof(buff),raw_buff,sizeof(raw_buff));
@ -73,7 +90,9 @@ main(int argc, char *argv[])
//mbus_frame_print(&reply);
//mbus_frame_data_print(&frame_data);
if ((xml_result = mbus_frame_data_xml(&frame_data)) == NULL)
xml_result = normalized ? mbus_frame_data_xml_normalized(&frame_data) : mbus_frame_data_xml(&frame_data);
if (xml_result == NULL)
{
fprintf(stderr, "Failed to generate XML representation of MBUS frame: %s\n", mbus_error_str());
return 1;

View File

@ -0,0 +1 @@
68 4A 4A 68 08 01 72 45 23 11 70 93 15 0A 07 02 00 00 00 0C 13 67 45 23 01 04 6D 3A 0D E6 02 42 6C E1 01 4C 13 51 69 45 00 42 EC 7E 01 11 12 3B 39 17 42 6C 01 11 02 3B F9 17 0F 0E 42 20 01 01 01 00 05 08 5E 01 20 3D 12 08 3D 12 08 00 C0 16

View File

@ -0,0 +1 @@
68 2F 2F 68 08 04 72 04 00 00 00 AC 48 12 00 01 00 00 00 0C 00 00 00 00 00 04 6D 10 0D 34 09 42 6C 1F 0C 4C 00 00 00 00 00 42 EC 7E 3F 0C 0F 43 01 01 00 D0 16

View File

@ -0,0 +1 @@
68 2F 2F 68 08 01 72 01 01 03 01 AC 48 40 08 1E 00 00 00 0C 6E 87 19 00 00 04 6D 29 0A 1F 0C 42 6C 1F 0C 4C 6E 02 13 00 00 42 EC 7E 3F 0C 0F C0 01 01 0C 40 16