How to understand the functions model_delay_encode() and model_delay_decode() in light_switch example?

Hi Nordic Support Team,

uint32_t model_delay_decode(uint8_t enc_delay)
{
    return (enc_delay * DELAY_TIME_STEP_FACTOR_MS);
}

uint8_t model_delay_encode(uint32_t delay)
{
    if (delay > DELAY_TIME_STEP_MAX)
    {
        return DELAY_TIME_STEP_MAX;
    }
    else
    {
        return (delay/DELAY_TIME_STEP_FACTOR_MS);
    }
}

When decode the delay, DELAY_TIME_STEP_FACTOR_MS is used for the decoded result. However, in model_delay_encode(), if (delay > DELAY_TIME_STEP_MAX), it just returns DELAY_TIME_STEP_MAX, without being divided by DELAY_TIME_STEP_FACTOR_MS, why?  how to understand this kind of situation. 

Parents
  • Hello,

    /** Maximum encoded value of the delay field */
    #define DELAY_TIME_STEP_MAX                     (0xFF)

    Based on this, I would guess that the 0xff value is a special case where you just would want to send the maximum value. 

    However, I see that in the light_switch\client example (I don't know which one you are using), there is a check before this function is called, every time message_set_packet_create() is called, to check whether p_transition->delay_ms > DELAY_TIME_MAX_MS, so in that case, it will never happen that the delay is larger than 0xFF.

    BR,

    Edvin

Reply
  • Hello,

    /** Maximum encoded value of the delay field */
    #define DELAY_TIME_STEP_MAX                     (0xFF)

    Based on this, I would guess that the 0xff value is a special case where you just would want to send the maximum value. 

    However, I see that in the light_switch\client example (I don't know which one you are using), there is a check before this function is called, every time message_set_packet_create() is called, to check whether p_transition->delay_ms > DELAY_TIME_MAX_MS, so in that case, it will never happen that the delay is larger than 0xFF.

    BR,

    Edvin

Children
Related