Electronics > Beginners

Arduino Code Request - Byte Stream to Array

(1/6) > >>

Chet T16:
I've been looking at this on and off for the last while but i'm admitting defeat now!

I have a byte stream coming in with 43 bytes total and some 'quiet time' in between each lot of 43 bytes, as can be seen in this pic



The first 4 bytes are always the same.

All i need is to get this into an array of the same length so i can access the relevent bytes and display the info somewhere, obviously it would need to be constantly updating.

Is the 'quiet time' (i'm sure theres probably a proper name for it) useful for determining where the stream starts or would checking for the first 4 bytes be better?

Any suggestions and offers to do it for me would be greatly appreciated ;)

Thanks

Psi:
I'd use the 4 bytes sequence to trigger the code that starts filling the array.

But you should check if this 4 byte sequence could ever occur in other areas of the packet?
If that could happen the you have the potential for missing packets, so you might have to check for the dead time as well.

If the 4 byte sequence starts occuring in a location other than the start and this continues to happen in all following packets then you can get problems where the code keeps trying to assemble a packet starting from halfway through.
In this situation it may never get back into sync.

What kind of data is this? The structure and type of data in the packet can make solving these types of problems easier or harder.

Mechatrommer:

--- Quote from: Chet T16 on September 18, 2011, 11:10:05 am ---I have a byte stream coming in with 43 bytes total and some 'quiet time' in between each lot of 43 bytes, as can be seen in this pic
The first 4 bytes are always the same.
Is the 'quiet time' (i'm sure theres probably a proper name for it) useful for determining where the stream starts or would checking for the first 4 bytes be better?

--- End quote ---
if the 4 bytes (let me call header) is always at the beginning after each pause (silent time) then you can set the pause as the indicator (you can put a listening timeout in your code, it can be done either by polling or "interrupt and timer count"), but if the header is not always in the beginning (or even if it is), then probing for the 4 bytes value is more bulletproof. you can also count the total bytes read, ie after 4 bytes, there will be 39 bytes remaining right? counting this number and if it reaches the "fixed" value, you can start with another stream, or another "header finder" (my term). or header or pause or timeout probing or whatever.

"the beauty of software is you can put your intelligence into it much quicker" - mr shafri :P

Psi:
Ya have to be a little careful with how you deal with detecting the dead time.
If at a later date you decide to upgrade the speed of your communication it might reduce the dead time length that you're relying on.

Chet T16:
The output is not something i have control over so the speed won't be changing although i'm lead to believe its given a low priority so it may not be completely consistent

Should i be reading bytes, comparing to the previous byte and setting flags as i work my way through the sequence?

Whether the sequence can occur elsewhere i don't know but i'm willing to assume not for now!

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod