NordicSemiconductor / Android-nRF-Connect-Device-Manager

A mobile management library for devices running Apache Mynewt and Zephyr (DFU, logs, stats, config, etc.)
Apache License 2.0
85 stars 41 forks source link

Question: In the context of file-uploading and file-downloading what is the enum type of HasReturnCode.GroupReturnCode.group and .rc? #201

Open ksidirop-laerdal opened 1 month ago

ksidirop-laerdal commented 1 month ago

https://github.com/NordicSemiconductor/Android-nRF-Connect-Device-Manager/blob/main/mcumgr-core/src/main/java/io/runtime/mcumgr/response/HasReturnCode.java

In our Laerdal.McuMgr bindings-library we need to perform exception-mapping and error-mapping between the Java world and the C# world whenever an error occurs during file-downloading or file-uploading (for example "file not found", "corrupted", etc).

private final class FileDownloaderCallbackProxy implements DownloadCallback
{
        @Override
        public void onDownloadFailed(@NonNull final McuMgrException exception)
        { ...
        }
}

private final class FileUploaderCallbackProxy implements UploadCallback
{
        @Override
        public void onUploadFailed(@NonNull final McuMgrException error)
        {...
        }
}

Is it correct to say that in the context of file-uploading and file-downloading any McuMgrErrorException adheres to the following statements?

exception.getGroupCode().rc (int field)          ->  always adheres to 'enum McuMgrErrorCode' (?)
exception.getGroupCode().group (int field)   ->  always adheres to 'enum FsManager.ReturnCode' (?)

Likewise in the case of firmware-installation we have the following callbacks-proxy:

private final class FirmwareInstallCallbackProxy implements FirmwareUpgradeCallback<FirmwareUpgradeManager.State>
{
        @Override
        public void onUpgradeFailed(final FirmwareUpgradeManager.State state, final McuMgrException ex)
        {   ...
        }
}

Is it correct to say that in the context of firmware-installation any McuMgrErrorException adheres to the following statements?

exception.getGroupCode().rc (int field)          ->  always adheres to 'enum McuMgrErrorCode' (?)
exception.getGroupCode().group (int field)   ->  always adheres to 'enum ImageManager.ReturnCode' (?)

( I just want to be sure that there isn't some corner case where these integer fields are adhering to some other enums because if this happens our error-mapping and exception-mapping will end up mapping and reporting the wrong kind of error over to the C# world misleading the host-application! )

philips77 commented 1 month ago

The group is the ID of the manager (group), so that's one of these: https://github.com/NordicSemiconductor/Android-nRF-Connect-Device-Manager/blob/389c60095a11e685ec3023fc33eed205866f87e2/mcumgr-core/src/main/java/io/runtime/mcumgr/McuManager.java#L60-L76

The rc is a the [TheManagerWithGivenGroupId].ReturnCode. So, if exception.getGroupCode().rc == 8 (FSManager), than rc adheres to 'enum FsManager.ReturnCode', etc.

philips77 commented 1 month ago

If the device doesn't support SMP v. 2, the exception.getGroupCode() returns null, and you need to use exception.getCode(), which adverse to https://github.com/NordicSemiconductor/Android-nRF-Connect-Device-Manager/blob/389c60095a11e685ec3023fc33eed205866f87e2/mcumgr-core/src/main/java/io/runtime/mcumgr/McuMgrErrorCode.java#L24

ksidirop-laerdal commented 1 month ago

Appreciate the prompt response. Now it all makes sense. Just a quick follow up question or two:

  1. I tried to track down the return codes for the following groups but I couldn't spot them anywhere in the code base:
int GROUP_LOGS   = 4
int GROUP_CRASH  = 5
int GROUP_SPLIT  = 6
int GROUP_RUN    = 7
  1. On the flip-side I've found the BasicManager.ReturnCode enum in the java libraries but I can't see which group it belongs to. Does it have a group-id and if so which one?

Appreciate any insights!

philips77 commented 1 month ago

Hi, Basic Group is called Zephyr Group, as far as I remember. These are Zephyr specific commands, or actually just one, the erase app settings.

The other group you mentioned aren't supported on Zephyr, thus weren't migrated to SMP V2, so they don't support group errors.

ksidirop-laerdal commented 1 month ago

Basic Group is called Zephyr Group, as far as I remember. These are Zephyr specific commands, or actually just one, the erase app settings.

Cool. By the way what is the group-id of the basic-group ("zephyr-group"). Can I find it somewhere?

(pardon me if I'm missing something obvious while reading between the lines)