public void Unpack(List <byte> bytes) { if (bytes.Count < 4) { throw new Exception($"Invalid byte count {bytes.Count} to unpack emission header"); } this.StartByte = bytes[0]; if (this.StartByte != CONSTANTS.FRAME_START_BYTE) { throw new Exception($"Invalid start byte {this.StartByte} while unpacking emission header"); } this.Length = (ushort)(((ushort)bytes[1] << 8) | bytes[2]); if (!Enum.IsDefined(typeof(EmissionTypes), bytes[3])) { throw new NotImplementedException($"Emission frame type {bytes[3]} not implemented"); } this.FrameType = (EmissionTypes)bytes[3]; }
public EmissionDescriptor WaitForEmission(EmissionTypes type, int timeout) { EmissionDescriptor desc = null; DateTime start = DateTime.Now; while (desc == null) { if (DateTime.Now > start + TimeSpan.FromMilliseconds(timeout)) { throw new TimeoutException("Timeout while waiting for emission"); } this.mutexEmissions.WaitOne(); int index = this.emissions.FindIndex(em => em.Header.FrameType == type); if (index > -1) { desc = this.emissions[index]; this.emissions.RemoveAt(index); } this.mutexEmissions.ReleaseMutex(); } return(desc); }
internal EmissionHeader(EmissionTypes type) { this.FrameType = type; }