use of com.qualcomm.robotcore.exception.RobotCoreException 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.exception.RobotCoreException in project robotcode by OutoftheBoxFTC.
the class FtcEventLoopBase method handleCommandSaveConfiguration.
protected void handleCommandSaveConfiguration(String fileInfo) {
String[] fileInfoArray = fileInfo.split(RobotConfigFileManager.FILE_LIST_COMMAND_DELIMITER);
try {
RobotConfigFile cfgFile = robotCfgFileMgr.getConfigFromString(fileInfoArray[0]);
robotCfgFileMgr.writeToFile(cfgFile, false, fileInfoArray[1]);
robotCfgFileMgr.setActiveConfigAndUpdateUI(false, cfgFile);
} catch (RobotCoreException | IOException e) {
e.printStackTrace();
}
}
use of com.qualcomm.robotcore.exception.RobotCoreException in project robotcode by OutoftheBoxFTC.
the class FtcEventLoopBase method getLynxUsbDeviceForFirmwareUpdate.
protected LynxUsbDeviceContainer getLynxUsbDeviceForFirmwareUpdate(SerialNumber serialNumber) {
// Is is it something that's already open?
for (LynxUsbDeviceImpl lynxUsbDevice : ftcEventLoopHandler.getExtantLynxDeviceImpls()) {
if (lynxUsbDevice.getSerialNumber().equals(serialNumber)) {
return new LynxUsbDeviceContainer(lynxUsbDevice);
}
}
// No, then open it
try {
RobotUsbManager robotUsbManager = HardwareDeviceManager.createUsbManager(AppUtil.getDefContext());
RobotUsbDevice robotUsbDevice = LynxUsbUtil.openUsbDevice(robotUsbManager, serialNumber);
return new LynxUsbDeviceContainer(robotUsbDevice);
} catch (RobotCoreException e) {
// ignored;
}
return null;
}
use of com.qualcomm.robotcore.exception.RobotCoreException in project robotcode by OutoftheBoxFTC.
the class ConfigureFromTemplateActivity method configureFromTemplate.
void configureFromTemplate(RobotConfigFile templateMeta, XmlPullParser xmlPullParser) {
try {
RobotConfigMap robotConfigMap = instantiateTemplate(templateMeta, xmlPullParser);
awaitScannedDevices();
//
Class clazz = FtcConfigurationActivity.class;
EditParameters parameters = new EditParameters(this);
parameters.setRobotConfigMap(robotConfigMap);
parameters.setExtantRobotConfigurations(configurationList);
parameters.setScannedDevices(scannedDevices);
Intent intent = new Intent(context, clazz);
parameters.putIntent(intent);
//
// Start with an unnamed config, but don't update the header here as that's just distracting
// as it just shows briefly before FtcConfigurationActivity takes over.
robotConfigFileManager.setActiveConfig(RobotConfigFile.noConfig(robotConfigFileManager));
startActivityForResult(intent, FtcConfigurationActivity.requestCode.value);
} catch (RobotCoreException e) {
}
}
use of com.qualcomm.robotcore.exception.RobotCoreException in project robotcode by OutoftheBoxFTC.
the class ModernRoboticsUsbUtil method openUsbDevice.
// ----------------------------------------------------------------------------------------------
// Device management
// ----------------------------------------------------------------------------------------------
/**
* Note: when doScan is false, several openUsbDevice() calls (for different serial numbers) can execute concurrently.
*/
public static RobotUsbDevice openUsbDevice(boolean doScan, RobotUsbManager robotUsbManager, SerialNumber serialNumber) throws RobotCoreException {
String description = "";
boolean found = false;
int deviceCount = doScan ? robotUsbManager.scanForDevices() : robotUsbManager.getScanCount();
for (int index = 0; index < deviceCount; ++index) {
if (serialNumber.equals(robotUsbManager.getDeviceSerialNumberByIndex(index))) {
found = true;
description = robotUsbManager.getDeviceDescriptionByIndex(index) + " [" + serialNumber.toString() + "]";
break;
}
}
if (!found) {
RobotLog.logAndThrow("Unable to find USB device with serial number " + serialNumber.toString());
}
RobotUsbDevice robotUsbDevice = null;
try {
robotUsbDevice = robotUsbManager.openBySerialNumber(serialNumber);
} catch (Exception e) {
throw RobotCoreException.createChained(e, "Unable to open USB device " + serialNumber + " - " + description + ": " + e.getMessage());
}
try {
robotUsbDevice.setBaudRate(ModernRoboticsConstants.USB_BAUD_RATE);
robotUsbDevice.setDataCharacteristics((byte) 8, (byte) 0, (byte) 0);
robotUsbDevice.setLatencyTimer(ModernRoboticsConstants.LATENCY_TIMER);
} catch (Exception e) {
robotUsbDevice.close();
throw RobotCoreException.createChained(e, "Unable to parameterize USB device " + serialNumber + " - " + description + ": " + e.getMessage());
}
try {
/**
* TODO: This timeout of 400ms can almost assuredly be reduced with some further analysis.
*
* "From: Berling, Jonathan
* Sent: Tuesday, January 3, 2017
*
* [...] When we were developing that code, if we tried to open too many USB devices too
* quickly they would sometimes fail. We never looked into the cause. It could have been
* anything from the USB devices themselves, to Android, to the type of hub we were using,
* etc. (This was long before MR was even considering making a USB hub.)"
*/
Thread.sleep(400L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return robotUsbDevice;
}
Aggregations