private static void ReplaySeek(Bookmark ev) { Int32 rewindFrames = (Int32)sdk.GetData("ReplayFrameNum") - (int)ev.ReplayPos - (ev.Rewind * 60); sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, 0, 0); sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.CamSwitchNum, ev.DriverIdx, ev.CamIdx); sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlayPosition, (int)iRSDKSharp.ReplayPositionModeTypes.Begin, (int)(ev.ReplayPos - (ev.Rewind * 60))); Int32 curpos = (Int32)sdk.GetData("ReplayFrameNum"); DateTime timeout = DateTime.Now; // wait rewind to finish, but only 15 secs while (curpos != (int)(ev.ReplayPos - (ev.Rewind * 60)) && (DateTime.Now - timeout).TotalSeconds < 15) { Thread.Sleep(16); curpos = (Int32)sdk.GetData("ReplayFrameNum"); } SetPlaySpeed(ev.PlaySpeed); }
public void ApiTick(iRacingSDK api) { if (this.position < length) { switch (this.state) { case 1: api.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, this.max_value - ease(this.position) + 1, 1); break; case -1: api.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, ease(this.position), 1); break; default: break; } } else if (this.position >= length + 10 && this.state != 0) { Console.WriteLine("Finished..." + this.state); if (this.state == 1) { api.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, 1, 0); } else if (this.state == -1) { api.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, this.max_value, 1); } this.state = 0; } if (this.state != 0) { position++; } }
internal int BroadcastMessage(BroadcastMessageType msg, int var1, int var2) { return(sdk.BroadcastMessage(msg, var1, var2)); }
static void Main(string[] args) { if (args.Length < 1) { return; } Bookmarks myBookmarks = new Bookmarks();; Bookmark thisEvent = null; int currentIndex = 0; int CurrentFrame = 0; bool run = true; using (StreamReader sw = new StreamReader(args[0], Encoding.UTF8)) { System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(myBookmarks.GetType()); myBookmarks = x.Deserialize(sw) as Bookmarks; } Console.WriteLine("Waiting for iRacing to come up ...."); sdk = new iRacingSDK(); while (!Console.KeyAvailable && run) { //Check if the SDK is connected if (sdk.IsConnected()) { while (sdk.GetData("SessionNum") == null) { Console.WriteLine("Waiting for Session..."); Thread.Sleep(200); // Allow other windows to initialize more faster } thisEvent = myBookmarks.List[currentIndex]; switch (thisEvent.BookmarkType) { case BookmarkType.Start: ReplaySeek(thisEvent); currentIndex++; break; case BookmarkType.Play: CurrentFrame = (Int32)sdk.GetData("ReplayFrameNum"); if (CurrentFrame < thisEvent.ReplayPos) { continue; } sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.CamSwitchNum, thisEvent.DriverIdx, thisEvent.CamIdx); SetPlaySpeed(thisEvent.PlaySpeed); currentIndex++; break; case BookmarkType.Stop: CurrentFrame = (Int32)sdk.GetData("ReplayFrameNum"); if (CurrentFrame < thisEvent.ReplayPos) { continue; } sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, 0, 0); Console.WriteLine("End"); run = false; break; default: run = false; break; } } else { if (sdk.Startup()) { Console.WriteLine("iRacing up and running."); } else { Thread.Sleep(2000); } } } sdk.Shutdown(); }
private static string callbackCamera = "TV1"; // camera group to switch to when the client requests it static void Main(string[] args) { sdk = new iRacingSDK(); int lastUpdate = -1; //setup WebSocketServer var allSockets = new List <IWebSocketConnection>(); var server = new WebSocketServer("ws://localhost:8181"); server.Start(socket => { socket.OnOpen = () => { Console.WriteLine("Client Connected"); allSockets.Add(socket); }; socket.OnClose = () => { Console.WriteLine("Client Disconnected"); allSockets.Remove(socket); }; socket.OnMessage = message => { Console.WriteLine("Received -> " + message); int groupNum = cameras[callbackCamera]; sdk.BroadcastMessage(BroadcastMessageTypes.CamSwitchNum, Convert.ToInt32(message), groupNum, 0); }; }); while (true) { if (sdk.IsConnected()) { //If it is connected then see if the Session Info has been updated int newUpdate = sdk.Header.SessionInfoUpdate; if (telemData.getTrackId() == 0) { telemData.setTrackId(Convert.ToInt32(YamlParser.Parse(sdk.GetSessionInfo(), "WeekendInfo:TrackID:"))); DiscoverCameras(); } if (newUpdate != lastUpdate) { // Session Info updated (e.g. perhaps a client has connected/disconnected) lastUpdate = newUpdate; // Update the current Driver list string yaml = sdk.GetSessionInfo(); length = yaml.Length; start = yaml.IndexOf("DriverInfo:\n", 0, length); end = yaml.IndexOf("\n\n", start, length - start); string DriverInfo = yaml.Substring(start, end - start); ParseDrivers(DriverInfo); } UpdateDriverPositions(drivers); foreach (var socket in allSockets.ToList()) { Console.WriteLine("Broadcast sent..."); Console.WriteLine(telemData.toJson()); socket.Send(telemData.toJson()); } } else if (sdk.IsInitialized) { drivers.Clear(); cameras.Clear(); telemData.setTrackId(0); sdk.Shutdown(); lastUpdate = -1; } else { drivers.Clear(); cameras.Clear(); telemData.setTrackId(0); Console.WriteLine("NOT CONNECTED!"); sdk.Startup(); } System.Threading.Thread.Sleep(1000); } }