Go to Post A true form of GP would be to send out a congratulations to all the teams that made it, regardless of whether or not you think they should have. - Molten [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #76   Spotlight this post!  
Unread 13-06-2002, 20:36
DanL DanL is offline
Crusty Mentor
FRC #0097
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Somerville, MA
Posts: 682
DanL is just really niceDanL is just really niceDanL is just really niceDanL is just really niceDanL is just really nice
Send a message via AIM to DanL
Quote:
Originally posted by rbayer
I'd avoid reading one byte at a time if possible. It is inefficient and means your program will loop more often. And if you miss a byte, the output could appear sluggish or delayed. If you want to do something similar to this, I'd recommend that that you just discard data until you find a 255,255 and then copy the next 24 bytes into your data structure.
Hmm, well what happens if you loose one of those 24 bytes... it'll be that your 24th byte will actually be the first byte of the new packet... how does your way protect against this?
__________________
Dan L
Team 97 Mentor
Software Engineer, Vecna Technologies
  #77   Spotlight this post!  
Unread 13-06-2002, 20:43
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Quote:
Originally posted by SuperDanman


Hmm, well what happens if you loose one of those 24 bytes... it'll be that your 24th byte will actually be the first byte of the new packet... how does your way protect against this?
You won't. PC serial ports use buffers to store data in. Once you begin the read, you will get 26 continuous bytes. On the other hand, if the buffers overflow between read operations, you might loose a byte or two. Even if you do, by some mysterious fluke of Windows, loose a byte from the middle of a 24-byte read, checking for the start of the packet on each loop will make sure it corrects itself.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #78   Spotlight this post!  
Unread 13-06-2002, 20:48
DanL DanL is offline
Crusty Mentor
FRC #0097
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Somerville, MA
Posts: 682
DanL is just really niceDanL is just really niceDanL is just really niceDanL is just really niceDanL is just really nice
Send a message via AIM to DanL
Hmm, well thats a bit more simple than I thought... however, I was more concerned about no information coming over because of a radio failure between the robot and the oi or some interfereance...

Quote:
Originally posted by rbayer

Even if you do, by some mysterious fluke of Windows, loose a byte from the middle of a 24-byte read, checking for the start of the packet on each loop will make sure it corrects itself.
Well, suppose the check fails... what if the first two bytes aren't 255's... I suppose you have to switch to a read-1-byte-at-a-time loop until you DO get two consequetive 255's?
__________________
Dan L
Team 97 Mentor
Software Engineer, Vecna Technologies

Last edited by DanL : 13-06-2002 at 20:51.
  #79   Spotlight this post!  
Unread 13-06-2002, 21:03
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
actually dan, before you even posted that, or at least before i read that last post, that's what i just did. hopefully it will work...
__________________
AIM --> Woloi
Email --> ian@woloschin.com
  #80   Spotlight this post!  
Unread 13-06-2002, 21:07
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
I'd think so...

If not, here's the code I used. It takes the cross between two consecutive packets, but it really doesn't matter since the refresh rate is much higher than the eye could ever detect.
Code:
int i;
int start;
unsigned char info[26];
for(int i=0; i <=24; i++){
  if(readBuff[i]==255 && readBuff[i+1]==255){  //packets start with 255,255
  start=i;
  break;
  }
}

for(int i=start; i<=25; i++){
  info[i-start]=readBuff[i];
}
for(int i=0; i<start; i++){
  info[i+(26-start)]=readBuff[i];
}
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #81   Spotlight this post!  
Unread 13-06-2002, 21:41
DanL DanL is offline
Crusty Mentor
FRC #0097
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Somerville, MA
Posts: 682
DanL is just really niceDanL is just really niceDanL is just really niceDanL is just really niceDanL is just really nice
Send a message via AIM to DanL
ahhhh, now I see what you were talking about all along!

Just I don't like the fact that you overlap 2 packets into one... yeah it's too high to pick up, but just so I know I have an understanding of packets, this code would make it get the full packet, right?
Code:
int i;
int start;
unsigned char info[26];
for(int i=0; i <=24; i++){
  if(readBuff[i]==255 && readBuff[i+1]==255){  //packets start with 255,255
  start=i;
  break;
  }
}

for(int i=start; i<=25; i++){
  info[i-start]=readBuff[i];
}

unsigned char remainingBuffer[start];
ReadFile (hSerial, remainingBuffer, start, &read, 0);
for (int j=0; j<start; j++) {
  info[26-start+j]=remainingBuffer[j];
}
__________________
Dan L
Team 97 Mentor
Software Engineer, Vecna Technologies
  #82   Spotlight this post!  
Unread 13-06-2002, 21:58
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Looks good. It should also align the data for all subsequent reads, making it a little bit faster. Just make sure start isn't equal to 0 before you go into that last block of code, as I don't know how VC++ deals with arrays of size 0 or how ReadFile deals with requests of length 0. Might be OK, might cause page faults; you never know 'til you try.

I definately agree that overlapping two packets isn't ideal, but I was too lazy to change it after I realized that was what it was doing (I wrote the algorithim around 3am last year in Florida and wasn't quite thinking right).
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #83   Spotlight this post!  
Unread 14-06-2002, 09:00
Unsung FIRST Hero
Matt Leese Matt Leese is offline
Been-In-FIRST-Too-Long
FRC #1438 (The Aztechs)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1998
Location: Long Beach, CA
Posts: 937
Matt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond repute
Send a message via AIM to Matt Leese
When I wrote my dashboard viewer, I took a bit different take on how to read in the data. I did read in everything one byte at a time. Once I received two 255's, I then started a count. Given the value of the count, I determined what data I was actually reading in. Given that, I processed the data into a structure (ie the structure was updated everytime through the loop which means everytime a byte was read). Then, once the count reached the end of data, I updated the display.

