Ok, Today is not working day in Madrid and I can get some time for rFactor.
First, the way I used to solve my problems was study a lot of github project and much stackoverflow and google.
I usually works with C# but my area is web developing and it was my first time with Marshall Structures, and I didn't touch C++ afert my university days, some years ago...
The dll plugin has not change so much, basically what I do is define my structure with basic variables:
Code:
#ifndef DATOS_H
#define DATOS_H
struct DatosToConector
{
bool SessionRunning = false;
bool PlayerDriving = false;
int mGear = 0;
int mSpeed = 0;
int mRPM = 0;
.
.
.
.
.
//Put any variables as you need.
}
#endif
void ExampleInternalsPlugin::UpdateTelemetry(const TelemInfoV01 &info)
{
telem->PlayerDriving = false;
telem->SessionRunning = false;
telem->mGear = (int)info.mGear;
telem->mSpeed= mSpeed;
telem->mRPM = (int)info.mEngineRPM;
/*
*mSpeed is a local variable not rfactor plugin data.
*/
}
And in the C# app these is my structure and the way I get data, the most important part is define the MarshalAs data type as you can see.
Code:
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct DatosH
{
[MarshalAs(UnmanagedType.VariantBool)]
public bool SessionRunning;
[MarshalAs(UnmanagedType.VariantBool)]
public bool PlayerDriving;
[MarshalAs(UnmanagedType.I4)]
public int mGear;
public int mSpeed;
public int mRPM;
public int mMaxRPM;
public int mPctRPM;
public int mFrontLeftTemp;
public int mFrontLeftWear;
public int mFrontLeftBrakeTemp;
public int mFrontLeftFlat;
public int mFrontRightTemp;
public int mFrontRightWear;
public int mFrontRightBrakeTemp;
public int mFrontRightFlat;
public int mRearLeftTemp;
public int mRearLeftWear;
public int mRearLeftBrakeTemp;
public int mRearLeftFlat;
public int mRearRightTemp;
public int mRearRightWear;
public int mRearRightBrakeTemp;
public int mRearRightFlat;
public int mWater;
public int mOil;
public int mFuel;
public int mHeating;
public int mDRSLegal;
public int mDRSStatus;
public int mLapNumber;
public int mCurrentSector;
public double mCurrentET;
public double mBestSector1;
public double mBestSector2;
public double mBestLapTime;
public double mLastSector1;
public double mLastSector2;
public double mLastLapTime;
public double mCurSector1;
public double mCurSector2;
public double mLapStartET;
public double mEndET;
public int mSpeedLimiter;
public int mSpeedLimiterAvailable;
}
To get the data:
Code:
DatosH _datosh;
string memFile = string.Empty;
memFile = "Local\\SimTelemetryRfactor2";
using (MemoryMappedFile memoryMappedFile = MemoryMappedFile.OpenExisting(memFile))
{
using (MemoryMappedViewStream viewStream = memoryMappedFile.CreateViewStream())
{
Type outputType = typeof(DatosH).IsEnum ? Enum.GetUnderlyingType(typeof(DatosH)) : typeof(DatosH);
int count = Marshal.SizeOf(outputType);
byte[] numArray = new byte[count];
_datosh = (DatosH)Marshal.PtrToStructure(GCHandle.Alloc((object)new BinaryReader((Stream)viewStream).ReadBytes(count), GCHandleType.Pinned).AddrOfPinnedObject(), typeof(DatosH));
}
}
And thats all, now you can acces to telemetry simply with
Code:
_datosh.mRearRightTemp
_datosh.mRPM
Or use your own structure for your proposes.
Now I have a minor problems, I'm trying to get lap times, I do this:
Code:
string LapTime = "";
tsCurrent = TimeSpan.FromSeconds(_datosh.mCurrentET - _datosh.mLapStartET);
LapTime = tsCurrent.Minutes.ToString("00", (IFormatProvider)CultureInfo.InvariantCulture) + ":" + tsCurrent.Seconds.ToString("00", (IFormatProvider)CultureInfo.InvariantCulture) + ":" + tsCurrent.Milliseconds.ToString("000", (IFormatProvider)CultureInfo.InvariantCulture);
But I observed that plugin send me _datosh.mCurrentET with only one decimal and I can't get the exact lap time, I always get some milisecons differences.
My question is what are the bes way to get lap times (Delta time, best time, current time....)
Thanks.