Passing byte strings to a routine - clarity of thinking help please
pacman
Posts: 327
I know this has been asked before, but I'm unable to find the thread.
I have a string (of hex bytes) that is of the format "09 01 04 00 00 00 04 F1 C9" {The spaces are my addition to make reading easier}
The first byte contains the number of bytes of information (the sting often contains '00' thus null terminated methods don't work (like strlength - I've discovered)
Now this string lives in a VAR declaration
byte InBuffer[25]
So when I rattle through the array from the MAIN routine I get the responses I expect -
It's when I pass this string to a function that it gets all wierd on me
eg: CheckFrame[@inbuffer]
So in CheckFrame(mesg) I do the same repeat loop
The second set of debug info has vaules like D9 as the 'first result'
I'm currently thinking that is _might_ be that as 'mesg' is not defined as a byte array I'm getting some overlap from the higher order bits. Is my thinking correct? - My theory _seems_ (by me) to be backed up as if I run the first snippet in CheckFrame {without passing the string pointer, and thus using global varaibles) I get the same result correct result.
If that is correct - then now can I specificy that mesg is a btye array in CheckFrame? should I just be using something like PST.hex(mesg.byte[j++],2)?
Or am I just overly confused and the solution is painfully ovbious to all (except me) - so can you explain it in _simple_ terms.
Isn't it amazing how you can come up with 'other' ideas after you have pressed submit? or even at 11pm...
Other potential solutions I can think of - may or may not be good
Copy InBuffer to a long array like InBufferLong then I could just pass @inBufferLong to CheckFrame
Define Inbuffer as Long to start with - even though no single 'value' will be more than FF, memory {at this stage} is not an issue.
Merits/problems with alternate solutions?
I have a string (of hex bytes) that is of the format "09 01 04 00 00 00 04 F1 C9" {The spaces are my addition to make reading easier}
The first byte contains the number of bytes of information (the sting often contains '00' thus null terminated methods don't work (like strlength - I've discovered)
Now this string lives in a VAR declaration
byte InBuffer[25]
So when I rattle through the array from the MAIN routine I get the responses I expect -
j := 0 repeat while j < Inbuffer[0] PST.newline PST.dec(j) PST.str(string(" : ")) PST.hex(inbuffer[j++],2)
It's when I pass this string to a function that it gets all wierd on me
eg: CheckFrame[@inbuffer]
So in CheckFrame(mesg) I do the same repeat loop
j := 0 repeat while j < mesg[0] PST.newline PST.dec(j) PST.str(string(" : ")) PST.hex(mesg[j++],2)
The second set of debug info has vaules like D9 as the 'first result'
I'm currently thinking that is _might_ be that as 'mesg' is not defined as a byte array I'm getting some overlap from the higher order bits. Is my thinking correct? - My theory _seems_ (by me) to be backed up as if I run the first snippet in CheckFrame {without passing the string pointer, and thus using global varaibles) I get the same result correct result.
If that is correct - then now can I specificy that mesg is a btye array in CheckFrame? should I just be using something like PST.hex(mesg.byte[j++],2)?
Or am I just overly confused and the solution is painfully ovbious to all (except me) - so can you explain it in _simple_ terms.
Isn't it amazing how you can come up with 'other' ideas after you have pressed submit? or even at 11pm...
Other potential solutions I can think of - may or may not be good
Copy InBuffer to a long array like InBufferLong then I could just pass @inBufferLong to CheckFrame
Define Inbuffer as Long to start with - even though no single 'value' will be more than FF, memory {at this stage} is not an issue.
Merits/problems with alternate solutions?
Comments
Thanks but are the indexes the same?
would Inbuffer[2] == byte(mesg[2]) for example
or do I have to work with some offsets on the mesg array?