View Single Post
  #2   Spotlight this post!  
Unread 18-11-2013, 01:24
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: Which communication protocol is best?

Quote:
Originally Posted by Jay_To_The_Be View Post
I just don't know how to setup up the connection between the cRIO and Processing, and how to separate a comma-delimited string and make those values.
Quote:
Originally Posted by DomenicR View Post
Mentioned within is Team 3574's 2012 code, which used a TCP to send vision data from the driver station laptop.
You can also check out the Network Tables code in the WPILib source code, which includes a TCP server. VxWorks looks like it basically uses the Berkeley/POSIX sockets API, so any resources on the Internet for Linux or Unix socket code should work as well. The code is a little extensive to replicate in-thread.

As for parsing delimited strings, here's some code for that separates numbers delimited by whitespace:

Spoiler for Parse whitespace-delimited numbers:

Code:
#include <string>
#include <sstream>
#include <iterator>
#include <vector>

#include <iostream>

int main(int argc, char **argv)
{
	if (argc != 2)
		return 1;
	
	std::string input(argv[1]);
	std::stringstream ss(input);
	std::vector<double> parts((std::istream_iterator<double>(ss)), (std::istream_iterator<double>()));
	if (ss.fail() && !ss.eof())
	{
		std::cout << "Data format error" << std::endl;
		return -1;
	}
	
	for(int i=0; i < parts.size(); ++i)
	{
		std::cout << parts[i] << std::endl;
	}
	
	return 0;
}


if you need comma to be delimiters as well, the code gets a bit more complicated:

Spoiler for Parse comma- and whitespace-delimited numbers:

Code:
#include <string>
#include <sstream>
#include <vector>
#include <cctype>

#include <iostream>

int main(int argc, char **argv)
{
	if (argc != 2)
		return 1;
	
	std::string input(argv[1]);
	std::stringstream ss(input);
	std::vector<double> parts;
	double val;
	
	while(ss >> val)
	{
		parts.push_back(val);
		
		while(std::isspace(ss.peek()) || ss.peek() == ',')
			ss.ignore();
	}
	if (!ss.eof())
	{
		std::cout << "Data format error" << std::endl;
		return -1;
	}
	
	for(int i=0; i < parts.size(); ++i)
	{
		std::cout << parts[i] << std::endl;
	}
	
	return 0;
}
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
Reply With Quote