NDI_commands.h

Go to the documentation of this file.
00001 #ifndef NDI_COMMANDS_H
00002 #define NDI_COMMANDS_H
00003 
00004 #include <map>
00005 #include <deque>
00006 #include <memory>
00007 #include <iostream>
00008 #include <OpenTracker/misc/serialcomm.h>
00009 
00010 namespace ot {
00011 
00012 class SerialIO;
00013 
00014 
00021 class TransformData
00022 {
00023 public:
00024         TransformData()
00025         {
00026                 strPortHandle = "";
00027                 bIsTracked = false;
00028                 bIsDisabled = false;
00029                 bIsMissing = false;
00030                 fQ0 = 0.0f;
00031                 fQX = 0.0f;
00032                 fQY = 0.0f;
00033                 fQZ = 0.0f;
00034                 fX = 0.0f;
00035                 fY = 0.0f;
00036                 fZ = 0.0f;
00037                 fError = 0.0f;
00038                 bOutOfVolume = false;
00039                 bPartiallyOutOfVolume = false;
00040                 bDisturbanceDetected = false;
00041                 uFrameNumber = 0;
00042         }
00044         std::string strPortHandle;
00045 
00046         // ToolID given in the xml file (matching the Aurora/Polaris toolID)
00047         std::string toolID;
00048 
00050         bool bIsTracked, bIsDisabled, bIsMissing;
00051         
00053         float fQ0, fQX, fQY, fQZ;
00054 
00056         float fX, fY, fZ;
00057 
00059         float fError;
00060 
00062         bool bOutOfVolume, bPartiallyOutOfVolume, bDisturbanceDetected;
00063 
00065         unsigned long uFrameNumber;
00066 };
00067 
00068 
00069 
00080 class NDICommands
00081 {
00082 public:
00083 
00085     static const int TOOL_ADDED;
00086 
00088     static const int TOOL_REMOVED;
00089     
00091     static const int NORMAL_EXECUTION;  
00092 
00094                 static const int INTERFERENCE;
00095   
00097     NDICommands(const std::string& strDevice, long nBaudeRate, int nDataBits, char cParity, int nStopBits, bool bHardwareHandShake);
00098         
00100     ~NDICommands();
00101 
00103     void initialize();
00104 
00106     void trackNodes(std::deque<TransformData>& queTransformData, int* nStatus);
00107 
00109     int getNumberOfMagneticPorts() const;
00110     
00112     void getOccupiedPortHandles(std::deque<std::string>& occupiedPorts);
00113     
00115     void getFreeablePortHandles(std::deque<std::string>& occupiedPorts);
00116     
00118     void getEnabledPortHandles(std::deque<std::string>& enabledPorts);
00119 
00121     void initializePort(std::string strPort);
00122 
00124     void enablePort(std::string strPort, bool bIsDynamic);
00125 
00127     std::string getToolID(std::string);
00128 
00130     std::string getFirmwareVersion();
00131 
00133     void enterTrackingMode();
00134 
00136     void freeToolPort(std::string strPort);
00137   
00139     void voidToolTracking(std::string strPort);
00140 
00142     void setUseCRC(bool bEnable);
00143 
00145     void setCheckCRC(bool bEnable);
00146 
00148     void reset();
00149 
00151     void changeCommSettings(long        nBaudRate,
00152                             int         nDataBits,
00153                             char        cParity,
00154                             int         nStopBits,
00155                             bool        bHardwareHandshake);
00156 
00158     void exitTrackingMode(bool bExpedient);
00159 
00161     void checkProcessorStatus();
00162 
00164     void turnOnGPIO(std::string strPort);
00165     
00167     void turnOffGPIO(std::string strPort);
00168 
00169                 // gets a port handle for a new wireless port
00170                 std::string getWirelessPortHandle();
00171                 
00172                 // send SROM data
00173                 void sendSROMData(std::string strPort,unsigned char sROM[1024]);
00174 
00175                 // set rotation and translation multipliers
00176                 void setMultipliers(long rotation, long translation);
00177 
00178 
00180     static const std::string m_strScope;
00181 
00182     // Strings to indicate error
00183     static const std::string m_strCantInitializeNDI;
00184     static const std::string m_strUnexpectedReply;
00185     static const std::string m_strFailedToReset;
00186     static const std::string m_strFailedToChangeCommSettings;
00187     static const std::string m_strCommandFailed;
00188     static const std::string m_strTimeout;
00189     static const std::string m_strCRCError;
00190     static const std::string m_strInvalidPort;
00191     static const std::string m_strNoToolPluggedIn;
00192     static const std::string m_strInvalidBaudRate;
00193     static const std::string m_strInvalidDataBits;
00194     static const std::string m_strInvalidParity;
00195     static const std::string m_strInvalidStopBits;
00196     static const std::string m_strErrorFromNDI;
00197     static const std::string m_strBadProcessorStatus;
00198     static const std::string m_strSynchronizationError;
00199     static const std::string m_strInvalidVolume;
00200     static const std::string m_strTooMuchInterference;
00201 
00202 protected:
00203 
00205     void sendGPIO(std::string strOption);
00206 
00208     const std::string sendCommand(const std::string& strExpectedReply,
00209                               const std::string& strCode,
00210                               const std::string& strParams,
00211                               const int nMaxRetries = 5);
00212                                                 
00214     const std::string sendCommand(const std::string& strCode,
00215                               const std::string& strParams,
00216                               const int nMaxRetries = 5);
00217 
00219     const std::string mapCommParams(long nBaudRate,
00220                                 int nDataBits,
00221                                 char cParity,
00222                                 int nStopBits,
00223                                 bool bHardwareHandshake);
00224 
00226     float parseTransform(const std::string strField,
00227                          int* nOffset,
00228                          const int nLength,
00229                          const long nMultiplier) const;
00230 
00232     int handleTransformStatus(const std::string& strStatus);
00233 
00235     //std::string getSection(std::string theString, int start, int end);
00236 
00238     void getSomePortHandles(std::deque<std::string>& occupiedPorts, std::string strOption);
00239 
00241     const std::string getReply();
00242 
00244     bool headMatches(std::string sOne, std::string sTwo);
00245         
00247     bool bitTest(unsigned int nBitField, int nBit) const;
00248 
00250     void handleNDIError(const std::string strErrorCode);
00251 
00253     std::string getNextField(const std::string& str,
00254                          int* nOffset,
00255                          const std::string& strDelimiter);
00256 
00258     std::string calcCRC16(const char* ptr, int nLen);
00259 
00260     // Various commands send to/received from the Aurora/Polaris
00261     static const std::string mt_strCOMM;
00262     static const std::string mt_strDSTART;
00263     static const std::string mt_strDSTOP;
00264     static const std::string mt_strERROR;
00265     static const std::string mt_strGX;
00266     static const std::string mt_strINIT;
00267     static const std::string mt_strOKAY;
00268     static const std::string mt_strPENA;
00269     static const std::string mt_strPDIS;
00270     static const std::string mt_strPINIT;
00271     static const std::string mt_strPSTAT;
00272     static const std::string mt_strPURD;
00273     static const std::string mt_strPVCLR;
00274                 static const std::string mt_strPHRQ;
00275     static const std::string mt_strPVWR;
00276     static const std::string mt_strRESET;
00277     static const std::string mt_strSFLIST;
00278     static const std::string mt_strSSTAT;
00279     static const std::string mt_strTSTART;
00280     static const std::string mt_strTSTOP;
00281     static const std::string mt_strVER;
00282     static const std::string mt_strVSEL;
00283     static const std::string mt_strBX;
00284     static const std::string mt_strTX;
00285     static const std::string mt_strPHINF;
00286     static const std::string mt_strPHSR;
00287     static const std::string mt_strPHF;
00288     static const std::string mt_strPSOUT;
00289     
00290     // Command sending/timing parameters
00291     static const unsigned int mt_nCommSleepInMilliseconds;
00292     static const int mt_nPINITReadTimeoutInMilliSeconds;
00293     static const std::string mt_strFieldDelimiter;
00294     static const int mt_nBlockSize;
00295     static const int mt_nMarkerInfoLength;
00296 
00297     // The Strings from the tool status
00298     static const std::string mt_strDISABLED;
00299     static const std::string mt_strMISSING;
00300 
00301     // Stuff to parse and convert the tranform data
00302     static const int mt_nRotationLength;
00303     static long mt_nRotationMultiplier;
00304     static const int mt_nTranslationLength;
00305     static long mt_nTranslationMultiplier;
00306     static const int mt_nErrorLength;
00307     static const long mt_nErrorMultiplier;
00308     static const int mt_nFrameNumberLength;
00309 
00310     static const int mt_nDefaultMaxRetries;
00311 
00312     //maps a long integer from baud rate to an "NDI happy" char 
00313     std::map<long, char> mt_BaudMap;
00314 
00316     SerialPort port;
00317 
00319     int mt_pSerialIO;
00320 
00322     bool mt_bUseCRC;
00323         
00325     bool mt_bCheckCRC;
00326 
00328     NDICommands(const NDICommands&);
00329         
00331     int m_nNumFieldGenerators;
00332 
00334     int m_nNumMagneticPorts;
00335 };
00336 }
00337 
00338 #endif

Generated on Wed Feb 28 15:18:49 2007 for NaviTrack by  doxygen 1.4.6