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/extras/rangesensor/reportrangesensorconfiguration.h"
00041
00042 using namespace JAUS;
00043
00055 int ReportRangeSensorConfiguration::WriteMessageBody(Packet& packet) const
00056 {
00057 int total = 0;
00058 int expected = BYTE_SIZE;
00059
00060 RangeSensorConfig::List::const_iterator config;
00061
00062 total += packet.Write((Byte)mConfiguration.size());
00063
00064 for(config = mConfiguration.begin();
00065 config != mConfiguration.end();
00066 config++)
00067 {
00068 expected += BYTE_SIZE*2 + UINT_SIZE + LONG_FLOAT_SIZE*4 + (UInt)config->mName.size();
00069 total += packet.WriteByte(config->mID);
00070 total += packet.Write( (UInt)config->mName.size() );
00071 total += packet.Write( config->mName);
00072 total += packet.Write( config->mMaxRange );
00073 total += packet.Write( config->mMinRange );
00074 total += packet.Write( config->mAngleIncrement );
00075 total += packet.Write( config->mScanAngle );
00076 total += packet.WriteByte((Byte)config->mUnitType);
00077 }
00078
00079 return total == expected ? total : -1;
00080 }
00081
00082
00094 int ReportRangeSensorConfiguration::ReadMessageBody(const Packet& packet)
00095 {
00096 int total = 0;
00097 int expected = BYTE_SIZE;
00098 Byte size = 0;
00099
00100 total += packet.Read(size);
00101
00102 for(Byte i = 0; i < size; i++)
00103 {
00104 Byte bval = 0;
00105 UInt uval = 0;
00106 RangeSensorConfig config;
00107
00108 expected += BYTE_SIZE*2 + UINT_SIZE + LONG_FLOAT_SIZE*4;
00109 total += packet.Read(bval);
00110 config.mID = bval;
00111 total += packet.Read(uval);
00112 if(uval > 0)
00113 {
00114 total += packet.Read(config.mName, uval);
00115 expected += uval;
00116 }
00117 total += packet.Read(config.mMaxRange);
00118 total += packet.Read(config.mMinRange);
00119 total += packet.Read(config.mAngleIncrement);
00120 total += packet.Read(config.mScanAngle);
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 total += packet.Read(bval);
00132 config.mUnitType = (RangeSensorConfig::UnitType)bval;
00133
00134 mConfiguration.push_back(config);
00135 }
00136
00137 return total == expected ? total : -1;
00138 }
00139
00140
00147 bool ReportRangeSensorConfiguration::IsLargeDataSet(const unsigned int maxPayloadSize) const
00148 {
00149 unsigned int expected = BYTE_SIZE;
00150
00151 RangeSensorConfig::List::const_iterator config;
00152
00153 for(config = mConfiguration.begin();
00154 config != mConfiguration.end();
00155 config++)
00156 {
00157 expected += BYTE_SIZE*2 + UINT_SIZE*4;
00158 }
00159
00160 return expected > maxPayloadSize ? true : false;
00161 }
00162
00163
00164