-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: read header to determine num sensors/readings, large refactor t…
…o improve clarity
- Loading branch information
1 parent
0d52243
commit 75b9a65
Showing
10 changed files
with
255 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package hwinfoShMem | ||
|
||
// #include "hwisenssm2.h" | ||
import "C" | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
const headerLength = C.sizeof_HWiNFO_SENSORS_SHARED_MEM2 | ||
|
||
type Header struct { | ||
c C.PHWiNFO_SENSORS_SHARED_MEM2 | ||
} | ||
|
||
func NewHeader(data []byte) Header { | ||
return Header{ | ||
c: C.PHWiNFO_SENSORS_SHARED_MEM2(unsafe.Pointer(&data[0])), | ||
} | ||
} | ||
|
||
// Signature "HWiS" if active, 'DEAD' when inactive | ||
func (header *Header) Signature() string { | ||
return DecodeCharPtr(unsafe.Pointer(&header.c.dwSignature), C.sizeof_DWORD) | ||
} | ||
|
||
// Version version of shared memory | ||
func (header *Header) Version() int { | ||
return int(header.c.dwVersion) | ||
} | ||
|
||
// Revision revision of version | ||
func (header *Header) Revision() int { | ||
return int(header.c.dwRevision) | ||
} | ||
|
||
// PollTime last polling time | ||
func (header *Header) PollTime() uint64 { | ||
addr := unsafe.Pointer(uintptr(unsafe.Pointer(&header.c.dwRevision)) + C.sizeof_DWORD) | ||
return uint64(*(*C.__time64_t)(addr)) | ||
} | ||
|
||
// OffsetOfSensorSection offset of the Sensor section from beginning of HWiNFO_SENSORS_SHARED_MEM2 | ||
func (header *Header) OffsetOfSensorSection() int { | ||
return int(header.c.dwOffsetOfSensorSection) | ||
} | ||
|
||
// SizeOfSensorElement size of each sensor element = sizeof( HWiNFO_SENSORS_SENSOR_ELEMENT ) | ||
func (header *Header) SizeOfSensorElement() int { | ||
return int(header.c.dwSizeOfSensorElement) | ||
} | ||
|
||
// NumSensorElements number of sensor elements | ||
func (header *Header) NumSensorElements() int { | ||
return int(header.c.dwNumSensorElements) | ||
} | ||
|
||
// OffsetOfReadingSection offset of the Reading section from beginning of HWiNFO_SENSORS_SHARED_MEM2 | ||
func (header *Header) OffsetOfReadingSection() int { | ||
return int(header.c.dwOffsetOfReadingSection) | ||
} | ||
|
||
// SizeOfReadingElement size of each Reading element = sizeof( HWiNFO_SENSORS_READING_ELEMENT ) | ||
func (header *Header) SizeOfReadingElement() int { | ||
return int(header.c.dwSizeOfReadingElement) | ||
} | ||
|
||
// NumReadingElements number of Reading elements | ||
func (header *Header) NumReadingElements() int { | ||
return int(header.c.dwNumReadingElements) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.