Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Ofono bridge #83

Open
wants to merge 45 commits into
base: devel
Choose a base branch
from
Open

[WIP] Ofono bridge #83

wants to merge 45 commits into from

Conversation

monsieurh
Copy link
Collaborator

@monsieurh monsieurh commented Jan 13, 2018

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

  • powering the modem down prevents from powering it back up afterwards

todo

zpui

  • will probably need its own thread to run the D-BUS loop
  • GUI for phone calls
  • GUI for texting
  • GUI for contact management

ofono

system

  • compile and distribute ofono binaries
  • distribute the default config file 00-ofono.rules for SIM800L (to be placed in /etc/udev/rules.d/)
  • make and distribute a systemd unit file to run ofono on startup

@monsieurh monsieurh changed the title Ofono bridge [WIP] Ofono bridge Jan 13, 2018
ofono/bridge.py Outdated

from helpers import Singleton, setup_logger

DBusGMainLoop(set_as_default=True) # has to be called first
Copy link
Member

@CRImier CRImier Jan 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

threads_init() 
Initialize threads in dbus-glib, if this has not already been done.
This must be called before creating a second thread in a program that uses this module.

(from here)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this applies to us. If so, that's a big problem since many threads are created before app import even starts

@@ -1,5 +1,4 @@
from helpers import setup_logger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why? I think you need to revert this particular change, which reverses our "setup_logger" integration work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as in, revert the logger-> logging replacements, not the from_string addition)

@@ -0,0 +1,2 @@
KERNEL=="ttyAMA0", ENV{OFONO_DRIVER}="sim900"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll be shipping this file in our own Debian package, most likely

ofono/bridge.py Outdated
manager = bus.get('org.ofono', '/')
modem_path = manager.GetModems()[0][0]

if modem_path != '/sim900_0':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to have the sim900 modem as the default modem? As in, what's wrong if it's not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a check because if you run ofono with some plugins, you might have a /stk_test virtual modem (standing for SimToolKit test). I wanted to be able to check the modem was correctly initialized at this point, but it might be an issue when we switch to SIM52XX later on. Shall I remove it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"check if it's correctly initialized" - you mean, check if it's available? If so, I'm guessing it might still be there in some cases, just not the 0th element in the list of the modems that you'll get. I suggest using if "/sim900_0" in manager.getModems()[0] or something along those lines.

ofono/bridge.py Outdated
@property
def _bus(self):
# lil hack so we always have an up-to-date bus
return pydbus.SystemBus().get('org.ofono', '/sim900_0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That "/sim900_0" string looks like it could benefit from being an attribute, it's repeated 3 times in this class

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

ofono/bridge.py Outdated
return self._get_dbus_interface('MessageManager')

def _get_dbus_interface(self, name):
''.startswith('org.ofono')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this particular line of code do here? It seems like a leftover line of code.

ofono/bridge.py Outdated
def main():
ofono = OfonoBridge()
ofono.start()
mainloop = GLib.MainLoop() # todo : own thread
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it - you have the GLib.MainLoop, and you have the DBusGMainLoop initialized in the beginning - are you sure you need both?

ofono/bridge.py Outdated

@property
def _bus(self):
# lil hack so we always have an up-to-date bus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's happening with the bus? Why can it get out-of-date?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you get the bus, you actually get a snapshot of the currently available methods.

So if you get the bus before the modem is initialized you don't have any method. Using it that way ensures you always have the latest exposed methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood! Would be great to put this explanation in the docstring/comment inside that function =)

ofono/bridge.py Outdated
if modem_path != '/sim900_0':
raise ValueError("Default modem should be '/sim900_0', was '{}'".format(modem_path))

# self.start() #todo: check if it's the suitable place to do it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so - it makes sense not to start() the loop right when the OfonoBridge is initialized.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in, explicit is better than implicit =)

ofono/bridge.py Outdated
try:
self._bus.SetProperty("Powered", pydbus.Variant('b', True))
sleep(2) # Let the modem some time to initialize
except Exception:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Just except: is enough if you want a catch-all
  2. I think that, if the modem can't power on, we'll want some more information - as much as the exception can provide us, and maybe more, so don't skimp on logging here =)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

ofono/bridge.py Outdated
super(ConversationManager, self).__init__()
self.folder = os.path.expanduser("~/.phone/sms/") # todo: store as a constant somewhere
if not os.path.exists(self.folder):
os.mkdir(self.folder)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll probably want os.mkdirs - it works like mkdir -p

@CRImier
Copy link
Member

CRImier commented Jan 13, 2018

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
Copy link
Collaborator Author

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 !

ofono/bridge.py Outdated
mainloop.run()
except KeyboardInterrupt:
logger.info("Caught CTRL-C:exiting without powering off...")
except AttributeError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.exception instead of just error, and make it a catch-all (as in, except: instead of catching AttributeError)? Would be great to have exception information in the logs, as well as protect from future errors.

@CRImier
Copy link
Member

CRImier commented Jun 16, 2018

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:

  • the modem is being set to CFUN=4 (essentially, flight mode) on power_off(). On next ofono bootup, the modem doesn't respond to ATE0 (AT command echo off), even though the flight mode shouldn't turn the serial communications off. Resetting the modem and restarting ofonod fixes the problem - funnily enough, resetting the modem without restarting ofonod doesn't.
  • ofonod has good debugging abilities (though I do still want to add a double-RX-UART to my debugging setup)
  • I don't have to reboot the phone - all I need is this commandline, then restart ofonod and bridge.py:
python -c 'import zerophone_hw; zerophone_hw.GSM_Modem().reset()'

@CRImier
Copy link
Member

CRImier commented Jun 16, 2018

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

@CRImier
Copy link
Member

CRImier commented Jun 17, 2018


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.

@CRImier CRImier added this to In progress in November SD image Oct 23, 2018
@codecov
Copy link

codecov bot commented Jan 6, 2019

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%) ⬇️
libs/ofono/bridge.py 0% <0%> (ø)
apps/phone/graphics.py 100% <100%> (ø)
ui/dialog.py 94.33% <100%> (+0.76%) ⬆️
ui/__init__.py 100% <100%> (ø) ⬆️
ui/overlays.py 79.81% <100%> (-3.6%) ⬇️
ui/numpad_input.py 77.44% <100%> (+0.49%) ⬆️
ui/tests/test_numpad_input.py 86.99% <100%> (+2.08%) ⬆️
ui/base_list_ui.py 84.61% <100%> (+2.14%) ⬆️
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 CRImier closed this Jan 6, 2019
@CRImier CRImier reopened this Jan 6, 2019
@CRImier
Copy link
Member

CRImier commented Jan 6, 2019

ouch, accident

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
November SD image
  
In progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants