Go to Post AND... ...GET OFF MY LAWN! You young whippersnappers. dang nabit... - Joe Johnson [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
  #1   Spotlight this post!  
Unread 08-01-2009, 08:22
rfrank's Avatar
rfrank rfrank is offline
Programmer
AKA: Russell Frank
FRC #0041 (RoboWarriors)
Team Role: Alumni
 
Join Date: Aug 2008
Rookie Year: 2007
Location: Somerset, New Jersey
Posts: 19
rfrank will become famous soon enough
Getting Packets from the cRio

I'm attempting to write some code to parse the packets coming from the Driver's Station. I opened up WireShark to confirm that packets were coming in - UDP port 1165. I examined the packet and found a 2-byte counter at the beginning, then what appeared to be actual data - after looking at "DashboardDataExample", I concluded that the first 64 bytes must all be floats (4b/float, 64/4 = 16 an. inputs) - analog voltages.

So I wrote some simple C code which uses winsock2 to get the packets and a struct to parse it. Here is my code.

Code:
#include <stdio.h>
#include <time.h>
#include <winsock2.h>

#define PORT 1165

typedef struct {
  unsigned short int num;
  float analog[8];
} packet;

void
print_packet (packet * p)
{
  printf ("Packet num: %d\n", p->num);
  int i;
  for (i = 0; i <= 7; i++) {
    printf ("Analog %d: %f\n", i, p->analog[i]);
  }
  printf ("\n\n");
}

int
main (void)
{
  WSADATA info;
  SOCKET recv_socket;
  struct sockaddr_in recv_addr;
  char recv_buff[1024];
  int recv_buff_len = 1024;
  struct sockaddr_in send_addr;
  int send_addr_size = sizeof (send_addr);
  if (WSAStartup (MAKELONG (1, 1), &info) == SOCKET_ERROR) {
    printf ("could not init winsock\n");
    exit (0);
  }
  recv_socket = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  recv_addr.sin_family = AF_INET;
  recv_addr.sin_port = htons (PORT);
  recv_addr.sin_addr.s_addr = htonl (INADDR_ANY);
  bind (recv_socket, (SOCKADDR *) &recv_addr, sizeof (recv_addr));
  while (1) {
    recvfrom (recv_socket, recv_buff, recv_buff_len, 0, (SOCKADDR *) &send_addr, &send_addr_size);
    print_packet ((packet *) recv_buff);
  }
  closesocket (recv_socket);
  WSACleanup ();
  return 0;
}
Here is an example of the output, while the whole controller system is running:

Quote:
Packet num: 9381
Analog 0: 0.000000
Analog 1: 0.000003
Analog 2: 0.000042
Analog 3: 0.000000
Analog 4: 0.000000
Analog 5: 0.000000
Analog 6: 0.000000
Analog 7: 0.000000


Packet num: 9637
Analog 0: 0.000000
Analog 1: 0.000003
Analog 2: 0.000042
Analog 3: 0.000000
Analog 4: 0.000000
Analog 5: 0.000000
Analog 6: 0.000000
Analog 7: 0.000000


Packet num: 9893
Analog 0: 0.000000
Analog 1: 0.000003
Analog 2: 0.000042
Analog 3: 0.000000
Analog 4: 0.000000
Analog 5: 0.000000
Analog 6: 0.000000
Analog 7: 0.000000


Packet num: 10149
Analog 0: 0.000000
Analog 1: 0.000003
Analog 2: 0.000042
Analog 3: 0.000000
Analog 4: 0.000000
Analog 5: 0.000000
Analog 6: 0.000000
Analog 7: 0.000000
It appears that the program isn't getting the packets fast enough to get every single packet. Also, every packet has those two values for analogs 1 and 2 (technically 2 and 3 I believe). I plugged in an analog ultrasonic into two different analog inputs with no response.

Also, I still get packets from the DS when the cRio is powered off. So I must assume that the packets go from the cRio to the DS, then from the DS to the PC. Is it possible the packets aren't getting from the cRio to the DS?

I also tried adding in

dashboardPacker.AddU8 (255);

to DashboardDataFormat.cpp in some random places, so the packet should have a bunch of FF bytes but I didn't see any in WireShark.

Any help is appreciated.
__________________

FRC 41: RoboWarriors Alumni. www.team41robotics.com Winners of 2008 NY Regional.
Bassist of Obviatus. www.dreamdefined.com Personal site: www.russfrank.us
  #2   Spotlight this post!  
Unread 17-01-2009, 15:36
rhoads2234's Avatar
rhoads2234 rhoads2234 is offline
Registered User
AKA: Erin
FRC #2234
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: PA
Posts: 80
rhoads2234 will become famous soon enough
Re: Getting Packets from the cRio

Quote:
Originally Posted by rfrank View Post
I plugged in an analog ultrasonic into two different analog inputs with no response.
Ultrasonics are digital sensors. You get an analog value because of math done to find the time it takes to recieve the ping you sent out.
__________________
ALWAYS a mechanical problem!
  #3   Spotlight this post!  
Unread 17-01-2009, 22:35
nathanww nathanww is offline
Hacker
FRC #1678 (Citrus Circuits)
Team Role: Programmer
 
Join Date: Dec 2008
Rookie Year: 2007
Location: Davis, CA
Posts: 224
nathanww is just really nicenathanww is just really nicenathanww is just really nicenathanww is just really nice
Re: Getting Packets from the cRio

Not neccesarily--some ultrasonics send back a voltage that represents the distance from whatever they're looking at.
__________________
Get yer robot source code here!
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
Problems undeploying a program from the cRIO ellisk Programming 2 29-12-2008 16:21
Tricks getting the CRIO to talk to laptop mac7attack FRC Control System 10 08-12-2008 09:20
24v Power Conector to from the PDB to the cRIO mcf747 Electrical 14 01-12-2008 19:19
Getting data from the robot mfwit LabView and Data Acquisition 1 19-02-2006 20:07
Getting program from RC PhatalEphekt Programming 4 18-02-2003 17:44


All times are GMT -5. The time now is 13:43.

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