We look at the basic implementation of a repeater.
The relay provides a function of relaying in response to network requirements, but can also perform other tasks such as transmitting sensor information. As a rule, they are always powered.
Relay packets are not processed by the cbToCoNet_vRxEvent() callback. Packets that arrive directly at the relay (e.g. packets from a transmit-only child) are processed.
void cbToCoNet_vRxEvent(tsRxDataApp *pRx) {
uint8 *p = pRx->auData;
// Show packets
if (pRx->u8Cmd == TOCONET_PACKET_CMD_APP_DATA) {
// Basic information
uint8 u8lqi_1st = pRx->u8Lqi; // LQI
uint32 u32addr_1st = pRx->u32SrcAddr; // Sender
// Interpreting the data
uint8 u8b = G_OCTET();
...
}
}
vProcessEvCore()
On system start-up E_EVENT_START_UP of the data, set the tsToCoNet_NwkLyTr_Config structure, execute the ToCoNet_NwkLyTr_psConfig() function, initialize the network with the ToCoNet_Nwk_bInit() function and start the network with the ToCoNet_Nwk_bStart() function.
The setting must specify the repeater (TOCONET_NWK_ROLE_ROUTER), the number of layers, and the NB beacon (TOCONET_MOD_LAYERTREE_STARTOPT_NB_BEACON).
We get E_EVENT_TOCONET_NWK_START event after network start. It also receives E_EVENT_TOCONET_NWK_DISCONNECT if the upper node is lost.
static tsToCoNet_NwkLyTr_Config sNwkLayerTreeConfig;
static tsToCoNet_Nwk_Context* pContextNwk;
static void vProcessEvCore(tsEvent *pEv, teEvent eEvent, uint32 u32evarg) {
switch (pEv->eState) {
case E_STATE_IDLE:
if (eEvent == E_EVENT_START_UP) {
memset(&sNwkLayerTreeConfig, 0, sizeof(sNwkLayerTreeConfig));
// Determination of the number of layers
sNwkLayerTreeConfig.u8Layer = 4;
// Use of NB beacon-based networks
sNwkLayerTreeConfig.u8StartOpt =
TOCONET_MOD_LAYERTREE_STARTOPT_NB_BEACON;
// Starts as a repeater
sNwkLayerTreeConfig.u8Role = TOCONET_NWK_ROLE_ROUTER;
pContextNwk = ToCoNet_NwkLyTr_psConfig(&sNwkLayerTreeConfig);
if (pContextNwk) {
ToCoNet_Nwk_bInit(pContextNwk);
ToCoNet_Nwk_bStart(pContextNwk);
} else {
// fatal error
}
}
break;
default:
break;
}
}