>> @@ -100,6 +113,12 @@ double servo_sample(struct servo *servo,
>> 
>>      if (*state != SERVO_UNLOCKED)
>>              servo->first_update = 0;
>> +    else
>> +            servo->curr_offset_values = servo->num_offset_values;
>> +
>> +    if (*state == SERVO_LOCKED && check_offset_threshold(servo, offset)) {
>> +            *state = SERVO_LOCKED_STABLE;
>> +    }
> 
> This is getting hard to follow.  Time for switch/case(*state) with all the
> cases listed explicitly.
> 
After pondering a little bit more, I think that switch/case is not suitable in 
this scenario. The current we switch/case is implemented is as follows:

switch (*state) {
        case SERVO_UNLOCKED:
                servo->curr_offset_values = servo->num_offset_values;
                break;
        case SERVO_LOCKED:
                if (check_offset_threshold(servo, offset)) {
                        *state = SERVO_LOCKED_STABLE;
                }
                /* fall through. */
        case SERVO_JUMP:
                servo->first_update = 0;
                break;
        case SERVO_LOCKED_STABLE:
                break;
        }

But, here SERVO_LOCKED_STABLE case will never occur. Also, if we decide to move 
out the check_offset_threshold() check outside the switch case so that 
SERVO_LOCKED_STABLE case is able to execute, the "servo->curr_offset_values = 
servo->num_offset_values;” should also be done before that whenever we reset 
the state and state is moved to SERVO_UNLOCKED. So, there is a lot of 
interdependency within the code in this switch-case statement and it will 
probably be cleaner to keep it as if-else.

Thanks,
Vedang

> Thanks,
> Richard


_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to