Merge branch 'master' of github.com:jamesbowman/i2cdriver
This commit is contained in:
commit
2697bf5046
|
@ -343,19 +343,26 @@ class I2CDriver:
|
||||||
self.scl,
|
self.scl,
|
||||||
self.sda)
|
self.sda)
|
||||||
|
|
||||||
def capture_start(self, start = START, abyte = BYTE, stop = STOP):
|
def capture_start(self, idle=False, start = START, abyte = BYTE, stop = STOP):
|
||||||
self.__ser_w([ord('c')])
|
self.__ser_w([ord('c')])
|
||||||
def nstream():
|
def nstream():
|
||||||
while 1:
|
while True:
|
||||||
for b in self.ser.read(256):
|
bb = self.ser.read(256)
|
||||||
yield (b >> 4) & 0xf
|
if PYTHON2:
|
||||||
yield b & 0xf
|
for b in bb:
|
||||||
|
yield (ord(b) >> 4) & 0xf
|
||||||
|
yield ord(b) & 0xf
|
||||||
|
else:
|
||||||
|
for b in bb:
|
||||||
|
yield (b >> 4) & 0xf
|
||||||
|
yield b & 0xf
|
||||||
def parser():
|
def parser():
|
||||||
starting = False
|
starting = False
|
||||||
rw = 0
|
rw = 0
|
||||||
for n in nstream():
|
for n in nstream():
|
||||||
if n == 0:
|
if n == 0:
|
||||||
pass
|
if idle:
|
||||||
|
yield None
|
||||||
elif n == 1:
|
elif n == 1:
|
||||||
starting = True
|
starting = True
|
||||||
bits = []
|
bits = []
|
||||||
|
|
|
@ -5,6 +5,7 @@ import struct
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import csv
|
||||||
import threading
|
import threading
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
@ -39,6 +40,21 @@ def ping_thr(win):
|
||||||
wx.PostEvent(win, PingEvent())
|
wx.PostEvent(win, PingEvent())
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
StopCapture = False
|
||||||
|
|
||||||
|
def capture_thr(sd, log_csv):
|
||||||
|
global StopCapture
|
||||||
|
c = sd.capture_start(True)
|
||||||
|
with open(log_csv, 'w') as csvfile:
|
||||||
|
logcsv = csv.writer(csvfile)
|
||||||
|
for token in c():
|
||||||
|
if token:
|
||||||
|
token.dump(logcsv, "csv") # write to CSV
|
||||||
|
if StopCapture:
|
||||||
|
break
|
||||||
|
StopCapture = False
|
||||||
|
sd.capture_stop()
|
||||||
|
|
||||||
class HexTextCtrl(wx.TextCtrl):
|
class HexTextCtrl(wx.TextCtrl):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(HexTextCtrl, self).__init__(*args, **kwargs)
|
super(HexTextCtrl, self).__init__(*args, **kwargs)
|
||||||
|
@ -52,6 +68,12 @@ class HexTextCtrl(wx.TextCtrl):
|
||||||
self.ChangeValue(value)
|
self.ChangeValue(value)
|
||||||
self.SetSelection(*selection)
|
self.SetSelection(*selection)
|
||||||
|
|
||||||
|
class MyDialog(wx.Dialog):
|
||||||
|
def __init__(self, parent, title):
|
||||||
|
super(MyDialog, self).__init__(parent, title = title, size = (250,150))
|
||||||
|
panel = wx.Panel(self)
|
||||||
|
self.btn = wx.Button(panel, wx.ID_OK, label = "ok", size = (50,20), pos = (75,50))
|
||||||
|
|
||||||
class Frame(wx.Frame):
|
class Frame(wx.Frame):
|
||||||
def __init__(self, preferred = None):
|
def __init__(self, preferred = None):
|
||||||
|
|
||||||
|
@ -76,6 +98,12 @@ class Frame(wx.Frame):
|
||||||
r.Add(b, 1, wx.RIGHT)
|
r.Add(b, 1, wx.RIGHT)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def epair(a, b):
|
||||||
|
r = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
r.Add(a, 1, wx.LEFT)
|
||||||
|
r.Add(b, 1, wx.RIGHT)
|
||||||
|
return r
|
||||||
|
|
||||||
def label(s):
|
def label(s):
|
||||||
return wx.StaticText(self, label = s)
|
return wx.StaticText(self, label = s)
|
||||||
|
|
||||||
|
@ -149,6 +177,10 @@ class Frame(wx.Frame):
|
||||||
self.ckM = wx.ToggleButton(self, label = "Monitor mode")
|
self.ckM = wx.ToggleButton(self, label = "Monitor mode")
|
||||||
self.ckM.Bind(wx.EVT_TOGGLEBUTTON, self.check_m)
|
self.ckM.Bind(wx.EVT_TOGGLEBUTTON, self.check_m)
|
||||||
|
|
||||||
|
self.capture = False
|
||||||
|
self.ckC = wx.ToggleButton(self, label = "Capture mode")
|
||||||
|
self.ckC.Bind(wx.EVT_TOGGLEBUTTON, self.check_c)
|
||||||
|
|
||||||
self.txVal = HexTextCtrl(self, size=wx.DefaultSize, style=0)
|
self.txVal = HexTextCtrl(self, size=wx.DefaultSize, style=0)
|
||||||
|
|
||||||
self.rxVal = HexTextCtrl(self, size=wx.DefaultSize, style=wx.TE_READONLY)
|
self.rxVal = HexTextCtrl(self, size=wx.DefaultSize, style=wx.TE_READONLY)
|
||||||
|
@ -194,7 +226,7 @@ class Frame(wx.Frame):
|
||||||
label(""),
|
label(""),
|
||||||
hcenter(cb),
|
hcenter(cb),
|
||||||
label(""),
|
label(""),
|
||||||
hcenter(self.ckM),
|
hcenter(epair(self.ckM, self.ckC)),
|
||||||
hcenter(self.reset_button),
|
hcenter(self.reset_button),
|
||||||
label(""),
|
label(""),
|
||||||
hcenter(info),
|
hcenter(info),
|
||||||
|
@ -286,7 +318,7 @@ class Frame(wx.Frame):
|
||||||
self.refresh(None)
|
self.refresh(None)
|
||||||
|
|
||||||
def refresh(self, e):
|
def refresh(self, e):
|
||||||
if self.sd and not self.monitor:
|
if self.sd and not self.monitor and not self.capture:
|
||||||
lowhigh = ["LOW", "HIGH"]
|
lowhigh = ["LOW", "HIGH"]
|
||||||
self.sd.getstatus()
|
self.sd.getstatus()
|
||||||
self.label_serial.SetLabel(self.sd.serial)
|
self.label_serial.SetLabel(self.sd.serial)
|
||||||
|
@ -331,6 +363,32 @@ class Frame(wx.Frame):
|
||||||
if self.monitor:
|
if self.monitor:
|
||||||
[self.hot(i, False) for i in self.heat]
|
[self.hot(i, False) for i in self.heat]
|
||||||
|
|
||||||
|
def check_c(self, e):
|
||||||
|
global StopCapture
|
||||||
|
cm = e.EventObject.GetValue()
|
||||||
|
# self.sd.monitor(self.monitor)
|
||||||
|
if cm:
|
||||||
|
openFileDialog = wx.FileDialog(self, "CSV dump to file", "", "",
|
||||||
|
"CSV files (*.csv)|*.csv",
|
||||||
|
wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
|
||||||
|
openFileDialog.ShowModal()
|
||||||
|
self.log_csv = openFileDialog.GetPath()
|
||||||
|
openFileDialog.Destroy()
|
||||||
|
|
||||||
|
StopCapture = False
|
||||||
|
t = threading.Thread(target=capture_thr, args=(self.sd, self.log_csv))
|
||||||
|
t.setDaemon(True)
|
||||||
|
t.start()
|
||||||
|
else:
|
||||||
|
StopCapture = True
|
||||||
|
wx.MessageBox("Capture finished. Traffic written to " + self.log_csv, "Message" ,wx.OK | wx.ICON_INFORMATION)
|
||||||
|
while StopCapture:
|
||||||
|
pass
|
||||||
|
[d.Enable(not cm) for d in self.dynamic]
|
||||||
|
if cm:
|
||||||
|
[self.hot(i, False) for i in self.heat]
|
||||||
|
self.capture = cm
|
||||||
|
|
||||||
def set_speed(self, e):
|
def set_speed(self, e):
|
||||||
w = e.EventObject
|
w = e.EventObject
|
||||||
s = int(w.GetString(w.GetCurrentSelection()))
|
s = int(w.GetString(w.GetCurrentSelection()))
|
||||||
|
|
Loading…
Reference in New Issue