Jump to content

Technical Reference:States of Operation

From BCI2000 Wiki

This page describes the states of operation that apply to a BCI2000 system as a whole. These are different from the concept of BCI2000 States which are saved to data files on a per-data block basis.

Driven by user interaction from the operator module, the system cycles through five phases of operation: Startup, Initialization, Suspended, Running, Termination.

State Diagram

Startup -> Initialization <-> Suspended -> Termination
                                  ^
                                  |
                                  v
                               Running

System Startup

Introduction

Since the system is a distributed system of encapsulated modules, this procedure ensures a proper and well defined information flow at start-up. Each module publishes its requests for parameters and states to the Operator module, which configures those and sends them back. After Data Acquisition receives all parameters and states, it tries to connect to Signal Processing and -- upon successful connection -- sends a positive status message to the Operator. In the same way, Signal Processing connects to the Application and the Application module connects to the Data Acquisition module. After the Operator receives status messages from all three core modules, the system is fully initialized and is triggered to start, as soon as the Operator sends the state Running with a value of 1 to the Data Acquisition module.

Startup Sequence

The operator module must be started first. Since in most cases the IP address of the operator module can be more easily statically defined, its IP address and port number(s) have to be provided to the core modules. The operator module listens on ports 4000 (for Source), 4001 (for Signal Processing), and 4002 (for Application) and waits for the respective core module to connect. Each can connect to its assigned port on the operator module in any order. Upon start-up, each core module opens a listening socket on an arbitrary port number.

Publishing Phase

Upon connection, each core module publishes its parameters to the operator module as a sequence of parameter messages. After publishing its parameters, each core module publishes the states it requests as a sequence of state messages. At this time, the operator module ignores every field except Name and Length , which it needs to construct the state vector. For this and all subsequent communication, the modules use the BCI2000 messages protocol. Following the last state, each core module sends a system command containing the string EndOfState. On receiving this command from all core modules, the operator module processes the received parameters and states. It creates a list of all parameters and all states and creates the state vector (duplicate parameters or states are ignored), and ends this initial publishing phase. In order to maintain integrity throughout operation, no parameters or states should be added to or removed from the system beyond this point.

System Initialization

Information Phase

At this point, the operator module may modify the value of the parameters and states (depending on the investigator's input or the parameter file). The operator module then uses the same channel on which it received data from the core modules to send back to all core modules a list of all system-wide parameters and system-wide states (in any order). Since the IP address and port number on which the core modules listen for data from other core modules are published in system parameters as described, each module now knows where to send its data. The connections from the core modules to the operator module remain open (all subsequent traffic will go through these connections). As in the publishing phase, the Information Phase ends when a system command EndOfState is sent.

Preflight Phase

In the preflight phase, each core module declares whether it can process data with the received parameters and states, and reports the properties of its output signal.

The operator module opens the preflight phase by sending an empty signal properties message to the source module. The source module then reports its output signal properties to the signal processing module by sending it an appropriate signal properties message. The signal processing module, in turn, sends its output signal properties to the application module.

During the preflight phase, modules indicate errors by sending descriptions into an error channel. If any errors are indicated during the preflight phase, the module will not initiate the initialization phase; the operator module will display the errors, prompting the user to fix the problems detected, and not offer the "Start" option.

Initialization Phase

Each core module uses the information in the received parameters to configure and initialize its operation. It also opens an active (i.e., client) connection to the other core module it must connect to, i.e., Source opens a connection to Signal Processing, Signal Processing to Application and Application to Source. Each core module sends a status message to the operator that indicates either successful or failed initialization. The Initialization Phase ends when all core modules indicate successful configuration.

System is Suspended

At the end of the Initialization Phase, the system is fully configured. All parameters and states (and positions thereof in the state vector) are defined. The system is suspended when Running is 0. Any module shall disregard a change in parameters if the system is not suspended. Data flows through the system and it is up to each module to decide how to process these data. The Application, for example, might give visual feedback that indicates that the system is suspended. As long as operation is suspended (i.e., Running is 0), any module might update system parameters and send them back to the Operator.

System is Running

During system operation, the Operator module must send states only to the Source module; Signal Processing and Application must disregard any state that the Operator does send to them. The system is started when the Operator module sets the state Running to 1 and sends it to the Source module.

System Termination

To each of the three core modules, the operator module indicates system termination by closing the connection to that module.

When a core module loses connection to the two other core modules it is connected to, it will send an error message to the operator, and then quit. The operator module, in turn, will close the connections to the remaining core modules.


See also: