Skip to content

Commit

Permalink
Adding status information, fix line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
Billiam committed Jul 2, 2015
1 parent 1f06773 commit da0910b
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 137 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build/*
dist/*
gauge.spec
build/*
dist/*
gauge.spec
48 changes: 24 additions & 24 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
The MIT License (MIT)
=====================

Copyright © `2015` `Colin Fein`

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
The MIT License (MIT)
=====================

Copyright © `2015` `Colin Fein`

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
22 changes: 11 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
set -e

cd `dirname $0`

rm gauge.zip
rm -r dist/*
pyinstaller --onefile gauge.py
cp config.yml dist
cp LICENSE.md dist/LICENSE.txt
7z a -tzip dist/gauge.zip ./dist/* -mx0
#!/usr/bin/env bash
set -e

cd `dirname $0`

rm gauge.zip
rm -r dist/*
pyinstaller --onefile gauge.py
cp config.yml dist
cp LICENSE.md dist/LICENSE.txt
7z a -tzip dist/gauge.zip ./dist/* -mx0
6 changes: 3 additions & 3 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
arduino_port: COM3
telemetry_server:
host: 127.0.0.1
arduino_port: COM3
telemetry_server:
host: 127.0.0.1
port: 20777
188 changes: 95 additions & 93 deletions gauge.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,95 @@
import socket
import struct
import asyncore
import serial
import yaml
import os.path
import sys
class Sender:
def __init__(self, serial_name):
self.ser = serial.Serial(
serial_name,
115200,
writeTimeout=0,
timeout=0,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE
)

def send(self, data):
self.ser.write(struct.pack('>cHHchcB', 'R', data['rpm'], data['max_rpm'], 'S', data['speed'], 'G', data['gear']))

class Receiver(asyncore.dispatcher):
def __init__(self, address, sender):
asyncore.dispatcher.__init__(self)
self.sender = sender

self.address = address
self.reconnect()

def reconnect(self):
self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)
self.bind(self.address)

def writable(self):
return False

def handle_accept(self):
print 'accepted'

def handle_connect(self):
print 'connected!'

def handle_expt(self):
print 'exception occurred!'
self.close()

def readable(self):
return True

def handle_close(self):
print 'closing connection'
self.close()

def handle_read(self):
data = self.recv(512)

if not data:
return

self.parse(data)

def parse(self, data):
# Unpack the data.
stats = struct.unpack('64f', data[0:256])

gear = stats[33]
rpm = stats[37] * 10
max_rpm = stats[63] * 10

data = {
'speed': int(stats[7] * 3.6 * 0.625), # mph (remove '* 0.625' for kph)
'gear': int(stats[33]),
'rpm': int(stats[37] * 10),
'max_rpm': int(stats[63] * 10)
}
self.sender.send(data)


if __name__ == '__main__':
if getattr(sys, 'frozen', None):
approot = os.path.dirname(sys.executable)
else:
approot = os.path.dirname(os.path.realpath(__file_))

try:
config = yaml.load(file(approot + '/config.yml', 'r'))
except yaml.YAMLError, exc:
print "Error in configuration file:", exc

arduino = Sender(config['arduino_port'])
server = (config['telemetry_server']['host'], config['telemetry_server']['port'])
game = Receiver(server, arduino)
asyncore.loop()
import socket
import struct
import asyncore
import serial
import yaml
import os.path
import sys
class Sender:
def __init__(self, serial_name):
try:
self.ser = serial.Serial(
serial_name,
115200,
writeTimeout=0,
timeout=0,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE
)
except serial.serialutil.SerialException, exc:
sys.exit("Could not connect to serial port: %s" % serial_name)

print "Connected to serial port: %s" % serial_name

def send(self, data):
self.ser.write(struct.pack('>cHHchcB', 'R', data['rpm'], data['max_rpm'], 'S', data['speed'], 'G', data['gear']))

class Receiver(asyncore.dispatcher):
def __init__(self, address, sender):
asyncore.dispatcher.__init__(self)
self.sender = sender

self.address = address
self.reconnect()

def reconnect(self):
self.received_data = False

self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)
self.bind(self.address)
print "Waiting for data on %s:%s" % self.address

def writable(self):
return False

def handle_expt(self):
print 'exception occurred!'
self.close()

def readable(self):
return True

def handle_read(self):
data = self.recv(512)

if not data:
return

if not self.received_data:
self.received_data = True
print "Receiving data on %s:%s" % self.address

self.parse(data)

def parse(self, data):
# Unpack the data.
stats = struct.unpack('64f', data[0:256])

gear = stats[33]
rpm = stats[37] * 10
max_rpm = stats[63] * 10

data = {
'speed': int(stats[7] * 3.6 * 0.625), # mph (remove '* 0.625' for kph)
'gear': int(stats[33]),
'rpm': int(stats[37] * 10),
'max_rpm': int(stats[63] * 10)
}
self.sender.send(data)


if __name__ == '__main__':
if getattr(sys, 'frozen', None):
approot = os.path.dirname(sys.executable)
else:
approot = os.path.dirname(os.path.realpath(__file__))

try:
config = yaml.load(file(approot + '/config.yml', 'r'))
except yaml.YAMLError, exc:
print "Error in configuration file:", exc

arduino = Sender(config['arduino_port'])
server = (config['telemetry_server']['host'], config['telemetry_server']['port'])
game = Receiver(server, arduino)
asyncore.loop()
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pyserial==2.7
PyYAML==3.11
pyinstaller==2.1
pyserial==2.7
PyYAML==3.11
pyinstaller==2.1

0 comments on commit da0910b

Please sign in to comment.