I would like to convert this Python
code in Go
:
#!/usr/bin/python3
import sys
import dbus
if (len(sys.argv) < 2):
print("Usage: %s <modem> <ussd-string>" % (sys.argv[0]))
sys.exit(1)
bus = dbus.SystemBus()
path = sys.argv[1]
ussdstring = sys.argv[2]
ussd = dbus.Interface(bus.get_object('org.ofono', path),
'org.ofono.SupplementaryServices')
properties = ussd.GetProperties()
state = properties["State"]
if state == "idle":
result = ussd.Initiate(ussdstring, timeout=100)[1]
elif state == "user-response":
result = ussd.Respond(ussdstring, timeout=100)
else:
sys.exit(1);
properties = ussd.GetProperties()
state = properties["State"]
print('USSD RESPONSE:
', result)
print('USSD SESSION:
', state)
I made a try with the github.com/guelfey/go.dbus
library:
package main
import (
"fmt"
"os"
"github.com/guelfey/go.dbus"
)
func main() {
fmt.Printf("DBUS Test.
")
conn, err := dbus.SessionBus()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err)
os.Exit(1)
}
busObject := conn.Object("org.ofono", "/ril_0")
fmt.Println("busObject:", busObject)
var list []string
busObject.Call("org.ofono.SupplementaryServices.Initiate", 0, "#101#").Store(&list)
fmt.Println("list:", list)
for _, v := range list {
fmt.Println(v)
}
}
But I got the following response:
DBUS Test.
Failed to connect to session bus: user: Current not implemented on linux/arm
Do you know how to use this DBUS library? Is this library the best one for go
on ARM7?
Thank you
This particular problem is right in the error message:
... user: Current not implemented on linux/arm"
user.Current
is only called for auth, so if you supply your own Auth
method it won't call user.Current
.
It looks like you'll have to create your own conn though, instead of using the global sessionBus
. (see the source of SessionBus
and Conn.Auth
for more details)
conn, err := dbusSessionBusPrivate()
if err != nil {
return
}
auths := []dbus.Auth{dbus.AuthExternal(username), dbus.AuthCookieSha1(username, homedir)}
if err := conn.Auth(auths); err != nil {
conn.Close()
return
}
You could also patch go.dbus
to use an alternative method for finding the username and homedir for arm, like checking $USER
and $HOME
(or file an issue, or open a pull request).