-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a65c5c1
Showing
6 changed files
with
1,178 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"../src" | ||
"fmt" | ||
"net" | ||
) | ||
|
||
func main() { | ||
airport := &airport.Airport{ | ||
Password: "", // Your password here. | ||
Address: net.IPv4(10, 0, 1, 1), // Base station IP. | ||
} | ||
name, err := airport.GetStationName() | ||
if nil != err { | ||
panic(err) | ||
} | ||
fmt.Printf("Station name: %s\n", name) | ||
} |
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,19 @@ | ||
package main | ||
|
||
import ( | ||
"../src" | ||
"fmt" | ||
"net" | ||
) | ||
|
||
func main() { | ||
airport := &airport.Airport{ | ||
Password: "", // Your password here. | ||
Address: net.IPv4(10, 0, 1, 1), // Base station IP. | ||
} | ||
err := airport.Reboot() | ||
if nil != err { | ||
panic(err) | ||
} | ||
fmt.Println("Station rebooted") | ||
} |
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,100 @@ | ||
package airport | ||
|
||
import ( | ||
"net" | ||
"bytes" | ||
"io" | ||
) | ||
|
||
// Airport TODO | ||
type Airport struct { | ||
Password string | ||
Address net.IP | ||
} | ||
|
||
//Reboot TODO | ||
func (a *Airport) Reboot() error { | ||
info := NewInfo(nil).Get("acRB").GetUpdateBytes() | ||
|
||
return a.write(info) | ||
} | ||
|
||
// GetStationName TODO | ||
func (a *Airport) GetStationName() (string, error) { | ||
requestBytes := NewInfo(nil).GetRequestBytes() | ||
|
||
info, err := a.read(requestBytes) | ||
|
||
if nil != err { | ||
return "", err | ||
} | ||
|
||
return string(info.Get("syNm").GetValue()), nil | ||
} | ||
|
||
func (a *Airport) read(requestPayload []byte) (*Info, error) { | ||
requestMessage := NewMessage(MessageTypeRead, a.Password, requestPayload, len(requestPayload)) | ||
conn, err := a.createConnection() | ||
if nil != err { | ||
return nil, err | ||
} | ||
|
||
defer conn.Close() | ||
|
||
_, err = conn.Write(requestMessage.GetBytes()) | ||
if nil != err { | ||
return nil, err | ||
} | ||
|
||
_, err = conn.Write(requestPayload) | ||
if nil != err { | ||
return nil, err | ||
} | ||
|
||
responseHeader := make([]byte, 128) | ||
|
||
_, err = conn.Read(responseHeader) | ||
if nil != err { | ||
return nil, err | ||
} | ||
|
||
responseBuffer := new(bytes.Buffer) | ||
io.Copy(responseBuffer, conn) | ||
|
||
return NewInfo(responseBuffer.Bytes()), nil | ||
} | ||
|
||
func (a *Airport) write(requestPayload []byte) error { | ||
requestMessage := NewMessage(MessageTypeWrite, a.Password, requestPayload, len(requestPayload)) | ||
conn, err := a.createConnection() | ||
if nil != err { | ||
return err | ||
} | ||
|
||
defer conn.Close() | ||
|
||
_, err = conn.Write(requestMessage.GetBytes()) | ||
if nil != err { | ||
return err | ||
} | ||
|
||
_, err = conn.Write(requestPayload) | ||
if nil != err { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *Airport) createConnection() (*net.TCPConn, error) { | ||
address := &net.TCPAddr{ | ||
IP: a.Address, | ||
Port: 5009, | ||
} | ||
conn, err := net.DialTCP("tcp", nil, address) | ||
if nil != err { | ||
return nil, err | ||
} | ||
|
||
return conn, nil | ||
} |
Oops, something went wrong.