SDC C-Project CF Review 프로그램
LYW
2021-06-09 754fa0614469b76fcd789a4f50f9bee59aa09e9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "StdAfx.h"
#include "AlignServerControl.h"
#include "CHReviewResult/AlignResult.h"
#include "IOCPNetwork/NetDefinition.h"
#include "IOCPNetwork/NetServer.h"
 
CAlignServerControl::CAlignServerControl(void)
{
    m_pServerSocket = NULL;
    InitAlignServer();
}
 
CAlignServerControl::~CAlignServerControl(void)
{
    DeinitAlignServer();
}
 
// Align Server
int    CAlignServerControl::InitAlignServer()
{
    if (m_pServerSocket)
    {
        delete m_pServerSocket;
        m_pServerSocket = NULL;
    }
 
    m_pServerSocket = new CNetServer();
 
    if (m_pServerSocket==NULL) return 0;
 
    int nClientCount = 5;
    m_pServerSocket->SetIN2P(static_cast<IIOCPNetwork2Parent*>(this));
    m_pServerSocket->SetClientInfo(Socket_All_Client, nClientCount, NETCODE_ALIGN_SERVER_ALL, NETVER_ALIGN_SERVER_ALL, FALSE);
 
    BOOL bResult = m_pServerSocket->InitNetwork(ServerMode, nClientCount, NETPORT_ALIGN_SERVER_ALL);
 
    return bResult;
}
 
void CAlignServerControl::DeinitAlignServer()
{
    if (m_pServerSocket)
    {
        m_pServerSocket->DeinitNetwork();
        delete m_pServerSocket;
    }
    m_pServerSocket = NULL;
}
 
BOOL CAlignServerControl::SendAlignResult(const CAlignRecipe* pRecipe, const CAlignResult* pResult)
{
    if (m_pServerSocket==NULL) return FALSE;
 
    CNetPacket* pPacket = m_pServerSocket->GetPacket();
 
    if (pPacket && pRecipe && pResult) // normal
    {
        // int
        pPacket->SetInt(pResult->nResultCode);                            // result code ( 1 => success )
        pPacket->SetInt((int)pResult->dFindPixelX[0]);                    // find first mark pixel x
        pPacket->SetInt((int)pResult->dFindPixelY[0]);                    // find first mark pixel y
        pPacket->SetInt((int)pResult->dFindPixelX[1]);                    // find second mark pixel x
        pPacket->SetInt((int)pResult->dFindPixelY[1]);                    // find second mark pixel y
 
        // short
        pPacket->SetShort((short)pRecipe->nCameraDirX[0]);                // first cam x dir
        pPacket->SetShort((short)pRecipe->nCameraDirY[0]);                // first cam y dir
        pPacket->SetShort((short)pRecipe->nCameraDirX[1]);                // second cam x dir
        pPacket->SetShort((short)pRecipe->nCameraDirY[1]);                // second cam y dir
 
        // double
        pPacket->SetDouble(pRecipe->dCameraResolution[0]);                // first cam resolution
        pPacket->SetDouble(pRecipe->dCameraResolution[1]);                // second cam resolution
 
        //        CString str1stAlignPath = g_pSetting->m_strResultImagePath + _T("\\") + m_strCurrentPPID + _T("\\") + m_strAlignFirstCutFile;
        //        CString str2ndAlignPath = g_pSetting->m_strResultImagePath + _T("\\") + m_strCurrentPPID + _T("\\") + m_strAlignSecondCutFile;
        //        pPacket->SetString(str1stAlignPath);                                        // First 얼라인 파일 경로 및 이름
        //        pPacket->SetString(str2ndAlignPath);                                        // Second 얼라인 파일 경로 및 이름
 
        return m_pServerSocket->InvokeToClient(AC_ALIGN_RESULT, NET_RESULT_SUCCESS, pPacket);
    }
    
    return m_pServerSocket->InvokeToClient(AC_ALIGN_RESULT, NET_RESULT_FAIL);
}
 
