00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 #include "jaus/core/control/reportcontrol.h" 00041 00042 using namespace JAUS; 00043 00044 const Byte ReportControl::Limits::MaxNodeID = 255; 00045 const Byte ReportControl::Limits::MaxComponentID = 255; 00046 00047 00056 ReportControl::ReportControl(const Address& dest, const Address& src) : Message(REPORT_CONTROL, dest, src) 00057 { 00058 mControllingComponent = 0; 00059 mAuthorityCode = 0; 00060 } 00061 00062 00068 ReportControl::ReportControl(const ReportControl& message) : Message(REPORT_CONTROL) 00069 { 00070 *this = message; 00071 } 00072 00073 00079 ReportControl::~ReportControl() 00080 { 00081 } 00082 00083 00091 bool ReportControl::SetControllingComponent(const Address &controller) 00092 { 00093 mControllingComponent = controller; 00094 return true; 00095 } 00096 00097 00109 int ReportControl::WriteMessageBody(Packet& packet) const 00110 { 00111 int expected = USHORT_SIZE + (3 * BYTE_SIZE); 00112 int written = 0; 00113 00114 written += packet.Write(mControllingComponent.mSubsystem); 00115 written += packet.Write(mControllingComponent.mNode); 00116 written += packet.Write(mControllingComponent.mComponent); 00117 written += packet.Write(mAuthorityCode); 00118 00119 return expected == written ? written : -1; 00120 } 00121 00122 00134 int ReportControl::ReadMessageBody(const Packet& packet) 00135 { 00136 int expected = USHORT_SIZE + (3 * BYTE_SIZE); 00137 int read = 0; 00138 00139 read += packet.Read(mControllingComponent.mSubsystem); 00140 read += packet.Read(mControllingComponent.mNode); 00141 read += packet.Read(mControllingComponent.mComponent); 00142 read += packet.Read(mAuthorityCode); 00143 00144 return expected == read ? read : -1; 00145 } 00146 00147 00153 void ReportControl::ClearMessageBody() 00154 { 00155 mControllingComponent = 0; 00156 mAuthorityCode = 0; 00157 } 00158 00159 00167 int ReportControl::RunTestCase() const 00168 { 00169 int result = 0; 00170 00171 Packet packet; 00172 ReportControl msg1, msg2; 00173 msg1.SetControllingComponent(Address(1, 2, 3)); 00174 msg1.SetAuthorityCode(1); 00175 00176 if( msg1.WriteMessageBody(packet) != -1 && 00177 msg2.ReadMessageBody(packet) != -1 && 00178 msg1.GetAuthorityCode() == msg2.GetAuthorityCode() && 00179 msg1.GetControllingComponent() == msg2.GetControllingComponent()) 00180 { 00181 result = 1; 00182 } 00183 00184 return result; 00185 } 00186 00187 00193 ReportControl& ReportControl::operator=(const ReportControl& message) 00194 { 00195 if(this != &message) 00196 { 00197 CopyHeaderData(&message); 00198 mControllingComponent = message.mControllingComponent; 00199 mAuthorityCode = message.mAuthorityCode; 00200 } 00201 return *this; 00202 } 00203 00204 00205 /* End of File */