|
| 1 | +#!/usr/bin/env python2 |
| 2 | + |
| 3 | +# Copyright (C) 2011,2012,2013 Brendan Le Foll <[email protected]> |
| 4 | +# |
| 5 | +# This program is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation, either version 2 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# This program is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +import dbus.service |
| 19 | +from dbus.mainloop.glib import DBusGMainLoop |
| 20 | +from SerialController import SerialController |
| 21 | +from BaseService import BaseService |
| 22 | + |
| 23 | +import arcam_cmds |
| 24 | + |
| 25 | +ARCAMSERVICE_IFACE = 'uk.co.madeo.rs232server.arcam' |
| 26 | +ARCAMSERVICE_OBJ_PATH = '/uk/co/madeo/rs232server/arcam' |
| 27 | + |
| 28 | +DELAY = 1 |
| 29 | +BAUD_RATE = 38400 |
| 30 | +BYTESIZE = 8 |
| 31 | +READVAL = 10 |
| 32 | + |
| 33 | +class ArcamService(BaseService): |
| 34 | + |
| 35 | + def __init__(self, tty, bus_name): |
| 36 | + BaseService.__init__(self, bus_name, ARCAMSERVICE_OBJ_PATH, tty, BAUD_RATE, READVAL, arcam_cmds) |
| 37 | + |
| 38 | + @dbus.service.method(ARCAMSERVICE_IFACE, in_signature='sib', out_signature='s') |
| 39 | + def send_cmd(self, cmd, repeat, check): |
| 40 | + self.logger.debug("sent command : %s", cmd) |
| 41 | + if cmd == "help": |
| 42 | + self.logger.debug("Getting help!") |
| 43 | + return self.help() |
| 44 | + if (check): |
| 45 | + return self.queue.add(arcam_cmds.commands[cmd], check) |
| 46 | + for i in range(0, repeat): |
| 47 | + self.queue.add(arcam_cmds.commands[cmd], check) |
| 48 | + return "" |
0 commit comments