diff --git a/autom4te.cache/requests b/autom4te.cache/requests
index bc7bb56..e01a738 100644
--- a/autom4te.cache/requests
+++ b/autom4te.cache/requests
@@ -1,4 +1,4 @@
-# This file was generated by Autom4te Sun May 1 09:53:53 UTC 2011.
+# This file was generated.
# It contains the lists of macros which have been traced.
# It can be safely removed.
@@ -14,55 +14,55 @@
'configure.ac'
],
{
- 'AM_PROG_F77_C_O' => 1,
'_LT_AC_TAGCONFIG' => 1,
- 'm4_pattern_forbid' => 1,
+ 'AM_PROG_F77_C_O' => 1,
'AC_INIT' => 1,
- '_AM_COND_IF' => 1,
+ 'm4_pattern_forbid' => 1,
'AC_CANONICAL_TARGET' => 1,
- 'AC_SUBST' => 1,
+ '_AM_COND_IF' => 1,
'AC_CONFIG_LIBOBJ_DIR' => 1,
- 'AC_FC_SRCEXT' => 1,
+ 'AC_SUBST' => 1,
'AC_CANONICAL_HOST' => 1,
+ 'AC_FC_SRCEXT' => 1,
'AC_PROG_LIBTOOL' => 1,
'AM_INIT_AUTOMAKE' => 1,
- 'AM_PATH_GUILE' => 1,
'AC_CONFIG_SUBDIRS' => 1,
+ 'AM_PATH_GUILE' => 1,
'AM_AUTOMAKE_VERSION' => 1,
'LT_CONFIG_LTDL_DIR' => 1,
- 'AC_REQUIRE_AUX_FILE' => 1,
'AC_CONFIG_LINKS' => 1,
- 'LT_SUPPORTED_TAG' => 1,
+ 'AC_REQUIRE_AUX_FILE' => 1,
'm4_sinclude' => 1,
+ 'LT_SUPPORTED_TAG' => 1,
'AM_MAINTAINER_MODE' => 1,
'AM_NLS' => 1,
'AM_GNU_GETTEXT_INTL_SUBDIR' => 1,
- 'AM_MAKEFILE_INCLUDE' => 1,
'_m4_warn' => 1,
+ 'AM_MAKEFILE_INCLUDE' => 1,
'AM_PROG_CXX_C_O' => 1,
- '_AM_MAKEFILE_INCLUDE' => 1,
'_AM_COND_ENDIF' => 1,
+ '_AM_MAKEFILE_INCLUDE' => 1,
'AM_ENABLE_MULTILIB' => 1,
'AM_PROG_MOC' => 1,
'AM_SILENT_RULES' => 1,
'AC_CONFIG_FILES' => 1,
- 'LT_INIT' => 1,
'include' => 1,
- 'AM_PROG_AR' => 1,
+ 'LT_INIT' => 1,
'AM_GNU_GETTEXT' => 1,
+ 'AM_PROG_AR' => 1,
'AC_LIBSOURCE' => 1,
- 'AM_PROG_FC_C_O' => 1,
'AC_CANONICAL_BUILD' => 1,
+ 'AM_PROG_FC_C_O' => 1,
'AC_FC_FREEFORM' => 1,
'AH_OUTPUT' => 1,
- '_AM_SUBST_NOTMAKE' => 1,
'AC_CONFIG_AUX_DIR' => 1,
- 'm4_pattern_allow' => 1,
- 'sinclude' => 1,
+ '_AM_SUBST_NOTMAKE' => 1,
'AM_PROG_CC_C_O' => 1,
- 'AM_XGETTEXT_OPTION' => 1,
- 'AC_CANONICAL_SYSTEM' => 1,
+ 'sinclude' => 1,
+ 'm4_pattern_allow' => 1,
'AM_CONDITIONAL' => 1,
+ 'AC_CANONICAL_SYSTEM' => 1,
+ 'AM_XGETTEXT_OPTION' => 1,
'AC_CONFIG_HEADERS' => 1,
'AC_DEFINE_TRACE_LITERAL' => 1,
'AM_POT_TOOLS' => 1,
@@ -123,8 +123,8 @@
'_m4_warn' => 1,
'AC_LIBTOOL_OBJDIR' => 1,
'gl_FUNC_ARGZ' => 1,
- 'LTOBSOLETE_VERSION' => 1,
'AM_SANITY_CHECK' => 1,
+ 'LTOBSOLETE_VERSION' => 1,
'AC_LIBTOOL_LANG_GCJ_CONFIG' => 1,
'AC_LIBTOOL_PROG_COMPILER_PIC' => 1,
'LT_LIB_M' => 1,
@@ -138,19 +138,19 @@
'_LT_WITH_SYSROOT' => 1,
'LT_SYS_DLOPEN_DEPLIBS' => 1,
'LT_FUNC_DLSYM_USCORE' => 1,
- 'AC_LIBTOOL_CONFIG' => 1,
'_LT_AC_LANG_F77' => 1,
- '_AM_SUBST_NOTMAKE' => 1,
+ 'AC_LIBTOOL_CONFIG' => 1,
'AC_LTDL_DLLIB' => 1,
+ '_AM_SUBST_NOTMAKE' => 1,
'_AM_AUTOCONF_VERSION' => 1,
'AM_DISABLE_SHARED' => 1,
'_LT_PROG_ECHO_BACKSLASH' => 1,
'_LTDL_SETUP' => 1,
- 'AM_PROG_LIBTOOL' => 1,
'_LT_AC_LANG_CXX' => 1,
- 'AC_LIB_LTDL' => 1,
- '_LT_AC_FILE_LTDLL_C' => 1,
+ 'AM_PROG_LIBTOOL' => 1,
'AM_PROG_LD' => 1,
+ '_LT_AC_FILE_LTDLL_C' => 1,
+ 'AC_LIB_LTDL' => 1,
'AU_DEFUN' => 1,
'AC_PROG_NM' => 1,
'AC_LIBTOOL_DLOPEN' => 1,
@@ -175,33 +175,33 @@
'AC_LTDL_OBJDIR' => 1,
'_LT_PATH_TOOL_PREFIX' => 1,
'AC_LIBTOOL_RC' => 1,
- 'AM_SILENT_RULES' => 1,
- 'AC_DISABLE_FAST_INSTALL' => 1,
'_LT_AC_PROG_ECHO_BACKSLASH' => 1,
- '_LT_AC_SYS_LIBPATH_AIX' => 1,
- '_LT_AC_TRY_DLOPEN_SELF' => 1,
+ 'AC_DISABLE_FAST_INSTALL' => 1,
+ 'AM_SILENT_RULES' => 1,
'include' => 1,
+ '_LT_AC_TRY_DLOPEN_SELF' => 1,
+ '_LT_AC_SYS_LIBPATH_AIX' => 1,
'LT_AC_PROG_SED' => 1,
'AM_ENABLE_SHARED' => 1,
'LTDL_INSTALLABLE' => 1,
'_LT_AC_LANG_GCJ_CONFIG' => 1,
'AC_ENABLE_SHARED' => 1,
- 'AC_ENABLE_STATIC' => 1,
- 'AC_LIBTOOL_SYS_HARD_LINK_LOCKS' => 1,
'_LT_REQUIRED_DARWIN_CHECKS' => 1,
+ 'AC_LIBTOOL_SYS_HARD_LINK_LOCKS' => 1,
+ 'AC_ENABLE_STATIC' => 1,
'_LT_AC_TAGVAR' => 1,
'AC_LIBTOOL_LANG_F77_CONFIG' => 1,
'AM_CONDITIONAL' => 1,
'LT_LIB_DLLOAD' => 1,
- 'LTDL_INIT' => 1,
- '_LT_PROG_F77' => 1,
- '_LT_PROG_CXX' => 1,
'LTVERSION_VERSION' => 1,
- 'AM_PROG_INSTALL_SH' => 1,
+ '_LT_PROG_CXX' => 1,
+ '_LT_PROG_F77' => 1,
+ 'LTDL_INIT' => 1,
'm4_include' => 1,
+ 'AM_PROG_INSTALL_SH' => 1,
'AC_PROG_EGREP' => 1,
- '_AC_AM_CONFIG_HEADER_HOOK' => 1,
'AC_PATH_MAGIC' => 1,
+ '_AC_AM_CONFIG_HEADER_HOOK' => 1,
'AC_LTDL_SYSSEARCHPATH' => 1,
'AM_MAKE_INCLUDE' => 1,
'LT_CMD_MAX_LEN' => 1,
@@ -235,11 +235,11 @@
'_AC_PROG_LIBTOOL' => 1,
'_AM_IF_OPTION' => 1,
'AC_PATH_TOOL_PREFIX' => 1,
- 'AC_LIBTOOL_F77' => 1,
'm4_pattern_allow' => 1,
+ 'AC_LIBTOOL_F77' => 1,
'AM_SET_LEADING_DOT' => 1,
- 'LT_AC_PROG_EGREP' => 1,
'_LT_PROG_FC' => 1,
+ 'LT_AC_PROG_EGREP' => 1,
'_AM_DEPENDENCIES' => 1,
'AC_LIBTOOL_LANG_C_CONFIG' => 1,
'LTOPTIONS_VERSION' => 1,
@@ -247,11 +247,11 @@
'AM_PROG_NM' => 1,
'AC_LIBLTDL_CONVENIENCE' => 1,
'AC_DEPLIBS_CHECK_METHOD' => 1,
- 'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1,
'AC_LIBLTDL_INSTALLABLE' => 1,
+ 'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1,
'AC_LTDL_ENABLE_INSTALL' => 1,
- 'AC_LIBTOOL_SYS_DYNAMIC_LINKER' => 1,
'LT_PROG_GCJ' => 1,
+ 'AC_LIBTOOL_SYS_DYNAMIC_LINKER' => 1,
'AM_INIT_AUTOMAKE' => 1,
'AC_DISABLE_STATIC' => 1,
'LT_PATH_NM' => 1,
@@ -259,25 +259,25 @@
'_LT_AC_LOCK' => 1,
'_LT_AC_LANG_RC_CONFIG' => 1,
'LT_SYS_MODULE_PATH' => 1,
- 'AC_LIBTOOL_POSTDEP_PREDEP' => 1,
'LT_WITH_LTDL' => 1,
+ 'AC_LIBTOOL_POSTDEP_PREDEP' => 1,
'AC_LTDL_SHLIBPATH' => 1,
'AM_AUX_DIR_EXPAND' => 1,
- '_LT_AC_LANG_F77_CONFIG' => 1,
'AC_LIBTOOL_PROG_COMPILER_NO_RTTI' => 1,
- '_AM_SET_OPTIONS' => 1,
+ '_LT_AC_LANG_F77_CONFIG' => 1,
'_LT_COMPILER_OPTION' => 1,
- '_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1,
+ '_AM_SET_OPTIONS' => 1,
'AM_RUN_LOG' => 1,
- 'AC_LIBTOOL_SYS_OLD_ARCHIVE' => 1,
- 'AC_LTDL_SYS_DLOPEN_DEPLIBS' => 1,
+ '_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1,
'AC_LIBTOOL_PICMODE' => 1,
- 'LT_PATH_LD' => 1,
+ 'AC_LTDL_SYS_DLOPEN_DEPLIBS' => 1,
+ 'AC_LIBTOOL_SYS_OLD_ARCHIVE' => 1,
'AC_CHECK_LIBM' => 1,
+ 'LT_PATH_LD' => 1,
'AC_LIBTOOL_SYS_LIB_STRIP' => 1,
'_AM_MANGLE_OPTION' => 1,
- 'AC_LTDL_SYMBOL_USCORE' => 1,
'AC_LIBTOOL_SYS_MAX_CMD_LEN' => 1,
+ 'AC_LTDL_SYMBOL_USCORE' => 1,
'AM_SET_DEPDIR' => 1,
'_LT_CC_BASENAME' => 1,
'_LT_LIBOBJ' => 1
@@ -295,55 +295,55 @@
'configure.ac'
],
{
- '_LT_AC_TAGCONFIG' => 1,
'AM_PROG_F77_C_O' => 1,
- 'm4_pattern_forbid' => 1,
+ '_LT_AC_TAGCONFIG' => 1,
'AC_INIT' => 1,
- '_AM_COND_IF' => 1,
+ 'm4_pattern_forbid' => 1,
'AC_CANONICAL_TARGET' => 1,
- 'AC_SUBST' => 1,
+ '_AM_COND_IF' => 1,
'AC_CONFIG_LIBOBJ_DIR' => 1,
- 'AC_FC_SRCEXT' => 1,
+ 'AC_SUBST' => 1,
'AC_CANONICAL_HOST' => 1,
+ 'AC_FC_SRCEXT' => 1,
'AC_PROG_LIBTOOL' => 1,
'AM_INIT_AUTOMAKE' => 1,
- 'AM_PATH_GUILE' => 1,
'AC_CONFIG_SUBDIRS' => 1,
+ 'AM_PATH_GUILE' => 1,
'AM_AUTOMAKE_VERSION' => 1,
'LT_CONFIG_LTDL_DIR' => 1,
- 'AC_REQUIRE_AUX_FILE' => 1,
'AC_CONFIG_LINKS' => 1,
- 'm4_sinclude' => 1,
+ 'AC_REQUIRE_AUX_FILE' => 1,
'LT_SUPPORTED_TAG' => 1,
+ 'm4_sinclude' => 1,
'AM_MAINTAINER_MODE' => 1,
'AM_NLS' => 1,
'AM_GNU_GETTEXT_INTL_SUBDIR' => 1,
- 'AM_MAKEFILE_INCLUDE' => 1,
'_m4_warn' => 1,
+ 'AM_MAKEFILE_INCLUDE' => 1,
'AM_PROG_CXX_C_O' => 1,
- '_AM_COND_ENDIF' => 1,
'_AM_MAKEFILE_INCLUDE' => 1,
+ '_AM_COND_ENDIF' => 1,
'AM_ENABLE_MULTILIB' => 1,
'AM_SILENT_RULES' => 1,
'AM_PROG_MOC' => 1,
'AC_CONFIG_FILES' => 1,
- 'LT_INIT' => 1,
'include' => 1,
- 'AM_PROG_AR' => 1,
+ 'LT_INIT' => 1,
'AM_GNU_GETTEXT' => 1,
+ 'AM_PROG_AR' => 1,
'AC_LIBSOURCE' => 1,
- 'AM_PROG_FC_C_O' => 1,
'AC_CANONICAL_BUILD' => 1,
+ 'AM_PROG_FC_C_O' => 1,
'AC_FC_FREEFORM' => 1,
'AH_OUTPUT' => 1,
- '_AM_SUBST_NOTMAKE' => 1,
'AC_CONFIG_AUX_DIR' => 1,
- 'sinclude' => 1,
- 'AM_PROG_CC_C_O' => 1,
+ '_AM_SUBST_NOTMAKE' => 1,
'm4_pattern_allow' => 1,
- 'AM_XGETTEXT_OPTION' => 1,
- 'AC_CANONICAL_SYSTEM' => 1,
+ 'AM_PROG_CC_C_O' => 1,
+ 'sinclude' => 1,
'AM_CONDITIONAL' => 1,
+ 'AC_CANONICAL_SYSTEM' => 1,
+ 'AM_XGETTEXT_OPTION' => 1,
'AC_CONFIG_HEADERS' => 1,
'AC_DEFINE_TRACE_LITERAL' => 1,
'AM_POT_TOOLS' => 1,
diff --git a/mbus/mbus-protocol.c b/mbus/mbus-protocol.c
index 4da4b45..5abed3a 100644
--- a/mbus/mbus-protocol.c
+++ b/mbus/mbus-protocol.c
@@ -25,6 +25,30 @@ static char error_str[512];
//------------------------------------------------------------------------------
static mbus_slave_data slave_data[MBUS_MAX_PRIMARY_SLAVES];
+//
+// init event callback
+//
+void (*_mbus_recv_event)(u_char src_type) = NULL;
+void (*_mbus_send_event)(u_char src_type) = NULL;
+
+//------------------------------------------------------------------------------
+/// Register a function for receive events.
+//------------------------------------------------------------------------------
+void
+mbus_register_recv_event(void (*event)(u_char src_type))
+{
+ _mbus_recv_event = event;
+}
+
+//------------------------------------------------------------------------------
+/// Register a function for send events.
+//------------------------------------------------------------------------------
+void
+mbus_register_send_event(void (*event)(u_char src_type))
+{
+ _mbus_send_event = event;
+}
+
//------------------------------------------------------------------------------
/// Return a string that contains an the latest error message.
//------------------------------------------------------------------------------
@@ -292,11 +316,11 @@ mbus_frame_verify(mbus_frame *frame)
return -1;
}
- if ((frame->control != MBUS_CONTROL_MASK_SND_NKE) &&
- (frame->control != MBUS_CONTROL_MASK_REQ_UD1) &&
- (frame->control != MBUS_CONTROL_MASK_REQ_UD1 | MBUS_CONTROL_MASK_FCB) &&
- (frame->control != MBUS_CONTROL_MASK_REQ_UD2) &&
- (frame->control != MBUS_CONTROL_MASK_REQ_UD2 | MBUS_CONTROL_MASK_FCB))
+ if ((frame->control != MBUS_CONTROL_MASK_SND_NKE) &&
+ (frame->control != MBUS_CONTROL_MASK_REQ_UD1) &&
+ (frame->control != (MBUS_CONTROL_MASK_REQ_UD1 | MBUS_CONTROL_MASK_FCB)) &&
+ (frame->control != MBUS_CONTROL_MASK_REQ_UD2) &&
+ (frame->control != (MBUS_CONTROL_MASK_REQ_UD2 | MBUS_CONTROL_MASK_FCB)))
{
snprintf(error_str, sizeof(error_str), "Unknown Control Code 0x%.2x", frame->control);
@@ -315,12 +339,12 @@ mbus_frame_verify(mbus_frame *frame)
return -1;
}
- if ((frame->control != MBUS_CONTROL_MASK_SND_UD) &&
- (frame->control != MBUS_CONTROL_MASK_SND_UD | MBUS_CONTROL_MASK_FCB) &&
- (frame->control != MBUS_CONTROL_MASK_RSP_UD) &&
- (frame->control != MBUS_CONTROL_MASK_RSP_UD | MBUS_CONTROL_MASK_DFC) &&
- (frame->control != MBUS_CONTROL_MASK_RSP_UD | MBUS_CONTROL_MASK_ACD) &&
- (frame->control != MBUS_CONTROL_MASK_RSP_UD | MBUS_CONTROL_MASK_DFC | MBUS_CONTROL_MASK_ACD))
+ if ((frame->control != MBUS_CONTROL_MASK_SND_UD) &&
+ (frame->control != (MBUS_CONTROL_MASK_SND_UD | MBUS_CONTROL_MASK_FCB)) &&
+ (frame->control != MBUS_CONTROL_MASK_RSP_UD) &&
+ (frame->control != (MBUS_CONTROL_MASK_RSP_UD | MBUS_CONTROL_MASK_DFC)) &&
+ (frame->control != (MBUS_CONTROL_MASK_RSP_UD | MBUS_CONTROL_MASK_ACD)) &&
+ (frame->control != (MBUS_CONTROL_MASK_RSP_UD | MBUS_CONTROL_MASK_DFC | MBUS_CONTROL_MASK_ACD)))
{
snprintf(error_str, sizeof(error_str), "Unknown Control Code 0x%.2x", frame->control);
@@ -3021,7 +3045,7 @@ mbus_data_variable_header_xml(mbus_data_variable_header *header)
/// Generate XML for a single variable-length data record
//------------------------------------------------------------------------------
char *
-mbus_data_variable_record_xml(mbus_data_record *record, int record_cnt, int frame_cnt)
+mbus_data_variable_record_xml(mbus_data_record *record, int record_cnt, int frame_cnt, mbus_data_variable_header *header)
{
static char buff[8192];
char str_encoded[768];
@@ -3095,7 +3119,7 @@ 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, "%s",
- mbus_data_variable_record_xml(record, i, -1));
+ mbus_data_variable_record_xml(record, i, -1, &(data->header)));
}
len += snprintf(&buff[len], sizeof(buff) - len, "\n");
@@ -3285,7 +3309,7 @@ mbus_frame_xml(mbus_frame *frame)
for (record = frame_data.data_var.record; record; record = record->next, record_cnt++)
{
len += snprintf(&buff[len], sizeof(buff) - len, "%s",
- mbus_data_variable_record_xml(record, record_cnt, frame_cnt));
+ mbus_data_variable_record_xml(record, record_cnt, frame_cnt, &(frame_data.data_var.header)));
}
// free all records in the list
@@ -3309,7 +3333,7 @@ mbus_frame_xml(mbus_frame *frame)
for (record = frame_data.data_var.record; record; record = record->next, record_cnt++)
{
len += snprintf(&buff[len], sizeof(buff) - len, "%s",
- mbus_data_variable_record_xml(record, record_cnt, frame_cnt));
+ mbus_data_variable_record_xml(record, record_cnt, frame_cnt, &(frame_data.data_var.header)));
}
// free all records in the list
diff --git a/mbus/mbus-protocol.h b/mbus/mbus-protocol.h
index cb5cbd1..2c9cc50 100644
--- a/mbus/mbus-protocol.h
+++ b/mbus/mbus-protocol.h
@@ -99,6 +99,12 @@ typedef struct _mbus_slave_data {
#define NITEMS(x) (sizeof(x)/sizeof(x[0]))
+//
+// Supported handle types
+//
+#define MBUS_HANDLE_TYPE_TCP 0
+#define MBUS_HANDLE_TYPE_SERIAL 1
+
//------------------------------------------------------------------------------
// MBUS FRAME DATA FORMATS
//
@@ -453,6 +459,17 @@ typedef struct _mbus_data_secondary_address {
#define MBUS_VARIABLE_DATA_MEDIUM_PRESSURE 0x18
#define MBUS_VARIABLE_DATA_MEDIUM_ADC 0x19
+//
+// Event callback functions
+//
+extern void (*_mbus_recv_event)(u_char src_type);
+extern void (*_mbus_send_event)(u_char src_type);
+
+//
+// Event register functions
+//
+void mbus_register_recv_event(void (*event)(u_char src_type));
+void mbus_register_send_event(void (*event)(u_char src_type));
//
// variable length records
diff --git a/mbus/mbus-serial.c b/mbus/mbus-serial.c
index 80a7b06..ecb28e9 100644
--- a/mbus/mbus-serial.c
+++ b/mbus/mbus-serial.c
@@ -166,7 +166,7 @@ mbus_serial_send_frame(mbus_serial_handle *handle, mbus_frame *frame)
fprintf(stderr, "%s: mbus_frame_pack failed\n", __PRETTY_FUNCTION__);
return -1;
}
-
+
#ifdef MBUS_SERIAL_DEBUG
// if debug, dump in HEX form to stdout what we write to the serial port
printf("%s: Dumping M-Bus frame [%d bytes]: ", __PRETTY_FUNCTION__, len);
@@ -177,7 +177,15 @@ mbus_serial_send_frame(mbus_serial_handle *handle, mbus_frame *frame)
printf("\n");
#endif
- if ((ret = write(handle->fd, buff, len)) != len)
+ if ((ret = write(handle->fd, buff, len)) == len)
+ {
+ //
+ // call the send event function, if the callback function is registered
+ //
+ if (_mbus_send_event)
+ _mbus_send_event(MBUS_HANDLE_TYPE_SERIAL);
+ }
+ else
{
fprintf(stderr, "%s: Failed to write frame to socket (ret = %d: %s)\n", __PRETTY_FUNCTION__, ret, strerror(errno));
return -1;
@@ -206,7 +214,17 @@ mbus_serial_recv_frame(mbus_serial_handle *handle, mbus_frame *frame)
do {
//printf("%s: Attempt to read %d bytes [len = %d]\n", __PRETTY_FUNCTION__, remaining, len);
- if ((nread = read(handle->fd, &buff[len], remaining)) == -1)
+ nread = read(handle->fd, &buff[len], remaining);
+
+ if (nread > 0)
+ {
+ //
+ // call the receive event function, if the callback function is registered
+ //
+ if (_mbus_recv_event)
+ _mbus_recv_event(MBUS_HANDLE_TYPE_SERIAL);
+ }
+ else if (nread == -1)
{
// fprintf(stderr, "%s: aborting recv frame (remaining = %d, len = %d, nread = %d)\n",
// __PRETTY_FUNCTION__, remaining, len, nread);
diff --git a/mbus/mbus-tcp.c b/mbus/mbus-tcp.c
index 33ad5f7..62d21e2 100644
--- a/mbus/mbus-tcp.c
+++ b/mbus/mbus-tcp.c
@@ -138,7 +138,15 @@ mbus_tcp_send_frame(mbus_tcp_handle *handle, mbus_frame *frame)
return -1;
}
- if ((ret = write(handle->sock, buff, len)) != len)
+ if ((ret = write(handle->sock, buff, len)) == len)
+ {
+ //
+ // call the send event function, if the callback function is registered
+ //
+ if (_mbus_send_event)
+ _mbus_send_event(MBUS_HANDLE_TYPE_TCP);
+ }
+ else
{
char error_str[128];
snprintf(error_str, sizeof(error_str), "%s: Failed to write frame to socket (ret = %d)\n", __PRETTY_FUNCTION__, ret);
@@ -167,8 +175,18 @@ mbus_tcp_recv_frame(mbus_tcp_handle *handle, mbus_frame *frame)
len = 0;
do {
+
+ nread = read(handle->sock, &buff[len], remaining);
- if ((nread = read(handle->sock, &buff[len], remaining)) == -1)
+ if (nread > 0)
+ {
+ //
+ // call the receive event function, if the callback function is registered
+ //
+ if (_mbus_recv_event)
+ _mbus_recv_event(MBUS_HANDLE_TYPE_TCP);
+ }
+ else if (nread == -1)
{
mbus_error_str_set("M-Bus tcp transport layer failed to read data.");
return -1;
diff --git a/test/mbus_parse_hex.c b/test/mbus_parse_hex.c
index 913b0d2..6d2d9c7 100644
--- a/test/mbus_parse_hex.c
+++ b/test/mbus_parse_hex.c
@@ -89,7 +89,8 @@ main(int argc, char *argv[])
//mbus_frame_print(&reply);
//mbus_frame_data_print(&frame_data);
- printf("%s", mbus_frame_data_xml(&frame_data));
+ printf("%s", mbus_frame_data_xml_normalized(&frame_data));
+ // printf("%s", mbus_frame_data_xml(&frame_data));
return 0;
}
diff --git a/test/test-frames/frame1.xml b/test/test-frames/frame1.xml
index 91315d9..32f246d 100644
--- a/test/test-frames/frame1.xml
+++ b/test/test-frames/frame1.xml
@@ -12,6 +12,7 @@
Manufacturer specific
+ 5F 42 01 11 FF FF FF FF 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
diff --git a/test/test-frames/kamstrup_multical_601.xml b/test/test-frames/kamstrup_multical_601.xml
index 2be75e4..7be7b49 100644
--- a/test/test-frames/kamstrup_multical_601.xml
+++ b/test/test-frames/kamstrup_multical_601.xml
@@ -4,7 +4,7 @@
6855817
KAM
8
- Heat
+ Heat: Outlet
4
00
0000
@@ -174,6 +174,7 @@
Manufacturer specific
+ 00 00 00 00 E7 E4 00 00 63 66 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5B C9 A5 02 34 53 00 00 E0 B2 03 00 89 9C 68 00 00 00 00 00 01 00 01 07 07 09 01 03 00 00 00 00 00
diff --git a/test/test-frames/svm_f22_telegram1.xml b/test/test-frames/svm_f22_telegram1.xml
index da0cc53..00e2178 100644
--- a/test/test-frames/svm_f22_telegram1.xml
+++ b/test/test-frames/svm_f22_telegram1.xml
@@ -4,7 +4,7 @@
1006089
SVM
9
- Heat (Volume measured at flow temperature: inlet)
+ Heat: Inlet
148
70
0000
@@ -89,7 +89,8 @@
- Manufacturer specific
+ More records follow
+