00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 from . import payloads
00047
00048 from collections import namedtuple
00049
00050
00051 __version__ = "1.0"
00052 __revision__ = "$Revision: 916 $"
00053
00054 VERSION_BYTE = 0x00
00055
00056 SET = 0x01
00057 REQUEST = 0x02
00058
00059 class Code:
00060 def __init__(self, base_code, capability, data_payload_cls, request_payload_cls=None):
00061 self.base_code = base_code
00062 self.capability = capability
00063 self.data_payload = data_payload_cls
00064 if request_payload_cls:
00065
00066 self.request_payload = request_payload_cls
00067 else:
00068
00069 self.request_payload = payloads.Subscribe
00070
00071 def set(self):
00072 if self.capability & SET: return self.base_code
00073
00074 def request(self):
00075 if self.capability & REQUEST: return self.base_code + 0x4000
00076
00077 def data(self):
00078 if self.capability & REQUEST: return self.base_code + 0x8000
00079
00080 codes = {}
00081 names = {}
00082
00083 def extend(new_codes):
00084 global codes, names
00085 codes.update(new_codes)
00086 for name, code in new_codes.items():
00087 if code.set(): names[code.set()] = name
00088 if code.request(): names[code.request()] = name
00089 if code.data(): names[code.data()] = name
00090
00091
00092 extend({
00093 'echo':
00094 Code( 0x0000, REQUEST, payloads.Echo ),
00095 'platform_info':
00096 Code( 0x0001, SET | REQUEST, payloads.PlatformInfo ),
00097 'platform_name':
00098 Code( 0x0002, SET | REQUEST, payloads.PlatformName ),
00099 'firmware_info':
00100 Code( 0x0003, REQUEST, payloads.FirmwareInfo ),
00101 'system_status':
00102 Code( 0x0004, REQUEST, payloads.SystemStatus ),
00103
00104
00105 'power_status':
00106 Code( 0x0005, REQUEST, payloads.PowerStatus ),
00107 'processor_status':
00108 Code( 0x0006, REQUEST, payloads.ProcessorStatus ),
00109 'safety_status':
00110 Code( 0x0010, REQUEST, payloads.SafetyStatus ),
00111 'config':
00112 Code( 0x0100, SET | REQUEST, payloads.Config, payloads.ConfigRequest ),
00113 'differential_speed':
00114 Code( 0x0200, SET | REQUEST, payloads.DifferentialSpeed ),
00115 'differential_control':
00116 Code( 0x0201, SET | REQUEST, payloads.DifferentialControl ),
00117 'differential_output':
00118 Code( 0x0202, SET | REQUEST, payloads.DifferentialOutput ),
00119 'ackermann_output':
00120 Code( 0x0203, SET | REQUEST, payloads.AckermannOutput ),
00121 'differential_current':
00122 Code( 0x0220, SET | REQUEST, payloads.DifferentialCurrent ),
00123 'differential_current_control':
00124 Code( 0x0221, SET | REQUEST, payloads.DifferentialCurrentControl ),
00125 'velocity':
00126 Code( 0x0204, SET | REQUEST, payloads.Velocity ),
00127 'turn':
00128 Code( 0x0205, SET | REQUEST, payloads.Turn ),
00129 'max_speed':
00130 Code( 0x0210, SET | REQUEST, payloads.MaxSpeed ),
00131 'max_accel':
00132 Code( 0x0211, SET | REQUEST, payloads.MaxAccel ),
00133 'gear_status':
00134 Code( 0x0212, SET | REQUEST, payloads.GearStatus ),
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 'distance':
00146 Code( 0x0500, REQUEST, payloads.Distance ),
00147 'distance_timing':
00148 Code( 0x0501, REQUEST, payloads.DistanceTiming ),
00149 'platform_orientation':
00150 Code( 0x0600, REQUEST , payloads.Orientation ),
00151 'platform_rotation':
00152 Code( 0x0601, REQUEST, payloads.Rotation ),
00153 'platform_acceleration':
00154 Code( 0x0602, REQUEST, payloads.Acceleration ),
00155
00156
00157
00158
00159 'platform_magnetometer':
00160 Code( 0x0606, REQUEST, payloads.Magnetometer ),
00161 'encoders':
00162 Code( 0x0800, REQUEST, payloads.Encoders ),
00163 'raw_encoders':
00164 Code( 0x0801, REQUEST, payloads.RawEncoders ),
00165 'encoders_config':
00166 Code( 0x0802, SET | REQUEST, payloads.EncodersConfig ),
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 'reset':
00184 Code( 0x2000, SET, payloads.Reset ),
00185 'restore_system_config':
00186 Code( 0x2001, SET, payloads.RestoreSystemConfig ),
00187 'store_system_config':
00188 Code( 0x2002, SET, payloads.StoreSystemConfig ),
00189 'current_sensor_config':
00190 Code( 0x2100, SET | REQUEST, payloads.CurrentSensorConfig ),
00191 'voltage_sensor_config':
00192 Code( 0x2101, SET | REQUEST, payloads.VoltageSensorConfig ),
00193 'temperature_sensor_config':
00194 Code( 0x2102, SET | REQUEST, payloads.TemperatureSensorConfig ),
00195 'orientation_sensor_config':
00196 Code( 0x2103, SET | REQUEST, payloads.OrientationSensorConfig ),
00197 'gyro_config':
00198 Code( 0x2104, SET | REQUEST, payloads.GyroConfig ),
00199 'accelerometer_config':
00200 Code( 0x2105, SET | REQUEST, payloads.AccelerometerConfig ),
00201 'magnetometer_config':
00202 Code( 0x2106, SET | REQUEST, payloads.MagnetometerConfig ),
00203 'battery_estimation_config':
00204 Code( 0x2107, SET | REQUEST, payloads.BatteryEstimationConfig ),
00205 'platform_kinematics':
00206 Code( 0x2108, SET | REQUEST, payloads.PlatformKinematics ),
00207 'raw_current_sensor':
00208 Code( 0x2110, REQUEST, payloads.RawCurrentSensor ),
00209 'raw_voltage_sensor':
00210 Code( 0x2111, REQUEST, payloads.RawVoltageSensor ),
00211 'raw_temperature_sensor':
00212 Code( 0x2112, REQUEST, payloads.RawTemperatureSensor ),
00213 'raw_orientation_sensor':
00214 Code( 0x2113, REQUEST, payloads.RawOrientationSensor ),
00215 'raw_gyro':
00216 Code( 0x2114, REQUEST, payloads.RawGyro ),
00217 'raw_accelerometer':
00218 Code( 0x2115, REQUEST, payloads.RawAccelerometer ),
00219 'raw_magnetometer':
00220 Code( 0x2116, REQUEST, payloads.RawMagnetometer ),
00221 'control_flags':
00222 Code( 0x2130, SET | REQUEST, payloads.ControlFlags )
00223 })