1 package org.metricshub.ipmi.core.coding.commands.sel;
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 java.security.InvalidKeyException;
26 import java.security.NoSuchAlgorithmException;
27
28 import org.metricshub.ipmi.core.coding.commands.CommandCodes;
29 import org.metricshub.ipmi.core.coding.commands.IpmiCommandCoder;
30 import org.metricshub.ipmi.core.coding.payload.IpmiPayload;
31 import org.metricshub.ipmi.core.coding.payload.lan.IPMIException;
32 import org.metricshub.ipmi.core.coding.payload.lan.IpmiLanRequest;
33 import org.metricshub.ipmi.core.coding.payload.lan.NetworkFunction;
34 import org.metricshub.ipmi.core.coding.protocol.IpmiMessage;
35 import org.metricshub.ipmi.core.common.TypeConverter;
36
37
38
39
40
41 public class GetSelTimeUtcOffset extends IpmiCommandCoder<GetSelTimeUtcOffsetResponseData> {
42
43 private static final int RESPONSE_LENGTH = 2;
44
45
46
47
48 public GetSelTimeUtcOffset() {}
49
50 @Override
51 public byte getCommandCode() {
52 return CommandCodes.GET_SEL_TIME_UTC_OFFSET;
53 }
54
55 @Override
56 public NetworkFunction getNetworkFunction() {
57 return NetworkFunction.StorageRequest;
58 }
59
60 @Override
61 protected IpmiPayload preparePayload(int sequenceNumber) throws NoSuchAlgorithmException, InvalidKeyException {
62 return new IpmiLanRequest(getNetworkFunction(), getCommandCode(), null, TypeConverter.intToByte(sequenceNumber));
63 }
64
65 @Override
66 public GetSelTimeUtcOffsetResponseData getResponseData(IpmiMessage message)
67 throws IPMIException,
68 NoSuchAlgorithmException,
69 InvalidKeyException {
70 byte[] raw = validateResponse(message);
71
72 if (raw == null || raw.length != RESPONSE_LENGTH) {
73 throw new IllegalArgumentException("Invalid response payload length: " + (raw != null ? raw.length : "null"));
74 }
75
76 GetSelTimeUtcOffsetResponseData responseData = new GetSelTimeUtcOffsetResponseData();
77
78 responseData.setOffsetMinutes((short) ((raw[0] & 0xff) | (raw[1] & 0xff) << 8));
79 return responseData;
80 }
81 }