void CreateSegment(int index, float x, float y, float z, float width, float height, float length, float xrot, float yrot, float zrot) { Vector3 position = new Vector3(x, y, z); Vector3 size = new Vector3(width, height, length); Vector3 rotation = new Vector3(xrot, yrot, zrot); robotParts[index] = GameObject.CreatePrimitive(PrimitiveType.Cube); Color color; color = colors.TryGetValue(robotColor, out color) ? color : Color.white; robotParts[index].GetComponent <Renderer>().material.color = color; robotParts[index].transform.position = position; robotParts[index].transform.localScale = size; robotParts[index].AddComponent <Rigidbody>(); robotParts[index].name = "Robot Body " + index; robotParts[index].GetComponent <Rigidbody>().collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; robotParts[index].transform.eulerAngles = rotation; robotParts[index].GetComponent <Rigidbody>().mass = 4f; SensorHandler sh = robotParts[index].AddComponent <SensorHandler>(); sh.parentIndex = index; //place eyes on the appropriate body segment. if (index == 2) { CreateEyes(index); } }
public decimal update() { decimal energy = 0; energy = Decimal.Parse(energyProductionAmount); if (isTimeSet) { var intTime = time.read().Split(':'); var hour = int.Parse(intTime[0]); if (hour < 10 && hour > 4) { energy += (SensorHandler.getRandom() % 10) - 1; } else { energy -= (SensorHandler.getRandom() % 10) - 9; } } else { energy -= (SensorHandler.getRandom() % 10) - 5; } makeHistory(energy); return(energy); }
/// <summary> /// Initializes a new instance of the <see cref="T:WatchTower.iOS.BluetoothSensorMonitor"/> class. /// </summary> /// <param name="manager">Manager.</param> /// <param name="peripheral">Peripheral.</param> public BluetoothSensorMonitor(CBCentralManager manager, CBPeripheral peripheral) { if (manager == null) { throw new ArgumentNullException(nameof(manager)); } if (peripheral == null) { throw new ArgumentNullException(nameof(peripheral)); } // set creation order to allow for sorting this.CreationOrder = ++BluetoothSensorMonitor._creationOrder; Manager = manager; Peripheral = peripheral; Peripheral.Delegate = new SensorPeripheralDelegate(this); // Find the services advertised by the peripheral Peripheral.DiscoverServices(); SensorHandler = new SensorHandler(GetDeviceDetailsMap(peripheral.Name), _watchTowerSettings.UserID); PresentButDisconnected = false; bIsHexoskinMonitor = false; _name = peripheral.Name; }
/// <summary> /// Initializes a new instance of the <see cref="T:WatchTower.iOS.BluetoothSensorMonitor"/> class. /// </summary> /// <param name="hexoskinName">Hexoskin name.</param> /// <param name="id">Identifier.</param> public BluetoothSensorMonitor(string hexoskinName, NSUuid id) { bIsHexoskinMonitor = true; _name = hexoskinName; ID = id; SensorHandler = new SensorHandler(GetDeviceDetailsMap(hexoskinName), _watchTowerSettings.UserID); }
public decimal update() { decimal energy = 0; energy = Decimal.Parse(energyProductionAmount); energy += (SensorHandler.getRandom() % 10) - 5; makeHistory(energy); return(energy); }
public decimal update() { decimal energy = 0; energy = getTrend(); energy += (SensorHandler.getRandom() % 6) - 3; makeHistory(energy); currentValue = energy; Math.Round(energy, 2); return(energy); }
private void OutputDevices_add_Click(object sender, EventArgs e) { //output device add //TODO this should pop up a modal window to create new devices //DEBUG string device_name = "oDev " + SensorHandler.getRandom() % 100; string energy_consumption_default = "20"; deviceHandler.addOutputDevice(Device.makeDevice(device_name, energy_consumption_default, 21)); //OutputDevices.Items.Add("oDev " + SensorHandler.getRandom() % 100); }
/// <summary> /// Updates the data associated with the sensor /// </summary> /// <param name="hr">Hr.</param> void UpdateData(NSData hr) { var now = DateTime.Now; // A byte array to store data from sensor byte[] data = new byte[hr.Length]; // Copy data from sensor data to byte array System.Runtime.InteropServices.Marshal.Copy(hr.Bytes, data, 0, Convert.ToInt32(data.Length)); // Then send to sensor handler for parsing and processing SensorHandler.updateData(data); }
public override void ProcessRequest(JToken casJSON) { KinectSensor kinectSensor = SensorHandler.GetSensor(); this.coordinateMapper = kinectSensor.CoordinateMapper; this.colorFrameDescription = kinectSensor.ColorFrameSource.FrameDescription; int time_slept = 0; while (!kinectSensor.IsAvailable) { Thread.Sleep(5); time_slept += 5; if (time_slept > TIMEOUT_MS) { System.Environment.Exit(-2); } } bool dataReceived = false; while (!dataReceived) { this.currColorFrame = SensorHandler.GetColorFrame(); if (this.currColorFrame != null) { dataReceived = true; } } dataReceived = false; while (!dataReceived) { this.currDepthFrame = SensorHandler.GetDepthFrame(); if (this.currDepthFrame != null) { dataReceived = true; } } this.aggregatedData = this.ProcessBlocksFromFrames(); this.currColorFrame = null; this.currDepthFrame = null; }
public Form1() { InitializeComponent(); /****************** / * Init * / ******************/ battery = 900; //Initial setup with battery containing 500 MaH sHandler = new SensorHandler(@".\SensorPackage\DataSets\location1\December.csv"); deviceHandler.generateDebugList(); //DEBUG iSensor mockSensor = iSensor.makeSensor("DATE", "01/01/2017", "String", false); //SensorParser sparse = new SensorParser(); //sparse.filename = @"C:\Users\Justin\Dropbox\class\CS5860\project\SensorPackage\DataSets\location1\December.csv"; //sparse.readFile(); /****************** / * Program * / ******************/ //TODO run program }
public decimal update() { decimal energy = 0; energy = Decimal.Parse(energyProductionAmount); if (isTimeSet) { if (time.read().Contains('A')) //is before AM { energy += (SensorHandler.getRandom() % 10) - 1; } else { energy -= (SensorHandler.getRandom() % 10) - 9; } } else { energy += (SensorHandler.getRandom() % 10) - 5; } makeHistory(energy); return(energy); }
public override void ProcessRequest(JToken allAnnotations) { KinectSensor kinectSensor = SensorHandler.GetSensor(); int ms_slept = 0; while (!kinectSensor.IsAvailable) { Thread.Sleep(500); ms_slept += 500; System.Diagnostics.Debug.WriteLine("Waiting on sensor..."); if (ms_slept >= CONNECT_TIMEOUT_MS) { System.Environment.Exit(-1); } } CoordinateMapper coordinateMapper = kinectSensor.CoordinateMapper; FrameDescription frameDescription = kinectSensor.DepthFrameSource.FrameDescription; List <Tuple <JointType, JointType> > bones = new List <Tuple <JointType, JointType> >(); bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); bool dataReceived = false; Body[] bodies = null; Body body = null; ms_slept = 0; while (!dataReceived) { BodyFrame bodyFrame = null; System.Diagnostics.Debug.WriteLine("Waiting on body frame..."); while (bodyFrame == null) { bodyFrame = SensorHandler.GetBodyFrame(); } bodies = new Body[bodyFrame.BodyCount]; bodyFrame.GetAndRefreshBodyData(bodies); System.Diagnostics.Debug.WriteLine("Checking if body is detected in frame..."); System.Diagnostics.Debug.WriteLine(bodyFrame.BodyCount + " bodies detected"); int count = 0; if (bodyFrame.BodyCount > 0) { foreach (Body b in bodies) { if (b.IsTracked) { System.Diagnostics.Debug.WriteLine("Found body frame."); body = b; dataReceived = true; count++; } } } System.Diagnostics.Debug.WriteLine(count + " bodies tracked"); Thread.Sleep(100); ms_slept += 100; if (ms_slept >= POINTING_TIMEOUT_MS) { System.Environment.Exit(-1); } bodyFrame.Dispose(); } //// convert the joint points to depth (display) space /// IReadOnlyDictionary <JointType, Joint> joints = body.Joints; Dictionary <JointType, CameraSpacePoint> jointPoints = new Dictionary <JointType, CameraSpacePoint>(); foreach (JointType jointType in joints.Keys) { // sometimes the depth(Z) of an inferred joint may show as negative // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity) CameraSpacePoint position = joints[jointType].Position; if (position.Z < 0) { position.Z = 0.1f; } DepthSpacePoint depthSpacePoint = coordinateMapper.MapCameraPointToDepthSpace(position); jointPoints[jointType] = position; } Tuple <JointType, JointType> bone = bones.First(); List <BlockData> blocks = this.GetBlocks(allAnnotations); this.ComputeConfidenceScores(bone, jointPoints, blocks); }
/// <summary> /// Connets the service and enable notifications for the chars we need /// </summary> /// <param name="gatt">Gatt.</param> public void connectToService(BluetoothGatt gatt) { try { if (handle == null) { handle = new SensorHandler(deviceDetails, AppConfig.UserID); } BluetoothDevice d = gatt.Device; // Getting Char/services UUIDS UUID serviceUUID = null; UUID charUUID = null; UUID ccdUUID = UUID.FromString(BluetoothConstants.CCD_UUID); // Can add other ones later or maybe swap out config files? if (gatt.Device.Name.StartsWith("MVSS", StringComparison.CurrentCulture)) { serviceUUID = UUID.FromString(BluetoothConstants.MVSS_SERVICE); charUUID = UUID.FromString(BluetoothConstants.MVSS_CHAR); } if (gatt.Device.Name.StartsWith("Zephyr", StringComparison.CurrentCulture)) { serviceUUID = UUID.FromString(BluetoothConstants.HEART_RATE_SERVICE); charUUID = UUID.FromString(BluetoothConstants.HEART_RATE_CHAR); } /* if (serviceUUID == null || charUUID == null || ccdUUID == null) * { * // dont continue * // throw error? * }*/ notifyChars.Add(serviceUUID.ToString()); notifyChars.Add(charUUID.ToString()); // Getting Service BluetoothGattService ser = gatt.GetService(serviceUUID); // Getting custom characteristic and enabling the notifications for it BluetoothGattCharacteristic cha = ser.GetCharacteristic(charUUID); // Getting Descriptor from characteristic BluetoothGattDescriptor ds = cha.GetDescriptor(ccdUUID); // Setting desc to notify ds.SetValue(BluetoothGattDescriptor.EnableNotificationValue.ToArray()); //ds.SetValue(BluetoothGattDescriptor.EnableIndicationValue.ToArray()); gatt.WriteDescriptor(ds); // Enabling the notifications gatt.SetCharacteristicNotification(cha, true); } catch (NullReferenceException e) { // Service could not be reached // How to get this back to the user? string t = e.ToString(); } }
public CreateSensorHandleTest() { _sensorRepository = Substitute.For <ISensorRepository>(); _sensorHandle = new SensorHandler(_sensorRepository); }
public SensorController(ApplicationDbContext newDbContext, ILogger <SensorController> logger) { _sensorHandler = new SensorHandler(new DbSensor(newDbContext, logger), logger); _jsonEditor = new JsonEditor(logger); _logger = logger; }
public SensorTest() { _sensor = new SensorHandler(new DbSensorFake(), new JsonEditorFake()); }
public void hexoSkinConnect(BluetoothDevice dev) { DateTime lastChange = DateTime.MinValue; System.Timers.Timer t = new System.Timers.Timer(AppUtil.HEXOSKIN_INTERVAL); System.Timers.Timer timeOut = new System.Timers.Timer(AppUtil.HEXOSKIN_CONNECT_TIMEOUT); timeOut.AutoReset = true; timeOut.Elapsed += delegate { // Checking if HexoSkin Timed out TimeSpan duration = DateTime.Now - lastChange; if (duration.TotalMilliseconds > AppUtil.HEXOSKIN_CONNECT_TIMEOUT) { timeOut.Enabled = false; t.Enabled = false; // Send disconnect notice sendStateUpdate(dev.Address, false, "Hexoskin stopped reporting data"); } timeOut.Interval = AppUtil.SENSOR_CONNECT_TIMEOUT; }; t.AutoReset = true; t.Elapsed += async delegate { timeOut.Enabled = true; Log.Debug(LOG_TAG, "Getting hexoskin reading"); try { string data = await HTTPSender.getMessage("https://s3.amazonaws.com/pscloud-watchtower/", dev.Name); // If we got valid data if (!string.IsNullOrWhiteSpace(data)) { if (lastChange == DateTime.MinValue) { // First time we read data. sendStateUpdate(dev.Address, true, "Hexoskin started reporting data"); } lastChange = DateTime.Now; // Sending data to SensorHandler Dictionary <string, string> deviceDetails = new Dictionary <string, string>(); deviceDetails.Add("device_name", dev.Name); // Get the sensor handler SensorHandler sh = new SensorHandler(deviceDetails, AppConfig.UserID); byte[] dataArr = Encoding.UTF8.GetBytes(data); sh.updateData(dataArr); string xmlDetail = sh.xmlDetail; Log.Debug(LOG_TAG, xmlDetail); // Notifying Intent message = new Intent(AppUtil.SENSOR_READING_UPDATE_ACTION); Bundle intentBundle = new Bundle(); intentBundle.PutString(AppUtil.ADDRESS_KEY, dev.Address); intentBundle.PutString(AppUtil.DETAIL_KEY, xmlDetail); // Get Time last reading was taken Dictionary <string, string> dataJson = JsonConvert.DeserializeObject <Dictionary <string, string> >(data); double epochValue; if (double.TryParse(dataJson["timestamp"], out epochValue)) { epochValue = epochValue / 256; DateTime hexoSkinRead = AppUtil.FromUnixTime((long)epochValue); hexoSkinRead = DateTime.SpecifyKind(hexoSkinRead, DateTimeKind.Utc); hexoSkinRead = hexoSkinRead.ToLocalTime(); intentBundle.PutString(AppUtil.TIME_KEY, hexoSkinRead.ToString() ); } message.PutExtras(intentBundle); SendBroadcast(message); } } catch (Exception ex) { Log.Debug(LOG_TAG, "Getting Hexoskin data failed"); } }; t.Enabled = true; }
public async Task <GenericCommandResult> Delete([FromBody] DeleteSensorCommand command, [FromServices] SensorHandler handler) { return((GenericCommandResult)await handler.Handle(command)); }
public Renderer2d(SensorHandler sensorHandler) { _sensorHandler = sensorHandler; }
/// <summary> /// Accepts a dynamic packet. packet must contain a [NameSpace.][packet.cmd]. ex. "VDash." + [packet.cmd] /// </summary> /// <param name="packet">An unknon object received from a vehicle.</param> private void Command(dynamic packet) { object receivedObject; try { if (packet.cmd == "Heartbeat") { SendRaw(null, null, "Heartbeat"); return; } var cat = ""; if (packet.cmd.ToString().Contains("Error")) { cat = "Errors."; } else if (packet.cmd.ToString().Contains("Sensor")) { cat = "Sensors."; } else if (packet.cmd.ToString().Contains("Event")) { cat = "Events."; } string finder = "VehicleLib." + cat + packet.cmd + ", VehicleLib"; var t = Type.GetType(finder, true); var cast = typeof(JToken).GetMethod("ToObject", new Type[] { }).MakeGenericMethod(t); receivedObject = cast.Invoke(packet.data, null); } catch (RuntimeBinderException) { throw new MalformedMessageException { Malformed = JsonConvert.SerializeObject(packet) }; } if (packet.cmd.ToString().Contains("Error")) { OnError?.Invoke((Error)receivedObject); return; } if (packet.cmd.ToString().Contains("Sensor")) { SensorHandler cb = null; if (packet.id != null) { uint id = packet.id.ToObject <uint>(); cb = _callbacks[id]; _callbacks.Remove(id); } var sens = (Sensor)receivedObject; if (cb != null) { cb(sens); } else { OnSensorEvent?.Invoke(sens); } return; } if (packet.cmd.ToString().Contains("Event")) { ((Event)receivedObject).Invoke(); } }