1 package org.metricshub.ipmi.core.coding.payload.sol; 2 3 /*- 4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ 5 * IPMI Java Client 6 * ჻჻჻჻჻჻ 7 * Copyright 2023 Verax Systems, MetricsHub 8 * ჻჻჻჻჻჻ 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU Lesser General Public License as 11 * published by the Free Software Foundation, either version 3 of the 12 * License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Lesser Public License for more details. 18 * 19 * You should have received a copy of the GNU General Lesser Public 20 * License along with this program. If not, see 21 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 22 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 23 */ 24 25 import org.metricshub.ipmi.core.common.TypeConverter; 26 27 import java.util.HashSet; 28 import java.util.Set; 29 30 /** 31 * {@link SolOutboundOperationField} is a transfer object for operation sent by this application to remote system in {@link SolOutboundMessage}. 32 */ 33 public class SolOutboundOperationField { 34 35 /** 36 * Acknowledge state of {@link SolMessage} that this message is response for. 37 */ 38 private final SolAckState ackState; 39 40 /** 41 * Set of operations to invoke on BMC. 42 */ 43 private final Set<SolOperation> operations; 44 45 /** 46 * Creates new instance of {@link SolOutboundOperationField} filled with given data. 47 * 48 * @param ackState 49 * Acknowledge state carried by this object 50 * @param operations 51 * Set of SOL specific operations for outbound message 52 */ 53 public SolOutboundOperationField(SolAckState ackState, Set<SolOperation> operations) { 54 this.ackState = ackState; 55 this.operations = operations; 56 } 57 58 /** 59 * Creates new instance of {@link SolOutboundOperationField} from raw byte. 60 * 61 * @param raw 62 * byte carrying information about SOL operations 63 */ 64 public SolOutboundOperationField(byte raw) { 65 this.ackState = SolAckState.extractFromByte(raw); 66 this.operations = extractOperationsFromByte(raw); 67 } 68 69 protected Set<SolOperation> extractOperationsFromByte(byte raw) { 70 Set<SolOperation> result = new HashSet<SolOperation>(); 71 72 for (SolOperation operation : SolOperation.values()) { 73 if (TypeConverter.isBitSetOnPosition(operation.getOperationNumber(), raw)) { 74 result.add(operation); 75 } 76 } 77 78 return result; 79 } 80 81 public Set<SolOperation> getOperations() { 82 return operations; 83 } 84 85 public SolAckState getAckState() { 86 return ackState; 87 } 88 89 /** 90 * Convert this object to it's raw, byte representation. 91 */ 92 public byte convertToByte() { 93 byte value = (byte) 0; 94 95 value = ackState.encodeInByte(value); 96 97 for (SolOperation operation : operations) { 98 value = TypeConverter.setBitOnPosition(operation.getOperationNumber(), value); 99 } 100 101 return value; 102 } 103 104 }