-
-
Save keionbis/5bb2cadaa80b9f700edc91a5b25a5c04 to your computer and use it in GitHub Desktop.
Adding new file from BowlerStudio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='com.neuronrobotics', module='SimplePacketComsJava', version='0.0.9') | |
import edu.wpi.SimplePacketComs.bytepacket.BytePacketType; | |
import edu.wpi.SimplePacketComs.floatpacket.FloatPacketType; | |
import edu.wpi.SimplePacketComs.*; | |
import edu.wpi.SimplePacketComs.phy.UDPSimplePacketComs; | |
import java.net.InetAddress; | |
import java.util.HashSet; | |
class GameController extends NonBowlerDevice{ | |
UDPSimplePacketComs udpdevice; | |
def packets = [new BytePacketType(1970, 64)] | |
byte [] valuesFromController = new byte[19]; | |
byte [] valuesToController = new byte[60]; | |
public GameController(InetAddress add){ | |
udpdevice = new UDPSimplePacketComs(add); | |
for(PacketType pt:packets) | |
udpdevice.addPollingPacket(pt); | |
udpdevice.addEvent(1970, { | |
udpdevice.writeBytes( 1970, valuesToController) | |
udpdevice.readBytes( 1970, valuesFromController) | |
}); | |
} | |
byte [] getData(){ | |
return valuesFromController | |
} | |
byte [] getStatus(){ | |
return valuesToController | |
} | |
/** | |
* This method tells the connection object to disconnect its pipes and close out the connection. Once this is called, it is safe to remove your device. | |
*/ | |
public void disconnectDeviceImp(){ | |
udpdevice.disconnect(); | |
} | |
/** | |
* Connect device imp. | |
* | |
* @return true, if successful | |
*/ | |
public boolean connectDeviceImp(){ | |
udpdevice.connect(); | |
} | |
/** | |
* Gets the namespaces imp. | |
* | |
* @return the namespaces imp | |
*/ | |
public ArrayList<String> getNamespacesImp(){return []} | |
} | |
boolean noreturn = false | |
if(args == null){ | |
args = ["GameController_22"] | |
noreturn=true | |
} | |
HashSet<InetAddress> addresses = UDPSimplePacketComs.getAllAddresses(args[0]); | |
if (addresses.size() < 1) { | |
println("No devices found"); | |
return null | |
} | |
def robots = [] | |
for (InetAddress add : addresses) { | |
System.out.println("Got " + add); | |
def robot =DeviceManager.getSpecificDevice(add.toString(),{ | |
//If the device does not exist, prompt for the connection | |
def e = new GameController(add); | |
e.connect() | |
return e | |
}) | |
robots.add(robot) | |
} | |
if(noreturn) | |
return null | |
return robots[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment