/*-------------------------------------------------------------------------------*/ /* MessageCommand.cpp 7-Oct-99 28-Oct-99 Coor Command Parsing split onto separate files */ /*-------------------------------------------------------------------------------*/ #include "stdafx.h" #include "MessageCommand.h" #include "MessageKeywordsCoorL1FW.h" #include "MessageKeywordsCoorL1CT.h" #include "UtilsParsing.h" /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ CMessageCommand::CMessageCommand () { ResetCommand () ; } /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ CMessageCommand::~CMessageCommand () { } /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ void CMessageCommand::ResetCommand () { m_uiCoorCmdCode = Ki_CoorCmd_None ; m_uiCoorSubCmdCode = Ki_CoorCmd_None ; m_uiObjectIndex = 0 ; m_eObjectPolarity = ItemNotPresent ; m_uiValue = 0 ; m_eValuePolarity = ItemNotPresent ; for ( int i = 0 ; i <= KiMaxItemIndexInMessageCommand ; i++ ) m_aubItemPolarity[i] = ItemNotPresent ; // initialize the Eta and Phi arrays. // Note we also zero the non-existing Eta/Phi = 0 values that are not used for ( unsigned char ubTT_Eta_Sign = eTT_Eta_Neg ; ubTT_Eta_Sign <= eTT_Eta_Pos ; ubTT_Eta_Sign++ ) for ( unsigned char ubTT_Eta_Magn = 0 ; ubTT_Eta_Magn <= KiMax_TT_Eta_Magn ; ubTT_Eta_Magn++ ) m_xTT.aalTT_Eta[ ubTT_Eta_Sign ] [ ubTT_Eta_Magn ] = false ; for ( unsigned char ubTT_Phi = 0 ; ubTT_Phi <= KiMax_TT_Phi ; ubTT_Phi++ ) m_xTT.alTT_Phi[ubTT_Phi] = false ; m_uiRefSetNum = 0 ; m_fdThreshold = 0.0 ; } /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ CMessageCommandLine::CMessageCommandLine () { ResetCommand () ; } /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ CMessageCommandLine::~CMessageCommandLine () { } /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ void CMessageCommandLine::ResetCommand () { m_psRawCommand = NULL ; m_pcCurrentCommandCharNum = NULL ; m_psReplyText = NULL ; m_uiCurrentReplyLength = 0 ; m_lTokenList.DeleteAllEntries () ; m_lCommandList.DeleteAllEntries () ; } /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ void CMessageCommandLine::NewRawCommand ( const char* _psMessageCommand, char* _psReplyText ) { //\\// ResetCommand () ; m_psRawCommand = _psMessageCommand ; m_pcCurrentCommandCharNum = _psMessageCommand ; m_pcCurrentTokenCharNum = _psMessageCommand ; m_psReplyText = _psReplyText ; m_psReplyText[0] = NULL ; m_uiCurrentReplyLength = 0 ; return ; } /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ char* CMessageCommandLine::GetNextToken ( char* _psToken ) // The raw command is parsed to locate the next token. // The calling routine supplies the buffer to copy the token to. // The routine returns a pointer to the argument that was passed. // Not being able to find a token is handled by writing the supplied string // with the null string, meaning the value pointed to is the NULL character (i.e.=0) { char* pcToken ; unsigned int uiTokenLength ; //\\// // initialize returned argument to Null String _psToken[0] = NULL ; // Locate the next keyword, and advance the current parsing position pcToken = FirstTokenBegin(m_pcCurrentCommandCharNum) ; uiTokenLength = FirstTokenLength(pcToken) ; m_pcCurrentTokenCharNum = pcToken ; m_pcCurrentCommandCharNum = pcToken + uiTokenLength ; //maybe there were no more tokens if ( pcToken == NULL ) goto Done ; // strncat is prefered over strncpy because it does not pad // the destination string with NULLs to reach the specified number of chars // and always appends a NULL character at the end of the resulting string strncat ( _psToken, pcToken, uiTokenLength ) ; Done: return _psToken ; } /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ void CMessageCommandLine::CopyReplyText ( const char* _psPreplyText ) { //\\// // strncat is prefered over strncpy because it does not pad // the destination string with NULLs to reach the specified number of chars // and always appends a NULL character at the end of the resulting string m_psReplyText[0] = NULL ; strncat ( m_psReplyText, _psPreplyText, KiMaxLengthReplyTextToCoor ) ; // remember the current length of the reply string m_uiCurrentReplyLength = strlen ( m_psReplyText ) ; return ; } /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ void CMessageCommandLine::AppendReplyText ( const char* _psPreplyText ) { //\\// // Add the new characters, starting at the known current end of the string // to minimize the search for the NULL character within strncat strncat ( &m_psReplyText[m_uiCurrentReplyLength], _psPreplyText, KiMaxLengthReplyTextToCoor - m_uiCurrentReplyLength ) ; // remember the current length of the reply string m_uiCurrentReplyLength += strlen ( &m_psReplyText[m_uiCurrentReplyLength] ) ; return ; }