Kart Racing Pro Official Forum

General => General Discussion => Documentation => Topic started by: PiBoSo on October 08, 2012, 10:27:43 PM

Title: Live Timing
Post by: PiBoSo on October 08, 2012, 10:27:43 PM
It is possible to connect to a dedicated server or challenge server to receive live race data.
The feature is off by default and must be enabled:
http://forum.kartracing-pro.com/index.php?topic=8.0
http://forum.kartracing-pro.com/index.php?topic=3609.0
Only 1 client can connect to the server.

Communication is made with UDP sockets and strings terminated with "\n".

Send "CONNECT" followed by the connection password ( empty string if no password ).
Reply:
OK -> connected
FULL -> another client is already connected
WRONGPASSWORD -> wrong password

Send "START", followed by two parameter strings to start receiving data.
First parameter: either "0" or "1". If set to "1", the track centerline and the track position of the karts are sent, too.
Second parameters: either "0", "1" or "2". If set to "1", the contacts between karts are sent. IF set to "2", contacts between karts and walls are sent, too.

Data format is "MSG" followed by the message ID and then a stream of strings.
Send "ACK" followed by the message ID after each MSG.

Send "KEEPALIVE" every 15 seconds to keep the connection active.
The server sends "ALIVE" to report that the connection is active.

Send "DISCONNECT" to correctly close the connection.

Example source code can be downloaded at this link: http://www.kartracing-pro.com/downloads/livetiming.c


Messages data format

EVENT
Type
- TESTINGDAY
- RACE
Name
Track
Track Length ( meters )
Allowed Categories and Karts
Empty string

Challenge server only:
EVENT
Type
- CHALLENGE
Name
Track
Track Length ( meters )
Allowed Categories and Karts
Challenge Type
- PRACTICE
- RACE
Challenge Length ( minutes if practice, laps if race )
Challenge Max Tries
Empty string

ENTRY
Race Number
Name
Kart Name
Kart Short Name
Categories
GUID
Extra
Empty string

ENTRYREMOVE
Race Number
Empty string

Testing Day:
SESSION
Session
- WAITING
- TESTINGDAY
State
Length
Empty string

Race:
SESSION
Session
- WAITING
- PRACTICE
- QUALIFY
- WARMUP
- QUALIFYHEAT
- SECONDCHANCEHEAT
- PREFINAL
- FINAL
State
if session = practice ( PRACTICE, QUALIFY, WARMUP )
- INPROGRESS
- COMPLETE
else if session = race ( QUALIFYHEAT, SECONDCHANCEHEAT, PREFINAL, FINAL )
- WARMUPLAP
- PRESTART
- ROLLINGSTART
- STARTSEQUENCE
- INPROGRESS
- RACEOVER
- COMPLETE
endif
Length ( minutes if practice, laps if race )
Empty string

SESSIONSTATUS
Session
- WAITING
- PRACTICE
- QUALIFY
- WARMUP
- QUALIFYHEAT
- SECONDCHANCEHEAT
- PREFINAL
- FINAL
State
if session = practice ( PRACTICE, QUALIFY, WARMUP )
- INPROGRESS
- COMPLETE
else if session = race ( QUALIFYHEAT, SECONDCHANCEHEAT, PREFINAL, FINAL )
- WARMUPLAP
- PRESTART
- ROLLINGSTART
- STARTSEQUENCE
- INPROGRESS
- RACEOVER
- COMPLETE
endif
Empty string

Always sent after SESSION:
WEATHER
Conditions
- CLEAR
- CLOUDY
- RAINY
Air Temperature
Track Temperature
Empty string

SESSIONENTRY
Race Number
Empty string

DRIVERSTATUS
Race Number
State
- DNS
- RET
- DSQ
if state = DSQ
Reason
- JUMPSTART
- TOOMANYOFFENCES
- ROLLINGSTARTSPEEDING
- ROLLINGSTARTTOOSLOW
- ROLLINGSTARTCORRIDOR
- ROLLINGSTARTOVERTAKE
- DIRECTOR
endif
Empty string

