Pages: [1]   Go Down
Author Topic: Help with using byteDiscard  (Read 947 times)
0 Members and 1 Guest are viewing this topic.
Kansas
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would like to look for an array of bytes that is an acknowledgement packet and if seen at the beginning of the data I want to discard it and immediately use the data that comes after it.I was thinking that stream.findUntil(target, terminal) might be a method to initially look for it. I belive byte discard is the proper method to dispose of it but I didn't find a-lot of info on how to use it. How would I indicate the number of bytes and where they are to discard.

Example: This data is read, I want to discard the portion in RED and then use the rest.
24 01 80 F3 98 03 24 06 81 2E 05 05 95 95 59 66 03


Thanks
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to read and store those bytes in an array, so that you can compare the array with a standard response array. If they match, then what? Why is starting, then, to store data in a (different or reinitialized)  array a problem?
Logged

Kansas
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I think see what you are getting at. I guess I was thinking somewhat along that same line. Store it in an array then discard or dead end it and do nothing with that data right?

It's a pain in the ass because most all of the data plays nice but for some reason there is this one packet that for some reason it prefixes with an ACK packet. Because of that it throws all the offsets off that I'm pointing to so I have to make a duplicate loop and set of pointers and operations for that packet to handle it when it's encountered. Keeping all the data perfectly justified by all interesting packets starting at offset 0x00 it would make things much easier, if that makes any sense as to why I'm wanting to do this.
« Last Edit: May 16, 2012, 11:32:36 am by mancow » Logged

Kansas
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One more quick question and I think my project will be done. Thanks for all of your help. Without it I wouldn't have been anywhere near this far.

The last hurdle is the scan channel indicator. Normally all data is sent as ASCII equivalent in hex so is directly displayed properly when printed to the lcd directly. However, the channel scan is sent as 0x01 for channel one and 0x02 for ch 2 etc... instead of 0x31, 0x32 etc... I know this should be a simple task but for some reason I can't seem to get it to display properly. I have tried the various format extensions such as DEC etc...
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1260
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For a single digit you can just add 0x30 to get an ASCII character '0' thru '9'.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Kansas
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks I will try that.

What do you think about something like this then?

ale = buffer[5];

ale +0x30;

 lcd.setCursor(8,1);
 lcd.print(ale);
« Last Edit: May 16, 2012, 06:16:00 pm by mancow » Logged

Kansas
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep, that worked for the single digit as you said, thanks. Just trying now to get the double digits going.
« Last Edit: May 16, 2012, 06:22:01 pm by mancow » Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1260
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Top hex digit is (0xnn >> 4)
Lower hex digit is (0xnn & 0xF)

Once you have the number as above you can display it as decimal (0-15) or hex (0-F) in the print() statement.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Kansas
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working with data that streams in and changes at a certain spot in the buffer. That's what has me confused. I'ts not static.
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1260
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am sure that you know this, but you must have certain points in the data that you know where you are. Most protocols have a start and a stop indicator in the packet (or a start and a a length). What is the protocol definition (ie, what does the documentation say you should be getting?)

Also your example ale+0x30 - does that even compile?
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Kansas
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int ale;
         int chan;
         if (buffer[0] == 0x07 && buffer[3] == 0x0D)
         {
           ale = buffer[5];
           chan = (ale + 0x30);
            
           lcd.setCursor(9,1);
           lcd.write(chan);
         }


Yes, it works up to 9 as you stated.

What this code does is point to offsets in an array named buffer that is filled from a loop that pulls from the serial read when the radio transmits a data packet to the Arduino. I flag for start of line 0x24 and know the max packet length will not exceed 34 bytes. When this certain data packet with that 07 and 0D in those spaces is seen I know it's what is called an ALE scan packet. Each time the radio changes to the next channel that data at offset [5] in the buffer is the only thing that changes. It increments from 0x00 to 0xC8 to represent the channel 0 through 200 that it's on. I am wanting to zero in on just that data and display it on that spot on the LCD.
When I exit that mode (say I go to free tuning mode) the op codes and other data in the incoming data packets change and this IF statement is no longer valid. Another similar IF statement below flags for their corresponding "identificatin", for lack of better term, bytes then it processes and displays interesting data from those packets, etc... and so forth. It's all working and all other packets are already formatted as ASCII but for whatever reason that one above ( the ALE scan) I initially mentioned is presenting the channel data as raw hex.

I hope that makes a bit more sense.
« Last Edit: May 16, 2012, 07:41:02 pm by mancow » Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1260
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, makes more sense.

As you only have 3 digits to worry about this is how you extract the:
- Highest digit (hundreds) is ale/100
- Middle digit (tens) is (ale/10)%10
- Lowest digit (units) is ale%10

Addiing 0x30 will convert to ascii character
« Last Edit: May 16, 2012, 09:07:59 pm by marco_c » Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Kansas
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That did it! Thanks!!!
Logged

Pages: [1]   Go Up
Jump to: