Skip to content

Commit

Permalink
SHELF fix #70 support POE reset for GS316xx
Browse files Browse the repository at this point in the history
  • Loading branch information
nitram509 committed Sep 26, 2024
1 parent b540881 commit b636c75
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: "setup go"
uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.23'
- name: Get the version
id: get_version
run: echo "VERSION=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: "setup go"
uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.23'
- name: "go mod download"
run: "go mod download"
- name: "go test ./..."
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: "setup go"
uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.23'
- name: "build binary and print --help"
run: |
go build -o ntgrrc .
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

# ntgrrc (Netgear Remote Control) CHANGELOG

## v0.11.0 (WiP)

* switch to Go v1.23

----

## v0.10.1

* added outputs to standard output by @oalfreda in #64
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ntgrrc

go 1.20
go 1.23

require (
github.com/PuerkitoBio/goquery v1.9.2
Expand Down
40 changes: 37 additions & 3 deletions poe_cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/url"
"strings"
)

type PoeCyclePowerCommand struct {
Expand All @@ -12,11 +13,17 @@ type PoeCyclePowerCommand struct {
}

func (poe *PoeCyclePowerCommand) Run(args *GlobalOptions) error {
err := ensureModelIs30x(args, poe.Address)
if err != nil {
return err
model := args.model
if isModel30x(model) {
return poe.cyclePowerGs30xEPx(args)
}
if isModel316(model) {
return poe.cyclePowerGs316EPx(args)
}
panic("model not supported")
}

func (poe *PoeCyclePowerCommand) cyclePowerGs30xEPx(args *GlobalOptions) error {
poeExt := &PoeExt{}

settings, err := requestPoeConfiguration(args, poe.Address, poeExt)
Expand Down Expand Up @@ -53,3 +60,30 @@ func (poe *PoeCyclePowerCommand) Run(args *GlobalOptions) error {
prettyPrintSettings(args.OutputFormat, changedPorts)
return nil
}

func (poe *PoeCyclePowerCommand) cyclePowerGs316EPx(args *GlobalOptions) error {
createPortResetPayloadGs316EPx(poe.Ports)

url := fmt.Sprintf("http://%s/iss/specific/poePortConf.html", poe.Address)
err := postPage(args, poe.Address, url, data)

Check failure on line 68 in poe_cycle.go

View workflow job for this annotation

GitHub Actions / go test (ubuntu-latest)

assignment mismatch: 1 variable but postPage returns 2 values

Check failure on line 68 in poe_cycle.go

View workflow job for this annotation

GitHub Actions / go test (ubuntu-latest)

undefined: data
return err
}

func createPortResetPayloadGs316EPx(poePorts []int) string {
result := strings.Builder{}
const maxPorts = 16
for i := 0; i < maxPorts; i++ {
written := false
for _, p := range poePorts {
if p-1 == i {
result.WriteString("1")
written = true
break
}
}
if !written {
result.WriteString("0")
}
}
return result.String()
}
12 changes: 12 additions & 0 deletions poe_cycle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"testing"
)

func TestPoePortReset(t *testing.T) {
s := createPortResetPayloadGs316EPx([]int{3, 5})
then.AssertThat(t, s, is.EqualTo("0010100000000000"))
}

0 comments on commit b636c75

Please sign in to comment.