Following situation:
My system gets an hardware signal and writes a time value to a buffer in my signal handler routine. Afterwards a (software) signal is sent with the time value as argument to the appropriate slot function. The slot routine gets called correctly, but here my problem lays in:
In the slot function I have a simple switch-case statement like this:
switch(id) {
case 1:
do something..
id = 2;
break;
case 2:
start_time = val;
id = 3;
break;
case 3:
end_time = val;
id = 1;
break;
}
In those three cases I store a start and end time value between case 2 and 3 and out of those time values I determine the elapsed time between the hardware signals. This works fine, but now I have to measure the time sometimes "longer", depening on parameter. This means, I can't stop the measurement at case 3 instead I have case 4, 5, 6 and so on . What is an elegant and optimal solution for this "problem" instead of writing:
if (param < xy) {
switch(id) {
case 1:
...
break;
case 2:
...
break;
} else if (param > xy) {
switch(id) {
case 1:
...;
break;
case 2:
...;
break;
case 3:
...;
break;
case 4:
...;
break;
case 5:
...;
break;
}
}
}