Skip to content

Commit

Permalink
Merge pull request reef-pi#2290 from reef-pi/pi5
Browse files Browse the repository at this point in the history
(chore)update gopsutil and pi detection logic to support pi5
  • Loading branch information
ranjib authored Jan 28, 2025
2 parents a172c40 + 55b22f4 commit d13aba5
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 63 deletions.
4 changes: 3 additions & 1 deletion controller/device_manager/device_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/gorilla/mux"
"github.com/reef-pi/rpi/i2c"

"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v4/host"

"github.com/reef-pi/reef-pi/controller/device_manager/connectors"
"github.com/reef-pi/reef-pi/controller/device_manager/drivers"
Expand Down Expand Up @@ -51,6 +51,8 @@ func New(s settings.Settings, store storage.Store, t telemetry.Telemetry) *Devic
log.Println("ERROR: failed to initialize drivers. Error:", err)
t.LogError("device-manager", "failed to initialize drivers:"+err.Error())
}
log.Println("device-manager subsystem initialized with", drvrs.Size(), "drivers")

return &DeviceManager{
bus: bus,
drivers: drvrs,
Expand Down
40 changes: 40 additions & 0 deletions controller/device_manager/drivers/driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package drivers

import (
"encoding/json"

"github.com/reef-pi/hal"

"github.com/reef-pi/reef-pi/controller/storage"
)

const (
DriverBucket = storage.DriverBucket
_rpi = "rpi"
)

// swagger:model driver
type Driver struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Config json.RawMessage `json:"config"`
PinMap map[string][]int `json:"pinmap"`
Parameters map[string]interface{} `json:"parameters"`
}

func (dr *Driver) loadPinMap(d hal.Driver) {
pinmap := make(map[string][]int)
for _, cap := range d.Metadata().Capabilities {
pins, err := d.Pins(cap)
if err != nil {
continue
}
var ps []int
for _, pin := range pins {
ps = append(ps, pin.Number())
}
pinmap[cap.String()] = ps
}
dr.PinMap = pinmap
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,13 @@ import (
"sync"

"github.com/reef-pi/hal"
"github.com/reef-pi/rpi/i2c"

"github.com/shirou/gopsutil/v3/host"

"github.com/reef-pi/reef-pi/controller/settings"
"github.com/reef-pi/reef-pi/controller/storage"
"github.com/reef-pi/reef-pi/controller/telemetry"
"github.com/reef-pi/rpi/i2c"
"github.com/shirou/gopsutil/v4/host"
)

const (
DriverBucket = storage.DriverBucket
_rpi = "rpi"
)

// swagger:model driver
type Driver struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Config json.RawMessage `json:"config"`
PinMap map[string][]int `json:"pinmap"`
Parameters map[string]interface{} `json:"parameters"`
}

