Service
- class olaf.ServiceState(value)[source]
State a service can be in.
- STOPPED = 0
Service is not running.
- STARTING = 1
Service is starting up.
- RUNNING = 2
Service is running.
- STOPPING = 3
Service is stopping.
- FAILED = 3
Service has failed.
- class olaf.Service[source]
OLAF service, basically a
Resourcewith a dedicated thread.All the
on_*members can be overridden as needed.- node
The app’s CANopen node. Set to None until start() is called.
- Type:
Node or MasterNode
- start(node: Node)[source]
App will call this to start the service. This will call self.on_start() start a thread that will call self.on_loop().
- on_start()[source]
Called when the service starts.
Should be used to add SDO read/write callbacks to app.
- on_loop_error(error: Exception)[source]
Called when on_loop raises an exception before the thread stops.
Should be used to stop any hardware the service controls (if possible) and logs the errors.
- stop()[source]
App will call this to stop the service when the app stops. This will call self.on_stop().
- on_stop_before()[source]
Called when the app stops before the thread is stopped. Should be used to stop any blocking calls in the thread loop.
Will be called reguardless if self.on_loop_error() was called or not when the app stops.
- on_stop()[source]
Called when the app stops after the thread has stopped. Should be used to stop any hardware the service controls.
Will be called reguardless if self.on_loop_error() was called or not when the app stops.
- sleep(timeout: float)[source]
Sleep for X seconds, that can be interupted if stop() is called.
- Parameters:
timeout (float) – The time to sleep in seconds.
- sleep_ms(timeout: float)[source]
Sleep for X milliseconds, that can be interupted if stop() is called.
- Parameters:
timeout (float) – The time to sleep in milliseconds.
- property status: ServiceState
Get the service state.
- Type: