use of com.qualcomm.hardware.lynx.commands.standard.LynxDiscoveryCommand in project robotcode by OutoftheBoxFTC.
the class LynxUsbDeviceImpl method discoverModules.
@Override
public LynxModuleMetaList discoverModules() throws RobotCoreException, InterruptedException {
RobotLog.vv(TAG, "lynx discovery beginning...transmitting LynxDiscoveryCommand()...");
// Initialize our set of known modules and send out discovery requests
this.discoveredModules.clear();
// Make ourselves a fake module so that we can (mostly) use the normal transmission infrastructure
LynxModule fakeModule = new LynxModule(this, 0, /*ignored*/
false);
try {
// Make a discovery command and send it out
LynxDiscoveryCommand discoveryCommand = new LynxDiscoveryCommand(fakeModule);
discoveryCommand.send();
// Wait an interval sufficient so as to guarantee that we'll see all the replies
// that are there to see
long nsPerModuleInterval = 3 * ElapsedTime.MILLIS_IN_NANO;
int maxNumberOfModules = 254;
// "entire packet must be received within 50ms from the first Frame Byte"
long nsPacketTimeMax = 50 * ElapsedTime.MILLIS_IN_NANO;
// should be oodles
long nsSlop = 200 * ElapsedTime.MILLIS_IN_NANO;
long nsWait = nsPerModuleInterval * maxNumberOfModules + nsPacketTimeMax + nsSlop;
long msWait = (nsWait / ElapsedTime.MILLIS_IN_NANO);
nsWait = nsWait - msWait * ElapsedTime.MILLIS_IN_NANO;
RobotLog.vv(TAG, "discovery waiting %dms and %dns", msWait, nsWait);
Thread.sleep(msWait, (int) nsWait);
RobotLog.vv(TAG, "discovery waiting complete: #modules=%d", discoveredModules.size());
} catch (LynxNackException e) {
throw e.wrap();
} finally {
// Tidy up
fakeModule.close();
}
LynxModuleMetaList result = new LynxModuleMetaList(serialNumber, discoveredModules.values());
RobotLog.vv(TAG, "...lynx discovery completed");
return result;
}
Aggregations