use of com.qualcomm.robotcore.robocol.Command in project robotcode by OutoftheBoxFTC.
the class FtcEventLoop method handleCommandScan.
/**
* @see FtcConfigurationActivity#doUSBScanAndUpdateUI()
*/
protected void handleCommandScan(String extra) throws RobotCoreException, InterruptedException {
RobotLog.vv(FtcConfigurationActivity.TAG, "handling command SCAN");
final USBScanManager usbScanManager = startUsbScanMangerIfNecessary();
// Start a scan and wait for it to complete, but if a scan is already in progress, then just wait for that one to finish
final ThreadPool.SingletonResult<ScannedDevices> future = usbScanManager.startDeviceScanIfNecessary();
// Actually carry out the scan in a worker thread so that we don't hold up the receive loop for
// half-second or so that carrying out the scan will take.
ThreadPool.getDefault().execute(new Runnable() {
@Override
public void run() {
try {
ScannedDevices scannedDevices = future.await();
if (scannedDevices == null) {
scannedDevices = new ScannedDevices();
}
// Package up the raw scanned device info and send that back to the DS
String data = usbScanManager.packageCommandResponse(scannedDevices);
RobotLog.vv(FtcConfigurationActivity.TAG, "handleCommandScan data='%s'", data);
networkConnectionHandler.sendCommand(new Command(CommandList.CMD_SCAN_RESP, data));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
});
}
use of com.qualcomm.robotcore.robocol.Command in project robotcode by OutoftheBoxFTC.
the class FtcEventLoopBase method handleCommandRequestParticularConfiguration.
/*
* The driver station wants the contents of the configuration file.
*/
protected void handleCommandRequestParticularConfiguration(String data) {
RobotConfigFile file = robotCfgFileMgr.getConfigFromString(data);
ReadXMLFileHandler parser = new ReadXMLFileHandler();
if (file.isNoConfig()) {
// don't try to parse if there's no file
return;
}
try {
WriteXMLFileHandler writeXMLFileHandler = new WriteXMLFileHandler(activityContext);
ArrayList<ControllerConfiguration> deviceList = (ArrayList<ControllerConfiguration>) parser.parse(file.getXml());
String xmlData = writeXMLFileHandler.toXml(deviceList);
RobotLog.vv(FtcConfigurationActivity.TAG, "FtcEventLoop: handleCommandRequestParticularConfigFile, data: " + xmlData);
networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_PARTICULAR_CONFIGURATION_RESP, xmlData));
} catch (RobotCoreException e) {
e.printStackTrace();
}
}
use of com.qualcomm.robotcore.robocol.Command in project robotcode by OutoftheBoxFTC.
the class FtcEventLoopBase method handleCommandRequestConfigurations.
/**
* Serialize the entire list of config file metadata and send to the driver station
*/
protected void handleCommandRequestConfigurations() {
ArrayList<RobotConfigFile> fileList = robotCfgFileMgr.getXMLFiles();
String objsSerialized = RobotConfigFileManager.serializeXMLConfigList(fileList);
networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_CONFIGURATIONS_RESP, objsSerialized));
}
use of com.qualcomm.robotcore.robocol.Command in project robotcode by OutoftheBoxFTC.
the class FtcEventLoopBase method handleCommandRequestRememberedGroups.
/**
* Serialize the list of remembered Wifi Direct groups and send it to the driver station
*/
protected void handleCommandRequestRememberedGroups() {
WifiDirectPersistentGroupManager manager = new WifiDirectPersistentGroupManager(WifiDirectAgent.getInstance());
String serialized = WifiDirectGroupName.serializeNames(manager.getPersistentGroups());
networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_REMEMBERED_GROUPS_RESP, serialized));
}
use of com.qualcomm.robotcore.robocol.Command in project robotcode by OutoftheBoxFTC.
the class FtcEventLoopBase method handleCommandGetCandidateLynxFirmwareImages.
protected void handleCommandGetCandidateLynxFirmwareImages(Command commandRequest) {
// We return the full path to files with a .bin extension, case insensitive
final Pattern pattern = Pattern.compile("(?i).*\\.bin");
// We look for files in the file system on the robot controller
File firmwareDir = AppUtil.LYNX_FIRMWARE_UPDATE_DIR;
File[] candidateFiles = firmwareDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
Assert.assertTrue(pathname.isAbsolute());
return pattern.matcher(pathname.getName()).matches();
}
});
CommandList.LynxFirmwareImagesResp respParams = new CommandList.LynxFirmwareImagesResp();
respParams.firstFolder = AppUtil.FIRST_FOLDER;
for (File candidate : candidateFiles) {
respParams.firmwareImages.add(new CommandList.FWImage(candidate, false));
}
// We also look for files in our assets
try {
File fromBase = new File(firmwareDir.getParentFile().getName(), firmwareDir.getName());
String[] firmwareAssets = activityContext.getAssets().list(fromBase.getPath());
for (String firmwareAsset : firmwareAssets) {
if (pattern.matcher(firmwareAsset).matches()) {
File file = new File(fromBase, firmwareAsset);
Assert.assertTrue(!file.isAbsolute());
respParams.firmwareImages.add(new CommandList.FWImage(file, true));
}
}
} catch (IOException ignore) {
}
// Return all those, unsorted
networkConnectionHandler.sendReply(commandRequest, new Command(CommandList.CMD_GET_CANDIDATE_LYNX_FIRMWARE_IMAGES_RESP, respParams.serialize()));
}
Aggregations