// ECTrainer1Dlg.h : ヘッダー ファイル
//
#pragma once
#include <winsock2.h>
#include <ws2tcpip.h>
#include "myOpenCV.h"
//#define ADDR "192.168.71.50"
#define ADDR "192.168.23.158"
const std::string KA_DATA_MSG = "{\"type\": \"live.data.unicast\", \"key\": \"some_GUID\", \"op\": \"start\"}";
// CECTrainer1Dlg ダイアログ
class CECTrainer1Dlg : public CDialogEx
{
// コンストラクション
public:
CECTrainer1Dlg(CWnd* pParent = nullptr); // 標準コンストラクター
// ダイアログ データ
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_ECTRAINER1_DIALOG };
#endif
// 実装
protected:
static const int PORT = 49152; //The port on which to listen for incoming data
static const int BUFLEN = 512; //Max length of buffer
static const int FRAMES = 2;
HICON _hIcon;
bool _bRunning;
CWinThread* _pCameraThread;
CWinThread* _pImageThread;
CWinThread* _pTargetThread;
CWinThread* _pKeepAliveThread;
CWinThread* _pDataThread;
SOCKET _socket;
struct sockaddr_in _socketAddr;
Point2f _gpC;
Point2f _gpW;
Mat _frames[FRAMES];
int _write, _read;
// 生成された、メッセージ割り当て関数
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV サポート
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
void ShowImage(int id, Mat &img);
bool StartImageThreads();
bool StartDataThreads();
public:
static UINT CallCameraThreadProc(LPVOID pParam);
static UINT CallImageThreadProc(LPVOID pParam);
static UINT CallTargetThreadProc(LPVOID pParam);
static UINT CallKeepAliveThreadProc(LPVOID pParam);
static UINT CallDataThreadProc(LPVOID pParam);
void CameraThreadProc();
void ImageThreadProc();
void TargetThreadProc();
void KeepAliveThreadProc();
void DataThreadProc();
afx_msg void OnClose();
};
//
struct GazeData {
long ts = 0;
int s = 0;
int gidx = 0;
int l = 0;
Point2f gp;
Point3f gdr;
Point3f gdl;
bool isGP = false;
bool isGDR = false;
bool isGDL = false;
GazeData(char* str) {
char* pts = strstr(str, "\"ts\"");
if (pts) ts = atol(pts + 5);
else pts = str;
char* ps = strstr(pts + 5, "\"s\"");
if (ps) s = atoi(ps + 4);
else ps = str;
char* pgidx = strstr(ps + 4, "\"gidx\"");
if (pgidx) gidx = atoi(pgidx + 7);
else pgidx = str;
char* pl = strstr(pgidx + 7, "\"l\"");
if (pl) {
l = atoi(pl + 4);
char* pgp = strstr(pl + 4, "\"gp\"");
if (pgp) {
isGP = true;
gp.x = (float)atof(pgp + 6);
pgp = strchr(pgp + 6, ',');
if (pgp) gp.y = (float)atof(pgp + 1);
}
}
char* pgd = strstr(pgidx, "\"gd\"");
if (pgd) {
if (strstr(pgd, "right") != NULL) {
isGDR = true;
gdr.x = (float)atof(pgd + 6);
pgd = strchr(pgd + 6, ',');
if (pgd) gdr.y = (float)atof(pgd + 1);
else pgd = pgidx;
pgd = strchr(pgd + 1, ',');
if (pgd) gdr.z = (float)atof(pgd + 1);
} else {
isGDL = true;
gdl .x = (float)atof(pgd + 6);
pgd = strchr(pgd + 6, ',');
if (pgd) gdl.y = (float)atof(pgd + 1);
pgd = strchr(pgd + 1, ',');
if (pgd) gdl.z = (float)atof(pgd + 1);
}
}
}
};