TobiiGlasses2SDK
sources/TobiiSDK/TobiiGlasses2SDK/src/TobiiGlassesSDK.h
Go to the documentation of this file.
00001 /******************************************************
00002  * This is a port in C++11 of the Tobii Glasses 2 SDK *
00003  * This will ensure an easy access to the Tobii Glass *
00004  * Author: Pierre-Marie Plans                         *
00005  * E-mail: pierre.plans@gmail.com                     *
00006  ******************************************************/
00007 
00008 #ifndef TOBIISDK_H_
00009 #define TOBIISDK_H_
00010 
00018 #define TOBII_LIVE_ON_WINDOW 0x01
00019 #define TOBII_LIVE_ON_OPENCV 0x02
00020 
00021 #include "Network.h"
00022 #include "Streamer.h"
00023 #include <map>
00024 #include <functional>
00025 #include <jaula.h> // uses libfl-dev
00026 
00032 namespace Tobii {
00033         static const short DATAROW_EYEL_PC_FILLED = 0x0001; 
00034         static const short DATAROW_EYEL_PD_FILLED = 0x0002; 
00035         static const short DATAROW_EYEL_GD_FILLED = 0x0004; 
00036         static const short DATAROW_EYER_PC_FILLED = 0x0008; 
00037         static const short DATAROW_EYER_PD_FILLED = 0x0010; 
00038         static const short DATAROW_EYER_GD_FILLED = 0x0020; 
00039         static const short DATAROW_GP2_FILLED = 0x0040; 
00040         static const short DATAROW_GP3_FILLED = 0x0080; 
00041         static const short DATAROW_GY_FILLED = 0x0100; 
00042         static const short DATAROW_AC_FILLED = 0x0200; 
00043         static const short DATAROW_FIXATION_FILLED = 0x00FF; 
00044         static const short DATAROW_FILLED = 0x03FF; 
00046         static const char DATA_IS_TRACKING = 0x01; 
00047         static const char DATA_IS_FRAME = 0x02; 
00048         static const char DATA_IS_SYNC = 0x04; 
00052         struct Eye {
00053                 float pupilCenter[3]; 
00054                 float pupilDiameter; 
00055                 float gazeDirection[3]; 
00056         };
00060         struct DataRow {
00061                 int64_t ts; 
00062                 short check_flags; 
00063                 Eye left; 
00064                 Eye right; 
00065                 float gazePosition2D[2]; 
00066                 float gazePosition3D[3]; 
00067                 float gyroscope[3]; 
00068                 float accelerometer[3]; 
00069                 DataRow() {
00070                         check_flags = 0x0000; // we will set the flags to 0 here.
00071                 }
00072         };
00078         struct DataRowFrame {
00079                 int64_t pts; 
00080                 cv::Mat frame; 
00081                 DataRowFrame(int64_t _pts, cv::Mat _frame) {
00082                         pts = _pts;
00083                         frame = _frame;
00084                 }
00085         };
00086         
00090         struct Data {
00091                 std::map<int64_t, DataRowFrame> bufferFrames; 
00092                 std::map<int64_t, DataRow> bufferData; 
00093                 int64_t lastSyncTS;
00094                 int64_t lastSyncPTS;
00095         };
00096 
00106         class GlassesSDK {
00107                 // attributes, flags
00108                 private:
00109                         std::string m_IPAddress;        
00110                         int m_port;     
00111                         Network m_udpNw;        
00112                         Streamer m_videoStreamer;       
00113                         bool m_isRunning;       
00114                         bool m_isStreaming;     
00115                         std::function< void(std::string &) > m_dataCallback;    
00116                         std::function< void(Data & data, unsigned int sizeBuffer, const char flag) > m_dataFilledCallback;      
00117                         Data m_data;    
00118                         unsigned int m_data_size;       
00119                 public:
00120                         static const char HTTP_HEADER_JSON = 0x01;      
00122                 // methods, constructors and destructors
00123                 private:
00124 
00135                         int post_request(const std::string & url,const std::string & data, std::string & response, char flags = 0x00);
00146                         void send_keepalive_msg(int socket, const std::string msg, const char * glassesIPAddress, int port);
00154                         void setIsRunning(bool);
00162                         void setIsStreaming(bool);
00170                         void onDataArrived(const std::string &);
00179                         void onFrameArrived(const int64_t pts, cv::Mat & frame);
00180 
00181                 public:
00187                         GlassesSDK(const char * glassesIPAddress = "192.168.71.50", unsigned int bufferSize = 10);
00191                         ~GlassesSDK();
00192 
00200                         void setVideoCallback(std::function< void(cv::Mat &, const int64_t) > func);
00208                         void setDataCallback(std::function< void(std::string &) > );
00218                         void setDataFilledCallback(std::function<void(Data & data, unsigned int sizeBuffer, char flag)>);
00227                         bool discovery(bool setSyncDate);
00235                         void livestream(int flag);
00236 
00244                         static uint64_t getTimeStamp();
00253                         static void timestamp2date(uint64_t t, std::string &);
00262                         static void date2timestamp(const std::string & datestr, uint64_t * t);
00268                         void showServices();
00276                         std::string listProjects();
00285                         std::string createParticipant(const char * project_id);
00295                         std::string createCalibration(const char * project_id, const char * participant_id);
00304                         std::string startCalibration(const char * calibration_id);
00313                         std::string stopCalibration(const char * calibration_id);
00324                         std::string wait_for_status(const std::string & api_action,const std::string & key, const std::vector<std::string> & refvals);
00333                         bool calibrate(const std::string & calibration_id);
00341                         std::string listRecordings();
00350                         std::string showRecording(const char * recording_id);
00359                         std::string createRecording(const char * participant_id);
00368                         std::string startRecording(const char * recording_id);
00377                         std::string stopRecording(const char * recording_id);
00383                         void stopLiveStream();
00389                         static void JAULA_traverse(JAULA::Value * val, int level = 0);
00390         };
00391 }
00392 #endif
 All Classes Namespaces Files Functions Variables