getDeviceDeploymentFor method
Get the deployment configuration for the specified primary device
in
this study deployment.
Implementation
PrimaryDeviceDeployment getDeviceDeploymentFor(
PrimaryDeviceConfiguration device,
) {
// Verify whether the specified device is part of the protocol of this
// deployment and has been registered.
assert(_protocol.hasPrimaryDevice(device.roleName),
"The specified primary device with role name '${device.roleName}' is not part of the protocol of this deployment.");
assert(_registeredDevices.containsKey(device.roleName),
"The specified primary device with role name '${device.roleName}' has not been registered to this deployment.");
// TODO - Verify whether the specified device is ready to be deployed.
DeviceRegistration configuration = _registeredDevices[device.roleName]!;
// mark all registered devices as deployed
_deployedDevices.addAll(_registeredDevices.keys);
// determine which devices this device needs to connect to
// TODO - only retrieve configuration for preregistered devices
Set<DeviceConfiguration> connectedDevices = _protocol.connectedDevices!;
// create a map of device registration for the connected devices
Map<String, DeviceRegistration?> connectedDeviceConfigurations = {};
for (var descriptor in connectedDevices) {
connectedDeviceConfigurations[descriptor.roleName] =
_registeredDevices[descriptor.roleName];
}
Set<TaskConfiguration> tasks = {};
// get all tasks which need to be executed on this primary device
tasks.addAll(protocol.getTasksForDeviceRoleName(device.roleName));
// .. and connected devices
// note that connected devices need NOT to be registered to be included
for (var descriptor in connectedDevices) {
tasks.addAll(protocol.getTasksForDeviceRoleName(descriptor.roleName));
}
// Get all trigger information for this and connected devices.
// TODO - this implementation just returns all triggers and triggered tasks.
// - but should check which devices are available
Map<String, TriggerConfiguration>? usedTriggers = _protocol.triggers;
Set<TaskControl>? triggeredTasks = _protocol.taskControls;
_status.status = StudyDeploymentStatusTypes.Running;
return PrimaryDeviceDeployment(
deviceConfiguration: device,
registration: configuration,
connectedDevices: connectedDevices,
connectedDeviceRegistrations: connectedDeviceConfigurations,
tasks: tasks,
triggers: usedTriggers,
taskControls: triggeredTasks);
}