Skip to content

Commit

Permalink
Added dbus call for getting modem status
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronRP committed Oct 5, 2023
1 parent 9eb295f commit c168b44
Show file tree
Hide file tree
Showing 9 changed files with 338 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ nfpms:
dst: /etc/systemd/system/modemd.service
- src: _release/org.cacophony.modemd.conf
dst: /etc/dbus-1/system.d/org.cacophony.modemd.conf
- src: _release/99-modem-udev.rules
dst: /etc/udev/rules.d/99-modem-udev.rules
#- src: _release/uhubctl
# dst: /usr/sbin/uhubctl
scripts:
Expand Down
5 changes: 5 additions & 0 deletions _release/99-modem-udev.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Need to have two separate rules to avoid mixing attributes from multiple parent devices.
# Rule to check that it is the Qualcomm Modem.
ACTION=="add", SUBSYSTEM=="tty", ATTRS{idVendor}=="1e0e", ATTRS{idProduct}=="9011", ENV{MODEM}="1"
# Rule to check that it is the interface that can accept AT commands (bInterfaceNumber==04).
ACTION=="add", SUBSYSTEM=="tty", ENV{MODEM}=="1", ATTRS{bInterfaceNumber}=="04", SYMLINK+="UsbModemAT"
2 changes: 2 additions & 0 deletions _release/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if ! command -v nslookup &> /dev/null; then
exit 1
fi

udevadm control --reload-rules

systemctl daemon-reload
systemctl enable modemd.service
systemctl restart modemd.service
2 changes: 1 addition & 1 deletion cmd/check-gps/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func processGPSOut(parts []string) (*gpsData, error) {
func runATCommand(atCommand string) (string, error) {
log.Printf("Running '%s'", atCommand)

c := &serial.Config{Name: "/dev/ttyUSB3", Baud: 115200}
c := &serial.Config{Name: "/dev/UsbModemAT", Baud: 115200, ReadTimeout: 2 * time.Second}
s, err := serial.OpenPort(c)
if err != nil {
log.Fatal(err)
Expand Down
42 changes: 1 addition & 41 deletions cmd/modemd/modem.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package main

import (
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/cookiejar"
"os/exec"
"strings"
"time"
Expand Down Expand Up @@ -72,13 +68,6 @@ func (m *Modem) IsDefaultRoute() (bool, error) {
return false, nil
}

type responseHolder struct {
response
}
type response struct {
SignalIcon int
}

func (m *Modem) WaitForConnection(timeout int) (bool, error) {
start := time.Now()
for {
Expand All @@ -89,38 +78,9 @@ func (m *Modem) WaitForConnection(timeout int) (bool, error) {
if def {
return true, nil
}
if time.Now().Sub(start) > time.Second*time.Duration(timeout) {
if time.Since(start) > time.Second*time.Duration(timeout) {
return false, nil
}
time.Sleep(time.Second)
}
}

func (m *Modem) signalStrengthHuawei() (int, error) {
cookieJar, err := cookiejar.New(nil)
if err != nil {
return 0, err
}
client := &http.Client{
Jar: cookieJar,
Timeout: time.Second * 10,
}
_, err = client.Get("http://192.168.8.1") // Goto homepage first to get cookie for API request
if err != nil {
return 0, err
}
resp, err := client.Get("http://192.168.8.1" + "/api/monitoring/status")
if err != nil {
return 0, err
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return 0, err
}
var r responseHolder
err = xml.Unmarshal(bodyBytes, &r)
if err != nil {
return 0, err
}
return r.SignalIcon, nil
}
Loading

0 comments on commit c168b44

Please sign in to comment.