BESTLAP
Race Number
Session Time ( milliseconds )
Lap Time ( milliseconds )
Lap Number
Split 1 ( milliseconds )
Split 2 ( milliseconds )
Speed Trap ( meters/s )
Empty string

LASTLAP
Race Number
Session Time ( milliseconds )
Lap Time ( milliseconds )
Lap Number
Split 1 ( milliseconds )
Split 2 ( milliseconds )
Speed Trap ( meters/s )
Empty string

PENALTY
Race Number
Penalty Number
Type
- TIME
- POS
if type = TIME
Penalty Time ( seconds )
else
Counter
endelse
Offence
- JUMPSTART
- CUTTING
- ROLLINGSTARTSPEEDING
- ROLLINGSTARTTOOSLOW
- ROLLINGSTARTCORRIDOR
- ROLLINGSTARTOVERTAKING
Empty string

LAP
Race Number
Lap Invalid
Session Time ( milliseconds )
Lap Time ( milliseconds )
Split 1 ( milliseconds )
Split 2 ( milliseconds )
Speed Trap ( meters/s )
Empty string

SPLIT
Race Number
Split Number
Split Time ( milliseconds )
Empty string

SPEED
Race Number
Speed Trap ( meters/s )
Empty string

CLASSIFICATION
Session
Status
Session Timer ( milliseconds )
Session Length ( minutes )
Session Lap
Number of Laps
for each entry:
Race Number
if the session is practice ( practice, qualify, warmup )
Best Lap ( milliseconds )
if best lap not zero
Lap Number
Total Laps
Gap ( milliseconds, -- if zero )
Speed ( meters/s )
endif
else
Race Time ( milliseconds ) or Status
- DNS
- DSQ
if Race Time not zero
Lap Number
Gap ( milliseconds or L if lapped )
endif
endelse
Kart Status
- TRK: on track
- PIT: in the pits
endfor
Empty string after the last entry

Challenge server only:
CHALLENGEDATA
Name
Kart Name
Kart Short Name
GUID
Extra
Try Number
if challenge practice:
Best Lap ( milliseconds )
Lap Number
Total Laps
endif
Empty string

TRACKDATA
Start / Finish Longitudinal Position
Split 1 Longitudinal Position
Split 2 Longitudinal Position
Speed Trap Longitudinal Position
Number of Segments
Empty string

TRACKSEGMENT
Segment Number
Type ( 0 = straight, 1 = curve )
Length ( meters )
Radius ( meters )
Angle ( degrees )
Start Position X ( meters )
Start Position z ( meters )
Height ( meters )
Empty string

TRACKPOSITION
for each entry on track:
Race Number
Position X ( meters )
Position Y ( meters )
Position Z ( meters )
endfor
Empty string after the last entry

CONTACT
Time ( milliseconds )
Race Number 1 ( -1 if wall )
Race Number 2 ( -1 if wall )
Relative Velocity ( meters/s )
Empty string

END
Empty string
Title: Re: Live Timing
Post by: NOP on October 09, 2012, 02:04:35 PM
I have some problems.
After connecting to server i get
"MSG 0 SESSION WAITING" (newlines removed)
i send ack and server goes silent (not counting "ALIVE" messages)
after connecting to server i'm getting
"MSG 1 SESSION QUALIFY INPROGRESS WEATHER CLEAR 0.0 0.0 ENTRY 4 NOP. B F100 B F100"
each time after that i send (i think i didn't cock this up) "ACK\n" and "1\n" (ID + '\n').
But server keeps sending same "MSG 1..." even if another client joins session (and this message is constantly repeated).
\
Nevermind my bad.
Title: Re: Live Timing
Post by: PiBoSo on October 09, 2012, 02:35:21 PM
Quote from: NOP on October 09, 2012, 02:04:35 PM
I have some problems.
After connecting to server i get
"MSG 0 SESSION WAITING" (newlines removed)
i send ack and server goes silent (not counting "ALIVE" messages)
after connecting to server i'm getting
"MSG 1 SESSION QUALIFY INPROGRESS WEATHER CLEAR 0.0 0.0 ENTRY 4 NOP. B F100 B F100"
each time after that i send (i think i didn't cock this up) "ACK\n" and "1\n" (ID + '\n').
But server keeps sending same "MSG 1..." even if another client joins session (and this message is constantly repeated).
\
Nevermind my bad.

Good to know you solved the problem.
Title: Re: Live Timing
Post by: NOP on October 09, 2012, 03:26:55 PM
Quote from: PiBoSo on October 09, 2012, 02:35:21 PM
...
Good to know you solved the problem.
Now i feel compelled to explain.
What i think i did was send one message "ACK\n" and then next message ID + '\n'. Proper way was to send one message "ACK\n" + ID + '\n'. And it seems to work.

For people wondering what is Live Timing, it's some very basic data about karts times in splits and on start meta line. There is also some info about track and session.
Maybe it will find some use in leagues to present players more statistics (like consistency of drivers), or give server admins a bit more knowledge about what is going on in server. Or maybe i just don't get it  :P.
Title: Re: Live Timing
Post by: PiBoSo on October 09, 2012, 04:03:42 PM
Quote from: NOP on October 09, 2012, 03:26:55 PM
For people wondering what is Live Timing, it's some very basic data about karts times in splits and on start meta line. There is also some info about track and session.
Maybe it will find some use in leagues to present players more statistics (like consistency of drivers), or give server admins a bit more knowledge about what is going on in server. Or maybe i just don't get it  :P.

The idea is to give the possibility to stream race data to a web page or to an application ( like many real-life live timing services ).
It was kept simple to be as flexible as possible.
Title: Re: Live Timing
Post by: dibu on October 09, 2012, 05:43:42 PM
NOP will you code something for public use?  Maybe it's also worth to have a look at GameQ ( http://gameq.sourceforge.net/ ). Possibly a profile for KRP can be added.

This morning I also played around with the live timing but very basicly. I mainly used Netcat (nc.exe) for testing.
Title: Re: Live Timing
Post by: NOP on October 09, 2012, 06:17:39 PM
Well i was doing app but i don't know how much sense is in doing something that will be visible only to one person. I guess i can slap some GUI and add data logging but i don't see big point to be honest.
Title: Re: Live Timing
Post by: dibu on October 09, 2012, 07:35:25 PM
You are right, but you know if there is a new toy we have to play with it until it gets boring  ;)
I just thought maybe you have already a quick and dirty tool for testing. Everything is better than nc.exe and a hexeditor  ;D

Title: Re: Live Timing
Post by: Aritz on October 09, 2012, 07:55:13 PM
It will be interesting to have some kind of races/championships administration plugin for websites:

http://www.liveforspeed.es/modules.php?nombre_carrera=Vuelta al cole 6.0&op=modload&name=liga&file=consulta_carrera (http://www.liveforspeed.es/modules.php?nombre_carrera=Vuelta al cole 6.0&op=modload&name=liga&file=consulta_carrera)
Title: Re: Live Timing
Post by: NOP on October 09, 2012, 08:13:16 PM
I'am completely green if it comes to writing websites... but it would be neat thing too learn.
For now dibu if you want i will wrap my program with some user interface to make it a bit easier to use and maybe you will find it useful.
Title: Re: Live Timing
Post by: dibu on October 09, 2012, 08:17:06 PM
Same for me with the websites  ::)
If it's not too much work, I would be happy to get your program  :)
Title: Re: Live Timing
Post by: PiBoSo on October 09, 2012, 08:18:11 PM
Quote from: Aritz on October 09, 2012, 07:55:13 PM
It will be interesting to have some kind of races/championships administration plugin for websites:

http://www.liveforspeed.es/modules.php?nombre_carrera=Vuelta al cole 6.0&op=modload&name=liga&file=consulta_carrera (http://www.liveforspeed.es/modules.php?nombre_carrera=Vuelta al cole 6.0&op=modload&name=liga&file=consulta_carrera)

