Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpioioctl:Implement ioctl access to Linux GPIO chips/lines. #59

Merged
merged 32 commits into from
Sep 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f2576ad
Implement ioctl access to Linux GPIO chips/lines.
gsexton Aug 28, 2024
3606c9b
Restructure tests. Remoe exposted fields from Chip and replace with g…
gsexton Sep 2, 2024
fde9c61
Remove obsoleted tests
gsexton Sep 2, 2024
5a2bd2e
Restore deleted files from sysfs
gsexton Sep 4, 2024
7e310bb
Changes for review comments
gsexton Sep 8, 2024
a4bd079
Pickup missed file
gsexton Sep 8, 2024
ac0bfa3
Fix prerequisite
gsexton Sep 8, 2024
7105f30
Cleanup JSON Marshaling for String()
gsexton Sep 9, 2024
9f4e183
Fix tests
gsexton Sep 9, 2024
6ff2ec3
Fix versions in test
gsexton Sep 9, 2024
1010695
try again
gsexton Sep 9, 2024
ad454c1
Remove String() funcs made for debugging since they're not really nee…
gsexton Sep 9, 2024
91c118d
Add gpioioctl initialization to host since it's required, and netlink…
gsexton Sep 9, 2024
0a36c23
gofmt
gsexton Sep 9, 2024
f80454e
generalize comment
gsexton Sep 9, 2024
ec651b5
Fix lint errors on various close statements.
gsexton Sep 9, 2024
9e052c9
Fix lint errors on various close statements.
gsexton Sep 9, 2024
7d39120
Fix test failure
gsexton Sep 9, 2024
342cb00
Fix commit
gsexton Sep 9, 2024
8cf3652
Fix sysfs test
gsexton Sep 9, 2024
dd8d970
Add conditional compilation
gsexton Sep 12, 2024
d6353a3
gofmt
gsexton Sep 12, 2024
1b97518
Revert go.mod
gsexton Sep 12, 2024
21d9499
Fix lint error on shadowed variable.
gsexton Sep 12, 2024
0f05e40
Lint fixes
gsexton Sep 12, 2024
2eaa0bc
Add timeout to onewire init to ensure pipeline compatibility.
gsexton Sep 12, 2024
47b0b70
add fd to socket. sort of necessary because the case of s to interfac…
gsexton Sep 12, 2024
0ffd4b2
Add conditional compilation to deal with OS differences
gsexton Sep 12, 2024
6990635
add license
gsexton Sep 12, 2024
1edbb95
Fix typo
gsexton Sep 12, 2024
aaec1cc
Revert init changes
gsexton Sep 12, 2024
9204ccc
More revert
gsexton Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
gsexton committed Sep 9, 2024
commit 9f4e18313caf3af8f0f665ed74007b0ea7dec21b
15 changes: 13 additions & 2 deletions gpioioctl/basic_test.go
Original file line number Diff line number Diff line change
@@ -48,7 +48,9 @@ func init() {
}
Chips = append(Chips, &chip)
if err = gpioreg.Register(&line); err != nil {
log.Println("chip", chip.Name(), " gpioreg.Register(line) ", line, " returned ", err)
nameStr := chip.Name()
lineStr := line.String()
log.Println("chip", nameStr, " gpioreg.Register(line) ", lineStr, " returned ", err)
}
}
}
@@ -69,7 +71,7 @@ func TestChips(t *testing.T) {
t.Errorf("Incorrect line count. Found: %d for LineCount, Returned Lines length=%d", chip.LineCount(), len(chip.Lines()))
}
for _, line := range chip.Lines() {
if len(line.Consumer()) == 0 {
if len(line.Consumer()) == 0 && len(line.Name()) > 0 {
testLine = line
break
}
@@ -90,6 +92,9 @@ func TestChips(t *testing.T) {
}

func TestGPIORegistryByName(t *testing.T) {
if testLine == nil {
return
}
outLine := gpioreg.ByName(testLine.Name())
if outLine == nil {
t.Fatalf("Error retrieving GPIO Line %s", testLine.Name())
@@ -105,6 +110,9 @@ func TestGPIORegistryByName(t *testing.T) {

func TestNumber(t *testing.T) {
chip := Chips[0]
if testLine == nil {
return
}
l := chip.ByName(testLine.Name())
if l == nil {
t.Fatalf("Error retrieving GPIO Line %s", testLine.Name())
@@ -120,6 +128,9 @@ func TestNumber(t *testing.T) {
}

func TestString(t *testing.T) {
if testLine == nil {
return
}
line := gpioreg.ByName(testLine.Name())
if line == nil {
t.Fatalf("Error retrieving GPIO Line %s", testLine.Name())
2 changes: 1 addition & 1 deletion gpioioctl/gpio.go
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@
// to the pin numbering scheme that may be in use on a board.
number uint32
// The name supplied by the OS Driver
name string `json:"Name"`
name string
// If the line is in use, this may be populated with the
// consuming application's information.
consumer string
@@ -96,7 +96,7 @@
if line.fEdge != nil {
line.fEdge.Close()
} else if line.fd != 0 {
syscall.Close(int(line.fd))

Check failure on line 99 in gpioioctl/gpio.go

GitHub Actions / lint: windows-latest

cannot use int(line.fd) (value of type int) as syscall.Handle value in argument to syscall.Close
}
line.fd = 0
line.consumer = ""
@@ -242,7 +242,7 @@
}
var err error
if line.fEdge == nil {
err = syscall.SetNonblock(int(line.fd), true)

Check failure on line 245 in gpioioctl/gpio.go

GitHub Actions / lint: windows-latest

cannot use int(line.fd) (value of type int) as syscall.Handle value in argument to syscall.SetNonblock
if err != nil {
log.Println("WaitForEdge() SetNonblock(): ", err)
return false
@@ -361,7 +361,7 @@
chip := GPIOChip{path: path}
f, err := os.OpenFile(path, os.O_RDONLY, 0444)
if err != nil {
err = fmt.Errorf("Opening GPIO Chip %s failed. Error: %w", path, err)

Check failure on line 364 in gpioioctl/gpio.go

GitHub Actions / lint: ubuntu-latest

error strings should not be capitalized (ST1005)

Check failure on line 364 in gpioioctl/gpio.go

GitHub Actions / lint: macos-latest

error strings should not be capitalized (ST1005)
log.Println(err)
return nil, err
}
@@ -405,7 +405,7 @@
for _, lineset := range chip.lineSets {
lineset.Close()
}
syscall.Close(int(chip.fd))

Check failure on line 408 in gpioioctl/gpio.go

GitHub Actions / lint: windows-latest

cannot use int(chip.fd) (value of type int) as syscall.Handle value in argument to syscall.Close
}

// ByName returns a GPIOLine for a specific name. If not
@@ -460,7 +460,7 @@
for ix, name := range config.Lines {
gpioLine := chip.ByName(name)
if gpioLine == nil {
return nil, fmt.Errorf("Line %s not found in chip %s", name, chip.Name())

Check failure on line 463 in gpioioctl/gpio.go

GitHub Actions / lint: ubuntu-latest

error strings should not be capitalized (ST1005)

Check failure on line 463 in gpioioctl/gpio.go

GitHub Actions / lint: macos-latest

error strings should not be capitalized (ST1005)
}
lines[ix] = uint32(gpioLine.Number())
}
Loading