void CAlignServerControl::SetAlignResult(const CAlignRecipe* pRecipe, const CAlignResult* pResult)
{
    if (pRecipe && pResult) // normal
    {
        m_nResultCode                = pResult->nResultCode;
        m_dFirstOriginPixelX        = pRecipe->dOriginPixelX[0];
        m_dFirstOriginPixelY        = pRecipe->dOriginPixelY[0];
        m_dSecondOriginPixelX        = pRecipe->dOriginPixelX[1];
        m_dSecondOriginPixelY        = pRecipe->dOriginPixelY[1];
        m_dFirstFindPixelX            = pResult->dFindPixelX[0];
        m_dFirstFindPixelY            = pResult->dFindPixelY[0];
        m_dSecondFindPixelX            = pResult->dFindPixelX[1];
        m_dSecondFindPixelY            = pResult->dFindPixelY[1];
 
        m_nFirstCameraDirX            = pRecipe->nCameraDirX[0];
        m_nFirstCameraDirY            = pRecipe->nCameraDirY[0];
        m_nSecondCameraDirX            = pRecipe->nCameraDirX[1];
        m_nSecondCameraDirY            = pRecipe->nCameraDirY[1];
 
        m_dFirstCameraResolution    = pRecipe->dCameraResolution[0];
        m_dSecondCameraResolution    = pRecipe->dCameraResolution[1];
    }
}
 
void CAlignServerControl::IOCPNet2P_Connected(int nType)
{
    g_pLog->DisplayMessage(_T("Align Client Connect! [%d]"), nType);
}
 
void CAlignServerControl::IOCPNet2P_Disconnected(int nType, int nModuleNo)
{
    g_pLog->DisplayMessage(_T("Align Client Disconnected! [%d, %d]"), nType, nModuleNo);
}
 
BOOL CAlignServerControl::IOCPNet2P_Received(int Type, CNetPacket* pPacket, __int64 nContext)
{
    if (Type!=Socket_All_Client) return FALSE;
 
    if(!pPacket) return FALSE;
    
    CNetJoiner* pNetJoiner = NULL;
    
    switch(pPacket->GetPacketCode())
    {
    case CA_MODULE_INDEX:
        g_pLog->DisplayMessage(_T("[%d]NetIOCP2P_Received CA_MODULE_INDEX"), pPacket->GetModuleNo());
        for(int i = 0; i < m_pServerSocket->GetClientCount(); i++)
        {
            pNetJoiner = m_pServerSocket->GetJoinerArray(i);
            if (pNetJoiner && reinterpret_cast<int>(pNetJoiner->GetSocketContext()) == nContext)
            {
                pNetJoiner->SetModuleNo(pPacket->GetModuleNo(), FALSE);
                m_pServerSocket->SendToClient(i, AC_MODULE_INDEX, NET_RESULT_SUCCESS);
            }
        }
        break;
 
    case CA_ALIGN_RESULT:
    case CA_ALIGN_GLASS:
        g_pLog->DisplayMessage(_T("[%d]NetIOCP2P_Received CA_ALIGN_RESULT"), pPacket->GetModuleNo());
        {
            CNetPacket* pSendPacket = m_pServerSocket->GetPacket();
 
            pSendPacket->SetInt(m_nResultCode);
            pSendPacket->SetInt((int)m_dFirstFindPixelX);
            pSendPacket->SetInt((int)m_dFirstFindPixelY);
            pSendPacket->SetInt((int)m_dSecondFindPixelX);
            pSendPacket->SetInt((int)m_dSecondFindPixelY);
 
            pSendPacket->SetShort((short)m_nFirstCameraDirX);
            pSendPacket->SetShort((short)m_nFirstCameraDirY);
            pSendPacket->SetShort((short)m_nSecondCameraDirX);
            pSendPacket->SetShort((short)m_nSecondCameraDirY);
 
            pSendPacket->SetDouble(m_dFirstCameraResolution);
            pSendPacket->SetDouble(m_dSecondCameraResolution);
 
            m_pServerSocket->InvokeToClient(AC_ALIGN_RESULT, NET_RESULT_SUCCESS, pSendPacket);
        }
        break;
 
    default:
        break;
    }
 
    return TRUE;
}