What technology is used for that website?
Title: Re: Live Timing
Post by: NOP on October 09, 2012, 09:51:37 PM
Ok simple Live Timing logger
http://www.sendspace.pl/file/6b436eaacde80195c061e9d

Before starting server add configuration
[live]
enable = 1; 1 to enable live timing
port = 10660; the UDP port
password = admin

Start server, start logger if you didnt change anything click "connect" button.
Connection state should change to "OK". If it says "FULL" close program and try again after more than 15 seconds.

Messages from server will appear "Server data" label.
All messages are logged into text file. Slight difference is that rather than saving newlines '\n' I'm changing them to '|' sign. It keeps log file a bit more redable and still allows for easy parsing (file is open for writing and immediately closed).

If i didn't cocked something there will be also displayed times of sectors.
Title: Re: Live Timing
Post by: Aritz on October 09, 2012, 10:01:02 PM
Quote from: PiBoSo on October 09, 2012, 08:18:11 PM
Quote from: Aritz on October 09, 2012, 07:55:13 PM
It will be interesting to have some kind of races/championships administration plugin for websites:

http://www.liveforspeed.es/modules.php?nombre_carrera=Vuelta al cole 6.0&op=modload&name=liga&file=consulta_carrera (http://www.liveforspeed.es/modules.php?nombre_carrera=Vuelta al cole 6.0&op=modload&name=liga&file=consulta_carrera)

What technology is used for that website?

-Waiting for an answer-
Title: Re: Live Timing
Post by: dibu on October 10, 2012, 07:49:51 AM
Thank you NOP  :)
I just did a quick test and it works. In the log all MSG are properly ACKed. The splits and the laptime shows up. I'll do some more testing in the evening.
Title: Re: Live Timing
Post by: Pudlea on January 02, 2013, 08:45:00 AM
Hi NOP,

Would be interested in getting this running on our website.  Any chance for the file to be re-loaded with some detailed instructions.
Title: Re: Live Timing
Post by: Alibaskins on May 11, 2014, 06:02:51 PM
Hi,

QuoteSend "CONNECT" followed by the connection password ( empty string if no password ).

Is it possible to disconnect from a server ? correctly ?
Title: Re: Live Timing
Post by: PiBoSo on May 11, 2014, 07:03:54 PM
Quote from: Alibaskins on May 11, 2014, 06:02:51 PM
Hi,

QuoteSend "CONNECT" followed by the connection password ( empty string if no password ).

Is it possible to disconnect from a server ? correctly ?

First post updated to add the disconnection message.
Title: Re: Live Timing
Post by: Alibaskins on May 11, 2014, 07:12:24 PM
Ok thank you  Piboso.

I wasn't sure :)

Since there is no return from the server, i thought it did not work.
Title: Re: Live Timing
Post by: Alibaskins on May 23, 2014, 06:44:15 PM
In a future version, it will be possible to you to add the category of the vehicle in the answer from server ?
Title: Re: Live Timing
Post by: PiBoSo on December 29, 2019, 02:25:21 AM

First post updated to add a parameter to the "START" message, that allows to receive the track centerline and bikes' track position, too.
Title: Re: Live Timing
Post by: PiBoSo on July 10, 2020, 04:14:51 PM
First post updated to add a link to example source code.
Title: Re: Live Timing
Post by: PiBoSo on September 09, 2020, 11:36:03 PM
First post updated to add the messages data format.
Title: Re: Live Timing
Post by: Alessandro Ceronetti on September 30, 2020, 03:02:51 PM
I have read messages on all f this, and I still have not figured out what program I need to use to view the live timing data. Any help?
Title: Re: Live Timing
Post by: PiBoSo on January 12, 2021, 11:27:42 PM
First post updated with the latest messages data format and to add an extra setting to the "START" parameter, that allows to receive contacts.
Title: Re: Live Timing
Post by: PiBoSo on June 09, 2021, 03:12:30 PM
First post updated with the latest protocol, that adds a second parameter for the "START" message.