Implement mbus_set_primary_address()
This function sends a frame to change primary address of a slave.
This commit is contained in:
@ -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.
|
||||
|
@ -307,6 +307,17 @@ int mbus_send_request_frame(mbus_handle * handle, int address);
|
||||
*/
|
||||
int mbus_send_user_data_frame(mbus_handle * handle, int address, const unsigned char *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Sends frame to change primary address of given slave using "unified" handle
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param old_address Old Address (0-255)
|
||||
* @param new_address New Address (0-250)
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_set_primary_address(mbus_handle * handle, int old_address, int new_address);
|
||||
|
||||
/**
|
||||
* Sends a request and read replies until no more records available
|
||||
* or limit is reached.
|
||||
|
Reference in New Issue
Block a user