# HG changeset patch # User bastiena # Date 1333377056 -7200 # Node ID 4b78f179e7ce9cf280c8ff0c02ffdeb47eaf6dd5 # Parent 10d5199d9874b5d757fabd71c23842d52549ceac Middleware : segmentation of Middleware between 4 modules : Communication Debug Tracking MainModule I chose to integer the events in the mainModule, so I can use them to send data to Debug and Communication. Soon DLLs will be copied to a main root folder "lib". diff -r 10d5199d9874 -r 4b78f179e7ce middleware/Communication/Communication.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/middleware/Communication/Communication.csproj Mon Apr 02 16:30:56 2012 +0200 @@ -0,0 +1,62 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {D8DC5409-6FF4-49CC-BC53-85AE6AE43E91} + Library + Properties + Communication + Communication + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\lib\Microsoft.Kinect.dll + + + + + + + + + + + ..\lib\TuioServer.dll + + + + + + + + + \ No newline at end of file diff -r 10d5199d9874 -r 4b78f179e7ce middleware/Communication/Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/middleware/Communication/Properties/AssemblyInfo.cs Mon Apr 02 16:30:56 2012 +0200 @@ -0,0 +1,36 @@ +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("Communication")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Communication")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[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("3d4ee9d9-0965-40e2-ac20-2e1e4a2c698e")] + +// 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.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff -r 10d5199d9874 -r 4b78f179e7ce middleware/Communication/Server.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/middleware/Communication/Server.cs Mon Apr 02 16:30:56 2012 +0200 @@ -0,0 +1,242 @@ +/* +* This file is part of the TraKERS\Middleware package. +* +* (c) IRI +* +* For the full copyright and license information, please view the LICENSE_MIDDLEWARE +* file that was distributed with this source code. +*/ + +/* + * Projet : TraKERS + * Module : MIDDLEWARE + * Sous-Module : Communication + * Classe : Server + * + * Auteur : alexandre.bastien@iri.centrepompidou.fr + * + * Fonctionnalités : Reçoit des notifications du module sous-module Tracking. + * Traduit les notifications sous forme de messages OSC et les envoie au Front Atelier. + * Forme des messages : + * - Notification de main dans le champ de recherche : Point3D indiquant la position de la main dans l'espace. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using Tuio; +using System.Windows; +using Microsoft.Kinect; +using System.Windows.Media.Media3D; +using System.Timers; +using System.Resources; +using System.Reflection; + +namespace Trakers.Communication +{ + public class Server + { + //Serveur TUIO, provenant de la DLL TuioServer créé par Bespoke. + private TuioServer server; + + //Permet de savoir si un curseur pour la main gauche/droite a été créé. + private bool leftHandCursorCreated; + private bool rightHandCursorCreated; + private bool messageCreated; + private bool gestureLocked, modLocked; + //Intervalle minimum entre les gestures. + private int timerElapsing; + //Timer. + private System.Timers.Timer _timer; + //Dernier code envoyé. + private String lastCode; + + /* + * Constructeur : On initialise le serveur avec une adresse et un port, au début les curseurs + * ne sont pas créés et on indique au ThreadPool une fonction de callback de manière à vérifier + * s'il reçoit des notifications. + */ + public Server(String host, int port, int _timerElapsing) + { + //Au départ, aucune main n'est dans le champ de recherche et aucune gesture n'est détectée. + leftHandCursorCreated = false; + rightHandCursorCreated = false; + messageCreated = false; + gestureLocked = false; + modLocked = false; + lastCode = ""; + + timerElapsing = _timerElapsing; + + //On démarre le serveur TUIO. + server = new TuioServer(host, port); + //On initialise le threadPool (appelé toutes les N ms). + ThreadPool.QueueUserWorkItem(ThreadPoolCallback); + + //On instancie le timer à N ms. + _timer = new System.Timers.Timer(timerElapsing); + //Dès que le timer est expiré, on appelle _timer_Elapsed. + _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed); + } + + /* + * Getter du serveur. + */ + public TuioServer getServer() + { + return server; + } + + /* + * Méthode appelée à l'expiration du timer pour les gestures et modes. + */ + public void _timer_Elapsed(object sender, ElapsedEventArgs e) + { + //On débloque la détection de gesture. + gestureLocked = false; + //On débloque la notification de nouveau mode. + modLocked = false; + //On arrête le timer. + _timer.Stop(); + } + + /* + * Méthode appelée lors d'une notification de type : main gauche entrée dans le champ. + */ + public void LeftHandTracked(Point3D pt) + { + //Si le curseur de la main gauche n'est pas créé, alors on le crée. + if (!leftHandCursorCreated) + { + server.AddTuioCursor(0, pt); + leftHandCursorCreated = true; + } + //S'il existe, on le met simplement à jour. + else + server.UpdateTuioCursor(0, pt); + } + + /* + * Méthode appelée lors d'une notification de type : main droite entrée dans le champ. + */ + public void RightHandTracked(Point3D pt) + { + //Si le curseur de la main droite n'est pas créé, alors on le crée. + if (!rightHandCursorCreated) + { + server.AddTuioCursor(1, pt); + rightHandCursorCreated = true; + } + //S'il existe, on le met simplement à jour. + else + server.UpdateTuioCursor(1, pt); + } + + /* + * Méthode appelée lors d'une notification de type : main gauche sortie du champ. + */ + public void LeftHandQuit() + { + //Si le curseur de la main gauche existe, alors on le supprime. + if (leftHandCursorCreated) + { + server.DeleteTuioCursor(0); + leftHandCursorCreated = false; + } + } + + /* + * Méthode appelée lors d'une notification de type : main droite sortie du champ. + */ + public void RightHandQuit() + { + //Si le curseur de la main droite existe, alors on le supprime. + if (rightHandCursorCreated) + { + server.DeleteTuioCursor(1); + rightHandCursorCreated = false; + } + } + + /* + * Méthode appelée lorsqu'une gesture a été détectée et que l'événement approprié a été lancé. + */ + public void GesturePerformed(String code) + { + //Si le code vient d'être envoyé, on passe. + if (lastCode.Equals(code)) + return; + lastCode = code; + //Si une gesture a été effectuée, on bloque un certain temps. + if (!gestureLocked) + { + gestureLocked = true; + + //On crée un message contenant le code à envoyer. + if (!messageCreated) + { + messageCreated = true; + server.AddTuioString(2, code); + //On démarre le timer. + _timer.Start(); + } + } + } + + /* + * Méthode appelée lorsqu'on doit entrer dans un autre mode. + */ + public void ModeNotification(String code) + { + //Si le code vient d'être envoyé, on passe. + if (lastCode.Equals(code)) + return; + lastCode = code; + //Si on a été notifié. + if (!modLocked) + { + modLocked = true; + + //On crée un message contenant le code à envoyer. + if (!messageCreated) + { + messageCreated = true; + server.AddTuioString(2, code); + //On démarre le timer. + _timer.Start(); + } + } + } + + /* + * Méthode de callback vérifiant toutes les 25 ms les nouvelles notifications. + * Il est à noter que si le temps de rafraîchissement des trop rapide, les messages n'ont pas + * le temps d'être envoyés. + */ + private void ThreadPoolCallback(Object threadContext) + { + while (true) + { + //On initialise le message OSC. + server.InitFrame(); + //On l'envoie au client (au host et au port spécifiés dans le constructeur). + server.CommitFrame(); + //On attend 25 ms. + Thread.Sleep(25); + + //Si une gesture a été effectuée et que le délai d'attente est expiré. + if (messageCreated && !gestureLocked && !modLocked) + { + //On débloque la détection de gesture et on supprime l'objet envoyant les messages OSC de gesture. + messageCreated = false; + server.DeleteTuioString(2); + } + } + } + } +} diff -r 10d5199d9874 -r 4b78f179e7ce middleware/Debug/App.config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/middleware/Debug/App.config Mon Apr 02 16:30:56 2012 +0200 @@ -0,0 +1,110 @@ + + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + 1 + + + + + 1 + + + + + + + 1.5 + + + 1 + + + 3.2 + + + 1.8 + + + 127.0.0.1 + + + 80 + + + 1000 + + + 25 + + + 10 + + + 10 + + + 0.01 + + + + + 1.5 + + + 1 + + + 3.2 + + + 1.8 + + + 127.0.0.1 + + + 80 + + + 1000 + + + 25 + + + 10 + + + 10 + + + 0.01 + + + + \ No newline at end of file diff -r 10d5199d9874 -r 4b78f179e7ce middleware/Debug/Debug.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/middleware/Debug/Debug.csproj Mon Apr 02 16:30:56 2012 +0200 @@ -0,0 +1,154 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {EC766553-473F-4865-84E9-88F79D5F12A9} + Library + Properties + Trakers.Debug + Debug + v4.0 + 512 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + True + + + ..\lib\Coding4Fun.Kinect.Wpf.dll + + + False + ..\lib\Microsoft.Kinect.dll + + + + + + + + + + + + + + + + + + + DebugParameters.xaml + + + DebugWindow.xaml + + + + Resources.resx + True + PreserveNewest + True + + + True + True + Settings.settings + + + + + + MSBuild:Compile + Designer + + + + + MSBuild:Compile + Designer + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + ResXFileCodeGenerator + Resources.Designer.cs + PreserveNewest + + + + + False + Microsoft .NET Framework 4 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 3.1 + true + + + + + \ No newline at end of file diff -r 10d5199d9874 -r 4b78f179e7ce middleware/Debug/Debug.csproj.user --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/middleware/Debug/Debug.csproj.user Mon Apr 02 16:30:56 2012 +0200 @@ -0,0 +1,13 @@ + + + + publish\ + + + + + + en-US + false + + \ No newline at end of file diff -r 10d5199d9874 -r 4b78f179e7ce middleware/Debug/DebugParameters.xaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/middleware/Debug/DebugParameters.xaml Mon Apr 02 16:30:56 2012 +0200 @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +