<NWK_LAYERED>
Initialize in setup()
as follows. Assign the role as a parent using NWK_LAYERED::ROLE_PARENT
.
##include <NWK_LAYERED>
void setup() {
...
auto&& nwk_ly = the_twelite.network.use<NWK_LAYERED>();
nwk_ly << NWK_LAYERED::network_role(NWK_LAYERED::ROLE_PARENT);
// set a role as parent.
}
When a packet is received, on_rx_packet()
is called similarly to NWK_SIMPLE
.
void on_rx_packet(packet_rx& rx, bool_t &handled) {
auto type = rx.get_network_type();
if (type == mwx::NETWORK::LAYERED) {
; // Packet of layered tree network
handled = true; // Mark as handled
}
}
rx
is a class that wraps packet information. Internally, except for setting an internal flag for the processing of _get_network_type()
, no modification of packet information is performed.
In other words, by referring to rx.get_psRxDataApp()
, which returns tsRxDataApp*
, you can obtain the same packet information as in the TWENET C library. packet_rx
defines some procedures to access this information, but the information obtained does not change.
Using with NWK_SIMPLE
When used together with NWK_SIMPLE
, assign NWK_LAYERED
to the_twelite.network
and NWK_SIMPLE
to the_twelite.network2
.
##include <NWK_LAYERED>
##include <NWK_SIMPLE>
void setup() {
...
auto&& nwk_ly = the_twelite.network.use<NWK_LAYERED>();
auto&& nwk_sm = the_twelite.network2.use<NWK_SIMPLE>();
}
void on_rx_packet(packet_rx& rx, bool_t &handled) {
auto type = rx.get_network_type();
if (type == mwx::NETWORK::LAYERED) {
; // Packet of layered tree network
}
else if (type == mwx::NETWORK::SIMPLE) {
; // Packet of NWK_SIMPLE
}
else if (type == mwx::NETWORK::NONE) {
; // Normal app (such as App_Twelite)
}
else {
; // Uninterpretable packet
}
// Mark the packet as handled, and prevent further intervention by the MWX library.
handled = true;
}
Each packet type is identified by .get_network_type()
as shown above.
mwx::NETWORK::LAYERED
: Refer to the packet information as is.mwx::NETWORK::SIMPLE
: Follow the processing ofNWK_SIMPLE
.mwx::NETWORK::NONE
: No network processing or duplicate packet handling is performed. For example, in the standard App_Twelite application, three packets including retransmissions are sent per transmission. If all packets are successfully received,on_rx_packet()
will be called three times. Usually, receiving three times does not mean the data from the 2nd and 3rd receptions is needed. You need to add processing for duplicate packets.
For examples, please refer to Act_Samples Rcv_Univsl
. It handles reception of packets with the same wireless channel and application ID but different types in TWELITE PAL, Act_samples, and App_Twelite. Additionally, duplicate check processing is provided for App_Twelite.