Versionen im Vergleich

Schlüssel

  • Diese Zeile wurde hinzugefügt.
  • Diese Zeile wurde entfernt.
  • Formatierung wurde geändert.

...

SIDENOTE: Strangely, Jablotron sends the status update also automatically, every 8 seconds. This update contains only 16 characters (8 bytes), which Loxone seems to support and parse with \h (although I haven't tested this fully so I don't know if all 8 bytes are supported). If you don't want to wait 8 seconds and want to trigger it on your own, keep reading.

This article will help you to decode any two hexadecimal characters on your own

Interpret them as \2\1:

That will give you 16-bit (big-endian word) representation of two ASCII characters. For "2A" (42 dec) on input you get 12865, because "2" is coded as 50 in ASCII, "A" as 65 in ASCII, "2" is the more significant byte => 50 * 256 + 65 = 12865. We want 42, though.

...

If FLAG is 0, then 55 is subtracted, 48 if FLAG is 1.

 


Now we need to find a way transforming the input to the flag, ie. 0 for 48..58 and 1 for 65..70. Oh look, a logarithm!

INPUTASCIIASCII-48LOG10(ASCII-48)LOG10((ASCII-48)*0.9+1)INT(LOG10((ASCII-48)*0.9+1)
'0'480n/a0,000
'1'4910,000,280
'2'5020,300,450
'3'5130,480,570
'4'5140,600,660
'5'5250,700,740
'6'5460,780,810
'7'5570,850,860
'8'5680,900,910
'9'5790,950,960
'A'65171,231,211
'B'66181,261,241
'C'67191,281,261
'D'68201,301,281
'E'69211,321,301
'F'70221,341,321

Let's put it together:

Readable implementation:

Formula on the left - just:

...

((I3 - 55) * I4 + (I3 - 48) * (1 - I4)) * 16 + ((I1 - 55) * I2 + (I1 - 48) * (1 - I2))

...


Single function block implementation:

Perfect from outside:

Unreadable from inside

...

Just cut'n paste this formula, that's it.

 


Enjoy,

  Aleš

Part 2 of Convert hexadecimal string to a number:

Convert hexadecimal string to a number (Part 2)