-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPROFino.py
More file actions
69 lines (56 loc) · 2.05 KB
/
PROFino.py
File metadata and controls
69 lines (56 loc) · 2.05 KB
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
#!/usr/bin/python3
import os, sys, getopt, shutil
import instrument, make, monitor
from GUI import initGUI
# Exibe a mensagem de ajuda caso os argumentos passados não sejam válidos
def displayHelp():
print('Usage: ')
print('{0:<20}{1:}'.format('-h --help', 'Display this help.'))
print('{0:<20}{1:}'.format('-c --source', 'Path to source code.'))
print('{0:<20}{1:}'.format('-p --port', 'USB port where the Arduino is connected, Ex: /dev/ttyACM0, /dev/ttyUSB0.'))
print('{0:<20}{1:}'.format('-g --graphic', 'Flag that indicates if the program must run in GUI mode.'))
sys.exit(0) # Se por acaso o parâmetro de ajuda foi passado, não faz nada senão exibir a ajuda
# Valida se os parâmetros foram passados corretamente pela linha de comando
def evaluate_args():
short_options = 'hc:p:g'
long_options = ['help', 'source=', 'port=', 'graphic']
try:
args, values = getopt.getopt(sys.argv[1:], short_options, long_options)
filename, port = '', ''
graphic = False
for arg, value in args:
if arg in ['-h', '--help']:
displayHelp()
elif arg in ['-c', '--source']:
filename = value
elif arg in ['-p', '--port']:
port = value
elif arg in ['-g', '--graphic']:
graphic = True
if not graphic:
if filename == '' or port == '':
print('Invalid arguments!')
displayHelp()
return filename, port, graphic
except getopt.error as e:
print (str(e))
sys.exit(2)
# ...
def main():
filepath, port, graphic = evaluate_args()
if graphic:
initGUI(filepath, port)
else:
if '/' in filepath:
shutil.copy(filepath, './')
filename = filepath.split('/')[-1]
else:
filename = filepath
source = filename.split('.')[0] + '.inst' # "arquivo.inst.c"
functions = instrument.instrument(filename) # Instrumenta o código-fonte original
make.run(source, port) # Compila o código-fonte instrumentado e faz upload para o Arduino
if '/' in filepath:
os.remove(filename)
monitor.monitor(functions, port) # Inicia o 'live-profiling' do código instrumentado sendo executado no Arduino
if __name__ == '__main__':
main()