internal LinuxDeviceConfiguration(ConfigurationDescriptor descriptor, string devname, byte[] otherDescriptors = null) { this.devname = devname; this.descriptor = descriptor; this.otherDescriptors = otherDescriptors; SetValues(descriptor); }
public async Task InitAsync() { if (this._initialized) { return; } using (HttpClient client = new HttpClient((HttpMessageHandler)HttpClientHelpers.GetClientHandler(true))) { HttpResponseMessage async = await client.GetAsync(this._descriptorUrl); if (async.IsSuccessStatusCode) { this._descriptor = (ConfigurationDescriptor)JsonConvert.DeserializeObject <ConfigurationDescriptor>(await async.Content.ReadAsStringAsync()); switch (ConfigurationRepository.EnvironmentSetting.Environment) { case Ekreta.Mobile.Core.Models.Environments.Environments.PROD: ConfigurationRepository.EnvironmentSetting.GlobalMobileApiUrl = "https://kretaglobalmobileapi2.ekreta.hu"; break; case Ekreta.Mobile.Core.Models.Environments.Environments.UAT: ConfigurationRepository.EnvironmentSetting.GlobalMobileApiUrl = this._descriptor.GlobalMobileApiUrlUAT; break; case Ekreta.Mobile.Core.Models.Environments.Environments.TEST: ConfigurationRepository.EnvironmentSetting.GlobalMobileApiUrl = this._descriptor.GlobalMobileApiUrlTEST; break; case Ekreta.Mobile.Core.Models.Environments.Environments.DEV: ConfigurationRepository.EnvironmentSetting.GlobalMobileApiUrl = this._descriptor.GlobalMobileApiUrlDEV; break; } this._initialized = true; } } }
public void WriteConfiguration(string fileName, ConfigurationDescriptor configurationDescriptor) { XmlSerializer serializer = new XmlSerializer(typeof(ConfigurationDescriptor)); try { StreamWriter writer = new StreamWriter(fileName); serializer.Serialize(writer, configurationDescriptor); writer.Dispose(); } catch (Exception) { } }
void FindDfuInterface() { ConfigurationDescriptor cfg = BaseDevice.GetConfigurationDescriptor(); DfuInterface = 0xFFFF; bool done = false; foreach (InterfaceDescriptor i in cfg.Interfaces) { if (i.Class == 0xFE && i.SubClass == 1) // DFU Interface { // Look for DFU descriptor foreach (DescriptorNode n in i.RawSubDescriptors) // Todo: change to use interface subdescriptors rather than raw list (once implemented) { if (n.RawType == 0x21 && n.Data.Length == 7) { // Extract values from it. Attributes = (DfuAttributes)n.ReadByte(2); DetachTimeout = n.ReadShort(3); MaxTransferSize = n.ReadShort(5); DfuVersion = n.ReadShort(7); DfuMode = i.Protocol == 2; // Confirm this is the interface we need. DfuInterface = i.Number; done = true; break; } } if (done) { break; } } } if (DfuInterface == 0xFFFF) { throw new Exception("Unable to find DFU descriptor on device."); } }
public ConfigurationDescriptor GetConnections(string fileName, ConfigurationDescriptor configurationDescriptor) { XmlSerializer serializer = new XmlSerializer(typeof(ConfigurationDescriptor)); ConfigurationDescriptor config = null; try { StreamReader reader = new StreamReader(fileName); config = (ConfigurationDescriptor)serializer.Deserialize(reader); } catch (FileNotFoundException) { StreamWriter writer = new StreamWriter(fileName); serializer.Serialize(writer, configurationDescriptor); writer.Dispose(); StreamReader reader2 = new StreamReader(fileName); config = (ConfigurationDescriptor)serializer.Deserialize(reader2); } catch (Exception) { } return(config); }
public void writeConfiguration(string fileName, ConfigurationDescriptor configurationDescriptor) { ioService.WriteConfiguration(fileName, configurationDescriptor); }
public ConfigurationDescriptor loadConfiguration(string fileName, ConfigurationDescriptor configurationDescriptor) { return(ioService.GetConnections(fileName, configurationDescriptor)); }
protected void SetValues(ConfigurationDescriptor descriptor) { this.ConfigurationValue = descriptor.bConfigurationValue; this.InterfaceCount = descriptor.bNumInterfaces; }
// Temporary test application to validate functionality as it's being built. static void Main(string[] args) { Guid testGuid = new Guid("d2938a49-3191-4b25-ba33-e45f0828ced4"); Random r = new Random(); WinUSBEnumeratedDevice[] allDevices = WinUSBDevice.EnumerateAllDevices().ToArray(); foreach (WinUSBEnumeratedDevice devicePath in allDevices) { Console.Out.WriteLine(devicePath.ToString()); try { WinUSBDevice d = new WinUSBDevice(devicePath); try { DeviceDescriptor dev = d.GetDeviceDescriptor(); Console.Out.WriteLine(dev.ToString()); ConfigurationDescriptor cfg = d.GetConfigurationDescriptor(); Console.Out.WriteLine(cfg.ToString()); } finally { d.Close(); } } catch (Exception ex) { Console.Out.WriteLine("Exception while querying descriptors: {0}", ex); } } WinUSBEnumeratedDevice[] devices = WinUSBDevice.EnumerateDevices(testGuid).ToArray(); foreach (WinUSBEnumeratedDevice devicePath in devices) { Console.Out.WriteLine(devicePath); WinUSBDevice test = new WinUSBDevice(devicePath); // Try a data test. Test board just has OUT 3 looped back into IN 3 // Set pipe timeouts to avoid hanging forever. test.SetPipePolicy(0x03, WinUsbPipePolicy.PIPE_TRANSFER_TIMEOUT, 100); test.SetPipePolicy(0x83, WinUsbPipePolicy.PIPE_TRANSFER_TIMEOUT, 100); // Send some junk via OUT 3 byte[] data = new byte[128]; r.NextBytes(data); // Flush out any data that might have been here from a previous run... // Will take about as long as the transfer timeout. while (test.ReadPipe(0x83, 64).Length != 0) { ; } test.WritePipe(0x03, data); // read it back. byte[] returnData = test.ReadExactPipe(0x83, data.Length); for (int i = 0; i < data.Length; i++) { if (data[i] != returnData[i]) { throw new Exception("Error validating data returned from the device!"); } } Console.Out.WriteLine("Passed basic transfer test"); // Timeout test returnData = test.ReadPipe(0x83, 32); if (returnData.Length != 0) { throw new Exception("Pipe didn't timeout, where did it get that data?"); } Console.Out.WriteLine("Passed timeout test"); test.Close(); test.Close(); // checking that double close doesn't cause issues. } Console.Out.WriteLine("{0} device{1}", devices.Length, devices.Length == 1?"":"s"); WinUSBEnumeratedDevice[] hackrfs = HackRF.Enumerate().ToArray(); if (hackrfs.Length > 0) { Console.WriteLine("Connecting to hackrf device {0}", hackrfs[0].ToString()); HackRF rf = new HackRF(hackrfs[0]); Console.WriteLine("Version String: {0}", rf.ReadVersion()); // Do some benchmarking with the receive modes. rf.SetSampleRate(2000000); rf.ModeReceive(); rf.SetFrequency(100000000); // 100 MHz rf.SetSampleRate(10000000); int lastEaten = 0; int eaten = rf.PacketsEaten; long lastEatenBytes = 0; long eatenBytes = rf.BytesEaten; DateTime lastTime = DateTime.Now; while (true) { System.Threading.Thread.Sleep(2000); DateTime newTime = DateTime.Now; lastEaten = eaten; eaten = rf.PacketsEaten; lastEatenBytes = eatenBytes; eatenBytes = rf.BytesEaten; double seconds = newTime.Subtract(lastTime).TotalSeconds; double pps = (eaten - lastEaten) / seconds; double mbps = ((eatenBytes - lastEatenBytes) / seconds) / 1000000; lastTime = newTime; Console.WriteLine("Receiving... {0} {1:n2}pps {2:n4}MB/s", eaten, pps, mbps); string[] histogramData; lock (rf) { histogramData = rf.EatenHistogram.OrderByDescending(kv => kv.Value).Take(8).Select(kv => string.Format("{0}:{1}", kv.Key, kv.Value)).ToArray(); } Console.WriteLine(string.Join(" ", histogramData)); } } WinUSBEnumeratedDevice[] fadecandies = Fadecandy.Enumerate().ToArray(); if (fadecandies.Length > 0) { Fadecandy fc = new Fadecandy(fadecandies[0]); RgbRing ring = new RgbRing(24); double t = 0; while (true) { ring.Update(t); Array.Copy(ring.Ring, fc.Pixels, 24); fc.Pixels[64].G = Math.Sin(t) * 0.2 + 0.2; fc.FlushRange(0, 65); t += 0.01; System.Threading.Thread.Sleep(10); } } WinUSBEnumeratedDevice[] rgbbuttons = RgbButton.Enumerate().ToArray(); if (rgbbuttons.Length > 0) { RgbButton rb = new RgbButton(rgbbuttons[0]); #if false { // Put device into programming mode. rb.EnterProgrammingMode(); return; } #endif double t = 0; while (true) { rb.ButtonColors[0].G = Math.Sin(t) * 0.2 + 0.2; rb.ButtonColors[1].R = Math.Sin(t) * 0.2 + 0.2; rb.ButtonColors[2].G = 0.5 - rb.ButtonValues[0] / 256.0; rb.ButtonColors[2].R = 0.5 - rb.ButtonValues[1] / 256.0; rb.ButtonColors[2].B = 0.5 - rb.ButtonValues[3] / 256.0; rb.ButtonColors[3].B = (rb.DataCount & 1023) / 2048.0; rb.SendButtonColors(); t += 0.02; System.Threading.Thread.Sleep(20); Console.WriteLine("{0} {1} {2} {3}", rb.ButtonValues[0], rb.ButtonValues[1], rb.ButtonValues[2], rb.ButtonValues[3]); } } }