public override bool Equals(object obj) { if (!(obj is DeviceIdInfo)) { return(false); } DeviceIdInfo o = (DeviceIdInfo)obj; return(o.DeviceId == DeviceId && o.VendorId == VendorId); }
private static int DecodeNextBlock(System.IO.Stream buffer, ushort dcp_length, out KeyValuePair <BlockOptions, object> block) { int ret = 0; BlockOptions options; UInt16 dcp_block_length; UInt16 block_info = 0; UInt16 tmp, tmp2; string str; object content; ResponseStatus set_response; if (buffer.Position >= buffer.Length || dcp_length <= 0) { block = new KeyValuePair <BlockOptions, object>(0, null); return(ret); } ret += DecodeBlock(buffer, out options, out dcp_block_length); if (dcp_block_length >= 2) { ret += DecodeU16(buffer, out block_info); } dcp_block_length -= 2; switch (options) { case BlockOptions.DeviceProperties_NameOfStation: ret += DecodeString(buffer, dcp_block_length, out str); content = str; break; case BlockOptions.IP_IPParameter: byte[] ip, subnet, gateway; ret += DecodeOctets(buffer, 4, out ip); ret += DecodeOctets(buffer, 4, out subnet); ret += DecodeOctets(buffer, 4, out gateway); content = new IpInfo((BlockInfo)block_info, ip, subnet, gateway);; break; case BlockOptions.DeviceProperties_DeviceID: ret += DecodeU16(buffer, out tmp); ret += DecodeU16(buffer, out tmp2); content = new DeviceIdInfo(tmp, tmp2); break; case BlockOptions.DeviceProperties_DeviceOptions: BlockOptions[] option_list = new BlockOptions[dcp_block_length / 2]; for (int i = 0; i < option_list.Length; i++) { ret += DecodeU16(buffer, out tmp); option_list[i] = (BlockOptions)tmp; } content = option_list; break; case BlockOptions.DeviceProperties_DeviceRole: DeviceRoles roles = (DeviceRoles)buffer.ReadByte(); buffer.ReadByte(); //padding ret += 2; content = new DeviceRoleInfo(roles); break; case BlockOptions.DeviceProperties_DeviceVendor: ret += DecodeString(buffer, dcp_block_length, out str); content = str; break; case BlockOptions.Control_Response: set_response = new ResponseStatus(); set_response.Option = (BlockOptions)block_info; set_response.Error = (BlockErrors)buffer.ReadByte(); ret++; content = set_response; break; default: byte[] arr; ret += DecodeOctets(buffer, dcp_block_length, out arr); content = arr; break; } block = new KeyValuePair <BlockOptions, object>(options, content); //padding if ((dcp_block_length % 2) != 0) { buffer.ReadByte(); ret++; } return(ret); }
/// <summary> /// Finds the Light Stone device. /// </summary> /// <returns>A new <see cref="LightStoneDevice"/> or null if not found.</returns> private static LightStoneDevice FindLightStoneDevice() { // Constants as hard coded in version 0.7 of lsm: // Vendor ID: 1155 (0x0483), Product ID: 53 (0x0035) // LightStone bought December 2006: // Vendor ID: 5370 (0x14FA), Product ID: 1 (0x0001) [Version number: 9281 (0x2441)] // VID and PID for Lightstone device are 0x054c and 0x1000 respectively DeviceIdInfo[] deviceIdInfos = new DeviceIdInfo[] { new DeviceIdInfo(0x0483, 0x0035), new DeviceIdInfo(0x14FA, 0x0001), }; foreach (DeviceIdInfo deviceIdInfo in deviceIdInfos) { HidDevice hidDevice = HidDevice.FindDevice( deviceIdInfo.VendorId, deviceIdInfo.ProductId ); if (hidDevice != null) { return new LightStoneDevice(hidDevice); } } return null; }