示例#1
0
        internal static string GetErrorReason(ScanHeadVersionInformation version)
        {
            string scanHeadVersion = $"{version.Major}.{version.Minor}.{version.Patch}";
            string apiVersion      = $"{VersionInformation.Major}.{VersionInformation.Minor}.{VersionInformation.Patch}";

            return($"Scan head version {scanHeadVersion} is not compatible with API version {apiVersion}");
        }
示例#2
0
 internal VersionCompatibilityException(ScanHeadVersionInformation version)
     : base(GetErrorReason(version))
 {
 }
        /// <summary>
        /// Deserialize a scan head status packet from a raw byte stream.
        /// </summary>
        /// <exception cref="VersionCompatibilityException">Thrown if the scan head version
        /// is incompatible with the client API</exception>"
        /// <param name="buf"></param>
        internal ScanHeadStatus(byte[] buf)
        {
            int idx = 0;

            // The header and version data should never change to maintain backwards compatibility
            Header = new PacketHeader
            {
                Magic = NetworkByteUnpacker.ExtractUShortFromNetworkBuffer(buf, ref idx),
                Size  = NetworkByteUnpacker.ExtractByteFromNetworkBuffer(buf, ref idx),
                Type  = (ScanPacketType)NetworkByteUnpacker.ExtractByteFromNetworkBuffer(buf, ref idx)
            };

            FirmwareVersion = new ScanHeadVersionInformation
            {
                Major   = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx),
                Minor   = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx),
                Patch   = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx),
                Commit  = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx),
                Product =
                    (ProductType)NetworkByteUnpacker.ExtractUShortFromNetworkBuffer(buf, ref idx),
                Flags = NetworkByteUnpacker.ExtractUShortFromNetworkBuffer(buf, ref idx)
            };

            // Minor versions can be differ, but differences in
            // major versions are considered to be incompatible
            if (FirmwareVersion.Major != VersionInformation.Major)
            {
                throw new VersionCompatibilityException(FirmwareVersion);
            }

            // Static Data
            ScanHeadSerialNumber = NetworkByteUnpacker.ExtractIntFromNetworkBuffer(buf, ref idx);
            MaxScanRate          = NetworkByteUnpacker.ExtractIntFromNetworkBuffer(buf, ref idx);
#pragma warning disable CS0618 // Type or member is obsolete
            ScanHeadIPAddress = NetworkByteUnpacker.ExtractIPAddressFromNetworkBuffer(buf, ref idx);
#pragma warning restore CS0618 // Type or member is obsolete
            ClientIPAddress   = NetworkByteUnpacker.ExtractIPAddressFromNetworkBuffer(buf, ref idx);
            ClientUdpPort     = NetworkByteUnpacker.ExtractUShortFromNetworkBuffer(buf, ref idx);
            ScanSyncID        = NetworkByteUnpacker.ExtractUShortFromNetworkBuffer(buf, ref idx);
            GlobalTime        = NetworkByteUnpacker.ExtractLongFromNetworkBuffer(buf, ref idx);
            NumPacketsSent    = NetworkByteUnpacker.ExtractIntFromNetworkBuffer(buf, ref idx);
            ProfilesSentCount = NetworkByteUnpacker.ExtractIntFromNetworkBuffer(buf, ref idx);
            NumValidEncoders  = NetworkByteUnpacker.ExtractByteFromNetworkBuffer(buf, ref idx);
            NumValidCameras   = NetworkByteUnpacker.ExtractByteFromNetworkBuffer(buf, ref idx);

            Reserved0 = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx);
            Reserved1 = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx);
            Reserved2 = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx);
            Reserved3 = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx);
            Reserved4 = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx);
            Reserved5 = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx);
            Reserved6 = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx);
            Reserved7 = NetworkByteUnpacker.ExtractUIntFromNetworkBuffer(buf, ref idx);

            // Variable Length Data
            EncoderValues = new Dictionary <Encoder, long>(NumValidEncoders);
            foreach (int i in Enumerable.Range(0, NumValidEncoders))
            {
                var  encoder      = (Encoder)Enum.ToObject(typeof(Encoder), i);
                long encoderValue = NetworkByteUnpacker.ExtractLongFromNetworkBuffer(buf, ref idx);
                EncoderValues.Add(encoder, encoderValue);
            }

            PixelsInWindow = new Dictionary <Camera, int>(NumValidCameras);
            foreach (int i in Enumerable.Range(0, NumValidCameras))
            {
                var camera = (Camera)Enum.ToObject(typeof(Camera), i);
                int pixels = NetworkByteUnpacker.ExtractIntFromNetworkBuffer(buf, ref idx);
                PixelsInWindow.Add(camera, pixels);
            }

            Temperatures = new Dictionary <TemperatureSensor, float>(NumValidCameras);
            foreach (int i in Enumerable.Range(0, NumValidCameras))
            {
                var   temperatureSensor = (TemperatureSensor)Enum.ToObject(typeof(TemperatureSensor), i);
                float temperature       = NetworkByteUnpacker.ExtractFloatFromNetworkBuffer(buf, ref idx);
                Temperatures.Add(temperatureSensor, temperature);
            }
        }