add new function to send application reset incl. subcode

fix typo in comment
add new program to test experimental feature application reset
add mbus-tcp-application-reset to build process
This commit is contained in:
Stefan Wahren 2013-04-27 13:16:44 +02:00
parent f6601ca40f
commit e1657399ff
3 changed files with 71 additions and 2 deletions

View File

@ -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-tcp-select-secondary mbus-tcp-scan-secondary \
mbus-serial-scan mbus-serial-request-data mbus-serial-request-data-multi-reply \ mbus-serial-scan mbus-serial-request-data mbus-serial-request-data-multi-reply \
mbus-serial-select-secondary mbus-serial-scan-secondary \ 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 # tcp
mbus_tcp_scan_LDFLAGS = -L$(top_builddir)/mbus 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_LDADD = -lmbus -lm
mbus_tcp_raw_send_SOURCES = mbus-tcp-raw-send.c 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 # serial
mbus_serial_scan_LDFLAGS = -L$(top_builddir)/mbus mbus_serial_scan_LDFLAGS = -L$(top_builddir)/mbus

View File

@ -1711,6 +1711,61 @@ mbus_send_switch_baudrate_frame(mbus_handle * handle, int address, int baudrate)
return retval; 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 // send a request packet to from master to slave
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -246,7 +246,7 @@ int mbus_purge_frames(mbus_handle * handle);
int mbus_send_frame(mbus_handle * handle, mbus_frame *frame); 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 handle Initialized handle
* @param secondary_addr_str Secondary address * @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); 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 * Sends switch baudrate frame using "unified" handle
* *