configure method

Future<void> configure({
  1. DataEndPoint? dataEndPoint,
  2. DataTransformer? transformer,
})

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 (SmartphoneDeployment.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}'. "
        "Data sampling will still start, but no data will be saved.");
  }

  // 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;

  var statusMsg =
      '===============================================================\n'
      '  CARP Mobile Sensing (CAMS) - $runtimeType\n'
      '===============================================================\n'
      ' deployment id : ${deployment!.studyDeploymentId}\n'
      ' deployed time : ${deployment!.deployed}\n'
      '     role name : ${deployment!.deviceConfiguration.roleName}\n'
      '      platform : ${DeviceInfo().platform.toString()}\n'
      '     device ID : ${DeviceInfo().deviceID.toString()}\n'
      ' data endpoint : $_dataEndPoint\n'
      '  data manager : $_dataManager\n'
      '        status : ${status.toString().split('.').last}\n'
      '===============================================================\n';
  debugPrint(statusMsg);
}