checksum function for sending serial bytes

Hi all. Been away from propeller for a while and a little rusty now.
What I'm needing to do is send a byte stream to a 4D display. This will be 6 bytes. Five data and one checksum. Id like to make a function that accepts the 5 bytes and makes a checksum and then sends the 6 bytes out serial. What would be the best way to go about this? The checksum is just the 5 byte xor'd together.
I think I would start another PUB and then call it from the main with 5 parameters?
Any quick examples to start with would be appreciated.
Thanks

Comments

  • CRST1CRST1 Posts: 49
    edited 2019-11-04 - 05:08:11
    Also fullduplexserial has a tx(byte) function. I'm a little confused on how to send multiple bytes. I have sent separate tx commands one after the other. Is there a way to send multiples like tx(1A, 9C. 10) or tx.byte(19 & 10 & 32).
    I saw someone said use tx.str(string($80, 2, 2)) aslong as not sending 0
    I will need to send 0.

  • Tracy AllenTracy Allen Posts: 6,402
    edited 2019-11-07 - 19:38:29
    You can add a method to fullDuplexSerial or to your main code, to send a counted string:
    PUB StrN(stringptr,nchar)
    '' Send counted string, nulls okay
      repeat nchar
        tx(byte[stringptr++])
    
    That is pretty much the way you are doing it. tx[byte] at a time. There is also a way to transfer packets, multiple bytes at once to the transmit buffer, using bytemove instructions. That is useful for high baud rates and large packets, but for your purposes one tx[byte] at a time may well be fast enough.

    For the checksum, you could roll it into the transmit routine.
    PUB StrN(stringptr,nchar) : check | bite
    '' Send nchar counted string, append simple checksum
      repeat nchar
         bite := byte[stringptr++]
         check := check ^ bite
         [s]tx(byte[bite])[/s]  tx(bite) .  ' per comments below
      tx(check)
    
  • Thanks I'll start with this and see what I can do
  • Shouldn't
    tx(byte[bite])
    
    be
    tx(bite)
    
    ??
    When the going gets weird, the weird turn pro. -- HST

    my site: 1uffakind.com
    create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
    resistor ladder tool: 1uffakind.com/robots/resistorLadder.php
    convert images to ascii art: 1uffakind.com/apptoys/convtoascii/
    MC6808/Hero-1 assembler: 1uffakind.com/apptoys/onlinecompilers/MC6800/
  • yes
    I am just another Code Monkey.
    A determined coder can write COBOL programs in any language. -- Author unknown.
    Press any key to continue, any other key to quit

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
  • Right about that, bite is local.
  • Right about that, bite is local.

    no, bite is already the char, byte[stringptr++], so the second invoke of byte[..] is not needed.

    nothing to do with local or global.

    Enjoy!

    Mike
    I am just another Code Monkey.
    A determined coder can write COBOL programs in any language. -- Author unknown.
    Press any key to continue, any other key to quit

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
  • Deleted

    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
Sign In or Register to comment.