Is Luos for me? 🤔

Detection side effects on your device applications

Symptom(s)

An application can auto-update a data from a driver in a Luos system. However, after running a detection from another application or by using a gate, the application doesn't seem to retrieve data anymore. Using the gate you can still detect the packages of the system and can retrieve the data from the driver, as well as see the application running.

Possible explanation

When you plug a gate in a Luos system, it will automatically asks to perform a detection, making the drivers' IDs to change. If you start a detection with another application the effect will be the same. When a detection occurs, Luos removes all auto-update automation, and doing so avoids any troubles regarding the destination movement. So the application is not able to retrieve data from the driver anymore.

If you already managed the re-detection on your app, the problem should come from the gate's configuration. By default a gate initiates an auto-update to all the services available on the network, improving its performance. But if you plan to have an application also using this feature on your network, you don't want the gate to make the auto-update anymore. You can avoid it by configuring your gate in GATE_POLLING mode. To do that, add #define GATE_POLLING in the file node_config.h. The entire list of gate's configuration is available in the gate_config.h file.

Resolution

To make it resistant to detection, you need to reconfigure the driver's auto-update from the application that calls it, after each detection. You have to manage this configuration in a loop, and catch the application's ID changes.

Example

A button-LED application that turns the LED on and off with a button. It contains:

  • 1 LED package (Driver)
  • 1 button package (Driver)
  • 1 led_control package (Application)

The application called led_control gets the state of the button and turns on the LED. To do it, the button's driver sends information on its state every 100ms to the application. Here is the initialization of this application:

Initial code

uint16_t id_led, id_but;
void LedControl_MsgHandler(container_t *container, msg_t *msg)
{
    if (msg->header.cmd == IO_STATE)
    {
        // This is a message from the button, update the LED state
        msg_t pub_msg;
        pub_msg.header.target      = id_led;
        pub_msg.header.target_mode = IDACK;
        pub_msg.header.cmd         = IO_STATE;
        pub_msg.header.size        = 1;
        pub_msg.header.data[0]     = msg->header.data[0];
        Luos_SendMsg(container, &pub_msg);
    }
}
 void LedControl_Init(void)
{
    revision_t revision = {.unmap = [0.0.1]};
    container_t* app = Luos_CreateContainer(LedControl_MsgHandler, LEDCONTROL_APP, "App_LedControl", revision);
    //Detect all containers of the network and create a routing_table
    RoutingTB_DetectContainers(app);
    //Get the ID of our LED from the routing table
    id_led = RoutingTB_IDFromAlias("myled");
    id_but = RoutingTB_IDFromAlias("mybutton");
    //Auto-update messages
    msg_t msg;
    msg.header.target      = id_but;
    msg.header.target_mode = IDACK;
    time_luos_t time       = TimeOD_TimeFrom_ms(100.0);
    TimeOD_TimeToMsg(&time, &msg);
    msg.header.cmd = UPDATE_PUB;
    Luos_SendMsg(app, &msg);
}

Here is how to reconfigure after a detection:

Solution

 void LedControl_Loop(container_t *container, msg_t *msg)
    {
        static uint16_t previous_id = -1; allowing us to monitor the detection state
        // Check the detection status.
    if (RoutingTB_IDFromContainer(app) == 0)
    {
        // No ID, meaning either no detection occured, or a detection is occuring right now.
        if (previous_id == -1)
        {
            // This is the start period, we have to make a detection.
            // Be sure the network is powered-up 20 ms before starting a detection
            if (Luos_GetSystick() > 20)
            {
                // No detection occured, do the detection
                RoutingTB_DetectContainers(app);
            }
        }
        else
        {
            // A detection is being made, we let it finish.
            // reset the previous_id state to be ready to setup container at the end of detection:
            previous_id = 0;
        }
    }
        else
        {
            if (RoutingTB_IDFromContainer(app) != previous_id)
            {
                // This is the first loop execution after a detection, here goes the initial configuration:
                    
            //Get the ID of our LED from the routing table
            id_led = RoutingTB_IDFromAlias("myled");
            id_but = RoutingTB_IDFromAlias("mybutton");
            //Auto-update messages
            msg_t msg;
            msg.header.target      = id_but;
            msg.header.target_mode = IDACK;
            time_luos_t time       = TimeOD_TimeFrom_ms(100.0);
            TimeOD_TimeToMsg(&time, &msg);
            msg.header.cmd = UPDATE_PUB;
            Luos_SendMsg(app, &msg);
            }
        }
    }


Associated documentation page(s):