Skip to content

Commit

Permalink
Decode and display basic datalog packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Barnes committed Sep 4, 2009
1 parent c8335c6 commit 721dc65
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 47 deletions.
1 change: 1 addition & 0 deletions comms/protocols/IFreeEMS_Vanilla/v0_0_1/__init__.py
Expand Up @@ -81,6 +81,7 @@
REQUEST_HARD_SYSTEM_RESET: "HardReset",
REQUEST_ASYNC_ERROR_CODE: "AsyncError",
REQUEST_ASYNC_DEBUG_INFO: "AsyncDebug",
REQUEST_BASIC_DATALOG: "BasicDatalog",
# REQUEST_ASYNC_DATALOG_STATUS: "AsyncDatalogStatus",
}

Expand Down
10 changes: 7 additions & 3 deletions comms/protocols/IFreeEMS_Vanilla/v0_0_1/requests.py
Expand Up @@ -66,12 +66,16 @@ def __init__(self):
self.setPayload(string)


# Async Logging Status
class requestAsyncDatalogStatus(request):
class requestBasicDatalog(request):
'''
Basic datalog toggle packet
Toggles datalogging depending on payload
'''

def __init__(self):
request.__init__(self)
self.setPayloadId(protocol.REQUEST_ASYNC_DATALOG_STATUS)
self.setPayloadId(protocol.REQUEST_BASIC_DATALOG)


def stop(self):
Expand Down
16 changes: 16 additions & 0 deletions comms/protocols/IFreeEMS_Vanilla/v0_0_1/responses.py
Expand Up @@ -18,6 +18,7 @@
# We ask that if you make any changes to this file you send them upstream to us at admin@diyefi.org

import comms.protocols as protocols, packet, __init__ as protocol
import random


def getPacket(id):
Expand Down Expand Up @@ -201,3 +202,18 @@ def __init__(self):
response.__init__(self)
rules = self._validation_rules
rules['requires_length'] = True


def createTestResponse(self, request):
'''
Create an accurate example response for testing
'''
self.setPayloadId(protocol.RESPONSE_BASIC_DATALOG)

# Generate 2 random shorts for each of the 27 variables
binary = ''
while len(binary) < (27 * 4):
binary += protocols.shortTo8bit(random.randint(0,65535))
binary += protocols.shortTo8bit(random.randint(0,65535))

self.setPayload(binary)
149 changes: 107 additions & 42 deletions gui/realtimeDataInterface.py
Expand Up @@ -18,7 +18,7 @@
# We ask that if you make any changes to this file you send them upstream to us at admin@diyefi.org


import comms, gui, commsConnectWarning
import comms, comms.protocols as protocols, gui, commsConnectWarning

import wx

Expand All @@ -30,36 +30,36 @@ class realtimeDataInterface(wx.BoxSizer):

ID_LOGGING_TOGGLE = wx.NewId()

hum_label = ['Inlet Air Temperature',
'Coolant/Head Temperature',
'Throttle Position',
'Exhaust Gas Oxygen 1',
'Manifold Absolute Pressure',
'Atmospheric Absolute Pressure',
'Battery Reference Voltage',
'Manifold Air Temperature',
'Exhaust Gas Oxygen 2',
'Intercooler Absolute Pressure',
'Mass Air Flow',
'Delta MAP',
'Delta TPS',
'Revolutions Per Minute',
'Delta RPM',
'Delta Delta RPM',
'Load Main',
'Volumetric Efficiency Main',
'Lamda',
'Air Flow',
'Density And Fuel',
'Base Pulse Width',
'Injector Dead Time',
'Engine Temperature Enrichment',
'Transient Fuel Correction Total',
'Final Pulse Width',
'Reference Pulse Width'
]
_vars = ['Inlet Air Temperature',
'Coolant/Head Temperature',
'Throttle Position',
'Exhaust Gas Oxygen 1',
'Manifold Absolute Pressure',
'Atmospheric Absolute Pressure',
'Battery Reference Voltage',
'Manifold Air Temperature',
'Exhaust Gas Oxygen 2',
'Intercooler Absolute Pressure',
'Mass Air Flow',
'Delta MAP',
'Delta TPS',
'Revolutions Per Minute',
'Delta RPM',
'Delta Delta RPM',
'Load Main',
'Volumetric Efficiency Main',
'Lamda',
'Air Flow',
'Density And Fuel',
'Base Pulse Width',
'Injector Dead Time',
'Engine Temperature Enrichment',
'Transient Fuel Correction Total',
'Final Pulse Width',
'Reference Pulse Width'
]

