cmtpacket.cpp

00001 /*! \file Cmtpacket.cpp
00002 
00003         For information about objects in this file, see the appropriate header:
00004         \ref Cmtpacket.h
00005 
00006         \section FileCopyright Copyright Notice 
00007         Copyright (C) Xsens Technologies B.V., 2006.  All rights reserved.
00008         
00009         This source code is intended for use only by Xsens Technologies BV and
00010         those that have explicit written permission to use it from
00011         Xsens Technologies BV.
00012         
00013         THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
00014         KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
00015         IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00016         PARTICULAR PURPOSE.
00017 */
00018 
00019 #include "cmtpacket.h"
00020 
00021 #ifdef _CMT_DLL_EXPORT
00022 //#include "xsens_math.h"
00023 #include <settings.h>
00024 #endif
00025 
00026 #ifdef _LOG_PACKET
00027 #        define PACKETLOG        CMTLOG
00028 #else
00029 #        define PACKETLOG(...)
00030 #endif
00031 
00032 
00033 namespace xsens {
00034 
00035 //////////////////////////////////////////////////////////////////////////////////////////
00036 ////////////////////////////////////// Packet class //////////////////////////////////////
00037 //////////////////////////////////////////////////////////////////////////////////////////
00038 #ifndef CMT_OUTPUTSETTINGS_DATAFORMAT_DOUBLE
00039 #define CMT_OUTPUTSETTINGS_DATAFORMAT_DOUBLE                0x00000300
00040 #endif
00041 #define FORMAT_DOUBLE                ((m_formatList[index].m_outputSettings & CMT_OUTPUTSETTINGS_DATAFORMAT_MASK)|CMT_OUTPUTSETTINGS_DATAFORMAT_DOUBLE)
00042 #define ISDOUBLE(a)                        (m_infoList[index].a >= m_infoList[index].m_doubleBoundary)
00043 #define CHECKIFDOUBLE(a)        ISDOUBLE(a)?FORMAT_DOUBLE:m_formatList[index].m_outputSettings
00044 
00045 //////////////////////////////////////////////////////////////////////////////////////////
00046 Packet::Packet(uint16_t items, bool xbus)
00047 {
00048         PACKETLOG("Create Packet %p\n",this);
00049 
00050         m_itemCount = items;
00051         m_infoList = NULL;
00052         m_formatList = new CmtDataFormat[m_itemCount];
00053         m_toa = 0;
00054         m_rtc = 0;
00055         m_xm = xbus;
00056 }
00057 
00058 //////////////////////////////////////////////////////////////////////////////////////////
00059 Packet::~Packet()
00060 {
00061         PACKETLOG("Destroy Packet %p\n",this);
00062         LSTCHKDELNUL(m_formatList);
00063         LSTCHKDELNUL(m_infoList);
00064 }
00065 
00066 //////////////////////////////////////////////////////////////////////////////////////////
00067 CmtDataFormat Packet::getDataFormat(const uint16_t index) const
00068 {
00069         if (index >= m_itemCount || m_formatList == NULL)
00070         {
00071                 CmtDataFormat temp;
00072                 return temp;
00073         }
00074         return m_formatList[index];
00075 }
00076 
00077 //////////////////////////////////////////////////////////////////////////////////////////
00078 bool Packet::setDataFormat(const CmtDataFormat& format, const uint16_t index)
00079 {
00080         if (index < m_itemCount)
00081         {
00082                 m_formatList[index] = format;
00083                 LSTCHKDELNUL(m_infoList);
00084                 return true;
00085         }
00086         return false;
00087 }
00088 
00089 //////////////////////////////////////////////////////////////////////////////////////////
00090 bool Packet::setDataFormat(const CmtOutputMode outputMode, const CmtOutputSettings outputSettings, const uint16_t index)
00091 {
00092         if (index < m_itemCount)
00093         {
00094                 m_formatList[index].m_outputMode = outputMode;
00095                 m_formatList[index].m_outputSettings = outputSettings;
00096                 LSTCHKDELNUL(m_infoList);
00097                 return true;
00098         }
00099         return false;
00100 }
00101 
00102 //////////////////////////////////////////////////////////////////////////////////////////
00103 bool Packet::getXbus(void) const
00104 {
00105         return m_xm;
00106 }
00107 
00108 //////////////////////////////////////////////////////////////////////////////////////////
00109 void Packet::setXbus(bool xbus, bool convert)
00110 {
00111         if (xbus != m_xm)
00112         {
00113                 if (convert)
00114                 {
00115                         CmtMtTimeStamp stamp = getSampleCounter(0);
00116 
00117                         // move the time stamp value(s) around
00118                         if (xbus)
00119                         {
00120                                 // new version is Xbus, so old version is regular format -> place timestamp at start of packet and remove from all individual data units
00121                                 // remove the timestamp from all data units
00122 
00123                                 // insert timestamp at the start
00124                                 m_msg.insertData(2,0);
00125                                 m_msg.setDataShort(stamp,0);
00126                         }
00127                         else
00128                         {
00129                                 // new version is regular, so old version is Xbus format -> place timestamp at end of all individual data units and remove from start of packet
00130                                 // append the timestamp to all data units
00131 
00132                                 // remove timestamp from the start
00133                                 m_msg.deleteData(2,0);
00134                         }
00135                 }
00136                 // update the state cache
00137                 m_xm = xbus;
00138                 LSTCHKDELNUL(m_infoList);
00139         }
00140 }
00141 
00142 //////////////////////////////////////////////////////////////////////////////////////////
00143 // Return the floating/fixed point value size
00144 uint16_t Packet::getFPValueSize(const uint16_t index) const
00145 {
00146         uint16_t ds = 4;
00147         switch (m_formatList[index].m_outputSettings & CMT_OUTPUTSETTINGS_DATAFORMAT_MASK)
00148         {
00149                 case CMT_OUTPUTSETTINGS_DATAFORMAT_FLOAT:
00150                         ds = 4;
00151                         break;
00152 
00153                 case CMT_OUTPUTSETTINGS_DATAFORMAT_DOUBLE:
00154                         ds = 8;
00155                         break;
00156 
00157                 case CMT_OUTPUTSETTINGS_DATAFORMAT_FP1632:
00158                         ds = 6;
00159                         break;
00160 
00161                 case CMT_OUTPUTSETTINGS_DATAFORMAT_F1220:
00162                         ds = 4;
00163                         break;
00164         }
00165         return ds;
00166 }
00167 
00168 //////////////////////////////////////////////////////////////////////////////////////////
00169 // Return the data size.
00170 uint16_t Packet::getDataSize(const uint16_t index) const
00171 {
00172         if (m_infoList == NULL)
00173         {
00174                 // allocate list
00175                 m_infoList = new PacketInfo[m_itemCount];
00176                 uint16_t totalOffset;
00177                 if (m_xm)
00178                         totalOffset = 2;
00179                 else
00180                         totalOffset = 0;
00181 
00182                 // fill lists
00183                 for (uint16_t i = 0;i < m_itemCount;++i)
00184                 {
00185                         m_infoList[i].m_offset = totalOffset;
00186                         m_infoList[i].m_size = 0;
00187 
00188                         uint16_t ds = getFPValueSize(i);
00189 
00190                         if (m_formatList[i].m_outputMode & CMT_OUTPUTMODE_RAW)
00191                         {
00192                                 m_infoList[i].m_rawData = totalOffset;
00193                                 m_infoList[i].m_rawAcc = totalOffset;
00194                                 m_infoList[i].m_rawGyr = totalOffset+6;
00195                                 m_infoList[i].m_rawMag = totalOffset+12;
00196                                 m_infoList[i].m_rawTemp = totalOffset+18;
00197 
00198                                 m_infoList[i].m_size += 20;
00199                                 totalOffset += 20;
00200                         }
00201                         else
00202                         {
00203                                 m_infoList[i].m_rawData = CMT_DATA_ITEM_NOT_AVAILABLE;
00204                                 m_infoList[i].m_rawAcc = CMT_DATA_ITEM_NOT_AVAILABLE;
00205                                 m_infoList[i].m_rawGyr = CMT_DATA_ITEM_NOT_AVAILABLE;
00206                                 m_infoList[i].m_rawMag = CMT_DATA_ITEM_NOT_AVAILABLE;
00207                                 m_infoList[i].m_rawTemp = CMT_DATA_ITEM_NOT_AVAILABLE;
00208                         }
00209 
00210 
00211                         if (m_formatList[i].m_outputMode & CMT_OUTPUTMODE_GPSPVT_PRESSURE)
00212                         {
00213                                 m_infoList[i].m_gpsPvtData = totalOffset;
00214                                 m_infoList[i].m_gpsPvtPressure = totalOffset;
00215                                 m_infoList[i].m_gpsPvtPressureAge = totalOffset + 2;
00216                                 m_infoList[i].m_size += 3;
00217                                 totalOffset += 3;
00218                                 
00219                                 m_infoList[i].m_gpsPvtGpsData = totalOffset;
00220                                 m_infoList[i].m_gpsPvtItow = totalOffset;
00221                                 m_infoList[i].m_gpsPvtLatitude = totalOffset + 4;
00222                                 m_infoList[i].m_gpsPvtLongitude = totalOffset + 8;
00223                                 m_infoList[i].m_gpsPvtHeight = totalOffset + 12;
00224                                 m_infoList[i].m_gpsPvtVeln = totalOffset + 16;
00225                                 m_infoList[i].m_gpsPvtVele = totalOffset + 20;
00226                                 m_infoList[i].m_gpsPvtVeld = totalOffset + 24;
00227                                 m_infoList[i].m_gpsPvtHacc = totalOffset + 28;
00228                                 m_infoList[i].m_gpsPvtVacc = totalOffset + 32;
00229                                 m_infoList[i].m_gpsPvtSacc = totalOffset + 36;
00230                                 m_infoList[i].m_gpsPvtGpsAge = totalOffset + 40;
00231                                 m_infoList[i].m_size += 41;
00232                                 totalOffset += 41;
00233                         }
00234                         else
00235                         {
00236                                 m_infoList[i].m_gpsPvtData = CMT_DATA_ITEM_NOT_AVAILABLE;
00237                                 m_infoList[i].m_gpsPvtPressure = CMT_DATA_ITEM_NOT_AVAILABLE;
00238                                 m_infoList[i].m_gpsPvtPressureAge = CMT_DATA_ITEM_NOT_AVAILABLE;
00239 
00240                                 m_infoList[i].m_gpsPvtGpsData = CMT_DATA_ITEM_NOT_AVAILABLE;
00241                                 m_infoList[i].m_gpsPvtItow = CMT_DATA_ITEM_NOT_AVAILABLE;
00242                                 m_infoList[i].m_gpsPvtLatitude = CMT_DATA_ITEM_NOT_AVAILABLE;
00243                                 m_infoList[i].m_gpsPvtLongitude = CMT_DATA_ITEM_NOT_AVAILABLE;
00244                                 m_infoList[i].m_gpsPvtHeight = CMT_DATA_ITEM_NOT_AVAILABLE;
00245                                 m_infoList[i].m_gpsPvtVeln = CMT_DATA_ITEM_NOT_AVAILABLE;
00246                                 m_infoList[i].m_gpsPvtVele = CMT_DATA_ITEM_NOT_AVAILABLE;
00247                                 m_infoList[i].m_gpsPvtVeld = CMT_DATA_ITEM_NOT_AVAILABLE;
00248                                 m_infoList[i].m_gpsPvtHacc = CMT_DATA_ITEM_NOT_AVAILABLE;
00249                                 m_infoList[i].m_gpsPvtVacc = CMT_DATA_ITEM_NOT_AVAILABLE;
00250                                 m_infoList[i].m_gpsPvtSacc = CMT_DATA_ITEM_NOT_AVAILABLE;
00251                                 m_infoList[i].m_gpsPvtGpsAge = CMT_DATA_ITEM_NOT_AVAILABLE;
00252                         }
00253 
00254                         m_infoList[i].m_temp = CMT_DATA_ITEM_NOT_AVAILABLE;
00255                         if (m_formatList[i].m_outputMode & CMT_OUTPUTMODE_TEMP)
00256                         {
00257                                 m_infoList[i].m_temp = totalOffset;
00258                                 m_infoList[i].m_size += ds;
00259                                 totalOffset += ds;
00260                         }
00261 
00262                         if (m_formatList[i].m_outputMode & CMT_OUTPUTMODE_CALIB)
00263                         {
00264                                 m_infoList[i].m_calData = totalOffset;
00265                                 if ((m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_CALIBMODE_ACC_MASK) == 0)
00266                                 {
00267                                         m_infoList[i].m_calAcc = totalOffset;
00268                                         m_infoList[i].m_size += 3*ds;
00269                                         totalOffset += 3*ds;
00270                                 }
00271                                 else
00272                                         m_infoList[i].m_calAcc = CMT_DATA_ITEM_NOT_AVAILABLE;
00273 
00274                                 if ((m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_CALIBMODE_GYR_MASK) == 0)
00275                                 {
00276                                         m_infoList[i].m_calGyr = totalOffset;
00277                                         m_infoList[i].m_size += 3*ds;
00278                                         totalOffset += 3*ds;
00279                                 }
00280                                 else
00281                                         m_infoList[i].m_calGyr = CMT_DATA_ITEM_NOT_AVAILABLE;
00282 
00283                                 if ((m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_CALIBMODE_MAG_MASK) == 0)
00284                                 {
00285                                         m_infoList[i].m_calMag = totalOffset;
00286                                         m_infoList[i].m_size += 3*ds;
00287                                         totalOffset += 3*ds;
00288                                 }
00289                                 else
00290                                         m_infoList[i].m_calMag = CMT_DATA_ITEM_NOT_AVAILABLE;
00291 
00292                                 if ((m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_CALIBMODE_ACCGYRMAG_MASK) == CMT_OUTPUTSETTINGS_CALIBMODE_ACCGYRMAG_MASK)
00293                                         m_infoList[i].m_calData = CMT_DATA_ITEM_NOT_AVAILABLE;
00294                         }
00295                         else
00296                         {
00297                                 m_infoList[i].m_calData = CMT_DATA_ITEM_NOT_AVAILABLE;
00298                                 m_infoList[i].m_calAcc = CMT_DATA_ITEM_NOT_AVAILABLE;
00299                                 m_infoList[i].m_calGyr = CMT_DATA_ITEM_NOT_AVAILABLE;
00300                                 m_infoList[i].m_calMag = CMT_DATA_ITEM_NOT_AVAILABLE;
00301                         }
00302 
00303                         m_infoList[i].m_oriEul = CMT_DATA_ITEM_NOT_AVAILABLE;
00304                         m_infoList[i].m_oriQuat = CMT_DATA_ITEM_NOT_AVAILABLE;
00305                         m_infoList[i].m_oriMat = CMT_DATA_ITEM_NOT_AVAILABLE;
00306 
00307                         if (m_formatList[i].m_outputMode & CMT_OUTPUTMODE_ORIENT)
00308                         {
00309                                 switch (m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_ORIENTMODE_MASK)
00310                                 {
00311                                 case CMT_OUTPUTSETTINGS_ORIENTMODE_EULER:
00312                                         m_infoList[i].m_oriEul = totalOffset;
00313                                         m_infoList[i].m_size += 3*ds;
00314                                         totalOffset += 3*ds;
00315                                         break;
00316                                 case CMT_OUTPUTSETTINGS_ORIENTMODE_QUATERNION:
00317                                         m_infoList[i].m_oriQuat = totalOffset;
00318                                         m_infoList[i].m_size += 4*ds;
00319                                         totalOffset += 4*ds;
00320                                         break;
00321                                 case CMT_OUTPUTSETTINGS_ORIENTMODE_MATRIX:
00322                                         m_infoList[i].m_oriMat = totalOffset;
00323                                         m_infoList[i].m_size += 9*ds;
00324                                         totalOffset += 9*ds;
00325                                         break;
00326                                 default:
00327                                         break;
00328                                 }
00329                         }
00330 
00331                         m_infoList[i].m_analogIn1 = CMT_DATA_ITEM_NOT_AVAILABLE;
00332                         if (m_formatList[i].m_outputMode & CMT_OUTPUTMODE_AUXILIARY)
00333                         {
00334                                 if ((m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_AUXILIARYMODE_AIN1_MASK) == 0)
00335                                 {
00336                                         m_infoList[i].m_analogIn1 = totalOffset;
00337                                         m_infoList[i].m_size += 2;
00338                                         totalOffset += 2;
00339                                 }
00340                                 else
00341                                         m_infoList[i].m_analogIn1 = CMT_DATA_ITEM_NOT_AVAILABLE;
00342 
00343                                 if ((m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_AUXILIARYMODE_AIN2_MASK) == 0)
00344                                 {
00345                                         m_infoList[i].m_analogIn2 = totalOffset;
00346                                         m_infoList[i].m_size += 2;
00347                                         totalOffset += 2;
00348                                 }
00349                                 else
00350                                         m_infoList[i].m_analogIn2 = CMT_DATA_ITEM_NOT_AVAILABLE;
00351                         }
00352 
00353                         m_infoList[i].m_posLLA = CMT_DATA_ITEM_NOT_AVAILABLE;
00354                         if (m_formatList[i].m_outputMode & CMT_OUTPUTMODE_POSITION)
00355                         {
00356                                 switch (m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_POSITIONMODE_MASK)
00357                                 {
00358                                 case CMT_OUTPUTSETTINGS_POSITIONMODE_LLA_WGS84:
00359                                         m_infoList[i].m_posLLA = totalOffset;
00360                                         m_infoList[i].m_size += 3*ds;
00361                                         totalOffset += 3*ds;
00362                                 }
00363                         }
00364 
00365                         m_infoList[i].m_velNEDorNWU = CMT_DATA_ITEM_NOT_AVAILABLE;
00366                         if (m_formatList[i].m_outputMode & CMT_OUTPUTMODE_VELOCITY)
00367                         {
00368                                 switch (m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_VELOCITYMODE_MASK)
00369                                 {
00370                                 case CMT_OUTPUTSETTINGS_VELOCITYMODE_MS_XYZ:
00371                                         m_infoList[i].m_velNEDorNWU = totalOffset;
00372                                         m_infoList[i].m_size += 3*ds;
00373                                         totalOffset += 3*ds;
00374                                 }
00375                         }
00376 
00377                         m_infoList[i].m_status = CMT_DATA_ITEM_NOT_AVAILABLE;
00378                         if (m_formatList[i].m_outputMode & CMT_OUTPUTMODE_STATUS)
00379                         {
00380                                 m_infoList[i].m_status = totalOffset;
00381                                 m_infoList[i].m_size += 1;
00382                                 totalOffset += 1;
00383                         }
00384 
00385                         m_infoList[i].m_sc = CMT_DATA_ITEM_NOT_AVAILABLE;
00386                         if (m_xm)
00387                                 m_infoList[i].m_sc = 0;
00388                         if (m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_TIMESTAMP_SAMPLECNT)
00389                         {
00390                                 if (!m_xm)
00391                                         m_infoList[i].m_sc = totalOffset;
00392                                 m_infoList[i].m_size += 2;
00393                                 totalOffset += 2;
00394                         }
00395 
00396                         if (m_formatList[i].m_outputSettings & CMT_OUTPUTSETTINGS_TIMESTAMP_SAMPLEUTC)
00397                         {
00398                                 m_infoList[i].m_utcTime = totalOffset;
00399                                 m_infoList[i].m_utcNano = totalOffset;
00400                                 m_infoList[i].m_utcYear = totalOffset + 4;
00401                                 m_infoList[i].m_utcMonth = totalOffset + 6;
00402                                 m_infoList[i].m_utcDay = totalOffset + 7;
00403                                 m_infoList[i].m_utcHour = totalOffset + 8;
00404                                 m_infoList[i].m_utcMinute = totalOffset + 9;
00405                                 m_infoList[i].m_utcSecond = totalOffset + 10;
00406                                 m_infoList[i].m_utcValid = totalOffset + 11;
00407                                 m_infoList[i].m_size += 12;
00408                                 totalOffset += 12;
00409                         }
00410                         else {
00411                                 m_infoList[i].m_utcTime = CMT_DATA_ITEM_NOT_AVAILABLE;
00412                                 m_infoList[i].m_utcNano = CMT_DATA_ITEM_NOT_AVAILABLE;
00413                                 m_infoList[i].m_utcYear = CMT_DATA_ITEM_NOT_AVAILABLE;
00414                                 m_infoList[i].m_utcMonth = CMT_DATA_ITEM_NOT_AVAILABLE;
00415                                 m_infoList[i].m_utcDay = CMT_DATA_ITEM_NOT_AVAILABLE;
00416                                 m_infoList[i].m_utcHour = CMT_DATA_ITEM_NOT_AVAILABLE;
00417                                 m_infoList[i].m_utcMinute = CMT_DATA_ITEM_NOT_AVAILABLE;
00418                                 m_infoList[i].m_utcSecond = CMT_DATA_ITEM_NOT_AVAILABLE;
00419                                 m_infoList[i].m_utcValid = CMT_DATA_ITEM_NOT_AVAILABLE;
00420                         }
00421 
00422                         // post-processing data is never available at this point
00423                         m_infoList[i].m_acc_g = CMT_DATA_ITEM_NOT_AVAILABLE;
00424                         m_infoList[i].m_doubleBoundary = totalOffset;
00425                 }
00426         }
00427 
00428         if (index < m_itemCount)
00429                 return m_infoList[index].m_size;
00430         return 0;
00431 }
00432 
00433 //////////////////////////////////////////////////////////////////////////////////////////
00434 // Return the Raw Accelerometer component of a data item.
00435 CmtShortVector Packet::getRawAcc(const uint16_t index) const
00436 {
00437         CmtShortVector buffer;
00438         if (containsRawAcc(index))
00439                 for (uint16_t i=0;i<3;++i)
00440                         buffer.m_data[i] = m_msg.getDataShort(m_infoList[index].m_rawAcc + (2*i));
00441         
00442         return buffer;
00443 }
00444 bool Packet::containsRawAcc(const uint16_t index) const
00445 {
00446         if (getDataSize(index) == 0)
00447                 return false;
00448         if (m_infoList[index].m_rawAcc == CMT_DATA_ITEM_NOT_AVAILABLE)
00449                 return false;
00450         return true;
00451 }
00452 bool Packet::updateRawAcc(const CmtShortVector& vec, const uint16_t index)
00453 {
00454         if (getDataSize(index) == 0)
00455                 return false;
00456         if (m_infoList[index].m_rawAcc == CMT_DATA_ITEM_NOT_AVAILABLE)
00457         {
00458                 // add
00459                 m_infoList[index].m_rawAcc = m_msg.getDataSize();
00460                 m_msg.resizeData(m_msg.getDataSize() + 3*2);
00461                 m_infoList[index].m_size += 3*2;
00462         }
00463         // update
00464         for (uint16_t i=0;i<3;++i)
00465                 m_msg.setDataShort(vec.m_data[i], m_infoList[index].m_rawAcc + (2*i));
00466         return true;
00467 }
00468 
00469 //////////////////////////////////////////////////////////////////////////////////////////
00470 // Return the Raw Gyroscope component of a data item.
00471 CmtShortVector Packet::getRawGyr(const uint16_t index) const
00472 {
00473         CmtShortVector buffer;
00474         if (containsRawGyr(index))
00475                 for (uint16_t i=0;i<3;++i)
00476                         buffer.m_data[i] = m_msg.getDataShort(m_infoList[index].m_rawGyr + (2*i));
00477         
00478         return buffer;
00479 }
00480 bool Packet::containsRawGyr(const uint16_t index) const
00481 {
00482         if (getDataSize(index) == 0)
00483                 return false;
00484         if (m_infoList[index].m_rawGyr == CMT_DATA_ITEM_NOT_AVAILABLE)
00485                 return false;
00486         return true;
00487 }
00488 bool Packet::updateRawGyr(const CmtShortVector& vec, const uint16_t index)
00489 {
00490         if (getDataSize(index) == 0)
00491                 return false;
00492         if (m_infoList[index].m_rawGyr == CMT_DATA_ITEM_NOT_AVAILABLE)
00493         {
00494                 // add
00495                 m_infoList[index].m_rawGyr = m_msg.getDataSize();
00496                 m_msg.resizeData(m_msg.getDataSize() + 3*2);
00497                 m_infoList[index].m_size += 3*2;
00498         }
00499         // update
00500         for (uint16_t i=0;i<3;++i)
00501                 m_msg.setDataShort(vec.m_data[i], m_infoList[index].m_rawGyr + (2*i));
00502         return true;
00503 }
00504 
00505 //////////////////////////////////////////////////////////////////////////////////////////
00506 // Return the Raw Magnetometer component of a data item.
00507 CmtShortVector Packet::getRawMag(const uint16_t index) const
00508 {
00509         CmtShortVector buffer;
00510         if (containsRawMag(index))
00511                 for (uint16_t i=0;i<3;++i)
00512                         buffer.m_data[i] = m_msg.getDataShort(m_infoList[index].m_rawMag + (2*i));
00513         
00514         return buffer;
00515 }
00516 bool Packet::containsRawMag(const uint16_t index) const
00517 {
00518         if (getDataSize(index) == 0)
00519                 return false;
00520         if (m_infoList[index].m_rawMag == CMT_DATA_ITEM_NOT_AVAILABLE)
00521                 return false;
00522         return true;
00523 }
00524 bool Packet::updateRawMag(const CmtShortVector& vec, const uint16_t index)
00525 {
00526         if (getDataSize(index) == 0)
00527                 return false;
00528         if (m_infoList[index].m_rawMag == CMT_DATA_ITEM_NOT_AVAILABLE)
00529         {
00530                 // add
00531                 m_infoList[index].m_rawMag = m_msg.getDataSize();
00532                 m_msg.resizeData(m_msg.getDataSize() + 3*2);
00533                 m_infoList[index].m_size += 3*2;
00534         }
00535         // update
00536         for (uint16_t i=0;i<3;++i)
00537                 m_msg.setDataShort(vec.m_data[i], m_infoList[index].m_rawMag + (2*i));
00538         return true;
00539 }
00540 
00541 //////////////////////////////////////////////////////////////////////////////////////////
00542 // Return the Raw Temperature component of a data item.
00543 uint16_t Packet::getRawTemp(const uint16_t index) const
00544 {
00545         if (!containsRawTemp(index))
00546                 return 0;
00547         
00548         return m_msg.getDataShort(m_infoList[index].m_rawTemp);
00549 }
00550 bool Packet::containsRawTemp(const uint16_t index) const
00551 {
00552         if (getDataSize(index) == 0)
00553                 return false;
00554         if (m_infoList[index].m_rawTemp == CMT_DATA_ITEM_NOT_AVAILABLE)
00555                 return false;
00556         return true;
00557 }
00558 bool Packet::updateRawTemp(const uint16_t temp, const uint16_t index)
00559 {
00560         if (getDataSize(index) == 0)
00561                 return false;
00562         if (m_infoList[index].m_rawTemp == CMT_DATA_ITEM_NOT_AVAILABLE)
00563         {
00564                 // add
00565                 m_infoList[index].m_rawTemp = m_msg.getDataSize();
00566                 m_msg.resizeData(m_msg.getDataSize() + 2);
00567                 m_infoList[index].m_size += 2;
00568         }
00569         // update
00570         m_msg.setDataShort(temp, m_infoList[index].m_rawTemp);
00571         return true;
00572 }
00573 
00574 //////////////////////////////////////////////////////////////////////////////////////////
00575 // Return the Raw Data component of a data item.
00576 CmtRawData Packet::getRawData(const uint16_t index) const
00577 {
00578         CmtRawData buffer;
00579         if (containsRawData(index))
00580         {
00581                 const uint8_t* tmp = m_msg.getDataBuffer(m_infoList[index].m_rawData);
00582                 const uint16_t* sh = (const uint16_t*) tmp;
00583                 uint16_t* bare = (uint16_t*) &buffer;
00584 
00585                 for (uint16_t i=0;i<10;++i, ++sh, ++bare)
00586                         *bare = swapEndian16(*sh);// m_msg.getDataShort(m_infoList[index].m_rawData + (2*i));
00587         }
00588         return buffer;
00589 }
00590 bool Packet::containsRawData(const uint16_t index) const
00591 {
00592         if (getDataSize(index) == 0)
00593                 return false;
00594         if (m_infoList[index].m_rawData == CMT_DATA_ITEM_NOT_AVAILABLE)
00595                 return false;
00596         return true;
00597 }
00598 bool Packet::updateRawData(const CmtRawData& data, const uint16_t index)
00599 {
00600         if (getDataSize(index) == 0)
00601                 return false;
00602         if (m_infoList[index].m_rawData == CMT_DATA_ITEM_NOT_AVAILABLE)
00603         {
00604                 // add
00605                 m_infoList[index].m_rawData = m_msg.getDataSize();
00606                 m_msg.resizeData(m_msg.getDataSize() + 3* 3*2 + 2);
00607                 m_infoList[index].m_rawAcc = m_infoList[index].m_rawData;
00608                 m_infoList[index].m_rawGyr = m_infoList[index].m_rawData + 3*2;
00609                 m_infoList[index].m_rawMag = m_infoList[index].m_rawData + 6*2;
00610                 m_infoList[index].m_rawTemp= m_infoList[index].m_rawData + 9*2;
00611                 m_infoList[index].m_size += 3* 3*2 + 2;
00612         }
00613         // update
00614         int16_t* bare = (int16_t*) &data;
00615         for (uint16_t i=0;i<10;++i)
00616                 m_msg.setDataShort(bare[i], m_infoList[index].m_rawData + (2*i));
00617         return true;
00618 }
00619 
00620 //////////////////////////////////////////////////////////////////////////////////////////
00621 // Return the Gps PVT Data component of a data item.
00622 CmtGpsPvtData Packet::getGpsPvtData(const uint16_t index) const
00623 {
00624         CmtGpsPvtData buffer;
00625         if (containsGpsPvtData(index))
00626         {
00627                 //const uint8_t* tmp = m_msg.getDataBuffer(m_infoList[index].m_gpsPvtData);
00628                 //const uint16_t* sh = (const uint16_t*) tmp;
00629                 //uint16_t* bare = (uint16_t*) &buffer;
00630 
00631                 // pressure data
00632                 buffer.m_pressure = m_msg.getDataShort(m_infoList[index].m_gpsPvtPressure);
00633                 // pressAge
00634                 buffer.m_pressureAge = m_msg.getDataByte(m_infoList[index].m_gpsPvtPressureAge);
00635 
00636                 // lon,lat,height,hacc,vacc,veln,vele,veld
00637                 //tmp = m_msg.getDataBuffer(m_infoList[index].m_gpsPvtGpsData);
00638                 //const uint32_t* ln = (const uint32_t*) tmp;
00639                 uint32_t *bareln = (uint32_t*) &buffer.m_itow;
00640                 for (uint16_t i=0; i < 10; ++i)
00641                         bareln[i] = m_msg.getDataLong(m_infoList[index].m_gpsPvtGpsData + (4*i));
00642 
00643                 // gpsAge
00644                 buffer.m_gpsAge = m_msg.getDataByte(m_infoList[index].m_gpsPvtGpsAge);
00645         }
00646         return buffer;
00647 }
00648 bool Packet::containsGpsPvtData(const uint16_t index) const
00649 {
00650         if (getDataSize(index) == 0)
00651                 return false;
00652         if (m_infoList[index].m_gpsPvtData == CMT_DATA_ITEM_NOT_AVAILABLE)
00653                 return false;
00654         return true;
00655 }
00656 bool Packet::updateGpsPvtData(const CmtGpsPvtData& data, const uint16_t index)
00657 {
00658         if (getDataSize(index) == 0)
00659                 return false;
00660         if (m_infoList[index].m_gpsPvtData == CMT_DATA_ITEM_NOT_AVAILABLE)
00661         {
00662                 // add
00663                 m_infoList[index].m_gpsPvtData = m_msg.getDataSize();
00664                 m_msg.resizeData(m_msg.getDataSize() + (2+1) + (40 + 1));
00665                 m_infoList[index].m_gpsPvtPressure = m_infoList[index].m_gpsPvtData;
00666                 m_infoList[index].m_gpsPvtPressureAge = m_infoList[index].m_gpsPvtData + 2;
00667 
00668                 m_infoList[index].m_gpsPvtGpsData = m_infoList[index].m_gpsPvtData + 3;
00669                 m_infoList[index].m_gpsPvtItow = m_infoList[index].m_gpsPvtData + 3;
00670                 m_infoList[index].m_gpsPvtLatitude = m_infoList[index].m_gpsPvtData + 3 + 4;
00671                 m_infoList[index].m_gpsPvtLongitude = m_infoList[index].m_gpsPvtData + 3 + 8;
00672                 m_infoList[index].m_gpsPvtHeight = m_infoList[index].m_gpsPvtData + 3 + 12;
00673                 m_infoList[index].m_gpsPvtVeln = m_infoList[index].m_gpsPvtData + 3 + 16;
00674                 m_infoList[index].m_gpsPvtVele = m_infoList[index].m_gpsPvtData + 3 + 20;
00675                 m_infoList[index].m_gpsPvtVeld = m_infoList[index].m_gpsPvtData + 3 + 24;
00676                 m_infoList[index].m_gpsPvtHacc = m_infoList[index].m_gpsPvtData + 3 + 28;
00677                 m_infoList[index].m_gpsPvtVacc = m_infoList[index].m_gpsPvtData + 3 + 32;
00678                 m_infoList[index].m_gpsPvtSacc = m_infoList[index].m_gpsPvtData + 3 + 36;
00679                 m_infoList[index].m_gpsPvtGpsAge = m_infoList[index].m_gpsPvtData + 3 + 40;
00680                 
00681                 m_infoList[index].m_size += (2+1) + (40 + 1);
00682         }
00683         // update
00684         m_msg.setDataShort(data.m_pressure, m_infoList[index].m_gpsPvtPressure);
00685         m_msg.setDataByte(data.m_pressureAge, m_infoList[index].m_gpsPvtPressureAge);
00686 
00687         // lon,lat,height,hacc,vacc,veln,vele,veld
00688         int32_t* bareln = (int32_t*)&data.m_itow;
00689         for (uint16_t i=0; i<10;++i)
00690                 m_msg.setDataLong(bareln[i],m_infoList[index].m_gpsPvtGpsData + (4*i));
00691 
00692         // gpsAge
00693         m_msg.setDataByte(data.m_gpsAge,  m_infoList[index].m_gpsPvtGpsAge);
00694         return true;
00695 }
00696 
00697 //////////////////////////////////////////////////////////////////////////////////////////
00698 // Return the Raw Pressure Data component of a data item.
00699 CmtRawPressureData Packet::getRawPressureData(const uint16_t index) const
00700 {
00701         CmtRawPressureData buffer;
00702         if (containsRawPressureData(index))
00703         {
00704                 // pressure data
00705                 buffer.m_pressure = m_msg.getDataShort(m_infoList[index].m_gpsPvtPressure);
00706                 // pressAge
00707                 buffer.m_pressureAge = m_msg.getDataByte(m_infoList[index].m_gpsPvtPressureAge);
00708         }
00709         return buffer;
00710 }
00711 bool Packet::containsRawPressureData(const uint16_t index) const
00712 {
00713         if (getDataSize(index) == 0)
00714                 return false;
00715         if (m_infoList[index].m_gpsPvtPressure == CMT_DATA_ITEM_NOT_AVAILABLE)
00716                 return false;
00717         return true;
00718 }
00719 bool Packet::updateRawPressureData(const CmtRawPressureData& data, const uint16_t index)
00720 {
00721         if (getDataSize(index) == 0)
00722                 return false;
00723         if (m_infoList[index].m_gpsPvtPressure == CMT_DATA_ITEM_NOT_AVAILABLE)
00724         {
00725                 // add
00726                 m_infoList[index].m_gpsPvtData = m_msg.getDataSize();
00727                 m_msg.resizeData(m_msg.getDataSize() + (2+1));
00728                 m_infoList[index].m_gpsPvtPressure = m_infoList[index].m_gpsPvtData;
00729                 m_infoList[index].m_gpsPvtPressureAge = m_infoList[index].m_gpsPvtData + 2;
00730 
00731                 m_infoList[index].m_size += (2+1);
00732         }
00733         // update
00734         m_msg.setDataShort(data.m_pressure, m_infoList[index].m_gpsPvtPressure);
00735         m_msg.setDataByte(data.m_pressureAge, m_infoList[index].m_gpsPvtPressureAge);
00736 
00737         return true;
00738 }
00739 
00740 //////////////////////////////////////////////////////////////////////////////////////////
00741 // Return the Temperature component of a data item.
00742 double Packet::getTemp(const uint16_t index) const
00743 {
00744         if (containsTemp(index))
00745                 return m_msg.getDataFPValue(CHECKIFDOUBLE(m_temp), m_infoList[index].m_temp);
00746 
00747         return 0.0;
00748 }
00749 bool Packet::containsTemp(const uint16_t index) const
00750 {
00751         if (getDataSize(index) == 0)
00752                 return false;
00753         if (m_infoList[index].m_temp == CMT_DATA_ITEM_NOT_AVAILABLE)
00754                 return false;
00755         return true;
00756 }
00757 bool Packet::updateTemp(const double& temp, const uint16_t index)
00758 {
00759         if (getDataSize(index) == 0)
00760                 return false;
00761 
00762         uint16_t ds = getFPValueSize(index);
00763 
00764         if (m_infoList[index].m_temp == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_temp))
00765         {
00766                 // add
00767                 ds = 8;
00768                 m_msg.m_autoUpdateChecksum = false;
00769 
00770                 m_infoList[index].m_temp = m_msg.getDataSize();
00771                 m_msg.resizeData(m_msg.getDataSize() + ds);
00772                 m_infoList[index].m_size += ds;
00773         }
00774         // update
00775         m_msg.setDataFPValue(CHECKIFDOUBLE(m_temp), temp, m_infoList[index].m_temp);
00776         return true;
00777 }
00778 
00779 //////////////////////////////////////////////////////////////////////////////////////////
00780 // Return the Calibrated Accelerometer component of a data item.
00781 CmtVector Packet::getCalAcc(const uint16_t index) const
00782 {
00783         CmtVector buffer;
00784         if (containsCalAcc(index))
00785                 m_msg.getDataFPValue(&buffer.m_data[0], CHECKIFDOUBLE(m_calAcc), m_infoList[index].m_calAcc, 3);
00786         else
00787                 memset(&buffer, 0, sizeof(buffer));
00788         return buffer;
00789 }
00790 bool Packet::containsCalAcc(const uint16_t index) const
00791 {
00792         if (getDataSize(index) == 0)
00793                 return false;
00794         if (m_infoList[index].m_calAcc == CMT_DATA_ITEM_NOT_AVAILABLE)
00795                 return false;
00796         return true;
00797 }
00798 bool Packet::updateCalAcc(const CmtVector& vec, const uint16_t index)
00799 {
00800         const uint16_t numValues = 3;
00801         if (getDataSize(index) == 0)
00802                 return false;
00803 
00804         uint16_t ds = getFPValueSize(index);
00805 
00806         if (m_infoList[index].m_calAcc == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_calAcc))
00807         {
00808                 // add
00809                 ds = 8;
00810                 m_msg.m_autoUpdateChecksum = false;
00811 
00812                 m_infoList[index].m_calAcc = m_msg.getDataSize();
00813                 m_msg.resizeData(m_msg.getDataSize() + numValues*ds);
00814                 m_infoList[index].m_size += numValues*ds;
00815         }
00816         // update
00817         m_msg.setDataFPValue(CHECKIFDOUBLE(m_calAcc), &vec.m_data[0], m_infoList[index].m_calAcc, numValues);
00818         return true;
00819 }
00820 
00821 //////////////////////////////////////////////////////////////////////////////////////////
00822 // Return the Calibrated Gyroscope component of a data item.
00823 CmtVector Packet::getCalGyr(const uint16_t index) const
00824 {
00825         CmtVector buffer;
00826         if (containsCalGyr(index))
00827                 m_msg.getDataFPValue(&buffer.m_data[0], CHECKIFDOUBLE(m_calGyr), m_infoList[index].m_calGyr, 3);
00828         else
00829                 memset(&buffer, 0, sizeof(buffer));
00830         return buffer;
00831 }
00832 bool Packet::containsCalGyr(const uint16_t index) const
00833 {
00834         if (getDataSize(index) == 0)
00835                 return false;
00836         if (m_infoList[index].m_calGyr == CMT_DATA_ITEM_NOT_AVAILABLE)
00837                 return false;
00838         return true;
00839 }
00840 bool Packet::updateCalGyr(const CmtVector& vec, const uint16_t index)
00841 {
00842         const uint16_t numValues = 3;
00843         if (getDataSize(index) == 0)
00844                 return false;
00845 
00846         uint16_t ds = getFPValueSize(index);
00847 
00848         if (m_infoList[index].m_calGyr == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_calGyr))
00849         {
00850                 // add
00851                 ds = 8;
00852                 m_msg.m_autoUpdateChecksum = false;
00853 
00854                 m_infoList[index].m_calGyr = m_msg.getDataSize();
00855                 m_msg.resizeData(m_msg.getDataSize() + numValues*ds);
00856                 m_infoList[index].m_size += numValues*ds;
00857         }
00858         // update
00859         m_msg.setDataFPValue(CHECKIFDOUBLE(m_calGyr), &vec.m_data[0], m_infoList[index].m_calGyr, numValues);
00860         return true;
00861 }
00862 
00863 //////////////////////////////////////////////////////////////////////////////////////////
00864 // Return the Calibrated Magnetometer component of a data item.
00865 CmtVector Packet::getCalMag(const uint16_t index) const
00866 {
00867         CmtVector buffer;
00868         if (containsCalMag(index))
00869                 m_msg.getDataFPValue(&buffer.m_data[0], CHECKIFDOUBLE(m_calMag), m_infoList[index].m_calMag, 3);
00870         else
00871                 memset(&buffer, 0, sizeof(buffer));
00872         return buffer;
00873 }
00874 bool Packet::containsCalMag(const uint16_t index) const
00875 {
00876         if (getDataSize(index) == 0)
00877                 return false;
00878         if (m_infoList[index].m_calMag == CMT_DATA_ITEM_NOT_AVAILABLE)
00879                 return false;
00880         return true;
00881 }
00882 bool Packet::updateCalMag(const CmtVector& vec, const uint16_t index)
00883 {
00884         const uint16_t numValues = 3;
00885         if (getDataSize(index) == 0)
00886                 return false;
00887 
00888         uint16_t ds = getFPValueSize(index);
00889 
00890         if (m_infoList[index].m_calMag == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_calMag))
00891         {
00892                 // add
00893                 ds = 8;
00894                 m_msg.m_autoUpdateChecksum = false;
00895 
00896                 m_infoList[index].m_calMag = m_msg.getDataSize();
00897                 m_msg.resizeData(m_msg.getDataSize() + numValues*ds);
00898                 m_infoList[index].m_size += numValues*ds;
00899         }
00900         // update
00901         m_msg.setDataFPValue(CHECKIFDOUBLE(m_calMag), &vec.m_data[0], m_infoList[index].m_calMag, numValues);
00902         return true;
00903 }
00904 
00905 //////////////////////////////////////////////////////////////////////////////////////////
00906 // Return the Calibrated Accelerometer component of a data item.
00907 CmtCalData Packet::getCalData(const uint16_t index) const
00908 {
00909         CmtCalData buffer;
00910         double* bare = (double*) &buffer;
00911         if (containsCalData(index))
00912         {
00913                 if (m_infoList[index].m_calAcc == CMT_DATA_ITEM_NOT_AVAILABLE)
00914                         memset(bare, 0, 3*sizeof(double));
00915                 else
00916                         m_msg.getDataFPValue(bare, CHECKIFDOUBLE(m_calAcc) , m_infoList[index].m_calAcc, 3);
00917 
00918                 bare += 3;
00919                 if (m_infoList[index].m_calGyr == CMT_DATA_ITEM_NOT_AVAILABLE)
00920                         memset(bare, 0, 3*sizeof(double));
00921                 else
00922                         m_msg.getDataFPValue(bare, CHECKIFDOUBLE(m_calGyr), m_infoList[index].m_calGyr, 3);
00923 
00924                 bare += 3;
00925                 if (m_infoList[index].m_calMag == CMT_DATA_ITEM_NOT_AVAILABLE)
00926                         memset(bare, 0, 3*sizeof(double));
00927                 else
00928                         m_msg.getDataFPValue(bare, CHECKIFDOUBLE(m_calMag), m_infoList[index].m_calMag, 3);
00929         }
00930         else
00931                 memset(&buffer, 0, sizeof(buffer));
00932         return buffer;
00933 }
00934 bool Packet::containsCalData(const uint16_t index) const
00935 {
00936         if (getDataSize(index) == 0)
00937                 return false;
00938         if (m_infoList[index].m_calData == CMT_DATA_ITEM_NOT_AVAILABLE)
00939                 return false;
00940         return true;
00941 }
00942 bool Packet::updateCalData(const CmtCalData& data, const uint16_t index)
00943 {
00944         const uint16_t numValues = 9;
00945         if (getDataSize(index) == 0)
00946                 return false;
00947 
00948         uint16_t ds = getFPValueSize(index);
00949 
00950         if (m_infoList[index].m_calData == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_calData))
00951         {
00952                 // add
00953                 ds = 8;        // added values are always in double precision
00954                 m_msg.m_autoUpdateChecksum = false;
00955 
00956                 m_infoList[index].m_calData = m_msg.getDataSize();
00957                 m_msg.resizeData(m_msg.getDataSize() + numValues*ds);
00958                 m_infoList[index].m_calAcc = m_infoList[index].m_calData;
00959                 m_infoList[index].m_calGyr = m_infoList[index].m_calData + 3*ds;
00960                 m_infoList[index].m_calMag = m_infoList[index].m_calData + 6*ds;
00961                 m_infoList[index].m_size += numValues*ds;
00962         }
00963         // update
00964         double* bare = (double*) &data;
00965         if (m_infoList[index].m_calAcc != CMT_DATA_ITEM_NOT_AVAILABLE)
00966                 m_msg.setDataFPValue(CHECKIFDOUBLE(m_calAcc), bare, m_infoList[index].m_calAcc, 3);
00967         bare += 3;
00968         if (m_infoList[index].m_calGyr != CMT_DATA_ITEM_NOT_AVAILABLE)
00969                 m_msg.setDataFPValue(CHECKIFDOUBLE(m_calGyr), bare, m_infoList[index].m_calGyr, 3);
00970         bare += 3;
00971         if (m_infoList[index].m_calMag != CMT_DATA_ITEM_NOT_AVAILABLE)
00972                 m_msg.setDataFPValue(CHECKIFDOUBLE(m_calMag), bare, m_infoList[index].m_calMag, 3);
00973 
00974         return true;
00975 }
00976 
00977 //////////////////////////////////////////////////////////////////////////////////////////
00978 // Return the Orientation component of a data item as a Quaternion.
00979 CmtQuat Packet::getOriQuat(const uint16_t index) const
00980 {
00981         CmtQuat buffer;
00982         if (containsOriQuat(index))
00983                 m_msg.getDataFPValue(&buffer.m_data[0], CHECKIFDOUBLE(m_oriQuat), m_infoList[index].m_oriQuat, 4);
00984         else
00985                 memset(&buffer, 0, sizeof(buffer));
00986         return buffer;
00987 }
00988 
00989 bool Packet::containsOriQuat(const uint16_t index) const
00990 {
00991         if (getDataSize(index) == 0)
00992                 return false;
00993         if (m_infoList[index].m_oriQuat == CMT_DATA_ITEM_NOT_AVAILABLE)
00994                 return false;
00995         return true;
00996 }
00997 bool Packet::updateOriQuat(const CmtQuat& data, const uint16_t index)
00998 {
00999         const uint16_t numValues = 4;
01000         if (getDataSize(index) == 0)
01001                 return false;
01002 
01003         uint16_t ds = getFPValueSize(index);
01004 
01005         if (m_infoList[index].m_oriQuat == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_oriQuat))
01006         {
01007                 // add
01008                 ds = 8;        // added values are always in double precision
01009                 m_msg.m_autoUpdateChecksum = false;
01010 
01011                 m_infoList[index].m_oriQuat = m_msg.getDataSize();
01012                 m_msg.resizeData(m_msg.getDataSize() + numValues*ds);
01013                 m_infoList[index].m_size += numValues*ds;
01014 
01015                 double* bare = (double*) &data;
01016                 m_msg.setDataFPValue((m_formatList[index].m_outputSettings & CMT_OUTPUTSETTINGS_DATAFORMAT_MASK)|CMT_OUTPUTSETTINGS_DATAFORMAT_DOUBLE,
01017                                                         bare, m_infoList[index].m_oriQuat, numValues);
01018                 return true;
01019         }
01020         // update
01021         m_msg.setDataFPValue(CHECKIFDOUBLE(m_oriQuat), &data.m_data[0], m_infoList[index].m_oriQuat, numValues);
01022         return true;
01023 }
01024 
01025 //////////////////////////////////////////////////////////////////////////////////////////
01026 // Return the Orientation component of a data item as CmtEuler angles.
01027 CmtEuler Packet::getOriEuler(const uint16_t index) const
01028 {
01029         CmtEuler buffer;
01030         if (containsOriEuler(index))
01031                 m_msg.getDataFPValue(&buffer.m_roll, CHECKIFDOUBLE(m_oriEul), m_infoList[index].m_oriEul, 3);
01032         else
01033                 memset(&buffer, 0, sizeof(buffer));
01034         return buffer;
01035 }
01036 bool Packet::containsOriEuler(const uint16_t index) const
01037 {
01038         if (getDataSize(index) == 0)
01039                 return false;
01040         if (m_infoList[index].m_oriEul == CMT_DATA_ITEM_NOT_AVAILABLE)
01041                 return false;
01042         return true;
01043 }
01044 bool Packet::updateOriEuler(const CmtEuler& data, const uint16_t index)
01045 {
01046         const uint16_t numValues = 3;
01047         if (getDataSize(index) == 0)
01048                 return false;
01049 
01050         uint16_t ds = getFPValueSize(index);
01051 
01052         if (m_infoList[index].m_oriEul == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_oriEul))
01053         {
01054                 // add
01055                 ds = 8;        // added values are always in double precision
01056                 m_msg.m_autoUpdateChecksum = false;
01057 
01058                 m_infoList[index].m_oriEul = m_msg.getDataSize();
01059                 m_msg.resizeData(m_msg.getDataSize() + numValues*ds);
01060                 m_infoList[index].m_size += numValues*ds;
01061         }
01062         // update
01063         m_msg.setDataFPValue(CHECKIFDOUBLE(m_oriEul), &data.m_roll, m_infoList[index].m_oriEul, numValues);
01064         return true;
01065 }
01066 
01067 //////////////////////////////////////////////////////////////////////////////////////////
01068 // Return the Orientation component of a data item as an Orientation Matrix.
01069 CmtMatrix Packet::getOriMatrix(const uint16_t index) const
01070 {
01071         CmtMatrix buffer;
01072         uint16_t k = 0;
01073         if (containsOriMatrix(index))
01074         {
01075                 uint16_t ds = getFPValueSize(index);
01076                 for (int32_t i=0;i<3;++i)
01077                         for (int32_t j=0;j<3;++j, k+=ds)
01078                                 buffer.m_data[i][j] = m_msg.getDataFPValue(CHECKIFDOUBLE(m_oriMat), m_infoList[index].m_oriMat+k);
01079         }        
01080         else
01081                 memset(&buffer, 0, sizeof(buffer));
01082 
01083         return buffer;
01084 }
01085 bool Packet::containsOriMatrix(const uint16_t index) const
01086 {
01087         if (getDataSize(index) == 0)
01088                 return false;
01089         if (m_infoList[index].m_oriMat == CMT_DATA_ITEM_NOT_AVAILABLE)
01090                 return false;
01091         return true;
01092 }
01093 bool Packet::updateOriMatrix(const CmtMatrix& data, const uint16_t index)
01094 {
01095         const uint16_t numValues = 9;
01096         if (getDataSize(index) == 0)
01097                 return false;
01098 
01099         uint16_t ds = getFPValueSize(index);
01100 
01101         if (m_infoList[index].m_oriMat == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_oriMat))
01102         {
01103                 // add
01104                 ds = 8;        // added values are always in double precision
01105                 m_msg.m_autoUpdateChecksum = false;
01106 
01107                 m_infoList[index].m_oriMat = m_msg.getDataSize();
01108                 m_msg.resizeData(m_msg.getDataSize() + numValues*ds);
01109                 m_infoList[index].m_size += numValues*ds;
01110         }
01111         // update
01112         uint16_t k = 0;
01113         for (int32_t i=0;i<3;++i)
01114                 for (int32_t j=0;j<3;++j, k+=ds)
01115                         m_msg.setDataFPValue(CHECKIFDOUBLE(m_oriMat), data.m_data[i][j], m_infoList[index].m_oriMat+k);
01116         return true;
01117 }
01118 
01119 bool Packet::containsOri(const uint16_t index) const
01120 {
01121         if (getDataSize(index) == 0)
01122                 return false;
01123         if (m_infoList[index].m_oriEul == CMT_DATA_ITEM_NOT_AVAILABLE &&
01124                 m_infoList[index].m_oriMat == CMT_DATA_ITEM_NOT_AVAILABLE &&
01125                 m_infoList[index].m_oriQuat == CMT_DATA_ITEM_NOT_AVAILABLE)
01126                 return false;
01127         return true;
01128 }
01129 
01130 //////////////////////////////////////////////////////////////////////////////////////////
01131 // Return the AnalogIn 1 component of a data item.
01132 CmtAnalogInData Packet::getAnalogIn1(const uint16_t index) const
01133 {
01134         CmtAnalogInData buffer;
01135         if (containsAnalogIn1(index))
01136                 buffer.m_data = m_msg.getDataShort(m_infoList[index].m_analogIn1);
01137 
01138         return buffer;
01139 }
01140 bool Packet::containsAnalogIn1(const uint16_t index) const
01141 {
01142         if (getDataSize(index) == 0)
01143                 return false;
01144         if (m_infoList[index].m_analogIn1 == CMT_DATA_ITEM_NOT_AVAILABLE)
01145                 return false;
01146         return true;
01147 }
01148 bool Packet::updateAnalogIn1(const CmtAnalogInData& data, const uint16_t index)
01149 {
01150         if (getDataSize(index) == 0)
01151                 return false;
01152         if (m_infoList[index].m_analogIn1 == CMT_DATA_ITEM_NOT_AVAILABLE)
01153         {
01154                 // add
01155                 m_infoList[index].m_analogIn1 = m_msg.getDataSize();
01156                 m_msg.resizeData(m_msg.getDataSize() + 2);
01157                 m_infoList[index].m_size += 2;
01158         }
01159         // update
01160         m_msg.setDataShort(data.m_data, m_infoList[index].m_analogIn1);
01161         return true;
01162 }
01163 
01164 //////////////////////////////////////////////////////////////////////////////////////////
01165 // Return the AnalogIn 2 component of a data item.
01166 CmtAnalogInData Packet::getAnalogIn2(const uint16_t index) const
01167 {
01168         CmtAnalogInData buffer;
01169         if (containsAnalogIn2(index))
01170                 buffer.m_data = m_msg.getDataShort(m_infoList[index].m_analogIn2);
01171 
01172         return buffer;
01173 }
01174 bool Packet::containsAnalogIn2(const uint16_t index) const
01175 {
01176         if (getDataSize(index) == 0)
01177                 return false;
01178         if (m_infoList[index].m_analogIn2 == CMT_DATA_ITEM_NOT_AVAILABLE)
01179                 return false;
01180         return true;
01181 }
01182 bool Packet::updateAnalogIn2(const CmtAnalogInData& data, const uint16_t index)
01183 {
01184         if (getDataSize(index) == 0)
01185                 return false;
01186         if (m_infoList[index].m_analogIn2 == CMT_DATA_ITEM_NOT_AVAILABLE)
01187         {
01188                 // add
01189                 m_infoList[index].m_analogIn2 = m_msg.getDataSize();
01190                 m_msg.resizeData(m_msg.getDataSize() + 2);
01191                 m_infoList[index].m_size += 2;
01192         }
01193         // update
01194         m_msg.setDataShort(data.m_data, m_infoList[index].m_analogIn2);
01195         return true;
01196 }
01197 
01198 //////////////////////////////////////////////////////////////////////////////////////////
01199 // Return the Position LLA component of a data item.
01200 CmtVector Packet::getPositionLLA(const uint16_t index) const
01201 {
01202         CmtVector buffer;
01203         if (containsPositionLLA(index))
01204                 m_msg.getDataFPValue(&buffer.m_data[0], CHECKIFDOUBLE(m_posLLA), m_infoList[index].m_posLLA, 3);
01205         else
01206                 memset(&buffer, 0, sizeof(buffer));
01207         return buffer;
01208 }
01209 bool Packet::containsPositionLLA(const uint16_t index) const
01210 {
01211         if (getDataSize(index) == 0)
01212                 return false;
01213         if (m_infoList[index].m_posLLA == CMT_DATA_ITEM_NOT_AVAILABLE)
01214                 return false;
01215         return true;
01216 }
01217 bool Packet::updatePositionLLA(const CmtVector& data, const uint16_t index)
01218 {
01219         const uint16_t numValues = 3;
01220         if (getDataSize(index) == 0)
01221                 return false;
01222 
01223         uint16_t ds = getFPValueSize(index);
01224 
01225         if (m_infoList[index].m_posLLA == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_posLLA))
01226         {
01227                 // add
01228                 ds = 8;        // added values are always in double precision
01229                 m_msg.m_autoUpdateChecksum = false;
01230 
01231                 m_infoList[index].m_posLLA = m_msg.getDataSize();
01232                 m_msg.resizeData(m_msg.getDataSize() + numValues*ds);
01233                 m_infoList[index].m_size += numValues*ds;
01234         }
01235         // update
01236         m_msg.setDataFPValue(CHECKIFDOUBLE(m_posLLA), &data.m_data[0], m_infoList[index].m_posLLA, numValues);
01237         return true;
01238 }
01239 
01240 //////////////////////////////////////////////////////////////////////////////////////////
01241 // Return the Velocity NED component of a data item.
01242 CmtVector Packet::getVelocity(const uint16_t index) const
01243 {
01244         CmtVector buffer;
01245         if (containsVelocity(index))
01246                 m_msg.getDataFPValue(&buffer.m_data[0], CHECKIFDOUBLE(m_velNEDorNWU), m_infoList[index].m_velNEDorNWU, 3);
01247         else
01248                 memset(&buffer, 0, sizeof(buffer));
01249 
01250         return buffer;
01251 }
01252 bool Packet::containsVelocity(const uint16_t index) const
01253 {
01254         if (getDataSize(index) == 0)
01255                 return false;
01256         if (m_infoList[index].m_velNEDorNWU == CMT_DATA_ITEM_NOT_AVAILABLE)
01257                 return false;
01258         return true;
01259 }
01260 bool Packet::updateVelocity(const CmtVector& data, const uint16_t index)
01261 {
01262         const uint16_t numValues = 3;
01263         if (getDataSize(index) == 0)
01264                 return false;
01265 
01266         uint16_t ds = getFPValueSize(index);
01267 
01268         if (m_infoList[index].m_velNEDorNWU == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_posLLA))
01269         {
01270                 // add
01271                 ds = 8;        // added values are always in double precision
01272                 m_msg.m_autoUpdateChecksum = false;
01273 
01274                 m_infoList[index].m_velNEDorNWU = m_msg.getDataSize();
01275                 m_msg.resizeData(m_msg.getDataSize() + numValues*ds);
01276                 m_infoList[index].m_size += numValues*ds;
01277         }
01278         // update
01279         m_msg.setDataFPValue(CHECKIFDOUBLE(m_velNEDorNWU), &data.m_data[0], m_infoList[index].m_velNEDorNWU, numValues);
01280         return true;
01281 }
01282 
01283 //////////////////////////////////////////////////////////////////////////////////////////
01284 // Return the Status component of a data item.
01285 uint8_t Packet::getStatus(const uint16_t index) const
01286 {
01287         if (containsStatus(index))
01288                 return m_msg.getDataByte(m_infoList[index].m_status);
01289         return 0;
01290 }
01291 bool Packet::containsStatus(const uint16_t index) const
01292 {
01293         if (getDataSize(index) == 0)
01294                 return false;
01295         if (m_infoList[index].m_status == CMT_DATA_ITEM_NOT_AVAILABLE)
01296                 return false;
01297         return true;
01298 }
01299 bool Packet::updateStatus(const uint8_t data, const uint16_t index)
01300 {
01301         if (getDataSize(index) == 0)
01302                 return false;
01303 
01304         if (m_infoList[index].m_status == CMT_DATA_ITEM_NOT_AVAILABLE)
01305         {
01306                 // add
01307                 m_infoList[index].m_status = m_msg.getDataSize();
01308                 m_msg.resizeData(m_msg.getDataSize() + 1);
01309                 m_infoList[index].m_size += 1;
01310         }
01311         // update
01312         m_msg.setDataByte(data,m_infoList[index].m_status);
01313         return true;
01314 }
01315 
01316 //////////////////////////////////////////////////////////////////////////////////////////
01317 // Return the Sample Counter component of the packet.
01318 uint16_t Packet::getSampleCounter(const uint16_t index) const
01319 {
01320         if (!containsSampleCounter(index))
01321                 return 0;
01322         return m_msg.getDataShort(m_infoList[index].m_sc);
01323 }
01324 bool Packet::containsSampleCounter(const uint16_t index) const
01325 {
01326         if (getDataSize(index) == 0)
01327                 return false;
01328         if (m_infoList[index].m_sc == CMT_DATA_ITEM_NOT_AVAILABLE)
01329                 return false;
01330         return true;
01331 }
01332 bool Packet::updateSampleCounter(const uint16_t counter, const uint16_t index)
01333 {
01334         if (getDataSize(index) == 0)
01335                 return false;
01336         if (m_infoList[index].m_sc == CMT_DATA_ITEM_NOT_AVAILABLE)
01337         {
01338                 // add
01339                 m_infoList[index].m_sc = m_msg.getDataSize();
01340                 m_msg.resizeData(m_msg.getDataSize() + 2);
01341                 m_infoList[index].m_size += 2;
01342         }
01343         // update
01344         m_msg.setDataShort(counter, m_infoList[index].m_sc);
01345         return true;
01346 }
01347 
01348 //////////////////////////////////////////////////////////////////////////////////////////
01349 // Return the UTC Time component of the packet.
01350 CmtUtcTime Packet::getUtcTime(const uint16_t index) const
01351 {
01352         CmtUtcTime buffer;
01353         if (containsUtcTime(index))
01354         {
01355                 buffer.m_nano = m_msg.getDataLong(m_infoList[index].m_utcNano);
01356                 buffer.m_year = m_msg.getDataShort(m_infoList[index].m_utcYear);
01357 
01358                 // month, day, hour, minute, second and valid
01359                 uint8_t *bareByte = (uint8_t*) &buffer.m_month;
01360                 for (uint16_t i=0; i < 6; ++i)
01361                         bareByte[i] = m_msg.getDataByte(m_infoList[index].m_utcMonth + i);
01362         }
01363         return buffer;
01364 }
01365 bool Packet::containsUtcTime(const uint16_t index) const
01366 {
01367         if (getDataSize(index) == 0)
01368                 return false;
01369         if (m_infoList[index].m_utcTime == CMT_DATA_ITEM_NOT_AVAILABLE)
01370                 return false;
01371         return true;
01372 }
01373 bool Packet::updateUtcTime(const CmtUtcTime& data, const uint16_t index)
01374 {
01375         if (getDataSize(index) == 0)
01376                 return false;
01377         if (m_infoList[index].m_utcTime == CMT_DATA_ITEM_NOT_AVAILABLE)
01378         {
01379                 // add
01380                 m_infoList[index].m_utcTime = m_msg.getDataSize();
01381                 m_msg.resizeData(m_msg.getDataSize() + 12);
01382                 m_infoList[index].m_utcNano = m_infoList[index].m_utcTime;
01383                 m_infoList[index].m_utcYear = m_infoList[index].m_utcTime + 4;
01384                 m_infoList[index].m_utcMonth = m_infoList[index].m_utcTime + 6;
01385                 m_infoList[index].m_utcDay = m_infoList[index].m_utcTime + 7;
01386                 m_infoList[index].m_utcHour = m_infoList[index].m_utcTime + 8;
01387                 m_infoList[index].m_utcMinute = m_infoList[index].m_utcTime + 9;
01388                 m_infoList[index].m_utcSecond = m_infoList[index].m_utcTime + 10;
01389                 m_infoList[index].m_utcValid = m_infoList[index].m_utcTime + 11;
01390                 
01391                 m_infoList[index].m_size += 12;
01392         }
01393         // update
01394         m_msg.setDataLong(data.m_nano, m_infoList[index].m_utcNano);
01395         m_msg.setDataShort(data.m_year, m_infoList[index].m_utcYear);
01396 
01397         // month, day, hour, minute, second and valid
01398         int8_t* bareByte = (int8_t*)&data.m_month;
01399         for (uint16_t i=0; i<6;++i)
01400                 m_msg.setDataByte(bareByte[i],m_infoList[index].m_utcMonth + i);
01401 
01402         return true;
01403 }
01404 
01405 TimeStamp Packet::getRtc(const uint16_t index) const
01406 {
01407         (void)index;
01408         return m_rtc;
01409 }
01410 
01411 //////////////////////////////////////////////////////////////////////////////////////////
01412 // Return the XKF-3 Acc G component of the packet.
01413 CmtVector Packet::getAccG(const uint16_t index) const
01414 {
01415         CmtVector buffer;
01416         if (containsAccG(index))
01417                 m_msg.getDataFPValue(&buffer.m_data[0], CHECKIFDOUBLE(m_acc_g), m_infoList[index].m_acc_g, 3);
01418         else
01419                 memset(&buffer, 0, sizeof(buffer));
01420 
01421         return buffer;
01422 }
01423 bool Packet::containsAccG(const uint16_t index) const
01424 {
01425         if (getDataSize(index) == 0)
01426                 return false;
01427         if (m_infoList[index].m_acc_g == CMT_DATA_ITEM_NOT_AVAILABLE)
01428                 return false;
01429         return true;
01430 }
01431 bool Packet::updateAccG(const CmtVector& g, const uint16_t index)
01432 {
01433         const uint16_t numValues = 3;
01434         if (getDataSize(index) == 0)
01435                 return false;
01436 
01437         uint16_t ds = getFPValueSize(index);
01438 
01439         if (m_infoList[index].m_acc_g == CMT_DATA_ITEM_NOT_AVAILABLE || !ISDOUBLE(m_acc_g))
01440         {
01441                 // add
01442                 ds = 8;        // added values are always in double precision
01443                 m_msg.m_autoUpdateChecksum = false;
01444 
01445                 m_infoList[index].m_acc_g = m_msg.getDataSize();
01446                 m_msg.resizeData(m_msg.getDataSize() + numValues*ds);
01447                 m_infoList[index].m_size += numValues*ds;
01448         }
01449         // update
01450         m_msg.setDataFPValue(CHECKIFDOUBLE(m_acc_g), &g.m_data[0], m_infoList[index].m_acc_g, numValues);
01451         return true;
01452 }
01453 
01454 Packet::Packet(const Packet& pack)
01455 {
01456         PACKETLOG("Create new packet from Packet %p\n",&pack);
01457 
01458         m_itemCount = 0;
01459         m_formatList = NULL;
01460         m_infoList = NULL;
01461         *this = pack;
01462 }
01463 
01464 void Packet::operator = (const Packet& pack)
01465 {
01466         PACKETLOG("Copy packet from Packet %p\n",this);
01467 
01468         if (m_itemCount != pack.m_itemCount)
01469         {
01470                 LSTCHKDELNUL(m_formatList);
01471                 m_itemCount = pack.m_itemCount;
01472                 m_formatList = new CmtDataFormat[m_itemCount];
01473         }
01474         
01475         LSTCHKDELNUL(m_infoList);
01476         m_infoList = new PacketInfo[m_itemCount];
01477         for (uint16_t i = 0; i < m_itemCount; ++i)
01478         {
01479                 m_formatList[i] = pack.m_formatList[i];
01480                 m_infoList[i] = pack.m_infoList[i];
01481         }
01482         
01483         m_toa = pack.m_toa;
01484         m_rtc = pack.m_rtc;
01485         m_msg = pack.m_msg;
01486         m_xm = pack.m_xm;
01487 }
01488 
01489 
01490 } // end of xsens namespace
Generated on Sun May 8 08:05:57 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3