configure method
Configure this SmartphoneDeploymentController.
Must be called after a deployment is ready using tryDeployment and before start is called.
The dataEndPoint
parameter is a custom DataEndPoint specifying where to save
or upload data. If not specified, the endpoint specified in the study deployment
(deployment.dataEndPoint
) which originates from the study protocol is used.
If no data endpoint is specified in the study protocol either, then no data
management is done, but sensing can still be started. This is useful for
apps that wants to use the framework for in-app consumption of sensing
events without saving the data.
The transformer
is a generic DataTransformer function which transform
each collected measurement. If not specified, a 1:1 mapping is done,
i.e. no transformation.
Implementation
Future<void> configure({
DataEndPoint? dataEndPoint,
DataTransformer? transformer,
}) async {
assert(deployment != null,
'Cannot configure a StudyDeploymentController without a deployment.');
assert(deployment is SmartphoneDeployment,
'A StudyDeploymentController can only work with a SmartphoneDeployment device deployment');
info('Configuring $runtimeType');
// initialize all devices from the primary deployment, incl. this smartphone.
initializeDevices();
// try to register relevant connected devices
super.tryRegisterRemainingDevicesToRegister();
// initialize optional parameters
_dataEndPoint = dataEndPoint ?? deployment!.dataEndPoint;
_transformer = transformer ?? ((data) => data);
if (_dataEndPoint != null) {
_dataManager = DataManagerRegistry().create(_dataEndPoint!.type);
}
if (_dataManager == null) {
warning(
"No data manager for the specified data endpoint found: '${deployment?.dataEndPoint}'.");
}
// initialize the data manager, device registry, and study executor
await _dataManager?.initialize(
deployment!.dataEndPoint!,
deployment!,
measurements,
);
// initialize the executor, which recursively initializes all executors and probes
_executor.initialize(deployment!, deployment!);
// Connect to all connectable devices, incl. this phone.
// (Re-)connecting a device will trigger that sampling is (re)started
await connectAllConnectableDevices();
// start heartbeat monitoring
if (SmartPhoneClientManager().heartbeat) startHeartbeatMonitoring();
measurements.listen((_) => _samplingSize++);
status = StudyStatus.Deployed;
print('===============================================================');
print(' CARP Mobile Sensing (CAMS) - $runtimeType');
print('===============================================================');
print(' deployment id : ${deployment!.studyDeploymentId}');
print(' deployed time : ${deployment!.deployed}');
print(' role name : ${deployment!.deviceConfiguration.roleName}');
// print(' user id : ${deployment!.userId}');
print(' platform : ${DeviceInfo().platform.toString()}');
print(' device ID : ${DeviceInfo().deviceID.toString()}');
print(' data endpoint : $_dataEndPoint');
print(' data manager : $_dataManager');
print(' status : ${status.toString().split('.').last}');
print('===============================================================');
}