checksum function for sending serial bytes
in Propeller 1
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
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
I saw someone said use tx.str(string($80, 2, 2)) aslong as not sending 0
I will need to send 0.
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)
tx(byte[bite])
betx(bite)
??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