Go to the documentation of this file.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/mobility/sensors/reportgeomagneticproperty.h"
00041 #include "jaus/core/scaledinteger.h"
00042 #include <cxutils/math/cxmath.h>
00043
00044 const double JAUS::ReportGeomagneticProperty::Limits::MinMagneticVariation = -CxUtils::PI;
00045 const double JAUS::ReportGeomagneticProperty::Limits::MaxMagneticVariation = CxUtils::PI;
00046
00047 using namespace JAUS;
00048
00049
00058 ReportGeomagneticProperty::ReportGeomagneticProperty(const Address& dest, const Address& src) : Message(REPORT_GEOMAGNETIC_PROPERTY, dest, src)
00059 {
00060 mMagneticVariation = 0;
00061 }
00062
00063
00069 ReportGeomagneticProperty::ReportGeomagneticProperty(const ReportGeomagneticProperty& message) : Message(REPORT_GEOMAGNETIC_PROPERTY)
00070 {
00071 *this = message;
00072 }
00073
00074
00080 ReportGeomagneticProperty::~ReportGeomagneticProperty()
00081 {
00082 }
00083
00084
00095 bool ReportGeomagneticProperty::SetMagneticVariation(const double radians)
00096 {
00097 if(radians >= Limits::MinMagneticVariation && radians <= Limits::MaxMagneticVariation)
00098 {
00099 mMagneticVariation = radians;
00100 return true;
00101 }
00102 return false;
00103 }
00104
00105
00117 int ReportGeomagneticProperty::WriteMessageBody(Packet& packet) const
00118 {
00119 int expected = USHORT_SIZE;
00120 int written = 0;
00121
00122 written += ScaledInteger::Write(packet, mMagneticVariation, Limits::MaxMagneticVariation, Limits::MinMagneticVariation, ScaledInteger::UShort);
00123
00124 return expected == written ? written : -1;
00125 }
00126
00127
00139 int ReportGeomagneticProperty::ReadMessageBody(const Packet& packet)
00140 {
00141 int expected = USHORT_SIZE;
00142 int read = 0;
00143
00144 read += ScaledInteger::Read(packet, mMagneticVariation, Limits::MaxMagneticVariation, Limits::MinMagneticVariation, ScaledInteger::UShort);
00145
00146 return expected == read ? read : -1;
00147 }
00148
00149
00155 void ReportGeomagneticProperty::ClearMessageBody()
00156 {
00157 mMagneticVariation = 0;
00158 }
00159
00160
00168 int ReportGeomagneticProperty::RunTestCase() const
00169 {
00170 int result = 0;
00171
00172 Packet packet;
00173 ReportGeomagneticProperty msg1, msg2;
00174 msg1.SetMagneticVariation(1.2333);
00175
00176 if(msg1.WriteMessageBody(packet))
00177 {
00178 msg2.ClearMessage();
00179 if(msg2.ReadMessageBody(packet))
00180 {
00181 if(msg1.GetMagneticVariation() - msg2.GetMagneticVariation() <= 0.001)
00182 {
00183 result = 1;
00184 }
00185 }
00186 }
00187
00188 return result;
00189 }
00190
00191
00197 ReportGeomagneticProperty& ReportGeomagneticProperty::operator=(const ReportGeomagneticProperty& message)
00198 {
00199 if(this != &message)
00200 {
00201 CopyHeaderData(&message);
00202 mMagneticVariation = message.mMagneticVariation;
00203 }
00204 return *this;
00205 }
00206
00207
00208