Appearance
Session State
A measuring session is always in a "state". The session transitions between possible states either by following an API action called by the application, or via internal logic that is intended to prepare the session for performing measurements. The session state diagram appears in the figure below.
Session States
The table below provides a description of each session state:
State Name | State Definition |
---|---|
initializing | The session is in its initial state, performing initialization actions. Please wait until you receive the message indicating that the session is in the ready state before starting to measure vital signs or before calling any session APIs. |
ready | The session is now ready to be started. The application can display the camera preview, if using face/finger measurements. Refer to the Creating a Preview page for detailed instructions. On Polar sessions the SDK starts receiving data from the PPG device and optimized for a quick session start. |
starting | The session is currently preparing to measure vital signs. |
processing | The session is processing the data and calculating vital signs. For information on the handling of instantaneous vital signs, please refer to the Vital Signs page. |
stopping | The session has been stopped, and the measurement results are being calculated. For information on the handling the final results, please see the Vital Signs page. |
terminating | The session is currently being terminated. Please refrain from calling any session APIs. |
terminated | The session has been gracefully terminated, and a new session can now be initiated. |
Session State Transitions
The table below describes the actions that cause a transition between the states:
State | Next State | Trigger |
---|---|---|
initializing | ready | Once all initialization actions are completed, the session transitions to the ready state. |
ready | starting | Calling the start() method causes the session to transition to the starting state. |
starting | processing | The session's actions in the starting state were completed. |
processing | stopping | The session will transition to the stopping state under the following circumstances: *The measurement ends gracefully either because it reached the defined duration or due to a manual invocation of the stop() method. *The measurement was stopped due to an error. Refer to the Alerts section for more information. |
stopping | ready | The SDK has finished performing the vital sign calculations. |
ready | terminating | By calling the terminate() method, the session transitions to the terminating state. |
terminating | terminated | The termination actions have been completed. |
Note
The starting, stopping and terminating states are 'transition states' that end automatically after a short period. Do not call any session methods while the session is in transition.
Receiving Session State Updates
The application can receive session state updates by implementing onSessionStateChange
as part of SessionInfoListener
:
Swift
func onSessionStateChange(sessionState: SessionState) {
// Receive session state updates
}
func onWarning(warningData: WarningData) {
// Receive warnings
}
func onError(errorData: ErrorData) {
// Receive errors
}
func onLicenseInfo(licenseInfo: LicenseInfo) {
// Receive license info
}
func onEnabledVitalSigns(enabledVitalSigns: SessionEnabledVitalSigns) {
// Receive the enabled vital signs for the session
}
func onSessionStateChange(sessionState: SessionState) {
// Receive session state updates
}
func onWarning(warningData: WarningData) {
// Receive warnings
}
func onError(errorData: ErrorData) {
// Receive errors
}
func onLicenseInfo(licenseInfo: LicenseInfo) {
// Receive license info
}
func onEnabledVitalSigns(enabledVitalSigns: SessionEnabledVitalSigns) {
// Receive the enabled vital signs for the session
}
Objective-C
- (void)onSessionStateChangeWithSessionState:(BNHSessionState *)sessionState {
// Receive session state updates
}
- (void)onWarningWithData:(BNHWarningData *)warningData {
// Receive warnings
}
- (void)onErrorWithData:(BNHErrorData *)errorData {
// Receive errors
}
- (void)onLicenseInfoWithInfo:(BNHLicenseInfo *)licenseInfo {
// Receive license info
}
- (void)onEnabledVitalSignsWithEnabledVitalSigns:(BNHEnabledVitalSigns *)enabledVitalSigns {
// Receive the enabled vital signs for the session
}
- (void)onSessionStateChangeWithSessionState:(BNHSessionState *)sessionState {
// Receive session state updates
}
- (void)onWarningWithData:(BNHWarningData *)warningData {
// Receive warnings
}
- (void)onErrorWithData:(BNHErrorData *)errorData {
// Receive errors
}
- (void)onLicenseInfoWithInfo:(BNHLicenseInfo *)licenseInfo {
// Receive license info
}
- (void)onEnabledVitalSignsWithEnabledVitalSigns:(BNHEnabledVitalSigns *)enabledVitalSigns {
// Receive the enabled vital signs for the session
}
Handling State Transitions
The code below is a simple example for handling session transitions updates by implementing onSessionStateChange
as part of SessionInfoListener
.
Swift
func onSessionStateChange(sessionState: SessionState) {
DispatchQueue.main.async {
switch (sessionState) {
case .initializing:
print("Session is initializing and NOT ready")
case .ready:
print("Session is ready to start measuring")
case .starting:
print("Session is preparing for the measurement of vital signs")
case .processing:
print("Session is measuring vital signs")
case .stopping:
print("Session is stopping the measuring of vital signs")
case .terminating:
print("Session is preparing to terminate")
case .terminated:
print("Session is terminated")
}
}
}
func onSessionStateChange(sessionState: SessionState) {
DispatchQueue.main.async {
switch (sessionState) {
case .initializing:
print("Session is initializing and NOT ready")
case .ready:
print("Session is ready to start measuring")
case .starting:
print("Session is preparing for the measurement of vital signs")
case .processing:
print("Session is measuring vital signs")
case .stopping:
print("Session is stopping the measuring of vital signs")
case .terminating:
print("Session is preparing to terminate")
case .terminated:
print("Session is terminated")
}
}
}
Objective-C
- (void)onSessionStateChangeWithSessionState:(BNHSessionState)sessionState {
dispatch_async(dispatch_get_main_queue(), ^{
switch (sessionState) {
case BNHSessionStateInitializing:
NSLog(@"Session is initializing and NOT ready");
break;
case BNHSessionStateReady:
NSLog(@"Session is ready to start measuring");
break;
case BNHSessionStateStarting:
NSLog(@"Session is preparing for the measurement of vital signs");
break;
case BNHSessionStateProcessing:
NSLog(@"Session is measuring vital signs");
break;
case BNHSessionStateStopping:
NSLog(@"Session is stopping the measuring of vital signs");
break;
case BNHSessionStateTerminating:
NSLog(@"Session is preparing to terminate");
break;
case BNHSessionStateTerminated:
NSLog(@"Session is terminated");
break;
}
});
}
- (void)onSessionStateChangeWithSessionState:(BNHSessionState)sessionState {
dispatch_async(dispatch_get_main_queue(), ^{
switch (sessionState) {
case BNHSessionStateInitializing:
NSLog(@"Session is initializing and NOT ready");
break;
case BNHSessionStateReady:
NSLog(@"Session is ready to start measuring");
break;
case BNHSessionStateStarting:
NSLog(@"Session is preparing for the measurement of vital signs");
break;
case BNHSessionStateProcessing:
NSLog(@"Session is measuring vital signs");
break;
case BNHSessionStateStopping:
NSLog(@"Session is stopping the measuring of vital signs");
break;
case BNHSessionStateTerminating:
NSLog(@"Session is preparing to terminate");
break;
case BNHSessionStateTerminated:
NSLog(@"Session is terminated");
break;
}
});
}