KM3NeT CLB
2.0
KM3NeT CLB v2 Embedded Software
|
The CLBv2 platform uses symantics similar to Linux for handling error state.
It has a global error module which tracks the first error set. An error can be set using the errSet()
function. This function takes a number, the error code, and optionally a character string, the error message.
When an operation can not be executed the error can be set on the module. The convention is that any module which may fail returns a boolean. The function below is an example from our fictional transporter device.
As you can see when transporter is not powered, it will set an error and return false. Otherwise it will return true. In this case the responsibility for defining whether or not an error is fatal is left to the caller.
Suppose its absolutely essential that the transporter is initialized properly and else the software should fail the caller can trigger a fatal error:
However, it may also depend on the type of error whether or not the error is fatal. In this case the caller must know more. In the example above we saw the errorcode is set to 1. This is not very descriptive and if every module would return 1 as an error code we may just as well leave it out.
To solve this problem, each module gets a unique code range assigned. This code range can be used to create module specific errors. Unfortunately this requires a bit of bureaucracy, but its not to be helped. If you look at errorcode.h you will see defines with E_*
. These indicate error related codes and subcodes. The most important codes are E_PLATFORM
and E_APP
. These define the main offsets for platform errors and application errors. Generic errors start from zero, though there is no error 0.