2
0
mirror of https://opendev.org/x/pyghmi synced 2025-08-21 18:40:20 +00:00

Merge "Migrate V2 and newer systems to new meters"

This commit is contained in:
Zuul
2022-08-29 13:51:28 +00:00
committed by Gerrit Code Review

View File

@@ -27,6 +27,15 @@ class EnergyManager(object):
# We start with a 'find firmware instance' to test the water and
# get the handle (which has always been the same, but just in case
self.iana = bytearray(b'\x66\x4a\x00')
self._usefapm = False
try:
rsp = ipmicmd.xraw_command(netfn=0x3a, command=0x32, data=[4, 2, 0, 0, 0])
self.supportedmeters = ('DC Energy',)
self._usefapm = True
return
except pygexc.IpmiException:
pass
try:
rsp = ipmicmd.xraw_command(netfn=0x2e, command=0x82,
data=self.iana + b'\x00\x00\x01')
@@ -47,6 +56,12 @@ class EnergyManager(object):
else:
self.supportedmeters = ('DC Energy',)
def get_fapm_energy(self, ipmicmd):
rsp = ipmicmd.xraw_command(netfn=0x3a, command=0x32, data=[4, 2, 0, 0, 0])
j, mj = struct.unpack('<IH', rsp['data'][2:8])
mj = mj + (j * 1000)
return float(mj / 1000000 / 3600)
def get_energy_precision(self, ipmicmd):
rsp = ipmicmd.xraw_command(
netfn=0x2e, command=0x81,
@@ -67,6 +82,8 @@ class EnergyManager(object):
raise
def get_dc_energy(self, ipmicmd):
if self._usefapm:
return self.get_fapm_energy(ipmicmd)
rsp = ipmicmd.xraw_command(
netfn=0x2e, command=0x81,
data=self.iana + self.modhandle + b'\x01\x82\x00\x08')