VinnoProbe.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.IO;
  2. namespace fis.Vid
  3. {
  4. public enum VinnoProbeType
  5. {
  6. Undefined,
  7. Linear,
  8. Convex,
  9. Sector,
  10. };
  11. public class VinnoProbe
  12. {
  13. public string Name { get; }
  14. public VinnoProbeType Type { get; }
  15. public VinnoApplication Application { get; }
  16. public double FrameRate { get; }
  17. public VinnoProbe(string name,VinnoProbeType type, VinnoApplication application, double frameRate)
  18. {
  19. Name = name;
  20. Type = type;
  21. Application = application;
  22. FrameRate = frameRate;
  23. }
  24. public byte[] ToBytes()
  25. {
  26. byte[] result;
  27. using (var stream = new MemoryStream())
  28. {
  29. var writer = new VinnoStreamWriter(stream);
  30. writer.WriteString(Name);
  31. writer.WriteByte((byte)Type);
  32. writer.WriteBytes(Application.ToBytes());
  33. writer.WriteDouble(FrameRate);
  34. result = stream.ToArray();
  35. }
  36. return result;
  37. }
  38. public static VinnoProbe FromBytes(byte[] bytes)
  39. {
  40. if (bytes == null)
  41. {
  42. return null;
  43. }
  44. VinnoProbe result;
  45. using (var stream = new MemoryStream(bytes))
  46. {
  47. stream.Position = 0;
  48. var reader = new VinnoStreamReader(stream);
  49. var name = reader.ReadString();
  50. var type = (VinnoProbeType)reader.ReadByte();
  51. var application = VinnoApplication.FromBytes(reader.ReadBytes());
  52. var frameRate = reader.ReadDouble();
  53. if (frameRate == 0)
  54. {
  55. frameRate = 15;
  56. }
  57. if (frameRate<10&&frameRate>= 1)
  58. {
  59. frameRate = 10;
  60. }
  61. result = new VinnoProbe(name, type, application, frameRate);
  62. }
  63. return result;
  64. }
  65. }
  66. }