Android-nRF-Mesh-Library icon indicating copy to clipboard operation
Android-nRF-Mesh-Library copied to clipboard

Add a command to fetch the user properties list

Open vkurkchi opened this issue 2 years ago • 2 comments

The current implementation lacks the functionality to retrieve the list of supported user properties. My suggestion is to add 2 new structures GenericUserPropertiesGet and GenericUserPropertiesStatus, described in Mesh Models documentation, sections 3.2.8.1 and 3.2.8.2 respectively.

The implementation could look something like this:

public class GenericUserPropertiesGet extends ApplicationMessage {

    private static final String TAG = GenericUserPropertiesGet.class.getSimpleName();
    private static final int OP_CODE = ApplicationMessageOpCodes.GENERIC_USER_PROPERTIES_GET;


    /**
     * Constructs GenericLevelGet message.
     *
     * @param appKey {@link ApplicationKey} key for this message
     * @throws IllegalArgumentException if any illegal arguments are passed
     */
    public GenericUserPropertiesGet(@NonNull final ApplicationKey appKey) throws IllegalArgumentException {
        super(appKey);
        assembleMessageParameters();
    }

    @Override
    public int getOpCode() {
        return OP_CODE;
    }

    @Override
    void assembleMessageParameters() {
        mAid = SecureUtils.calculateK4(mAppKey.getKey());
    }
}

and

public class GenericUserPropertiesStatus extends ApplicationStatusMessage  implements Parcelable {

    private final int opCode;
    private ArrayList<Short> propertyIds;

    private static final Creator<GenericUserPropertiesStatus> CREATOR = new Creator<GenericUserPropertiesStatus>() {
        @Override
        public GenericUserPropertiesStatus createFromParcel(Parcel in) {
            final AccessMessage message = in.readParcelable(AccessMessage.class.getClassLoader());
            //noinspection ConstantConditions
            return new GenericUserPropertiesStatus(message);
        }

        @Override
        public GenericUserPropertiesStatus[] newArray(int size) {
            return new GenericUserPropertiesStatus[size];
        }
    };

    public GenericUserPropertiesStatus(@NonNull final AccessMessage message) {
        super(message);
        this.opCode = message.getOpCode();
        this.mMessage = message;
        this.mParameters = message.getParameters();
        parseStatusParameters();
    }

    @Override
    void parseStatusParameters() {
        BitReader bitReader = new BitReader(mParameters);
        propertyIds = new ArrayList<Short>(mParameters.length / 2);
        for(int i = 0; i < mParameters.length; i += 2) {
            int firstPropertyByte = bitReader.getBits(8);
            int secondPropertyByte = bitReader.getBits(8);

            propertyIds.add((short) (secondPropertyByte << 8 | firstPropertyByte));
        }
    }

    @Override
    public int getOpCode() {
        return opCode;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        final AccessMessage message = (AccessMessage) mMessage;
        dest.writeParcelable(message, flags);
    }

    public ArrayList<Short> getPropertyIds() {
        return propertyIds;
    }
}

vkurkchi avatar Nov 10 '23 13:11 vkurkchi