ZeroPhone / ZPUI

Official ZeroPhone UI framework, based on pyLCI
http://zpui.rtfd.org/
Apache License 2.0
79 stars 19 forks source link

[WIP] Ofono bridge #83

Open monsieurh opened 6 years ago

monsieurh commented 6 years ago

ofono bridge progress

purpose

Use ofono as a backend for all phone/texting features

implementation

A new package ofono contains all the libraries, the class OfonoBridge is the interface between ZPUI and Ofono. OfonoBridge uses D-Bus to communicate with ofono and thus needs a new dependency : pydbus library (added to requirements.txt).

issues

todo

zpui

ofono

system

CRImier commented 6 years ago

Why do we need it as a separate package (in the ZPUI folder root), instead of having it as a library in one of the apps?

monsieurh commented 6 years ago

We don't need it as a separate package, but in my mind 'apps' are programs the user interact with. Ofono bridge is indeed a library on which will depends 'phone app', 'sms app' and maybe others. So i didn't know where to place it in the hierarchy. Open to suggestion !

CRImier commented 6 years ago

I'm working on this now. First thing first, modem communications (and easy-to-use timestamps) can be seen by using this ofonod CLI:

OFONO_AT_DEBUG=1 ofonod -n -d 'plugins/sim900.c,src/*,drivers/atmodem/*' 2>&1 | ts -s

You can get the ts utility from the moreutils package. So:

python -c 'import zerophone_hw; zerophone_hw.GSM_Modem().reset()'
CRImier commented 6 years ago

Ofono is already run at startup (debian ships a .service file), shall we have our own fork, we'll use that

CRImier commented 6 years ago

Also, the ofono library was moved into libs/. Now, bridge.py can be launched from ZPUI root as:

python -i -m libs.ofono.bridge

After code fails/is interrupted, a Python console opens (python -i) and an OfonoBridge instance is available as ofono.

CRImier commented 6 years ago

So, debugging the "can't power off" problem. Here's how it manifests:

00:00:43 ofonod[4140]: Voice: < \r\nOK\r\n
# Powering off - I set it up so that Ctrl+C-ing the script calls power_off()
00:00:56 ofonod[4140]: src/modem.c:modem_change_state() old state: 3, new state: 0
00:00:56 ofonod[4140]: src/modem.c:flush_atoms()
00:00:56 ofonod[4140]: src/call-volume.c:call_volume_remove() atom: 0xcc6e48
00:00:56 ofonod[4140]: src/voicecall.c:voicecall_remove() atom: 0xcc1a18
00:00:56 ofonod[4140]: src/ussd.c:ussd_remove() atom: 0xcc18d8
00:00:56 ofonod[4140]: src/sim.c:ofono_sim_remove_spn_watch() 0xc8bd40
00:00:56 ofonod[4140]: src/network.c:netreg_remove() atom: 0xcc17c0
00:00:56 ofonod[4140]: src/gprs.c:gprs_context_remove() atom: 0xca06d8
00:00:56 ofonod[4140]: src/gprs.c:gprs_unregister() 0xca0510
00:00:56 ofonod[4140]: src/gprs.c:gprs_remove() atom: 0xca0578
00:00:56 ofonod[4140]: src/sms.c:sms_remove() atom: 0xca0438
00:00:56 ofonod[4140]: src/phonebook.c:phonebook_remove() atom: 0xc869c8
00:00:56 ofonod[4140]: src/sim.c:sim_remove() atom: 0xc8be68
00:00:56 ofonod[4140]: src/modem.c:devinfo_remove() atom: 0xcc1c28
00:00:56 ofonod[4140]: plugins/sim900.c:sim900_disable() 0xc8b378
00:00:56 ofonod[4140]: Setup: > AT+CFUN=4\r
00:01:16 ofonod[4140]: src/modem.c:set_powered_timeout() modem: 0xc8b378
# At this point, bridge code crashes with:
# GLib.Error: g-io-error-quark: GDBus.Error:org.ofono.Error.Timedout: Operation failure due to timeout (36)
# However, 40 seconds after a timeout, ofono gets something from the modem:
00:01:58 ofonod[4140]: Voice: < \r\n+CREG: 1,"01A5","1483"\r\n
00:01:58 ofonod[4140]: Voice: < \r\n+CGREG: 1,"01A5","1483"\r\n
00:01:58 ofonod[4140]: Net: < \r\n+CREG: 1,"01A5","1483"\r\n\r\n+CGREG: 1,"01A5","1483"\r\n
00:01:58 ofonod[4140]: SMS: < \r\n+CREG: 1,"01A5","1483"\r\n
00:01:58 ofonod[4140]: GPRS: < \r\n+CREG: 1,"01A5","1483"\r\n
00:01:58 ofonod[4140]: SMS: < \r\n+CGREG: 1,"01A5","1483"\r\n
00:01:58 ofonod[4140]: GPRS: < \r\n+CGREG: 1,"01A5","1483"\r\n
# Then it gets that one more time:
00:02:16 ofonod[4140]: Voice: < \r\n+CREG: 1,"01A5","1482"\r\n
00:02:16 ofonod[4140]: Voice: < \r\n+CGREG: 1,"01A5","1482"\r\n
00:02:16 ofonod[4140]: Net: < \r\n+CREG: 1,"01A5","1482"\r\n
00:02:16 ofonod[4140]: SMS: < \r\n+CREG: 1,"01A5","1482"\r\n
00:02:16 ofonod[4140]: GPRS: < \r\n+CREG: 1,"01A5","1482"\r\n
00:02:16 ofonod[4140]: Net: < \r\n+CGREG: 1,"01A5","1482"\r\n
00:02:16 ofonod[4140]: SMS: < \r\n+CGREG: 1,"01A5","1482"\r\n
00:02:16 ofonod[4140]: GPRS: < \r\n+CGREG: 1,"01A5","1482"\r\n

