Serial Extended Level Parsing

Discussion in 'C-Bus Toolkit and C-Gate Software' started by mrgadget, Feb 9, 2011.

  1. mrgadget

    mrgadget

    Joined:
    Feb 9, 2011
    Messages:
    2
    Likes Received:
    0
    Location:
    Hastings, NZ
    Hi,

    Long-time reader, first time poster.

    I've been working with the serial protocol for a while, and have come up against something I just can't figure out. I'm hoping that someone with superior knowledge can tell me!

    I'm requesting the status levels and getting back the nibble pairs. Where I'm falling short is being able to mathematically translate these to a group level. In the doco(pg.48), they state that;
    • $5=11
    • $6=10
    • $9=01
    • $A=11
    How!? The document describes this conversion as nibble->binary. The second step from binary to hex isn't an issue.

    Any ideas would be greatly appreciated!

    Cheers,
    Ben :)
     
    mrgadget, Feb 9, 2011
    #1
  2. mrgadget

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    A "5" in the status reply represents a binary value of 11. A "6" represents binary 10 and so on. There is a good reason for this, but it isn't important for understanding how to do the decoding.

    So if there is a "56" in the status reply, this is equivalent to binary 1110 or hexadecimal "E".

    The example provided shows the rest of the details for decoding a full message.
     
    Darren, Feb 9, 2011
    #2
  3. mrgadget

    mrgadget

    Joined:
    Feb 9, 2011
    Messages:
    2
    Likes Received:
    0
    Location:
    Hastings, NZ
    Hi Darren,

    Thanks for the response. I understand what you mean, and I've got no problems manually decoding it via the table/method on pg 48 of that doc, the issue I have is doing it programatically without using textual replacements.

    Surely there must be a mathematical correlation for this first step? Once the nibble pairs are converted to binary, the hex conversion is easy.

    Cheers,
    Ben
     
    Last edited by a moderator: Feb 9, 2011
    mrgadget, Feb 9, 2011
    #3
  4. mrgadget

    daniel C-Busser Moderator

    Joined:
    Jul 26, 2004
    Messages:
    770
    Likes Received:
    21
    Location:
    Adelaide
    Hi Ben,

    The doco actually states (correction in bold):

    • $5 => 11
    • $6 => 10
    • $9 => 01
    • $A => 00

    I'm sure you probably know already but thought I should mention it just in case someone uses this thread as a reference.

    Anyway, essentially you are just excluding the even bits.

    $5 => 0101 => 11
    $9 => 1001 => 01

    Mathematically, x = ( n & 0x01 ) + ( n & 0x04 >> 1 )

    where n is the nibble.

    Hope this helps!
     
    Last edited by a moderator: Feb 9, 2011
    daniel, Feb 9, 2011
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.