Skip to content

Commit 71c2a08

Browse files
committed
docs: main: Add documentation for main module
Add docs for main module. Signed-off-by: Jan Tore Guggedal <jantore.guggedal@nordicsemi.no>
1 parent 9c97c43 commit 71c2a08

File tree

2 files changed

+98
-8
lines changed

2 files changed

+98
-8
lines changed

app/src/Kconfig.main

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ config APP_MODULE_TRIGGER_TIMEOUT_SECONDS
1212
Timeout for the trigger timer. On timeout, the module will send triggers for
1313
sensor sampling, location search and polling of shadow and FOTA status from cloud.
1414

15-
config APP_MODULE_THREAD_STACK_SIZE
16-
int "Thread stack size"
17-
default 3200
18-
1915
config APP_REQUEST_NETWORK_QUALITY
2016
bool "Request network quality"
2117
help

docs/modules/main.md

+98-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,105 @@
1-
# Main module
1+
# Main Module
22

3-
What does this module do
3+
The Main module serves as the central control unit of the Asset Tracker Template application. It implements a hierarchical state machine that coordinates the activities of all other modules through [zbus](https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/services/zbus/index.html) messages.
4+
This module handles the application's business logic, including cloud connectivity, data sampling, firmware updates, configuration updates, and user interactions.
45

56
## Messages
67

8+
The main module does not implement messages available to other modules. Instead, it processes messages from other modules to control the application's behavior.
9+
It subscribes to messages on the following zbus channels:
10+
11+
The Main module uses the following zbus channels, both for subscribing to incoming data and publishing outbound requests or status updates:
12+
13+
* **BUTTON_CHAN**
14+
- Processes user button presses for manually triggering data samples.
15+
16+
* **CLOUD_CHAN**
17+
- Receive connectivity status (connected, disconnected) and cloud response data.
18+
- Trigger device shadow polling to retrieve configuration updates.
19+
20+
* **ENVIRONMENTAL_CHAN**
21+
- Request sensor data from the environmental module.
22+
23+
* **FOTA_CHAN**
24+
- Poll for FOTA updates and manage the FOTA process.
25+
- Apply FOTA updates to install the new firmware image.
26+
27+
* **LED_CHAN**
28+
- Update LED pattern to indicate system state).
29+
30+
* **LOCATION_CHAN**
31+
- Requests new location data when a sample is due.
32+
33+
* **NETWORK_CHAN**
34+
- Control LTE network connection.
35+
- Track cellular connectivity events.
36+
- Request network quality samples.
37+
38+
* **POWER_CHAN**
39+
- Request battery status.
40+
- Initiate low-power mode.
41+
42+
* **TIMER_CHAN**
43+
- Handle timer events for sampling.
44+
45+
746
## Configurations
847

9-
Kconfig and device tree
48+
The Main module can be configured using the following Kconfig options:
49+
50+
* **CONFIG_APP_LOG_LEVEL**
51+
Controls logging level for the main module.
52+
53+
* **CONFIG_APP_MODULE_TRIGGER_TIMEOUT_SECONDS**
54+
Default data sampling interval.
55+
56+
* **CONFIG_APP_REQUEST_NETWORK_QUALITY**
57+
When enabled, requests network quality metrics during regular sampling.
58+
59+
* **CONFIG_APP_MSG_PROCESSING_TIMEOUT_SECONDS**
60+
Maximum time allowed for processing a single message.
61+
62+
* **CONFIG_APP_WATCHDOG_TIMEOUT_SECONDS**
63+
Defines the watchdog timeout for the main module.
64+
65+
66+
## State Diagram
67+
68+
The Main module implements a hierarchical state machine with the following states:
69+
70+
```mermaid
71+
stateDiagram-v2
72+
[*] --> STATE_RUNNING
73+
74+
state STATE_RUNNING {
75+
[*] --> STATE_IDLE
76+
77+
STATE_IDLE --> STATE_TRIGGERING : CLOUD_CONNECTED_READY_TO_SEND
78+
STATE_TRIGGERING --> STATE_IDLE : CLOUD_DISCONNECTED/CLOUD_CONNECTED_PAUSED
79+
80+
state STATE_TRIGGERING {
81+
[*] --> STATE_SAMPLE_DATA
82+
STATE_WAIT_FOR_TRIGGER --> STATE_SAMPLE_DATA : timer_trigger/button_press
83+
84+
STATE_SAMPLE_DATA --> STATE_WAIT_FOR_TRIGGER : LOCATION_SEARCH_DONE
85+
}
86+
}
87+
88+
STATE_RUNNING --> STATE_FOTA : FOTA_DOWNLOADING_UPDATE
89+
90+
state STATE_FOTA {
91+
[*] --> STATE_FOTA_DOWNLOADING
92+
93+
STATE_FOTA_DOWNLOADING --> STATE_FOTA_WAITING_FOR_NETWORK_DISCONNECT : FOTA_SUCCESS_REBOOT_NEEDED
94+
STATE_FOTA_DOWNLOADING --> STATE_FOTA_WAITING_FOR_NETWORK_DISCONNECT_TO_APPLY_IMAGE : FOTA_IMAGE_APPLY_NEEDED
95+
96+
STATE_FOTA_WAITING_FOR_NETWORK_DISCONNECT --> STATE_FOTA_REBOOTING : NETWORK_DISCONNECTED
97+
98+
STATE_FOTA_WAITING_FOR_NETWORK_DISCONNECT_TO_APPLY_IMAGE --> STATE_FOTA_APPLYING_IMAGE : NETWORK_DISCONNECTED
99+
STATE_FOTA_APPLYING_IMAGE --> STATE_FOTA_REBOOTING : FOTA_SUCCESS_REBOOT_NEEDED
100+
101+
STATE_FOTA_REBOOTING --> [*] : sys_reboot()
102+
}
10103
11-
## State diagram
104+
STATE_FOTA --> STATE_RUNNING : FOTA_DOWNLOAD_CANCELED/TIMED_OUT/FAILED
105+
```

0 commit comments

Comments
 (0)