The online racing simulator
Searching in All forums
(921 results)
DarkTimes
S2 licensed
Vettel is pissed.
DarkTimes
S2 licensed
Schumi under investigation, quite rightly.
DarkTimes
S2 licensed
Yay for Rubens!
DarkTimes
S2 licensed
Quote from Töki (HUN) :Rosberg's wheel caused injuries for a Williams mechanic who was taken to hospital.

He went for a checkover at the medical centre, he has a few bruises but is otherwise fine.
DarkTimes
S2 licensed
"The most important part of a racing car is the nut that holds the wheel" - Unknown (attributed to Martin Brundle)

"Maximum attack!" - Mika Häkkinen.
Last edited by DarkTimes, .
DarkTimes
S2 licensed
I will release a version with encoding support tomorrow. While adding encoding support isn't hard in itself, it's difficult to explain how to do it in a forum post.
DarkTimes
S2 licensed
Yes, Spark does not understand about different encodings, so this is an issue with the library. I was thinking about releasing a stand-alone LFS string library, which is why Spark does not include any encoding support, but while this was a good idea, I haven't been able to find the energy to finish it. This means I will need to add encoding to Spark, but I'm not sure when that will be.
Last edited by DarkTimes, .
DarkTimes
S2 licensed
Has anyone tried the BBC JavaScript library? It looks pretty nice, especially the widgets that come with it. Not sure it has enough going to replace jQuery however, but it does look interesting.
Last edited by DarkTimes, .
DarkTimes
S2 licensed
Quote from GreyBull [CHA] :Nah, the marshalls would have a look at Free Practice times I guess... Like how it was done at Spa 2001 for instance. 4 cars were out of the 107% due to heavy rain, but they were allowed to race on Sunday.

Yeah, I guess I'm thinking too logically, they would have to look at the whole weekend and make a judgement.
DarkTimes
S2 licensed
Quote from Mustafur :107% rule should apply to the fastest time of Qualiy not from Q1 in my opinion, or maybe the rule is under that???

Yeah, I agree in general, but Greybull made a good point about track conditions. What if it was raining in Q1 but dry in Q3? Seven or even fourteen cars could be out the race before it started.
Last edited by DarkTimes, .
DarkTimes
S2 licensed
Well my dodgy arithmetic says was still outside the 107% marker for Q1 and so was Senna. di Grassi would be in though.
DarkTimes
S2 licensed
Does anyone have the qualifying times from Q1?

I couldn't make my google search sufficiently vague enough to find them.
DarkTimes
S2 licensed
Correct me if my arithmetic is failing me, but that looks like Yamamoto is only within 109% of the pole time. From next year he wouldn't even be allowed to race. I think slow backmarkers could play a role into tomorrows win.
DarkTimes
S2 licensed
OK - I've figured this out. All the JSON stuff from LFSWorld is returned as a list, even if there is only a single entry, so instead of deserializing a type of PlayerStats, you need to deserialize a type of List<PlayerStats>. So basically the code above gets changed to this:

public PlayerStats GetPlayerStats(string identKey, string racer)
{
var uri = new Uri(string.Format(@"http://www.lfsworld.net/pubstat/get_stat2.php?version=1.4&idk={0}&action=pst&racer={1}&s=1", identKey, racer));
var request = WebRequest.Create(uri);
var response = request.GetResponse();

using (var stream = response.GetResponseStream())
{
var json = new DataContractJsonSerializer(typeof(List<PlayerStats>));

var stats = (List<PlayerStats>)json.ReadObject(stream);

return stats.Single();
}
}

