Skip to content

Commit db2035f

Browse files
authored
Add the optional software and hardware objects to the system info API result (#64)
1 parent e298be1 commit db2035f

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ and this project adheres to
1313
- Add log event metadata instead of prepending "[JSON incompatible term]" to
1414
log string data.
1515

16+
### Added
17+
18+
- Add the optional software and hardware information objects to the system
19+
info API result.
20+
1621
## [2.0.0] - 2025-02-26
1722

1823
### Changed

docs/grisp_connect_api.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ release name and version and if update is enabled.
4343
| update_progress | integer | optional | The progress as a percentage |
4444
| update_message | string | optional | Message describing the current state of the system |
4545
| action_required | boolean | optional | `"reboot"`, `"remove_sdcard_and_reboot"` or `"validate"` |
46+
| software | object | optional | Object describing the software running in the device |
47+
| hardware | object | optional | Object describing the hardware of the device |
4648

4749
Meaning of the status:
4850

@@ -54,6 +56,26 @@ Meaning of the status:
5456
| `"failed"` | The update failed, a new update can be initiated |
5557
| `"updated"` | The update succeed, but actions are required like "reboot" or "validate" |
5658

59+
Software description object:
60+
61+
| key | value | description |
62+
|-------------------|----------------|-------------------------------------------------------------------------------------|
63+
| `"id"` | string or null | The software unique identifier |
64+
| `"relname"` | string or null | The name of the release deployed on the device |
65+
| `"relvsn"` | string or null | The version of the release deployed on the device |
66+
| `"toolchain_rev"` | string or null | The revision hash of the toolchain used to build the release deployed on the device |
67+
| `"rtems_ver"` | string or null | The RTEMS version of the software depployed on the device |
68+
| `"otp_ver"` | string or null | The OTP version of the software depployed on the device |
69+
70+
Hardware description object:
71+
72+
| key | value | description |
73+
|-------------------|----------------|-------------------------------------------------------------------------------------|
74+
| `"platform"` | string | The hardware platform name |
75+
| `"version"` | string | The hardware version |
76+
| `"serial"` | string | The hardware serial number |
77+
| `"batch"` | integer | The hardware batch number |
78+
5779
</p>
5880
</details>
5981
<details><summary><i>Post - Start an update</i></summary>

src/grisp_connect_api.erl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,31 @@ handle_msg({request, M, Params, ID}) ->
2626

2727
%--- Internal Funcitons --------------------------------------------------------
2828

29+
maybe_put(Map, []) -> Map;
30+
maybe_put(Map, [{Key, Fun, Filter} | Rest]) ->
31+
maybe_put(maybe_put(Map, Key, Fun, Filter), Rest).
32+
33+
maybe_put(Map, Key, Fun, Filter) ->
34+
try Fun() of
35+
V when is_map(V) -> Map#{Key => maps:with(Filter, V)};
36+
_ -> Map
37+
catch
38+
_:_ -> Map
39+
end.
40+
2941
handle_notification([log, sync], Params) ->
3042
grisp_connect_log:sync(Params);
3143
handle_notification(Method, Params) ->
3244
?LOG_ERROR("Received unexpected notification ~p: ~p", [Method, Params]),
3345
ok.
3446

3547
handle_request([?method_get], #{type := <<"system_info">>} = _Params, ID) ->
36-
Info = grisp_connect_updater:system_info(),
48+
Info = maybe_put(grisp_connect_updater:system_info(), [
49+
{software, fun grisp_info:software/0,
50+
[id, relname, relvsn, profiles, toolchain_rev, rtems_ver, otp_ver]},
51+
{hardware, fun grisp_info:hardware/0,
52+
[platform, version, serial, batch]}
53+
]),
3754
{reply, Info, ID};
3855
handle_request([?method_post], #{type := <<"start_update">>} = Params, ID) ->
3956
try

0 commit comments

Comments
 (0)