Skip to content

Commit

Permalink
格式化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
yumaojun03 committed May 11, 2020
1 parent 1dce596 commit 766ff82
Show file tree
Hide file tree
Showing 45 changed files with 3,584 additions and 3,582 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# dmidecode
[![Go Report Card](https://goreportcard.com/badge/github.com/yumaojun03/dmidecode)](https://goreportcard.com/report/github.com/yumaojun03/dmidecode)
[![Release](https://img.shields.io/github/release/yumaojun03/dmidecode.svg?style=flat-square)](https://github.com/yumaojun03/dmidecode/releases)

纯Golang实现的dmidecode, 零依赖, 支持Linux, Unix, Windows

Expand Down
60 changes: 30 additions & 30 deletions parser/baseboard/parse.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package baseboard

import (
"github.com/yumaojun03/dmidecode/smbios"
)

// Parse 解析
func Parse(s *smbios.Structure) (*Information, error) {
data := s.Formatted

info := &Information{
Header: s.Header,
Manufacturer: s.GetString(0x0),
ProductName: s.GetString(0x1),
Version: s.GetString(0x2),
SerialNumber: s.GetString(0x3),
AssetTag: s.GetString(0x4),
LocationInChassis: s.GetString(0x6),
}

if len(s.Formatted) >= 0x05 {
info.FeatureFlags = FeatureFlags(data[0x05])
}

if len(s.Formatted) >= 0x09 {
info.BoardType = Type(data[0x09])
}

return info, nil
}
package baseboard

import (
"github.com/yumaojun03/dmidecode/smbios"
)

// Parse 解析
func Parse(s *smbios.Structure) (*Information, error) {
data := s.Formatted

info := &Information{
Header: s.Header,
Manufacturer: s.GetString(0x0),
ProductName: s.GetString(0x1),
Version: s.GetString(0x2),
SerialNumber: s.GetString(0x3),
AssetTag: s.GetString(0x4),
LocationInChassis: s.GetString(0x6),
}

if len(s.Formatted) >= 0x05 {
info.FeatureFlags = FeatureFlags(data[0x05])
}

if len(s.Formatted) >= 0x09 {
info.BoardType = Type(data[0x09])
}

return info, nil
}
58 changes: 29 additions & 29 deletions parser/baseboard/parse_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package baseboard_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/yumaojun03/dmidecode/parser/baseboard"
"github.com/yumaojun03/dmidecode/smbios"
)

var (
s = &smbios.Structure{
Header: smbios.Header{
Type: 2,
Length: 8,
Handle: 512,
},
Formatted: []byte{0x1, 0x2, 0x3, 0x4},
Strings: []string{"Dell Inc.", "0CNCJW", "A05", ".HVSRF52.CN7475154A0700."},
}
)

func TestParse(t *testing.T) {
bios, err := baseboard.Parse(s)
if assert.NoError(t, err) {
t.Log(bios)
}
}
package baseboard_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/yumaojun03/dmidecode/parser/baseboard"
"github.com/yumaojun03/dmidecode/smbios"
)

var (
s = &smbios.Structure{
Header: smbios.Header{
Type: 2,
Length: 8,
Handle: 512,
},
Formatted: []byte{0x1, 0x2, 0x3, 0x4},
Strings: []string{"Dell Inc.", "0CNCJW", "A05", ".HVSRF52.CN7475154A0700."},
}
)

func TestParse(t *testing.T) {
bios, err := baseboard.Parse(s)
if assert.NoError(t, err) {
t.Log(bios)
}
}
150 changes: 75 additions & 75 deletions parser/baseboard/types.go
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
package baseboard

import "fmt"

// FeatureFlags 主板功能标签
type FeatureFlags byte

// Baseboard feature flags
const (
HostingBoard FeatureFlags = 1 << iota
AtLeastOneDaughter
Removable
Repleaceable
HotSwappable
//FeatureFlagsReserved = 000b
)

func (f FeatureFlags) String() string {
fmt.Printf("xxx,%d", f)
features := [...]string{
"Board is a hosting board", /* 0 */
"Board requires at least one daughter board",
"Board is removable",
"Board is replaceable",
"Board is hot swappable", /* 4 */
}
var s string
for i := uint32(0); i < 5; i++ {
if f&(1<<i) != 0 {
s += "\n\t\t" + features[i]
}
}
return s
}

// Type 主板类型
type Type byte

const (
Unknown Type = 1 + iota
Other
ServerBlade
ConnectivitySwitch
ManagementModule
ProcessorModule
IOModule
MemModule
DaughterBoard
Motherboard
ProcessorMemmoryModule
ProcessorIOModule
InterconnectBoard
)

func (b Type) String() string {
types := [...]string{
"Unknown", /* 0x01 */
"Other",
"Server Blade",
"Connectivity Switch",
"System Management Module",
"Processor Module",
"I/O Module",
"Memory Module",
"Daughter Board",
"Motherboard",
"Processor+Memory Module",
"Processor+I/O Module",
"Interconnect Board", /* 0x0D */
}
if b > Unknown && b < InterconnectBoard {
return types[b-1]
}
return "Out Of Spec"
}
package baseboard

import "fmt"

// FeatureFlags 主板功能标签
type FeatureFlags byte

// Baseboard feature flags
const (
HostingBoard FeatureFlags = 1 << iota
AtLeastOneDaughter
Removable
Repleaceable
HotSwappable
//FeatureFlagsReserved = 000b
)

func (f FeatureFlags) String() string {
fmt.Printf("xxx,%d", f)
features := [...]string{
"Board is a hosting board", /* 0 */
"Board requires at least one daughter board",
"Board is removable",
"Board is replaceable",
"Board is hot swappable", /* 4 */
}
var s string
for i := uint32(0); i < 5; i++ {
if f&(1<<i) != 0 {
s += "\n\t\t" + features[i]
}
}
return s
}

// Type 主板类型
type Type byte

const (
Unknown Type = 1 + iota
Other
ServerBlade
ConnectivitySwitch
ManagementModule
ProcessorModule
IOModule
MemModule
DaughterBoard
Motherboard
ProcessorMemmoryModule
ProcessorIOModule
InterconnectBoard
)

func (b Type) String() string {
types := [...]string{
"Unknown", /* 0x01 */
"Other",
"Server Blade",
"Connectivity Switch",
"System Management Module",
"Processor Module",
"I/O Module",
"Memory Module",
"Daughter Board",
"Motherboard",
"Processor+Memory Module",
"Processor+I/O Module",
"Interconnect Board", /* 0x0D */
}
if b > Unknown && b < InterconnectBoard {
return types[b-1]
}
return "Out Of Spec"
}
110 changes: 55 additions & 55 deletions parser/bios/bios.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package bios

import (
"fmt"

"github.com/yumaojun03/dmidecode/smbios"
)

// Information bios信息
type Information struct {
smbios.Header
Vendor string `json:"vendor,omitempty"`
BIOSVersion string `json:"bios_version,omitempty"`
StartingAddressSegment uint16 `json:"starting_address_segment,omitempty"`
ReleaseDate string `json:"release_date,omitempty"`
RomSize RomSize `json:"rom_size,omitempty"`
RuntimeSize RuntimeSize `json:"runtime_size,omitempty"`
Characteristics Characteristics `json:"characteristics,omitempty"`
CharacteristicsExt1 Ext1 `json:"characteristics_ext_1,omitempty"`
CharacteristicsExt2 Ext2 `json:"characteristics_ext_2,omitempty"`
SystemBIOSMajorRelease byte `json:"system_bios_major_release,omitempty"`
SystemBIOSMinorRelease byte `json:"system_bios_minor_release,omitempty"`
EmbeddedControllerFirmwareMajorRelease byte `json:"firmware_major_release,omitempty"`
EmbeddedControllerFirmawreMinorRelease byte `json:"firmawre_minor_release,omitempty"`
}

func (b Information) String() string {
s := fmt.Sprintf("Handle %x, DMI type %d, %d bytes\n"+
"\tBIOS Information\n"+
"\tVendor: %s\n"+
"\tVersion: %s\n"+
"\tRelease Date: %s\n"+
"\tAddress: 0x%4X0\n"+
"\tRuntime Size: %s\n"+
"\tROM Size: %s\n"+
"\tCharacteristics:%s",
b.Header.Handle,
b.Header.Type,
b.Header.Length,
b.Vendor,
b.BIOSVersion,
b.ReleaseDate,
b.StartingAddressSegment,
b.RuntimeSize,
b.RomSize,
b.Characteristics)

if b.CharacteristicsExt1 != 0 {
s += b.CharacteristicsExt1.String()
}
if b.CharacteristicsExt2 != 0 {
s += b.CharacteristicsExt2.String()
}
return s
}
package bios

import (
"fmt"

"github.com/yumaojun03/dmidecode/smbios"
)

// Information bios信息
type Information struct {
smbios.Header
Vendor string `json:"vendor,omitempty"`
BIOSVersion string `json:"bios_version,omitempty"`
StartingAddressSegment uint16 `json:"starting_address_segment,omitempty"`
ReleaseDate string `json:"release_date,omitempty"`
RomSize RomSize `json:"rom_size,omitempty"`
RuntimeSize RuntimeSize `json:"runtime_size,omitempty"`
Characteristics Characteristics `json:"characteristics,omitempty"`
CharacteristicsExt1 Ext1 `json:"characteristics_ext_1,omitempty"`
CharacteristicsExt2 Ext2 `json:"characteristics_ext_2,omitempty"`
SystemBIOSMajorRelease byte `json:"system_bios_major_release,omitempty"`
SystemBIOSMinorRelease byte `json:"system_bios_minor_release,omitempty"`
EmbeddedControllerFirmwareMajorRelease byte `json:"firmware_major_release,omitempty"`
EmbeddedControllerFirmawreMinorRelease byte `json:"firmawre_minor_release,omitempty"`
}

func (b Information) String() string {
s := fmt.Sprintf("Handle %x, DMI type %d, %d bytes\n"+
"\tBIOS Information\n"+
"\tVendor: %s\n"+
"\tVersion: %s\n"+
"\tRelease Date: %s\n"+
"\tAddress: 0x%4X0\n"+
"\tRuntime Size: %s\n"+
"\tROM Size: %s\n"+
"\tCharacteristics:%s",
b.Header.Handle,
b.Header.Type,
b.Header.Length,
b.Vendor,
b.BIOSVersion,
b.ReleaseDate,
b.StartingAddressSegment,
b.RuntimeSize,
b.RomSize,
b.Characteristics)

if b.CharacteristicsExt1 != 0 {
s += b.CharacteristicsExt1.String()
}
if b.CharacteristicsExt2 != 0 {
s += b.CharacteristicsExt2.String()
}
return s
}
Loading

0 comments on commit 766ff82

Please sign in to comment.