public async Task OnTimeUpdateEventHandler(double value) { PlayerState.CurrentTime = TimeSpan.FromSeconds(value); await OnTimeUpdated.InvokeAsync(PlayerState); StateHasChanged(); }
/// <summary> /// Processes a 4A "Clock-time and date" frame 0b01000 /// </summary> private void ProcessFramePayload_ClockTime(RDSFrame frame) { //Read julian day code uint dayCode = (uint)((frame.c >> 1) & 0b0111111111111111); dayCode |= (uint)(((frame.b >> (HEADER_OFFSET - 4)) & 0b0000000000000011) << 15); //Decode day code according to Annex G of the linked document //This is in UTC int year = (int)((dayCode - 15078.2f) / 365.25f); int month = (int)((dayCode - 14956.1f - (int)(year * 365.25f)) / 30.6001f); int day = (int)dayCode - 14956 - ((int)(year * 365.25f)) - ((int)(month * 30.6001f)); int k; if (month == 14 || month == 15) { k = 1; } else { k = 0; } year += 1900 + k; month -= 1 - (k * 12); //Get the hour int localHour = ((frame.d >> 12) & 0b0000000000001111); localHour |= ((frame.c & 0b0000000000000001) << 4); //Get the minute int localMinute = ((frame.d >> 6) & 0b0000000000111111); //Get the local time offset, in half hours. Also calculate the sign int localOffsetParts = (frame.d & 0b0000000000011111); if ((frame.d & 0b0000000000100000) != 0) { localOffsetParts = -localOffsetParts; } DateTime time; TimeSpan localOffset; DateTime localTime; try { //Create a UTC DateTime from the UTC portion time = new DateTime(year, month, day, 0, 0, 0, 0, DateTimeKind.Local); //Convert the local hour and minute to a TimeSpan we'll save localOffset = new TimeSpan(0, 30 * localOffsetParts, 0); //Convert to local time localTime = time.AddMinutes((localHour * 60) + (localOffsetParts * 30) + localMinute); } catch { //Ignore. If this was a corrupted RDS frame, this would've thrown an exception return; } //Set this.timeLast = localTime; this.timeOffset = localOffset; this.timeComplete = true; //Send event OnTimeUpdated?.Invoke(this, localTime, localOffset); }