Implement mbus_set_primary_address()

This function sends a frame to change primary address of a slave.
This commit is contained in:
Stefan Wahren
2018-03-21 21:29:44 +01:00
parent 2680079db4
commit 73d58a9f7d
2 changed files with 38 additions and 0 deletions

View File

@ -1981,6 +1981,33 @@ mbus_send_user_data_frame(mbus_handle * handle, int address, const unsigned char
return retval;
}
//------------------------------------------------------------------------------
// send a request from master to slave in order to change the primary address
//------------------------------------------------------------------------------
int
mbus_set_primary_address(mbus_handle * handle, int old_address, int new_address)
{
/* primary address record, see chapter 6.4.2 */
unsigned char buffer[3] = { 0x01, 0x7A, new_address };
if (mbus_is_primary_address(new_address) == 0)
{
MBUS_ERROR("%s: invalid address %d\n", __PRETTY_FUNCTION__, new_address);
return -1;
}
switch (new_address)
{
case MBUS_ADDRESS_NETWORK_LAYER:
case MBUS_ADDRESS_BROADCAST_REPLY:
case MBUS_ADDRESS_BROADCAST_NOREPLY:
MBUS_ERROR("%s: invalid address %d\n", __PRETTY_FUNCTION__, new_address);
return -1;
}
return mbus_send_user_data_frame(handle, old_address, buffer, sizeof(buffer));
}
//------------------------------------------------------------------------------
// send a request from master to slave and collect the reply (replies)
// from the slave.