abrv_label = ['IAT', 'CHT', 'TPS',
_vars_abrv = ['IAT', 'CHT', 'TPS',
'EGO1', 'MAP', 'AAP',
'BRV', 'MAT', 'EGO2',
'IAP', 'MAF', 'DMAP',
Expand All @@ -70,14 +70,21 @@ class realtimeDataInterface(wx.BoxSizer):
'TFCTotal', 'FinalPW','RefPW'
]

realtime_data = [0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0]
# Latest data from datalog
_vars_data = [0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0]

# TextCtrl objects for each variable data display
_vars_display = []


def __init__(self, parent):
'''Setup UI elements'''
'''
Setup UI elements
'''

wx.BoxSizer.__init__(self, wx.VERTICAL)
self._controller = parent.controller
Expand All @@ -95,7 +102,6 @@ def __init__(self, parent):

self.toggle.Bind(wx.EVT_BUTTON, self.toggleLogging, id=self.ID_LOGGING_TOGGLE)


# Locating elements
sizer6 = wx.BoxSizer(wx.HORIZONTAL)
sizer6.Add(self.logging_type, 10, wx.EXPAND)
Expand All @@ -108,21 +114,26 @@ def __init__(self, parent):

sizer4 = wx.BoxSizer(wx.VERTICAL)
sizer4.Add(blank, 1)
for data in self.realtime_data:
text = wx.StaticText(parent, -1, str(data), style = wx.ALIGN_RIGHT)

# Generate TextCtrls to display variable values
for data in self._vars_data:
text = wx.TextCtrl(parent, -1, str(data), style = wx.ALIGN_RIGHT | wx.NO_BORDER)
sizer4.Add(text, 40, wx.EXPAND)
sizer4.Add(blank, 1)

# Save references to controls in list
self._vars_display.append(text)

sizer3 = wx.BoxSizer(wx.VERTICAL)
sizer3.Add(blank, 1)
for label in self.abrv_label:
for label in self._vars_abrv:
text = wx.StaticText(parent, -1, label, style = wx.ALIGN_RIGHT)
sizer3.Add(text, 40, wx.EXPAND)
sizer3.Add(blank, 1)

sizer2 = wx.BoxSizer(wx.VERTICAL)
sizer2.Add(blank, 1)
for label in self.hum_label:
for label in self._vars:
text = wx.StaticText(parent, -1, label, style = wx.ALIGN_LEFT)
sizer2.Add(text, 40, wx.EXPAND)
sizer2.Add(blank, 1)
Expand Down Expand Up @@ -152,8 +163,62 @@ def toggleLogging(self, event):
return

protocol = comms.getConnection().getProtocol()
packet = protocol.getRequestPacket('AsyncDatalogStatus')
packet = protocol.getRequestPacket('BasicDatalog')
packet.startBasic()

data = {'packet': packet}
self._controller.action('comms.sendRequest', data)


def updateData(self, packet):
'''
Update with data var with latest data from datalog
Loops through packet payload decoding the variables, updates
the self._data list, and then calls refreshDisplay()
Packet parameter is the basicDatalog packet received.
'''
# Data store
data = self._vars_data

# Basic datalog packet payloads consist of 4 bytes of data for each of the 27 variables logged
# These 4 bytes contain two ints, and we shall average the two for display
# Loop through playload 4 bytes at a time
payload = packet.getPayload()
payload_length = len(payload)

i = 0
while i < 27:
# Get to the right part of the string
start = i * 4

# Get the 2 values (converted to ints) and average them
a = protocols.shortFrom8bit(payload[start:start+2])
b = protocols.shortFrom8bit(payload[start+2:start+4])
value = (a + b) / 2

# Update display
data[i] = value

# Next var
i += 1

self.refreshDisplay()


def refreshDisplay(self):
'''
Refresh realtime data display
This function simply loops through the self._data list, and updates
the gui display for each variable with the latest data.
This currently does not support unsigned and signed ints, like it should
'''
display = self._vars_display

i = 0
for value in self._vars_data:
display[i].SetValue(str(value))
i += 1
32 changes: 31 additions & 1 deletion gui/tab/realtimeData.py
Expand Up @@ -20,7 +20,7 @@

import wx

import gui.realtimeDataInterface
import comms, gui.realtimeDataInterface


# Helper value for inserting spacing into sizers
Expand All @@ -32,6 +32,9 @@ class tab(wx.Panel):
Real-time data stream display tab
'''

# Protocol object cache
_protocol = None

def __init__(self, parent):
'''
Setup interface elements
Expand All @@ -44,3 +47,30 @@ def __init__(self, parent):
self.SetSizer(self.interface)
self.Layout()

self._setupComms()


def _setupComms(self):
'''
Bind watcher method to comms
'''
# Bind to connection
self.conn = comms.getConnection()
self.conn.bindReceiveWatcher(self)

# Bind to events
self.Bind(comms.interface.EVT_RECEIVE, self.monitorPackets)


def monitorPackets(self, event):
'''
Check for received datalogs
'''
if not self._protocol:
self._protocol = self.conn.getProtocol()

# Check
if isinstance(event.packet, self._protocol.responses.responseBasicDatalog):
self.interface.updateData(event.packet)


2 changes: 1 addition & 1 deletion version.py
Expand Up @@ -19,6 +19,6 @@


# FreeEMS-Tuner
__revision__ = 'r20090902232653'
__revision__ = 'r20090904213906'
__name__ = 'FreeEMS-Tuner'
__title__ = '%s %s' % (__name__, __revision__)

0 comments on commit 721dc65

Please sign in to comment.