summaryrefslogtreecommitdiff
path: root/software/communication/physical.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-30 16:47:29 +0200
committerxengineering <me@xengineering.eu>2024-05-30 16:48:39 +0200
commit96d159114af675d55fe0d7c0f22a69d65e9563fc (patch)
tree1d7b7e6a84b5d06765084ea6414874a21d3cbaa5 /software/communication/physical.go
parent0cfd378394b6c5d90e00c217b12113e0c3284031 (diff)
downloadiot-core-96d159114af675d55fe0d7c0f22a69d65e9563fc.tar
iot-core-96d159114af675d55fe0d7c0f22a69d65e9563fc.tar.zst
iot-core-96d159114af675d55fe0d7c0f22a69d65e9563fc.zip
software: communication: Add SerialInterface
This new type bundles the whole communication stack. This is easier to use than handling types for each layer on the user side of the communication package.
Diffstat (limited to 'software/communication/physical.go')
-rw-r--r--software/communication/physical.go28
1 files changed, 5 insertions, 23 deletions
diff --git a/software/communication/physical.go b/software/communication/physical.go
index f79d382..853e4c4 100644
--- a/software/communication/physical.go
+++ b/software/communication/physical.go
@@ -1,8 +1,6 @@
package communication
import (
- "fmt"
-
"go.bug.st/serial"
"go.bug.st/serial/enumerator"
)
@@ -11,11 +9,7 @@ const (
ST_VID = `0483`
)
-type Phy struct {
- port serial.Port
-}
-
-func GetStSerials() ([]string, error) {
+func getStSerials() ([]string, error) {
retval := make([]string, 0)
ports, err := enumerator.GetDetailedPortsList()
@@ -34,26 +28,14 @@ func GetStSerials() ([]string, error) {
return retval, nil
}
-func NewPhy(device string) (Phy, error) {
- p := Phy{}
+func openSerial(device string) (serial.Port, error) {
+ var port serial.Port
mode := &serial.Mode{
BaudRate: 115200,
}
port, err := serial.Open(device, mode)
if err != nil {
- return p, err
- }
- p.port = port
- return p, nil
-}
-
-func (phy *Phy) Cat() error {
- buff := make([]byte, 100)
- for {
- n, err := phy.port.Read(buff)
- if err != nil {
- return err
- }
- fmt.Printf("%s", string(buff[:n]))
+ return port, err
}
+ return port, nil
}