|
| 1 | +/* |
| 2 | + * Copyright (C) Photon Vision. |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.photonvision.common.hardware.metrics.proto; |
| 19 | + |
| 20 | +import edu.wpi.first.util.protobuf.Protobuf; |
| 21 | +import org.photonvision.common.hardware.metrics.DeviceMetrics; |
| 22 | +import org.photonvision.proto.Photon.ProtobufDeviceMetrics; |
| 23 | +import us.hebi.quickbuf.Descriptors.Descriptor; |
| 24 | + |
| 25 | +public class DeviceMetricsProto implements Protobuf<DeviceMetrics, ProtobufDeviceMetrics> { |
| 26 | + @Override |
| 27 | + public Class<DeviceMetrics> getTypeClass() { |
| 28 | + return DeviceMetrics.class; |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public Descriptor getDescriptor() { |
| 33 | + return ProtobufDeviceMetrics.getDescriptor(); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public ProtobufDeviceMetrics createMessage() { |
| 38 | + return ProtobufDeviceMetrics.newInstance(); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public DeviceMetrics unpack(ProtobufDeviceMetrics msg) { |
| 43 | + return new DeviceMetrics( |
| 44 | + msg.getCpuTemp(), |
| 45 | + msg.getCpuUtil(), |
| 46 | + msg.getCpuMem(), |
| 47 | + msg.getCpuThr(), |
| 48 | + msg.getCpuUptime(), |
| 49 | + msg.getGpuMem(), |
| 50 | + msg.getRamUtil(), |
| 51 | + msg.getGpuMemUtil(), |
| 52 | + msg.getDiskUtilPct(), |
| 53 | + msg.getNpuUsage(), |
| 54 | + msg.getIpAddress()); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public void pack(ProtobufDeviceMetrics msg, DeviceMetrics value) { |
| 59 | + msg.setCpuTemp(value.cpuTemp()); |
| 60 | + msg.setCpuUtil(value.cpuUtil()); |
| 61 | + msg.setCpuMem(value.cpuMem()); |
| 62 | + msg.setCpuThr(value.cpuThr()); |
| 63 | + msg.setCpuUptime(value.cpuUptime()); |
| 64 | + msg.setGpuMem(value.gpuMem()); |
| 65 | + msg.setRamUtil(value.ramUtil()); |
| 66 | + msg.setGpuMemUtil(value.gpuMemUtil()); |
| 67 | + msg.setDiskUtilPct(value.diskUtilPct()); |
| 68 | + msg.setNpuUsage(value.npuUsage()); |
| 69 | + msg.setIpAddress(value.ipAddress()); |
| 70 | + } |
| 71 | +} |
0 commit comments