Go to the documentation of this file.00001 """Constant and messages definition for MT communication."""
00002
00003
00004 class MID:
00005 """Values for the message id (MID)"""
00006
00007 Error = 0x42
00008 ErrorCodes = {
00009 0x03: "Invalid period",
00010 0x04: "Invalid message",
00011 0x1E: "Timer overflow",
00012 0x20: "Invalid baudrate",
00013 0x21: "Invalid parameter"
00014 }
00015
00016
00017
00018 WakeUp = 0x3E
00019
00020 GoToConfig = 0x30
00021
00022 GoToMeasurement = 0x10
00023
00024 Reset = 0x40
00025
00026
00027
00028 ReqDID = 0x00
00029
00030 DeviceID = 0x01
00031
00032 InitMT = 0x02
00033 InitMTResults = 0x03
00034
00035 ReqProductCode = 0x1C
00036
00037 ProductCode = 0x1D
00038
00039 ReqFWRev = 0x12
00040
00041 FirmwareRev = 0x13
00042
00043 ReqDataLength = 0x0A
00044
00045 DataLength = 0x0B
00046
00047 ReqGPSStatus = 0xA6
00048
00049 GPSStatus = 0xA7
00050
00051
00052
00053 SetBaudrate = 0x18
00054
00055 SetErrorMode = 0xDA
00056
00057 SetLocationID = 0x84
00058
00059 RestoreFactoryDef = 0x0E
00060
00061 SetTransmitDelay = 0xDC
00062
00063
00064
00065 SetSyncSettings = 0x2C
00066
00067 SetSyncInSettings = 0xD6
00068
00069 SetSyncOutSettings = 0xD8
00070
00071
00072
00073 ReqConfiguration = 0x0C
00074
00075 Configuration = 0x0D
00076
00077 SetOutputConfiguration = 0xC0
00078
00079 SetPeriod = 0x04
00080
00081 SetOutputSkipFactor = 0xD4
00082
00083 SetObjectAlignment = 0xE0
00084
00085 SetOutputMode = 0xD0
00086
00087 SetOutputSettings = 0xD2
00088
00089
00090
00091 ReqData = 0x34
00092
00093 MTData = 0x32
00094
00095 MTData2 = 0x36
00096
00097
00098
00099 SetHeading = 0x82
00100
00101 ResetOrientation = 0xA4
00102
00103 ReqUTCTime = 0x60
00104
00105 UTCTime = 0x61
00106
00107 ReqAvailableScenarios = 0x62
00108
00109 AvailableScenarios = 0x63
00110
00111 SetCurrentScenario = 0x64
00112
00113 SetGravityMagnitude = 0x66
00114
00115 SetLeverArmGPS = 0x68
00116
00117 SetMagneticDeclination = 0x6A
00118
00119
00120 SetLatLonAlt = 0x6E
00121
00122 SetProcessingFlags = 0x20
00123
00124 SetNoRotation = 0x22
00125
00126
00127
00128 def getName(cls, value):
00129 '''Return the name of the first found member of class cls with given
00130 value.'''
00131 for k, v in cls.__dict__.iteritems():
00132 if v==value:
00133 return k
00134 return ''
00135
00136
00137 def getMIDName(mid):
00138 '''Return the name of a message given the message id.'''
00139 name = getName(MID, mid)
00140 if name:
00141 return name
00142 if mid&1:
00143 name = getName(MID, mid-1)
00144 if name:
00145 return name+'Ack'
00146 return 'unknown MID'
00147
00148
00149 class Baudrates(object):
00150 """Baudrate information and conversion."""
00151
00152 Baudrates = [
00153 (0x80, 921600),
00154 (0x0A, 921600),
00155 (0x00, 460800),
00156 (0x01, 230400),
00157 (0x02, 115200),
00158 (0x03, 76800),
00159 (0x04, 57600),
00160 (0x05, 38400),
00161 (0x06, 28800),
00162 (0x07, 19200),
00163 (0x08, 14400),
00164 (0x09, 9600),
00165 (0x0B, 4800),
00166 (0x80, 921600)]
00167 @classmethod
00168 def get_BRID(cls, baudrate):
00169 """Get baudrate id for a given baudrate."""
00170 for brid, br in cls.Baudrates:
00171 if baudrate==br:
00172 return brid
00173 raise MTException("unsupported baudrate.")
00174 @classmethod
00175 def get_BR(cls, baudrate_id):
00176 """Get baudrate for a given baudrate id."""
00177 for brid, br in cls.Baudrates:
00178 if baudrate_id==brid:
00179 return br
00180 raise MTException("unknown baudrate id.")
00181
00182
00183 class OutputMode:
00184 """Values for the output mode."""
00185 Temp = 0x0001
00186 Calib = 0x0002
00187 Orient = 0x0004
00188 Auxiliary = 0x0008
00189 Position = 0x0010
00190 Velocity = 0x0020
00191 Status = 0x0800
00192 RAWGPS = 0x1000
00193 RAW = 0x4000
00194
00195
00196 class OutputSettings:
00197 """Values for the output settings."""
00198 Timestamp_None = 0x00000000
00199 Timestamp_SampleCnt = 0x00000001
00200 OrientMode_Quaternion = 0x00000000
00201 OrientMode_Euler = 0x00000004
00202 OrientMode_Matrix = 0x00000008
00203 CalibMode_AccGyrMag = 0x00000000
00204 CalibMode_GyrMag = 0x00000010
00205 CalibMode_AccMag = 0x00000020
00206 CalibMode_Mag = 0x00000030
00207 CalibMode_AccGyr = 0x00000040
00208 CalibMode_Gyr = 0x00000050
00209 CalibMode_Acc = 0x00000060
00210 CalibMode_Mask = 0x00000070
00211 DataFormat_Float = 0x00000000
00212 DataFormat_12_20 = 0x00000100
00213 DataFormat_16_32 = 0x00000200
00214 DataFormat_Double = 0x00000300
00215 AuxiliaryMode_NoAIN1 = 0x00000400
00216 AuxiliaryMode_NoAIN2 = 0x00000800
00217 PositionMode_LLA_WGS84 = 0x00000000
00218 VelocityMode_MS_XYZ = 0x00000000
00219 Coordinates_NED = 0x80000000
00220
00221
00222 class XDIGroup:
00223 """Values for the XDI groups."""
00224 Temperature = 0x0800
00225 Timestamp = 0x1000
00226 OrientationData = 0x2000
00227 Pressure = 0x3000
00228 Acceleration = 0x4000
00229 Position = 0x5000
00230 AngularVelocity = 0x8000
00231 GPS = 0x8800
00232 SensorComponentReadout = 0xA000
00233 AnalogIn = 0xB000
00234 Magnetic = 0xC000
00235 Velocity = 0xD000
00236 Status = 0xE000
00237
00238
00239 class MTException(Exception):
00240 def __init__(self, message):
00241 self.message = message
00242 def __str__(self):
00243 return "MT error: " + self.message
00244