As far as speed issues go, there is no problem reading in a byte at a time. Remember, the data will only be coming at you 20 times per second (20 Hz) which is something a computer can easily process.

Matt
  #84   Spotlight this post!  
Unread 14-06-2002, 14:37
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
one quick problem/question...

is it in anyway possible to loose a byte or two between reads? i'm doubting that, because of what i've heard, but it's something that's probably useful to know .
__________________
AIM --> Woloi
Email --> ian@woloschin.com
  #85   Spotlight this post!  
Unread 14-06-2002, 14:58
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
theoretically, yes. Probably, no. The only way you could loose a byte is if the PC's buffers overflow, and the only way I can imagine this happening is if you do a lot of time-consuming work between reads.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #86   Spotlight this post!  
Unread 14-06-2002, 15:09
DanL DanL is offline
Crusty Mentor
FRC #0097
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Somerville, MA
Posts: 682
DanL is just really niceDanL is just really niceDanL is just really niceDanL is just really niceDanL is just really nice
Send a message via AIM to DanL
What about if there's a break or interfereance in the radios between the robot and the oi?
__________________
Dan L
Team 97 Mentor
Software Engineer, Vecna Technologies
  #87   Spotlight this post!  
Unread 14-06-2002, 15:43
Unsung FIRST Hero
Matt Leese Matt Leese is offline
Been-In-FIRST-Too-Long
FRC #1438 (The Aztechs)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1998
Location: Long Beach, CA
Posts: 937
Matt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond repute
Send a message via AIM to Matt Leese
The OI should continue sending data even if there's a break between radios. It will only stall in between packets (ie all 26 bytes); that's because it doesn't have all the data to send.

Matt
  #88   Spotlight this post!  
Unread 14-06-2002, 16:10
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
so, theoretically, the OI will only send a complete packet, so the only way to get a partial packet is to unhook the cable from the dashboard port? that seems to make the most sense to me, so i'll go with that. also, that would mean we don't need to elaborate on some huge thing to crack down on missing packets and ignore them so they don't screw up the computer. makes everything a bit easier .
__________________
AIM --> Woloi
Email --> ian@woloschin.com
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Win32 serial port - recieve buffer seanwitte Programming 4 05-11-2003 21:41
White Paper Discuss: FIRST Editor v1.2 CD47-Bot Extra Discussion 1 18-09-2003 19:32
How to communicate both through radio and serial port? JC Denton Programming 1 08-02-2003 23:43
Ever seen this serial port problem before??? Aidan F. Browne Programming 5 05-02-2003 12:03
serial communication using c++ Malakili Programming 31 01-05-2002 15:51


All times are GMT -5. The time now is 10:32.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi