non-blocking socket client Posted by 빵빵빵 2009/04/11 16:13 분류없음 분류없음 // MiddleWare.h: interface for the CMiddleWare class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_MIDDLEWARE_H__45E65263_9FEF_4B08_986A_34A67347C085__INCLUDED_) #define AFX_MIDDLEWARE_H__45E65263_9FEF_4B08_986A_34A67347C085__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "winsock.h" typedef struct tagHEADERFRAME { BYTE cStx; BYTE cLen[2]; BYTE cCmd; BYTE cCnt; } HEADERFRAME; typedef struct tagTAILFRAME { BYTE cEtx; BYTE cLRC; } TAILFRAME; // 인원승인이력 typedef struct tagIF_APPROVE_LABOR { // Serial Number(2) BYTE cSN[2]; BYTE cTab0; // 사원번호/주민번호(14) BYTE cJUMIN_NO[14]; BYTE cTab1; // 성명(20) BYTE cLBR_NAME[20]; BYTE cTab2; // RF Tag(10) BYTE cTAG_NO[10]; BYTE cTab3; // 승인 시작일(8) BYTE cAPP_FROM[8]; BYTE cTab4; // 승인 종료일(8) BYTE cAPP_TO[8]; BYTE cTab5; // 장기인원,단기인원,임직원(10) BYTE cLS_GBN[10]; BYTE cTab6; // 업체명/팀명(20) BYTE cCO_NAME[20]; BYTE cTab7; // 출입가능한 출입문(20) BYTE cAPP_GATE[20]; BYTE cTab8; // 승인상태(U:사용, B:출입불가, S:출입정지)(1) BYTE cAPP_YN; } IF_APPROVE_LABOR; // 인원승인조회 typedef struct tagIF_APPROVE_LABOR_INQ { // Serial Number(2) BYTE cSN[2]; BYTE cTab0; // 사원번호/주민번호(14) BYTE cJUMIN_NO[14]; BYTE cTab1; // 성명(20) BYTE cLBR_NAME[20]; BYTE cTab2; // RF Tag(10) BYTE cTAG_NO[10]; BYTE cTab3; // 승인 시작일(8) BYTE cAPP_FROM[8]; BYTE cTab4; // 승인 종료일(8) BYTE cAPP_TO[8]; BYTE cTab5; // 장기인원,단기인원,임직원(10) BYTE cLS_GBN[10]; BYTE cTab6; // 업체명/팀명(20) BYTE cCO_NAME[20]; BYTE cTab7; // 출입가능한 출입문(20) BYTE cAPP_GATE[20]; BYTE cTab8; // 승인상태(U:사용, B:출입불가, S:출입정지)(1) BYTE cAPP_YN; } IF_APPROVE_LABOR_INQ; // 차량승인이력 typedef struct tagIF_APPROVE_CAR { // Serial Number(2) BYTE cSN[2]; BYTE cTab0; // 차량번호(12) BYTE cCAR_NUMBER[12]; BYTE cTab1; // 차량명(예:소나타)(20) BYTE cCAR_NAME[20]; BYTE cTab2; // 차량코드(7) BYTE cCAR_NO[7]; BYTE cTab3; // 승인시작일(8) BYTE cAPP_FROM[8]; BYTE cTab4; // 승인종료일(8) BYTE cAPP_TO[8]; BYTE cTab5; // 차량구분코드(8) BYTE cCAPV_TYPE[8]; BYTE cTab6; // 업체명/팀명(20) BYTE cCO_NAME[20] ; BYTE cTab7; // 운전자코드(주민번호/사번)(15) BYTE cDRV_CODE[15]; BYTE cTab8; // 운전자명(20) BYTE cDRV_NAME[20]; BYTE cTab9; // 출입가능한문(20) BYTE cAPP_GATE[20]; BYTE cTab10; // 승인상태(1) BYTE cAPP_YN; } IF_APPROVE_CAR; // 차량승인조회 typedef struct tagIF_APPROVE_CAR_INQ { // Serial Number(2) BYTE cSN[2]; BYTE cTab0; // 차량번호(12) BYTE cCAR_NUMBER[12]; BYTE cTab1; // 차명(20) BYTE cCAR_NAME[20]; BYTE cTab2; // 차량코드(7) BYTE cCAR_NO[7]; BYTE cTab3; // 승인시작일(8) BYTE cAPP_FROM[8]; BYTE cTab4; // 승인종료일(8) BYTE cAPP_TO[8]; BYTE cTab5; // 차량구분코드(8) BYTE cCAPV_TYPE[8]; BYTE cTab6; // 업체명/팀명(20) BYTE cCO_NAME[20] ; BYTE cTab7; // 운전자코드/주민번호/사번(15) BYTE cDRV_CODE[15]; BYTE cTab8; // 운전자명(20) BYTE cDRV_NAME[20]; BYTE cTab9; // 출입가능한문(20) BYTE cAPP_GATE[20]; BYTE cTab10; // 승인상태(1) BYTE cAPP_YN; } IF_APPROVE_CAR_INQ; // 인원출입기록 typedef struct tagIF_IO_LABOR { // Serial Number(2) BYTE cSN[2]; BYTE cTab0; // 바코드(10) BYTE cBARCODE[10]; BYTE cTab1; // 출입일자(10) BYTE cIO_DATE[10]; BYTE cTab2; // 출입시간(10) BYTE cIO_TIME[10]; BYTE cTab3; // 출입구분(I:입,O:출)(10) BYTE cIO_FLAG[10]; BYTE cTab4; // GATE장비 코드(00:Handy, 나머지는 Gate별 장비코드)(10) BYTE cCTL_ID[10]; BYTE cTab5; // GATE코드(10) BYTE cGATE_ID[10]; BYTE cTab6; // 인가여부(1) BYTE cIO_APP; BYTE cTab7; // 비인가사유-출입불가,출입정지,미등록,기간경과,통행불가(20) BYTE cIO_COMMENT[20]; } IF_IO_LABOR; // 차량출입기록 typedef struct tagIF_IO_CAR { // Serial Number(2) BYTE cSN[2]; BYTE cTab0; // 차량번호(15) BYTE cCAR_NO[15]; BYTE cTab1; // 출입일자(8) BYTE cIO_DATE[8]; BYTE cTab2; // 출입시간(6) BYTE cIO_TIME[6]; BYTE cTab3; // 출입구분(I:입,O:출)(1) BYTE cIO_FLAG; BYTE cTab4; // GATE장비코드(2) BYTE cCTL_ID[2]; BYTE cTab5; // GATE코드(2) BYTE cGATE_ID[2]; BYTE cTab6; // 인증여부(1) BYTE cIO_APP; BYTE cTab7; // 비인가 사유-판독불가,미등로,기간경과(20) BYTE cIO_COMMENT[20]; BYTE cTab8; // 차량구분-장기차량,단기차량,회사차량,직원차량,방문차량(8) BYTE cLS_GBN[8]; BYTE cTab9; // 업체명/팀명(20) BYTE CO_NAME[20]; BYTE cTab10; // 차량명(예:소나타)(20) BYTE cCAR_NAME[20]; } IF_IO_CAR; // 게이트코드 typedef struct tagVW_SET_HANDY_GATE { // GateCode(2) BYTE cGATE_CODE[2]; BYTE cTab0; // GateName (20) BYTE cGATE_NAME[20]; } VW_SET_HANDY_GATE; #define HEADERFRAME_SIZE sizeof( HEADERFRAME ) #define TAILFRAME_SIZE sizeof( TAILFRAME ) #define IF_APPROVE_LABOR_SIZE sizeof( IF_APPROVE_LABOR ) #define IF_APPROVE_CAR_SIZE sizeof( IF_APPROVE_CAR ) #define IF_APPROVE_LABOR_INQ_SIZE sizeof( IF_APPROVE_LABOR_INQ ) #define IF_APPROVE_CAR_INQ_SIZE sizeof( IF_APPROVE_CAR_INQ ) #define IF_IO_LABOR_SIZE sizeof( IF_IO_LABOR ) #define IF_IO_CAR_SIZE sizeof( IF_IO_CAR ) #define VW_SET_HANDY_GATE_SIZE sizeof( VW_SET_HANDY_GATE ) #define NULL_SIZE 1 typedef struct tagReceiveThreadParam { void *pOwner; int *pRtn; BYTE *pRcvBuff; int nRcvBuffSize; int *nRcvLen; } RECEIVETHREADPARAM; #define SetResultApproveLabor( m ) SendMessage( m_hWnd, WM_USER_STATUS, MIDDLEWARE_STATUS_98, ( LPARAM )m ) #define SetResultApproveCar( m ) SendMessage( m_hWnd, WM_USER_STATUS, MIDDLEWARE_STATUS_99, ( LPARAM )m ) #define SetOwnerStatus( m ) SendMessage( m_hWnd, WM_USER_STATUS, MIDDLEWARE_STATUS_1, ( LPARAM )m ) #define SetOwnerStatus2( m ) SendMessage( m_hWnd, WM_USER_STATUS, MIDDLEWARE_STATUS_2, ( LPARAM )m ) #define SetOwnerStatus3( m ) SendMessage( m_hWnd, WM_USER_STATUS, MIDDLEWARE_STATUS_3, ( LPARAM )m ) class CMiddleWare { public: enum { // 인원승인이력 수신 CMD_IF_APPROVE_LABOR = 'A', // 차량승인이력 수신 CMD_IF_APPROVE_CAR = 'C', // 인원승인이력 조회 CMD_IF_APPROVE_LABOR_INQ = 'S', // 차량승인이력 조회 CMD_IF_APPROVE_CAR_INQ = 'D', // 인원출입기록 전송 CMD_IF_IO_LABOR = 'I', // 차량출입기록 전송 CMD_IF_IO_CAR = 'F', // 게이트코드 수신 CMD_VW_SET_HANDY_GATE = 'G', // 수신 갯수 CMD_IF_APPROVE_COUNT = 'E', // 인원승인이력 삭제(사원번호 14 Byte) CMD_IF_APPROVE_LABOR_DELETE = 'X', // 차량승인이력 삭제(차량번호 12 Byte) CMD_IF_APPROVE_CAR_DELETE = 'Z' }; enum { PACKET_DELI = 0x00 }; enum { SOCK_ERROR = SOCKET_ERROR, SOCK_TIME_OUT = ( -2 ), SOCK_THREAD_TIME_OUT = ( -3 ), SOCK_THREAD_ERROR = ( -4 ), SOCK_CANCEL = ( -5 ), }; enum { BUFF_SIZE = 1024, // 1000 msec THREAD_TIME_OUT = 200, TIME_OUT_SEC60 = 60, TIME_OUT_SEC30 = 30, TIME_OUT_SEC10 = 10, RECV_INTERVAL = 200000, // 20msec RECV_RECEIVE_TIMEOUT = 5000000, // 5sec RECV_CONNECT_TIMEOUT = 15000000, // 15sec }; CMiddleWare(); virtual ~CMiddleWare(); CString GetServerIP( ); CString GetServerPort( ); CString GetLastStatus( ) { return ( m_strLastStaus ); }; // 인원승인정보 수신 BOOL IF_APPROVE_LABOR_Rcv( ); // 차량승인정보 수신 BOOL IF_APPROVE_CAR_Rcv( ); // 인원승인정보 조회 BOOL IF_APPROVE_LABOR_Inq( CString strJuminNo ); // 차량승인정보 조회 BOOL IF_APPROVE_CAR_Inq( CString strCarNo ); // 인원출입기록 전송 BOOL IF_IO_LABOR_Send( ); // 차량출입기록 전송 BOOL IF_IO_CAR_Send( ); // 게이트코드 수신 BOOL VW_SET_HANDY_GATE_Rcv( ); BOOL SendReceive( BYTE *pSendBuff, int nSendLen, BYTE *pRcvBuff, int *nRcvLen, BOOL bHangUp = FALSE ); BOOL Dial( ); BOOL HangUp( ); int Send( BYTE *pSendBuff, int nLen ); int Receive( BYTE *pRcvBuff, int nRcvBuffSize, int *nRcvLen = NULL ); int ReceiveThread( BYTE *pRcvBuff, int nRcvBuffSize, int *nRcvLen = NULL ); void Cancel( BOOL bCancel = TRUE ) { m_bCancel = bCancel; }; BOOL IsConnected( ) { return ( m_bConnected ); }; void SetOwner( HWND hWnd ) { m_hWnd = hWnd; }; static CMiddleWare *Instance( ) { static CMiddleWare _instance; return ( &_instance ); }; BOOL Connect( TCHAR *szHostIP, int nPort ); BOOL Connect( ); void DisConnect( ); private: BOOL AckNak( BOOL bNak = FALSE ); int MakeFrame( BYTE cCnt, BYTE cCmd, BYTE *szParam, int nParamLen, BYTE *pFrameBuf ); void MakeLRC( BYTE *p, BYTE *cLRC, int nLen ); CString m_strServerIP; CString m_strServerPort; int m_hSock; BOOL m_bConnected; HWND m_hWnd; CString m_strLastStaus; BOOL m_bCancel; }; #endif // !defined(AFX_MIDDLEWARE_H__45E65263_9FEF_4B08_986A_34A67347C085__INCLUDED_) // MiddleWare.cpp: implementation of the CMiddleWare class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "AccessCtl.h" #include "MiddleWare.h" #include "RasDialer.h" #include "vLib.h" #include "vLog.h" #include "constant.h" #include "DlgMessage.h" #include "d2sLib.h" #include "cdbman.h" #include "dlgSendRcv.h" #include "DlgSearchResult.h" #include "DlgSearchResultCar.h" #include "RegistryEx.h" #include "DlgRas.h" #include "DlgConfig.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CMiddleWare::CMiddleWare() { m_strServerIP = GetServerIP( ); m_strServerPort = GetServerPort( ); m_hSock = INVALID_SOCKET; m_bConnected = FALSE; m_hWnd = NULL; m_strLastStaus = _T( "" ); Cancel( FALSE ); } CMiddleWare::~CMiddleWare() { DisConnect( ); } // P(PDA), S(Server) // P->S : A // S->P : E (전체개수 (승인+삭제)) // S->P : A (반복) // S->P : X (반복 // 인원승인이력 수신 BOOL CMiddleWare::IF_APPROVE_LABOR_Rcv( ) { vLib_Log( _T( "[시작]CMiddleWare::IF_APPROVE_LABOR_Rcv\n" ) ); HEADERFRAME stHeader; BYTE szParam[32]; BYTE cSendBuff[64]; BYTE cRcvBuff[512 + 32]; int nSendLen = 0; int nRcvLen = 0; // 인원승인이력 갯수 요청 // LastRcvTime(8) int nRecordCount = CCDBMan::Instance( )->GetRecordCount( DB_IF_APPROVE_LABOR_TABLE_NAME ); CString strLastRcvTime; strLastRcvTime = CDlgConfig::GetLastRcvTime( ); if ( strLastRcvTime.GetLength( ) < 10 || nRecordCount <= 0 ) { sprintf( ( char * )szParam, "%s", "00000000" ); } else { CVLib::Instance()->vLib_UtoA( ( char * )&cSendBuff[0], strLastRcvTime ); szParam[0] = cSendBuff[0]; szParam[1] = cSendBuff[1]; szParam[2] = cSendBuff[2]; szParam[3] = cSendBuff[3]; szParam[4] = cSendBuff[5]; szParam[5] = cSendBuff[6]; szParam[6] = cSendBuff[8]; szParam[7] = cSendBuff[9]; } // sprintf( ( char * )szParam, "%s", "00000000" ); // Make Frame nSendLen = MakeFrame( 0x01, CMD_IF_APPROVE_LABOR, szParam, 8, cSendBuff ); if ( Send( cSendBuff, nSendLen ) != nSendLen ) { m_strLastStaus = _T( "인원승인이력 갯수 요청 전송 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Rcv - 인원승인이력 갯수 요청 전송 실패" ) ); return ( FALSE ); } int nRcvStatus = Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ); if ( nRcvStatus > 0 ) { memcpy( ( void * )&stHeader, ( void * )&cRcvBuff[0], HEADERFRAME_SIZE ); if ( stHeader.cCmd == CMD_IF_APPROVE_COUNT ) { WORD wCount = GET_WORD_VALUE( cRcvBuff[HEADERFRAME_SIZE], cRcvBuff[HEADERFRAME_SIZE + 1] ); vLib_Log( _T( "CMiddleWare::IF_APPROVE_LABOR_Rcv - 인원승인이력 갯수 수신 = [%d]" ), wCount ); if ( AckNak( ) ) { vLib_Log( _T( "CMiddleWare::IF_APPROVE_LABOR_Rcv - 인원승인이력 수신 시작" ) ); CADORecordset rs( &CCDBMan::Instance()->m_db ); CADORecordset rsd( &CCDBMan::Instance()->m_db ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.Open( rs ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.Open( rsd ); CString strMsg; strMsg.Format( _T( "%d/%d" ), 1, wCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); for ( int i = 0; i < wCount; ) { nRcvStatus = Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ); if ( nRcvStatus > 0 ) { memcpy( ( void * )&stHeader, ( void * )&cRcvBuff[0], HEADERFRAME_SIZE ); i += stHeader.cCnt; strMsg.Format( _T( "%d/%d" ), i, wCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); IF_APPROVE_LABOR *pstIF_APPROVE_LABOR; BYTE *p = ( BYTE * )&cRcvBuff[HEADERFRAME_SIZE]; // 인원승인이력 if ( stHeader.cCmd == CMD_IF_APPROVE_LABOR ) { if ( AckNak( ) ) { for ( int j = 0; j < stHeader.cCnt; j++ ) { pstIF_APPROVE_LABOR = ( IF_APPROVE_LABOR * )p; CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strJUMIN_NO = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_LABOR->cJUMIN_NO[0], sizeof( pstIF_APPROVE_LABOR->cJUMIN_NO ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strLBR_NAME = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_LABOR->cLBR_NAME[0], sizeof( pstIF_APPROVE_LABOR->cLBR_NAME ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strTAG = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_LABOR->cTAG_NO[0], sizeof( pstIF_APPROVE_LABOR->cTAG_NO ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strAPP_FROM = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_LABOR->cAPP_FROM[0], sizeof( pstIF_APPROVE_LABOR->cAPP_FROM ), CVLib::TRIM_RIGHT ); // TRACE( _T( "%s%s%s\n" ), CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strJUMIN_NO, // CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strLBR_NAME, // CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strTAG ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strAPP_TO = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_LABOR->cAPP_TO[0], sizeof( pstIF_APPROVE_LABOR->cAPP_TO ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strLS_GBN = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_LABOR->cLS_GBN[0], sizeof( pstIF_APPROVE_LABOR->cLS_GBN ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strCO_NAME = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_LABOR->cCO_NAME[0], sizeof( pstIF_APPROVE_LABOR->cCO_NAME ), CVLib::TRIM_RIGHT ); // CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strADDR = // CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strHEIGHT = // CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strWEIGHT = // CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strJIKWI = // CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strTEL = // CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strCHG_DATE = // CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strDEL_YN = CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strAPP_GATE = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_LABOR->cAPP_GATE[0], sizeof( pstIF_APPROVE_LABOR->cAPP_GATE ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strAPP_YN = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_LABOR->cAPP_YN, sizeof( pstIF_APPROVE_LABOR->cAPP_YN ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.Delete( rsd ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.Add( rs ); p += IF_APPROVE_LABOR_SIZE; p += NULL_SIZE; } } else { m_strLastStaus = _T( "인원승인이력 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Rcv - 인원승인이력 수신 실패" ) ); return ( FALSE ); } } // 인원승인이력 삭제 else if ( stHeader.cCmd == CMD_IF_APPROVE_LABOR_DELETE ) { if ( AckNak( ) ) { for ( int j = 0; j < stHeader.cCnt; j++ ) { CCDBMan::Instance()->m_IF_APPROVE_LABOR.m_strJUMIN_NO = CVLib::Instance( )->GetColumnValue( ( const char * )p, sizeof( pstIF_APPROVE_LABOR->cJUMIN_NO ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_LABOR.Delete( rs ); // 주민번호(14) + NULL_SIZE(1) p += ( sizeof( pstIF_APPROVE_LABOR->cJUMIN_NO ) + NULL_SIZE ); } } else { m_strLastStaus = _T( "인원승인이력 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Rcv - 인원승인이력 수신 실패" ) ); return ( FALSE ); } } } else { if ( nRcvStatus == SOCK_CANCEL ) { m_strLastStaus = _T( "인원승인이력 수신 취소" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Rcv - 인원승인이력 수신 취소" ) ); } else { m_strLastStaus = _T( "인원승인이력 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Rcv - 인원승인이력 수신 실패" ) ); } return ( FALSE ); } } m_strLastStaus = _T ( "인원승인이력 수신 완료" ); } } else { m_strLastStaus = _T( "인원승인이력 잘못된 이력 수신" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Rcv - 인원승인이력 갯수 수신 실패, stHeader.cCmd = [%c][%d][0x%08x]" ), \ stHeader.cCmd, stHeader.cCmd, stHeader.cCmd ); return ( FALSE ); } } else { if ( nRcvStatus == SOCK_CANCEL ) { m_strLastStaus = _T( "인원승인이력 갯수 수신 취소" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Rcv - 인원승인이력 갯수 수신 취소" ) ); } else { m_strLastStaus = _T( "인원승인이력 갯수 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Rcv - 인원승인이력 갯수 수신 실패" ) ); } return ( FALSE ); } vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Rcv" ) ); return ( TRUE ); } BOOL CMiddleWare::AckNak( BOOL bNak /* = FALSE */ ) { vLib_Log( _T( "[시작]CMiddleWare::AckNak" ) ); BYTE szParam[32]; BYTE cSendBuff[64]; int nSendLen = 0; if ( bNak ) { sprintf( ( char * )szParam, "%c", NAK ); } else { sprintf( ( char * )szParam, "%c", ACK ); } nSendLen = MakeFrame( 1, 'R', szParam, 1, cSendBuff ); if ( Send( cSendBuff, nSendLen ) != nSendLen ) { m_strLastStaus = _T( "ACK 전송 실패" ); vLib_Log( _T( "[종료]CMiddleWare::AckNak - 전송 실패" ) ); return ( FALSE ); } vLib_Log( _T( "[종료]CMiddleWare::AckNak" ) ); return ( TRUE ); } int CMiddleWare::MakeFrame( BYTE cCnt, BYTE cCmd, BYTE *szParam, int nParamLen, BYTE *pFrameBuf ) { // HEADERFRAME stHeader; TAILFRAME stTail; USHORT nLen = 0; BYTE cLRC = 0, cNULL = 0; int i, nIndex; stHeader.cStx = STX; stHeader.cCnt = cCnt; stHeader.cCmd = cCmd; nLen = HEADERFRAME_SIZE + ( nParamLen * cCnt ) + ( NULL_SIZE * ( cCnt - 1 ) ) + TAILFRAME_SIZE; stHeader.cLen[0] = HIBYTE( nLen ); stHeader.cLen[1] = LOBYTE( nLen ); stTail.cEtx = ETX; // // MakeLRC( ( BYTE * )&stHeader, &cLRC, HEADERFRAME_SIZE ); if ( szParam ) { for ( i = 0; i < cCnt; i++ ) { MakeLRC( ( BYTE * )&szParam[i * nParamLen], &cLRC, nParamLen ); if ( i < cCnt - 1 ) { MakeLRC( ( BYTE * )&cNULL, &cLRC, 1 ); } } } MakeLRC( ( BYTE * )&stTail, &cLRC, TAILFRAME_SIZE - 1); stTail.cLRC = cLRC; // memcpy( &pFrameBuf[0], ( BYTE * )&stHeader, HEADERFRAME_SIZE ); nIndex = HEADERFRAME_SIZE; if ( szParam ) { for ( i = 0; i < cCnt; i++ ) { memcpy( &pFrameBuf[nIndex], ( BYTE * )&szParam[i * nParamLen], nParamLen ); nIndex += nParamLen; if ( i < cCnt - 1 ) { memcpy( &pFrameBuf[nIndex], ( BYTE * )&cNULL, 1 ); nIndex++; } } } memcpy( &pFrameBuf[nIndex], ( BYTE * )&stTail, TAILFRAME_SIZE ); nIndex += TAILFRAME_SIZE; return ( nIndex ); } // 차량승인이력 수신 BOOL CMiddleWare::IF_APPROVE_CAR_Rcv( ) { vLib_Log( _T( "[시작]CMiddleWare::IF_APPROVE_CAR_Rcv\n" ) ); HEADERFRAME stHeader; BYTE szParam[32]; BYTE cSendBuff[64]; BYTE cRcvBuff[512 + 32]; int nSendLen = 0; int nRcvLen = 0; // 차량승인이력 갯수 요청 // GATE_CODE(1) sprintf( ( char * )szParam, "%c", _wtoi( CDlgConfig::GetCurGateCode( ) ) ); // Make Frame nSendLen = MakeFrame( 0x01, CMD_IF_APPROVE_CAR, szParam, 1, cSendBuff ); if ( Send( cSendBuff, nSendLen ) != nSendLen ) { m_strLastStaus = _T( "차량승인이력 갯수 요청 전송 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 갯수 요청 전송 실패" ) ); return ( FALSE ); } int nRcvStatus = Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ); if ( nRcvStatus > 0 ) { memcpy( ( void * )&stHeader, ( void * )&cRcvBuff[0], HEADERFRAME_SIZE ); if ( stHeader.cCmd == CMD_IF_APPROVE_COUNT ) { WORD wCount = GET_WORD_VALUE( cRcvBuff[HEADERFRAME_SIZE], cRcvBuff[HEADERFRAME_SIZE + 1] ); vLib_Log( _T( "CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 갯수 수신 = [%d]" ), wCount ); if ( AckNak( ) ) { vLib_Log( _T( "CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 수신 시작" ) ); CADORecordset rs( &CCDBMan::Instance()->m_db ); CCDBMan::Instance()->m_IF_APPROVE_CAR.Open( rs ); CString strMsg; strMsg.Format( _T( "%d/%d" ), 1, wCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); for ( int i = 0; i < wCount; ) { nRcvStatus = Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ); if ( nRcvStatus > 0 ) { memcpy( ( void * )&stHeader, ( void * )&cRcvBuff[0], HEADERFRAME_SIZE ); i += stHeader.cCnt; strMsg.Format( _T( "%d/%d" ), i, wCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); IF_APPROVE_CAR *pstIF_APPROVE_CAR; BYTE *p = ( BYTE * )&cRcvBuff[HEADERFRAME_SIZE]; // 차량승인이력 if ( stHeader.cCmd == CMD_IF_APPROVE_CAR ) { if ( AckNak( ) ) { for ( int j = 0; j < stHeader.cCnt; j++ ) { pstIF_APPROVE_CAR = ( IF_APPROVE_CAR * )p; CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCAR_NUMBER = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cCAR_NUMBER[0], sizeof( pstIF_APPROVE_CAR->cCAR_NUMBER ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCAR_NAME = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cCAR_NAME[0], sizeof( pstIF_APPROVE_CAR->cCAR_NAME ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCAR_NO = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cCAR_NO[0], sizeof( pstIF_APPROVE_CAR->cCAR_NO ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strAPP_FROM = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cAPP_FROM[0], sizeof( pstIF_APPROVE_CAR->cAPP_FROM ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strAPP_TO = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cAPP_TO[0], sizeof( pstIF_APPROVE_CAR->cAPP_TO ), CVLib::TRIM_RIGHT ); // CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strLS_GBN = // CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cLS_GBN[0], // sizeof( pstIF_APPROVE_CAR->cLS_GBN ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCO_NAME = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cCO_NAME[0], sizeof( pstIF_APPROVE_CAR->cCO_NAME ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strDRV_CODE = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cDRV_CODE[0], sizeof( pstIF_APPROVE_CAR->cDRV_CODE ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strDRV_NAME = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cDRV_NAME[0], sizeof( pstIF_APPROVE_CAR->cDRV_NAME ), CVLib::TRIM_RIGHT ); // CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCAR_OWN = // CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCHG_DATE = // CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strDEL_YN = CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strAPP_GATE = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cAPP_GATE[0], sizeof( pstIF_APPROVE_CAR->cAPP_GATE ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strAPP_YN = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cAPP_YN, sizeof( pstIF_APPROVE_CAR->cAPP_YN ), CVLib::TRIM_RIGHT ); // CCDBMan::Instance()->pstIF_APPROVE_CAR.m_strCAPV_COCODE = CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCAPV_TYPE = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_APPROVE_CAR->cCAPV_TYPE[0], sizeof( pstIF_APPROVE_CAR->cCAPV_TYPE ), CVLib::TRIM_RIGHT ); // CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCAPV_GOAL = // CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCAPV_CONST = // CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCAR_KIND = CCDBMan::Instance()->m_IF_APPROVE_CAR.Add( rs ); p += IF_APPROVE_CAR_SIZE; p += NULL_SIZE; } } else { m_strLastStaus = _T( "차량승인이력 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 수신 실패" ) ); return ( FALSE ); } } // 차량승인이력 삭제 else if ( stHeader.cCmd == CMD_IF_APPROVE_CAR_DELETE ) { if ( AckNak( ) ) { for ( int j = 0; j < stHeader.cCnt; j++ ) { CCDBMan::Instance()->m_IF_APPROVE_CAR.m_strCAR_NUMBER = CVLib::Instance( )->GetColumnValue( ( const char * )p, sizeof( pstIF_APPROVE_CAR->cCAR_NUMBER ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_APPROVE_CAR.Delete( rs ); // 주민번호(14) + NULL_SIZE(1) p += ( sizeof( pstIF_APPROVE_CAR->cCAR_NUMBER ) + NULL_SIZE ); } } else { m_strLastStaus = _T( "차량승인이력 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 수신 실패" ) ); return ( FALSE ); } } else { m_strLastStaus = _T( "차량승인이력 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 수신 실패" ) ); return ( FALSE ); } } else { if ( nRcvStatus == SOCK_CANCEL ) { m_strLastStaus = _T( "차량승인이력 수신 취소" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 수신 취소" ) ); } else { m_strLastStaus = _T( "차량승인이력 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 수신 실패" ) ); } return ( FALSE ); } } m_strLastStaus = _T ( "차량승인이력 수신 완료" ); } else { m_strLastStaus = _T( "차량승인이력 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 수신 실패" ) ); return ( FALSE ); } } else { m_strLastStaus = _T( "차량승인이력 잘못된 이력 수신" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 갯수 수신 실패, stHeader.cCmd = [%c][%d][0x%08x]" ), \ stHeader.cCmd, stHeader.cCmd, stHeader.cCmd ); return ( FALSE ); } } else { if ( nRcvStatus == SOCK_CANCEL ) { m_strLastStaus = _T( "차량승인이력 갯수 수신 취소" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 갯수 수신 취소" ) ); } else { m_strLastStaus = _T( "차량승인이력 갯수 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv - 차량승인이력 갯수 수신 실패" ) ); } return ( FALSE ); } vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Rcv" ) ); return ( TRUE ); } // 인원승인이력 조회 BOOL CMiddleWare::IF_APPROVE_LABOR_Inq( CString strJuminNo ) { vLib_Log( _T( "[시작]CMiddleWare::IF_APPROVE_LABOR_Inq = [%s]\n" ), strJuminNo ); HEADERFRAME stHeader; BYTE szParam[32]; BYTE cSendBuff[64]; BYTE cRcvBuff[512 + 32]; int nSendLen = 0; int nRcvLen = 0; // 인원승인이력 조회 // 사원번호(14) // // strJuminNo = _T( "310205-1852511" ); CVLib::Instance( )->vLib_Str2SpaceFillStr( strJuminNo, szParam, 14 ); // Make Frame nSendLen = MakeFrame( 0x01, CMD_IF_APPROVE_LABOR_INQ, szParam, 14, cSendBuff ); if ( Send( cSendBuff, nSendLen ) != nSendLen ) { m_strLastStaus = _T( "인원승인이력조회 요청 전송 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Inq - 인원승인이력조회 요청 전송 실패" ) ); return ( FALSE ); } if ( Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ) > 0 ) { memcpy( ( void * )&stHeader, ( void * )&cRcvBuff[0], HEADERFRAME_SIZE ); if ( stHeader.cCmd == CMD_IF_APPROVE_LABOR_INQ ) { vLib_Log( _T( "CMiddleWare::IF_APPROVE_LABOR_Inq - 인원승인이력조회 수신" ) ); if ( AckNak( ) ) { IF_APPROVE_LABOR_INQ *pstIF_APPROVE_LABOR_INQ = ( IF_APPROVE_LABOR_INQ * )&cRcvBuff[HEADERFRAME_SIZE]; SetResultApproveLabor( pstIF_APPROVE_LABOR_INQ ); } else { m_strLastStaus = _T( "인원승인이력조회 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Inq - 인원승인이력조회 수신 실패" ) ); return ( FALSE ); } } else if ( stHeader.cCmd == CMD_IF_APPROVE_COUNT ) { m_strLastStaus = _T( "비인가 인원" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Inq - 인원승인이력조회 비인가 인원" ) ); return ( FALSE ); } else { m_strLastStaus = _T( "인원승인이력조회 잘못된 이력 수신" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Inq - 인원승인이력조회 수신 실패, stHeader.cCmd = [%c][%d][0x%08x]" ), \ stHeader.cCmd, stHeader.cCmd, stHeader.cCmd ); return ( FALSE ); } } else { m_strLastStaus = _T( "인원승인이력조회 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Inq - 인원승인이력조회 수신 실패" ) ); return ( FALSE ); } m_strLastStaus = _T( "인원승인이력조회 완료" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_LABOR_Inq" ) ); return ( TRUE ); } // 차량승인이력 조회 BOOL CMiddleWare::IF_APPROVE_CAR_Inq( CString strCarNo ) { vLib_Log( _T( "[시작]CMiddleWare::IF_APPROVE_CAR_Inq\n" ) ); HEADERFRAME stHeader; BYTE szParam[32]; BYTE cSendBuff[64]; BYTE cRcvBuff[512 + 32]; int nSendLen = 0; int nRcvLen = 0; // 차량승인이력 조회 // 차량번호(14) CVLib::Instance( )->vLib_Str2SpaceFillStr( strCarNo, szParam, 14 ); // Make Frame nSendLen = MakeFrame( 0x01, CMD_IF_APPROVE_CAR_INQ, szParam, 14, cSendBuff ); if ( Send( cSendBuff, nSendLen ) != nSendLen ) { m_strLastStaus = _T( "차량승인이력조회 요청 전송 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 요청 전송 실패" ) ); return ( FALSE ); } int nRcvStatus = Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ); if ( nRcvStatus > 0 ) { memcpy( ( void * )&stHeader, ( void * )&cRcvBuff[0], HEADERFRAME_SIZE ); if ( stHeader.cCmd == CMD_IF_APPROVE_COUNT ) { WORD wCount = GET_WORD_VALUE( cRcvBuff[HEADERFRAME_SIZE], cRcvBuff[HEADERFRAME_SIZE + 1] ); vLib_Log( _T( "CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 갯수 수신 = [%d]" ), wCount ); if ( wCount == 0 ) { m_strLastStaus = _T( "미등록 차량" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 비인가 차량" ) ); return ( FALSE ); } vLib_Log( _T( "CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 수신" ) ); if ( AckNak( ) ) { CString strMsg; strMsg.Format( _T( "%d/%d" ), 1, wCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); for ( int i = 0; i < wCount; ) { nRcvStatus = Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ); if ( nRcvStatus > 0 ) { memcpy( ( void * )&stHeader, ( void * )&cRcvBuff[0], HEADERFRAME_SIZE ); i += stHeader.cCnt; strMsg.Format( _T( "%d/%d" ), i, wCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); // 차량승인이력 if ( stHeader.cCmd == CMD_IF_APPROVE_CAR_INQ ) { if ( AckNak( ) ) { BYTE *p = ( BYTE * )&cRcvBuff[HEADERFRAME_SIZE]; for ( int j = 0; j < stHeader.cCnt; j++ ) { SetResultApproveCar( p ); p += IF_APPROVE_CAR_SIZE; p += NULL_SIZE; } } else { m_strLastStaus = _T( "차량승인이력조회 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 실패" ) ); return ( FALSE ); } } else { m_strLastStaus = _T( "차량승인이력조회 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 실패" ) ); return ( FALSE ); } } else { if ( nRcvStatus == SOCK_CANCEL ) { m_strLastStaus = _T( "차량승인이력조회 취소" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 취소" ) ); } else { m_strLastStaus = _T( "차량승인이력조회 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 실패" ) ); } return ( FALSE ); } } m_strLastStaus = _T ( "차량승인이력조회 완료" ); } else { m_strLastStaus = _T( "차량승인이력조회 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 수신 실패" ) ); return ( FALSE ); } } else { m_strLastStaus = _T( "차량승인이력조회 잘못된 이력 수신" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 실패, stHeader.cCmd = [%c][%d][0x%08x]" ), \ stHeader.cCmd, stHeader.cCmd, stHeader.cCmd ); return ( FALSE ); } } else { if ( nRcvStatus == SOCK_CANCEL ) { m_strLastStaus = _T( "차량승인이력조회 수신 취소" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 취소" ) ); } else { m_strLastStaus = _T( "차량승인이력조회 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq - 차량승인이력조회 실패" ) ); } return ( FALSE ); } m_strLastStaus = _T( "차량승인이력조회 완료" ); vLib_Log( _T( "[종료]CMiddleWare::IF_APPROVE_CAR_Inq" ) ); return ( TRUE ); } // 인원출입기록 전송 BOOL CMiddleWare::IF_IO_LABOR_Send( ) { DWORD dwRecordCount = CCDBMan::Instance()->GetRecordCount( DB_IF_IO_LABOR_TABLE_NAME ); vLib_Log( _T( "[시작]CMiddleWare::IF_IO_LABOR_Send - dwRecordCount = [%d]" ), dwRecordCount ); BOOL bRtn = TRUE; if ( dwRecordCount > 0 ) { IF_IO_LABOR *pstIF_IO_LABOR = new IF_IO_LABOR[3]; BYTE cCnt = 0; WORD wSerial = 0x01; int nSendLen, nRcvLen; BYTE *pSendBuff = new BYTE[HEADERFRAME_SIZE + IF_IO_LABOR_SIZE + NULL_SIZE + IF_IO_LABOR_SIZE + NULL_SIZE + IF_IO_LABOR_SIZE + TAILFRAME_SIZE]; memset( pstIF_IO_LABOR, 0x20, IF_IO_LABOR_SIZE * 3 ); CADORecordset rs( &CCDBMan::Instance()->m_db ); // CADORecordset rsd( &CCDBMan::Instance()->m_db ); // CCDBMan::Instance()->m_IF_IO_LABOR.Find( rs ); CString strMsg; strMsg.Format( _T( "%d/%d" ), 1, dwRecordCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); for ( int i = 0; i < ( int )dwRecordCount; i++ ) { // Serial Number(2) pstIF_IO_LABOR[cCnt].cSN[0] = HIBYTE( wSerial ); pstIF_IO_LABOR[cCnt].cSN[1] = LOBYTE( wSerial ); pstIF_IO_LABOR[cCnt].cTab1 = TAB; // 바코드(10) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_LABOR.m_strBARCODE, pstIF_IO_LABOR[cCnt].cBARCODE, sizeof( pstIF_IO_LABOR[cCnt].cBARCODE ) ); pstIF_IO_LABOR[cCnt].cTab1 = TAB; // 출입일자(10) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_LABOR.m_strIO_DATE, pstIF_IO_LABOR[cCnt].cIO_DATE, sizeof( pstIF_IO_LABOR[cCnt].cIO_DATE ) ); pstIF_IO_LABOR[cCnt].cTab2 = TAB; // 출입시간(10) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_LABOR.m_strIO_TIME, pstIF_IO_LABOR[cCnt].cIO_TIME, sizeof( pstIF_IO_LABOR[cCnt].cIO_TIME ) ); pstIF_IO_LABOR[cCnt].cTab3 = TAB; // 출입구분(I:입,O:출)(10) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_LABOR.m_strIO_FLAG, pstIF_IO_LABOR[cCnt].cIO_FLAG, sizeof( pstIF_IO_LABOR[cCnt].cIO_FLAG ) ); pstIF_IO_LABOR[cCnt].cTab4 = TAB; // GATE장비 코드(00:Handy, 나머지는 Gate별 장비코드)(10) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_LABOR.m_strCTL_ID, pstIF_IO_LABOR[cCnt].cCTL_ID, sizeof( pstIF_IO_LABOR[cCnt].cCTL_ID ) ); pstIF_IO_LABOR[cCnt].cTab5 = TAB; // GATE코드(10) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_LABOR.m_strGATE_ID, pstIF_IO_LABOR[cCnt].cGATE_ID, sizeof( pstIF_IO_LABOR[cCnt].cGATE_ID ) ); pstIF_IO_LABOR[cCnt].cTab6 = TAB; // 인가여부(1) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_LABOR.m_strIO_APP, &pstIF_IO_LABOR[cCnt].cIO_APP, sizeof( pstIF_IO_LABOR[cCnt].cIO_APP ) ); pstIF_IO_LABOR[cCnt].cTab7 = TAB; // 비인가사유-출입불가,출입정지,미등록,기간경과,통행불가(20) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_LABOR.m_strIO_COMMENT, pstIF_IO_LABOR[cCnt].cIO_COMMENT, sizeof( pstIF_IO_LABOR[cCnt].cIO_COMMENT ) ); CCDBMan::Instance()->m_IF_IO_LABOR.Next( rs ); wSerial++; cCnt++; // 마지막 if ( cCnt == 3 || ( i == ( int )dwRecordCount - 1 ) ) { nSendLen = MakeFrame( cCnt, CMD_IF_IO_LABOR, ( BYTE * )pstIF_IO_LABOR, IF_IO_LABOR_SIZE, pSendBuff ); if ( Send( pSendBuff, nSendLen ) == nSendLen ) { strMsg.Format( _T( "%d/%d" ), wSerial - 1, dwRecordCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); BYTE cRcvBuff[32]; int nRcvStatus = Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ); if ( nRcvStatus > 0 ) { for ( int j = 0; j < cCnt; j++ ) { CCDBMan::Instance()->m_IF_IO_LABOR.m_strBARCODE = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_IO_LABOR[j].cBARCODE[0], sizeof( pstIF_IO_LABOR[j].cBARCODE ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_IO_LABOR.Delete( rsd ); } } else { if ( nRcvStatus == SOCK_CANCEL ) { m_strLastStaus = _T( "인원출입기록 전송 취소" ); vLib_Log( _T( "[종료]CMiddleWare::IF_IO_LABOR_Send - 인원출입기록 전송 취소" ) ); } else { m_strLastStaus = _T( "인원출입기록 전송 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_IO_LABOR_Send - 인원출입기록 전송 실패" ) ); } bRtn = FALSE; break; } } else { m_strLastStaus = _T( "인원출입기록 전송 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_IO_LABOR_Send - 인원출입기록 전송 실패" ) ); bRtn = FALSE; break; } cCnt = 0; } } delete []pstIF_IO_LABOR; } if ( bRtn ) { m_strLastStaus = _T( "인원출입기록 전송 완료" ); vLib_Log( _T( "[종료]CMiddleWare::IF_IO_LABOR_Send" ) ); } return ( bRtn ); } // 차량출입기록 전송 BOOL CMiddleWare::IF_IO_CAR_Send( ) { DWORD dwRecordCount = CCDBMan::Instance()->GetRecordCount( DB_IF_IO_CAR_TABLE_NAME ); vLib_Log( _T( "[시작]CMiddleWare::IF_IO_CAR_Send - dwRecordCount = [%d]" ), dwRecordCount ); BOOL bRtn = TRUE; if ( dwRecordCount > 0 ) { IF_IO_CAR *pstIF_IO_CAR = new IF_IO_CAR[3]; BYTE cCnt = 0; WORD wSerial = 0x01; int nSendLen, nRcvLen; BYTE *pSendBuff = new BYTE[HEADERFRAME_SIZE + IF_IO_CAR_SIZE + NULL_SIZE + IF_IO_CAR_SIZE + NULL_SIZE + IF_IO_CAR_SIZE + TAILFRAME_SIZE]; memset( pstIF_IO_CAR, 0x20, IF_IO_CAR_SIZE * 3 ); CADORecordset rs( &CCDBMan::Instance()->m_db ); // CADORecordset rsd( &CCDBMan::Instance()->m_db ); // CCDBMan::Instance()->m_IF_IO_CAR.Find( rs ); CString strMsg; strMsg.Format( _T( "%d/%d" ), 1, dwRecordCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); for ( int i = 0; i < ( int )dwRecordCount; i++ ) { // Serial Number(2) pstIF_IO_CAR[cCnt].cSN[0] = HIBYTE( wSerial ); pstIF_IO_CAR[cCnt].cSN[1] = LOBYTE( wSerial ); pstIF_IO_CAR[cCnt].cTab0 = TAB; // 차량번호(15) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strCAR_NUMBER, pstIF_IO_CAR[cCnt].cCAR_NO, sizeof( pstIF_IO_CAR[cCnt].cCAR_NO ) ); pstIF_IO_CAR[cCnt].cTab1 = TAB; // 출입일자(8) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strIO_DATE, pstIF_IO_CAR[cCnt].cIO_DATE, sizeof( pstIF_IO_CAR[cCnt].cIO_DATE ) ); pstIF_IO_CAR[cCnt].cTab2 = TAB; // 출입시간(6) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strIO_TIME, pstIF_IO_CAR[cCnt].cIO_TIME, sizeof( pstIF_IO_CAR[cCnt].cIO_TIME ) ); pstIF_IO_CAR[cCnt].cTab3 = TAB; // 출입구분(I:입,O:출)(1) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strIO_FLAG, &pstIF_IO_CAR[cCnt].cIO_FLAG, sizeof( pstIF_IO_CAR[cCnt].cIO_FLAG ) ); pstIF_IO_CAR[cCnt].cTab4 = TAB; // GATE장비코드(2) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strCTL_ID, pstIF_IO_CAR[cCnt].cCTL_ID, sizeof( pstIF_IO_CAR[cCnt].cCTL_ID ) ); pstIF_IO_CAR[cCnt].cTab5 = TAB; // GATE코드(2) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strGATE_ID, pstIF_IO_CAR[cCnt].cGATE_ID, sizeof( pstIF_IO_CAR[cCnt].cGATE_ID ) ); pstIF_IO_CAR[cCnt].cTab6 = TAB; // 인증여부(1) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strIO_APP, &pstIF_IO_CAR[cCnt].cIO_APP, sizeof( pstIF_IO_CAR[cCnt].cIO_APP ) ); pstIF_IO_CAR[cCnt].cTab7 = TAB; // 비인가 사유-판독불가,미등로,기간경과(20) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strIO_COMMENT, pstIF_IO_CAR[cCnt].cIO_COMMENT, sizeof( pstIF_IO_CAR[cCnt].cIO_COMMENT ) ); pstIF_IO_CAR[cCnt].cTab8 = TAB; // 차량구분-장기차량,단기차량,회사차량,직원차량,방문차량(8) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strLS_GBN, pstIF_IO_CAR[cCnt].cLS_GBN, sizeof( pstIF_IO_CAR[cCnt].cLS_GBN ) ); pstIF_IO_CAR[cCnt].cTab9 = TAB; // 업체명/팀명(20) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strCO_NAME, pstIF_IO_CAR[cCnt].CO_NAME, sizeof( pstIF_IO_CAR[cCnt].CO_NAME ) ); pstIF_IO_CAR[cCnt].cTab10 = TAB; // 차량명(예:소나타)(20) CVLib::Instance()->vLib_Str2SpaceFillStr( CCDBMan::Instance()->m_IF_IO_CAR.m_strCAR_NAME, pstIF_IO_CAR[cCnt].cCAR_NAME, sizeof( pstIF_IO_CAR[cCnt].cCAR_NAME ) ); CCDBMan::Instance()->m_IF_IO_CAR.Next( rs ); wSerial++; cCnt++; // 마지막 if ( cCnt == 3 || ( i == ( int )dwRecordCount - 1 ) ) { nSendLen = MakeFrame( cCnt, CMD_IF_IO_CAR, ( BYTE * )pstIF_IO_CAR, IF_IO_CAR_SIZE, pSendBuff ); if ( Send( pSendBuff, nSendLen ) == nSendLen ) { strMsg.Format( _T( "%d/%d" ), wSerial - 1, dwRecordCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); BYTE cRcvBuff[32]; // ACK 수신대기 int nRcvStatus = Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ); if ( nRcvStatus > 0 ) { for ( int j = 0; j < cCnt; j++ ) { CCDBMan::Instance()->m_IF_IO_CAR.m_strCAR_NUMBER = CVLib::Instance( )->GetColumnValue( ( const char * )&pstIF_IO_CAR[j].cCAR_NO[0], sizeof( pstIF_IO_CAR[j].cCAR_NO ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_IF_IO_CAR.Delete( rsd ); } } else { if ( nRcvStatus == SOCK_CANCEL ) { m_strLastStaus = _T( "차량출입기록 전송 취소" ); vLib_Log( _T( "[종료]CMiddleWare::IF_IO_CAR_Send - 차량출입기록 전송 취소" ) ); bRtn = FALSE; break; } } } else { m_strLastStaus = _T( "차량출입기록 전송 실패" ); vLib_Log( _T( "[종료]CMiddleWare::IF_IO_CAR_Send - 차량출입기록 전송 실패" ) ); bRtn = FALSE; break; } cCnt = 0; } } delete []pstIF_IO_CAR; } if ( bRtn ) { m_strLastStaus = _T( "차량출입기록 전송 완료" ); vLib_Log( _T( "[종료]CMiddleWare::IF_IO_CAR_Send" ) ); } return ( bRtn ); } // 게이트코드 수신 BOOL CMiddleWare::VW_SET_HANDY_GATE_Rcv( ) { vLib_Log( _T( "[시작]CMiddleWare::VW_SET_HANDY_GATE_Rcv\n" ) ); HEADERFRAME stHeader; BYTE cSendBuff[32]; BYTE cRcvBuff[512 + 32]; int nSendLen = 0; int nRcvLen = 0; // Make Frame nSendLen = MakeFrame( 0x01, CMD_VW_SET_HANDY_GATE, NULL, 0, cSendBuff ); if ( Send( cSendBuff, nSendLen ) != nSendLen ) { m_strLastStaus = _T( "게이트코드 갯수 요청 전송 실패" ); vLib_Log( _T( "[종료]CMiddleWare::VW_SET_HANDY_GATE_Rcv - 게이트코드 갯수 요청 전송 실패" ) ); return ( FALSE ); } int nRcvStatus = Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ); if ( nRcvStatus > 0 ) { memcpy( ( void * )&stHeader, ( void * )&cRcvBuff[0], HEADERFRAME_SIZE ); if ( stHeader.cCmd == CMD_IF_APPROVE_COUNT ) { WORD wCount = GET_WORD_VALUE( cRcvBuff[HEADERFRAME_SIZE], cRcvBuff[HEADERFRAME_SIZE + 1] ); vLib_Log( _T( "CMiddleWare::VW_SET_HANDY_GATE_Rcv - 게이트코드 갯수 수신 = [%d]" ), wCount ); if ( AckNak( ) ) { vLib_Log( _T( "CMiddleWare::VW_SET_HANDY_GATE_Rcv - 게이트코드 수신 시작" ) ); CCDBMan::Instance( )->DeleteAll( DB_VW_SET_HANDY_GATE_TABLE_NAME ); CADORecordset rs( &CCDBMan::Instance()->m_db ); CCDBMan::Instance()->m_VW_SET_HANDY_GATE.Open( rs ); CString strMsg; strMsg.Format( _T( "%d/%d" ), 1, wCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); nRcvStatus = Receive( cRcvBuff, sizeof( cRcvBuff ), &nRcvLen ); if ( nRcvStatus > 0 ) { strMsg.Format( _T( "%d/%d" ), wCount, wCount ); SetOwnerStatus3( strMsg.GetBuffer( 0 ) ); BYTE *p = &cRcvBuff[HEADERFRAME_SIZE]; for ( int j = 0; j < wCount; j++ ) { VW_SET_HANDY_GATE *pstVW_SET_HANDY_GATE = ( VW_SET_HANDY_GATE * )p; CCDBMan::Instance()->m_VW_SET_HANDY_GATE.m_strGATE_CODE = CVLib::Instance( )->GetColumnValue( ( const char * )&pstVW_SET_HANDY_GATE->cGATE_CODE[0], sizeof( pstVW_SET_HANDY_GATE->cGATE_CODE ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_VW_SET_HANDY_GATE.m_strGATE_NAME = CVLib::Instance( )->GetColumnValue( ( const char * )&pstVW_SET_HANDY_GATE->cGATE_NAME[0], sizeof( pstVW_SET_HANDY_GATE->cGATE_NAME ), CVLib::TRIM_RIGHT ); CCDBMan::Instance()->m_VW_SET_HANDY_GATE.Add( rs ); p += VW_SET_HANDY_GATE_SIZE; p += NULL_SIZE; } if ( AckNak( ) ) { } else { m_strLastStaus = _T( "게이트코드 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::VW_SET_HANDY_GATE_Rcv - 게이트코드 수신 실패" ) ); return ( FALSE ); } } else { if ( nRcvStatus == SOCK_CANCEL ) { m_strLastStaus = _T( "게이트코드 수신 취소" ); vLib_Log( _T( "[종료]CMiddleWare::VW_SET_HANDY_GATE_Rcv - 게이트코드 수신 취소" ) ); } else { m_strLastStaus = _T( "게이트코드 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::VW_SET_HANDY_GATE_Rcv - 게이트코드 수신 실패" ) ); } return ( FALSE ); } m_strLastStaus = _T ( "게이트코드 수신 완료" ); } else { m_strLastStaus = _T( "게이트코드 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::VW_SET_HANDY_GATE_Rcv - 게이트코드 수신 실패" ) ); return ( FALSE ); } } else { m_strLastStaus = _T( "게이트코드 잘못된 이력 수신" ); vLib_Log( _T( "[종료]CMiddleWare::VW_SET_HANDY_GATE_Rcv - 게이트코드 갯수 수신 실패, stHeader.cCmd = [%c][%d][0x%08x]" ), \ stHeader.cCmd, stHeader.cCmd, stHeader.cCmd ); return ( FALSE ); } } else { if ( nRcvStatus == SOCK_CANCEL ) { m_strLastStaus = _T( "게이트코드 갯수 수신 취소" ); vLib_Log( _T( "[종료]CMiddleWare::VW_SET_HANDY_GATE_Rcv - 게이트코드 갯수 수신 취소" ) ); } else { m_strLastStaus = _T( "게이트코드 갯수 수신 실패" ); vLib_Log( _T( "[종료]CMiddleWare::VW_SET_HANDY_GATE_Rcv - 게이트코드 갯수 수신 실패" ) ); } return ( FALSE ); } vLib_Log( _T( "[종료]CMiddleWare::VW_SET_HANDY_GATE_Rcv" ) ); return ( TRUE ); } BOOL CMiddleWare::SendReceive( BYTE *pSendBuff, int nSendLen, BYTE *pRcvBuff, int *nRcvLen, BOOL bHangUp /* = FALSE */ ) { vLib_Log( _T( "[시작]CMiddleWare::SendReceive\n" ) ); vLib_Log( _T( "[종료]CMiddleWare::SendReceive\n" ) ); return ( TRUE ); } BOOL CMiddleWare::Connect( ) { return ( Connect( m_strServerIP.GetBuffer( 0 ), _wtoi( m_strServerPort ) ) ); } BOOL CMiddleWare::Connect( TCHAR *szHostIP, int nPort ) /*@******************************************************************************/ /* 1. 기 능 : Init */ /* 2. 인 수 : TCHAR *szHostIP, int nPort */ /* 3. 리 턴 값 : TRUE : 성공, FALSE : 실패 */ /* 4. 참 조 : */ /*@******************************************************************************/ { unsigned long addr; struct sockaddr_in sAddr; struct hostent* pHost; char chHostIP[128]; fd_set fdRecv, fdWrt, fdError; struct timeval tv = { 0, 1000 }; vLib_Log( _T( "[시작]CMiddleWare::Connect - szHostIP = [%s], nPort = [%d]\n" ), szHostIP, nPort ); if ( ( m_hSock = ::socket( PF_INET, SOCK_STREAM, IPPROTO_IP ) ) != INVALID_SOCKET ) { int nLen = CVLib::Instance( )->vLib_UtoA( chHostIP, szHostIP ); chHostIP[nLen] = 0; addr = ::inet_addr( chHostIP ); if ( addr == SOCK_ERROR ) { pHost = ::gethostbyname( chHostIP ); if ( !pHost ) { DisConnect( ); m_strLastStaus = _T( "서버 연결 실패" ); vLib_Log( _T( "[종료]CMiddleWare::Connect - gethostbyname, pHost = [0x%08x]\n" ), pHost ); return ( FALSE ); } addr = *( ( unsigned long* )( pHost->h_addr_list )[0] ); } // non-blocking mode is enabled unsigned long val = 1; if ( ::ioctlsocket( m_hSock, FIONBIO, &val ) == SOCK_ERROR ) { vLib_Log( _T( "[종료]CMiddleWare::Connect - ::ioctlsocket, WSAGetLastError( ) = [%d]\n" ), WSAGetLastError( ) ); DisConnect( ); return ( FALSE ); } memset( &sAddr, 0, sizeof( sockaddr_in ) ); sAddr.sin_family = AF_INET; sAddr.sin_port = ::htons( ( u_short )nPort ); sAddr.sin_addr.s_addr = addr; int nConnStatus = ::connect( m_hSock, ( const sockaddr* )&sAddr, sizeof( sAddr ) ); vLib_Log9( _T( "CMiddleWare::Connect - ::connect( ) End = [%d]" ), nConnStatus ); // if ( nConnStatus == 0 ) { // m_strLastStaus = _T( "서버 연결 성공" ); // vLib_Log( _T( "[종료]CMiddleWare::Connect - 서버 연결 성공\n" ) ); // return ( TRUE ); // } // else { // m_strLastStaus = _T( "서버 연결 실패" ); // vLib_Log( _T( "[종료]CMiddleWare::Connect - ::select, WSAGetLastError( ) = [%d]\n" ), WSAGetLastError( ) ); // DisConnect( ); // return ( FALSE ); // } CTimeSpan span( 0, 0, 0, 15 * 2 ); CTime current_time, start_time; start_time = CTime::GetCurrentTime( ); do { // FD_ZERO( &fdRecv ); // FD_SET( m_hSock, &fdRecv ); FD_ZERO( &fdWrt ); FD_SET( m_hSock, &fdWrt ); FD_ZERO( &fdError ); FD_SET( m_hSock, &fdError ); int nSelStat = ::select( NULL, 0, &fdWrt, &fdError, &tv ); vLib_Log( _T( "CMiddleWare::Connect - ::select, nSelStat = [%d]\n" ), nSelStat ); CVLib::Instance()->vLib_PumpMessage( ); if ( nSelStat == SOCK_ERROR ) { m_strLastStaus = _T( "서버 연결 실패" ); vLib_Log( _T( "[종료]CMiddleWare::Connect - ::select, nSelStat = [%d]\n" ), nSelStat ); return ( SOCK_ERROR ); } else { if ( FD_ISSET( m_hSock, &fdError ) ) { m_strLastStaus = _T( "서버 연결 실패" ); vLib_Log( _T( "[종료]CMiddleWare::Connect - ::select, WSAGetLastError( ) = [%d]\n" ), WSAGetLastError( ) ); DisConnect( ); return ( FALSE ); } else if ( FD_ISSET( m_hSock, &fdWrt ) ) { m_strLastStaus = _T( "서버 연결 성공" ); vLib_Log( _T( "[종료]CMiddleWare::Connect - 서버 연결 성공\n" ) ); return ( TRUE ); } // else if ( FD_ISSET( m_hSock, &fdRecv ) ) { // m_strLastStaus = _T( "서버 연결 성공" ); // vLib_Log( _T( "[종료]CMiddleWare::Connect - 서버 연결 성공\n" ) ); // return ( TRUE ); // } } current_time = CTime::GetCurrentTime( ); if ( m_hWnd ) { // 취소 if ( m_bCancel ) { Cancel( FALSE ); vLib_Log( _T( "[종료]CMiddleWare::Connect - 서버 연결 취소\n" ) ); return ( SOCK_CANCEL ); } } } while ( current_time < ( start_time + span ) ); m_strLastStaus = _T( "서버 연결 타임 아웃" ); vLib_Log( _T( "[종료]CMiddleWare::Connect - select, WSAGetLastError( ) = [%d]\n" ), WSAGetLastError( ) ); DisConnect( ); return ( FALSE ); } else { m_strLastStaus = _T( "서버 연결 실패" ); vLib_Log( _T( "[종료]CMiddleWare::Connect - socket, WSAGetLastError( ) = [%d]\n" ), WSAGetLastError( ) ); return ( FALSE ); } } void CMiddleWare::DisConnect( ) /*@******************************************************************************/ /* 1. 기 능 : CloseSocket */ /* 2. 인 수 : */ /* 3. 리 턴 값 : 없음 */ /* 4. 참 조 : */ /*@******************************************************************************/ { vLib_Log( _T( "[시작]CMiddleWare::DisConnect\n" ) ); if ( m_hSock != INVALID_SOCKET ) { ::shutdown( m_hSock, 2 ); ::closesocket( m_hSock ); m_hSock = INVALID_SOCKET; vLib_Log( _T( "CMiddleWare::DisConnect Success.\n" ) ); } vLib_Log( _T( "[종료]CMiddleWare::DisConnect\n" ) ); } int CMiddleWare::Send( BYTE *pSendBuff, int nLen ) { // TODO: Add your specialized code here and/or call the base class vLib_Log( _T( "[시작]CMiddleWare::Send - nLen = [%d]" ), nLen ); vLib_Log( _T( "CMiddleWare::Send - pSendBuff Dump" ) ); vLib_Dump( pSendBuff, nLen ); if ( m_hSock != INVALID_SOCKET ) { int nRtn = 0; // 데이터 전송 while ( TRUE ) { int nCurRtn = 0; nCurRtn = ::send( m_hSock, ( const char * )( pSendBuff + nRtn ), nLen - nRtn, 0 ); if ( nCurRtn >= 0 ) { nRtn += nCurRtn; if ( nRtn >= nLen ) { break; } } else { nRtn = SOCK_ERROR; break; } } vLib_Log( _T( "[종료]CMiddleWare::Send - nRtn = [%d]\n" ), nRtn ); return ( nRtn ); } else { vLib_Log( _T( "[종료]CMiddleWare::Send - m_hSock = [%d]\n" ), m_hSock ); return ( SOCK_ERROR ); } } int CMiddleWare::Receive( BYTE *pRcvBuff, int nRcvBuffLen, int *nRcvLen /* = NULL */ ) { // TODO: Add your specialized code here and/or call the base class int nReceive; int nFramePos = 0; CTime current_time, start_time; CTimeSpan span( 0, 0, 0, 30 ); int nSelStat; fd_set fdRecv; struct timeval tv = { 0, 1000 }; vLib_Log( _T( "[시작]CMiddleWare::ReceiveFunc" ) ); if ( m_hSock == INVALID_SOCKET ) { vLib_Log( _T( "[종료]CMiddleWare::ReceiveFunc - m_hSocket = [%d][0x%08x]" ), m_hSock, m_hSock ); return ( SOCK_ERROR ); } start_time = CTime::GetCurrentTime( ); int nRcvBuffSize = 1; HEADERFRAME stHeader; memset( pRcvBuff, 0x00, nRcvBuffLen ); memset( ( BYTE * )&stHeader, 0x00, HEADERFRAME_SIZE ); do { FD_ZERO( &fdRecv ); FD_SET( m_hSock, &fdRecv ); // vLib_Log9( _T( "CMiddleWare::ReceiveFunc - select\n" ) ); nSelStat = ::select( NULL, &fdRecv, 0, 0, &tv ); CVLib::Instance()->vLib_PumpMessage( ); vLib_Log9( _T( "CMiddleWare::ReceiveFunc - select, nSelStat = [%d]\n" ), nSelStat ); if ( nSelStat == SOCK_ERROR ) { vLib_Log( _T( "[종료]CMiddleWare::ReceiveFunc - select, nSelStat = [%d]\n" ), nSelStat ); return ( SOCK_ERROR ); } // 타임 아웃 else if ( nSelStat == 0 ) { } else { nReceive = ::recv( m_hSock, ( char * )pRcvBuff + nFramePos, nRcvBuffSize, 0 ); vLib_Log9( _T( "CMiddleWare::ReceiveFunc recv - nReceive = [%d]\n" ), nReceive ); // Socket Closed if ( nReceive == 0 || nReceive == SOCKET_ERROR ) { vLib_Log( _T( "[종료]CMiddleWare::ReceiveFunc - recv, nReceive = [%d]\n" ), nReceive ); return ( SOCK_ERROR ); } else { // 수신버퍼에 복사 if ( pRcvBuff[0] == STX ) { } else { continue; } // memcpy( ( pRcvBuff + nFramePos ), cTemp, nReceive ); nFramePos += nReceive; // if ( nFramePos == HEADERFRAME_SIZE && stHeader.cStx == 0x00 ) { memcpy( &stHeader, pRcvBuff, HEADERFRAME_SIZE ); *nRcvLen = stHeader.cLen[0] << 8; *nRcvLen |= stHeader.cLen[1]; vLib_Log( _T( "CMiddleWare::ReceiveFunc - 헤더 데이터 수신, stHeader.cLen = [%d]\n" ), *nRcvLen ); continue; } if ( stHeader.cStx == STX ) { if ( nFramePos >= *nRcvLen ) { vLib_Log( _T( "CMiddleWare::ReceiveFunc - pRcvBuff Dump" ) ); vLib_Dump( pRcvBuff, *nRcvLen ); // 비정상 데이터 수신 if ( pRcvBuff[*nRcvLen - 2] != ETX ) { vLib_Log( _T( "[종료]CMiddleWare::ReceiveFunc - 비정상 데이터 수신, *nRcvLen = [%d], ETX = [0x%02x]\n" ), *nRcvLen, pRcvBuff[*nRcvLen - 2] ); return ( SOCK_ERROR ); } else { BYTE cLRC = 0; MakeLRC( pRcvBuff, &cLRC, *nRcvLen - 1 ); // LRC 에러 if ( pRcvBuff[*nRcvLen - 1] != cLRC ) { vLib_Log( _T( "[종료]CMiddleWare::ReceiveFunc - 비정상 데이터 수신, *nRcvLen = [%d], LRC = [0x%02x][0x%02x]\n" ), *nRcvLen, cLRC, pRcvBuff[*nRcvLen - 1] ); return ( SOCK_ERROR ); } else { vLib_Log( _T( "[종료]CMiddleWare::ReceiveFunc - 데이터 수신 완료, nFramePos = [%d], stHeader.cLen = [%d]\n" ), nFramePos, *nRcvLen ); return ( nFramePos ); } } } nRcvBuffSize = *nRcvLen - nFramePos; } else { nRcvBuffSize = HEADERFRAME_SIZE - nFramePos; } } } current_time = CTime::GetCurrentTime( ); if ( m_hWnd ) { // 취소 if ( m_bCancel ) { Cancel( FALSE ); vLib_Log( _T( "[종료]CMiddleWare::ReceiveFunc - 데이터 수신 취소, nFramePos = [%d], stHeader.cLen = [%d]\n" ), nFramePos, *nRcvLen ); return ( SOCK_CANCEL ); } } } while ( current_time < ( start_time + span ) ); vLib_Log( _T( "[종료]CMiddleWare::ReceiveFunc - 타임 아웃\n" ) ); return ( SOCK_TIME_OUT ); } UINT ReceiveThreadFunc( LPVOID lParam ) { RECEIVETHREADPARAM *pstThreadParm =( RECEIVETHREADPARAM * )lParam; CMiddleWare *pMiddleWare = ( CMiddleWare * )pstThreadParm->pOwner; *pstThreadParm->pRtn = pMiddleWare->Receive( pstThreadParm->pRcvBuff, pstThreadParm->nRcvBuffSize, pstThreadParm->nRcvLen ); return ( 0 ); } int CMiddleWare::ReceiveThread( BYTE *pRcvBuff, int nRcvBuffSize, int *nRcvLen /* = NULL */ ) { int nTimeOut = 0; int nRtnCd = 0; DWORD dwLastError = 0; RECEIVETHREADPARAM stThreadParm; vLib_Log( _T( "[시작]CMiddleWare::ReceiveThread\n" ) ); stThreadParm.pOwner = this; stThreadParm.pRtn = &nRtnCd; stThreadParm.pRcvBuff = pRcvBuff; stThreadParm.nRcvBuffSize = nRcvBuffSize; stThreadParm.nRcvLen = nRcvLen; CWinThread *pThread; pThread = ::AfxBeginThread( ReceiveThreadFunc, &stThreadParm ); // pWinThread->m_bAutoDelete = FALSE; DWORD dwExitCode = 0, dwStatus = 0; while ( TRUE ) { if ( ::GetExitCodeThread( pThread->m_hThread, &dwExitCode ) ) { if ( dwExitCode == STILL_ACTIVE ) { dwStatus = ::WaitForSingleObject( pThread->m_hThread, THREAD_TIME_OUT ); // Thread가 블록됨 if ( dwStatus == WAIT_TIMEOUT ) { CVLib::Instance( )->vLib_PumpMessage( ); nTimeOut += THREAD_TIME_OUT; if ( nTimeOut >= TIME_OUT_SEC60 ) { TerminateThread( pThread->m_hThread, dwExitCode ); // delete pThread; nRtnCd = SOCK_THREAD_TIME_OUT; break; } } // Thread 정상 종료 else if ( dwStatus == WAIT_OBJECT_0 ) { break; } } // Thread 정상 종료 else { break; } } else { dwLastError = GetLastError( ); nRtnCd = SOCK_THREAD_TIME_OUT; break; } } CloseHandle( pThread->m_hThread ); delete pThread; vLib_Log( _T( "[종료]CMiddleWare::ReceiveThread, nRtnCd = [%d], dwLastError = [%d]\n" ), nRtnCd, dwLastError ); return ( nRtnCd ); } void CMiddleWare::MakeLRC( BYTE *p, BYTE *cLRC, int nLen ) { for ( int i = 0; i < nLen; i++ ) { *cLRC ^= p[i]; } } CString CMiddleWare::GetServerIP( ) { CString strValue; CRegistryEx reg; vLib_RegOpenEx( reg, REG_PATH, REG_PATH_ENV ); reg.Read( REG_VALUE_SERVER_IP, strValue ); return ( strValue ); } CString CMiddleWare::GetServerPort( ) { CString strValue; CRegistryEx reg; vLib_RegOpenEx( reg, REG_PATH, REG_PATH_ENV ); reg.Read( REG_VALUE_SERVER_PORT, strValue ); return ( strValue ); } 2009/04/11 16:13 2009/04/11 16:13 Trackback: 0 Comment: 0 이 글에는 트랙백을 보낼 수 없습니다