Skip to content

Instantly share code, notes, and snippets.

@aforemny
Created February 25, 2021 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aforemny/0e028aca3841fc8da6d240c40449ad5c to your computer and use it in GitHub Desktop.
Save aforemny/0e028aca3841fc8da6d240c40449ad5c to your computer and use it in GitHub Desktop.
-- phonesim.nix (phonesim module)
```nix
{ config, pkgs, lib, ... }:
with lib;
let
port = "12345";
in
{
config = {
systemd.services.phonesim = {
description = "phonesim";
after = [ "ofono.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkgs.ofono-phonesim}/bin/phonesim -p ${port} ${pkgs.ofono-phonesim}/share/phonesim/default.xml";
};
};
# Could not get this to work. I used the scripts from the ofono source distribution, see blow.
#systemd.services.phonesim-modem = {
# description = "phonesim-modem";
# after = [ "phonesim.service" ];
# wantedBy = [ "multi-user.target" ];
# serviceConfig = {
# ExecStart = "${pkgs.dbus}/bin/dbus-send --print-reply --system --dest=org.ofono /phonesim org.ofono.Modem.SetProperty string:'Powered' variant:boolean:'true'";
# ExecStop = "${pkgs.dbus}/bin/dbus-send --print-reply --system --dest=org.ofono /phonesim org.ofono.Modem.SetProperty string:'Powered' variant:boolean:'false'";
# };
#};
};
}
```
-- ofonod config
```nix
environment.etc."ofono/phonesim.conf".text = ''
[phonesim]
Driver=phonesim
Address=127.0.0.1
Port=12345
'';
```
-- enable-modem /phonesim (ofono/test/
```py
#!/usr/bin/env python3
import dbus
import sys
bus = dbus.SystemBus()
if len(sys.argv) == 2:
path = sys.argv[1]
else:
manager = dbus.Interface(bus.get_object('org.ofono', '/'),
'org.ofono.Manager')
modems = manager.GetModems()
path = modems[0][0]
print("Connecting modem %s..." % path)
modem = dbus.Interface(bus.get_object('org.ofono', path),
'org.ofono.Modem')
modem.SetProperty("Powered", dbus.Boolean(1), timeout = 120)
```
-- disable-modem /phonesim
```py
#!/usr/bin/env python3
import dbus
import sys
bus = dbus.SystemBus()
if len(sys.argv) == 2:
path = sys.argv[1]
else:
manager = dbus.Interface(bus.get_object('org.ofono', '/'),
'org.ofono.Manager')
modems = manager.GetModems()
path = modems[0][0]
print("Disconnecting modem %s..." % path)
modem = dbus.Interface(bus.get_object('org.ofono', path),
'org.ofono.Modem')
modem.SetProperty("Powered", dbus.Boolean(0), timeout = 120
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment