public static SpheroDeviceMessage messageFromEncodedString(string encodedMessage) { SpheroDeviceMessageDecoder decoder = new SpheroDeviceMessageDecoder(encodedMessage); return((SpheroDeviceMessage)decoder.CreateObject()); }
public SpheroLocatorData( SpheroDeviceMessageDecoder decoder ) : base(decoder) { position.x = decoder.DecodeFloat("position.x"); position.y = decoder.DecodeFloat("position.y"); velocity.x = decoder.DecodeFloat("velocity.x"); velocity.y = decoder.DecodeFloat("velocity.y"); }
public object DecodeObject(string key) { object value = null; dictionaryRepresentation.TryGetValue(key, out value); if (value is Array) { // need to decode the objects in the array Dictionary <string, object>[] encodedArray = (Dictionary <string, object>[])value; Object[] decodedArray = new Object[encodedArray.Length]; int index = 0; foreach (Dictionary <string, object> encodedDictionary in encodedArray) { SpheroDeviceMessageDecoder itemDecoder = new SpheroDeviceMessageDecoder(encodedDictionary); object decodedItem = itemDecoder.CreateObject(); decodedArray[index++] = decodedItem; } value = decodedArray; } else if (value is Dictionary <string, object> ) { SpheroDeviceMessageDecoder decoder = new SpheroDeviceMessageDecoder((Dictionary <string, object>)value); value = decoder.CreateObject(); } return(value); }
public object DecodeObject(string key) { object value = null; dictionaryRepresentation.TryGetValue(key, out value); if (value is Array) { // need to decode the objects in the array Dictionary<string,object>[] encodedArray = (Dictionary<string,object>[])value; Object[] decodedArray = new Object[encodedArray.Length]; int index = 0; foreach(Dictionary<string,object> encodedDictionary in encodedArray) { SpheroDeviceMessageDecoder itemDecoder = new SpheroDeviceMessageDecoder(encodedDictionary); object decodedItem = itemDecoder.CreateObject(); decodedArray[index++] = decodedItem; } value = decodedArray; } else if (value is Dictionary<string, object>) { SpheroDeviceMessageDecoder decoder = new SpheroDeviceMessageDecoder((Dictionary<string,object>)value); value = decoder.CreateObject(); } return value; }
public SpheroBackEMFData(SpheroDeviceMessageDecoder decoder) : base(decoder) { filtered.right = decoder.DecodeInt32("filtered.rightMotor"); filtered.left = decoder.DecodeInt32("filtered.leftMotor"); raw.right = decoder.DecodeInt32("raw.rightMotor"); raw.left = decoder.DecodeInt32("raw.leftMotor"); }
public SpheroLocatorData(SpheroDeviceMessageDecoder decoder) : base(decoder) { position.x = decoder.DecodeFloat("position.x"); position.y = decoder.DecodeFloat("position.y"); velocity.x = decoder.DecodeFloat("velocity.x"); velocity.y = decoder.DecodeFloat("velocity.y"); }
public SpheroQuaternionData(SpheroDeviceMessageDecoder decoder) : base(decoder) { q0 = decoder.DecodeFloat("quaternions.q0"); q1 = decoder.DecodeFloat("quaternions.q1"); q2 = decoder.DecodeFloat("quaternions.q2"); q3 = decoder.DecodeFloat("quaternions.q3"); }
public SpheroQuaternionData( SpheroDeviceMessageDecoder decoder ) : base(decoder) { q0 = decoder.DecodeFloat("quaternions.q0"); q1 = decoder.DecodeFloat("quaternions.q1"); q2 = decoder.DecodeFloat("quaternions.q2"); q3 = decoder.DecodeFloat("quaternions.q3"); }
public SpheroAccelerometerData(SpheroDeviceMessageDecoder decoder) : base(decoder) { normalized.X = decoder.DecodeFloat("normalized.x"); normalized.Y = decoder.DecodeFloat("normalized.y"); normalized.Z = decoder.DecodeFloat("normalized.z"); raw.x = decoder.DecodeInt32("accelerationRaw.x"); raw.y = decoder.DecodeInt32("accelerationRaw.y"); raw.z = decoder.DecodeInt32("accelerationRaw.z"); }
public SpheroGyroData(SpheroDeviceMessageDecoder decoder) : base(decoder) { rotationRate.x = decoder.DecodeInt32("rotationRate.x"); rotationRate.y = decoder.DecodeInt32("rotationRate.y"); rotationRate.z = decoder.DecodeInt32("rotationRate.z"); rotationRateRaw.x = decoder.DecodeInt32("rotationRateRaw.x"); rotationRateRaw.y = decoder.DecodeInt32("rotationRateRaw.y"); rotationRateRaw.z = decoder.DecodeInt32("rotationRateRaw.z"); }
public SpheroGyroData( SpheroDeviceMessageDecoder decoder ) : base(decoder) { rotationRate.x = decoder.DecodeInt32("rotationRate.x"); rotationRate.y = decoder.DecodeInt32("rotationRate.y"); rotationRate.z = decoder.DecodeInt32("rotationRate.z"); rotationRateRaw.x = decoder.DecodeInt32("rotationRateRaw.x"); rotationRateRaw.y = decoder.DecodeInt32("rotationRateRaw.y"); rotationRateRaw.z = decoder.DecodeInt32("rotationRateRaw.z"); }
public SpheroDeviceSensorsData(SpheroDeviceMessageDecoder decoder) { accelerometerData = (SpheroAccelerometerData)decoder.DecodeObject("accelerometerData"); attitudeData = (SpheroAttitudeData)decoder.DecodeObject("attitudeData"); quaternionData = (SpheroQuaternionData)decoder.DecodeObject("quaternionData"); backEMFData = (SpheroBackEMFData)decoder.DecodeObject("backEMFData"); locatorData = (SpheroLocatorData)decoder.DecodeObject("locatorData"); gyroData = (SpheroGyroData)decoder.DecodeObject("gyroData"); }
protected static void ReceiveDeviceMessage(string encodedMessage) { // Decode the string into an object SpheroDeviceMessage message = SpheroDeviceMessageDecoder.messageFromEncodedString(encodedMessage); // Pass it on to event handlers if (message is SpheroDeviceAsyncMessage) { sharedInstance.OnAsyncMessageReceived(new MessengerEventArgs(message)); } else if (message is SpheroDeviceNotification) { sharedInstance.OnNotificationMessageReceived(new MessengerEventArgs(message)); } }
public SpheroDeviceSensorsAsyncData(SpheroDeviceMessageDecoder decoder) : base(decoder) { frameCount = decoder.DecodeInt32("frameCount"); mask = decoder.DecodeUInt64("mask"); // Decode the frames array and create the frames array converting the // type of each object Object[] decodedArray = (Object[])decoder.DecodeObject("dataFrames"); frames = new SpheroDeviceSensorsData[decodedArray.Length]; int i = 0; foreach( Object decodedObject in decodedArray ) { frames[i++] = (SpheroDeviceSensorsData)decodedObject; } }
public SpheroDeviceSensorsAsyncData(SpheroDeviceMessageDecoder decoder) : base(decoder) { frameCount = decoder.DecodeInt32("frameCount"); mask = decoder.DecodeUInt64("mask"); // Decode the frames array and create the frames array converting the // type of each object Object[] decodedArray = (Object[])decoder.DecodeObject("dataFrames"); frames = new SpheroDeviceSensorsData[decodedArray.Length]; int i = 0; foreach (Object decodedObject in decodedArray) { frames[i++] = (SpheroDeviceSensorsData)decodedObject; } }
public SpheroAttitudeData(SpheroDeviceMessageDecoder decoder) : base(decoder) { pitch = decoder.DecodeFloat("pitch"); roll = decoder.DecodeFloat("roll"); yaw = decoder.DecodeFloat("yaw"); }
public SpheroDeviceNotification(SpheroDeviceMessageDecoder decoder) : base(decoder) { // Do not change the "type" string since it is linked in RobotKit m_NotificationType = (SpheroNotificationType)decoder.DecodeInt32("type"); }
public void TestDecode() { string encodedString = File.ReadAllText("/Users/brian/Documents/code/development/unity-plugin/ExampleProject/SensorStreaming/Assets/Plugins/SpheroTests/DataStreamingExample.json"); // Test that a message is created. SpheroDeviceMessage message = SpheroDeviceMessageDecoder.messageFromEncodedString(encodedString); Assert.NotNull(message); Assert.True(message is SpheroDeviceSensorsAsyncData); Assert.Equal(123456, message.TimeStamp); // Specific test for SpheroDeviceSensorsAsyncData SpheroDeviceSensorsAsyncData sensorsAsyncData = (SpheroDeviceSensorsAsyncData)message; Assert.Equal(2, sensorsAsyncData.FrameCount); Assert.Equal(0xF0000000E067E060, sensorsAsyncData.Mask); Assert.NotNull(sensorsAsyncData.Frames); Assert.True(sensorsAsyncData.Frames.Length > 1); // Check values for a DeviceSensorsData object SpheroDeviceSensorsData sensorsData = sensorsAsyncData.Frames[0]; // Accelerometer Assert.Equal(1.23f, sensorsData.AccelerometerData.Normalized.X); Assert.Equal(1.23f, sensorsData.AccelerometerData.Normalized.Y); Assert.Equal(1.23f, sensorsData.AccelerometerData.Normalized.Z); Assert.Equal(4096, sensorsData.AccelerometerData.Raw.x); Assert.Equal(4096, sensorsData.AccelerometerData.Raw.y); Assert.Equal(4096, sensorsData.AccelerometerData.Raw.z); // Attitude Assert.Equal(45.0f, sensorsData.AttitudeData.Pitch); Assert.Equal(180.0f, sensorsData.AttitudeData.Roll); Assert.Equal(270.0f, sensorsData.AttitudeData.Yaw); // Quaternion Assert.Equal(0.3f, sensorsData.QuaternionData.Q0); Assert.Equal(0.7f, sensorsData.QuaternionData.Q1); Assert.Equal(0.3f, sensorsData.QuaternionData.Q2); Assert.Equal(1.0f, sensorsData.QuaternionData.Q3); // back EMF Assert.Equal(200, sensorsData.BackEMFData.Filtered.right); Assert.Equal(200, sensorsData.BackEMFData.Filtered.left); Assert.Equal(200, sensorsData.BackEMFData.Raw.right); Assert.Equal(200, sensorsData.BackEMFData.Raw.left); // locator Assert.Equal(190.2f, sensorsData.LocatorData.Position.x); Assert.Equal(85.6f, sensorsData.LocatorData.Position.y); Assert.True(Math.Abs(208.5746868630036f - sensorsData.LocatorData.Position.Magnitude()) < 0.001); Assert.Equal(9.99f, sensorsData.LocatorData.Velocity.x); Assert.Equal(86.4f, sensorsData.LocatorData.Velocity.y); // gyro Assert.Equal(300, sensorsData.GyroData.RotationRate.x); Assert.Equal(300, sensorsData.GyroData.RotationRate.y); Assert.Equal(300, sensorsData.GyroData.RotationRate.z); Assert.Equal(300, sensorsData.GyroData.RotationRateRaw.x); Assert.Equal(300, sensorsData.GyroData.RotationRateRaw.y); Assert.Equal(300, sensorsData.GyroData.RotationRateRaw.z); }
public SpheroDeviceAsyncMessage(SpheroDeviceMessageDecoder decoder) : base(decoder) { }
public SpheroDeviceMessage(SpheroDeviceMessageDecoder decoder) { timeStamp = decoder.DecodeInt64("timeStamp"); robotId = decoder.DecodeString("robotId"); }
public static SpheroDeviceMessage messageFromEncodedString(string encodedMessage) { SpheroDeviceMessageDecoder decoder = new SpheroDeviceMessageDecoder(encodedMessage); return (SpheroDeviceMessage)decoder.CreateObject(); }
public SpheroSensorData(SpheroDeviceMessageDecoder decoder) { }