Skip to content

Commit

Permalink
Default manager / Bootloader info command
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 committed Aug 4, 2023
1 parent ef7f77a commit 6aec45e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.runtime.mcumgr.response.HasReturnCode;
import io.runtime.mcumgr.response.McuMgrResponse;
import io.runtime.mcumgr.response.dflt.McuMgrAppInfoResponse;
import io.runtime.mcumgr.response.dflt.McuMgrBootloaderInfoResponse;
import io.runtime.mcumgr.response.dflt.McuMgrEchoResponse;
import io.runtime.mcumgr.response.dflt.McuMgrMpStatResponse;
import io.runtime.mcumgr.response.dflt.McuMgrOsResponse;
Expand Down Expand Up @@ -92,6 +93,7 @@ default DefaultManager.ReturnCode getOsReturnCode() {
private final static int ID_RESET = 5;
private final static int ID_MCUMGR_PARAMS = 6;
private final static int ID_APP_INFO = 7;
private final static int ID_BOOTLOADER_INFO = 8;

/**
* Construct an default manager.
Expand Down Expand Up @@ -353,4 +355,40 @@ public McuMgrResponse appInfo(@Nullable String format) throws McuMgrException {
}
return send(OP_READ, ID_APP_INFO, payloadMap, SHORT_TIMEOUT, McuMgrParamsResponse.class);
}

public static String BOOTLOADER_INFO_QUERY_MODE = "mode";

/**
* Reads the Bootloader info (asynchronous).
*
* @param query Allows to query MCUmgr about bootloader used by device and various bootloader
* parameters. Use {@link #BOOTLOADER_INFO_QUERY_MODE} to get the bootloader mode.
* @param callback the asynchronous callback.
*/
public void bootloaderInfo(@Nullable String query, @NotNull McuMgrCallback<McuMgrBootloaderInfoResponse> callback) {
HashMap<String, Object> payloadMap = null;
if (query != null) {
payloadMap = new HashMap<>();
payloadMap.put("query", query);
}
send(OP_READ, ID_BOOTLOADER_INFO, payloadMap, SHORT_TIMEOUT, McuMgrBootloaderInfoResponse.class, callback);
}

/**
* Reads the Bootloader info (synchronous).
*
* @param query Allows to query MCUmgr about bootloader used by device and various bootloader
* parameters. Use {@link #BOOTLOADER_INFO_QUERY_MODE} to get the bootloader mode.
* @return The response.
* @throws McuMgrException Transport error. See cause.
*/
@NotNull
public McuMgrBootloaderInfoResponse bootloaderInfo(@Nullable String query) throws McuMgrException {
HashMap<String, Object> payloadMap = null;
if (query != null) {
payloadMap = new HashMap<>();
payloadMap.put("query", query);
}
return send(OP_READ, ID_BOOTLOADER_INFO, payloadMap, SHORT_TIMEOUT, McuMgrBootloaderInfoResponse.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) Intellinium SAS, 2014-present
*
* SPDX-License-Identifier: Apache-2.0
*/

package io.runtime.mcumgr.response.dflt;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/** @noinspection unused*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class McuMgrBootloaderInfoResponse extends McuMgrOsResponse {
/** Unknown mode of MCUboot. */
public static final int MODE_UNKNOWN = -1;
/** MCUboot is in single application mode. */
public static final int MODE_SINGLE_APP = 0;
/** MCUboot is in swap using scratch partition mode. */
public static final int MODE_SWAP_SCRATCH = 1;
/** MCUboot is in swap without scratch mode. */
public static final int MODE_SWAP_WITHOUT_SCRATCH = 2;
/** MCUboot is in DirectXIP mode. */
public static final int MODE_DIRECT_XIP = 3;

// Note: other modes may be added in the future.

/** Text response including requested parameters. */
@JsonProperty("mode")
public int mode = MODE_UNKNOWN;

@JsonProperty("bootloader")
public String bootloader;

@JsonCreator
public McuMgrBootloaderInfoResponse() {}
}

0 comments on commit 6aec45e

Please sign in to comment.