public override void InitData(SimulatorData data) { base.InitData(data); // Create ODE world. //world = new World(); world = Tao.Ode.Ode.dWorldCreate(); // Set default gravity. Gravity = Defaults.Gravity; // Create the root ODE space. if (data.UseOctreeInsteadHash) { //space = new QuadTreeSpace(data.worldCenter, data.worldSize, data.octreeDepth); space = Tao.Ode.Ode.dQuadTreeSpaceCreate(IntPtr.Zero, OdeHelper.ToOdeVector3(data.WorldCenter), OdeHelper.ToOdeVector3(data.WorldSize), data.OctreeDepth); } else { space = Tao.Ode.Ode.dHashSpaceCreate(IntPtr.Zero); Tao.Ode.Ode.dHashSpaceSetLevels(space, data.HashMinLevel, data.HashMaxLevel); // (KleMiX) ... } //space.Collider = OdeHelper.CollisionCallback; rootSpace = new OdeSpace(space); // Create the ODE contact joint group. //contactJointGroup = new ODE.Joints.JointGroup(); contactJointGroup = Tao.Ode.Ode.dJointGroupCreate(0); // Set the ODE global CFM value that will be used by all Joints // (including contacts). This affects normal Joint constraint // operation and Joint limits. The user cannot adjust CFM, but // they can adjust ERP (a.k.a. bounciness/restitution) for materials // (i.e. contact settings) and Joint limits. //dWorldSetCFM( mWorldID, Defaults.Ode.globalCFM ); //world.CFM = Defaults.Ode.globalCFM; Tao.Ode.Ode.dWorldSetCFM(world, Defaults.Ode.GlobalCFM); // Set the ODE global ERP value. This will only be used for Joints // under normal conditions, not at their limits. Also, it will not // affect contacts at all since they use material properties to // calculate ERP. //dWorldSetERP( mWorldID, ( real ) 0.5 * ( defaults::ode::maxERP +defaults::ode::minERP ) ); //world.ERP = 0.5f * (Defaults.Ode.maxERP + Defaults.Ode.minERP); Tao.Ode.Ode.dWorldSetERP(world, 0.5f * (Defaults.Ode.MaxERP + Defaults.Ode.MinERP)); Tao.Ode.Ode.dWorldSetContactSurfaceLayer(world, Defaults.Ode.SurfaceLayer); SolverAccuracy = Defaults.SolverAccuracy; collisionCount = 0; // "mRaycastResult" is initialized in its own constructor. sensorSolid = null; rayContactGroup = Defaults.Shape.ContactGroup; }
public async Task Run() { // runs loop to send telemetry // set up a callback for connection status change _client.SetConnectionStatusChangesHandler(ConnectionStatusChangeHandler); // set up callback for Desired Property update (Settings/Properties in IoT Central) await _client.SetDesiredPropertyUpdateCallbackAsync(OnDesiredPropertyChangedAsync, null).ConfigureAwait(false); // set up callback for Methond (Command in IoT Central) await _client.SetMethodHandlerAsync("displayMessage", DisplayMessage, null).ConfigureAwait(false); Twin twin = await _client.GetTwinAsync().ConfigureAwait(false); Console.WriteLine("\r\nDevice Twin received:"); Console.WriteLine($"{twin.ToJson(Newtonsoft.Json.Formatting.Indented)}"); // Properties in IoT Central looks like this // "properties": { // "desired": { // "isCelsius": { // "value": true // }, // "$version": 2 // }, if (twin.Properties.Desired.Contains("isCelsius") && twin.Properties.Desired["isCelsius"]["value"] != null) { _bCelsius = twin.Properties.Desired["isCelsius"]["value"]; // update reported properties to keep UI and device state in synch TwinCollection twinValue = new TwinCollection(); twinValue["desiredVersion"] = twin.Properties.Desired["$version"]; twinValue["statusCode"] = 200; twinValue["value"] = _bCelsius; TwinCollection reportedProperties = new TwinCollection(); reportedProperties["isCelsius"] = twinValue; await _client.UpdateReportedPropertiesAsync(reportedProperties).ConfigureAwait(false); } if (_hasSenseHat) { // read sensor data from SenseHat using (var settings = RTIMUSettings.CreateDefault()) using (var imu = settings.CreateIMU()) using (var humidity = settings.CreateHumidity()) using (var pressure = settings.CreatePressure()) { while (true) { var imuData = imu.GetData(); var humidityReadResult = humidity.Read(); if (humidityReadResult.HumidityValid && humidityReadResult.TemperatureValid) { string buffer; // format telemetry based on settings from Cloud if (_bCelsius) { buffer = $"{{\"humidity\":{humidityReadResult.Humidity:F2},\"tempC\":{humidityReadResult.Temperatur:F2}}}"; } else { double fahrenheit = (humidityReadResult.Temperatur * 9 / 5) + 32; buffer = $"{{\"humidity\":{humidityReadResult.Humidity:F2},\"tempF\":{fahrenheit:F2}}}"; } using (var telemetryMessage = new Message(Encoding.UTF8.GetBytes(buffer))) { Console.WriteLine($"Message Out : {buffer}"); await _client.SendEventAsync(telemetryMessage).ConfigureAwait(false); } } else { Console.WriteLine("Err : Sensor data not valid"); } await Task.Delay(3 * 1000); } } } else { // simulate sensor date string buffer; var simulatorData = new SimulatorData { TempCMax = 36, HumidityMax = 100, TempC = 30, Humidity = 40, }; while (true) { if (simulatorData.TempC > simulatorData.TempCMax) { simulatorData.TempC += Rnd.NextDouble() - 0.5; // add value between [-0.5..0.5] } else { simulatorData.TempC += -0.25 + (Rnd.NextDouble() * 1.5); // add value between [-0.25..1.25] - average +0.5 } if (simulatorData.Humidity > simulatorData.HumidityMax) { simulatorData.Humidity += Rnd.NextDouble() - 0.5; // add value between [-0.5..0.5] } else { simulatorData.Humidity += -0.25 + (Rnd.NextDouble() * 1.5); // add value between [-0.25..1.25] - average +0.5 } // format telemetry based on settings from Cloud if (_bCelsius) { buffer = $"{{\"humidity\":{simulatorData.Humidity:F2},\"tempC\":{simulatorData.TempC:F2}}}"; } else { double fahrenheit = (simulatorData.TempC * 9 / 5) + 32; buffer = $"{{\"humidity\":{simulatorData.Humidity:F2},\"tempF\":{fahrenheit:F2}}}"; } using (var telemetryMessage = new Message(Encoding.UTF8.GetBytes(buffer))) { Console.WriteLine($"Message Out : {buffer}"); await _client.SendEventAsync(telemetryMessage).ConfigureAwait(false); } await Task.Delay(3 * 1000); } } }
void FindSimulator() { string simulator_devicetype; string simulator_runtime; switch (Harness.Target) { case "ios-simulator-32": simulator_devicetype = "com.apple.CoreSimulator.SimDeviceType.iPhone-5"; simulator_runtime = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-'); break; case "ios-simulator-64": simulator_devicetype = "com.apple.CoreSimulator.SimDeviceType.iPhone-5s"; simulator_runtime = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-'); break; case "ios-simulator": simulator_devicetype = "com.apple.CoreSimulator.SimDeviceType.iPhone-4s"; simulator_runtime = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-'); break; case "tvos-simulator": simulator_devicetype = "com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p"; simulator_runtime = "com.apple.CoreSimulator.SimRuntime.tvOS-" + Xamarin.SdkVersions.TVOS.Replace('.', '-'); break; case "watchos-simulator": simulator_devicetype = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm"; simulator_runtime = "com.apple.CoreSimulator.SimRuntime.watchOS-" + Xamarin.SdkVersions.WatchOS.Replace('.', '-'); break; default: throw new Exception(string.Format("Unknown simulator target: {0}", Harness.Target)); } var tmpfile = Path.GetTempFileName(); try { ExecuteCommand(Harness.MlaunchPath, string.Format("--sdkroot {0} --listsim {1}", Harness.XcodeRoot, tmpfile), output_verbosity_level: 1); simulator_data = new XmlDocument(); simulator_data.LoadWithoutNetworkAccess(tmpfile); SimulatorData candidate = null; simulators = null; foreach (XmlNode sim in simulator_data.SelectNodes("/MTouch/Simulator/AvailableDevices/SimDevice")) { var data = new SimulatorData { Node = sim }; if (data.runtime == simulator_runtime && data.devicetype == simulator_devicetype) { var udid = data.udid; var secondaryData = (SimulatorData)null; var nodeCompanion = simulator_data.SelectSingleNode("/MTouch/Simulator/AvailableDevicePairs/SimDevicePair/Companion[text() = '" + udid + "']"); var nodeGizmo = simulator_data.SelectSingleNode("/MTouch/Simulator/AvailableDevicePairs/SimDevicePair/Gizmo[text() = '" + udid + "']"); if (nodeCompanion != null) { var gizmo_udid = nodeCompanion.ParentNode.SelectSingleNode("Gizmo").InnerText; var node = simulator_data.SelectSingleNode("/MTouch/Simulator/AvailableDevices/SimDevice[@UDID = '" + gizmo_udid + "']"); secondaryData = new SimulatorData() { Node = node }; } else if (nodeGizmo != null) { var companion_udid = nodeGizmo.ParentNode.SelectSingleNode("Companion").InnerText; var node = simulator_data.SelectSingleNode("/MTouch/Simulator/AvailableDevices/SimDevice[@UDID = '" + companion_udid + "']"); secondaryData = new SimulatorData() { Node = node }; } if (secondaryData != null) { simulators = new SimulatorData[] { data, secondaryData }; break; } else { candidate = data; } } } if (simulators == null) { simulators = new SimulatorData[] { candidate } } ; } finally { File.Delete(tmpfile); } if (simulators == null) { throw new Exception("Could not find simulator"); } Harness.Log(1, "Found simulator: {0} {1}", simulators [0].name, simulators [0].udid); if (simulators.Length > 1) { Harness.Log(1, "Found companion simulator: {0} {1}", simulators [1].name, simulators [1].udid); } }