// License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2017 Intel Corporation. All Rights Reserved. namespace Intel.RealSense { using System; using System.Runtime.InteropServices; public class UpdateDevice : Device { private readonly rs2_update_progress_callback onUpdateProgressCallback; internal UpdateDevice(IntPtr dev) : base(dev) { onUpdateProgressCallback = new rs2_update_progress_callback(OnUpdateProgressInternal); } /// /// Create an from existing /// /// a device that supports /// a new /// Thrown when does not support public static UpdateDevice FromDevice(Device dev) { object error; if (NativeMethods.rs2_is_device_extendable_to(dev.Handle, Extension.UpdateDevice, out error) == 0) { throw new ArgumentException($"Device does not support {nameof(Extension.UpdateDevice)}"); } return Device.Create(dev.Handle); } /// /// Update an updatable device to the provided firmware, this call is executed on the caller's thread. /// For progress notifications, register to OnUpdateProgress event. /// public void Update(byte[] fwImage) { IntPtr nativeFwImage = Marshal.AllocHGlobal(fwImage.Length); Marshal.Copy(fwImage, 0, nativeFwImage, fwImage.Length); object error; NativeMethods.rs2_update_firmware(Handle, nativeFwImage, fwImage.Length, onUpdateProgressCallback, IntPtr.Zero, out error); Marshal.FreeHGlobal(nativeFwImage); } public delegate void OnUpdateProgressDelegate(float progress); public event OnUpdateProgressDelegate OnUpdateProgress; private void OnUpdateProgressInternal(float progress, IntPtr userData) { OnUpdateProgress?.Invoke(progress); } } }