#!/usr/bin/env python
|
#!/usr/bin/env python
|
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
|
|
import wx
|
import wx
|
import guiparent
|
import guiparent
|
|
|
import os # se usa para el dialogo de abrir fichero
|
import os # se usa para el dialogo de abrir fichero
|
import subprocess # para interactuar con el shell
|
import subprocess # para interactuar con el shell
|
import thread # to prevent gui blocking
|
import thread # to prevent gui blocking
|
from sys import platform as _platform # para detectar el sistema operativo
|
from sys import platform as _platform # para detectar el sistema operativo
|
|
|
|
|
class phrgui (guiparent.guiParent):
|
class phrgui (guiparent.guiParent):
|
def __init__(self, *args, **kwds):
|
def __init__(self, *args, **kwds):
|
guiparent.guiParent.__init__(self, *args, **kwds)
|
guiparent.guiParent.__init__(self, *args, **kwds)
|
self.__set_extra_properties()
|
self.__set_extra_properties()
|
|
|
|
|
def __set_extra_properties(self):
|
def __set_extra_properties(self):
|
# Definicion de la fuente monospace
|
# Definicion de la fuente monospace
|
font1 = self.text_ctrl_console.GetFont()
|
font1 = self.text_ctrl_console.GetFont()
|
font1 = wx.Font(font1.GetPointSize(), wx.TELETYPE,
|
font1 = wx.Font(font1.GetPointSize(), wx.TELETYPE,
|
font1.GetStyle(),
|
font1.GetStyle(),
|
font1.GetWeight(), font1.GetUnderlined())
|
font1.GetWeight(), font1.GetUnderlined())
|
|
|
# Propiedades de la consola
|
# Propiedades de la consola
|
self.text_ctrl_console.SetFont(font1)
|
self.text_ctrl_console.SetFont(font1)
|
self.text_ctrl_console.SetValue("PHR>>> ")
|
self.text_ctrl_console.SetValue("PHR>>> ")
|
|
|
# Propiedades de la la lista de dispositivos detectados
|
# Propiedades de la la lista de dispositivos detectados
|
self.list_box_dispositivos_conectados.SetFont(font1)
|
self.list_box_dispositivos_conectados.SetFont(font1)
|
|
|
|
|
def menu_item_ayuda_acerca_de_handler(self, event): # wxGlade: wg_parent_class.<event_handler>
|
def menu_item_ayuda_acerca_de_handler(self, event): # wxGlade: wg_parent_class.<event_handler>
|
description = """
|
description = u"""
|
PHR GUI es una interfaz gráfica que permite interactuar con
|
PHR GUI es una interfaz gráfica que permite interactuar con
|
la Plataforma de Hardware Reconfigurable (CUDAR) a través
|
la Plataforma de Hardware Reconfigurable (CUDAR) a través
|
del software xc3sprog.
|
del software xc3sprog.
|
|
|
$Rev: 336 $
|
$Rev: 337 $
|
$Date: 2014-06-11 03:58:02 +0200 (Wed, 11 Jun 2014) $
|
$Date: 2014-06-13 04:58:39 +0200 (Fri, 13 Jun 2014) $
|
"""
|
"""
|
licence = """
|
licence = """
|
PHR GUI is free software; you can redistribute it and/or modify
|
PHR GUI is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License as
|
it under the terms of the GNU General Public License as
|
published by the Free Software Foundation; either version 2
|
published by the Free Software Foundation; either version 2
|
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
|
|
PHR GUI is distributed in the hope that it will be useful,
|
PHR GUI is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
See the GNU General Public License for more details. You should have
|
See the GNU General Public License for more details. You should have
|
received a copy of the GNU General Public License along with
|
received a copy of the GNU General Public License along with
|
PHR GUI; if not, write to the Free Software Foundation, Inc.,
|
PHR GUI; if not, write to the Free Software Foundation, Inc.,
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
"""
|
"""
|
info = wx.AboutDialogInfo()
|
info = wx.AboutDialogInfo()
|
|
|
info.SetIcon(wx.Icon('grafica/phr-gui-96.png', wx.BITMAP_TYPE_PNG))
|
info.SetIcon(wx.Icon('grafica/phr-gui-96.png', wx.BITMAP_TYPE_PNG))
|
info.SetName('PHR GUI')
|
info.SetName('PHR GUI')
|
info.SetVersion('0.1.1')
|
info.SetVersion('0.1.1')
|
info.SetDescription(description)
|
info.SetDescription(description)
|
#info.SetCopyright('(C) 2014 CUDAR (UTN-FRC)')
|
#info.SetCopyright('(C) 2014 CUDAR (UTN-FRC)')
|
info.SetCopyright('2014, CUDAR (UTN-FRC)')
|
info.SetCopyright('2014, CUDAR (UTN-FRC)')
|
info.SetWebSite('http://opencores.org/project,phr')
|
info.SetWebSite('http://opencores.org/project,phr')
|
#info.SetLicence(licence)
|
#info.SetLicence(licence)
|
info.AddDeveloper('Luis Guanuco, Maximiliano Quinteros.')
|
info.AddDeveloper('Luis Guanuco, Maximiliano Quinteros.')
|
|
|
wx.AboutBox(info)
|
wx.AboutBox(info)
|
event.Skip()
|
event.Skip()
|
|
|
|
|
def menu_item_ayuda_hint_handler(self, event): # wxGlade: guiParent.<event_handler>
|
def menu_item_ayuda_hint_handler(self, event): # wxGlade: guiParent.<event_handler>
|
mensaje = """
|
mensaje = u"""
|
Procedimiento general para utilizar este programa:
|
Procedimiento general para utilizar este programa:
|
|
|
1. Conecte el programador y presione en el botón \"Detectar\".
|
1. Conecte el programador y presione en el botón \"Detectar\".
|
Se listaran los dispositivos encontrados en la cadena JTAG.
|
Se listaran los dispositivos encontrados en la cadena JTAG.
|
2. Seleccione el dispositivo que desea programar o configurar.
|
2. Seleccione el dispositivo que desea programar o configurar.
|
3. Elija un fichero de configuración/programación.
|
3. Elija un fichero de configuración/programación.
|
*.BIT para FPGA
|
*.BIT para FPGA
|
*.JED para CPLD
|
*.JED para CPLD
|
4. Presione el botón \"Transferir\".
|
4. Presione el botón \"Transferir\".
|
|
|
Considere las recomendaciones de la placa especÃfica que esté
|
Considere las recomendaciones de la placa especÃfica que esté
|
utilizando.
|
utilizando.
|
"""
|
"""
|
wx.MessageBox(mensaje, 'Info', wx.OK | wx.ICON_INFORMATION)
|
wx.MessageBox(mensaje, 'Info', wx.OK | wx.ICON_INFORMATION)
|
event.Skip()
|
event.Skip()
|
|
|
|
|
def boton_elegir_fichero_handler(self, event): # wxGlade: wg_parent_class.<event_handler>
|
def boton_elegir_fichero_handler(self, event): # wxGlade: wg_parent_class.<event_handler>
|
wildcard = "Archivo BIT de Xilinx (*.bit)|*.bit|" \
|
wildcard = "Archivo BIT de Xilinx (*.bit)|*.bit|" \
|
"Archivo JEDEC para CPLD (*.jed)|*.jed|" \
|
"Archivo JEDEC para CPLD (*.jed)|*.jed|" \
|
"Todos los archivos (*.*)|*.*"
|
"Todos los archivos (*.*)|*.*"
|
dialog = wx.FileDialog(None, "Elija un archivo", os.getcwd(), "", wildcard, wx.OPEN)
|
dialog = wx.FileDialog(None, "Elija un archivo", os.getcwd(), "", wildcard, wx.OPEN)
|
if dialog.ShowModal() == wx.ID_OK:
|
if dialog.ShowModal() == wx.ID_OK:
|
self.text_ctrl_fichero.SetValue(dialog.GetPath())
|
self.text_ctrl_fichero.SetValue(dialog.GetPath())
|
print "New file to transfer: " + dialog.GetPath()
|
print "New file to transfer: " + dialog.GetPath()
|
|
|
dialog.Destroy()
|
dialog.Destroy()
|
event.Skip()
|
event.Skip()
|
|
|
|
|
def boton_borrar_salida_handler(self, event): # wxGlade: wg_parent_class.<event_handler>
|
def boton_borrar_salida_handler(self, event): # wxGlade: wg_parent_class.<event_handler>
|
self.text_ctrl_console.SetValue("PHR>>> ") # borra el contenido de la consola
|
self.text_ctrl_console.SetValue("PHR>>> ") # borra el contenido de la consola
|
print "Console cleared"
|
print "Console cleared"
|
event.Skip()
|
event.Skip()
|
|
|
|
|
def before_run (self):
|
def before_run (self):
|
# preparar entorno para los eventos de transferencia y deteccion de dispositivos
|
# preparar entorno para los eventos de transferencia y deteccion de dispositivos
|
self.boton_transferir.Disable()
|
self.boton_transferir.Disable()
|
self.boton_elegir_fichero.Disable()
|
self.boton_elegir_fichero.Disable()
|
self.boton_detectar.Disable()
|
self.boton_detectar.Disable()
|
self.boton_borrar_salida.Disable()
|
self.boton_borrar_salida.Disable()
|
self.statusbar.SetFields(["Espere ..."])
|
self.statusbar.SetFields(["Espere ..."])
|
|
|
|
|
def after_run (self):
|
def after_run (self):
|
# restaurar entorno
|
# restaurar entorno
|
self.boton_transferir.Enable()
|
self.boton_transferir.Enable()
|
self.boton_elegir_fichero.Enable()
|
self.boton_elegir_fichero.Enable()
|
self.boton_detectar.Enable()
|
self.boton_detectar.Enable()
|
self.boton_borrar_salida.Enable()
|
self.boton_borrar_salida.Enable()
|
self.statusbar.SetFields(["Listo"])
|
self.statusbar.SetFields(["Listo"])
|
|
|
|
|
def boton_transferir_thread(self):
|
def boton_transferir_thread(self, position):
|
## preparar entorno
|
## preparar entorno
|
wx.CallAfter(self.before_run)
|
wx.CallAfter(self.before_run)
|
|
|
device_list_selection = self.list_box_dispositivos_conectados.GetSelections()
|
position = str (position)
|
if len (device_list_selection) > 0:
|
|
position = str(device_list_selection[0])
|
|
else:
|
|
position = ""
|
|
|
|
if _platform == "linux" or _platform == "linux2":
|
if _platform == "linux" or _platform == "linux2":
|
# linux
|
# linux
|
command = "./xc3sprog/xc3sprog -v -c ftdi -p " + position + " \""+ self.text_ctrl_fichero.GetValue() + "\""
|
command = "./xc3sprog/lin/xc3sprog -v -c ftdi -p " + position + " \""+ self.text_ctrl_fichero.GetValue() + "\""
|
else:
|
else:
|
# windows
|
# windows
|
subprocess.call ("copy \"" + self.text_ctrl_fichero.GetValue() + "\" fpgaFile", shell=True)
|
subprocess.call ("copy \"" + self.text_ctrl_fichero.GetValue() + "\" fpgaFile", shell=True)
|
command = "xc3sprog\\xc3sprog.exe -v -L -c ftdi -p " + position + " fpgaFile:w:0:BIT"
|
command = "xc3sprog\\win\\xc3sprog -v -L -c ftdi -p " + position + " fpgaFile:w:0:BIT"
|
|
|
wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
|
wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
|
|
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
|
|
|
|
|
if _platform == "linux" or _platform == "linux2":
|
if _platform == "linux" or _platform == "linux2":
|
# linux
|
# linux
|
for line in iter(process.stdout.readline, ''):
|
for line in iter(process.stdout.readline, ''):
|
wx.CallAfter(self.text_ctrl_console.AppendText, line)
|
wx.CallAfter(self.text_ctrl_console.AppendText, line)
|
process.stdout.close()
|
process.stdout.close()
|
else:
|
else:
|
# Windows
|
# Windows
|
line = ''
|
line = ''
|
while True:
|
while True:
|
out = process.stdout.read(1)
|
out = process.stdout.read(1)
|
if out == '' and process.poll() != None:
|
if out == '' and process.poll() != None:
|
break
|
break
|
if out != '' and out != '\x0a':
|
if out != '' and out != '\x0a':
|
line = line + out
|
line = line + out
|
if out == '\x0d':
|
if out == '\x0d':
|
wx.CallAfter(self.text_ctrl_console.AppendText, line)
|
wx.CallAfter(self.text_ctrl_console.AppendText, line)
|
line = ''
|
line = ''
|
|
|
wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
|
wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
|
|
|
## restaurar entorno
|
## restaurar entorno
|
wx.CallAfter(self.after_run)
|
wx.CallAfter(self.after_run)
|
|
|
|
|
def boton_transferir_handler(self, event): # wxGlade: wg_parent_class.<event_handler>
|
def boton_transferir_handler(self, event): # wxGlade: wg_parent_class.<event_handler>
|
thread.start_new_thread(self.boton_transferir_thread, ())
|
|
|
device_list_selection = self.list_box_dispositivos_conectados.GetSelections()
|
|
|
|
if len (device_list_selection) > 0:
|
|
position = device_list_selection[0]
|
|
else:
|
|
position = 0
|
|
|
|
thread.start_new_thread(self.boton_transferir_thread, (position,))
|
event.Skip()
|
event.Skip()
|
|
|
|
|
def boton_detectar_thread (self):
|
def boton_detectar_thread (self):
|
## preparar entorno
|
## preparar entorno
|
wx.CallAfter(self.before_run, )
|
wx.CallAfter(self.before_run, )
|
wx.CallAfter(self.list_box_dispositivos_conectados.Clear)
|
wx.CallAfter(self.list_box_dispositivos_conectados.Clear)
|
|
|
## accion
|
## accion
|
|
|
if _platform == "linux" or _platform == "linux2":
|
if _platform == "linux" or _platform == "linux2":
|
# linux
|
# linux
|
command = "./xc3sprog/xc3sprog -c ftdi"
|
command = "./xc3sprog/lin/xc3sprog -c ftdi"
|
else:
|
else:
|
# windows
|
# windows
|
command = "xc3sprog\\xc3sprog -c ftdi -L -j -v"
|
command = "xc3sprog\\win\\xc3sprog -c ftdi -L -j -v"
|
|
|
wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
|
wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
|
|
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
|
|
|
for line in iter(process.stdout.readline, ''):
|
for line in iter(process.stdout.readline, ''):
|
# Append output to console
|
# Append output to console
|
wx.CallAfter(self.text_ctrl_console.AppendText, line)
|
wx.CallAfter(self.text_ctrl_console.AppendText, line)
|
|
|
# If it is a JTAG device append it in list box as well
|
# If it is a JTAG device append it in list box as well
|
if line.lower()[0:10] == "jtag loc.:":
|
if line.lower()[0:10] == "jtag loc.:":
|
deviceStr = line.split ()
|
deviceStr = line.split ()
|
appendStr = deviceStr[0] + " " + deviceStr[2] + ": "
|
appendStr = deviceStr[0] + " " + deviceStr[2] + ": "
|
|
|
if deviceStr[5] == "Desc:":
|
if deviceStr[5] == "Desc:":
|
appendStr += deviceStr[6] + " (ID:" + deviceStr[4] + ")"
|
appendStr += deviceStr[6] + " (ID:" + deviceStr[4] + ")"
|
else:
|
else:
|
appendStr += "Unknown" + " (ID:" + deviceStr[4] + ")"
|
appendStr += "Unknown" + " (ID:" + deviceStr[4] + ")"
|
|
|
wx.CallAfter(self.list_box_dispositivos_conectados.Append, appendStr)
|
wx.CallAfter(self.list_box_dispositivos_conectados.Append, appendStr)
|
|
|
process.stdout.close()
|
process.stdout.close()
|
|
|
|
if self.list_box_dispositivos_conectados.GetCount() >= 1:
|
wx.CallAfter(self.list_box_dispositivos_conectados.SetSelection, 0)
|
wx.CallAfter(self.list_box_dispositivos_conectados.SetSelection, 0)
|
|
|
wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
|
wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
|
|
|
## restaurar entorno
|
## restaurar entorno
|
wx.CallAfter(self.after_run, )
|
wx.CallAfter(self.after_run, )
|
|
|
|
|
def boton_detectar_handler(self, event): # wxGlade: wg_parent_class.<event_handler>
|
def boton_detectar_handler(self, event): # wxGlade: wg_parent_class.<event_handler>
|
thread.start_new_thread(self.boton_detectar_thread, ())
|
thread.start_new_thread(self.boton_detectar_thread, ())
|
event.Skip()
|
event.Skip()
|
|
|
# end of class phrgui
|
# end of class phrgui
|
|
|
if __name__ == "__main__":
|
if __name__ == "__main__":
|
app = wx.PySimpleApp(0)
|
app = wx.App(False)
|
wx.InitAllImageHandlers()
|
|
frame = phrgui(None, -1, "")
|
frame = phrgui(None, -1, "")
|
app.SetTopWindow(frame)
|
app.SetTopWindow(frame)
|
frame.Show()
|
frame.Show()
|
app.MainLoop()
|
app.MainLoop()
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|