1 package org.metricshub.ipmi.core.coding.payload.sol;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import org.metricshub.ipmi.core.coding.payload.IpmiPayload;
26 import org.metricshub.ipmi.core.common.MessageComposer;
27 import org.metricshub.ipmi.core.common.TypeConverter;
28
29
30
31
32 public abstract class SolMessage extends IpmiPayload {
33
34 public static final byte MIN_SEQUENCE_NUMBER = 1;
35 public static final byte MAX_SEQUENCE_NUMBER = 15;
36
37 private static final int PACKET_SEQUENCE_NUMBER_LENGTH = 1;
38 private static final int PACKET_ACK_SEQUENCE_NUMBER_LENGTH = 1;
39 private static final int ACCEPTED_CHARACTERS_LENGTH = 1;
40 private static final int OPERATION_STATUS_LENGTH = 1;
41
42 public static final int PAYLOAD_HEADER_LENGTH =
43 PACKET_SEQUENCE_NUMBER_LENGTH +
44 PACKET_ACK_SEQUENCE_NUMBER_LENGTH +
45 ACCEPTED_CHARACTERS_LENGTH +
46 OPERATION_STATUS_LENGTH;
47
48
49
50
51 private final byte sequenceNumber;
52
53
54
55
56 private final byte ackNackSequenceNumber;
57
58
59
60
61 private final byte acceptedCharacterCount;
62
63
64
65
66 private final byte operationStatus;
67
68 protected SolMessage(byte sequenceNumber, byte ackNackSequenceNumber, byte acceptedCharacterCount, byte operationStatus) {
69 this.sequenceNumber = trimSequenceNumber(sequenceNumber);
70 this.ackNackSequenceNumber = trimSequenceNumber(ackNackSequenceNumber);
71 this.acceptedCharacterCount = acceptedCharacterCount;
72 this.operationStatus = operationStatus;
73 }
74
75
76
77
78
79
80
81
82 private byte trimSequenceNumber(byte sequenceNumber) {
83 return TypeConverter.intToByte(sequenceNumber & MAX_SEQUENCE_NUMBER);
84 }
85
86 @Override
87 public byte[] getPayloadData() {
88 return MessageComposer.get(getPayloadLength())
89 .appendField(sequenceNumber)
90 .appendField(ackNackSequenceNumber)
91 .appendField(acceptedCharacterCount)
92 .appendField(operationStatus)
93 .appendField(getData())
94 .getMessage();
95 }
96
97 @Override
98 public int getPayloadLength() {
99 return PAYLOAD_HEADER_LENGTH + getData().length;
100 }
101
102 @Override
103 public byte[] getIpmiCommandData() {
104 return getData();
105 }
106
107 @Override
108 public byte[] getData() {
109 byte[] data = super.getData();
110
111 if (data == null) {
112 return new byte[0];
113 }
114
115 return data;
116 }
117
118 public byte getSequenceNumber() {
119 return sequenceNumber;
120 }
121
122 public byte getAckNackSequenceNumber() {
123 return ackNackSequenceNumber;
124 }
125
126 public byte getAcceptedCharacterCount() {
127 return acceptedCharacterCount;
128 }
129
130
131
132
133 public boolean isDataCarrier() {
134 return sequenceNumber != 0 || getData().length > 0;
135 }
136
137
138
139
140 public boolean isAcknowledgeMessage() {
141 return ackNackSequenceNumber != 0;
142 }
143 }