Skip to content

Add the optional software and hardware objects to the system info API… #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ and this project adheres to
- Add log event metadata instead of prepending "[JSON incompatible term]" to
log string data.

### Added

- Add the optional software and hardware information objects to the system
info API result.

## [2.0.0] - 2025-02-26

### Changed
Expand Down
22 changes: 22 additions & 0 deletions docs/grisp_connect_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ release name and version and if update is enabled.
| update_progress | integer | optional | The progress as a percentage |
| update_message | string | optional | Message describing the current state of the system |
| action_required | boolean | optional | `"reboot"`, `"remove_sdcard_and_reboot"` or `"validate"` |
| software | object | optional | Object describing the software running in the device |
| hardware | object | optional | Object describing the hardware of the device |

Meaning of the status:

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

Software description object:

| key | value | description |
|-------------------|----------------|-------------------------------------------------------------------------------------|
| `"id"` | string or null | The software unique identifier |
| `"relname"` | string or null | The name of the release deployed on the device |
| `"relvsn"` | string or null | The version of the release deployed on the device |
| `"toolchain_rev"` | string or null | The revision hash of the toolchain used to build the release deployed on the device |
| `"rtems_ver"` | string or null | The RTEMS version of the software depployed on the device |
| `"otp_ver"` | string or null | The OTP version of the software depployed on the device |

Hardware description object:

| key | value | description |
|-------------------|----------------|-------------------------------------------------------------------------------------|
| `"platform"` | string | The hardware platform name |
| `"version"` | string | The hardware version |
| `"serial"` | string | The hardware serial number |
| `"batch"` | integer | The hardware batch number |

</p>
</details>
<details><summary><i>Post - Start an update</i></summary>
Expand Down
19 changes: 18 additions & 1 deletion src/grisp_connect_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,31 @@ handle_msg({request, M, Params, ID}) ->

%--- Internal Funcitons --------------------------------------------------------

maybe_put(Map, []) -> Map;
maybe_put(Map, [{Key, Fun, Filter} | Rest]) ->
maybe_put(maybe_put(Map, Key, Fun, Filter), Rest).

maybe_put(Map, Key, Fun, Filter) ->
try Fun() of
V when is_map(V) -> Map#{Key => maps:with(Filter, V)};
_ -> Map
catch
_:_ -> Map
end.

handle_notification([log, sync], Params) ->
grisp_connect_log:sync(Params);
handle_notification(Method, Params) ->
?LOG_ERROR("Received unexpected notification ~p: ~p", [Method, Params]),
ok.

handle_request([?method_get], #{type := <<"system_info">>} = _Params, ID) ->
Info = grisp_connect_updater:system_info(),
Info = maybe_put(grisp_connect_updater:system_info(), [
{software, fun grisp_info:software/0,
[id, relname, relvsn, profiles, toolchain_rev, rtems_ver, otp_ver]},
{hardware, fun grisp_info:hardware/0,
[platform, version, serial, batch]}
]),
{reply, Info, ID};
handle_request([?method_post], #{type := <<"start_update">>} = Params, ID) ->
try
Expand Down