The code converts a pubstat response to a .NET object perfectly.
Last edited by DarkTimes, .
DarkTimes
S2 licensed
I don't have a VB version, but here is a simple C# example of how to receive OutGauge packets.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace OutGauge
{
class Program
{
const int BufferSize = 1024;
const string Host = "127.0.0.1";
const ushort Port = 30000;

static void Main()
{
// Create UDP socket.
Socket socket = new Socket(
AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp);
byte[] buffer = new byte[BufferSize];

try
{
// Create EndPoint for LFS and bind the socket to it.
IPEndPoint endPoint = new IPEndPoint(
IPAddress.Parse(Host),
Port);
socket.Bind(endPoint);

while (true)
{
// Receive packet data.
int received = socket.Receive(buffer);
if (received > 0)
{
// Copy data from buffer into correctly sized array.
byte[] data = new byte[received];
Buffer.BlockCopy(buffer, 0, data, 0, received);

// Packet received...
OutGaugePack packet = new OutGaugePack(data);
OutGaugePacketReceived(packet);
}
else
{
Console.WriteLine("Lost connection to OutGauge");
break;
}
}
}
catch (SocketException ex)
{
Console.WriteLine("Socket Error: {0}", ex.Message);
}
}

static void OutGaugePacketReceived(OutGaugePack packet)
{
// Do stuff with packet etc..

Console.WriteLine(packet.RPM);

if (packet.DashLights.HasFlag(DashLightFlags.DL_SHIFT))
{
Console.WriteLine("Shift-light on!");
}
}

class OutGaugePack
{
public TimeSpan Time { get; private set; }
public string Car { get; private set; }
public OutGaugeFlags Flags { get; private set; }
public int Gear { get; private set; }
public int SpareB { get; private set; }
public float Speed { get; private set; }
public float RPM { get; private set; }
public float Turbo { get; private set; }
public float EngTemp { get; private set; }
public float Fuel { get; private set; }
public float OilPressure { get; private set; }
public float OilTemp { get; private set; }
public DashLightFlags DashLights { get; private set; }
public DashLightFlags ShowLights { get; private set; }
public float Throttle { get; private set; }
public float Brake { get; private set; }
public float Clutch { get; private set; }
public string Display1 { get; private set; }
public string Display2 { get; private set; }
public int ID { get; private set; }

public OutGaugePack(byte[] data)
{
Time = TimeSpan.FromMilliseconds(BitConverter.ToUInt32(data, 0));
Car = ASCIIEncoding.ASCII.GetString(data, 4, 4).TrimEnd(char.MinValue);
Flags = (OutGaugeFlags)BitConverter.ToUInt16(data, 8);
Gear = data[10];
SpareB = data[11];
Speed = BitConverter.ToSingle(data, 12);
RPM = BitConverter.ToSingle(data, 16);
Turbo = BitConverter.ToSingle(data, 20);
EngTemp = BitConverter.ToSingle(data, 24);
Fuel = BitConverter.ToSingle(data, 28);
OilPressure = BitConverter.ToSingle(data, 32);
OilTemp = BitConverter.ToSingle(data, 36);
DashLights = (DashLightFlags)BitConverter.ToUInt32(data, 40);
ShowLights = (DashLightFlags)BitConverter.ToUInt32(data, 44);
Throttle = BitConverter.ToSingle(data, 48);
Brake = BitConverter.ToSingle(data, 52);
Clutch = BitConverter.ToSingle(data, 56);
Display1 = ASCIIEncoding.ASCII.GetString(data, 60, 16).TrimEnd(char.MinValue);
Display2 = ASCIIEncoding.ASCII.GetString(data, 76, 16).TrimEnd(char.MinValue);

if (data.Length == 96)
{
ID = BitConverter.ToInt32(data, 92);
}
}
}

[Flags]
enum OutGaugeFlags
{
OG_TURBO = 8192,
OG_KM = 16384,
OG_BAR = 32768,
}

[Flags]
enum DashLightFlags
{
DL_SHIFT = 1,
DL_FULLBEAM = 2,
DL_HANDBRAKE = 4,
DL_PITSPEED = 8,
DL_TC = 16,
DL_SIGNAL_L = 32,
DL_SIGNAL_R = 64,
DL_SIGNAL_ANY = 128,
DL_OILWARN = 256,
DL_BATTERY = 512,
DL_ABS = 1024,
DL_SPARE = 2048,
}
}
}

DarkTimes
S2 licensed
The example you linked to is for C++ .NET, while the OutGauge code is written for native C++. I've never done any serial port programming before, but with a quick search I found some examples and a PDF tutorial on the subject. Those should get you started for how to do it without .NET.
DarkTimes
S2 licensed
Quote from DarkTimes :Hey, wasn't sure where to post this, but someone asked me for an example of writing an OutGauge app in C++, and this is what I came up with. I'm posting it here in case it's useful to other people. Just note that I ain't a great C++ programmer, so there may be a few issues that I've not realised. Anyway it appears to work and shouldn't explode.

The code is a rehash of the pyinsim OutGauge example, which basically prints out a message whenever the shift-light comes on. I use this because it's simple, demonstrates everything you need to know, and is easily testable. It's usefulness, however, can be disputed.

Note: The OutGauge flags mask thing is explained in this thread.

#include <iostream>
#include <winsock2.h> // WinSock2 library (may need to add WS2_32.lib to project dependencies).

#define BUFFER_SIZE 512 // Receive buffer size (basically maximum packet size in UDP).
#define HOST "127.0.0.1" // Host to connect to.
#define PORT 30000 // Port to connect to the host through.

// Define types used by InSim.
typedef unsigned char byte;
typedef unsigned short word;
typedef struct
{
int X, Y, Z;
} Vec;
typedef struct
{
float X, Y, Z;
} Vector;

// Include InSim header.
#include "InSim.h"

void OutGaugePacketReceived(const OutGaugePack packet);

int main(int argc, char *argv[])
{

// Initialise WinSock version 2.2.
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
WSACleanup();
std::cerr << "Error: Failed to init WinSock" << std::endl;
return EXIT_FAILURE;
}

// Create UDP socket.
SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock == INVALID_SOCKET)
{
WSACleanup();
std::cerr << "Error: Could not create socket." << std::endl;
return EXIT_FAILURE;
}

