Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Getting Packets from the cRio (http://www.chiefdelphi.com/forums/showthread.php?t=71570)

rfrank 08-01-2009 08:22

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.

rhoads2234 17-01-2009 15:36

Re: Getting Packets from the cRio
 
Quote:

Originally Posted by rfrank (Post 795669)
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.

nathanww 17-01-2009 22:35

Re: Getting Packets from the cRio
 
Not neccesarily--some ultrasonics send back a voltage that represents the distance from whatever they're looking at.


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

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