#include "stdafx.h" #include "cmmio_base.h" #ifdef _WIN64 #include "..\..\..\WAI64bit\WAI64bit.h" #endif // added notifying feature to base class CMMIO [7/30/2004] /MP // - SetCallback(ptr) to establish the feedback path // then AddReceived will notify if such a ptr was set // caller receive function is prototyped as function(CString), i.e. Recieved(CString sWhat) ///////////////////////////////////////////////////////////////////////////// void CMMIO::Init() { m_RXTempPtr = NULL; m_RXHead=NULL; m_RXTail=NULL; m_SXTempPtr = NULL; m_SXHead=NULL; m_SXTail=NULL; CurrentPointer=0; m_iNbMsgWaiting=0; m_terminator='\0'; m_usesTerminator=FALSE; m_pReceiveNotify = NULL; } void CMMIO::SetCallback(CMMIO::p_fstr ptr) { m_pReceiveNotify = ptr; } DWORD CMMIO::Send(CString buffer, BOOL needsResponse/*=FALSE*/) { //ZH 12-12-05 EnterCriticalSection(&m_QueueLock); //ZH-122904 char LocBuffer[MAX_OUTPUT_BUFFER_SIZE]; int length = buffer.GetLength (); if (length >MAX_OUTPUT_BUFFER_SIZE) { length = MAX_OUTPUT_BUFFER_SIZE; } unsigned short* ptr = (unsigned short*)buffer.GetBuffer (MAX_OUTPUT_BUFFER_SIZE); for (int i=0;iNext; // Point the temp pointer at the block m_RXTempPtr = Free->Buffer; cnt = Free->Bytes; // delete the list entry delete Free; --m_iNbMsgWaiting; // mp // move over the data to the user's buffer if (NULL != inputBuf) memcpy (inputBuf, m_RXTempPtr, cnt); } if( m_RXHead == NULL ) m_RXTail = NULL; // All done so out of the CriticalSection // LeaveCriticalSection( &m_QueueLock ); return(cnt); } int CMMIO::AddReceived( const char *Buffer,DWORD Bytes) { DWORD index = 0; //primary buffer index struct SerialList *Ptr; static char Buffer2[MAX_RECIEVE_BUFFER_SIZE]; // result buffer static char* pBuffer2 = &Buffer2[0]; unsigned char c; bool bArmed; /************************************************************************/ /* Greg Guilbeau - 2011/08/23 */ /* The following line(s) have been modified to handle x64 conversion */ /************************************************************************/ /* int count; */ INT_PTR count; static int escape = 0; static int tilde = 0; static int tildeseqcount = 0; bool bDone = false; bool bEventRequest = false; //TRACE(_T("AddReceived> pBuffer2 = %x\n"),pBuffer2); // TRACE(_T("Content %s\n"),Buffer); if (FALSE /*Bytes==0*/) { TRACE(_T("CMMIO> Exiting , no real input")); return TRUE; } do { bArmed = false; for (;indexBuffer = new char[count + 1 ]; /************************************************************************/ /* Greg Guilbeau - 2011/08/23 */ /* The following line(s) have been modified to handle x64 conversion */ /************************************************************************/ /* Ptr->Bytes = count; */ #ifdef _WIN64 Ptr->Bytes = WAI64bit::to32bit(count,__FILE__,__LINE__); #else Ptr->Bytes = count,__FILE__,__LINE__; #endif Ptr->Next = NULL; memcpy( Ptr->Buffer, Buffer2, count ); Ptr->Buffer[count] = 0; memcpy(m_sLastMessage,Buffer2,count); //copy to last message m_sLastMessage[count]=0; if( m_RXTail ) m_RXTail->Next = Ptr; else m_RXHead = Ptr; m_RXTail = Ptr; // All done so out of the CriticalSection ++m_iNbMsgWaiting; } // LeaveCriticalSection( &m_QueueLock ); pBuffer2=&Buffer2[0]; // reset out buffer count = 0; bEventRequest = true; } } while (!bDone); //TRACE (_T("CMMIO> Done\n")); return(TRUE); } void CMMIO::LineReceive(char* s, int nbCharAvail, BOOL ignoreDelimiter /*= FALSE*/) { if (nbCharAvail != -1) { //TRACE(_T("LineReceive got %d chars \n"),nbCharAvail); char c; for (int i=0 ; iNext; delete[] Free->Buffer; delete Free; } m_RXHead = NULL; // for now we are not using the Transmit list #if 0 while( m_TXHead ) { Free = m_TXHead; m_TXHead = m_TXHead->Next; delete[] Free->Buffer; delete Free; } m_TXHead = NULL; #endif // LeaveCriticalSection( &m_QueueLock ); return(TRUE); } /////////////////////////////////////////////////////////////////////////////// // END OF BASE CLASS CMMIO ///////////////////////////////////////////////////////////////////////////////