Skip to content

Commit 7c2a871

Browse files
authored
Merge pull request #217 from NordicSemiconductor/bugfix/slot-info
Slot Info command
2 parents 7bf52ef + ab583f5 commit 7c2a871

File tree

3 files changed

+81
-41
lines changed

3 files changed

+81
-41
lines changed

mcumgr-core/src/main/java/io/runtime/mcumgr/managers/ImageManager.java

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.runtime.mcumgr.response.UploadResponse;
3434
import io.runtime.mcumgr.response.img.McuMgrCoreLoadResponse;
3535
import io.runtime.mcumgr.response.img.McuMgrImageResponse;
36+
import io.runtime.mcumgr.response.img.McuMgrImageSlotResponse;
3637
import io.runtime.mcumgr.response.img.McuMgrImageStateResponse;
3738
import io.runtime.mcumgr.response.img.McuMgrImageUploadResponse;
3839
import io.runtime.mcumgr.transfer.Download;
@@ -208,7 +209,7 @@ default ImageManager.ReturnCode getImageReturnCode() {
208209
private final static int ID_CORELIST = 3;
209210
private final static int ID_CORELOAD = 4;
210211
private final static int ID_ERASE = 5;
211-
private final static int ID_ERASE_STATE = 6;
212+
private final static int ID_SLOT_INFO = 6;
212213

213214
/**
214215
* Construct an image manager.
@@ -513,55 +514,23 @@ public McuMgrImageResponse erase(int slot) throws McuMgrException {
513514
}
514515

515516
/**
516-
* Erase the state of secondary slot of main image (asynchronous).
517+
* Reads slot information (asynchronous).
517518
*
518519
* @param callback the asynchronous callback.
519520
*/
520-
public void eraseState(@NotNull McuMgrCallback<McuMgrImageResponse> callback) {
521-
eraseState(0, callback);
521+
public void slots(@NotNull McuMgrCallback<McuMgrImageSlotResponse> callback) {
522+
send(OP_READ, ID_SLOT_INFO, null, SHORT_TIMEOUT, McuMgrImageSlotResponse.class, callback);
522523
}
523524

524525
/**
525-
* Erase the state of secondary slot of the main image (asynchronous).
526-
*
527-
* @param image the image number, default is 0. Use 0 for core0, 1 for core1, etc.
528-
* @param callback the asynchronous callback.
529-
*/
530-
public void eraseState(int image, @NotNull McuMgrCallback<McuMgrImageResponse> callback) {
531-
HashMap<String, Object> payloadMap = null;
532-
if (image > 0) {
533-
payloadMap = new HashMap<>();
534-
payloadMap.put("image", image);
535-
}
536-
send(OP_WRITE, ID_ERASE_STATE, payloadMap, DEFAULT_TIMEOUT, McuMgrImageResponse.class, callback);
537-
}
538-
539-
/**
540-
* Erase the state of secondary slot of the main image (synchronous).
526+
* Reads slot information (synchronous).
541527
*
542528
* @return The response.
543529
* @throws McuMgrException Transport error. See cause.
544530
*/
545531
@NotNull
546-
public McuMgrImageResponse eraseState() throws McuMgrException {
547-
return eraseState(0);
548-
}
549-
550-
/**
551-
* Erase the state of secondary slot of given image (synchronous).
552-
*
553-
* @param image the image number, default is 0. Use 0 for core0, 1 for core1, etc.
554-
* @return The response.
555-
* @throws McuMgrException Transport error. See cause.
556-
*/
557-
@NotNull
558-
public McuMgrImageResponse eraseState(int image) throws McuMgrException {
559-
HashMap<String, Object> payloadMap = null;
560-
if (image > 0) {
561-
payloadMap = new HashMap<>();
562-
payloadMap.put("image", image);
563-
}
564-
return send(OP_WRITE, ID_ERASE_STATE, payloadMap, SHORT_TIMEOUT, McuMgrImageResponse.class);
532+
public McuMgrImageSlotResponse slots() throws McuMgrException {
533+
return send(OP_READ, ID_SLOT_INFO, null, SHORT_TIMEOUT, McuMgrImageSlotResponse.class);
565534
}
566535

567536
/**
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) Intellinium SAS, 2014-present
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
package io.runtime.mcumgr.response.img;
7+
8+
import com.fasterxml.jackson.annotation.JsonCreator;
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
11+
import io.runtime.mcumgr.managers.ImageManager;
12+
import io.runtime.mcumgr.response.McuMgrResponse;
13+
14+
@SuppressWarnings("unused")
15+
public class McuMgrImageSlotResponse extends McuMgrResponse implements ImageManager.Response {
16+
/** Slot information for each image (core). */
17+
@JsonProperty("images")
18+
public Image[] images;
19+
20+
/**
21+
* The single image data structure.
22+
*/
23+
public static class Image {
24+
25+
/**
26+
* The single slot data structure.
27+
*/
28+
public static class Slot {
29+
/** The slot number: 0 or 1. */
30+
@JsonProperty("slot")
31+
public int slot;
32+
/** The slot size in bytes. */
33+
@JsonProperty("size")
34+
public int size;
35+
/**
36+
* Optional field (only present if <code>CONFIG_MCUMGR_GRP_IMG_DIRECT_UPLOAD</code> is
37+
* enabled to allow direct image uploads) which specifies the image ID that can be
38+
* used by external tools to upload an image to that slot.
39+
*/
40+
@JsonProperty("upload_image_id")
41+
public Integer uploadImageId;
42+
43+
@JsonCreator
44+
public Slot() {}
45+
}
46+
47+
/**
48+
* The image number used for multi-core devices.
49+
* The main core image has index 0, second core image is 1, etc.
50+
* E.g. nRF5340 has 2 cores: application core (0) and network core (1).
51+
* For single core devices the value is 0 (default).
52+
*/
53+
@JsonProperty("image")
54+
public int image;
55+
@JsonProperty("slots")
56+
public Slot[] slots;
57+
/**
58+
* Optional field (only present if <code>CONFIG_MCUMGR_GRP_IMG_TOO_LARGE_SYSBUILD</code> or
59+
* <code>CONFIG_MCUMGR_GRP_IMG_TOO_LARGE_BOOTLOADER_INFO</code> are enabled) which specifies the
60+
* maximum size of an application that can be uploaded to that image number.
61+
*/
62+
@JsonProperty("max_image_size")
63+
public Integer maxImageSize;
64+
65+
@JsonCreator
66+
public Image() {}
67+
}
68+
69+
@JsonCreator
70+
public McuMgrImageSlotResponse() {}
71+
}

mcumgr-core/src/main/java/io/runtime/mcumgr/response/img/McuMgrImageStateResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ public static class ImageSlot {
6363
*/
6464
@JsonProperty("pending")
6565
public boolean pending;
66-
/** An image is confirmed when it managed to boot on slot 0. */
66+
/** An image is confirmed when it managed to boot from and was confirmed. */
6767
@JsonProperty("confirmed")
6868
public boolean confirmed;
69-
/** An image is active when it is running on slot 0. */
69+
/** An image is active when it is running. */
7070
@JsonProperty("active")
7171
public boolean active;
7272
/** An image is permanent after it was confirmed using <i>confirm</i> command. */

0 commit comments

Comments
 (0)