diff --git a/bin/Makefile.am b/bin/Makefile.am index 82b8446..e3cb10b 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -17,7 +17,7 @@ bin_PROGRAMS = mbus-tcp-scan mbus-tcp-request-data mbus-tcp-request-data-multi mbus-tcp-select-secondary mbus-tcp-scan-secondary \ mbus-serial-scan mbus-serial-request-data mbus-serial-request-data-multi-reply \ mbus-serial-select-secondary mbus-serial-scan-secondary \ - mbus-serial-switch-baudrate mbus-tcp-raw-send + mbus-serial-switch-baudrate mbus-tcp-raw-send mbus-tcp-application-reset # tcp mbus_tcp_scan_LDFLAGS = -L$(top_builddir)/mbus @@ -44,6 +44,9 @@ mbus_tcp_raw_send_LDFLAGS = -L$(top_builddir)/mbus mbus_tcp_raw_send_LDADD = -lmbus -lm mbus_tcp_raw_send_SOURCES = mbus-tcp-raw-send.c +mbus_tcp_application_reset_LDFLAGS = -L$(top_builddir)/mbus +mbus_tcp_application_reset_LDADD = -lmbus -lm +mbus_tcp_application_reset_SOURCES = mbus-tcp-application-reset.c # serial mbus_serial_scan_LDFLAGS = -L$(top_builddir)/mbus diff --git a/mbus/mbus-protocol-aux.c b/mbus/mbus-protocol-aux.c index b09a643..08e5d8c 100755 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -1711,6 +1711,61 @@ mbus_send_switch_baudrate_frame(mbus_handle * handle, int address, int baudrate) return retval; } +//------------------------------------------------------------------------------ +// send a user data packet from master to slave: the packet resets +// the application layer in the slave +//------------------------------------------------------------------------------ +int +mbus_send_application_reset_frame(mbus_handle * handle, int address, int subcode) +{ + int retval = 0; + mbus_frame *frame; + + if (mbus_is_primary_address(address) == 0) + { + MBUS_ERROR("%s: invalid address %d\n", __PRETTY_FUNCTION__, address); + return -1; + } + + if (subcode > 0xFF) + { + MBUS_ERROR("%s: invalid subcode %d\n", __PRETTY_FUNCTION__, subcode); + return -1; + } + + frame = mbus_frame_new(MBUS_FRAME_TYPE_LONG); + + 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 = MBUS_CONTROL_INFO_APPLICATION_RESET; + + if (subcode >= 0) + { + frame->data_size = 1; + frame->data[0] = (subcode & 0xFF); + } + else + { + frame->data_size = 0; + } + + 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 //------------------------------------------------------------------------------ diff --git a/mbus/mbus-protocol-aux.h b/mbus/mbus-protocol-aux.h index 7d996a1..dc655d3 100755 --- a/mbus/mbus-protocol-aux.h +++ b/mbus/mbus-protocol-aux.h @@ -246,7 +246,7 @@ int mbus_purge_frames(mbus_handle * handle); int mbus_send_frame(mbus_handle * handle, mbus_frame *frame); /** - * Sends secodary address selection frame using "unified" handle + * Sends secondary address selection frame using "unified" handle * * @param handle Initialized handle * @param secondary_addr_str Secondary address @@ -255,6 +255,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 application reset to given slave using "unified" handle + * + * @param handle Initialized handle + * @param address Address (0-255) + * @param subcode Subcode (0-255) or no subcode (-1) + * + * @return Zero when successful. + */ +int mbus_send_application_reset_frame(mbus_handle * handle, int address, int subcode); + /** * Sends switch baudrate frame using "unified" handle *