2e8ef4c3d11ec8dab498f0e05815e0db8e9a9c7a
[SaveMySugar/python3-savemysugar.git] / src / transmit.py
1 #!/usr/bin/env python3
2 #
3 # SaveMySugar - transmit messages using Morse code via phone rings
4 #
5 # Copyright (C) 2015  Antonio Ospite <ao2@ao2.it>
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 from savemysugar.CallDistanceTransceiver import CallDistanceTransceiver
21 from savemysugar.Modem import Modem
22 import logging
23
24 # TODO: set the logging level from the command line
25 FORMAT = "%(created)f %(levelname)s:%(funcName)s %(message)s"
26 logging.basicConfig(level=logging.DEBUG, format=FORMAT)
27
28
29 def transmit(port, number, message):
30     modem = Modem(port)
31
32     transmitter = CallDistanceTransceiver(modem)
33     transmitter.estimate_transmit_duration(message)
34     transmitter.transmit(message, number)
35
36
37 def main():
38     print("Available hardware serial ports:")
39     for port in Modem.scan():
40         print("  - " + port)
41     print()
42
43     import sys
44     if len(sys.argv) != 4:
45         print("usage: %s" % sys.argv[0],
46               "<serial port> <destination number> <message>")
47         sys.exit(1)
48     transmit(sys.argv[1], sys.argv[2], sys.argv[3])
49
50
51 if __name__ == "__main__":
52     main()