type Drivers struct {
sync.Mutex
drivers map[string]hal.Driver
Expand All @@ -54,14 +37,24 @@ func NewDrivers(s settings.Settings, bus i2c.Bus, store storage.Store, t telemet
t: t,
}
stats, sErr := host.Info()
if sErr == nil && strings.HasPrefix(stats.KernelArch, "arm") {
log.Println("Debug: host arch:", stats.KernelArch)
if sErr == nil && isPiArch(stats.KernelArch) {
d.isRaspberryPi = true
}
if s.Capabilities.DevMode {
d.isRaspberryPi = true
}
return d, d.loadAll()
}
func isPiArch(a string) bool {
if strings.HasPrefix(a, "arm") {
return true
}
if strings.HasPrefix(a, "aarch64") {
return true
}
return false
}

func (d *Drivers) Get(id string) (Driver, error) {
var dr Driver
Expand All @@ -76,22 +69,6 @@ func (d *Drivers) Get(id string) (Driver, error) {
return dr, nil
}

func (dr *Driver) loadPinMap(d hal.Driver) {
pinmap := make(map[string][]int)
for _, cap := range d.Metadata().Capabilities {
pins, err := d.Pins(cap)
if err != nil {
continue
}
var ps []int
for _, pin := range pins {
ps = append(ps, pin.Number())
}
pinmap[cap.String()] = ps
}
dr.PinMap = pinmap
}

func (d *Drivers) DigitalInputDriver(id string) (hal.DigitalInputDriver, error) {
driver, ok := d.drivers[id]
if !ok {
Expand Down Expand Up @@ -202,6 +179,9 @@ func (d *Drivers) Delete(id string) error {
return d.store.Delete(DriverBucket, id)
}

func (d *Drivers) Size() int {
return len(d.drivers)
}
func (d *Drivers) List() ([]Driver, error) {
ds := []Driver{}
fn := func(_ string, v []byte) error {
Expand Down Expand Up @@ -246,7 +226,7 @@ func (d *Drivers) ValidateParameters(d1 Driver) (map[string][]string, error) {
func (d *Drivers) Close() error {
for _, d1 := range d.drivers {
if err := d1.Close(); err != nil {
log.Println(err)
log.Println("device-manager: Failed to close driver. Error:", err)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion controller/modules/system/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v4/host"

"github.com/reef-pi/reef-pi/controller"
)
Expand Down
2 changes: 1 addition & 1 deletion controller/modules/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v4/host"

"github.com/reef-pi/reef-pi/controller/utils"
)
Expand Down
4 changes: 2 additions & 2 deletions controller/telemetry/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"time"

"github.com/shirou/gopsutil/load"
"github.com/shirou/gopsutil/mem"
"github.com/shirou/gopsutil/v4/mem"

"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v4/host"

"github.com/reef-pi/reef-pi/controller/settings"
"github.com/reef-pi/reef-pi/controller/storage"
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0
github.com/dustin/go-humanize v1.0.1
github.com/eclipse/paho.mqtt.golang v1.5.0
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/godbus/dbus/v5 v5.1.0
github.com/gorilla/mux v1.8.1
github.com/gorilla/sessions v1.4.0
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/prometheus/client_golang v1.20.5
github.com/reef-pi/adafruitio v0.0.0-20171007064130-a3cae37cdd64
github.com/reef-pi/drivers v0.0.0-20250128072720-92eb51c1f19f
github.com/reef-pi/hal v0.0.0-20241230081938-0bb4bbd0e03a
github.com/reef-pi/rpi v0.0.0-20250128071619-614c4ae80b22
github.com/robfig/cron/v3 v3.0.1
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/shirou/gopsutil/v3 v3.24.5
github.com/shirou/gopsutil/v4 v4.24.11
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.9.0 // indirect
go.etcd.io/bbolt v1.3.9
golang.org/x/crypto v0.31.0
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -27,21 +31,17 @@ require (
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/ebitengine/purego v0.8.1 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/warthog618/go-gpiocdev v0.9.1 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/net v0.33.0 // indirect
Expand Down
28 changes: 13 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/ebitengine/purego v0.8.1 h1:sdRKd6plj7KYW33EH5As6YKfe8m9zbN9JMrOjNVF/BE=
github.com/ebitengine/purego v0.8.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
github.com/eclipse/paho.mqtt.golang v1.5.0 h1:EH+bUVJNgttidWFkLLVKaQPGmkTUfQQqjOsyvMGvD6o=
github.com/eclipse/paho.mqtt.golang v1.5.0/go.mod h1:du/2qNQVqJf/Sqs4MEL77kR8QTqANF7XU7Fk0aOTAgk=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down Expand Up @@ -52,8 +55,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU=
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
Expand All @@ -76,18 +79,14 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI=
github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk=
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/shirou/gopsutil/v4 v4.24.11 h1:WaU9xqGFKvFfsUv94SXcUPD7rCkU0vr/asVdQOBZNj8=
github.com/shirou/gopsutil/v4 v4.24.11/go.mod h1:s4D/wg+ag4rG0WO7AiTj2BeYCRhym0vM7DHbZRxnIT8=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU=
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
github.com/tklauser/numcpus v0.9.0 h1:lmyCHtANi8aRUgkckBgoDk1nHCux3n2cgkJLXdQGPDo=
github.com/tklauser/numcpus v0.9.0/go.mod h1:SN6Nq1O3VychhC1npsWostA+oW+VOQTxZrS604NSRyI=
github.com/warthog618/go-gpiocdev v0.9.1 h1:pwHPaqjJfhCipIQl78V+O3l9OKHivdRDdmgXYbmhuCI=
github.com/warthog618/go-gpiocdev v0.9.1/go.mod h1:dN3e3t/S2aSNC+hgigGE/dBW8jE1ONk9bDSEYfoPyl8=
github.com/warthog618/go-gpiosim v0.1.1 h1:MRAEv+T+itmw+3GeIGpQJBfanUVyg0l3JCTwHtwdre4=
Expand All @@ -104,8 +103,7 @@ golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down

0 comments on commit d13aba5

Please sign in to comment.