MQTT-SN Gateway Library
Library that allows implementation of MQTT-SN gateway.
|
Interface for Gateway entity.
The responsibility of the Gateway object is to advertise its presence to all MQTT-SN clients on the network. It requests the driving code to send serialised ADVERTISE message periodically, using provided callback.
Public Types | |
using | NextTickProgramReqCb = std::function< void(unsigned ms)> |
Type of the callback used to request time measurement. | |
using | SendDataReqCb = std::function< void(const std::uint8_t *buf, std::size_t bufSize)> |
Type of callback used to request send the serialised ADVERTISE message. | |
Public Member Functions | |
Gateway () | |
Default constructor. | |
~Gateway () | |
Destructor. | |
void | setNextTickProgramReqCb (NextTickProgramReqCb &&func) |
Set the callback to be invoked when new time measurement is required. | |
void | setSendDataReqCb (SendDataReqCb &&func) |
Set the callback to be invoked when new ADVERTISE message needs to be broadcasted. | |
void | setAdvertisePeriod (std::uint16_t value) |
Set period after which ADVERTISE message needs to be constatly sent. | |
std::uint16_t | getAdvertisePeriod () const |
Get current configuration of the ADVERTISE message period. | |
void | setGatewayId (std::uint8_t value) |
Set gateway numeric ID to be advertised. | |
std::uint8_t | getGatewayId () const |
Get current gateway numeric ID configuration. | |
bool | start () |
Start the operation of the object. | |
void | stop () |
Stop the operation of the object. | |
void | tick () |
Notify the Gateway object about requested time period expiry. | |
using cc_mqttsn_gateway::Gateway::NextTickProgramReqCb = std::function<void (unsigned ms)> |
Type of the callback used to request time measurement.
The driving code is expected to invoke tick() member function when the requested time expires. The callback is set using setNextTickProgramReqCb() member function.
[in] | ms | Number of milliseconds to measure. |
using cc_mqttsn_gateway::Gateway::SendDataReqCb = std::function<void (const std::uint8_t* buf, std::size_t bufSize)> |
Type of callback used to request send the serialised ADVERTISE message.
According to MQTT-SN protocol, the ADVERTISE message needs to be broadcasted. The driving code is responsible to broadcast the requested message to all possible clients on the network. The callback is set using setSendDataReqCb() member function.
The buffer containing serialised ADVERTISE message belongs to the internal data structures of the Gateway, and may be tampered with when the callback function returns. The driving code may be required to copy contents of the buffer to its internal data structures and preserve it until send over I/O link operation is complete.
[in] | buf | Pointer to buffer containing serialised ADVERTISE message. |
[in] | bufSize | Number of bytes in the buffer. |
void cc_mqttsn_gateway::Gateway::setAdvertisePeriod | ( | std::uint16_t | value | ) |
Set period after which ADVERTISE message needs to be constatly sent.
The value must be greater than 0. If the value is not set, the object can not be started (see start()).
[in] | value | Advertise period in seconds. |
void cc_mqttsn_gateway::Gateway::setGatewayId | ( | std::uint8_t | value | ) |
Set gateway numeric ID to be advertised.
If not set, default value 0 is assumed.
[in] | value | Gateway numeric ID. |
void cc_mqttsn_gateway::Gateway::setNextTickProgramReqCb | ( | NextTickProgramReqCb && | func | ) |
Set the callback to be invoked when new time measurement is required.
This is a must have callback, without it the object can not be started (see start()).
[in] | func | R-value reference to the callback object |
void cc_mqttsn_gateway::Gateway::setSendDataReqCb | ( | SendDataReqCb && | func | ) |
Set the callback to be invoked when new ADVERTISE message needs to be broadcasted.
This is a must have callback, without it the object can not be started (see start()).
[in] | func | R-value reference to the callback object |
bool cc_mqttsn_gateway::Gateway::start | ( | ) |
Start the operation of the object.
The function will check whether all callbacks as well as advertise period have been properly set. It will also immediately request to send the serialised ADVERTISE message and to re-program the timer for the tick() after set advertise period.
void cc_mqttsn_gateway::Gateway::tick | ( | ) |
Notify the Gateway object about requested time period expiry.
This function needs to be called from the driving code after the requested time measurement has expired. The call will cause invocation of send data request callback as well as new time measurement request callback.