Go to Post I wish I were on the GDC, just to watch everyone struggle to grasp the meaning of this. - Brandon_L [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 10-02-2014, 21:40
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Java and C++ integration, UDP/TCP

I have written the skeleton of my vision code in C++ now. That runs on the Driver station computer parallel to all the FMS tasks. Our robot is coded in Java. To bring these together, C++ => Java, DS => cRIO, I am thinking about using network sockets.

I would prefer to use UDP because it is faster, but as I've heard, the UDP implementation is either non-existent or doesn't function well in Java, so TCP can work.

I'm persuading the rest of the programming team to work on a small socket client, but they probably either don't understand network sockets or they aren't showing GP.

How is the socket networking done with Java on the cRIO? I could use that as a starting point for getting the rest of the programmers to understand what I'm trying to do!
  #2   Spotlight this post!  
Unread 10-02-2014, 22:09
Joey1939's Avatar
Joey1939 Joey1939 is offline
Registered User
AKA: Joey Holliday
FRC #1939 (Kuhnigits)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Kansas City, Missouri
Posts: 140
Joey1939 has a spectacular aura aboutJoey1939 has a spectacular aura aboutJoey1939 has a spectacular aura about
Re: Java and C++ integration, UDP/TCP

I only have a basic understanding of all of this myself, but this idea is very interesting. A quick google search revealed this website on java networking. It talks about the basic ideas of networking as well as how to implement it in java.

I also found the open ports on the field here. It looks like you could be TCP 1180 or HTTP 80/443 depending on your camera configuration.

If you wanted to use java on both ends, I have had great success with Netty.
  #3   Spotlight this post!  
Unread 11-02-2014, 11:15
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Java and C++ integration, UDP/TCP

What about UDP/TCP 1234, etc. Does it mean that that port is blocked?
  #4   Spotlight this post!  
Unread 11-02-2014, 12:43
Joey1939's Avatar
Joey1939 Joey1939 is offline
Registered User
AKA: Joey Holliday
FRC #1939 (Kuhnigits)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Kansas City, Missouri
Posts: 140
Joey1939 has a spectacular aura aboutJoey1939 has a spectacular aura aboutJoey1939 has a spectacular aura about
Re: Java and C++ integration, UDP/TCP

I read it as only the ports listed are available for use.
  #5   Spotlight this post!  
Unread 11-02-2014, 12:45
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
Re: Java and C++ integration, UDP/TCP

Quote:
Originally Posted by yash101 View Post
What about UDP/TCP 1234, etc. Does it mean that that port is blocked?
Yes; Section 2.2.8 of the manual specifies the open ports on the field:
Quote:
Once plugged in to the Field Management System (FMS) via the Ethernet cable provided, the only open ports in the ARENA network are as follows:

TCP 1180: This port is typically used for camera data from the cRIO to the Driver Station (DS) when the camera is connected to port 2 on the 8-slot cRIO (P/N: cRIO-FRC). This port is bidirectional.
TCP 1735: SmartDashboard, bidirectional
UDP 1130: Dashboard-to-ROBOT control data, directional
UDP 1140: ROBOT-to-Dashboard status data, directional
HTTP 80: Camera connected via switch on the ROBOT, bidirectional
HTTP 443: Camera connected via switch on the ROBOT, bidirectional

Teams may use these ports as they wish if they do not employ them as outlined above (i.e. TCP 1180 can be used to pass data back and forth between the ROBOT and the DS if the team chooses not to use the camera on port 2).
It looks like Java ME sockets work a bit differently than Java SE sockets. You use the Connector class to open a StreamConnection or SocketConnection object. The Javadocs give an example:
Code:
SocketConnection sc = (SocketConnection) Connector.open("socket://10.xx.yy.5:1180");
sc.setSocketOption(SocketConnection.LINGER, 5);

InputStream is = sc.openInputStream();
OutputStream os = sc.openOutputStream();

os.write("\r\n".getBytes());
int ch = 0;
while(ch != -1) {
    ch = is.read();
}

is.close();
os.close();
sc.close();
Note that I have not used these classes, so YMMV.
__________________

LuNaTeCs - Learning Under Nurturing Adults Teaching Engineering Concepts and Skills - Small and Mighty!

FRC 316 LuNaTeCs - Student (2011-2014), Lead Programmer (2011-2014), Team Captain (2013-2014), Operator (2013), Drive Coach (2014), Mentor (2015-????)
'11 Philly Regional Finalists, '13 Chestnut Hill Finalists, '13 Lenape Champions, '13 Archimedes Division, '14 Chestnut Hill Champions, '14 Lenape Champions
FTC 7071 EngiNerds - Founding Advisor (2013-2014) | FRC 5420 Velocity - Founding Advisor (2015)
Grove City College Class of '18, Electrical/Computer Engineering (B.S.E.E)


Last edited by Domenic Rodriguez : 11-02-2014 at 12:55. Reason: Added more info
  #6   Spotlight this post!  
Unread 11-02-2014, 18:31
JesseK's Avatar
JesseK JesseK is offline
Expert Flybot Crasher
FRC #1885 (ILITE)
Team Role: Mentor
 
Join Date: Mar 2007
Rookie Year: 2005
Location: Reston, VA
Posts: 3,661
JesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond repute
Re: Java and C++ integration, UDP/TCP

We go TCP all the way. We have our own specific reasons, most stemming from the mentors' careers in critical applications where reliability trumps speed.

UDP is only faster because doesn't have QoS built in. This means you may only get part of the message back to the robot, which may not handle a bad message and crash. It also doesn't natively enforce FIFO messaging, so the messages may collide or come out of order. This is fine if your robot is trying to tweet something - but maybe not so much for that critical vision target message.

First 4-bytes are the 'magic number'; second 4-bytes are the message length; the third 4-bytes are the robot time stamp; then finally the message itself. The 12-byte custom header is well-worth the overhead when considering how easy it is to implement a new message. The message encode/decode order is hard-coded to reduce dependencies on external 'flavor of the month' libraries, but is generally easier to do than it seems on the surface. The design approach also teaches students the basics of network programming. We have different messages: one is the data, one is debug messaging, others are more custom. The debug messages have the same format but are arrays of 2-byte chars, making it very easy to dump to and yank off of the socket.

The robot is C++, our custom driver's display & vision system is Java. It wasn't trivial to setup and integrate (threading on the robot mainly), but now it works flawlessly.

I plan to release a more generic library over the summer for use with next year's control system. Can't wait for a Linux-based flavor of robot
__________________

Drive Coach, 1885 (2007-present)
CAD Library Updated 5/1/16 - 2016 Curie/Carver Industrial Design Winner
GitHub

Last edited by JesseK : 11-02-2014 at 18:35.
  #7   Spotlight this post!  
Unread 11-02-2014, 18:39
mhaeberli mhaeberli is offline
Registered User
FRC #3045
 
Join Date: Feb 2014
Location: Redwood City
Posts: 88
mhaeberli is on a distinguished road
Re: Java and C++ integration, UDP/TCP

I would recommend you also take a look at NetworkTables. Integrating C++ into NetworkTables on the drive station will take some use of magic Java stuff called JNI - Java Native Interface. Search here in ChiefDelphi to get some hints.
Best,
Martin Haeberli
(one of many)
Mentor(s) to FRC Team 3045 - SWAT - San Mateo, CA
  #8   Spotlight this post!  
Unread 12-02-2014, 05:36
KunlerOte KunlerOte is offline
Registered User
no team
 
Join Date: Feb 2014
Rookie Year: 2013
Location: North Vancouver, BC, Canada
Posts: 1
KunlerOte is an unknown quantity at this point
Re: Java and C++ integration, UDP/TCP

I recommend not just to use UDP, but to use UDP only and nothing more. Do not use TCP and UDP together - better learn how to implement those TCP features based on UDP you may require instead.

Last edited by KunlerOte : 12-02-2014 at 09:36.
  #9   Spotlight this post!  
Unread 14-02-2014, 12:19
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Java and C++ integration, UDP/TCP

I just asked our programming mentor and he told me he knew how to implement it! Now, I need to learn the C++ side! Can I use winsock.h/winsock2.h? I don't know how Java uses the network (the packets it sends) and how to use that with C++. If it can run in Linux too, that would be greatly appreciated!
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


All times are GMT -5. The time now is 02:31.

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