Each module follows a similar design:
- Message channel: Each module defines its own zbus channel. With some exceptions, a single channel is used for all messages that are specific to a module.
- Message types: Each module exposes a set of input and output message types. These can be considered events in the state machine sense and might have associated data.
- State machine: Most modules implement a state machine using SMF to manage their internal state and behavior.
- Thread: Most modules have dedicated threads.
- Watchdog: Each module thread is monitored by a task watchdog. Each thread periodically calls
task_wdt_feed()to feed the watchdog. If a thread fails to feed its watchdog within its configured timeout, the system resets. - Initialization: Modules are initialized at system startup, either through
SYS_INIT()or in their dedicated thread throughK_THREAD_DEFINE().
Modules in the Asset Tracker Template are designed as loosely coupled units with well-defined message-based interfaces. Modules communicate exclusively through their defined zbus interfaces, without reference to other modules' internals. This design ensures that modules are self-contained and can be developed, tested, and maintained independently. Most modules except the Main module can also be reused in other applications.
Modules often handle state transitions based on messages they themselves publish. For example, when the Network module publishes a NETWORK_CONNECTED message, it also receives this message in its own state machine, allowing it to transition to the connected state with consistent handling.