-
Notifications
You must be signed in to change notification settings - Fork 1
/
rpyloader
96 lines (84 loc) · 3.23 KB
/
rpyloader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
# coding=UTF-8
'''
rpyloader - Load hex programs on your robot
Copyright (C) 2011 Scirocco <[email protected]>
Copyright (C) 2016 Benedikt Wildenhain <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
"""rpyutils by Maximilian Mühlbauer <[email protected]>"""
import rpyutils.rlib
import rpyutils.hexlib
import getopt # get command line options
import sys
import gettext
from rpyutils.translation import _
def getargs(argv):
global port
port = "/dev/ttyUSB0"
global ignore
ignore = False
global terminal
terminal = False
global debuglevel
debuglevel = 0
global infile
infile = ""
try:
opts, args = getopt.getopt(argv, "htif:d:l:", ["help", "file=", "device=", "terminal", "ignore", "debug-level="])
except getopt.GetoptError:
print(_("Wrong option."))
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt in ("-d", "--device"):
port = arg
elif opt in ("-f", "--file"):
infile = arg
elif opt in ("-t", "--terminal"): # show terminal after flashing
terminal = True
elif opt in ("-i", "--ignore"): # ignore wrong type of binary
ignore = True
elif opt in ("-l", "--debug-level"):
debuglevel = int(arg)
def usage():
print(_("Usage: %(myName)s -[htif:d:l:] --[help, file, device, terminal, debug-level]") % { 'myName': __file__ })
print(_("-h, --help show this help dialog"))
print(_("-f, --file [file] specify a filename"))
print(_("-d, --device [device] select other device than /dev/ttyUSB0"))
print(_("-i, --ignore ignore that your program maybe doesn't suit the connected your robot device"))
print(_("-t, --terminal show rpyTerm at the end of the flash process"))
print(_("-l, --debug-level change debug level to show more / less"))
getargs(sys.argv[1:])
if infile[len(infile) - 3:] != "hex":
if debuglevel >= 1:
print(_("searching for *.hex files in current directory..."))
infile = rpyutils.hexlib.HexToBin.findHexFile()
if infile == False:
usage()
sys.exit(2)
progtype = rpyutils.rlib.Robby.getFileClass(infile)
# hexlib class; parse hex file
hexlib = rpyutils.hexlib.HexToBin(infile, debuglevel)
rp6 = rpyutils.rlib.Robby(port, debuglevel)
rp6.connect()
rp6.reset()
robottype = rp6.getType(True)
if robottype != progtype and ignore != True:
print(_("File for wrong board given. Ignore this with -i"))
sys.exit(2)
rp6.setHighSpeed()
rp6.getType()
rp6.flash(hexlib.getBinData())