private bool GetRobotEvent(byte mode, out byte[] data) { byte[] header = UBT.V2_GetEventHeader(mode); if (header == null) { data = null; return(false); } int evtCount = header[CONST.EH.OFFSET.COUNT]; data = new byte[evtCount * BLOCKLY.EVENT.SIZE]; byte startIdx = 0; while (startIdx < evtCount) { byte[] result = UBT.V2_GetEventData(mode, startIdx); if (result == null) { return(false); } byte count = result[CONST.ED.OFFSET.COUNT]; if (count > CONST.ED.BATCH_SIZE) { return(false); // Abnormal case } if (startIdx + count > evtCount) { return(false); } int startPos = startIdx * BLOCKLY.EVENT.SIZE; int bytes = count * BLOCKLY.EVENT.SIZE; for (int i = 0; i < bytes; i++) { data[startPos + i] = result[CONST.ED.OFFSET.DATA + i]; } startIdx += count; } return(true); }