Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CheesyVision for 2015 #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cheesyvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
import socket
import time

# CHANGE THIS TO BE YOUR TEAM'S cRIO IP ADDRESS!
HOST, PORT = "10.2.54.2", 1180
# CHANGE THIS TO BE YOUR TEAM NUMBER IP ADDRESS!
HOST, PORT = "roborio-254.local", 1180

# Name of displayed window
WINDOW_NAME = "CheesyVision"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
*/

import edu.wpi.first.wpilibj.Timer;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Vector;
import javax.microedition.io.Connector;
import javax.microedition.io.ServerSocketConnection;
import javax.microedition.io.SocketConnection;


public class CheesyVisionServer implements Runnable {

private static CheesyVisionServer instance_;
Thread serverThread = new Thread(this);
private int listenPort_;
private Vector connections_;
private Vector<Socket> connections_;
private boolean counting_ = false;
private int leftCount_ = 0, rightCount_ = 0, totalCount_ = 0;
private boolean curLeftStatus_ = false, curRightStatus_ = false;
Expand Down Expand Up @@ -46,7 +47,7 @@ private CheesyVisionServer() {

private CheesyVisionServer(int port) {
listenPort_ = port;
connections_ = new Vector();
connections_ = new Vector<Socket>();
}

public boolean hasClientConnection() {
Expand Down Expand Up @@ -101,25 +102,25 @@ public boolean getRightStatus() {
// This class handles incoming TCP connections
private class VisionServerConnectionHandler implements Runnable {

SocketConnection connection;
Socket connection;

public VisionServerConnectionHandler(SocketConnection c) {
public VisionServerConnectionHandler(Socket c) {
connection = c;
}

public void run() {
try {
InputStream is = connection.openInputStream();
InputStream is = connection.getInputStream();

int ch = 0;
//int ch = 0;
byte[] b = new byte[1024];
double timeout = 10.0;
double lastHeartbeat = Timer.getFPGATimestamp();
CheesyVisionServer.this.lastHeartbeatTime_ = lastHeartbeat;
while (Timer.getFPGATimestamp() < lastHeartbeat + timeout) {
boolean gotData = false;
//boolean gotData = false;
while (is.available() > 0) {
gotData = true;
//gotData = true;
int read = is.read(b);
for (int i = 0; i < read; ++i) {
byte reading = b[i];
Expand Down Expand Up @@ -151,11 +152,11 @@ public void run() {
// This method listens for incoming connections and spawns new
// VisionServerConnectionHandlers to handle them
public void run() {
ServerSocketConnection s = null;
ServerSocket s = null;
try {
s = (ServerSocketConnection) Connector.open("serversocket://:" + listenPort_);
s = new ServerSocket(listenPort_);
while (listening_) {
SocketConnection connection = (SocketConnection) s.acceptAndOpen();
Socket connection = (Socket) s.accept();
Thread t = new Thread(new CheesyVisionServer.VisionServerConnectionHandler(connection));
t.start();
connections_.addElement(connection);
Expand Down