aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Delmar Davis <don@suspectdevices.com>2012-10-10 16:29:47 -0700
committerDonald Delmar Davis <don@suspectdevices.com>2012-10-10 16:29:47 -0700
commitd60d28c60d450ad797308b4883ead3d57905146a (patch)
tree1bf16c3edc3a2447b64cabfd2504bdeb7ad88721
parent93a13d4622fa056e9817883c4d38b5877d565637 (diff)
try for reconnection
-rw-r--r--dumblogger/ConsoleApp.py228
-rw-r--r--dumblogger/ConsoleFrame.py83
-rw-r--r--dumblogger/Monitor.cpp3
-rw-r--r--dumblogger/datalogger.cpp3
4 files changed, 224 insertions, 93 deletions
diff --git a/dumblogger/ConsoleApp.py b/dumblogger/ConsoleApp.py
index 5bc07de..64897f3 100644
--- a/dumblogger/ConsoleApp.py
+++ b/dumblogger/ConsoleApp.py
@@ -1,21 +1,237 @@
#!/usr/bin/env python
-#Boa:App:BoaApp
import wx
+import subprocess
+import datetime
+import time
+import os
-import ConsoleFrame
+from AMAv2 import AMAv2
-modules ={u'ConsoleFrame': [1, 'Main frame of Application', u'ConsoleFrame.py']}
+build_dir=os.path.dirname(os.path.realpath(__file__)) + os.sep + '../../libmaple/'
+my_dir=os.path.dirname(os.path.realpath(__file__))
-class BoaApp(wx.App):
+
+[wxID_CONSOLE_FRAME, wxID_CONSOLE_FRAMECMD, wxID_CONSOLE_FRAMEOUTPUT, wxID_CONSOLE_FRAMEREBUILD,
+ wxID_CONSOLE_FRAMERESET, wxID_CONSOLE_FRAMESTATUSBAR1,
+] = [wx.NewId() for _init_ctrls in range(6)]
+
+class ConsoleFrame(wx.Frame):
+ def _init_coll_boxSizer1_Items(self, parent):
+ # generated method, don't edit
+
+ parent.AddSizer(self.boxSizer2, 0, border=0, flag=wx.EXPAND)
+ parent.AddSizer(self.boxSizer3, 1, border=0, flag=wx.EXPAND)
+ parent.AddWindow(self.statusBar1, 0, border=0, flag=0)
+
+ def _init_coll_boxSizer2_Items(self,parent):
+ parent.AddWindow(self.RESET, 0, border=0, flag=0)
+ parent.AddWindow(self.REBUILD, 0, border=0, flag=0)
+
+ def _init_coll_boxSizer3_Items(self, parent):
+ parent.AddWindow(self.OUTPUT, 1, border=0, flag=wx.EXPAND)
+ parent.AddWindow(self.CMD, 0, border=0, flag=wx.EXPAND)
+
+ def _init_sizers(self):
+ # generated method, don't edit
+ self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)
+
+ self.boxSizer2 = wx.BoxSizer(orient=wx.HORIZONTAL)
+
+ self.boxSizer3 = wx.BoxSizer(orient=wx.VERTICAL)
+
+ self._init_coll_boxSizer1_Items(self.boxSizer1)
+ self._init_coll_boxSizer2_Items(self.boxSizer2)
+ self._init_coll_boxSizer3_Items(self.boxSizer3)
+
+ self.SetSizer(self.boxSizer1)
+
+ def _init_ctrls(self, prnt):
+ # generated method, don't edit
+ wx.Frame.__init__(self, id=wxID_CONSOLE_FRAME, name='', parent=prnt,
+ pos=wx.Point(265, 195), size=wx.Size(838, 526),
+ style=wx.DEFAULT_FRAME_STYLE, title='BOM5k Console')
+ self.SetClientSize(wx.Size(838, 504))
+
+ self.CMD = wx.TextCtrl(id=wxID_CONSOLE_FRAMECMD, name=u'CMD', parent=self,
+ pos=wx.Point(0, 62), size=wx.Size(100, 22), style=wx.TE_PROCESS_ENTER|wx.PROCESS_ENTER, value=u'>')
+ self.CMD.Bind(wx.EVT_TEXT_ENTER, self.OnCMDText, id=wxID_CONSOLE_FRAMECMD)
+ self.CMD.Bind(wx.EVT_KILL_FOCUS, self.OnCMDKillFocus)
+
+ self.OUTPUT = wx.TextCtrl(id=wxID_CONSOLE_FRAMEOUTPUT, name=u'OUTPUT',
+ parent=self, pos=wx.Point(0, 40), size=wx.Size(100, 22), style=wx.TE_MULTILINE,
+ value=u'')
+ self.OUTPUT.SetEditable(False)
+ #self.OUTPUT.SetAutoLayout(True)
+ self.OUTPUT.Enable(False)
+
+ self.REBUILD = wx.Button(id=wxID_CONSOLE_FRAMEREBUILD, label=u'REBUILD',
+ name=u'REBUILD', parent=self, pos=wx.Point(0, 20),
+ size=wx.Size(84, 20), style=0)
+ self.REBUILD.Bind(wx.EVT_BUTTON, self.OnREBUILDButton,
+ id=wxID_CONSOLE_FRAMEREBUILD)
+
+ self.RESET = wx.Button(id=wxID_CONSOLE_FRAMERESET, label=u'RESET',
+ name=u'RESET', parent=self, pos=wx.Point(0, 0), size=wx.Size(84,
+ 20), style=0)
+
+ self.statusBar1 = wx.StatusBar(id=wxID_CONSOLE_FRAMESTATUSBAR1,
+ name='statusBar1', parent=self, style=0)
+ self.statusBar1.SetFieldsCount(4)
+ self.statusBar1.SetStatusWidths([-1,-1,-1,-1])
+
+ self._init_sizers()
+
+ def __init__(self, parent):
+ self._init_ctrls(parent)
+ MenuBar = wx.MenuBar()
+
+ FileMenu = wx.Menu()
+
+ item = FileMenu.Append(wx.ID_EXIT, text = "&Exit")
+ self.Bind(wx.EVT_MENU, self.OnQuit, item)
+
+ item = FileMenu.Append(wx.ID_ANY, text = "&Open")
+ self.Bind(wx.EVT_MENU, self.OnOpen, item)
+
+ item = FileMenu.Append(wx.ID_PREFERENCES, text = "&Preferences")
+ self.Bind(wx.EVT_MENU, self.OnPrefs, item)
+
+ MenuBar.Append(FileMenu, "&File")
+
+ HelpMenu = wx.Menu()
+
+ item = HelpMenu.Append(wx.ID_HELP, "Test &Help",
+ "Help for this simple test")
+ self.Bind(wx.EVT_MENU, self.OnHelp, item)
+
+ ## this gets put in the App menu on OS-X
+ item = HelpMenu.Append(wx.ID_ABOUT, "&About",
+ "More information About this program")
+ self.Bind(wx.EVT_MENU, self.OnAbout, item)
+ MenuBar.Append(HelpMenu, "&Help")
+
+ self.SetMenuBar(MenuBar)
+
+ self.device_was_already_attached=False
+ self.device=AMAv2(logger_only=True)
+ self.serialTimer = wx.Timer(self,-1)
+ self.Bind(wx.EVT_TIMER, self.processSerial, self.serialTimer)
+ self.serialTimer.Start(750)
+
+
+
+
+
+ def OnQuit(self,Event):
+ self.Destroy()
+
+ def OnAbout(self, event):
+ dlg = wx.MessageDialog(self, "This is a small program to test\n"
+ "the use of menus on Mac, etc.\n",
+ "About Me", wx.OK | wx.ICON_INFORMATION)
+ dlg.ShowModal()
+ dlg.Destroy()
+
+ def OnHelp(self, event):
+ dlg = wx.MessageDialog(self, "This would be help\n"
+ "If there was any\n",
+ "Test Help", wx.OK | wx.ICON_INFORMATION)
+ dlg.ShowModal()
+ dlg.Destroy()
+
+ def OnOpen(self, event):
+ dlg = wx.MessageDialog(self, "This would be an open Dialog\n"
+ "If there was anything to open\n",
+ "Open File", wx.OK | wx.ICON_INFORMATION)
+ dlg.ShowModal()
+ dlg.Destroy()
+
+ def OnPrefs(self, event):
+ dlg = wx.MessageDialog(self, "This would be an preferences Dialog\n"
+ "If there were any preferences to set.\n",
+ "Preferences", wx.OK | wx.ICON_INFORMATION)
+ dlg.ShowModal()
+ dlg.Destroy()
+
+
+
+ def OnREBUILDButton(self, event):
+ self.statusBar1.SetStatusText("...Uploading...",1)
+ self.OUTPUT.AppendText('\n---------------------- UPLOAD -------------------\n')
+ if self.device.ser is not None:
+ self.device.ser.close()
+ self.device.attached=False
+ try:
+ self.OUTPUT.AppendText(subprocess.check_output("make install",
+ env={'BOARD': 'maple_mini','USER_MODULES': '../programs/dumblogger',
+ 'PATH': '/usr/local/arm-none-eabi/bin/:/usr/local/bin/:/usr/bin:/bin/:$PATH'},
+ #stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ shell=True,
+ cwd=build_dir))
+ self.OUTPUT.AppendText('\n------------------- SUCCESS ------------------\n')
+
+ except CalledProcessError as e:
+ self.OUTPUT.AppendText(e.cmd +"Returned "+str(e.returncode))
+ self.OUTPUT.AppendText(e.output)
+ self.OUTPUT.AppendText('\n-------------------- FAIL --------------------\n')
+
+ time.sleep(1)
+ self.OnReconnect()
+ #self.device.attached=True # should be handled by ama class
+ event.Skip()
+
+ def OnCMDText(self, event):
+ comm=self.CMD.GetValue().rstrip('\r\n')
+ self.CMD.SetValue('')
+ self.statusBar1.SetStatusText(">>"+comm,0)
+ if self.device.attached:
+ self.device.ser.write(str(comm)+'\r\n')
+ event.Skip()
+
+ def OnReconnect(self, event=None):
+ self.device.attached=False
+ if self.device.ser is not None:
+ self.device.ser.close()
+ self.statusBar1.SetStatusText("...Searching...",1)
+ self.device.open(self.device.portname,9600,logger_only=True)
+ if event is not None:
+ event.Skip()
+
+
+ def OnCMDKillFocus(self, event):
+ event.Skip()
+
+
+ def processSerial(self,event=None):
+ if self.device.attached:
+ if not self.device_was_already_attached:
+ self.statusBar1.SetStatusText(self.device.logger_swv_string,1)
+ try:
+ while self.device.ser.inWaiting():
+ line=unicode(self.device.ser.readline(100).rstrip('\r\n'),errors='ignore')
+ line=line.encode('ascii','replace')
+ self.OUTPUT.AppendText(line+'\n')
+ self.device.dispatch(line)
+ except IOError as e:
+ self.device.attached=False
+ else:
+ self.OnReconnect()
+ self.device_was_already_attached=self.device.attached
+ if event is not None:
+ event.Skip()
+
+
+class ConsoleApp(wx.App):
def OnInit(self):
- self.main = ConsoleFrame.create(None)
+ self.main = ConsoleFrame(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
- application = BoaApp(0)
+ application = ConsoleApp(0)
application.MainLoop()
if __name__ == '__main__':
diff --git a/dumblogger/ConsoleFrame.py b/dumblogger/ConsoleFrame.py
deleted file mode 100644
index 276103a..0000000
--- a/dumblogger/ConsoleFrame.py
+++ /dev/null
@@ -1,83 +0,0 @@
-#Boa:Frame:Frame1
-
-import wx
-
-def create(parent):
- return Frame1(parent)
-
-[wxID_FRAME1, wxID_FRAME1CMD, wxID_FRAME1OUTPUT, wxID_FRAME1REBUILD,
- wxID_FRAME1RESET, wxID_FRAME1STATUSBAR1,
-] = [wx.NewId() for _init_ctrls in range(6)]
-
-class Frame1(wx.Frame):
- def _init_coll_boxSizer1_Items(self, parent):
- # generated method, don't edit
-
- parent.AddSizer(self.boxSizer2, 0, border=0, flag=wx.EXPAND)
- parent.AddSizer(self.boxSizer3, 1, border=0, flag=wx.EXPAND)
- parent.AddWindow(self.statusBar1, 0, border=0, flag=0)
-
- def _init_coll_boxSizer2_Items(self,parent):
- parent.AddWindow(self.RESET, 0, border=0, flag=0)
- parent.AddWindow(self.REBUILD, 0, border=0, flag=0)
-
- def _init_coll_boxSizer3_Items(self, parent):
- parent.AddWindow(self.OUTPUT, 1, border=0, flag=wx.EXPAND)
- parent.AddWindow(self.CMD, 0, border=0, flag=wx.EXPAND)
-
- def _init_sizers(self):
- # generated method, don't edit
- self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)
-
- self.boxSizer2 = wx.BoxSizer(orient=wx.HORIZONTAL)
-
- self.boxSizer3 = wx.BoxSizer(orient=wx.VERTICAL)
-
- self._init_coll_boxSizer1_Items(self.boxSizer1)
- self._init_coll_boxSizer2_Items(self.boxSizer2)
- self._init_coll_boxSizer3_Items(self.boxSizer3)
-
- self.SetSizer(self.boxSizer1)
-
- def _init_ctrls(self, prnt):
- # generated method, don't edit
- wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
- pos=wx.Point(265, 195), size=wx.Size(838, 526),
- style=wx.DEFAULT_FRAME_STYLE, title='BOM5k Console')
- self.SetClientSize(wx.Size(838, 504))
-
- self.CMD = wx.TextCtrl(id=wxID_FRAME1CMD, name=u'CMD', parent=self,
- pos=wx.Point(0, 62), size=wx.Size(100, 22), style=0, value=u'>')
- self.CMD.Bind(wx.EVT_TEXT, self.OnCMDText, id=wxID_FRAME1CMD)
- self.CMD.Bind(wx.EVT_KILL_FOCUS, self.OnCMDKillFocus)
-
- self.OUTPUT = wx.TextCtrl(id=wxID_FRAME1OUTPUT, name=u'OUTPUT',
- parent=self, pos=wx.Point(0, 40), size=wx.Size(100, 22), style=0,
- value=u'...')
-
- self.REBUILD = wx.Button(id=wxID_FRAME1REBUILD, label=u'REBUILD',
- name=u'REBUILD', parent=self, pos=wx.Point(0, 20),
- size=wx.Size(84, 20), style=0)
- self.REBUILD.Bind(wx.EVT_BUTTON, self.OnREBUILDButton,
- id=wxID_FRAME1REBUILD)
-
- self.RESET = wx.Button(id=wxID_FRAME1RESET, label=u'RESET',
- name=u'RESET', parent=self, pos=wx.Point(0, 0), size=wx.Size(84,
- 20), style=0)
-
- self.statusBar1 = wx.StatusBar(id=wxID_FRAME1STATUSBAR1,
- name='statusBar1', parent=self, style=0)
-
- self._init_sizers()
-
- def __init__(self, parent):
- self._init_ctrls(parent)
-
- def OnREBUILDButton(self, event):
- event.Skip()
-
- def OnCMDText(self, event):
- event.Skip()
-
- def OnCMDKillFocus(self, event):
- event.Skip()
diff --git a/dumblogger/Monitor.cpp b/dumblogger/Monitor.cpp
index 93e82ea..3ad9059 100644
--- a/dumblogger/Monitor.cpp
+++ b/dumblogger/Monitor.cpp
@@ -99,8 +99,7 @@ void toConsole(const char *format, ...){
uint8_t NOPaction(uint8_t source) {
if (source==CONSOLE) {
toConsole("DBG: Forwarding (%c%c%c)!",
- consoleComm.line[0], consoleComm.line[1], consoleComm.line[2]);
- toConsole(actionBuffer);
+ consoleComm.line[0], consoleComm.line[1], consoleComm.line[2]);
toDevice((char *)consoleComm.line);
return COMMAND_FORWARDED;
diff --git a/dumblogger/datalogger.cpp b/dumblogger/datalogger.cpp
index d683b71..1ff28f9 100644
--- a/dumblogger/datalogger.cpp
+++ b/dumblogger/datalogger.cpp
@@ -101,7 +101,6 @@ char deviceSWV[MAX_SWV_LENGTH]="0.0-000000";
time_t deviceLastContact=0L;
bool deviceIsConnected=false;
-
const int sensor_pin = 12;
@@ -180,7 +179,7 @@ static void serialTasks() {
}
consoleComm.line[consoleComm.len]='\0';
}
- SerialUSB.write(ch);
+ //SerialUSB.write(ch);
}
}