//////////////////////////////////////////////////////////////////////////////// // // Classification: Unclassified // //////////////////////////////////////////////////////////////////////////////// //------------------------------------------------------------------------------ // // File Name: BMC2_Delete_Msg.cc // // Description: A derived class for BMC2 messages for sending delete messages // to the FCC in the KI Testbed. // // %Z% Revision: %I% %M% %H% // //*********************** Change History *************************************** // // Date Engineer Description // ---- -------- ---------------------------------------------------- // 22Nov02 G. McKee Initial Creation. // 22Nov02 G. McKee added six new 'BMC2' subclasses as per SCR# 561 069 // 22Jan03 J. Freyschlag Added copy constructor and assignment operator. // 30Jun03 J. Freyschlag SCR 576503: Removed copy constructor and assignment // operator. Since no dynamic attributes, the defaults // work fine. (cleaned up some spacing) // 11Aug03 G. McKee adapted to 'gcc' compiler on SUSE LINUX 8.1 // 14oct03 G. McKee added 'Swap()' logic for LINUX // //////////////////////////////////////////////////////////////////////////////// //***************************************************************************** // INCLUDES //***************************************************************************** #include #include #include "BMC2_Delete_Msg.hh" #include "SerialuStrm.hh" //***************************************************************************** // DEFINES //***************************************************************************** //***************************************************************************** // ENUMERATIONS //***************************************************************************** //***************************************************************************** // CONSTANTS //***************************************************************************** static const char ABORT_CMD[] = "\n abort_cmd: "; static const char EAN[] = "\t EAN: "; //***************************************************************************** // TYPEDEFS //***************************************************************************** //***************************************************************************** // GLOBAL VARIABLES //***************************************************************************** //***************************************************************************** // STATIC DATA MEMBERS //***************************************************************************** //***************************************************************************** // EXTERNAL OBJECTS/FUNCTIONS //***************************************************************************** //***************************************************************************** // BMC2_Delete_Msg Class MEMBER FUNCTIONS //***************************************************************************** //////////////////////////////////////////////////////////////////////////// // // function name - ReadMsgBody // // Purpose: This function is called by 'ReadMsg' to do subclass specific // input of the subclass message body. This function reads in // the ICR message BODY from a UniStream and returns a reference // to the received message. The reference returned is a reference // to the derived message type of the message read. // In other words, if the format read in the ICR_Msg_Hdr is RADAR_FMT, // a RADAR_Msg& is returned in msgPtr; // // Inputs: inStream - the UniStream that the ICR_Msg is being read from // msgHeader - the msg header that has been received by 'ReadMsg' // // Output: msgPtr - the reference to the ICR_Msg body that has been read. // //////////////////////////////////////////////////////////////////////////// void BMC2_Delete_Msg::ReadMsgBody (UniStream* inStream, ICR_Msg_Hdr msgHeader, ICR_Ptr& msgPtr) { const char CSU[] = "ReadMsgBody: "; IO_Stat Stat; nat32 bodySize = sizeof( body ); // Number of Bytes in Message body uchar8* pBodyAddress = (uchar8*)&body; // Address of Message body nat32 calcCRC; nat32 xmtdCRC; hdr = msgHeader; // ok, Read the body. if ( bodySize > 0 ) { Stat = inStream->Read( pBodyAddress, bodySize ); // If error occurred while reading the body, // then report it and run for your life if ( Stat != OKAY ) { writeError(CSU, "Error reading message body from ", (char*)inStream->GetLabel()); if ( Stat != TIMEOUT ) inStream->Close(); msgPtr = NULL; return; // ERROR RETURN } // end if } // end if (bodySize>0) // Verify the CRC if this a serial port and a TTY. if (( inStream->UType() == SERIAL ) && ((SerialuStream *)inStream)->isTTY() ) { nat32 crcSz = sizeof(xmtdCRC); // Read the transmitted CRC Stat = inStream->Read( (uchar8 *)&xmtdCRC, crcSz ); if ( Stat != OKAY ) { writeError(CSU, "Error in CRC while reading message from ", (char*)inStream->GetLabel()); if ( Stat != TIMEOUT ) inStream->Close(); msgPtr = NULL; return; // ERROR RETURN } // Calculate the CRC based on the header and body of message calcCRC = computeCRC( (uchar8 *)&msgHeader, sizeof(ICR_Msg_Hdr), FALSE ); calcCRC = computeCRC( pBodyAddress, bodySize ); // Do the actual compare of the transmitted and calculated CRCs if ( xmtdCRC != calcCRC) { writeError(CSU, "Failed reading via serial input from ", (char*)inStream->GetLabel() ); writeError(CSU, ": Invalid CRC: ", xmtdCRC, "\t calculated: " , calcCRC); msgPtr = NULL; return; // ERROR RETURN } // end if (xmtdCRC!=calcCRC) } // end of the CRC logic // fix the translation code into this location msgPtr = this; } // end BMC2_Delete_Msg::ReadMsgBody (UniStream...) //////////////////////////////////////////////////////////////////////////// // function name - WriteMsg // // Purpose: This function writes a ICR message to a UniStream and // returns a bool indicating the write status. This parent // class method is called by derived classes after they copy // their data to a buffer. // // Inputs: outStream - the UniStream that the ICR_Msg is being read from // mvBuffer - if TRUE data is moved to buffer and written, // if FALSE data is written directly from the buffer // // Outputs: None //////////////////////////////////////////////////////////////////////////// boolean_tstt BMC2_Delete_Msg::WriteMsg( UniStream *outStream, bool mvBuffer ) { // if the data is supposed to be moved, move the header. if ( mvBuffer ) { // copy the message body memcpy( writeBuf + sizeof(ICR_Msg_Hdr), &body, sizeof(body) ); } // call the parent class version of 'WriteMsg' to finish the job // note: the parent class will copy the header as appropriate return ICR_Msg::WriteMsg(outStream, mvBuffer); } // end WriteMsg () // ************************************************************* // // function name - DisplaytoErrLog // // Description: // Write pertinent Radar data to the Error Log. // // Parameters: // MsgNumber - Sequential message number of data // being displayed. // RcvTime - Time of message receipt (in ascii // format. // ErrorMask - Error log mask value. // // ************************************************************* void BMC2_Delete_Msg::DisplaytoErrLog( nat32 MsgNumber, char* RcvTime, int32 ErrorMask ) { ICR_Msg::DisplaytoErrLog( MsgNumber, RcvTime, ErrorMask ); errorlog << Level( ErrorMask ); errorlog << ABORT_CMD << body.abort_cmd << EAN << body.EAN << endl << ende; } // ************************************************************* // // function name - DisplaytoLog // // Description: // Write pertinent Radar data to the Comm log file. // // Parameters: // LogStream - Comm processor log file stream // MsgNumber - Sequential message number of data // being displayed. // RcvTime - Time of message receipt (in ascii // format. // // ************************************************************* void BMC2_Delete_Msg::DisplaytoLog( ofstream& LogStream, nat32 MsgNumber, char* RcvTime ) { ICR_Msg::DisplaytoLog( LogStream, MsgNumber, RcvTime ); LogStream << endl << "BMC2 Delete Message: " << ABORT_CMD << body.abort_cmd << EAN << body.EAN << endl << endl; } // ============================================================================ BMC2_Delete_Msg::BMC2_Delete_Msg( DataSource source ) : ICR_Msg( source, LAUNCH_DELETE_FMT ) { hdr.body_length = sizeof (body); body.abort_cmd = ABORT_EAM; body.EAN = 0; } // end constructor () // ============================================================================ /////////////////////////////////////////////////////////////////////////////// // // BMC2_Engage_Msg::validateData - Validate Radar Data // // Parameters: None // // Returns: TT_TRUE - If contents of message are valid // TT_FALSE - If contents of message have invalid data // // This member function validates the contents of the radar data. // /////////////////////////////////////////////////////////////////////////////// boolean_tstt BMC2_Delete_Msg::validateData( ) {char* pNotUsed=""; return validateData( pNotUsed );} boolean_tstt BMC2_Delete_Msg::validateData( char* &pErrorTxt ) { // Initialize Error Text to Nothing pErrorTxt = ""; // Create a Stream for generating error text. Static for performance and // so that return pointer does not point to something on the stack // const int ERROR_BUFFER_SIZE = 256; // static char errorBuffer[ ERROR_BUFFER_SIZE ]; // static ostrstream errorStrm( errorBuffer, ERROR_BUFFER_SIZE ); // errorStrm.seekp( 0 ); // Reposition to start of stream // ******** // NOTE: no data field is checked, maybe there should be some checks // ******** // If fell through then data is valid, so return true. return TT_TRUE; } // end BMC2_Delete_Msg::validateData(char*) //////////////////////////////////////////////////////////////////////////// // // function name - Swap // // Purpose: This function performs a byte swap of all the fields in a // DATA STRUCTURE. // // Inputs: inBody - The DATA STRUCTURE that should be swapped. // // Outputs: Returns a swapped DATA STRUCTURE. // //////////////////////////////////////////////////////////////////////////// BMC2_Delete_Data BMC2_Delete_Msg::Swap (const BMC2_Delete_Data & inBody) { #if BYTE_ORDER != LITTLE_ENDIAN return inBody; #else BMC2_Delete_Data outData; outData.abort_cmd = (int32) byteswap( inBody.abort_cmd ); // will 'byteswap' do ENUMs correctly? outData.EAN = byteswap( inBody.EAN ); // outData.future = byteswap( inBody.future ); // not needed, just here for reference return outData; #endif } // end BMC2_Delete_Msg::Swap (BMC2_Delete_Data) //////////////////////////////////////////////////////////////////////////////// // // Classification: Unclassified // ////////////////////////////////////////////////////////////////////////////////