// Bind to receive UDP packets.
sockaddr_in saddr;
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = inet_addr(HOST);
saddr.sin_port = htons(PORT);
if (bind(sock, (sockaddr *)&saddr, sizeof(sockaddr)) == SOCKET_ERROR)
{
closesocket(sock);
WSACleanup();
std::cerr << "Error: Could not connect to LFS" << std::endl;
return EXIT_FAILURE;
}

// Packet receive loop.
char recvbuf[BUFFER_SIZE];
memset(recvbuf, 0, sizeof(recvbuf)); // Set recvbuf to zero.
int bytes = 0;
do
{
bytes = recv(sock, recvbuf, BUFFER_SIZE, 0);
if (bytes > 0)
OutGaugePacketReceived((OutGaugePack &)recvbuf);
else if (bytes == 0)
std::cerr << "Error: Lost connection with LFS" << std::endl;
else
std::cerr << "Error: " << WSAGetLastError() << std::endl;
} while (bytes > 0);

// Cleanup and exit.
closesocket(sock);
WSACleanup();
return EXIT_SUCCESS;
}

void OutGaugePacketReceived(const OutGaugePack packet)
{
unsigned mask = 1 << DL_SHIFT;
if (packet.ShowLights & mask)
{
std::cout << "Shift light on!" << std::endl;
}
}


I uploaded a VS2010 project for this, with dependencies and stuff, which should compile without any issue.
JSON .NET Deserializer issues...
DarkTimes
S2 licensed
Has anyone had any luck using the .NET DataContractJsonSerializer class to deserialize the LFSWorld pubstat data? I was thinking it would be cool if it worked, but nothing is happening and I'm not getting any error messages. This is the code I'm using, trying to get the PST stats.

[DataContract]
public class PlayerStats
{
[DataMember(Name = "distance")]
public string Distance { get; set; }

[DataMember(Name = "fuel")]
public string Fuel { get; set; }

[DataMember(Name = "laps")]
public string Laps { get; set; }

[DataMember(Name = "joined")]
public string Joined { get; set; }

[DataMember(Name = "win")]
public string Win { get; set; }

[DataMember(Name = "second")]
public string Second { get; set; }

[DataMember(Name = "third")]
public string Third { get; set; }

[DataMember(Name = "races_finished")]
public string RacesFinished { get; set; }

[DataMember(Name = "qual")]
public string Qual { get; set; }

[DataMember(Name = "pole")]
public string Pole { get; set; }

[DataMember(Name = "drags")]
public string Drags { get; set; }

[DataMember(Name = "dragwins")]
public string DragWins { get; set; }

[DataMember(Name = "country")]
public string Country { get; set; }

[DataMember(Name = "ostatus")]
public string OStatus { get; set; }

[DataMember(Name = "hostname")]
public string HostName { get; set; }

[DataMember(Name = "last_time")]
public string LastTime { get; set; }

[DataMember(Name = "track")]
public string Track { get; set; }

[DataMember(Name = "car")]
public string Car { get; set; }
}

That is my data contact, now here is the serialization code.

public PlayerStats GetPlayerStats(string identKey, string racer)
{
var uri = new Uri(string.Format(@"http://www.lfsworld.net/pubstat/get_stat2.php?version=1.4&idk={0}&action=pst&racer={1}&s=1", identKey, racer));
var request = WebRequest.Create(uri);
var response = request.GetResponse();
using (var stream = response.GetResponseStream())
{
var json = new DataContractJsonSerializer(typeof(PlayerStats));
return json.ReadObject(stream) as PlayerStats;
}
}

But as I say I'm getting nothing, no errors or anything, just lots of nulls.
DarkTimes
S2 licensed
Quote from rediske :not...

http://news.bbc.co.uk/2/shared ... e_muslim_veils/html/2.stm

Ah OK, my bad. Sorry. I was confusing the burka with the niqab.
DarkTimes
S2 licensed
Quote from Bose321 :But there are some things that you don't got with a burka, like eye contact

<snip/>

Surely with a burka, eye contact is the one thing you're pretty much guaranteed on...
Last edited by DarkTimes, .
DarkTimes
S2 licensed
Quote from P5YcHoM4N :The only thing that caught my eye from all of this is someone in the UK gov't who responded with "The UK would never ban the Burka because it is un-British to tell someone what they can and cannot wear". This is the same country that bans people from wearing hooded tops or T-Shirts with joke captions on them. Nice to keep the consistency there.

I'm British and I often wear a hooded top and many of my t-shirts have jokey captions on them. As far as I'm aware the government has never tried to ban either.
DarkTimes
S2 licensed
Flying ants are nothing compared to flying cockroaches. When I used to live in Africa, we had to carry round umbrellas to stop the cockroaches from landing on our heads. They were the size of your fist as well. Awful things. People used to eat fried cockroach wings as a delicacy. Yuck.
DarkTimes
S2 licensed
I think the ban is wrong. If people want to wear veils because of their religious beliefs, then they have every right to do so. The state has no right to tell people what they can and cannot wear. I will be very disappointed if this law comes into effect.
FGED GREDG RDFGDR GSFDG