Skip to content

Commit

Permalink
add support for log V3 (CBOR)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori committed May 23, 2018
1 parent 3eb1bff commit 36f49f4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
public class McuMgrHeader {

public final static int NMGR_HEADER_LEN = 8;
public final static int HEADER_LENGTH = 8;

private int mOp;
private int mFlags;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void setCommandId(int commandId) {
}

public static McuMgrHeader fromBytes(byte[] header) {
if (header == null || header.length != NMGR_HEADER_LEN) {
if (header == null || header.length != HEADER_LENGTH) {
return null;
}
int op = ByteUtil.unsignedByteArrayToInt(header, 0, 1, Endian.BIG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ public static <T extends McuMgrResponse> T buildResponse(McuMgrScheme scheme, by
throw new IllegalArgumentException("Cannot use this method with a coap scheme");
}

byte[] payload = Arrays.copyOfRange(bytes, McuMgrHeader.NMGR_HEADER_LEN, bytes.length);
McuMgrHeader header = McuMgrHeader.fromBytes(Arrays.copyOf(bytes, McuMgrHeader.NMGR_HEADER_LEN));
byte[] payload = Arrays.copyOfRange(bytes, McuMgrHeader.HEADER_LENGTH, bytes.length);
McuMgrHeader header = McuMgrHeader.fromBytes(Arrays.copyOf(bytes, McuMgrHeader.HEADER_LENGTH));

// Initialize response and set fields
T response = CBOR.toObject(payload, type);
Expand Down Expand Up @@ -255,20 +255,20 @@ public static boolean requiresDefragmentation(McuMgrScheme scheme, byte[] bytes)
if (scheme.isCoap()) {
throw new RuntimeException("Method not implemented for coap");
} else {
return (expectedLength > (bytes.length - McuMgrHeader.NMGR_HEADER_LEN));
return (expectedLength > (bytes.length - McuMgrHeader.HEADER_LENGTH));
}
}

public static int getExpectedLength(McuMgrScheme scheme, byte[] bytes) throws IOException {
if (scheme.isCoap()) {
throw new RuntimeException("Method not implemented for coap");
} else {
byte[] headerBytes = Arrays.copyOf(bytes, McuMgrHeader.NMGR_HEADER_LEN);
byte[] headerBytes = Arrays.copyOf(bytes, McuMgrHeader.HEADER_LENGTH);
McuMgrHeader header = McuMgrHeader.fromBytes(headerBytes);
if (header == null) {
throw new IOException("Invalid McuMgrHeader");
}
return header.getLen() + McuMgrHeader.NMGR_HEADER_LEN;
return header.getLen() + McuMgrHeader.HEADER_LENGTH;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package io.runtime.mcumgr.response.log;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import io.runtime.mcumgr.response.McuMgrResponse;

public class McuMgrLogResponse extends McuMgrResponse {
Expand All @@ -18,11 +20,13 @@ public static class LogResult {
public Entry[] entries;
}

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

0 comments on commit 36f49f4

Please sign in to comment.