GithubHelp home page GithubHelp logo

pcars's Introduction

pcars

Build Status Coverage Status

INTRODUCTION

pcars is a Python client for the Project CARS UDP data stream.

Quickstart

from pcars.stream import PCarsStreamReceiver

class MyPCarsListener(object):
    def handlePacket(self, data):
        # You probably want to do something more exciting here
        # You probably also want to switch on data.packetType
        # See listings in packet.py for packet types and available fields for each
        print data


listener = MyPCarsListener()
stream = PCarsStreamReceiver()
stream.addListener(listener)
stream.start()

pcars's People

Contributors

jamesremuscat avatar

Stargazers

Grant Robertson avatar Ricardo Quintela avatar Dean Davis avatar Ferdinand Mütsch avatar João Maia avatar  avatar  avatar  avatar Ravin Sardal avatar Jaeoh Lee avatar Robert C Edwards avatar Bob Vork avatar  avatar Ján Hajnár avatar Ole-Martin Mørk avatar

Watchers

Emmanuel Jacyna avatar James Cloos avatar  avatar  avatar yoshiaki-n avatar Travis avatar Gavin Smith avatar GreenT avatar  avatar  avatar Ricardo Quintela avatar

pcars's Issues

pcars.py, lines 229 and 232 ...

... go

self._data["pitSchedule"] = PitSchedule((self._data["pitModeSchedule"] & 0xF0) << 4)

and

self._data["highestFlagReason"] = FlagReason((self._data["highestFlag"] & 0xF0) << 4)

Both shift operators need to be reversed (>> instead of <<).

Example PitSchedule:

Currently, after the AND, an 0001 0000 is shifted left, resulting in 1 0000 0000 = 256 decimal.
This produces an exception, because 256 is not a valid PitSchedule enum.

With >>, 0001 0000 becomes 0000 0001 and Python is happy :-).

Info

Hello,
I'm trying to figure out the operation of reading data between ProjectCars and UDP, I saw your library, and I wanted to ask you in what format the data is returned and in case you can recognize them (tires, engine speeds, etc)
Thank you

pcars.py, lines 27 and 30 ...

... go

convertedValue = unicode(stringAsBytes, encoding='utf-8', errors='ignore')

and

convertedValue = str(stringAsBytes, encoding='utf-8', errors='surrogateescape')

The encoding should be iso_8859_1 instead of utf-8, otherwise German umlauts, like in Nürburgring, are not displayed properly.

TypeError: handlePacket() takes exactly 1 argument (2 given)

Hi,

I am trying to run your API using the "Quickstart" code you provide (just so that i know everything is working) and I get the following error message:

_Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in _bootstrap_inner
self.run()
File "/Users/cwprice/Documents/Python/pcars-master/src/pcars/stream.py", line 35, in run
listener.handlePacket(packet)
TypeError: handlePacket() takes exactly 1 argument (2 given)

The above error is thrown instantly that PCars sends a UDP packet. I have tried running the API with both Python 2.7 and 3.6 but I still get the same error. Do you have any ideas as to what might be causing this?

Many thanks,

Chris.

Troubles when using setup.py

Hello there, I'm really new to Python and UDP messaging, so excuse me if I'm committing dumb mistakes. For starters, I'm running python via Visual Studio due to reasons to do with another project that I'm working on. When I run setup.py I find this:

error

Should I worry? If you allow me to make a few comments about the documentation, it would be nice to have a more comprehensive version of the docs, especially one that could guide the newbie user (like me) a little easier along the route of running this solution. I'm just getting started with Python (although I have experience with some other few languages) and it has been a bit of a struggle to get going with the environment so far. I'm using this because I want to code my DIY dash in a raspberry, but I need to get to know how the packets look like first.

Thank you.

does this "work" with pcars2?

Hi. Awesome code. However, im using it with pcars2 and everything works except once in a while, ill get an error:

ValueError: 256 is not a valid PitSchedule

ive tried to edit out the relivent parts of packet.py, but then i get even worse errors.

pcars.py, line 32 ...

... goes

return convertedValue.rstrip('\x00')

That is not sufficient.

When the field is updated with a shorter text, this text is just terminated with one x'00' byte (the 64 byte buffer is not filled-up again with zeroes), leaving the old content exposed, e.g. ('*' = x'00'):

old: "This is a very long text.************************* ..."
new: "This is short.*long text.************************* ..."

A print() would produce This is short.long text..

OSError on Windows, Socket operation was attempted to an unreachable host

I'm trying to use this module with Project Cars 2 to send the data over a socket connection to another PC, which acts as a HUD. My code is as follows:

from pcars.stream import PCarsStreamReceiver
import socket, pickle
from udp_stream import Stream

dest, port = "192.168.1.247", 8001
myip = "192.168.1.190"

class MyPCarsListener(object):
    def __init__(self, dest, port, myip):
        self.stream = Stream(dest, port, myip)
        self.stream.create_socket()
        self.stream.bind_socket()
        
    def handlePacket(self, data):
        data = pickle.dumps(data)

        self.stream.send(data)

listener = MyPCarsListener(dest, port, myip)
stream = PCarsStreamReceiver()
stream.addListener(listener)
stream.start()

The module udp_stream is just a way to get all the connection-related things out of the main code, and is as follows:

import socket, pickle

class Stream:
    def __init__(self, dest, port, myip="127.0.0.1"):
        self.destination = dest
        self.port = port
        self.myip = myip

        self.bound = False

        self.BUFFER = 1024

    def create_socket(self):
        self.socket = socket.socket(socket.AF_INET,
                                    socket.SOCK_DGRAM,
                                    )

    def bind_socket(self):
        self.bound = True
        self.socket.bind((self.myip, self.port))

    def send(self, data):
        self.socket.sendto(data,
                           (self.destination,
                            self.port,
                            )
                           )

    def recv(self):
        if self.bound:
            data = self.socket.recvfrom(self.BUFFER)
            return data
        else:
            return RuntimeError("Socket is unbound, cannot recieve data")

When I run the code, I get the following error:

Traceback (most recent call last):
  File "D:\Program Files\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "D:\Program Files\Python38-32\lib\site-packages\pcars\stream.py", line 29, in run
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
OSError: [WinError 10065] A socket operation was attempted to an unreachable host

Project Cars 2 is setup correctly, with the API set to Project Cars 1, and the UDP frequency as 1. How can I fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.