<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Jul 9, 2017 12:06, "Dirk Hohndel" <<a href="mailto:dirk@hohndel.org">dirk@hohndel.org</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Your code is a lot more beautiful and better structured> +     if (state >= 1 && state <= 7) {<br>
> +             static const char *states[8] = {<br>
> +                     "",             // 000 - No state bits, not used<br>
> +                     "normal",       // 001 - only normal<br>
> +                     "critical",     // 010 - only critical<br>
> +                     "critical",     // 011 - both normal and critical<br>
> +                     "warning",      // 100 - only warning<br>
> +                     "warning",      // 101 - normal and warning<br>
> +                     "critical",     // 110 - warning and critical<br>
> +                     "critical",     // 111 - normal, warning and critical<br>
<br>
I know that this is wrong. The state is '0' when the battery is normal.<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">Look again.</div><div dir="auto"><br></div><div dir="auto">That's a *bitmap* of the states we've seen.</div><div dir="auto"><br></div><div dir="auto">So state 0 becomes *bit* zero, which has value 1.</div><div dir="auto"><br></div><div dir="auto">State 1 (critical) becomes bit 1, so value 2.</div><div dir="auto"><br></div><div dir="auto">If the dive saw pressures with both normal and critical states, at have both bit zero and bit one set, so 3.</div><div dir="auto"><br></div><div dir="auto">So the only time you see zero is when *no* state bits are set.</div><div dir="auto"><br></div><div dir="auto">Now, I haven't *tested* any of this, since I don't have any pressure data.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I haven't seen warning or critical, yet, but I bet that they meant the<br>
comment quite literally: the top four bits give you values from 0 to 15, 0<br>
is normal, 1 is critical, 2 is warning, rest is unused. Being able to<br>
combine them like bits would be just weird and nonsensical. What on earth<br>
does it mean to be both normal and critical?</blockquote></div></div></div><div dir="auto">.</div><div dir="auto">Those boots come in every sample. So normal and critical means that at saw different samples - some with normal battery and some with critical.</div><div dir="auto"><br></div><div dir="auto">And that *is* meaningful, and it's interesting data - it may mean that the battery is on the edge.</div><div dir="auto"><br></div><div dir="auto">Also, the four upper bits may end up having other meaning too. I didn't want to bother putting in the "no communication" state bits, because I wonder whether you might get those at the beginning and/or end of dives, but it might we'll be interesting to see that you lost communication during the dive for a while. Again, that shouldn't overwrite the other cases, but exactly *because* this is a bitmap of all the states we've seen, it's quite reasonable and possible.</div><div dir="auto"><br></div><div dir="auto">So please rethink.</div><div dir="auto"><br></div><div dir="auto">Because you're code was uglier, and it literally threw data away by just looking at the last sample with transmitter data.</div><div dir="auto"><br></div><div dir="auto">What if the transmitter was critical during the middle of the dive because it got cold, but then warmed up as you ascended, and was only warning at the end of the dive? Your code - because it only remembered one value - couldn't handle that.</div><div dir="auto"><br></div><div dir="auto">The bitmap code handles it very naturally, along with other potential flags.</div><div dir="auto"><br></div><div dir="auto">     Linus</div></div>