After Ctrl+C-ing ofono, I run screen /dev/ttyAMA0 115200. The modem does not respond to AT commands - either to AT or AT+CFUN=1, there's no echo either (though ofono turns that off, ATE1 has no effect either). I then reset the modem (I wrote a small ZPUI app, might be useful to publish that), and it starts responding to AT commands - but doesn't print any of the "Call ready, SMS ready" stuff it usually does.

Fun fact: ofono holds the serial port open after power_off() - confirmed by lsof. It'll be useful for us to disable that.

CRImier commented 6 years ago

I've copied the sim900 driver to a sim800 driver and made some changes, now I can add SIM800-specific stuff. First things first, I've changed CFUN=4 command to CFUN=1 (the state the modem already is in by default). However, switching still timeouts. Furthermore, serial communication is still broken after stopping ofono! Will research further.

codecov[bot] commented 5 years ago

Codecov Report

Merging #83 into devel will increase coverage by 0.14%. The diff coverage is 55.6%.

Impacted file tree graph

@@            Coverage Diff             @@
##            devel      #83      +/-   ##
==========================================
+ Coverage   41.26%   41.41%   +0.14%     
==========================================
  Files         260      266       +6     
  Lines       21830    22224     +394     
==========================================
+ Hits         9008     9203     +195     
- Misses      12822    13021     +199
Impacted Files Coverage Δ
ui/tests/test_canvas.py 84.61% <ø> (-0.93%) :arrow_down:
libs/ofono/bridge.py 0% <0%> (ø)
apps/phone/graphics.py 100% <100%> (ø)
ui/dialog.py 94.33% <100%> (+0.76%) :arrow_up:
ui/__init__.py 100% <100%> (ø) :arrow_up:
ui/overlays.py 79.81% <100%> (-3.6%) :arrow_down:
ui/numpad_input.py 77.44% <100%> (+0.49%) :arrow_up:
ui/tests/test_numpad_input.py 86.99% <100%> (+2.08%) :arrow_up:
ui/base_list_ui.py 84.61% <100%> (+2.14%) :arrow_up:
apps/phone/views.py 26.78% <26.78%> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b7cf8c4...5af4c3c. Read the comment docs.

CRImier commented 5 years ago

ouch, accident