Is is possible to switch between radios in Contiki NG during runtime (change NETSTACK_RADIO struct)?

76 Views Asked by At

I am having difficulty changing the NETSTACK_RADIO struct in Contiki NG to switch between 2 radios with Zolertia Firefly, since it is defined as preprocessor directives.

/* Radio driver configuration. Most often set by the platform. */
#ifdef NETSTACK_CONF_RADIO
#define NETSTACK_RADIO NETSTACK_CONF_RADIO

How can I configure radio switching in Contiki NG during execution, and is this even possible?

I tried following but it does not work.

myapp.c file extract


        /* Switch to the other radio */
        if (NETSTACK_RADIO.get_object == NETSTACK_CONF_RADIO.get_object) {
            NETSTACK_RADIO.set_object(NETSTACK_CONF_RADIO_SUBGHZ.get_object); 
        } 
        else if (NETSTACK_RADIO.get_object == NETSTACK_CONF_RADIO_SUBGHZ.get_object) {
            NETSTACK_RADIO.set_object(NETSTACK_CONF_RADIO.get_object);
        }

project-conf.h file

#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_

/* Enable the cc2420 radio driver */
#define NETSTACK_CONF_RADIO cc2538_rf_driver

/* Enable the sub-ghz radio driver */
#define NETSTACK_CONF_RADIO_SUBGHZ cc1200_driver



#endif /* PROJECT_CONF_H_ */
1

There are 1 best solutions below

0
Pasan Samarakkody On

Application file

int dual_radio_switch(int radio)
{
    if (radio == LONG_RADIO)
    {
        // long_range_radio = 1;
        *NETSTACK_CONF_RADIO = &cc1200_driver;
        *NETSTACK_RADIO = &cc1200_driver;
    }
    else if (radio == SHORT_RADIO)
    {
        // long_range_radio = 0;
        *NETSTACK_CONF_RADIO = &cc2538_rf_driver;
        *NETSTACK_RADIO = &cc2538_rf_driver;
    }
    return 1;
}

project-conf.h file

#ifndef SHORT_RADIO
#define SHORT_RADIO 2
#endif

#ifndef LONG_RADIO
#define LONG_RADIO 1
#endif

extern const struct radio_driver *NETSTACK_CONF_RADIO;
extern const struct radio_driver *NETSTACK_RADIO;

This is another solution I tried but it does not work. It fails to change NETSTACK_RADIO at runtime.

References used:

https://docs.contiki-ng.org/en/develop/

https://github.com/Apress/Prac-Contiki-Program-Wireless-Sens-Networks

J. Jung, J. Hong and Y. Yi, "On Self-Configuring IoT With Dual Radios: A Cross-Layer Approach" in IEEE Transactions on Mobile Computing, vol. 21, no. 11, pp. 4064-4077, 2022. doi: 10.1109/TMC.2021.3066441

https://github.com/mp3jjk/SEDA-Net