View Full Version : InSim/OutSim/OutGauge lib in .NET
sdether
18th May 2006, 23:50
Since my previous version of the library did not support activating OutGauge via InSim, I went back to integrate my two libraries into a single library. While I was at it, I also added OutSim.
The result is a new library, LFSLib.dll, providing handlers for OutSim, OutGauge and InSim including the ability to get OutSim and OutGauge via the InSim handler.
I've also changed the namespace from LiveForSpeed.* to FullMotion.LiveForSpeed.* so as to not monopolize the LiveForSpeed root namespace :)
Info, docs, binaries, etc. are all here: http://www.claassen.net/geek/lfs/
Details on what code changes are required between the new and old versions can be found here (http://www.claassen.net/geek/blog/2006/05/new-liveforspeed-lib-v010b-refactored.html)
GeForz
19th May 2006, 08:23
insim.txt: You can identify an OutGauge packet by its size (92 bytes) and 4th byte : zero.
your code: else if (bytesReceived == 96 && received[3] == 0)
So it doesn't work like that ;) And if you wold have run your Tester application you would have noticed it :D
Nevertheless good work :thumb:
Edit:
I think something is wrong with outgauge ;)
The packet in the file is 96 bytes big, but if you request outgauge through insim you only get 92 bytes whioch means the
"int ID; // (optional ID - if specified in cfg.txt)" is missing => check packet size of 96 and 92.
But if you use outgauge together with insim you receive at least two packets which are "size (92 bytes) and 4th byte : zero". The outgauge packet and the IS_LAP packet!
So I would suggest to move the OutGauge/Outsim check into the switch (receivedId.ToString())'s default part and check both outgauge packet sizes.
sdether
19th May 2006, 13:41
Ok... I'll go back and check. I did run the Tester and a separate command line tool and things seemed to be working, although i didn't scrutinize the values too closely.
CrazyICE
19th May 2006, 14:53
nice to see things are going forward :D
sdether
19th May 2006, 15:27
I think something is wrong with outgauge ;)
I just tested OutGauge both as standalone (using the tester app) and via InSim (separate console app) and both looked fine. I sanity checked time and ID (first and last bytes) and they came up right and the text values came out right as well.
edit: I just saw your comment that IS_LAP can be mistaken for OutGauge. I'll fix that.
more edit: Also, i saw that you were saying that if optional ID is not specified, it returns no bytes. I always just tested with the ID set and assumed that if it wasn't set i'd still get 4 0 bytes. I just took the Id out and yeah, that breakes my OutGauge. That explains why i always got 96 not 92 bytes like insim.txt said. I just figured it to be a typo. Ok, expect 0.11b today or tomorrow.
OutSim does seem to be broken as well, since i don't get the proper Id. I'll get that done as well by 0.11b
sdether
19th May 2006, 16:10
I assume this is proper behavior, but i can't seem to get any delay between packets larger than 1 second to work for either outsim or outgauge via insim.
Anyone able to confirm this?
sdether
20th May 2006, 06:07
Fixed OutSim and OutGauge bugs and added and OutSim form to the Tester app. Tested both as standalone and via InSim.
http://www.claassen.net/geek/lfs
Squelch
20th May 2006, 08:17
This is great work sdether. I'm learning so much from your code.
May I request a downloadable Doc package for us on dialup? Excellent documentation btw
sdether
20th May 2006, 16:49
http://www.claassen.net/geek/lfs/doc-0.11b.zip
I've also linked it on the project page and will keep having a download of the current version from now on
Squelch
21st May 2006, 06:48
That's great. Thank you very much sir.
Decibel
26th May 2006, 22:51
Any help for a noob ?
I can get the tester app to work with Insim data, but I get nothing using the Outgauge form tester. Do I have to set anything in the LFS cfg.txt for outgauge, or is it handled through Insim (which I assumed) ?
If I need to edit the cfg.txt file, what are the settings ?
Thanks for taking the time :thumb:
sdether
26th May 2006, 23:10
Any help for a noob ?
I can get the tester app to work with Insim data, but I get nothing using the Outgauge form tester. Do I have to set anything in the LFS cfg.txt for outgauge, or is it handled through Insim (which I assumed) ?
If I need to edit the cfg.txt file, what are the settings ?
Thanks for taking the time :thumb:
The OutSim and OutGauge testers are both meant for standalone mode. I think port 30002 and 30003 respectively, using 127.0.0.1 as IP.
Decibel
26th May 2006, 23:23
Thanks sdether.
I seem to be getting an error ...
"FullMotion.LiveForSpeed.OutGauge.OutGaugeReader: OutGaugeReader started
FullMotion.LiveForSpeed.AbstractLfsPacketReader: A Socket Exception has occurred!System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at FullMotion.LiveForSpeed.AbstractLfsPacketReader.Li sten()
FullMotion.LiveForSpeed.AbstractLfsPacketReader: Started Listener Thread on port 30003
Tester.LFSTesterForm: appender created"
I've set outgauge in the lfs.cgf to IP 127.0.0.1 on port 30003 and i've confirmed it's active using netstat -a.
I can usually persevere with this kind of stuff and get it working, but i'm stumped this time :shrug:
sdether
27th May 2006, 01:24
Basically that means something else is already bound to that port. I know I had some trouble on one of my machines that if the Tester didn't shut down properly, it wouldn't release the port. See if the problem continues if you reboot. And make sure you don't have your LFS insim bound to 30003 as well.
Decibel
27th May 2006, 17:36
That was it ! I had the tester crash on me once (because I restarted LFS while the tester was running) and hadn't rebooted. It was obvious in hindsight DOH :pillepall Thanks sdether.
The only thing that concerned me was that LFS started to stutter quite badly once the communication was working (the tester was pulling 99% cpu).
If you have a remedy for this or any suggestions, please let me know, otherwise i'm going to break out my VB installation and start playing :nod:
sdether
28th May 2006, 00:01
The only thing that concerned me was that LFS started to stutter quite badly once the communication was working (the tester was pulling 99% cpu).
If you have a remedy for this or any suggestions, please let me know, otherwise i'm going to break out my VB installation and start playing :nod:
Can't say I do. I've seen Visual Studio get very hungry in debug mode, but haven't had it happen with the Library tester. I can see it happening if you are limited in RAM. Mind you, the Tester is by no means a best practices approach to writing Windows Forms. Best suggestion I have is try out the lib in a console application and see if the same happens. I certainly wouldn't build your own application based on the GUI code in the Tester, it's just a harness that was thrown together with total disregard for design.
Tanuva
12th July 2006, 18:02
Is there a little tutorial available, f.e. how to make a program connecting to lfs using the library?
I can't manage to get or set the configuration variables - possibly because I have insufficient knowledge of C# ...
sdether
24th July 2006, 16:20
Is there a little tutorial available, f.e. how to make a program connecting to lfs using the library?
I can't manage to get or set the configuration variables - possibly because I have insufficient knowledge of C# ...
At this time the only tutorial is the Tester app, but being a hacky winforms application, that's liable to be more confusing than helpful. I'll try to post a quick console app in the next couple of days
wabz
25th July 2006, 04:02
Here's a snippet of code that connects (doesn't use an xml config file, just hardcoded values) and sends a message. Might get you started:
using FullMotion.LiveForSpeed.InSim;
<snip>
InSimHandler handler = new InSimHandler(true, false);
Configuration config = handler.Configuration;
config.LFSHost = "127.0.0.1";
config.LFSHostPort = 29999;
config.AdminPass = "adminPass";
config.UseSplitMessages = true;
config.UseKeepAlives = true;
handler.Initialize(3); // 3 is the number of seconds to wait for a version reply
handler.SendMessage("Hello world!");
handler.Close();
Note that there exists a bug where the reader thread doesn't stop if the connection fails. Here is a small, stupid patch against InSimHandler.cs which provides temporary relief:
@@ -360,7 +360,12 @@ namespace FullMotion.LiveForSpeed.InSim
{
initWait = wait*1000;
}
- CheckVersion();
+ try {
+ CheckVersion();
+ } catch (InSimHandlerException.NoVersion) {
+ reader.Stop(); //this is the wrong way to fix this, but this non connection kind of error really should have happened a long time ago.
+ throw new InSimHandlerException.NotConnected();
+ }
CheckState();
CheckForKeepAlive();
Tanuva
25th July 2006, 06:13
Hey, thats good to start from, thanks ;)
sdether
25th July 2006, 14:18
Very nice library with clear interface. I thought of using it for CityLife project instead of my ugly insim library from LFSLapper, but I am stuck at some problems:
Those are definitely all oversights and things I need to fix.
1 - Library does not support LFS code pages (you are using ascii encoding in all cases which yields wrong conversions with question marks as result ?)
Yeah, i wrote it before the non-latin support (or are accents and umlauts broken as well?) I need to properly evaluate the language support and get the changes in there
2 - Does not compile in Mono (doesn't work in Linux) ?
Do you have the errror you get? It used to compile a couple of versions ago. I'll get mono up to date one of my servers and figure out what I changed.
3 - Sometimes (will try to find out more) while running test, LFS completely freezes and I have to kill it from Task Manager.
LFS or the insim app? I've not seen this myself and have had apps running for over 24 hours.
sdether
27th July 2006, 15:15
Here is my quick patch for code pages support. 1 new function (and one replaced) in byte2string class, and one-line changes in other 3 files dealing with conversion.
Mono compiler gives errors about interface not implemented in some classes. See attached file (open with Wordpad not notepad). I didn't try to resolve yet...
Thanks. I'll put the patches in for the next release. I'll also figure out why its not compiling under mono. It runs under mono, though. I took my compiled console test application moved it to my linux box and was able to connect back to LFS on my windows machine. While i'll get it working under mono (and provide a nant build file), it is possible to use the binaries that come with the release in the meantime.
wabz
30th July 2006, 01:38
Here is my quick patch for code pages support. 1 new function (and one replaced) in byte2string class, and one-line changes in other 3 files dealing with conversion.
.
Parts of this patch look EXTREMELY similar to code given in 13321 in the BFS 0.6 thread over in unofficial addons. While it had no copyright/license attached, I think it's a bit rude to not give credit :razz:.
I left out ^G in there, which is Greek, which is missing from your patch too. You might want to add it. :x
MonkOnHotTinRoof
30th July 2006, 07:49
Parts of this patch look EXTREMELY similar to code given in 13321 in the BFS 0.6 thread over in unofficial addons. While it had no copyright/license attached, I think it's a bit rude to not give credit :razz:.
I left out ^G in there, which is Greek, which is missing from your patch too. You might want to add it. :x
OMG, mate, calm down. The only thing I looked for in your code was code page numbers (and comments near them :D), because I didn't want to look for them in docs. Sure I was mislead for missing greek then...
sdether, can you add missing greek line (and add in beginning license a comment: This code includes 4 numbers and 5 comments copied from wabz's code :D ).
wabz
30th July 2006, 08:02
Heh, sorry if I came across too angry - I thought the "Omg Plagiarism@!*&" thread title should have been sufficient to show I wasn't that serious :p Just would've been nice I think, because it is so different (and so much less) to the code you gave in that thread.
No comments in sdether's code required.... :thumb:
sdether
30th July 2006, 18:37
Heh, sorry if I came across too angry - I thought the "Omg Plagiarism@!*&" thread title should have been sufficient to show I wasn't that serious :p Just would've been nice I think, because it is so different (and so much less) to the code you gave in that thread.
No comments in sdether's code required.... :thumb:
This kind of thing is why I never patch my code directly with provided source, but use that source to understand the solution and roll my own. I'll gladly give credit to all sources that helped me, but I don't want to have my codebase infringe on anyone else's copyright, whether permission is granted or not.
Anyway, i'm playing with the codepage stuff now, but I have a ton of things on my plate, so it may still be another week until I release a new version of LFSLib.
bluejudas
9th September 2006, 14:51
Do you have a new version ready soon ??
I love what you have done so far...
btw, is it possible to connect through the isrelay.liveforspeed.net with this library?
sdether
11th September 2006, 18:35
I'm sorry it's taking so long, but the last two months have not given me any time to finish up the bug fixes and code page additions i've been working on. I don't have a date right now, except that it is on my list of things to do.
I have not looked at what is required to change transparent support for the relay server, but it's on the list after above changes go out.
Do you have a new version ready soon ??
I love what you have done so far...
btw, is it possible to connect through the isrelay.liveforspeed.net with this library?
bluejudas
12th September 2006, 06:25
I'm sorry it's taking so long, but the last two months have not given me any time to finish up the bug fixes and code page additions i've been working on. I don't have a date right now, except that it is on my list of things to do.
I have not looked at what is required to change transparent support for the relay server, but it's on the list after above changes go out.
Tanx, nice to see its alive :)
MaximUK
3rd November 2006, 18:40
Can somebody give me a pointer as I am a bit stuck.
I am trying to hook into LFS using this lib with visual Basic Express 2005.
I have declared
Dim handler As New InSim.InSimHandler(True, False)
and then inside a button event I have
With handler
With .Configuration
.LFSHost = "127.0.0.1"
.LFSHostPort = 29999
.UseSplitMessages = True
End With
Try
.Initialize(10)
Catch ex As FullMotion.LiveForSpeed.InSim.Exceptions.InSimHand lerException.ConnectionFailed
MsgBox("failed to make connection")
End Try
End With
Unfortunately it fails to find LFS and pretty much hangs the game, even when I have shut my routine down. I have probaby missed something very basic as I am only just starting with VB so any helpful pointers would be appreciated.
I am only really wanting to connect with outsim if it makes a difference.
thanks
Maxim
sdether
4th November 2006, 16:45
MaximUK:
A couple of things.
1. You do have LFS starting with \insim=29999 ?
2. you never set .ReplyPort, which just happens to default to 29999. Now, it should be possible to listen and send on the same port (never tested it myself), but not if who you are communicating with is on the same machine. I.e. LFS binds to port 29999 so when you try to bind the replyPort to 29999, you'll just block. Try setting .ReplyPort = 30000 . I assume this blocking prevents the exception to be thrown and that's why you are hanging.
3. If you really just want outsim, use OutSimHandler instead and make sure that outsim is properly configured in LFS's cfg.txt
Hope that helps
MaximUK
5th November 2006, 11:10
Thanks for the help sdether. I think I am close now but I still can't get OutSim data.
I start LFS with \inSim 29999
then my code is (ignore any _ characters as they are added to aid reading the code)
Dim InSimHandler As New InSim.InSimHandler(True, False)
Dim WithEvents outSimHandler As New OutSim.OutSimHandler(30001)
Dim OutSimPacket As OutSim.Events.PhysicsState
then inside the Connect button event:
With InSimHandler
_____With .Configuration
________.LFSHost = "127.0.0.1"
________.LFSHostPort = 29999
________ .UseSplitMessages = True
________ .ReplyPort = "30000"
_____End With
___ Try
______.Initialize(10)
______ tb_feedback.Text = "connected to InSim"
___ Catch ex As ___FullMotion.LiveForSpeed.InSim.Exceptions.InSimH andlerException.ConnectionFailed
______ MsgBox("failed to make connection")
___ End Try
End With
With outSimHandler
___ .Initialize()
End With
InSimHandler.SendMessage("are we talking?")
InSimHandler.StartOutSim(25)
tb_feedback.Text = "started OutSim at 25ms updates"
I then have an outSimHandler_Updated(....) event but it doesn't seem to trigger. InSim seems ok as it displays messages in-game ok
I wanted to enable InSim as well as OutSim so I can push messages into LFS while developing the software.
Maxim
Eldanor
15th November 2006, 18:01
Sorry but I can't still make Outgauge work I tried changing the cfg.txt file but it didn't work.
What exactly has to be changed and where?
sdether
22nd November 2006, 15:44
Ok, I don't to VB.NET, so this is going to be in C#, but it should at least be close enough to get you going.
There are two ways to use OutGauge, by itself or via InSim.
To use it by itself, you need to configure it in the cfg file, such as:
OutGauge Mode 2
OutGauge Delay 100
OutGauge IP 127.0.0.1
OutGauge Port 30001
OutGauge ID 0
And then the setup code in C# would be
OutGaugeHandler handler = new OutGaugeHandler(30001);
handler.Updated += new OutGaugeHandler.GaugeEvent(outGauge_Updated);
Console.WriteLine("created handler");
while (true)
{
//clearly you'll want to handle this loop some other way,
//or in the case of Windows.Forms, don't even need to
//worry about a loop like this.
//The point is, after you start the handler, your OutGauge events
//are received by another thread, so do whatever you need with
//thread that started the handler
}
If you are getting OutGauge via InSim, start lfs with /insim=30000 and the consuming code in C# would be
handler = new InSimHandler(false, false);
Configuration config = handler.Configuration;
config.LFSHost = "127.0.0.1";
config.LFSHostPort = 30000;
config.ReplyPort = 30001;
config.UseKeepAlives = true;
config.UseSplitMessages = true;
config.GuaranteedDelivery = true;
handler.Initialize();
Console.WriteLine("LFS info:");
Console.WriteLine(" Product: {0}", handler.Version.Product);
Console.WriteLine(" Version: {0}", handler.Version.Version);
Console.WriteLine(" Serial: {0}", handler.Version.Serial);
handler.GaugeUpdated += new OutGaugeHandler.GaugeEvent(outGauge_Updated);
handler.StartOutGauge(100);
while (true)
{
// same story with this loop as in the above case
}
How you just need to create the event handler that receives the OutGauge events, which is the same in both scenarios:
void outGauge_Updated(object sender,
FullMotion.LiveForSpeed.OutGauge.Events.Gauge gauge)
{
Console.WriteLine("OutGauge -----------------------");
Console.WriteLine("Time: {0}", gauge.Time);
Console.WriteLine("ID: {0}", gauge.Id);
Console.WriteLine("Car: {0}", gauge.Car);
Console.WriteLine("RPM: {0}", gauge.RPM);
Console.WriteLine("Speed: {0}", gauge.Speed);
Console.WriteLine("Message1: {0}", gauge.DisplayMessage1);
Console.WriteLine("Message2: {0}", gauge.DisplayMessage2);
}
Hope that helps,
sdether
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.