The online racing simulator
Searching in All forums
(12 results)
VeGe-
S2 licensed
Quote from Nadeo4441 :This is actually what most people want, feedback from the developers, not months-long silence. Just stating the obvious

Spot on! I really hope devs does this in future too, just keeps us even a bit updated. I though LFS is going down becose lack of interest from devs, but now I know they really are working hard. Small bits of info every once in a while is only thing we ask.
LCD Dash for LFS
VeGe-
S2 licensed
I wanted to share something I've done in last few weeks. I once made board with few leds and connected it straight to parallel port. Dirty and not really expandable. Now I did it better using microcontroller (Teensy++), USB-UART adapter (for data transmit), few leds and LCD. Previously with parallel port I used T-RonX's VB.NET library which is very nice to use. Unfortunately it's now out of date, but with a help of DarkTimes I made C# OutGauge program which sends the data to microcontroller. My part of the code is certainly not too pretty and effective but it does the job.

I have some experience in AVR programming so microcontroller part wasn't problem for me. It's not too fine code either as I've been modifying it multiple times and been too lazy to make it clean but nevertheless it works. It receives the 31 byte line from UART 20 times (50 ms) a second. There is now four leds: red, green, yellow and blue, so all lights in LFS virtual dashboard can be shown. Currently all same color (eg. oil warning, battery, shift light in red) shares the same led, but it's easily expandable. Unfortunately leds show bad in pictures (sorry for my not-too-good camera), but there they still are.

The LCD is from eBay and came from Hong Kong. It only costed like ~2,5€ including P&P so it was truly a bargain. It uses HD44780 controller as was my old one-line LCD so it was easy upgrade. LCD is tad slow, but I can't complain for this price. Currently it shows (up from left to right) RPM, fuel and speed, lower line is OutGauge's "Display2" which shows information about brake balance, some wing data or "Pit Instructions" if playing with pit settings. The gear indicator is from old school project and is fairly simple but is pretty cool.

I'm including the codes, both computer and AVR side here. They are still WIP and as of is unusable for anything else than JUST this hardware but you never know if someone makes something out of it. There is small part of tachometer in AVR code too, but I abandoned my old slow tacho for now. I used it in past with parallel port and extremely dirty DAC (http://www.youtube.com/watch?v=6er0Oc3niEc) and it works now somehow too but it would need small driving circuit which I haven't done (yet?). Been busy and more intersted in LCD.

I probably missed tons of things I wanted to say, so I'll update this thread when it comes to my mind.


Bigger picture

WIP codes
OutGauge Display1 [not a bug]
VeGe-
S2 licensed
In OutGauge "Display1" is 16 char string which shows car's fuel in percent and in absolute value (litres). After car change it only gives percentage and misses the litres value and is no longer 16 chars long. I kept driving and the litres value eventually appeared again when it was 10.0L. Can't be anything else than bug I guess, am I right?
VeGe-
S2 licensed
Thanks for the help! Got over the problem using C#, found it easier than C++. Maybe I'll try C++ some day and hopefully this thread can help some one else too!
VeGe-
S2 licensed
It seems that DarkTimes's code tells that "Shift light is ON!" all the time, even it isn't. Is there some small problem?

My OutGauge settings:

OutGauge Mode 2
OutGauge Delay 4
OutGauge IP 127.0.0.1
OutGauge Port 30000
OutGauge ID 2

Edit: Ah, yeah, it should be "if (packet.ShowLights.HasFlag(DashLightFlags.DL_ABS))", not DashLights.
Last edited by VeGe-, .
VeGe-
S2 licensed
Damn! I took that DarkTimes C# OutGauge example and combined it with this and I have excatly what I need!

Now my (or DarkTimes's and Microsoft's) C# program sends data to my microcontroller. It's WIP thingy but I have now RPM, Speed and emulated gear "N" (Edit: wrote it really, so it works now, see the code) on external LCD. I did all this with VB too, but outdated lib didn't understand new flags so this is as far as I got. Next I'll hook few LEDs to my uC and see how ABS, TC and stuff like that gives me signals.

My analog tacho is working somehow too, but it's old and slow. I'm more interested in this LCD and LEDs right now. I'll post some pics and videos when I'm far enough with this. Thank you DarkTimes, once again!!


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.IO.Ports;
using System.Threading;

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

static SerialPort _serialPort;

static void Main()
{
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;

// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();

// Allow the user to set the appropriate properties.
_serialPort.PortName = "COM3";
_serialPort.BaudRate = 57600;
_serialPort.DataBits = 8;
_serialPort.Parity = (Parity)Enum.Parse(typeof(Parity), "None");
_serialPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "Two");

// Set the read/write timeouts
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;

_serialPort.Open();

// 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..

_serialPort.Write("S"); // Start-byte for uC

if ((int)packet.RPM < 10){
_serialPort.Write("000");
} else if ((int)packet.RPM < 100){
_serialPort.Write("00");
} else if ((int)packet.RPM < 1000){
_serialPort.Write("0");
}

_serialPort.Write(((int)packet.RPM).ToString());

Int32 speed_kph = (int)(packet.Speed *3.6);

if (speed_kph < 10)
{
_serialPort.Write("00");
}
else if (speed_kph < 100)
{
_serialPort.Write("0");
}

_serialPort.Write(speed_kph.ToString());

if (packet.Gear == 0){
_serialPort.Write("R");
} else if (packet.Gear == 1){
_serialPort.Write("N");
} else if (packet.Gear > 1){
_serialPort.Write((packet.Gear - 1).ToString());
}
}

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,
}
}
}

Last edited by VeGe-, . Reason : Added real gear output to uC
VeGe-
S2 licensed
Tried the C-version with MinGW. It compiles great but for some reason I only get error that it's unable to open port. Maybe something to do with Windows 7 I'm using? But very easy to use:

#include <stdio.h>
#include <stdlib.h>
#include "rs232.h"

int main()
{
OpenComport(3, 9600);

SendByte(3, 'S');

char i;

for(i=0x30;i<0x40;i++){
SendByte(3, i);
}

CloseComport(3);
}

Wish there were something like this for C++ too...
VeGe-
S2 licensed
Ah, ok, I see. I'm kinda confused with whole .NET. It's C++ but then it isn't C++...

Tried that PDF tutorial but it was overwhelming. That other "some example" looked very nice easy-to-use library but it was written in plain C and it never compiled without great amount of cryptical errors. I'm not capable of modifying it so it would actually work.


\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(288): error C2065: 'port_settings' : undeclared identifier
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(288): warning C4133: 'function' : incompatible types - from 'int *' to 'LPDCB'
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(295): error C2065: 'port_settings' : undeclared identifier
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(295): warning C4133: 'function' : incompatible types - from 'int *' to 'LPDCB'
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(302): error C2275: 'COMMTIMEOUTS' : illegal use of this type as an expression
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(755) : see declaration of 'COMMTIMEOUTS'
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(302): error C2146: syntax error : missing ';' before identifier 'Cptimeouts'
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(302): error C2065: 'Cptimeouts' : undeclared identifier
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(304): error C2065: 'Cptimeouts' : undeclared identifier
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(304): error C2224: left of '.ReadIntervalTimeout' must have struct/union type
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(305): error C2065: 'Cptimeouts' : undeclared identifier
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(305): error C2224: left of '.ReadTotalTimeoutMultiplier' must have struct/union type
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(306): error C2065: 'Cptimeouts' : undeclared identifier
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(306): error C2224: left of '.ReadTotalTimeoutConstant' must have struct/union type
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(307): error C2065: 'Cptimeouts' : undeclared identifier
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(307): error C2224: left of '.WriteTotalTimeoutMultiplier' must have struct/union type
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(308): error C2065: 'Cptimeouts' : undeclared identifier
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(308): error C2224: left of '.WriteTotalTimeoutConstant' must have struct/union type
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(310): error C2065: 'Cptimeouts' : undeclared identifier
\visual studio 2010\projects\outgauge\outgaugetest\rs232.c(310): warning C4133: 'function' : incompatible types - from 'int *' to 'LPCOMMTIMEOUTS'

So still no success for me. I would love to find that sort of easy to use library for C++.
VeGe-
S2 licensed
Quote from kyler :Does anyone have a tutorial on how to update this or does someone have a tutorial on how to make a UDP socket and receive the packets? Thanks.

I'm also interested in getting the UDP socket to work in VB. Spent hours and hours yesterday trying to get over this problem somehow, but without any final breakthrough. Any VB experts around here to give us a clue how to start? I'm not completely newbie in VB, but UDP without any sign where to start is too much for my skills.
Visual C++ 2010 Express - Serial Communication
VeGe-
S2 licensed
I've been googling and researching for hours how to get my console Visual C++ Express program to transmit simple ASCII data to serial port. And without any success.

MSDN library doesn't help me as the example is unusable. I think it's for Express 2008. Everything else I've found is too old or just so complicated that I can't understand a word.

All I want to do is set up my serial port settings (COM3 57600 8-N-2, no handshake) and send few strings through serial port. How hard can it be?

Code is only slighty modified from DarkTimes's excellent tutorial.

#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 35555 // 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;
}

std::cout << (int)packet.RPM << std::endl;
}

The (int)packet.RPM shows revs beautifully in the console, I just need to put it through Serial Port along with speed and various other data. This wasn't a problem for me in VB, but out dated OutGauge lib forced me to look another ways to do this.
VeGe-
S2 licensed
No one has anything new about VB libraries? Got very nice example of handling OutGauge with C++ from DarkTimes but C++ serial communications is waaay beyond my skills. On the other hand I have perfectly working VB software but it doesn't support new flags becose of T-RonX's library is out of date. And make things even more frustrating I'm able to use serial communication in C# but it lacks of any understandable OutGauge example...
VeGe-
S2 licensed
Quote from Reese :

LFS currently uses DL's, not OG's anymore. LFS Extrenal is unfortunately yet to be updated as it only supports old OG's. T-RonX is on it, so hopefully it's only matter of time when new lib is released. I have project of my own (new gauge lights) so I'm waiting this too.

Here is chapter from LFS\Doc\InSim.txt which contains the updated flags:
Quote :
DL_SHIFT, // bit 0 - shift light
DL_FULLBEAM, // bit 1 - full beam
DL_HANDBRAKE, // bit 2 - handbrake
DL_PITSPEED, // bit 3 - pit speed limiter
DL_TC, // bit 4 - TC active or switched off
DL_SIGNAL_L, // bit 5 - left turn signal
DL_SIGNAL_R, // bit 6 - right turn signal
DL_SIGNAL_ANY, // bit 7 - shared turn signal
DL_OILWARN, // bit 8 - oil pressure warning
DL_BATTERY, // bit 9 - battery warning
DL_ABS, // bit 10 - ABS active or switched off
DL_SPARE, // bit 11
DL_NUM

FGED GREDG RDFGDR GSFDG