The online racing simulator
#1 - Beau
Programming LFS, outgauge? outsim?
Howdy.

Just curious as to where i should begin in making a plugin/ something that can get data out of LFS.

For starters i think i'd just like to get out the speed/tacho information. Then i can send it down to a uC via serial.

Micro side i can do, LFS side i'm not sure where to begin.

My best language is C/C++ so hopefully i can do it in that. Any links/guides etc? on how i grab the info i need?
Guide: My first InSim Application, that would be a good starting place, as it will show you how to connect to LFS (Granted, through InSim, but an OutGuage connection is not all that different.) Third post down, they have a C example.
#3 - Beau
Okay i have some code hopefully someone can help me with.

It's going like this, i can connect to Insim (port 29999), setup Outgauge on port 30000 (if it's on 29999, Insim captures it all with red warning writing).

I'm farily sure it seems to be working. It's just i'm not sure how to recieve UDP properly? and check that it's an OutgaugePack packet.

(what seems to happen is i treat everything as an outgaugepack, it sends something weird, then i'm trying to print something stupid on screen.)

here's the part that causes problems.

RecvAddr.sin_port = htons(30000);
bind(RecvSocket, (SOCKADDR *) &RecvAddr, sizeof(RecvAddr));


while ( quit==false){
printf("Settingmem...\n");
memset(&outgauge, 0, sizeof(struct OutGaugePack));
printf("Recieving...\n");
recvfrom(RecvSocket, (char *)&outgauge, sizeof(struct OutGaugePack), 0, (SOCKADDR *)&SenderAddr, &SenderAddrSize);
printf("Recieving2...\n");
if(outgauge.Speed!=NULL){
//TODO:if quit bail
printf("Speed: %n \n",outgauge.Speed);
}

i get recieving2 printed then caplunk . it happens the exact same way without my hacky null check.
The easier way would be to simply init OutGauge through the cfg.txt that LFS uses, rather than make it init through InSim, unless you actually need any of the the data from InSim as well as the outgauge packets.

You'd simply need to setup a listener socket and then parse the UDP outgauge packets as they come.

I don't have any projects that are solely related to outgauge that I could pass across, and that code doesn't look overly bad to me at a glance, but I'll see what I can come up with after work when I have the opportunity to look at it properly..
#5 - Beau
ahh well the init via insim, was surprisingly simple (after glancing through your examples).

So to me it really doesn't matter either way. But it's already going now....


as i was typing i fixed the problem with my debugger, upon that i relized that i was printing FLOATS as ints.

%f fixed it.... I win the stupidest error award lol.


But on that, is there anyway i can check to see if i'm recieving a OutGaugePack struct?. Because of the typecasting on memory locations, i'm a tad worried that i could possibly get something else through that port, resulting in gibberish and a crash...
The easiest way is to check the size of the packet you've got through the UDP socket, from the return value of recvfrom, (since UDP will only ever send a single packet at a time), and to check the 8th byte (the final byte in the "Car" character array), as it must be \0, if I recall correctly..

Aside from that, there isn't really. Mind you, Outgauge is more designed to run on trusted networks (since it's a client side only thing), so whether or not this is a relevant question is something to consider
#7 - Beau
Holy crap was LFS easy to get info out of. I'm surprised!!.

Already i've written a windows app that will let me get the RPM, speed (converted to km/h), and X,Y,Z accelerations.

Now if and when my damn servos come, i should be able to create something interesting .

Thanks mate

FGED GREDG RDFGDR GSFDG