Package: BitTask

BitTask

nameinstructionbranchcomplexitylinemethod
BitTask(ChannelRecord, int, int, Mode)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
runRead()
M: 0 C: 58
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
runUpdate(ToplevelBlockTask, ToplevelBlockTask)
M: 10 C: 55
85%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 12
92%
M: 0 C: 1
100%
runWrite()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setBit(int)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017 Eurotech and/or its affiliates and others
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: * Contributors:
10: * Eurotech
11: *******************************************************************************/
12:
13: package org.eclipse.kura.driver.block.task;
14:
15: import org.eclipse.kura.channel.ChannelRecord;
16: import org.eclipse.kura.driver.binary.Buffer;
17: import org.eclipse.kura.type.BooleanValue;
18: import org.slf4j.Logger;
19: import org.slf4j.LoggerFactory;
20:
21: public class BitTask extends UpdateBlockTask {
22:
23: private static final Logger logger = LoggerFactory.getLogger(BitTask.class);
24: private int bit;
25:
26: public BitTask(ChannelRecord record, int start, int bit, Mode mode) {
27: super(record, start, start + 1, mode);
28: this.bit = bit;
29: }
30:
31: public void setBit(int bit) {
32: this.bit = bit;
33: }
34:
35: @Override
36: protected void runRead() {
37: final ToplevelBlockTask parent = getParent();
38: Buffer buffer = parent.getBuffer();
39:
40: byte b = buffer.get(getStart() - parent.getStart());
41:
42:• final boolean result = (b >> this.bit & 0x01) == 1;
43:
44: logger.debug("Reading Bit: offset {} bit index {} result {}", getStart(), this.bit, result);
45:
46: this.record.setValue(new BooleanValue(result));
47: onSuccess();
48: }
49:
50: @Override
51: protected void runWrite() {
52: logger.warn("Write mode not supported");
53: onFailure(new UnsupportedOperationException(
54: "BitTask does not support WRITE mode, only READ and UPDATE modes are supported"));
55: }
56:
57: @Override
58: protected void runUpdate(ToplevelBlockTask write, ToplevelBlockTask read) {
59: Buffer outBuffer = write.getBuffer();
60: Buffer inBuffer = read.getBuffer();
61:
62: final int previousValueOffset = getStart() - read.getStart();
63: final boolean value = (Boolean) this.record.getValue().getValue();
64:
65: byte byteValue = inBuffer.get(previousValueOffset);
66:
67:• if (value) {
68: byteValue |= 1 << this.bit;
69: } else {
70: byteValue &= ~(1 << this.bit);
71: }
72:
73: inBuffer.put(previousValueOffset, byteValue);
74: logger.debug("Write Bit: offset: {} value: {}", getStart(), value);
75: outBuffer.put(getStart() - write.getStart(), byteValue);
76: }
77: }