$search
00001 """Constant and messages definition for MT communication.""" 00002 00003 00004 class MID: 00005 """Values for the message id (MID)""" 00006 ## Error message, 1 data byte 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 # State MID 00017 ## Switch to measurement state 00018 GoToMeasurement = 0x10 00019 ## Switch to config state 00020 GoToConfig = 0x30 00021 ## Reset device 00022 Reset = 0x40 00023 00024 # Informational messages 00025 ## Request device id 00026 ReqDID = 0x00 00027 ## DeviceID, 4 bytes: HH HL LH LL 00028 DeviceID = 0x01 00029 ## Request product code in plain text 00030 ReqProductCode = 0x1C 00031 ## Product code (max 20 bytes data) 00032 ProductCode = 0x1d 00033 ## Request firmware revision 00034 ReqFWRev = 0x12 00035 ## Firmware revision, 3 bytes: major minor rev 00036 FirmwareRev = 0x13 00037 ## Request data length according to current configuration 00038 ReqDataLength = 0x0a 00039 ## Data Length, 2 bytes 00040 DataLength = 0x0b 00041 ## Request GPS status 00042 ReqGPSStatus = 0xA6 00043 ## GPS status 00044 GPSStatus = 0xA7 00045 00046 # Device specific messages 00047 ## Request baudrate 00048 ReqBaudrate = 0x18 00049 ## Set next baudrate 00050 SetBaudrate = 0x18 00051 ## Restore factory defaults 00052 RestoreFactoryDef = 0x0E 00053 00054 # Configuration messages 00055 ## Request configuration 00056 ReqConfiguration = 0x0C 00057 ## Configuration, 118 bytes 00058 Configuration = 0x0D 00059 ## Set sampling period, 2 bytes 00060 SetPeriod = 0x04 00061 ## Set skip factor 00062 SetOutputSkipFactor = 0xD4 00063 ## Set output mode, 2 bytes 00064 SetOutputMode = 0xD0 00065 ## Set output settings, 4 bytes 00066 SetOutputSettings = 0xD2 00067 00068 # Data messages 00069 ## Data packet 00070 MTData = 0x32 00071 00072 # XKF Filter messages 00073 ## Request the available XKF scenarios on the device 00074 ReqAvailableScenarios = 0x62 00075 ## Request the ID of the currently used scenario 00076 ReqCurrentScenario = 0x64 00077 ## Set the scenario to use, 2 bytes 00078 SetCurrentScenario = 0x64 00079 00080 00081 class Baudrates(object): 00082 """Baudrate information and conversion.""" 00083 ## Baudrate mapping between ID and value 00084 Baudrates = [ 00085 (0x00, 460800), 00086 (0x01, 230400), 00087 (0x02, 115200), 00088 (0x03, 76800), 00089 (0x04, 57600), 00090 (0x05, 38400), 00091 (0x06, 28800), 00092 (0x07, 19200), 00093 (0x08, 14400), 00094 (0x09, 9600), 00095 (0x80, 921600)] 00096 @classmethod 00097 def get_BRID(cls, baudrate): 00098 """Get baudrate id for a given baudrate.""" 00099 for brid, br in cls.Baudrates: 00100 if baudrate==br: 00101 return brid 00102 raise MTException("unsupported baudrate.") 00103 @classmethod 00104 def get_BR(cls, baudrate_id): 00105 """Get baudrate for a given baudrate id.""" 00106 for brid, br in cls.Baudrates: 00107 if baudrate_id==brid: 00108 return br 00109 raise MTException("unknown baudrate id.") 00110 00111 00112 class OutputMode: 00113 """Values for the output mode.""" 00114 Temp = 0x0001 00115 Calib = 0x0002 00116 Orient = 0x0004 00117 Auxiliary = 0x0008 00118 Position = 0x0010 00119 Velocity = 0x0020 00120 Status = 0x0800 00121 RAWGPS = 0x1000 # supposed to be incompatible with previous 00122 RAW = 0x4000 # incompatible with all except RAWGPS 00123 00124 00125 class OutputSettings: 00126 """Values for the output settings.""" 00127 Timestamp_None = 0x00000000 00128 Timestamp_SampleCnt = 0x00000001 00129 OrientMode_Quaternion = 0x00000000 00130 OrientMode_Euler = 0x00000004 00131 OrientMode_Matrix = 0x00000008 00132 CalibMode_AccGyrMag = 0x00000000 00133 CalibMode_GyrMag = 0x00000010 00134 CalibMode_AccMag = 0x00000020 00135 CalibMode_Mag = 0x00000030 00136 CalibMode_AccGyr = 0x00000040 00137 CalibMode_Gyr = 0x00000050 00138 CalibMode_Acc = 0x00000060 00139 CalibMode_Mask = 0x00000070 00140 DataFormat_Float = 0x00000000 00141 DataFormat_12_20 = 0x00000100 # not supported yet 00142 DataFormat_16_32 = 0x00000200 # not supported yet 00143 DataFormat_Double = 0x00000300 # not supported yet 00144 AuxiliaryMode_NoAIN1 = 0x00000400 00145 AuxiliaryMode_NoAIN2 = 0x00000800 00146 PositionMode_LLA_WGS84 = 0x00000000 00147 VelocityMode_MS_XYZ = 0x00000000 00148 Coordinates_NED = 0x80000000 00149 00150 00151 class MTException(Exception): 00152 def __init__(self, message): 00153 self.message = message 00154 def __str__(self): 00155 return "MT error: " + self.message