dascubed/CubeMessages.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of dascubed.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created: 2011-05-25
00021 **  Authors:
00022 **    Marc Wathelet (ISTerre, Grenoble, France)
00023 **
00024 ***************************************************************************/
00025 
00026 #ifndef CUBEMESSAGES_H
00027 #define CUBEMESSAGES_H
00028 
00029 #include <WaranCore.h>
00030 #include "CubeTcpServer.h"
00031 
00032 class CubeBuffer;
00033 
00034 enum MessageClass {ControlMessageClass=0x01,
00035                    ParameterMessageClass=0x02,
00036                    StatusMessageClass=0x03,
00037                    DataMessageClass=0x04};
00038 
00039 class StartPayload
00040 {
00041 public:
00042   enum MessageId {MessageId=0x01};
00043 };
00044 
00045 class StopPayload
00046 {
00047 public:
00048   enum MessageId {MessageId=0x02};
00049 };
00050 
00051 class ResetPayload
00052 {
00053 public:
00054   enum MessageId {MessageId=0x03};
00055 };
00056 
00057 class FrequencyPayload
00058 {
00059 public:
00060   FrequencyPayload(int value) {_frequency.value=value;}
00061 
00062   enum MessageId {MessageId=0x01};
00063 
00064   inline void bigEndianValues();
00065   unsigned int value() const {return _frequency.value;}
00066 
00067   void get(CubeTcpServer * tcpServer) {sendTCP(tcpServer, value());}
00068   static void sendTCP(CubeTcpServer * tcpServer, unsigned int value);
00069 private:
00070   union {
00071     unsigned int value;
00072     unsigned char bytes[4];
00073   } _frequency;
00074 };
00075 
00076 inline void FrequencyPayload::bigEndianValues()
00077 {
00078 #if BYTE_ORDER==LITTLE_ENDIAN
00079   ByteOrder::swap(_frequency.bytes);
00080 #endif
00081 }
00082 
00083 class GainsPayload
00084 {
00085 public:
00086   GainsPayload(int hard, int soft) {_hard.value=hard; _soft.value=soft;}
00087 
00088   enum MessageId {MessageId=0x02};
00089 
00090   inline void bigEndianValues();
00091   unsigned int hard() const {return _hard.value;}
00092   unsigned int soft() const {return _soft.value;}
00093 
00094   void get(CubeTcpServer * tcpServer) {sendTCP(tcpServer, hard(), soft());}
00095   static void sendTCP(CubeTcpServer * tcpServer, unsigned int hard, unsigned int soft);
00096 private:
00097   union {
00098     unsigned int value;
00099     unsigned char bytes[4];
00100   } _hard;
00101   union {
00102     unsigned int value;
00103     unsigned char bytes[4];
00104   } _soft;
00105 };
00106 
00107 inline void GainsPayload::bigEndianValues()
00108 {
00109 #if BYTE_ORDER==LITTLE_ENDIAN
00110   ByteOrder::swap(_hard.bytes);
00111   ByteOrder::swap(_soft.bytes);
00112 #endif
00113 }
00114 
00115 class TimeModePayload
00116 {
00117 public:
00118   TimeModePayload(int value) {_timeMode.value=value;}
00119 
00120   enum MessageId {MessageId=0x03};
00121 
00122   inline void bigEndianValues();
00123   unsigned int value() const {return _timeMode.value;}
00124 
00125   void get(CubeTcpServer * tcpServer) {sendTCP(tcpServer, value());}
00126   static void sendTCP(CubeTcpServer * tcpServer, unsigned int value);
00127 private:
00128   union {
00129     unsigned int value;
00130     unsigned char bytes[4];
00131   } _timeMode;
00132 };
00133 
00134 inline void TimeModePayload::bigEndianValues()
00135 {
00136 #if BYTE_ORDER==LITTLE_ENDIAN
00137   ByteOrder::swap(_timeMode.bytes);
00138 #endif
00139 }
00140 
00141 class OkPayload
00142 {
00143 public:
00144   enum MessageId {MessageId=0x01};
00145 
00146   unsigned char messageClass() const {return _messageClass;}
00147   unsigned char messageId() const {return _messageId;}
00148 
00149   void get(CubeTcpServer * tcpServer);
00150 private:
00151   unsigned char _messageClass;
00152   unsigned char _messageId;
00153 };
00154 
00155 class ErrorPayload
00156 {
00157 public:
00158   enum MessageId {MessageId=0x02};
00159 
00160   inline void bigEndianValues();
00161 
00162   void get(CubeTcpServer * tcpServer, CubeBuffer * buffer);
00163 private:
00164   unsigned char _messageClass;
00165   unsigned char _messageId;
00166   unsigned char _errorClass;
00167   unsigned char _errorId;
00168   union {
00169     unsigned int value;
00170     unsigned char bytes[4];
00171   } _errorData;
00172 };
00173 
00174 inline void ErrorPayload::bigEndianValues()
00175 {
00176 #if BYTE_ORDER==LITTLE_ENDIAN
00177   ByteOrder::swap(_errorData.bytes);
00178 #endif
00179 }
00180 
00181 class HardVersionPayload
00182 {
00183 public:
00184   enum MessageId {MessageId=0x03};
00185 
00186   void get(CubeTcpServer * tcpServer);
00187 private:
00188   char _string[16];
00189 };
00190 
00191 class SoftVersionPayload
00192 {
00193 public:
00194   enum MessageId {MessageId=0x04};
00195 
00196   void get(CubeTcpServer * tcpServer);
00197 private:
00198   char _string[16];
00199 };
00200 
00201 class BatteryPayload
00202 {
00203 public:
00204   enum MessageId {MessageId=0x05};
00205 
00206   inline void bigEndianValues();
00207   float value() const {return _battery.value/2048.0;}
00208 
00209   void get(CubeTcpServer * tcpServer);
00210 private:
00211   union {
00212     unsigned int value;
00213     unsigned char bytes[4];
00214   } _battery;
00215 };
00216 
00217 inline void BatteryPayload::bigEndianValues()
00218 {
00219 #if BYTE_ORDER==LITTLE_ENDIAN
00220   ByteOrder::swap(_battery.bytes);
00221 #endif
00222 }
00223 
00224 class TemperaturePayload
00225 {
00226 public:
00227   enum MessageId {MessageId=0x06};
00228 
00229   inline void bigEndianValues();
00230   float value() const {return _temperature.value*0.125;}
00231 
00232   void get(CubeTcpServer * tcpServer);
00233 private:
00234   union {
00235     unsigned int value;
00236     unsigned char bytes[4];
00237   } _temperature;
00238 };
00239 
00240 inline void TemperaturePayload::bigEndianValues()
00241 {
00242 #if BYTE_ORDER==LITTLE_ENDIAN
00243   ByteOrder::swap(_temperature.bytes);
00244 #endif
00245 }
00246 
00247 class DataPayload
00248 {
00249 public:
00250   DataPayload(int seqNum) {_sequenceNumber.value=seqNum;}
00251 
00252   enum MessageId {MessageId=0x01};
00253 
00254   inline void bigEndianValues();
00255   unsigned int sequenceNumber() const {return _sequenceNumber.value;}
00256 private:
00257   union {
00258     unsigned int value;
00259     unsigned char bytes[4];
00260   } _sequenceNumber;
00261 };
00262 
00263 inline void DataPayload::bigEndianValues()
00264 {
00265 #if BYTE_ORDER==LITTLE_ENDIAN
00266   ByteOrder::swap(_sequenceNumber.bytes);
00267 #endif
00268 }
00269 
00270 class DataGetPayload: public DataPayload
00271 {
00272 public:
00273   inline void bigEndianValues();
00274   unsigned int numberOfSamples() const {return _numberOfSamples.value;}
00275   unsigned int ppsBegin() const {return _ppsBegin.value;}
00276   unsigned int sampleIndex() const {return _sampleIndex.value;}
00277 private:
00278   union {
00279     unsigned int value;
00280     unsigned char bytes[4];
00281   } _numberOfSamples;
00282   union {
00283     unsigned int value;
00284     unsigned char bytes[4];
00285   } _ppsBegin;
00286   union {
00287     unsigned int value;
00288     unsigned char bytes[4];
00289   } _sampleIndex;
00290 };
00291 
00292 inline void DataGetPayload::bigEndianValues()
00293 {
00294 #if BYTE_ORDER==LITTLE_ENDIAN
00295   DataPayload::bigEndianValues();
00296   ByteOrder::swap(_numberOfSamples.bytes);
00297   ByteOrder::swap(_ppsBegin.bytes);
00298   ByteOrder::swap(_sampleIndex.bytes);
00299 #endif
00300 }
00301 
00302 #endif // CUBEMESSAGES_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines