Skip to content

Commit

Permalink
- replace cp1252 control codes with spaces in yaml
Browse files Browse the repository at this point in the history
- add CarLeftRight enum
- updated vars.txt
  • Loading branch information
kutu committed Oct 2, 2017
1 parent 22776db commit e5ab738
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ dist
pyirsdk.egg-info
MANIFEST
*.pyc
*.bin
*.txt
test_*.py
19 changes: 15 additions & 4 deletions irsdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
except ImportError:
from yaml import Loader as YamlLoader

VERSION = '1.1.8'
VERSION = '1.1.9'

SIM_STATUS_URL = 'http://127.0.0.1:32034/get_sim_status?object=simStatus'

Expand All @@ -24,6 +24,9 @@

VAR_TYPE_MAP = ['c', '?', 'i', 'I', 'f', 'd']

YAML_TRANSLATER = bytes.maketrans(b'\x81\x8D\x8F\x90\x9D', b' ')
YAML_CODE_PAGE = 'cp1252'

class StatusField:
status_connected = 1

Expand Down Expand Up @@ -205,6 +208,14 @@ class PitSvFlags:
windshield_tearoff = 0x20
fast_repair = 0x40

class CarLeftRight:
clear = 1 # no cars around us.
car_left = 2 # there is a car to our left.
car_right = 3 # there is a car to our right.
car_left_right = 4 # there are cars on each side.
two_cars_left = 5 # there are two cars to our left.
two_cars_right = 6 # there are two cars to our right.

class FFBCommandMode: # You can call this any time
ffb_command_max_force = 0 # Set the maximum force when mapping steering torque force to direct input units (float in Nm)

Expand Down Expand Up @@ -356,7 +367,7 @@ def parse_to(self, to_file):
if not self.is_initialized:
return
f = open(to_file, 'w', encoding='utf-8')
f.write(self._shared_mem[self._header.session_info_offset:self._header.session_info_len].rstrip(b'\x00').decode('latin-1'))
f.write(self._shared_mem[self._header.session_info_offset:self._header.session_info_len].rstrip(b'\x00').decode(YAML_CODE_PAGE))
f.write('\n'.join([
'{:32}{}'.format(i, self[i])
for i in sorted(self._var_headers_dict.keys(), key=str.lower)
Expand Down Expand Up @@ -478,7 +489,7 @@ def _get_session_info(self, key):

# search section by key
self._shared_mem.seek(0)
start = self._shared_mem.find(('\n%s:\n' % key).encode('cp1252'), start, end)
start = self._shared_mem.find(('\n%s:\n' % key).encode(YAML_CODE_PAGE), start, end)
end = self._shared_mem.find(b'\n\n', start, end)
data_binary = self._shared_mem[start:end]

Expand All @@ -497,7 +508,7 @@ def _get_session_info(self, key):
sesData['data_binary'] = data_binary

# parsing
yaml_src = re.sub(YamlReader.NON_PRINTABLE, '', data_binary.rstrip(b'\x00').decode('cp1252'))
yaml_src = re.sub(YamlReader.NON_PRINTABLE, '', data_binary.translate(YAML_TRANSLATER).rstrip(b'\x00').decode(YAML_CODE_PAGE))
if key == 'DriverInfo':
def team_name_replace(m):
return 'TeamName: "%s"' % re.sub(r'(["\\])', '\\\\\\1', m.group(1))
Expand Down
1 change: 1 addition & 0 deletions vars.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CarIdxRPM Engine rpm by car index, revs/min
CarIdxSteer Steering wheel angle by car index, rad
CarIdxTrackSurface Track surface type by car index, irsdk_TrkLoc
CarIdxTrackSurfaceMaterial Track surface material type by car index, irsdk_TrkSurf
CarLeftRight Notify if car is to the left or right of driver, irsdk_CarLeftRight
Clutch 0=disengaged to 1=fully engaged, %
CpuUsageBG Percent of available tim bg thread took with a 1 sec avg, %
DCDriversSoFar Number of team drivers who have run a stint,
Expand Down

0 comments on commit e5ab738

Please sign in to comment.