How sampling packages work
A package has four parts:
| Part | Class | Job |
|---|---|---|
| Package | SamplingPackage |
Lists the measure types, their default sampling configuration, and creates probes |
| Data | Data subclass |
The measurement payload |
| Probe | Probe |
Reads the sensor |
| Device manager | DeviceManager |
Connects to the device. The default is the phone itself |
From measure to probe
- You write
Measure(type: SensorSamplingPackage.STEP_EVENT)in aBackgroundTask. - At runtime the
BackgroundTaskExecutorcallsSamplingPackageRegistry().create('dk.cachet.carp.stepevent'). - The registry asks each registered package; the one that supports the type returns a probe.
- The probe emits measurements, which go to the study’s data manager.
SamplingPackageRegistry registers DeviceSamplingPackage, SensorSamplingPackage and MonitoringSamplingPackage itself. Register every other package in your app before adding a study:
SamplingPackageRegistry().register(SurveySamplingPackage());Registering also adds the package’s data types, and its device manager to the DeviceController, and calls the package’s onRegister().
Where in the repo
Section titled “Where in the repo”| File | What is in it |
|---|---|
domain/services/sampling_package.dart |
SamplingPackage, SmartphoneSamplingPackage, MonitoringSamplingPackage |
runtime/sampling_package_registry.dart |
SamplingPackageRegistry |