#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(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(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; }