Skip to content

Commit

Permalink
deprecate log v2; finish support for log v3
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori committed May 25, 2018
1 parent 36f49f4 commit 549136a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ public static <T extends McuMgrResponse> T buildResponse(McuMgrScheme scheme, by


/**
* Build a CoAP McuMgrResponse. This method will also throw a McuMgrCoapException if the CoAP
* Build a CoAP McuMgrResponse. This method will throw a McuMgrCoapException if the CoAP
* response code indicates an error.
*
* @param scheme The transport scheme used (should be either COAP_BLE or COAP_UDP).
* @param bytes The packet's bytes
* @param bytes The packet's bytes, including the CoAP header
* @param header The raw McuManager header
* @param payload the raw McuManager payload
* @param codeClass The class of the CoAP response code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@

package io.runtime.mcumgr.response.log;

import android.support.annotation.Nullable;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import io.runtime.mcumgr.response.McuMgrResponse;
import io.runtime.mcumgr.util.CBOR;

public class McuMgrLogResponse extends McuMgrResponse {
public int next_index;
Expand All @@ -22,11 +28,33 @@ public static class LogResult {

@JsonIgnoreProperties(ignoreUnknown = true)
public static class Entry {
public String msg;
public byte[] msg;
public long ts;
public int level;
public int index;
public int module;
public String type;

/**
* Get a string representation of the message based on the message type.
* @return the type decoded string of the log message or null if the msg is null or decoding
* failed
*/
@Nullable
public String getMessage() {
if (msg == null) {
return null;
}
if (type != null && type.equals("cbor")) {
try {
return CBOR.toString(msg);
} catch (IOException e) {
e.printStackTrace();
return null;
}
} else {
return new String(msg, StandardCharsets.UTF_8);
}
}
}
}

0 comments on commit 549136a

Please sign in to comment.