1 behavior / 2 implementations

Hello,

I have a sputid question about C;

I OSv3_decode.pde on lostbyte.net,
i found this code :

uint short_count;
...
short_count++;
...
If (short_count > 20)

and at jeelabs on ookDecode ( part about os v3)
I found

byte flip;
...
++flip;
...
if (32 <= flip)

The code do the same, but what decide if we check about 20 or 32, because 20 is 32 in hexa. But Why not using 0x20. I don't understand when i need to give hex value and when i need to give dec value.

I don't understand when i need to give hex value and when i need to give dec value.

It isn't clear that the 32 in one program is supposed to be the same as 20 in the other program. Both look like base 10 numbers to me.

As for whether to use 0x20 or 32 in a given situation, use the one that makes the most sense. They are, after all, the same value.

Personally I prefer HEX when doing bit manipulating, masking or when individual bits have a distinct meaning. NB in a HEX value the individual bits are easily identified - each hex digit is a group of 4 bits.

It isn't clear that the 32 in one program is supposed to be the same as 20 in the other program. Both look like base 10 numbers to me.

in this case, the 2 does the same, counting pulse before data. and it is for same protocol ( oregon v3 ).

But I don't understand how i can figure it is an Hex value or not when reading code.

You need to post links to the code in question, or the actual code. 20 and 32 are not the same value. 0x20 and 32 are.

If (short_count > 20)

is not even legal C.

[edit]Scratch that; 'If' could be a user-defined function.
But then it would need a semicolon. [/edit]

here are the links :

http://www.lostbyte.com/wp-content/uploads/2010/04/osv3_decode.zip (at line 100)
and
http://jeelabs.net/attachments/365/Ook_OSV2.pde (at line 192)

the code dot the same : count the short pulse to determine the preamble.
the amount of short pulse must be the same, this is for decoding same protocol !

The line I compare are about to decode OS V3 (even if second is named OSV2, it decode also OSV3)

You missed one AWOL

#define If if

:wink:

Line 100:

      if(short_count > SYNC_COUNT)

Line 192:

                    else if (32 <= flip) {

Earlier in the first code,

#define SYNC_COUNT                              20

I do not get where they are doing the same thing or counting the same thing.

logic of the code is this :

interrupt fired at each pulse with duration ( short pulse and long pulse )

os v3 says communication packet are like this :

32 preamble short pulses,
start bit is a long pulse
...

in the two code, pulse are counted to determine end of preambule.

one is 20 one is 32.

So because nobody can give an explanation, is suppose that one of the two code is wrong ?

Hello,

I had some explanation from the dev of one of the 2 sketch.

In fact there is 32 pulse as preamble, BUT it is not mandatory to catch all, sync is done by the first bit after preamble.

As he says, preamble is done to prepare receiver to accept data.

thanks to all to try to explain me :wink: