Select vehivle telemetry
This commit is contained in:
Kilian Hofmann 2022-11-13 03:50:41 +01:00
parent ffae6c9a15
commit 1ac3ef7b86
6 changed files with 123 additions and 82 deletions

View File

@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("rFactor 2 Message Center")]
[assembly: AssemblyDescription("Read Access to the rFactor 2 Message Center")]
[assembly: AssemblyTitle("rFactor 2 MiscData")]
[assembly: AssemblyDescription("Read Access to miscellaneous rFactor 2 Data")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Kilian Kurt Hofmann")]
[assembly: AssemblyProduct("rFactor 2 Message Center")]
[assembly: AssemblyProduct("rFactor 2 MiscData")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

View File

@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace rFactor2MessageCenter.Properties {
namespace rFactor2MiscData.Properties {
using System;
@ -39,7 +39,7 @@ namespace rFactor2MessageCenter.Properties {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("rFactor2MessageCenter.Properties.Resources", typeof(Resources).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("rFactor2MiscData.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;

View File

@ -7,8 +7,8 @@
<ProjectGuid>{833040C9-FE5E-4CCF-B21D-71979E049B6B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>rFactor2MessageCenter</RootNamespace>
<AssemblyName>rFactor2 Message Center</AssemblyName>
<RootNamespace>rFactor2MiscData</RootNamespace>
<AssemblyName>rFactor2 Misc Data</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
@ -78,7 +78,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="rFactor2MessageCenter.cs" />
<Compile Include="rFactor2MiscData.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33103.184
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rFactor 2 Message Center", "rFactor 2 Message Center.csproj", "{833040C9-FE5E-4CCF-B21D-71979E049B6B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rFactor 2 Misc Data", "rFactor 2 Misc Data.csproj", "{833040C9-FE5E-4CCF-B21D-71979E049B6B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -1,73 +0,0 @@
using GameReaderCommon;
using RfactorReader.RF2;
using SimHub.Plugins;
namespace rFactor2MessageCenter
{
[PluginDescription("Read Access to the rFactor 2 Message Center")]
[PluginAuthor("Kilian Kurt Hofmann")]
[PluginName("rFactor 2 Message Center")]
public class rFactor2MessageCenter : IPlugin, IDataPlugin
{
private const string LAST_MESSAGE = "LastMessage";
/// <summary>
/// Instance of the current plugin manager
/// </summary>
public PluginManager PluginManager { get; set; }
/// <summary>
/// Gets a short plugin title to show in left menu. Return null if you want to use the title as defined in PluginName attribute.
/// </summary>
public string LeftMenuTitle => null;
/// <summary>
/// Called one time per game data update, contains all normalized game data,
/// raw data are intentionnally "hidden" under a generic object type (A plugin SHOULD NOT USE IT)
///
/// This method is on the critical path, it must execute as fast as possible and avoid throwing any error
///
/// </summary>
/// <param name="pluginManager"></param>
/// <param name="data">Current game data, including current and previous data frame.</param>
public void DataUpdate(PluginManager pluginManager, ref GameData data)
{
// Define the value of our property (declared in init)
if (data.GameRunning && data is GameData<WrapV2> _data)
{
StatusData<WrapV2> newData = _data.GameNewData;
string message = System.Text.Encoding.Default.GetString(newData.Raw.extended.mLastHistoryMessage);
int index = message.IndexOf('\0');
if( index >= 0)
{
message = message.Remove(index);
}
pluginManager.SetPropertyValue(LAST_MESSAGE, GetType(), message);
}
}
/// <summary>
/// Called at plugin manager stop, close/dispose anything needed here !
/// Plugins are rebuilt at game change
/// </summary>
/// <param name="pluginManager"></param>
public void End(PluginManager pluginManager)
{
SimHub.Logging.Current.Info("Stopping plugin");
pluginManager.ClearProperties(GetType());
}
/// <summary>
/// Called once after plugins startup
/// Plugins are rebuilt at game change
/// </summary>
/// <param name="pluginManager"></param>
public void Init(PluginManager pluginManager)
{
SimHub.Logging.Current.Info("Starting plugin");
pluginManager.AddProperty(LAST_MESSAGE, GetType(), "No Data", "Last Message Center Entry");
}
}
}

114
rFactor2MiscData.cs Normal file
View File

@ -0,0 +1,114 @@
using CrewChiefV4.rFactor2_V2.rFactor2Data;
using GameReaderCommon;
using RfactorReader.RF2;
using SimHub.Plugins;
using System;
namespace rFactor2MiscData
{
[PluginDescription("Read Access to miscellaneous rFactor 2 Data")]
[PluginAuthor("Kilian Kurt Hofmann")]
[PluginName("rFactor 2 Misc Data")]
public class rFactor2MiscData : IPlugin, IDataPlugin
{
private const string LAST_MESSAGE = "rF2MiscData.LastMessage";
private const string VEHICLE_BASE = "rF2MiscData.Position";
private const string VEHICLE_FUEL = ".Fuel";
private const string VEHICLE_THROTTLE= ".Throttle";
private const string VEHICLE_BRAKE = ".Brake";
private const string VEHICLE_PLACE = ".Place";
private const string VEHICLE_DRIVERNAME = ".DriverName";
/// <summary>
/// Instance of the current plugin manager
/// </summary>
public PluginManager PluginManager { get; set; }
/// <summary>
/// Gets a short plugin title to show in left menu. Return null if you want to use the title as defined in PluginName attribute.
/// </summary>
public string LeftMenuTitle => null;
/// <summary>
/// Called one time per game data update, contains all normalized game data,
/// raw data are intentionnally "hidden" under a generic object type (A plugin SHOULD NOT USE IT)
///
/// This method is on the critical path, it must execute as fast as possible and avoid throwing any error
///
/// </summary>
/// <param name="pluginManager"></param>
/// <param name="data">Current game data, including current and previous data frame.</param>
public void DataUpdate(PluginManager pluginManager, ref GameData data)
{
// Define the value of our property (declared in init)
if (data.GameRunning && data is GameData<WrapV2> _data)
{
WrapV2 newData = _data.GameNewData.Raw;
// Last Message
string message = System.Text.Encoding.Default.GetString(newData.extended.mLastHistoryMessage);
int index = message.IndexOf('\0');
if( index >= 0)
{
message = message.Remove(index);
}
pluginManager.SetPropertyValue(LAST_MESSAGE, GetType(), message);
int maxVehicles = Math.Min(newData.Scoring.mVehicles.Length, newData.telemetry.mVehicles.Length);
for(int i = 0; i < maxVehicles; i++)
{
rF2VehicleTelemetry telemetry = newData.telemetry.mVehicles[i];
rF2VehicleScoring scoring = newData.Scoring.mVehicles[i];
// Vehicle Fuel
pluginManager.SetPropertyValue($"{VEHICLE_BASE}{scoring.mPlace:000}{VEHICLE_FUEL}", GetType(), telemetry.mFuel);
// Vehicle Throttle
pluginManager.SetPropertyValue($"{VEHICLE_BASE}{scoring.mPlace:000}{VEHICLE_THROTTLE}", GetType(), telemetry.mFilteredThrottle);
// Vehicle Brake
pluginManager.SetPropertyValue($"{VEHICLE_BASE}{scoring.mPlace:000}{VEHICLE_BRAKE}", GetType(), telemetry.mFilteredBrake);
// Vehicle Position
pluginManager.SetPropertyValue($"{VEHICLE_BASE}{scoring.mPlace:000}{VEHICLE_PLACE}", GetType(), scoring.mPlace);
// Vehicle Driver Name
string driverName = System.Text.Encoding.Default.GetString(scoring.mDriverName);
index = message.IndexOf('\0');
if (index >= 0)
{
message = message.Remove(index);
}
pluginManager.SetPropertyValue($"{VEHICLE_BASE}{scoring.mPlace:000}{VEHICLE_DRIVERNAME}", GetType(), driverName);
}
}
}
/// <summary>
/// Called at plugin manager stop, close/dispose anything needed here !
/// Plugins are rebuilt at game change
/// </summary>
/// <param name="pluginManager"></param>
public void End(PluginManager pluginManager)
{
SimHub.Logging.Current.Info("Stopping plugin");
pluginManager.ClearProperties(GetType());
}
/// <summary>
/// Called once after plugins startup
/// Plugins are rebuilt at game change
/// </summary>
/// <param name="pluginManager"></param>
public void Init(PluginManager pluginManager)
{
SimHub.Logging.Current.Info("Starting plugin");
pluginManager.AddProperty(LAST_MESSAGE, GetType(), "No Data", "Last Message Center Entry");
for (int i = 1; i <= 104; i++)
{
pluginManager.AddProperty($"{VEHICLE_BASE}{i:000}{VEHICLE_FUEL}", GetType(), "No Data", $"Vehicle at position {i}: Fuel");
pluginManager.AddProperty($"{VEHICLE_BASE}{i:000}{VEHICLE_THROTTLE}", GetType(), "No Data", $"Vehicle at position {i}: Throttle");
pluginManager.AddProperty($"{VEHICLE_BASE}{i:000}{VEHICLE_BRAKE}", GetType(), "No Data", $"Vehicle at position {i}: Brake");
pluginManager.AddProperty($"{VEHICLE_BASE}{i:000}{VEHICLE_PLACE}", GetType(), "No Data", $"Vehicle at position {i}: Place");
pluginManager.AddProperty($"{VEHICLE_BASE}{i:000}{VEHICLE_DRIVERNAME}", GetType(), "No Data", $"Vehicle at position {i}: Driver Name");
}
}
}
}