Skip to content

Commit

Permalink
Realtime client SDK for .NET in c# initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mlveggo committed Jul 16, 2015
1 parent e0e50db commit 4669b3b
Show file tree
Hide file tree
Showing 11 changed files with 5,093 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .gitignore
@@ -0,0 +1,14 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/obj/Debug/RTClientSDK.pdb
/obj/Debug/RTClientSDK.Net.csproj.FileListAbsolute.txt
/obj/Debug/RTClientSDK.dll
/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
/obj/Debug
/bin/Debug/RTClientSDK.pdb
/bin/Debug/RTClientSDK.dll.config
/bin/Debug/RTClientSDK.dll
/bin/Debug
/.vs/RTClientSDK.Net/v14/.suo
146 changes: 146 additions & 0 deletions BitConvert.cs
@@ -0,0 +1,146 @@
// Realtime SDK for Qualisys Track Manager. Copyright 2015 Qualisys AB
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QTMRealTimeSDK.Data;

namespace QTMRealTimeSDK
{
/// <summary>
/// Converts bytes to different data types
/// </summary>
static class BitConvert
{
/// <summary>
/// Convert bytes at position to 32-bit integer
/// </summary>
/// <param name="data">Data packet</param>
/// <param name="position">position to convert, will be increased with the size of int in bytes</param>
/// <returns>converted integer</returns>
public static int GetInt32(byte[] data, ref int position)
{
byte[] intData = new byte[sizeof(int)];
Array.Copy(data, position, intData, 0, sizeof(int));
position += sizeof(int);
return BitConverter.ToInt32(intData, 0);
}

/// <summary>
/// Convert bytes at position to unsigned 32-bit integer
/// </summary>
/// <param name="data">Data packet</param>
/// <param name="position">position to convert, will be increased with the size of uint in bytes</param>
/// <returns>converted usigned integer</returns>
public static uint GetUInt32(byte[] data, ref int position)
{
byte[] intData = new byte[sizeof(uint)];
Array.Copy(data, position, intData, 0, sizeof(uint));
position += sizeof(uint);
return BitConverter.ToUInt32(intData, 0);
}

/// <summary>
/// Convert bytes at position to 16-bit integer
/// </summary>
/// <param name="data">Data packet</param>
/// <param name="position">position to convert, will be increased with the size of short in bytes</param>
/// <returns>converted short integer</returns>
public static short GetShort(byte[] data, ref int position)
{
byte[] shortData = new byte[sizeof(short)];
Array.Copy(data, position, shortData, 0, sizeof(short));
position += sizeof(short);
return BitConverter.ToInt16(shortData, 0);
}

/// <summary>
/// Convert bytes at position to unsigned 16-bit integer
/// </summary>
/// <param name="data">Data packet</param>
/// <param name="position">position to convert, will be increased with the size of ushort in bytes</param>
/// <returns>converted ushort integer</returns>
public static ushort GetUShort(byte[] data, ref int position)
{
byte[] shortData = new byte[sizeof(ushort)];
Array.Copy(data, position, shortData, 0, sizeof(ushort));
position += sizeof(ushort);
return BitConverter.ToUInt16(shortData, 0);
}

/// <summary>
/// Convert bytes at position to 64-bit integer
/// </summary>
/// <param name="data">Data packet</param>
/// <param name="position">position to convert, will be increased with the size of long in bytes</param>
/// <returns>converted long integer</returns>
public static long GetLong(byte[] data, ref int position)
{
byte[] longData = new byte[sizeof(long)];
Array.Copy(data, position, longData, 0, sizeof(long));
position += sizeof(long);
return BitConverter.ToInt64(longData, 0);
}

/// <summary>
/// Convert bytes at position to unsigned 64-bit integer
/// </summary>
/// <param name="data">Data packet</param>
/// <param name="position">position to convert, will be increased with the size of long in bytes</param>
/// <returns>converted ulong integer</returns>
public static ulong GetULong(byte[] data, ref int position)
{
byte[] longData = new byte[sizeof(ulong)];
Array.Copy(data, position, longData, 0, sizeof(ulong));
position += sizeof(ulong);
return BitConverter.ToUInt64(longData, 0);
}

/// <summary>
/// Convert bytes at position to 32-bit float
/// </summary>
/// <param name="data">Data packet</param>
/// <param name="position">position to convert, will be increased with the size of float in bytes</param>
/// <returns>converted float integer</returns>
public static float GetFloat(byte[] data, ref int position)
{
byte[] floatData = new byte[sizeof(float)];
Array.Copy(data, position, floatData, 0, sizeof(float));
position += sizeof(float);
return BitConverter.ToSingle(floatData, 0);
}

/// <summary>
/// Convert bytes at position to 64-bit float
/// </summary>
/// <param name="data">Data packet</param>
/// <param name="position">position to convert, will be increased with the size of double in bytes</param>
/// <returns>converted double integer</returns>
public static double GetDouble(byte[] data, ref int position)
{
byte[] doubleData = new byte[sizeof(double)];
Array.Copy(data, position, doubleData, 0, sizeof(double));
position += sizeof(double);
return BitConverter.ToInt64(doubleData, 0);
}

/// <summary>
/// Convert bytes at position to a sPoint (3 float values)
/// </summary>
/// <param name="data">Data packet</param>
/// <param name="position">position to convert, will be increased with the size of three floats in bytes</param>
/// <returns>struct of sPoint with 3 float values for x,y,z</returns>
public static Point GetPoint(byte [] data, ref int position)
{
Point point;
byte[] pointData = new byte[sizeof(float) * 3];
Array.Copy(data, position, pointData, 0, sizeof(float) * 3);
point.X = BitConverter.ToSingle(pointData, 0);
point.Y = BitConverter.ToSingle(pointData, 4);
point.Z = BitConverter.ToSingle(pointData, 8);
position += sizeof(float) * 3;
return point;
}
}
}
35 changes: 35 additions & 0 deletions Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RTClientSDK")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Qualisys AB")]
[assembly: AssemblyProduct("RTClientSDK")]
[assembly: AssemblyCopyright("Copyright © Qualisys 2014-2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5c1a8afb-7a99-42ed-9923-e7611153de0b")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.12.*")]

0 comments on commit 4669b3b

Please sign in to comment.