Skip to content

Commit 6214cbc

Browse files
Merge pull request iNavFlight#11343 from xznhj8129/msp_versioning
MSP spec versioning
2 parents 94fd8cb + 3c70959 commit 6214cbc

14 files changed

Lines changed: 16070 additions & 15618 deletions

docs/Settings.md

Lines changed: 555 additions & 246 deletions
Large diffs are not rendered by default.

docs/development/msp/README.md

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@ For details on the structure of MSP, see [The wiki page](https://github.com/iNav
88
For list of enums, see [Enum documentation page](https://github.com/iNavFlight/inav/wiki/Enums-reference)
99

1010

11+
**When To Regenerate**
1112

12-
**JSON file rev: 4**
13+
Run `docs/development/msp/gen_docs.sh` whenever MSP docs inputs change:
14+
- `msp_messages.json` message content/schema updates
15+
- source enum changes under `src/main` that affect `inav_enums.json`
16+
- `format.md` or this header template (`docs_v2_header.md`) changes
17+
18+
By default the script removes temporary generated headers. Use `--keep_headers` only when you need them.
19+
20+
**Versioning Rule**
21+
22+
When the MSP JSON specification changes, bump `msp_messages.json` version:
23+
- breaking schema/compatibility change: increment `version.major`, reset `minor` and `patch`
24+
- backward-compatible schema extension: increment `version.minor`, reset `patch`
25+
- message/content/docs-only update inside current schema: increment `version.patch`
1326

1427
**Warning: Verification needed, exercise caution until completely verified for accuracy and cleared, especially for integer signs. Source-based generation/validation is forthcoming. Refer to source for absolute certainty**
1528

@@ -27,36 +40,50 @@ For list of enums, see [Enum documentation page](https://github.com/iNavFlight/i
2740
# Format:
2841
## JSON format example:
2942
```
30-
"MSP_API_VERSION": {
31-
"code": 1,
32-
"mspv": 1,
33-
"request": null,
34-
"reply": {
35-
"payload": [
36-
{
37-
"name": "mspProtocolVersion",
38-
"ctype": "uint8_t",
39-
"units": "",
40-
"desc": "MSP Protocol version (`MSP_PROTOCOL_VERSION`, typically 0)."
41-
},
42-
{
43-
"name": "apiVersionMajor",
44-
"ctype": "uint8_t",
45-
"units": "",
46-
"desc": "INAV API Major version (`API_VERSION_MAJOR`)."
47-
},
48-
{
49-
"name": "apiVersionMinor",
50-
"ctype": "uint8_t",
51-
"units": "",
52-
"desc": "INAV API Minor version (`API_VERSION_MINOR`)."
53-
}
54-
],
55-
},
56-
"notes": "Used by configurators to check compatibility.",
57-
"description": "Provides the MSP protocol version and the INAV API version."
43+
{
44+
"version": {
45+
"major": 2,
46+
"minor": 0,
47+
"patch": 0
5848
},
49+
"messages": {
50+
"MSP_API_VERSION": {
51+
"code": 1,
52+
"mspv": 1,
53+
"request": null,
54+
"reply": {
55+
"payload": [
56+
{
57+
"name": "mspProtocolVersion",
58+
"ctype": "uint8_t",
59+
"units": "",
60+
"desc": "MSP Protocol version (`MSP_PROTOCOL_VERSION`, typically 0)."
61+
},
62+
{
63+
"name": "apiVersionMajor",
64+
"ctype": "uint8_t",
65+
"units": "",
66+
"desc": "INAV API Major version (`API_VERSION_MAJOR`)."
67+
},
68+
{
69+
"name": "apiVersionMinor",
70+
"ctype": "uint8_t",
71+
"units": "",
72+
"desc": "INAV API Minor version (`API_VERSION_MINOR`)."
73+
}
74+
]
75+
},
76+
"notes": "Used by configurators to check compatibility.",
77+
"description": "Provides the MSP protocol version and the INAV API version."
78+
},
79+
"...": {}
80+
}
81+
}
5982
```
83+
## Top-level fields:
84+
**version**: JSON spec version (`major.minor.patch`)\
85+
**messages**: Dictionary keyed by MSP message name
86+
6087
## Message fields:
6188
**name**: MSP message name\
6289
**code**: Integer message code\
@@ -66,6 +93,7 @@ For list of enums, see [Enum documentation page](https://github.com/iNavFlight/i
6693
**variable_len**: Optional boolean, if true, message does not have a predefined fixed length and needs appropriate handling\
6794
**variants**: Optional special case, message has different cases of reply/request. Key/description is not a strict expression or code; just a readable condition\
6895
**not_implemented**: Optional special case, message is not implemented (never or deprecated)\
96+
**replaced_by**: Optional array of MSP message names that replace this command. Present when a command is deprecated and scheduled for removal. Empty array if no replacement is needed\
6997
**notes**: String with details of message
7098

7199
## Data dict fields:
@@ -2213,7 +2241,7 @@ For list of enums, see [Enum documentation page](https://github.com/iNavFlight/i
22132241
| `armingFlags` | `uint16_t` | 2 | Bitmask | Bitmask: Flight controller arming flags (`armingFlags`). Note: Truncated to 16 bits |
22142242
| `accCalibAxisFlags` | `uint8_t` | 1 | Bitmask | Bitmask: Accelerometer calibrated axes flags (`accGetCalibrationAxisFlags()`) |
22152243

2216-
**Notes:** Superseded by `MSP2_INAV_STATUS` which provides the full 32-bit `armingFlags` and other enhancements.
2244+
**Notes:** Superseded by `MSP2_INAV_STATUS` which provides the full 32-bit `armingFlags` and other enhancements. The `accCalibAxisFlags` field is not present in `MSP2_INAV_STATUS` but is available via `MSP_CALIBRATION_DATA`.
22172245

22182246
## <a id="msp_sensor_status"></a>`MSP_SENSOR_STATUS (151 / 0x97)`
22192247
**Description:** Provides the hardware status for each individual sensor system.

docs/development/msp/docs_v2_header.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@ For details on the structure of MSP, see [The wiki page](https://github.com/iNav
88
For list of enums, see [Enum documentation page](https://github.com/iNavFlight/inav/wiki/Enums-reference)
99

1010

11+
**When To Regenerate**
1112

12-
**JSON file rev: <file_rev>**
13+
Run `docs/development/msp/gen_docs.sh` whenever MSP docs inputs change:
14+
- `msp_messages.json` message content/schema updates
15+
- source enum changes under `src/main` that affect `inav_enums.json`
16+
- `format.md` or this header template (`docs_v2_header.md`) changes
17+
18+
By default the script removes temporary generated headers. Use `--keep_headers` only when you need them.
19+
20+
**Versioning Rule**
21+
22+
When the MSP JSON specification changes, bump `msp_messages.json` version:
23+
- breaking schema/compatibility change: increment `version.major`, reset `minor` and `patch`
24+
- backward-compatible schema extension: increment `version.minor`, reset `patch`
25+
- message/content/docs-only update inside current schema: increment `version.patch`
1326

1427
**Warning: Verification needed, exercise caution until completely verified for accuracy and cleared, especially for integer signs. Source-based generation/validation is forthcoming. Refer to source for absolute certainty**
1528

docs/development/msp/format.md

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,50 @@
11
# Format:
22
## JSON format example:
33
```
4-
"MSP_API_VERSION": {
5-
"code": 1,
6-
"mspv": 1,
7-
"request": null,
8-
"reply": {
9-
"payload": [
10-
{
11-
"name": "mspProtocolVersion",
12-
"ctype": "uint8_t",
13-
"units": "",
14-
"desc": "MSP Protocol version (`MSP_PROTOCOL_VERSION`, typically 0)."
15-
},
16-
{
17-
"name": "apiVersionMajor",
18-
"ctype": "uint8_t",
19-
"units": "",
20-
"desc": "INAV API Major version (`API_VERSION_MAJOR`)."
21-
},
22-
{
23-
"name": "apiVersionMinor",
24-
"ctype": "uint8_t",
25-
"units": "",
26-
"desc": "INAV API Minor version (`API_VERSION_MINOR`)."
27-
}
28-
],
29-
},
30-
"notes": "Used by configurators to check compatibility.",
31-
"description": "Provides the MSP protocol version and the INAV API version."
4+
{
5+
"version": {
6+
"major": 2,
7+
"minor": 0,
8+
"patch": 0
329
},
10+
"messages": {
11+
"MSP_API_VERSION": {
12+
"code": 1,
13+
"mspv": 1,
14+
"request": null,
15+
"reply": {
16+
"payload": [
17+
{
18+
"name": "mspProtocolVersion",
19+
"ctype": "uint8_t",
20+
"units": "",
21+
"desc": "MSP Protocol version (`MSP_PROTOCOL_VERSION`, typically 0)."
22+
},
23+
{
24+
"name": "apiVersionMajor",
25+
"ctype": "uint8_t",
26+
"units": "",
27+
"desc": "INAV API Major version (`API_VERSION_MAJOR`)."
28+
},
29+
{
30+
"name": "apiVersionMinor",
31+
"ctype": "uint8_t",
32+
"units": "",
33+
"desc": "INAV API Minor version (`API_VERSION_MINOR`)."
34+
}
35+
]
36+
},
37+
"notes": "Used by configurators to check compatibility.",
38+
"description": "Provides the MSP protocol version and the INAV API version."
39+
},
40+
"...": {}
41+
}
42+
}
3343
```
44+
## Top-level fields:
45+
**version**: JSON spec version (`major.minor.patch`)\
46+
**messages**: Dictionary keyed by MSP message name
47+
3448
## Message fields:
3549
**name**: MSP message name\
3650
**code**: Integer message code\

docs/development/msp/gen_docs.sh

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
15
INAV_MAIN_PATH="../../../src/main"
6+
INAV_ROOT="../../.."
7+
BUILD_INFO_SCRIPT="./get_fc_build_info.sh"
8+
KEEP_HEADERS=0
9+
10+
for arg in "$@"; do
11+
if [[ "$arg" == "--keep_headers" ]]; then
12+
KEEP_HEADERS=1
13+
fi
14+
done
15+
16+
eval "$(bash "$BUILD_INFO_SCRIPT" "$INAV_ROOT")"
217

318
echo "###########"
419
echo get_all_inav_enums_h.py
520
python get_all_inav_enums_h.py --inav-root "$INAV_MAIN_PATH"
621

7-
echo "###########"
8-
echo "msp_messages.json checksum"
9-
actual="$(md5sum msp_messages.json | awk '{print $1}')"
10-
expected="$(awk '{print $1}' msp_messages.checksum)"
11-
echo "Hash:" $actual
12-
if [[ "$actual" != "$expected" ]]; then
13-
n="$(cat rev)"
14-
printf '%d' "$(n + 1)" > rev
15-
echo "File changed, incrementing revision"
16-
echo $actual > msp_messages.checksum
17-
fi
18-
1922
echo "###########"
2023
echo gen_msp_md.py
2124
python gen_msp_md.py
2225

2326
echo "###########"
2427
echo gen_enum_md.py
25-
python gen_enum_md.py
26-
rm all_enums.h
27-
read -n 1 -s -r -p "Press any key to continue"
28+
python gen_enum_md.py \
29+
--fc-version-major "$FC_VERSION_MAJOR" \
30+
--fc-version-minor "$FC_VERSION_MINOR" \
31+
--fc-version-patch-level "$FC_VERSION_PATCH_LEVEL"
32+
if [[ "$KEEP_HEADERS" -eq 0 ]]; then
33+
rm all_enums.h
34+
fi

docs/development/msp/gen_enum_md.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from pathlib import Path
2121
from typing import List, Optional
2222
import json
23+
import argparse
2324

2425
# ---------- Helpers ----------
2526

@@ -249,7 +250,7 @@ def parse_files(paths: List[Path]) -> List[EnumDef]:
249250

250251
# ---------- Markdown rendering ----------
251252

252-
def render_markdown(enums: List[EnumDef]) -> str:
253+
def render_markdown(enums: List[EnumDef], build: dict) -> str:
253254
jsonfile = {}
254255
out = []
255256
out.append("# Enumerations\n")
@@ -277,19 +278,37 @@ def render_markdown(enums: List[EnumDef]) -> str:
277278
if '_source' in jsonfile[e.name]:
278279
jsonfile[e.name]['_source'] = jsonfile[e.name]['_source'].replace('../../../src', 'inav/src')
279280
out.append("")
280-
# While we're at it, chuck this all into a JSON file
281-
Path("inav_enums.json").write_text(json.dumps(jsonfile,indent=4), encoding="utf-8")
281+
wrapped = {
282+
"build": build,
283+
"enums": jsonfile,
284+
}
285+
Path("inav_enums.json").write_text(json.dumps(wrapped, indent=4), encoding="utf-8")
282286
return "\n".join(out)
283287

284288
# ---------- Main ----------
285289

286290
def main() -> int:
291+
parser = argparse.ArgumentParser(description="Generate enum markdown/json from all_enums.h")
292+
parser.add_argument("--fc-version-major", required=True, type=int)
293+
parser.add_argument("--fc-version-minor", required=True, type=int)
294+
parser.add_argument("--fc-version-patch-level", required=True, type=int)
295+
args = parser.parse_args()
296+
287297
path = Path("all_enums.h")
288298
if not path.exists():
289299
print(f"Error: {path} not found", file=sys.stderr)
290300
return 1
291301
enums = parse_files([path])
292-
md = render_markdown(enums)
302+
md = render_markdown(
303+
enums,
304+
{
305+
"fc_version": {
306+
"major": args.fc_version_major,
307+
"minor": args.fc_version_minor,
308+
"patch": args.fc_version_patch_level,
309+
},
310+
},
311+
)
293312
Path("inav_enums_ref.md").write_text(md, encoding="utf-8")
294313
return 0
295314

docs/development/msp/gen_msp_md.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- STRICT: If a code exists in one (MSPCodes vs JSON) but not the other, crash with details.
99
- Index items link to headings via GitHub-style auto-anchors.
1010
- Tight layout; identical Request/Reply tables; skip complex=true with a stub.
11-
- Default input: msp_messages.json ; default output: MSP_Doc.md
11+
- Default input: msp_messages.json ; default output: README.md
1212
"""
1313

1414
import sys
@@ -414,24 +414,24 @@ def generate_markdown(defs: Dict[str, Any]) -> str:
414414
with open("format.md", "r", encoding="utf-8") as f:
415415
fmt = f.read()
416416

417-
with open("msp_messages.checksum", "r", encoding="utf-8") as f:
418-
chksum = f.read().split(' ')[0]
419-
with open("rev", "r", encoding="utf-8") as f:
420-
rev = f.read()
421-
422-
header = header.replace('<format>',fmt)
423-
header = header.replace('<file_rev>',rev)
424-
header = header.replace('<file_hash>',chksum)
417+
header = header.replace('<format>', fmt)
425418

426419
index_md = build_index(json_by_code)
427420
return header + "\n" + index_md + "\n" + "".join(sections)
428421

422+
423+
def get_messages_definitions(payload: Dict[str, Any]) -> Dict[str, Any]:
424+
if "messages" in payload:
425+
return payload["messages"]
426+
return payload
427+
429428
def main():
430429
in_path = Path(sys.argv[1]) if len(sys.argv) >= 2 else Path("msp_messages.json")
431430
out_path = Path(sys.argv[2]) if len(sys.argv) >= 3 else Path("README.md")
432431

433432
with in_path.open("r", encoding="utf-8") as f:
434-
defs = json.load(f)
433+
payload = json.load(f)
434+
defs = get_messages_definitions(payload)
435435

436436
md = generate_markdown(defs)
437437
out_path.write_text(md, encoding="utf-8")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
INAV_ROOT="${1:-$(git rev-parse --show-toplevel)}"
6+
CMAKE_FILE="$INAV_ROOT/CMakeLists.txt"
7+
8+
version_fields="$(sed -nE 's/^project\(INAV VERSION ([0-9]+)\.([0-9]+)\.([0-9]+)\).*/\1 \2 \3/p' "$CMAKE_FILE")"
9+
if [[ -z "$version_fields" ]]; then
10+
echo "Failed to parse version from $CMAKE_FILE" >&2
11+
exit 1
12+
fi
13+
read -r FC_VERSION_MAJOR FC_VERSION_MINOR FC_VERSION_PATCH_LEVEL <<< "$version_fields"
14+
15+
printf 'FC_VERSION_MAJOR=%s\n' "$FC_VERSION_MAJOR"
16+
printf 'FC_VERSION_MINOR=%s\n' "$FC_VERSION_MINOR"
17+
printf 'FC_VERSION_PATCH_LEVEL=%s\n' "$FC_VERSION_PATCH_LEVEL"

0 commit comments

Comments
 (0)