Guest User

Untitled

a guest
Jun 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 122.00 KB | None | 0 0
  1. function [] = OPLogConvert(varargin)
  2. %% Define indices and arrays of structures to hold data
  3. % THIS FILE IS AUTOMATICALLY GENERATED.
  4.  
  5. wrongSyncByte=0;
  6. wrongMessageByte=0;
  7. lastWrongSyncByte=0;
  8. lastWrongMessageByte=0;
  9. str1=[];
  10. str2=[];
  11. str3=[];
  12. str4=[];
  13. str5=[];
  14.  
  15. fprintf('\n\n***OpenPilot log parser***\n\n');
  16.  
  17. outputType='mat'; %Default output is a .mat file
  18. checkCRC = false;
  19. global crc_table;
  20. crc_table = [ ...
  21. hex2dec('00'),hex2dec('07'),hex2dec('0e'),hex2dec('09'),hex2dec('1c'),hex2dec('1b'),hex2dec('12'),hex2dec('15'),hex2dec('38'),hex2dec('3f'),hex2dec('36'),hex2dec('31'),hex2dec('24'),hex2dec('23'),hex2dec('2a'),hex2dec('2d'), ...
  22. hex2dec('70'),hex2dec('77'),hex2dec('7e'),hex2dec('79'),hex2dec('6c'),hex2dec('6b'),hex2dec('62'),hex2dec('65'),hex2dec('48'),hex2dec('4f'),hex2dec('46'),hex2dec('41'),hex2dec('54'),hex2dec('53'),hex2dec('5a'),hex2dec('5d'), ...
  23. hex2dec('e0'),hex2dec('e7'),hex2dec('ee'),hex2dec('e9'),hex2dec('fc'),hex2dec('fb'),hex2dec('f2'),hex2dec('f5'),hex2dec('d8'),hex2dec('df'),hex2dec('d6'),hex2dec('d1'),hex2dec('c4'),hex2dec('c3'),hex2dec('ca'),hex2dec('cd'), ...
  24. hex2dec('90'),hex2dec('97'),hex2dec('9e'),hex2dec('99'),hex2dec('8c'),hex2dec('8b'),hex2dec('82'),hex2dec('85'),hex2dec('a8'),hex2dec('af'),hex2dec('a6'),hex2dec('a1'),hex2dec('b4'),hex2dec('b3'),hex2dec('ba'),hex2dec('bd'), ...
  25. hex2dec('c7'),hex2dec('c0'),hex2dec('c9'),hex2dec('ce'),hex2dec('db'),hex2dec('dc'),hex2dec('d5'),hex2dec('d2'),hex2dec('ff'),hex2dec('f8'),hex2dec('f1'),hex2dec('f6'),hex2dec('e3'),hex2dec('e4'),hex2dec('ed'),hex2dec('ea'), ...
  26. hex2dec('b7'),hex2dec('b0'),hex2dec('b9'),hex2dec('be'),hex2dec('ab'),hex2dec('ac'),hex2dec('a5'),hex2dec('a2'),hex2dec('8f'),hex2dec('88'),hex2dec('81'),hex2dec('86'),hex2dec('93'),hex2dec('94'),hex2dec('9d'),hex2dec('9a'), ...
  27. hex2dec('27'),hex2dec('20'),hex2dec('29'),hex2dec('2e'),hex2dec('3b'),hex2dec('3c'),hex2dec('35'),hex2dec('32'),hex2dec('1f'),hex2dec('18'),hex2dec('11'),hex2dec('16'),hex2dec('03'),hex2dec('04'),hex2dec('0d'),hex2dec('0a'), ...
  28. hex2dec('57'),hex2dec('50'),hex2dec('59'),hex2dec('5e'),hex2dec('4b'),hex2dec('4c'),hex2dec('45'),hex2dec('42'),hex2dec('6f'),hex2dec('68'),hex2dec('61'),hex2dec('66'),hex2dec('73'),hex2dec('74'),hex2dec('7d'),hex2dec('7a'), ...
  29. hex2dec('89'),hex2dec('8e'),hex2dec('87'),hex2dec('80'),hex2dec('95'),hex2dec('92'),hex2dec('9b'),hex2dec('9c'),hex2dec('b1'),hex2dec('b6'),hex2dec('bf'),hex2dec('b8'),hex2dec('ad'),hex2dec('aa'),hex2dec('a3'),hex2dec('a4'), ...
  30. hex2dec('f9'),hex2dec('fe'),hex2dec('f7'),hex2dec('f0'),hex2dec('e5'),hex2dec('e2'),hex2dec('eb'),hex2dec('ec'),hex2dec('c1'),hex2dec('c6'),hex2dec('cf'),hex2dec('c8'),hex2dec('dd'),hex2dec('da'),hex2dec('d3'),hex2dec('d4'), ...
  31. hex2dec('69'),hex2dec('6e'),hex2dec('67'),hex2dec('60'),hex2dec('75'),hex2dec('72'),hex2dec('7b'),hex2dec('7c'),hex2dec('51'),hex2dec('56'),hex2dec('5f'),hex2dec('58'),hex2dec('4d'),hex2dec('4a'),hex2dec('43'),hex2dec('44'), ...
  32. hex2dec('19'),hex2dec('1e'),hex2dec('17'),hex2dec('10'),hex2dec('05'),hex2dec('02'),hex2dec('0b'),hex2dec('0c'),hex2dec('21'),hex2dec('26'),hex2dec('2f'),hex2dec('28'),hex2dec('3d'),hex2dec('3a'),hex2dec('33'),hex2dec('34'), ...
  33. hex2dec('4e'),hex2dec('49'),hex2dec('40'),hex2dec('47'),hex2dec('52'),hex2dec('55'),hex2dec('5c'),hex2dec('5b'),hex2dec('76'),hex2dec('71'),hex2dec('78'),hex2dec('7f'),hex2dec('6a'),hex2dec('6d'),hex2dec('64'),hex2dec('63'), ...
  34. hex2dec('3e'),hex2dec('39'),hex2dec('30'),hex2dec('37'),hex2dec('22'),hex2dec('25'),hex2dec('2c'),hex2dec('2b'),hex2dec('06'),hex2dec('01'),hex2dec('08'),hex2dec('0f'),hex2dec('1a'),hex2dec('1d'),hex2dec('14'),hex2dec('13'), ...
  35. hex2dec('ae'),hex2dec('a9'),hex2dec('a0'),hex2dec('a7'),hex2dec('b2'),hex2dec('b5'),hex2dec('bc'),hex2dec('bb'),hex2dec('96'),hex2dec('91'),hex2dec('98'),hex2dec('9f'),hex2dec('8a'),hex2dec('8d'),hex2dec('84'),hex2dec('83'), ...
  36. hex2dec('de'),hex2dec('d9'),hex2dec('d0'),hex2dec('d7'),hex2dec('c2'),hex2dec('c5'),hex2dec('cc'),hex2dec('cb'),hex2dec('e6'),hex2dec('e1'),hex2dec('e8'),hex2dec('ef'),hex2dec('fa'),hex2dec('fd'),hex2dec('f4'),hex2dec('f3') ...
  37. ];
  38.  
  39. if nargin==0
  40. %%
  41. if (exist('uigetfile')) %#ok<EXIST>
  42. [FileName, PathName]=uigetfile('*.opl');
  43. logfile=fullfile(PathName, FileName);
  44.  
  45. else
  46. error('Your technical computing program does not support file choosers. Please input the file name in the argument. ')
  47. end
  48. elseif nargin>0
  49. logfile=varargin{1};
  50. if nargin>1
  51. outputType=varargin{2};
  52. end
  53. end
  54.  
  55. if ~strcmpi(outputType,'mat') && ~strcmpi(outputType,'csv')
  56. error('Incorrect file format specified. Second argument must be ''mat'' or ''csv''.');
  57. end
  58.  
  59.  
  60. accelsIdx = 0;
  61. Accels=struct('timestamp', 0,...
  62. 'x', 0,...
  63. 'y', 0,...
  64. 'z', 0,...
  65. 'temperature', 0);
  66. ACCELS_OBJID=3718078400;
  67.  
  68. accessorydesiredIdx = 0;
  69. AccessoryDesired=struct('timestamp', 0,...
  70. 'instanceID', 0,...
  71. 'AccessoryVal', 0);
  72. ACCESSORYDESIRED_OBJID=3288963162;
  73.  
  74. actuatorcommandIdx = 0;
  75. ActuatorCommand=struct('timestamp', 0,...
  76. 'Channel', zeros(10,1),...
  77. 'MaxUpdateTime', 0,...
  78. 'UpdateTime', 0,...
  79. 'NumFailedUpdates', 0);
  80. ACTUATORCOMMAND_OBJID=87182520;
  81.  
  82. actuatordesiredIdx = 0;
  83. ActuatorDesired=struct('timestamp', 0,...
  84. 'Roll', 0,...
  85. 'Pitch', 0,...
  86. 'Yaw', 0,...
  87. 'Throttle', 0,...
  88. 'UpdateTime', 0,...
  89. 'NumLongUpdates', 0);
  90. ACTUATORDESIRED_OBJID=3393963172;
  91.  
  92. actuatorsettingsIdx = 0;
  93. ActuatorSettings=struct('timestamp', 0,...
  94. 'ChannelUpdateFreq', zeros(4,1),...
  95. 'ChannelMax', zeros(10,1),...
  96. 'ChannelNeutral', zeros(10,1),...
  97. 'ChannelMin', zeros(10,1),...
  98. 'FixedWingRoll1', 0,...
  99. 'FixedWingRoll2', 0,...
  100. 'FixedWingPitch1', 0,...
  101. 'FixedWingPitch2', 0,...
  102. 'FixedWingYaw1', 0,...
  103. 'FixedWingYaw2', 0,...
  104. 'FixedWingThrottle', 0,...
  105. 'VTOLMotorN', 0,...
  106. 'VTOLMotorNE', 0,...
  107. 'VTOLMotorE', 0,...
  108. 'VTOLMotorSE', 0,...
  109. 'VTOLMotorS', 0,...
  110. 'VTOLMotorSW', 0,...
  111. 'VTOLMotorW', 0,...
  112. 'VTOLMotorNW', 0,...
  113. 'ChannelType', zeros(10,1),...
  114. 'ChannelAddr', zeros(10,1),...
  115. 'MotorsSpinWhileArmed', 0);
  116. ACTUATORSETTINGS_OBJID=4068955974;
  117.  
  118. altholdsmoothedIdx = 0;
  119. AltHoldSmoothed=struct('timestamp', 0,...
  120. 'Altitude', 0,...
  121. 'Velocity', 0,...
  122. 'Accel', 0);
  123. ALTHOLDSMOOTHED_OBJID=734443986;
  124.  
  125. altitudeholddesiredIdx = 0;
  126. AltitudeHoldDesired=struct('timestamp', 0,...
  127. 'Altitude', 0,...
  128. 'Roll', 0,...
  129. 'Pitch', 0,...
  130. 'Yaw', 0);
  131. ALTITUDEHOLDDESIRED_OBJID=1230744942;
  132.  
  133. altitudeholdsettingsIdx = 0;
  134. AltitudeHoldSettings=struct('timestamp', 0,...
  135. 'Kp', 0,...
  136. 'Ki', 0,...
  137. 'Kd', 0,...
  138. 'Ka', 0,...
  139. 'PressureNoise', 0,...
  140. 'AccelNoise', 0,...
  141. 'AccelDrift', 0);
  142. ALTITUDEHOLDSETTINGS_OBJID=4274346818;
  143.  
  144. attitudeactualIdx = 0;
  145. AttitudeActual=struct('timestamp', 0,...
  146. 'q1', 0,...
  147. 'q2', 0,...
  148. 'q3', 0,...
  149. 'q4', 0,...
  150. 'Roll', 0,...
  151. 'Pitch', 0,...
  152. 'Yaw', 0);
  153. ATTITUDEACTUAL_OBJID=869979622;
  154.  
  155. attitudesettingsIdx = 0;
  156. AttitudeSettings=struct('timestamp', 0,...
  157. 'GyroGain', 0,...
  158. 'AccelKp', 0,...
  159. 'AccelKi', 0,...
  160. 'YawBiasRate', 0,...
  161. 'AccelBias', zeros(3,1),...
  162. 'GyroBias', zeros(3,1),...
  163. 'BoardRotation', zeros(3,1),...
  164. 'ZeroDuringArming', 0,...
  165. 'BiasCorrectGyro', 0,...
  166. 'TrimFlight', 0);
  167. ATTITUDESETTINGS_OBJID=3272064074;
  168.  
  169. baroaltitudeIdx = 0;
  170. BaroAltitude=struct('timestamp', 0,...
  171. 'Altitude', 0,...
  172. 'Temperature', 0,...
  173. 'Pressure', 0);
  174. BAROALTITUDE_OBJID=2573348458;
  175.  
  176. cameradesiredIdx = 0;
  177. CameraDesired=struct('timestamp', 0,...
  178. 'Roll', 0,...
  179. 'Pitch', 0,...
  180. 'Yaw', 0);
  181. CAMERADESIRED_OBJID=1394562126;
  182.  
  183. camerastabsettingsIdx = 0;
  184. CameraStabSettings=struct('timestamp', 0,...
  185. 'MaxAxisLockRate', 0,...
  186. 'ResponseTime', zeros(3,1),...
  187. 'Input', zeros(3,1),...
  188. 'InputRange', zeros(3,1),...
  189. 'InputRate', zeros(3,1),...
  190. 'StabilizationMode', zeros(3,1),...
  191. 'OutputRange', zeros(3,1));
  192. CAMERASTABSETTINGS_OBJID=999677370;
  193.  
  194. faultsettingsIdx = 0;
  195. FaultSettings=struct('timestamp', 0,...
  196. 'ActivateFault', 0);
  197. FAULTSETTINGS_OBJID=662223420;
  198.  
  199. firmwareiapobjIdx = 0;
  200. FirmwareIAPObj=struct('timestamp', 0,...
  201. 'crc', 0,...
  202. 'Command', 0,...
  203. 'BoardRevision', 0,...
  204. 'Description', zeros(40,1),...
  205. 'CPUSerial', zeros(12,1),...
  206. 'BoardType', 0,...
  207. 'ArmReset', 0);
  208. FIRMWAREIAPOBJ_OBJID=1020132200;
  209.  
  210. flightbatterysettingsIdx = 0;
  211. FlightBatterySettings=struct('timestamp', 0,...
  212. 'Capacity', 0,...
  213. 'VoltageThresholds', zeros(2,1),...
  214. 'SensorCalibrations', zeros(2,1),...
  215. 'Type', 0,...
  216. 'NbCells', 0,...
  217. 'SensorType', 0);
  218. FLIGHTBATTERYSETTINGS_OBJID=4050828056;
  219.  
  220. flightbatterystateIdx = 0;
  221. FlightBatteryState=struct('timestamp', 0,...
  222. 'Voltage', 0,...
  223. 'Current', 0,...
  224. 'PeakCurrent', 0,...
  225. 'AvgCurrent', 0,...
  226. 'ConsumedEnergy', 0,...
  227. 'EstimatedFlightTime', 0);
  228. FLIGHTBATTERYSTATE_OBJID=146855766;
  229.  
  230. flightplancontrolIdx = 0;
  231. FlightPlanControl=struct('timestamp', 0,...
  232. 'Command', 0);
  233. FLIGHTPLANCONTROL_OBJID=1407447424;
  234.  
  235. flightplansettingsIdx = 0;
  236. FlightPlanSettings=struct('timestamp', 0,...
  237. 'Test', 0);
  238. FLIGHTPLANSETTINGS_OBJID=2464808822;
  239.  
  240. flightplanstatusIdx = 0;
  241. FlightPlanStatus=struct('timestamp', 0,...
  242. 'ErrorFileID', 0,...
  243. 'ErrorLineNum', 0,...
  244. 'Debug', zeros(2,1),...
  245. 'Status', 0,...
  246. 'ErrorType', 0);
  247. FLIGHTPLANSTATUS_OBJID=570879558;
  248.  
  249. flightstatusIdx = 0;
  250. FlightStatus=struct('timestamp', 0,...
  251. 'Armed', 0,...
  252. 'FlightMode', 0);
  253. FLIGHTSTATUS_OBJID=3886315226;
  254.  
  255. flighttelemetrystatsIdx = 0;
  256. FlightTelemetryStats=struct('timestamp', 0,...
  257. 'TxDataRate', 0,...
  258. 'RxDataRate', 0,...
  259. 'TxFailures', 0,...
  260. 'RxFailures', 0,...
  261. 'TxRetries', 0,...
  262. 'Status', 0);
  263. FLIGHTTELEMETRYSTATS_OBJID=796797186;
  264.  
  265. gcsreceiverIdx = 0;
  266. GCSReceiver=struct('timestamp', 0,...
  267. 'Channel', zeros(6,1));
  268. GCSRECEIVER_OBJID=3430820796;
  269.  
  270. gcstelemetrystatsIdx = 0;
  271. GCSTelemetryStats=struct('timestamp', 0,...
  272. 'TxDataRate', 0,...
  273. 'RxDataRate', 0,...
  274. 'TxFailures', 0,...
  275. 'RxFailures', 0,...
  276. 'TxRetries', 0,...
  277. 'Status', 0);
  278. GCSTELEMETRYSTATS_OBJID=2881955652;
  279.  
  280. gpspositionIdx = 0;
  281. GPSPosition=struct('timestamp', 0,...
  282. 'Latitude', 0,...
  283. 'Longitude', 0,...
  284. 'Altitude', 0,...
  285. 'GeoidSeparation', 0,...
  286. 'Heading', 0,...
  287. 'Groundspeed', 0,...
  288. 'PDOP', 0,...
  289. 'HDOP', 0,...
  290. 'VDOP', 0,...
  291. 'Status', 0,...
  292. 'Satellites', 0);
  293. GPSPOSITION_OBJID=3802342326;
  294.  
  295. gpssatellitesIdx = 0;
  296. GPSSatellites=struct('timestamp', 0,...
  297. 'Elevation', zeros(16,1),...
  298. 'Azimuth', zeros(16,1),...
  299. 'SatsInView', 0,...
  300. 'PRN', zeros(16,1),...
  301. 'SNR', zeros(16,1));
  302. GPSSATELLITES_OBJID=153147800;
  303.  
  304. gpstimeIdx = 0;
  305. GPSTime=struct('timestamp', 0,...
  306. 'Year', 0,...
  307. 'Month', 0,...
  308. 'Day', 0,...
  309. 'Hour', 0,...
  310. 'Minute', 0,...
  311. 'Second', 0);
  312. GPSTIME_OBJID=3561455748;
  313.  
  314. guidancesettingsIdx = 0;
  315. GuidanceSettings=struct('timestamp', 0,...
  316. 'HorizontalPosPI', zeros(3,1),...
  317. 'HorizontalVelPID', zeros(4,1),...
  318. 'VerticalPosPI', zeros(3,1),...
  319. 'VerticalVelPID', zeros(4,1),...
  320. 'MaxRollPitch', 0,...
  321. 'UpdatePeriod', 0,...
  322. 'HorizontalVelMax', 0,...
  323. 'VerticalVelMax', 0,...
  324. 'GuidanceMode', 0,...
  325. 'ThrottleControl', 0);
  326. GUIDANCESETTINGS_OBJID=1856479156;
  327.  
  328. gyrosIdx = 0;
  329. Gyros=struct('timestamp', 0,...
  330. 'x', 0,...
  331. 'y', 0,...
  332. 'z', 0,...
  333. 'temperature', 0);
  334. GYROS_OBJID=69372662;
  335.  
  336. gyrosbiasIdx = 0;
  337. GyrosBias=struct('timestamp', 0,...
  338. 'x', 0,...
  339. 'y', 0,...
  340. 'z', 0);
  341. GYROSBIAS_OBJID=3837196672;
  342.  
  343. homelocationIdx = 0;
  344. HomeLocation=struct('timestamp', 0,...
  345. 'Latitude', 0,...
  346. 'Longitude', 0,...
  347. 'Altitude', 0,...
  348. 'ECEF', zeros(3,1),...
  349. 'RNE', zeros(9,1),...
  350. 'Be', zeros(3,1),...
  351. 'g_e', 0,...
  352. 'Set', 0);
  353. HOMELOCATION_OBJID=1538502396;
  354.  
  355. hwsettingsIdx = 0;
  356. HwSettings=struct('timestamp', 0,...
  357. 'CC_RcvrPort', 0,...
  358. 'CC_MainPort', 0,...
  359. 'CC_FlexiPort', 0,...
  360. 'OP_RcvrPort', 0,...
  361. 'OP_MainPort', 0,...
  362. 'OP_FlexiPort', 0,...
  363. 'TelemetrySpeed', 0,...
  364. 'GPSSpeed', 0,...
  365. 'ComUsbBridgeSpeed', 0,...
  366. 'USB_DeviceType', 0,...
  367. 'USB_HIDPort', 0,...
  368. 'USB_VCPPort', 0,...
  369. 'OptionalModules', zeros(5,1),...
  370. 'DSMxBind', 0);
  371. HWSETTINGS_OBJID=786847578;
  372.  
  373. i2cstatsIdx = 0;
  374. I2CStats=struct('timestamp', 0,...
  375. 'evirq_log', zeros(5,1),...
  376. 'erirq_log', zeros(5,1),...
  377. 'event_errors', 0,...
  378. 'fsm_errors', 0,...
  379. 'irq_errors', 0,...
  380. 'nacks', 0,...
  381. 'timeouts', 0,...
  382. 'last_error_type', 0,...
  383. 'event_log', zeros(5,1),...
  384. 'state_log', zeros(5,1));
  385. I2CSTATS_OBJID=3071574590;
  386.  
  387. magnetometerIdx = 0;
  388. Magnetometer=struct('timestamp', 0,...
  389. 'x', 0,...
  390. 'y', 0,...
  391. 'z', 0);
  392. MAGNETOMETER_OBJID=2168149470;
  393.  
  394. manualcontrolcommandIdx = 0;
  395. ManualControlCommand=struct('timestamp', 0,...
  396. 'Throttle', 0,...
  397. 'Roll', 0,...
  398. 'Pitch', 0,...
  399. 'Yaw', 0,...
  400. 'Collective', 0,...
  401. 'Channel', zeros(9,1),...
  402. 'Connected', 0);
  403. MANUALCONTROLCOMMAND_OBJID=511886034;
  404.  
  405. manualcontrolsettingsIdx = 0;
  406. ManualControlSettings=struct('timestamp', 0,...
  407. 'ChannelMin', zeros(9,1),...
  408. 'ChannelNeutral', zeros(9,1),...
  409. 'ChannelMax', zeros(9,1),...
  410. 'ArmedTimeout', 0,...
  411. 'ChannelGroups', zeros(9,1),...
  412. 'ChannelNumber', zeros(9,1),...
  413. 'Arming', 0,...
  414. 'Stabilization1Settings', zeros(3,1),...
  415. 'Stabilization2Settings', zeros(3,1),...
  416. 'Stabilization3Settings', zeros(3,1),...
  417. 'FlightModePosition', zeros(3,1));
  418. MANUALCONTROLSETTINGS_OBJID=2139802646;
  419.  
  420. mixersettingsIdx = 0;
  421. MixerSettings=struct('timestamp', 0,...
  422. 'MaxAccel', 0,...
  423. 'FeedForward', 0,...
  424. 'AccelTime', 0,...
  425. 'DecelTime', 0,...
  426. 'ThrottleCurve1', zeros(5,1),...
  427. 'ThrottleCurve2', zeros(5,1),...
  428. 'Curve2Source', 0,...
  429. 'Mixer1Type', 0,...
  430. 'Mixer1Vector', zeros(5,1),...
  431. 'Mixer2Type', 0,...
  432. 'Mixer2Vector', zeros(5,1),...
  433. 'Mixer3Type', 0,...
  434. 'Mixer3Vector', zeros(5,1),...
  435. 'Mixer4Type', 0,...
  436. 'Mixer4Vector', zeros(5,1),...
  437. 'Mixer5Type', 0,...
  438. 'Mixer5Vector', zeros(5,1),...
  439. 'Mixer6Type', 0,...
  440. 'Mixer6Vector', zeros(5,1),...
  441. 'Mixer7Type', 0,...
  442. 'Mixer7Vector', zeros(5,1),...
  443. 'Mixer8Type', 0,...
  444. 'Mixer8Vector', zeros(5,1),...
  445. 'Mixer9Type', 0,...
  446. 'Mixer9Vector', zeros(5,1),...
  447. 'Mixer10Type', 0,...
  448. 'Mixer10Vector', zeros(5,1));
  449. MIXERSETTINGS_OBJID=1561777860;
  450.  
  451. mixerstatusIdx = 0;
  452. MixerStatus=struct('timestamp', 0,...
  453. 'Mixer1', 0,...
  454. 'Mixer2', 0,...
  455. 'Mixer3', 0,...
  456. 'Mixer4', 0,...
  457. 'Mixer5', 0,...
  458. 'Mixer6', 0,...
  459. 'Mixer7', 0,...
  460. 'Mixer8', 0);
  461. MIXERSTATUS_OBJID=298824934;
  462.  
  463. nedaccelIdx = 0;
  464. NedAccel=struct('timestamp', 0,...
  465. 'North', 0,...
  466. 'East', 0,...
  467. 'Down', 0);
  468. NEDACCEL_OBJID=2088721344;
  469.  
  470. objectpersistenceIdx = 0;
  471. ObjectPersistence=struct('timestamp', 0,...
  472. 'ObjectID', 0,...
  473. 'InstanceID', 0,...
  474. 'Operation', 0,...
  475. 'Selection', 0);
  476. OBJECTPERSISTENCE_OBJID=4137343160;
  477.  
  478. overosyncstatsIdx = 0;
  479. OveroSyncStats=struct('timestamp', 0,...
  480. 'Send', 0,...
  481. 'Received', 0,...
  482. 'DroppedUpdates', 0,...
  483. 'Connected', 0);
  484. OVEROSYNCSTATS_OBJID=948201656;
  485.  
  486. positionactualIdx = 0;
  487. PositionActual=struct('timestamp', 0,...
  488. 'North', 0,...
  489. 'East', 0,...
  490. 'Down', 0);
  491. POSITIONACTUAL_OBJID=4204670274;
  492.  
  493. positiondesiredIdx = 0;
  494. PositionDesired=struct('timestamp', 0,...
  495. 'North', 0,...
  496. 'East', 0,...
  497. 'Down', 0);
  498. POSITIONDESIRED_OBJID=2005777956;
  499.  
  500. ratedesiredIdx = 0;
  501. RateDesired=struct('timestamp', 0,...
  502. 'Roll', 0,...
  503. 'Pitch', 0,...
  504. 'Yaw', 0);
  505. RATEDESIRED_OBJID=216582182;
  506.  
  507. receiveractivityIdx = 0;
  508. ReceiverActivity=struct('timestamp', 0,...
  509. 'ActiveGroup', 0,...
  510. 'ActiveChannel', 0);
  511. RECEIVERACTIVITY_OBJID=511464410;
  512.  
  513. revocalibrationIdx = 0;
  514. RevoCalibration=struct('timestamp', 0,...
  515. 'accel_bias', zeros(3,1),...
  516. 'accel_scale', zeros(3,1),...
  517. 'accel_var', zeros(3,1),...
  518. 'gyro_bias', zeros(3,1),...
  519. 'gyro_scale', zeros(3,1),...
  520. 'gyro_var', zeros(3,1),...
  521. 'gyro_tempcoeff', zeros(3,1),...
  522. 'mag_bias', zeros(3,1),...
  523. 'mag_scale', zeros(3,1),...
  524. 'mag_var', zeros(3,1),...
  525. 'BiasCorrectedRaw', 0);
  526. REVOCALIBRATION_OBJID=3261937586;
  527.  
  528. sonaraltitudeIdx = 0;
  529. SonarAltitude=struct('timestamp', 0,...
  530. 'Altitude', 0);
  531. SONARALTITUDE_OBJID=1817840828;
  532.  
  533. stabilizationdesiredIdx = 0;
  534. StabilizationDesired=struct('timestamp', 0,...
  535. 'Roll', 0,...
  536. 'Pitch', 0,...
  537. 'Yaw', 0,...
  538. 'Throttle', 0,...
  539. 'StabilizationMode', zeros(3,1));
  540. STABILIZATIONDESIRED_OBJID=3683646524;
  541.  
  542. stabilizationsettingsIdx = 0;
  543. StabilizationSettings=struct('timestamp', 0,...
  544. 'ManualRate', zeros(3,1),...
  545. 'MaximumRate', zeros(3,1),...
  546. 'RollRatePID', zeros(4,1),...
  547. 'PitchRatePID', zeros(4,1),...
  548. 'YawRatePID', zeros(4,1),...
  549. 'RollPI', zeros(3,1),...
  550. 'PitchPI', zeros(3,1),...
  551. 'YawPI', zeros(3,1),...
  552. 'GyroTau', 0,...
  553. 'WeakLevelingKp', 0,...
  554. 'RollMax', 0,...
  555. 'PitchMax', 0,...
  556. 'YawMax', 0,...
  557. 'MaxAxisLock', 0,...
  558. 'MaxAxisLockRate', 0,...
  559. 'MaxWeakLevelingRate', 0,...
  560. 'LowThrottleZeroIntegral', 0);
  561. STABILIZATIONSETTINGS_OBJID=1601750302;
  562.  
  563. systemalarmsIdx = 0;
  564. SystemAlarms=struct('timestamp', 0,...
  565. 'Alarm', zeros(18,1));
  566. SYSTEMALARMS_OBJID=164088830;
  567.  
  568. systemsettingsIdx = 0;
  569. SystemSettings=struct('timestamp', 0,...
  570. 'GUIConfigData', zeros(2,1),...
  571. 'AirframeType', 0);
  572. SYSTEMSETTINGS_OBJID=817716604;
  573.  
  574. systemstatsIdx = 0;
  575. SystemStats=struct('timestamp', 0,...
  576. 'FlightTime', 0,...
  577. 'HeapRemaining', 0,...
  578. 'IRQStackRemaining', 0,...
  579. 'CPULoad', 0,...
  580. 'CPUTemp', 0);
  581. SYSTEMSTATS_OBJID=3591414000;
  582.  
  583. taskinfoIdx = 0;
  584. TaskInfo=struct('timestamp', 0,...
  585. 'StackRemaining', zeros(17,1),...
  586. 'Running', zeros(17,1),...
  587. 'RunningTime', zeros(17,1));
  588. TASKINFO_OBJID=1360472970;
  589.  
  590. velocityactualIdx = 0;
  591. VelocityActual=struct('timestamp', 0,...
  592. 'North', 0,...
  593. 'East', 0,...
  594. 'Down', 0);
  595. VELOCITYACTUAL_OBJID=1510536730;
  596.  
  597. velocitydesiredIdx = 0;
  598. VelocityDesired=struct('timestamp', 0,...
  599. 'North', 0,...
  600. 'East', 0,...
  601. 'Down', 0);
  602. VELOCITYDESIRED_OBJID=2660526482;
  603.  
  604. watchdogstatusIdx = 0;
  605. WatchdogStatus=struct('timestamp', 0,...
  606. 'BootupFlags', 0,...
  607. 'ActiveFlags', 0);
  608. WATCHDOGSTATUS_OBJID=2718431868;
  609.  
  610.  
  611.  
  612. fid = fopen(logfile);
  613. correctMsgByte=hex2dec('20');
  614. correctSyncByte=hex2dec('3C');
  615.  
  616. % Parse log file, entry by entry
  617. prebuf = fread(fid, 12, 'uint8');
  618. log_size = dir(logfile);
  619. log_size = log_size.bytes;
  620. last_print = 0;
  621.  
  622. startTime=clock;
  623.  
  624. while (1)
  625. if (feof(fid)); break; end
  626.  
  627. %% Read message header
  628. % get sync field (0x3C, 1 byte)
  629. sync = fread(fid, 1, 'uint8');
  630. if sync ~= correctSyncByte
  631. prebuf = [prebuf(2:end); sync];
  632. wrongSyncByte=wrongSyncByte+1;
  633. % disp ('Wrong sync byte');
  634. continue
  635. end
  636.  
  637. %% Process header if we are aligned
  638. timestamp = typecast(uint8(prebuf(1:4)), 'uint32');
  639. datasize = typecast(uint8(prebuf(5:12)), 'uint64');
  640.  
  641. % get msg type (quint8 1 byte ) should be 0x20, ignore the rest?
  642. msgType = fread(fid, 1, 'uint8');
  643. if msgType ~= correctMsgByte
  644. % disp ('Wrong msgType');
  645. wrongMessageByte=wrongMessageByte+1;
  646. continue
  647. end
  648.  
  649. % get msg size (quint16 2 bytes) excludes crc, include msg header and data payload
  650. msgSize = fread(fid, 1, 'uint16'); %#ok<NASGU>
  651. % get obj id (quint32 4 bytes)
  652. objID = fread(fid, 1, 'uint32');
  653.  
  654. if (isempty(objID)) %End of file
  655. break;
  656. end
  657.  
  658. %% Read object
  659. try
  660. switch objID
  661. case ACCELS_OBJID
  662. accelsIdx = accelsIdx + 1;
  663. Accels= ReadAccelsObject(fid, timestamp, checkCRC, Accels, accelsIdx);
  664. if accelsIdx >= length(Accels.timestamp) %Check to see if pre-allocated memory is exhausted
  665. FieldNames= fieldnames(Accels);
  666. for i=1:length(FieldNames) %Grow structure
  667. Accels.(FieldNames{i})(:,accelsIdx*2+1) = 0;
  668. end;
  669. end
  670. case ACCESSORYDESIRED_OBJID
  671. accessorydesiredIdx = accessorydesiredIdx + 1;
  672. AccessoryDesired= ReadAccessoryDesiredObject(fid, timestamp, checkCRC, AccessoryDesired, accessorydesiredIdx);
  673. if accessorydesiredIdx >= length(AccessoryDesired.timestamp) %Check to see if pre-allocated memory is exhausted
  674. FieldNames= fieldnames(AccessoryDesired);
  675. for i=1:length(FieldNames) %Grow structure
  676. AccessoryDesired.(FieldNames{i})(:,accessorydesiredIdx*2+1) = 0;
  677. end;
  678. end
  679. case ACTUATORCOMMAND_OBJID
  680. actuatorcommandIdx = actuatorcommandIdx + 1;
  681. ActuatorCommand= ReadActuatorCommandObject(fid, timestamp, checkCRC, ActuatorCommand, actuatorcommandIdx);
  682. if actuatorcommandIdx >= length(ActuatorCommand.timestamp) %Check to see if pre-allocated memory is exhausted
  683. FieldNames= fieldnames(ActuatorCommand);
  684. for i=1:length(FieldNames) %Grow structure
  685. ActuatorCommand.(FieldNames{i})(:,actuatorcommandIdx*2+1) = 0;
  686. end;
  687. end
  688. case ACTUATORDESIRED_OBJID
  689. actuatordesiredIdx = actuatordesiredIdx + 1;
  690. ActuatorDesired= ReadActuatorDesiredObject(fid, timestamp, checkCRC, ActuatorDesired, actuatordesiredIdx);
  691. if actuatordesiredIdx >= length(ActuatorDesired.timestamp) %Check to see if pre-allocated memory is exhausted
  692. FieldNames= fieldnames(ActuatorDesired);
  693. for i=1:length(FieldNames) %Grow structure
  694. ActuatorDesired.(FieldNames{i})(:,actuatordesiredIdx*2+1) = 0;
  695. end;
  696. end
  697. case ACTUATORSETTINGS_OBJID
  698. actuatorsettingsIdx = actuatorsettingsIdx + 1;
  699. ActuatorSettings= ReadActuatorSettingsObject(fid, timestamp, checkCRC, ActuatorSettings, actuatorsettingsIdx);
  700. if actuatorsettingsIdx >= length(ActuatorSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  701. FieldNames= fieldnames(ActuatorSettings);
  702. for i=1:length(FieldNames) %Grow structure
  703. ActuatorSettings.(FieldNames{i})(:,actuatorsettingsIdx*2+1) = 0;
  704. end;
  705. end
  706. case ALTHOLDSMOOTHED_OBJID
  707. altholdsmoothedIdx = altholdsmoothedIdx + 1;
  708. AltHoldSmoothed= ReadAltHoldSmoothedObject(fid, timestamp, checkCRC, AltHoldSmoothed, altholdsmoothedIdx);
  709. if altholdsmoothedIdx >= length(AltHoldSmoothed.timestamp) %Check to see if pre-allocated memory is exhausted
  710. FieldNames= fieldnames(AltHoldSmoothed);
  711. for i=1:length(FieldNames) %Grow structure
  712. AltHoldSmoothed.(FieldNames{i})(:,altholdsmoothedIdx*2+1) = 0;
  713. end;
  714. end
  715. case ALTITUDEHOLDDESIRED_OBJID
  716. altitudeholddesiredIdx = altitudeholddesiredIdx + 1;
  717. AltitudeHoldDesired= ReadAltitudeHoldDesiredObject(fid, timestamp, checkCRC, AltitudeHoldDesired, altitudeholddesiredIdx);
  718. if altitudeholddesiredIdx >= length(AltitudeHoldDesired.timestamp) %Check to see if pre-allocated memory is exhausted
  719. FieldNames= fieldnames(AltitudeHoldDesired);
  720. for i=1:length(FieldNames) %Grow structure
  721. AltitudeHoldDesired.(FieldNames{i})(:,altitudeholddesiredIdx*2+1) = 0;
  722. end;
  723. end
  724. case ALTITUDEHOLDSETTINGS_OBJID
  725. altitudeholdsettingsIdx = altitudeholdsettingsIdx + 1;
  726. AltitudeHoldSettings= ReadAltitudeHoldSettingsObject(fid, timestamp, checkCRC, AltitudeHoldSettings, altitudeholdsettingsIdx);
  727. if altitudeholdsettingsIdx >= length(AltitudeHoldSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  728. FieldNames= fieldnames(AltitudeHoldSettings);
  729. for i=1:length(FieldNames) %Grow structure
  730. AltitudeHoldSettings.(FieldNames{i})(:,altitudeholdsettingsIdx*2+1) = 0;
  731. end;
  732. end
  733. case ATTITUDEACTUAL_OBJID
  734. attitudeactualIdx = attitudeactualIdx + 1;
  735. AttitudeActual= ReadAttitudeActualObject(fid, timestamp, checkCRC, AttitudeActual, attitudeactualIdx);
  736. if attitudeactualIdx >= length(AttitudeActual.timestamp) %Check to see if pre-allocated memory is exhausted
  737. FieldNames= fieldnames(AttitudeActual);
  738. for i=1:length(FieldNames) %Grow structure
  739. AttitudeActual.(FieldNames{i})(:,attitudeactualIdx*2+1) = 0;
  740. end;
  741. end
  742. case ATTITUDESETTINGS_OBJID
  743. attitudesettingsIdx = attitudesettingsIdx + 1;
  744. AttitudeSettings= ReadAttitudeSettingsObject(fid, timestamp, checkCRC, AttitudeSettings, attitudesettingsIdx);
  745. if attitudesettingsIdx >= length(AttitudeSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  746. FieldNames= fieldnames(AttitudeSettings);
  747. for i=1:length(FieldNames) %Grow structure
  748. AttitudeSettings.(FieldNames{i})(:,attitudesettingsIdx*2+1) = 0;
  749. end;
  750. end
  751. case BAROALTITUDE_OBJID
  752. baroaltitudeIdx = baroaltitudeIdx + 1;
  753. BaroAltitude= ReadBaroAltitudeObject(fid, timestamp, checkCRC, BaroAltitude, baroaltitudeIdx);
  754. if baroaltitudeIdx >= length(BaroAltitude.timestamp) %Check to see if pre-allocated memory is exhausted
  755. FieldNames= fieldnames(BaroAltitude);
  756. for i=1:length(FieldNames) %Grow structure
  757. BaroAltitude.(FieldNames{i})(:,baroaltitudeIdx*2+1) = 0;
  758. end;
  759. end
  760. case CAMERADESIRED_OBJID
  761. cameradesiredIdx = cameradesiredIdx + 1;
  762. CameraDesired= ReadCameraDesiredObject(fid, timestamp, checkCRC, CameraDesired, cameradesiredIdx);
  763. if cameradesiredIdx >= length(CameraDesired.timestamp) %Check to see if pre-allocated memory is exhausted
  764. FieldNames= fieldnames(CameraDesired);
  765. for i=1:length(FieldNames) %Grow structure
  766. CameraDesired.(FieldNames{i})(:,cameradesiredIdx*2+1) = 0;
  767. end;
  768. end
  769. case CAMERASTABSETTINGS_OBJID
  770. camerastabsettingsIdx = camerastabsettingsIdx + 1;
  771. CameraStabSettings= ReadCameraStabSettingsObject(fid, timestamp, checkCRC, CameraStabSettings, camerastabsettingsIdx);
  772. if camerastabsettingsIdx >= length(CameraStabSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  773. FieldNames= fieldnames(CameraStabSettings);
  774. for i=1:length(FieldNames) %Grow structure
  775. CameraStabSettings.(FieldNames{i})(:,camerastabsettingsIdx*2+1) = 0;
  776. end;
  777. end
  778. case FAULTSETTINGS_OBJID
  779. faultsettingsIdx = faultsettingsIdx + 1;
  780. FaultSettings= ReadFaultSettingsObject(fid, timestamp, checkCRC, FaultSettings, faultsettingsIdx);
  781. if faultsettingsIdx >= length(FaultSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  782. FieldNames= fieldnames(FaultSettings);
  783. for i=1:length(FieldNames) %Grow structure
  784. FaultSettings.(FieldNames{i})(:,faultsettingsIdx*2+1) = 0;
  785. end;
  786. end
  787. case FIRMWAREIAPOBJ_OBJID
  788. firmwareiapobjIdx = firmwareiapobjIdx + 1;
  789. FirmwareIAPObj= ReadFirmwareIAPObjObject(fid, timestamp, checkCRC, FirmwareIAPObj, firmwareiapobjIdx);
  790. if firmwareiapobjIdx >= length(FirmwareIAPObj.timestamp) %Check to see if pre-allocated memory is exhausted
  791. FieldNames= fieldnames(FirmwareIAPObj);
  792. for i=1:length(FieldNames) %Grow structure
  793. FirmwareIAPObj.(FieldNames{i})(:,firmwareiapobjIdx*2+1) = 0;
  794. end;
  795. end
  796. case FLIGHTBATTERYSETTINGS_OBJID
  797. flightbatterysettingsIdx = flightbatterysettingsIdx + 1;
  798. FlightBatterySettings= ReadFlightBatterySettingsObject(fid, timestamp, checkCRC, FlightBatterySettings, flightbatterysettingsIdx);
  799. if flightbatterysettingsIdx >= length(FlightBatterySettings.timestamp) %Check to see if pre-allocated memory is exhausted
  800. FieldNames= fieldnames(FlightBatterySettings);
  801. for i=1:length(FieldNames) %Grow structure
  802. FlightBatterySettings.(FieldNames{i})(:,flightbatterysettingsIdx*2+1) = 0;
  803. end;
  804. end
  805. case FLIGHTBATTERYSTATE_OBJID
  806. flightbatterystateIdx = flightbatterystateIdx + 1;
  807. FlightBatteryState= ReadFlightBatteryStateObject(fid, timestamp, checkCRC, FlightBatteryState, flightbatterystateIdx);
  808. if flightbatterystateIdx >= length(FlightBatteryState.timestamp) %Check to see if pre-allocated memory is exhausted
  809. FieldNames= fieldnames(FlightBatteryState);
  810. for i=1:length(FieldNames) %Grow structure
  811. FlightBatteryState.(FieldNames{i})(:,flightbatterystateIdx*2+1) = 0;
  812. end;
  813. end
  814. case FLIGHTPLANCONTROL_OBJID
  815. flightplancontrolIdx = flightplancontrolIdx + 1;
  816. FlightPlanControl= ReadFlightPlanControlObject(fid, timestamp, checkCRC, FlightPlanControl, flightplancontrolIdx);
  817. if flightplancontrolIdx >= length(FlightPlanControl.timestamp) %Check to see if pre-allocated memory is exhausted
  818. FieldNames= fieldnames(FlightPlanControl);
  819. for i=1:length(FieldNames) %Grow structure
  820. FlightPlanControl.(FieldNames{i})(:,flightplancontrolIdx*2+1) = 0;
  821. end;
  822. end
  823. case FLIGHTPLANSETTINGS_OBJID
  824. flightplansettingsIdx = flightplansettingsIdx + 1;
  825. FlightPlanSettings= ReadFlightPlanSettingsObject(fid, timestamp, checkCRC, FlightPlanSettings, flightplansettingsIdx);
  826. if flightplansettingsIdx >= length(FlightPlanSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  827. FieldNames= fieldnames(FlightPlanSettings);
  828. for i=1:length(FieldNames) %Grow structure
  829. FlightPlanSettings.(FieldNames{i})(:,flightplansettingsIdx*2+1) = 0;
  830. end;
  831. end
  832. case FLIGHTPLANSTATUS_OBJID
  833. flightplanstatusIdx = flightplanstatusIdx + 1;
  834. FlightPlanStatus= ReadFlightPlanStatusObject(fid, timestamp, checkCRC, FlightPlanStatus, flightplanstatusIdx);
  835. if flightplanstatusIdx >= length(FlightPlanStatus.timestamp) %Check to see if pre-allocated memory is exhausted
  836. FieldNames= fieldnames(FlightPlanStatus);
  837. for i=1:length(FieldNames) %Grow structure
  838. FlightPlanStatus.(FieldNames{i})(:,flightplanstatusIdx*2+1) = 0;
  839. end;
  840. end
  841. case FLIGHTSTATUS_OBJID
  842. flightstatusIdx = flightstatusIdx + 1;
  843. FlightStatus= ReadFlightStatusObject(fid, timestamp, checkCRC, FlightStatus, flightstatusIdx);
  844. if flightstatusIdx >= length(FlightStatus.timestamp) %Check to see if pre-allocated memory is exhausted
  845. FieldNames= fieldnames(FlightStatus);
  846. for i=1:length(FieldNames) %Grow structure
  847. FlightStatus.(FieldNames{i})(:,flightstatusIdx*2+1) = 0;
  848. end;
  849. end
  850. case FLIGHTTELEMETRYSTATS_OBJID
  851. flighttelemetrystatsIdx = flighttelemetrystatsIdx + 1;
  852. FlightTelemetryStats= ReadFlightTelemetryStatsObject(fid, timestamp, checkCRC, FlightTelemetryStats, flighttelemetrystatsIdx);
  853. if flighttelemetrystatsIdx >= length(FlightTelemetryStats.timestamp) %Check to see if pre-allocated memory is exhausted
  854. FieldNames= fieldnames(FlightTelemetryStats);
  855. for i=1:length(FieldNames) %Grow structure
  856. FlightTelemetryStats.(FieldNames{i})(:,flighttelemetrystatsIdx*2+1) = 0;
  857. end;
  858. end
  859. case GCSRECEIVER_OBJID
  860. gcsreceiverIdx = gcsreceiverIdx + 1;
  861. GCSReceiver= ReadGCSReceiverObject(fid, timestamp, checkCRC, GCSReceiver, gcsreceiverIdx);
  862. if gcsreceiverIdx >= length(GCSReceiver.timestamp) %Check to see if pre-allocated memory is exhausted
  863. FieldNames= fieldnames(GCSReceiver);
  864. for i=1:length(FieldNames) %Grow structure
  865. GCSReceiver.(FieldNames{i})(:,gcsreceiverIdx*2+1) = 0;
  866. end;
  867. end
  868. case GCSTELEMETRYSTATS_OBJID
  869. gcstelemetrystatsIdx = gcstelemetrystatsIdx + 1;
  870. GCSTelemetryStats= ReadGCSTelemetryStatsObject(fid, timestamp, checkCRC, GCSTelemetryStats, gcstelemetrystatsIdx);
  871. if gcstelemetrystatsIdx >= length(GCSTelemetryStats.timestamp) %Check to see if pre-allocated memory is exhausted
  872. FieldNames= fieldnames(GCSTelemetryStats);
  873. for i=1:length(FieldNames) %Grow structure
  874. GCSTelemetryStats.(FieldNames{i})(:,gcstelemetrystatsIdx*2+1) = 0;
  875. end;
  876. end
  877. case GPSPOSITION_OBJID
  878. gpspositionIdx = gpspositionIdx + 1;
  879. GPSPosition= ReadGPSPositionObject(fid, timestamp, checkCRC, GPSPosition, gpspositionIdx);
  880. if gpspositionIdx >= length(GPSPosition.timestamp) %Check to see if pre-allocated memory is exhausted
  881. FieldNames= fieldnames(GPSPosition);
  882. for i=1:length(FieldNames) %Grow structure
  883. GPSPosition.(FieldNames{i})(:,gpspositionIdx*2+1) = 0;
  884. end;
  885. end
  886. case GPSSATELLITES_OBJID
  887. gpssatellitesIdx = gpssatellitesIdx + 1;
  888. GPSSatellites= ReadGPSSatellitesObject(fid, timestamp, checkCRC, GPSSatellites, gpssatellitesIdx);
  889. if gpssatellitesIdx >= length(GPSSatellites.timestamp) %Check to see if pre-allocated memory is exhausted
  890. FieldNames= fieldnames(GPSSatellites);
  891. for i=1:length(FieldNames) %Grow structure
  892. GPSSatellites.(FieldNames{i})(:,gpssatellitesIdx*2+1) = 0;
  893. end;
  894. end
  895. case GPSTIME_OBJID
  896. gpstimeIdx = gpstimeIdx + 1;
  897. GPSTime= ReadGPSTimeObject(fid, timestamp, checkCRC, GPSTime, gpstimeIdx);
  898. if gpstimeIdx >= length(GPSTime.timestamp) %Check to see if pre-allocated memory is exhausted
  899. FieldNames= fieldnames(GPSTime);
  900. for i=1:length(FieldNames) %Grow structure
  901. GPSTime.(FieldNames{i})(:,gpstimeIdx*2+1) = 0;
  902. end;
  903. end
  904. case GUIDANCESETTINGS_OBJID
  905. guidancesettingsIdx = guidancesettingsIdx + 1;
  906. GuidanceSettings= ReadGuidanceSettingsObject(fid, timestamp, checkCRC, GuidanceSettings, guidancesettingsIdx);
  907. if guidancesettingsIdx >= length(GuidanceSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  908. FieldNames= fieldnames(GuidanceSettings);
  909. for i=1:length(FieldNames) %Grow structure
  910. GuidanceSettings.(FieldNames{i})(:,guidancesettingsIdx*2+1) = 0;
  911. end;
  912. end
  913. case GYROS_OBJID
  914. gyrosIdx = gyrosIdx + 1;
  915. Gyros= ReadGyrosObject(fid, timestamp, checkCRC, Gyros, gyrosIdx);
  916. if gyrosIdx >= length(Gyros.timestamp) %Check to see if pre-allocated memory is exhausted
  917. FieldNames= fieldnames(Gyros);
  918. for i=1:length(FieldNames) %Grow structure
  919. Gyros.(FieldNames{i})(:,gyrosIdx*2+1) = 0;
  920. end;
  921. end
  922. case GYROSBIAS_OBJID
  923. gyrosbiasIdx = gyrosbiasIdx + 1;
  924. GyrosBias= ReadGyrosBiasObject(fid, timestamp, checkCRC, GyrosBias, gyrosbiasIdx);
  925. if gyrosbiasIdx >= length(GyrosBias.timestamp) %Check to see if pre-allocated memory is exhausted
  926. FieldNames= fieldnames(GyrosBias);
  927. for i=1:length(FieldNames) %Grow structure
  928. GyrosBias.(FieldNames{i})(:,gyrosbiasIdx*2+1) = 0;
  929. end;
  930. end
  931. case HOMELOCATION_OBJID
  932. homelocationIdx = homelocationIdx + 1;
  933. HomeLocation= ReadHomeLocationObject(fid, timestamp, checkCRC, HomeLocation, homelocationIdx);
  934. if homelocationIdx >= length(HomeLocation.timestamp) %Check to see if pre-allocated memory is exhausted
  935. FieldNames= fieldnames(HomeLocation);
  936. for i=1:length(FieldNames) %Grow structure
  937. HomeLocation.(FieldNames{i})(:,homelocationIdx*2+1) = 0;
  938. end;
  939. end
  940. case HWSETTINGS_OBJID
  941. hwsettingsIdx = hwsettingsIdx + 1;
  942. HwSettings= ReadHwSettingsObject(fid, timestamp, checkCRC, HwSettings, hwsettingsIdx);
  943. if hwsettingsIdx >= length(HwSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  944. FieldNames= fieldnames(HwSettings);
  945. for i=1:length(FieldNames) %Grow structure
  946. HwSettings.(FieldNames{i})(:,hwsettingsIdx*2+1) = 0;
  947. end;
  948. end
  949. case I2CSTATS_OBJID
  950. i2cstatsIdx = i2cstatsIdx + 1;
  951. I2CStats= ReadI2CStatsObject(fid, timestamp, checkCRC, I2CStats, i2cstatsIdx);
  952. if i2cstatsIdx >= length(I2CStats.timestamp) %Check to see if pre-allocated memory is exhausted
  953. FieldNames= fieldnames(I2CStats);
  954. for i=1:length(FieldNames) %Grow structure
  955. I2CStats.(FieldNames{i})(:,i2cstatsIdx*2+1) = 0;
  956. end;
  957. end
  958. case MAGNETOMETER_OBJID
  959. magnetometerIdx = magnetometerIdx + 1;
  960. Magnetometer= ReadMagnetometerObject(fid, timestamp, checkCRC, Magnetometer, magnetometerIdx);
  961. if magnetometerIdx >= length(Magnetometer.timestamp) %Check to see if pre-allocated memory is exhausted
  962. FieldNames= fieldnames(Magnetometer);
  963. for i=1:length(FieldNames) %Grow structure
  964. Magnetometer.(FieldNames{i})(:,magnetometerIdx*2+1) = 0;
  965. end;
  966. end
  967. case MANUALCONTROLCOMMAND_OBJID
  968. manualcontrolcommandIdx = manualcontrolcommandIdx + 1;
  969. ManualControlCommand= ReadManualControlCommandObject(fid, timestamp, checkCRC, ManualControlCommand, manualcontrolcommandIdx);
  970. if manualcontrolcommandIdx >= length(ManualControlCommand.timestamp) %Check to see if pre-allocated memory is exhausted
  971. FieldNames= fieldnames(ManualControlCommand);
  972. for i=1:length(FieldNames) %Grow structure
  973. ManualControlCommand.(FieldNames{i})(:,manualcontrolcommandIdx*2+1) = 0;
  974. end;
  975. end
  976. case MANUALCONTROLSETTINGS_OBJID
  977. manualcontrolsettingsIdx = manualcontrolsettingsIdx + 1;
  978. ManualControlSettings= ReadManualControlSettingsObject(fid, timestamp, checkCRC, ManualControlSettings, manualcontrolsettingsIdx);
  979. if manualcontrolsettingsIdx >= length(ManualControlSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  980. FieldNames= fieldnames(ManualControlSettings);
  981. for i=1:length(FieldNames) %Grow structure
  982. ManualControlSettings.(FieldNames{i})(:,manualcontrolsettingsIdx*2+1) = 0;
  983. end;
  984. end
  985. case MIXERSETTINGS_OBJID
  986. mixersettingsIdx = mixersettingsIdx + 1;
  987. MixerSettings= ReadMixerSettingsObject(fid, timestamp, checkCRC, MixerSettings, mixersettingsIdx);
  988. if mixersettingsIdx >= length(MixerSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  989. FieldNames= fieldnames(MixerSettings);
  990. for i=1:length(FieldNames) %Grow structure
  991. MixerSettings.(FieldNames{i})(:,mixersettingsIdx*2+1) = 0;
  992. end;
  993. end
  994. case MIXERSTATUS_OBJID
  995. mixerstatusIdx = mixerstatusIdx + 1;
  996. MixerStatus= ReadMixerStatusObject(fid, timestamp, checkCRC, MixerStatus, mixerstatusIdx);
  997. if mixerstatusIdx >= length(MixerStatus.timestamp) %Check to see if pre-allocated memory is exhausted
  998. FieldNames= fieldnames(MixerStatus);
  999. for i=1:length(FieldNames) %Grow structure
  1000. MixerStatus.(FieldNames{i})(:,mixerstatusIdx*2+1) = 0;
  1001. end;
  1002. end
  1003. case NEDACCEL_OBJID
  1004. nedaccelIdx = nedaccelIdx + 1;
  1005. NedAccel= ReadNedAccelObject(fid, timestamp, checkCRC, NedAccel, nedaccelIdx);
  1006. if nedaccelIdx >= length(NedAccel.timestamp) %Check to see if pre-allocated memory is exhausted
  1007. FieldNames= fieldnames(NedAccel);
  1008. for i=1:length(FieldNames) %Grow structure
  1009. NedAccel.(FieldNames{i})(:,nedaccelIdx*2+1) = 0;
  1010. end;
  1011. end
  1012. case OBJECTPERSISTENCE_OBJID
  1013. objectpersistenceIdx = objectpersistenceIdx + 1;
  1014. ObjectPersistence= ReadObjectPersistenceObject(fid, timestamp, checkCRC, ObjectPersistence, objectpersistenceIdx);
  1015. if objectpersistenceIdx >= length(ObjectPersistence.timestamp) %Check to see if pre-allocated memory is exhausted
  1016. FieldNames= fieldnames(ObjectPersistence);
  1017. for i=1:length(FieldNames) %Grow structure
  1018. ObjectPersistence.(FieldNames{i})(:,objectpersistenceIdx*2+1) = 0;
  1019. end;
  1020. end
  1021. case OVEROSYNCSTATS_OBJID
  1022. overosyncstatsIdx = overosyncstatsIdx + 1;
  1023. OveroSyncStats= ReadOveroSyncStatsObject(fid, timestamp, checkCRC, OveroSyncStats, overosyncstatsIdx);
  1024. if overosyncstatsIdx >= length(OveroSyncStats.timestamp) %Check to see if pre-allocated memory is exhausted
  1025. FieldNames= fieldnames(OveroSyncStats);
  1026. for i=1:length(FieldNames) %Grow structure
  1027. OveroSyncStats.(FieldNames{i})(:,overosyncstatsIdx*2+1) = 0;
  1028. end;
  1029. end
  1030. case POSITIONACTUAL_OBJID
  1031. positionactualIdx = positionactualIdx + 1;
  1032. PositionActual= ReadPositionActualObject(fid, timestamp, checkCRC, PositionActual, positionactualIdx);
  1033. if positionactualIdx >= length(PositionActual.timestamp) %Check to see if pre-allocated memory is exhausted
  1034. FieldNames= fieldnames(PositionActual);
  1035. for i=1:length(FieldNames) %Grow structure
  1036. PositionActual.(FieldNames{i})(:,positionactualIdx*2+1) = 0;
  1037. end;
  1038. end
  1039. case POSITIONDESIRED_OBJID
  1040. positiondesiredIdx = positiondesiredIdx + 1;
  1041. PositionDesired= ReadPositionDesiredObject(fid, timestamp, checkCRC, PositionDesired, positiondesiredIdx);
  1042. if positiondesiredIdx >= length(PositionDesired.timestamp) %Check to see if pre-allocated memory is exhausted
  1043. FieldNames= fieldnames(PositionDesired);
  1044. for i=1:length(FieldNames) %Grow structure
  1045. PositionDesired.(FieldNames{i})(:,positiondesiredIdx*2+1) = 0;
  1046. end;
  1047. end
  1048. case RATEDESIRED_OBJID
  1049. ratedesiredIdx = ratedesiredIdx + 1;
  1050. RateDesired= ReadRateDesiredObject(fid, timestamp, checkCRC, RateDesired, ratedesiredIdx);
  1051. if ratedesiredIdx >= length(RateDesired.timestamp) %Check to see if pre-allocated memory is exhausted
  1052. FieldNames= fieldnames(RateDesired);
  1053. for i=1:length(FieldNames) %Grow structure
  1054. RateDesired.(FieldNames{i})(:,ratedesiredIdx*2+1) = 0;
  1055. end;
  1056. end
  1057. case RECEIVERACTIVITY_OBJID
  1058. receiveractivityIdx = receiveractivityIdx + 1;
  1059. ReceiverActivity= ReadReceiverActivityObject(fid, timestamp, checkCRC, ReceiverActivity, receiveractivityIdx);
  1060. if receiveractivityIdx >= length(ReceiverActivity.timestamp) %Check to see if pre-allocated memory is exhausted
  1061. FieldNames= fieldnames(ReceiverActivity);
  1062. for i=1:length(FieldNames) %Grow structure
  1063. ReceiverActivity.(FieldNames{i})(:,receiveractivityIdx*2+1) = 0;
  1064. end;
  1065. end
  1066. case REVOCALIBRATION_OBJID
  1067. revocalibrationIdx = revocalibrationIdx + 1;
  1068. RevoCalibration= ReadRevoCalibrationObject(fid, timestamp, checkCRC, RevoCalibration, revocalibrationIdx);
  1069. if revocalibrationIdx >= length(RevoCalibration.timestamp) %Check to see if pre-allocated memory is exhausted
  1070. FieldNames= fieldnames(RevoCalibration);
  1071. for i=1:length(FieldNames) %Grow structure
  1072. RevoCalibration.(FieldNames{i})(:,revocalibrationIdx*2+1) = 0;
  1073. end;
  1074. end
  1075. case SONARALTITUDE_OBJID
  1076. sonaraltitudeIdx = sonaraltitudeIdx + 1;
  1077. SonarAltitude= ReadSonarAltitudeObject(fid, timestamp, checkCRC, SonarAltitude, sonaraltitudeIdx);
  1078. if sonaraltitudeIdx >= length(SonarAltitude.timestamp) %Check to see if pre-allocated memory is exhausted
  1079. FieldNames= fieldnames(SonarAltitude);
  1080. for i=1:length(FieldNames) %Grow structure
  1081. SonarAltitude.(FieldNames{i})(:,sonaraltitudeIdx*2+1) = 0;
  1082. end;
  1083. end
  1084. case STABILIZATIONDESIRED_OBJID
  1085. stabilizationdesiredIdx = stabilizationdesiredIdx + 1;
  1086. StabilizationDesired= ReadStabilizationDesiredObject(fid, timestamp, checkCRC, StabilizationDesired, stabilizationdesiredIdx);
  1087. if stabilizationdesiredIdx >= length(StabilizationDesired.timestamp) %Check to see if pre-allocated memory is exhausted
  1088. FieldNames= fieldnames(StabilizationDesired);
  1089. for i=1:length(FieldNames) %Grow structure
  1090. StabilizationDesired.(FieldNames{i})(:,stabilizationdesiredIdx*2+1) = 0;
  1091. end;
  1092. end
  1093. case STABILIZATIONSETTINGS_OBJID
  1094. stabilizationsettingsIdx = stabilizationsettingsIdx + 1;
  1095. StabilizationSettings= ReadStabilizationSettingsObject(fid, timestamp, checkCRC, StabilizationSettings, stabilizationsettingsIdx);
  1096. if stabilizationsettingsIdx >= length(StabilizationSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  1097. FieldNames= fieldnames(StabilizationSettings);
  1098. for i=1:length(FieldNames) %Grow structure
  1099. StabilizationSettings.(FieldNames{i})(:,stabilizationsettingsIdx*2+1) = 0;
  1100. end;
  1101. end
  1102. case SYSTEMALARMS_OBJID
  1103. systemalarmsIdx = systemalarmsIdx + 1;
  1104. SystemAlarms= ReadSystemAlarmsObject(fid, timestamp, checkCRC, SystemAlarms, systemalarmsIdx);
  1105. if systemalarmsIdx >= length(SystemAlarms.timestamp) %Check to see if pre-allocated memory is exhausted
  1106. FieldNames= fieldnames(SystemAlarms);
  1107. for i=1:length(FieldNames) %Grow structure
  1108. SystemAlarms.(FieldNames{i})(:,systemalarmsIdx*2+1) = 0;
  1109. end;
  1110. end
  1111. case SYSTEMSETTINGS_OBJID
  1112. systemsettingsIdx = systemsettingsIdx + 1;
  1113. SystemSettings= ReadSystemSettingsObject(fid, timestamp, checkCRC, SystemSettings, systemsettingsIdx);
  1114. if systemsettingsIdx >= length(SystemSettings.timestamp) %Check to see if pre-allocated memory is exhausted
  1115. FieldNames= fieldnames(SystemSettings);
  1116. for i=1:length(FieldNames) %Grow structure
  1117. SystemSettings.(FieldNames{i})(:,systemsettingsIdx*2+1) = 0;
  1118. end;
  1119. end
  1120. case SYSTEMSTATS_OBJID
  1121. systemstatsIdx = systemstatsIdx + 1;
  1122. SystemStats= ReadSystemStatsObject(fid, timestamp, checkCRC, SystemStats, systemstatsIdx);
  1123. if systemstatsIdx >= length(SystemStats.timestamp) %Check to see if pre-allocated memory is exhausted
  1124. FieldNames= fieldnames(SystemStats);
  1125. for i=1:length(FieldNames) %Grow structure
  1126. SystemStats.(FieldNames{i})(:,systemstatsIdx*2+1) = 0;
  1127. end;
  1128. end
  1129. case TASKINFO_OBJID
  1130. taskinfoIdx = taskinfoIdx + 1;
  1131. TaskInfo= ReadTaskInfoObject(fid, timestamp, checkCRC, TaskInfo, taskinfoIdx);
  1132. if taskinfoIdx >= length(TaskInfo.timestamp) %Check to see if pre-allocated memory is exhausted
  1133. FieldNames= fieldnames(TaskInfo);
  1134. for i=1:length(FieldNames) %Grow structure
  1135. TaskInfo.(FieldNames{i})(:,taskinfoIdx*2+1) = 0;
  1136. end;
  1137. end
  1138. case VELOCITYACTUAL_OBJID
  1139. velocityactualIdx = velocityactualIdx + 1;
  1140. VelocityActual= ReadVelocityActualObject(fid, timestamp, checkCRC, VelocityActual, velocityactualIdx);
  1141. if velocityactualIdx >= length(VelocityActual.timestamp) %Check to see if pre-allocated memory is exhausted
  1142. FieldNames= fieldnames(VelocityActual);
  1143. for i=1:length(FieldNames) %Grow structure
  1144. VelocityActual.(FieldNames{i})(:,velocityactualIdx*2+1) = 0;
  1145. end;
  1146. end
  1147. case VELOCITYDESIRED_OBJID
  1148. velocitydesiredIdx = velocitydesiredIdx + 1;
  1149. VelocityDesired= ReadVelocityDesiredObject(fid, timestamp, checkCRC, VelocityDesired, velocitydesiredIdx);
  1150. if velocitydesiredIdx >= length(VelocityDesired.timestamp) %Check to see if pre-allocated memory is exhausted
  1151. FieldNames= fieldnames(VelocityDesired);
  1152. for i=1:length(FieldNames) %Grow structure
  1153. VelocityDesired.(FieldNames{i})(:,velocitydesiredIdx*2+1) = 0;
  1154. end;
  1155. end
  1156. case WATCHDOGSTATUS_OBJID
  1157. watchdogstatusIdx = watchdogstatusIdx + 1;
  1158. WatchdogStatus= ReadWatchdogStatusObject(fid, timestamp, checkCRC, WatchdogStatus, watchdogstatusIdx);
  1159. if watchdogstatusIdx >= length(WatchdogStatus.timestamp) %Check to see if pre-allocated memory is exhausted
  1160. FieldNames= fieldnames(WatchdogStatus);
  1161. for i=1:length(FieldNames) %Grow structure
  1162. WatchdogStatus.(FieldNames{i})(:,watchdogstatusIdx*2+1) = 0;
  1163. end;
  1164. end
  1165.  
  1166. otherwise
  1167. % disp(['Unknown object ID: 0x' dec2hex(objID)]);
  1168. msgBytesLeft = datasize - 1 - 1 - 2 - 4;
  1169. if msgBytesLeft > 255
  1170. msgBytesLeft = 0;
  1171. end
  1172. fread(fid, msgBytesLeft, 'uint8');
  1173. end
  1174. catch ME %#ok<NASGU>
  1175. % One of the reads failed - indicates EOF
  1176. break;
  1177. end
  1178.  
  1179. if 1 && (wrongSyncByte ~= lastWrongSyncByte || wrongMessageByte~=lastWrongMessageByte ) ||...
  1180. (ftell(fid) / log_size - last_print) > 0.01
  1181.  
  1182. lastWrongSyncByte=wrongSyncByte;
  1183. lastWrongMessageByte=wrongMessageByte;
  1184.  
  1185. str1=[];
  1186. for i=1:length([str2 str3 str4 str5]);
  1187. str1=[str1 sprintf('\b')];
  1188. end
  1189. str2=sprintf('wrongSyncByte instances: % 10d\n', wrongSyncByte );
  1190. str3=sprintf('wrongMessageByte instances: % 10d\n\n', wrongMessageByte );
  1191.  
  1192. str4=sprintf('Completed bytes: % 9d of % 9d\n', ftell(fid), log_size);
  1193.  
  1194.  
  1195. estTimeRemaining=(log_size-ftell(fid))/(ftell(fid)/etime(clock,startTime));
  1196. h=floor(estTimeRemaining/3600);
  1197. m=floor((estTimeRemaining-h*3600)/60);
  1198. s=ceil(estTimeRemaining-h*3600-m*60);
  1199.  
  1200. str5=sprintf('Est. time remaining, %02dh:%02dm:%02ds \n', h,m,s);
  1201.  
  1202. last_print = ftell(fid) / log_size;
  1203.  
  1204. fprintf([str1 str2 str3 str4 str5]);
  1205.  
  1206. % if etime(clock,startTime) > 5
  1207. % break;
  1208. % end
  1209.  
  1210. % else
  1211. % toc
  1212. % tic
  1213. end
  1214.  
  1215.  
  1216.  
  1217.  
  1218. prebuf = fread(fid, 12, 'uint8');
  1219. end
  1220.  
  1221. fprintf('%d records in %0.2f seconds.\n', ftell(fid), etime(clock,startTime))
  1222.  
  1223. %% Clean Up and Save mat file
  1224. fclose(fid);
  1225.  
  1226. % Trim output structs
  1227. Accels=PruneStructOfArrays(Accels,accelsIdx);
  1228. AccessoryDesired=PruneStructOfArrays(AccessoryDesired,accessorydesiredIdx);
  1229. ActuatorCommand=PruneStructOfArrays(ActuatorCommand,actuatorcommandIdx);
  1230. ActuatorDesired=PruneStructOfArrays(ActuatorDesired,actuatordesiredIdx);
  1231. ActuatorSettings=PruneStructOfArrays(ActuatorSettings,actuatorsettingsIdx);
  1232. AltHoldSmoothed=PruneStructOfArrays(AltHoldSmoothed,altholdsmoothedIdx);
  1233. AltitudeHoldDesired=PruneStructOfArrays(AltitudeHoldDesired,altitudeholddesiredIdx);
  1234. AltitudeHoldSettings=PruneStructOfArrays(AltitudeHoldSettings,altitudeholdsettingsIdx);
  1235. AttitudeActual=PruneStructOfArrays(AttitudeActual,attitudeactualIdx);
  1236. AttitudeSettings=PruneStructOfArrays(AttitudeSettings,attitudesettingsIdx);
  1237. BaroAltitude=PruneStructOfArrays(BaroAltitude,baroaltitudeIdx);
  1238. CameraDesired=PruneStructOfArrays(CameraDesired,cameradesiredIdx);
  1239. CameraStabSettings=PruneStructOfArrays(CameraStabSettings,camerastabsettingsIdx);
  1240. FaultSettings=PruneStructOfArrays(FaultSettings,faultsettingsIdx);
  1241. FirmwareIAPObj=PruneStructOfArrays(FirmwareIAPObj,firmwareiapobjIdx);
  1242. FlightBatterySettings=PruneStructOfArrays(FlightBatterySettings,flightbatterysettingsIdx);
  1243. FlightBatteryState=PruneStructOfArrays(FlightBatteryState,flightbatterystateIdx);
  1244. FlightPlanControl=PruneStructOfArrays(FlightPlanControl,flightplancontrolIdx);
  1245. FlightPlanSettings=PruneStructOfArrays(FlightPlanSettings,flightplansettingsIdx);
  1246. FlightPlanStatus=PruneStructOfArrays(FlightPlanStatus,flightplanstatusIdx);
  1247. FlightStatus=PruneStructOfArrays(FlightStatus,flightstatusIdx);
  1248. FlightTelemetryStats=PruneStructOfArrays(FlightTelemetryStats,flighttelemetrystatsIdx);
  1249. GCSReceiver=PruneStructOfArrays(GCSReceiver,gcsreceiverIdx);
  1250. GCSTelemetryStats=PruneStructOfArrays(GCSTelemetryStats,gcstelemetrystatsIdx);
  1251. GPSPosition=PruneStructOfArrays(GPSPosition,gpspositionIdx);
  1252. GPSSatellites=PruneStructOfArrays(GPSSatellites,gpssatellitesIdx);
  1253. GPSTime=PruneStructOfArrays(GPSTime,gpstimeIdx);
  1254. GuidanceSettings=PruneStructOfArrays(GuidanceSettings,guidancesettingsIdx);
  1255. Gyros=PruneStructOfArrays(Gyros,gyrosIdx);
  1256. GyrosBias=PruneStructOfArrays(GyrosBias,gyrosbiasIdx);
  1257. HomeLocation=PruneStructOfArrays(HomeLocation,homelocationIdx);
  1258. HwSettings=PruneStructOfArrays(HwSettings,hwsettingsIdx);
  1259. I2CStats=PruneStructOfArrays(I2CStats,i2cstatsIdx);
  1260. Magnetometer=PruneStructOfArrays(Magnetometer,magnetometerIdx);
  1261. ManualControlCommand=PruneStructOfArrays(ManualControlCommand,manualcontrolcommandIdx);
  1262. ManualControlSettings=PruneStructOfArrays(ManualControlSettings,manualcontrolsettingsIdx);
  1263. MixerSettings=PruneStructOfArrays(MixerSettings,mixersettingsIdx);
  1264. MixerStatus=PruneStructOfArrays(MixerStatus,mixerstatusIdx);
  1265. NedAccel=PruneStructOfArrays(NedAccel,nedaccelIdx);
  1266. ObjectPersistence=PruneStructOfArrays(ObjectPersistence,objectpersistenceIdx);
  1267. OveroSyncStats=PruneStructOfArrays(OveroSyncStats,overosyncstatsIdx);
  1268. PositionActual=PruneStructOfArrays(PositionActual,positionactualIdx);
  1269. PositionDesired=PruneStructOfArrays(PositionDesired,positiondesiredIdx);
  1270. RateDesired=PruneStructOfArrays(RateDesired,ratedesiredIdx);
  1271. ReceiverActivity=PruneStructOfArrays(ReceiverActivity,receiveractivityIdx);
  1272. RevoCalibration=PruneStructOfArrays(RevoCalibration,revocalibrationIdx);
  1273. SonarAltitude=PruneStructOfArrays(SonarAltitude,sonaraltitudeIdx);
  1274. StabilizationDesired=PruneStructOfArrays(StabilizationDesired,stabilizationdesiredIdx);
  1275. StabilizationSettings=PruneStructOfArrays(StabilizationSettings,stabilizationsettingsIdx);
  1276. SystemAlarms=PruneStructOfArrays(SystemAlarms,systemalarmsIdx);
  1277. SystemSettings=PruneStructOfArrays(SystemSettings,systemsettingsIdx);
  1278. SystemStats=PruneStructOfArrays(SystemStats,systemstatsIdx);
  1279. TaskInfo=PruneStructOfArrays(TaskInfo,taskinfoIdx);
  1280. VelocityActual=PruneStructOfArrays(VelocityActual,velocityactualIdx);
  1281. VelocityDesired=PruneStructOfArrays(VelocityDesired,velocitydesiredIdx);
  1282. WatchdogStatus=PruneStructOfArrays(WatchdogStatus,watchdogstatusIdx);
  1283.  
  1284.  
  1285. if strcmpi(outputType,'mat')
  1286. matfile = strrep(logfile,'opl','mat');
  1287. save(matfile ,'Accels','AccessoryDesired','ActuatorCommand','ActuatorDesired','ActuatorSettings','AltHoldSmoothed','AltitudeHoldDesired','AltitudeHoldSettings','AttitudeActual','AttitudeSettings','BaroAltitude','CameraDesired','CameraStabSettings','FaultSettings','FirmwareIAPObj','FlightBatterySettings','FlightBatteryState','FlightPlanControl','FlightPlanSettings','FlightPlanStatus','FlightStatus','FlightTelemetryStats','GCSReceiver','GCSTelemetryStats','GPSPosition','GPSSatellites','GPSTime','GuidanceSettings','Gyros','GyrosBias','HomeLocation','HwSettings','I2CStats','Magnetometer','ManualControlCommand','ManualControlSettings','MixerSettings','MixerStatus','NedAccel','ObjectPersistence','OveroSyncStats','PositionActual','PositionDesired','RateDesired','ReceiverActivity','RevoCalibration','SonarAltitude','StabilizationDesired','StabilizationSettings','SystemAlarms','SystemSettings','SystemStats','TaskInfo','VelocityActual','VelocityDesired','WatchdogStatus');
  1288. else
  1289. OPLog2csv(Accels, 'Accels', logfile);
  1290. OPLog2csv(AccessoryDesired, 'AccessoryDesired', logfile);
  1291. OPLog2csv(ActuatorCommand, 'ActuatorCommand', logfile);
  1292. OPLog2csv(ActuatorDesired, 'ActuatorDesired', logfile);
  1293. OPLog2csv(ActuatorSettings, 'ActuatorSettings', logfile);
  1294. OPLog2csv(AltHoldSmoothed, 'AltHoldSmoothed', logfile);
  1295. OPLog2csv(AltitudeHoldDesired, 'AltitudeHoldDesired', logfile);
  1296. OPLog2csv(AltitudeHoldSettings, 'AltitudeHoldSettings', logfile);
  1297. OPLog2csv(AttitudeActual, 'AttitudeActual', logfile);
  1298. OPLog2csv(AttitudeSettings, 'AttitudeSettings', logfile);
  1299. OPLog2csv(BaroAltitude, 'BaroAltitude', logfile);
  1300. OPLog2csv(CameraDesired, 'CameraDesired', logfile);
  1301. OPLog2csv(CameraStabSettings, 'CameraStabSettings', logfile);
  1302. OPLog2csv(FaultSettings, 'FaultSettings', logfile);
  1303. OPLog2csv(FirmwareIAPObj, 'FirmwareIAPObj', logfile);
  1304. OPLog2csv(FlightBatterySettings, 'FlightBatterySettings', logfile);
  1305. OPLog2csv(FlightBatteryState, 'FlightBatteryState', logfile);
  1306. OPLog2csv(FlightPlanControl, 'FlightPlanControl', logfile);
  1307. OPLog2csv(FlightPlanSettings, 'FlightPlanSettings', logfile);
  1308. OPLog2csv(FlightPlanStatus, 'FlightPlanStatus', logfile);
  1309. OPLog2csv(FlightStatus, 'FlightStatus', logfile);
  1310. OPLog2csv(FlightTelemetryStats, 'FlightTelemetryStats', logfile);
  1311. OPLog2csv(GCSReceiver, 'GCSReceiver', logfile);
  1312. OPLog2csv(GCSTelemetryStats, 'GCSTelemetryStats', logfile);
  1313. OPLog2csv(GPSPosition, 'GPSPosition', logfile);
  1314. OPLog2csv(GPSSatellites, 'GPSSatellites', logfile);
  1315. OPLog2csv(GPSTime, 'GPSTime', logfile);
  1316. OPLog2csv(GuidanceSettings, 'GuidanceSettings', logfile);
  1317. OPLog2csv(Gyros, 'Gyros', logfile);
  1318. OPLog2csv(GyrosBias, 'GyrosBias', logfile);
  1319. OPLog2csv(HomeLocation, 'HomeLocation', logfile);
  1320. OPLog2csv(HwSettings, 'HwSettings', logfile);
  1321. OPLog2csv(I2CStats, 'I2CStats', logfile);
  1322. OPLog2csv(Magnetometer, 'Magnetometer', logfile);
  1323. OPLog2csv(ManualControlCommand, 'ManualControlCommand', logfile);
  1324. OPLog2csv(ManualControlSettings, 'ManualControlSettings', logfile);
  1325. OPLog2csv(MixerSettings, 'MixerSettings', logfile);
  1326. OPLog2csv(MixerStatus, 'MixerStatus', logfile);
  1327. OPLog2csv(NedAccel, 'NedAccel', logfile);
  1328. OPLog2csv(ObjectPersistence, 'ObjectPersistence', logfile);
  1329. OPLog2csv(OveroSyncStats, 'OveroSyncStats', logfile);
  1330. OPLog2csv(PositionActual, 'PositionActual', logfile);
  1331. OPLog2csv(PositionDesired, 'PositionDesired', logfile);
  1332. OPLog2csv(RateDesired, 'RateDesired', logfile);
  1333. OPLog2csv(ReceiverActivity, 'ReceiverActivity', logfile);
  1334. OPLog2csv(RevoCalibration, 'RevoCalibration', logfile);
  1335. OPLog2csv(SonarAltitude, 'SonarAltitude', logfile);
  1336. OPLog2csv(StabilizationDesired, 'StabilizationDesired', logfile);
  1337. OPLog2csv(StabilizationSettings, 'StabilizationSettings', logfile);
  1338. OPLog2csv(SystemAlarms, 'SystemAlarms', logfile);
  1339. OPLog2csv(SystemSettings, 'SystemSettings', logfile);
  1340. OPLog2csv(SystemStats, 'SystemStats', logfile);
  1341. OPLog2csv(TaskInfo, 'TaskInfo', logfile);
  1342. OPLog2csv(VelocityActual, 'VelocityActual', logfile);
  1343. OPLog2csv(VelocityDesired, 'VelocityDesired', logfile);
  1344. OPLog2csv(WatchdogStatus, 'WatchdogStatus', logfile);
  1345. end
  1346.  
  1347.  
  1348.  
  1349. %% Object reading functions
  1350. %%
  1351. % Accels read function
  1352. function [Accels] = ReadAccelsObject(fid, timestamp, checkCRC, Accels, accelsIdx)
  1353. Accels.timestamp(accelsIdx)= timestamp;
  1354. if 1
  1355. headerSize = 8;
  1356. else
  1357. Accels.instanceID(accelsIdx) = (fread(fid, 1, 'uint16'));
  1358. headerSize = 10;
  1359. end
  1360.  
  1361. startPos = ftell(fid) - headerSize;
  1362. Accels.x(accelsIdx) = double(fread(fid, 1, 'float32'));
  1363. Accels.y(accelsIdx) = double(fread(fid, 1, 'float32'));
  1364. Accels.z(accelsIdx) = double(fread(fid, 1, 'float32'));
  1365. Accels.temperature(accelsIdx) = double(fread(fid, 1, 'float32'));
  1366. objLen = ftell(fid) - startPos;
  1367. % read CRC
  1368. crc_read = fread(fid, 1, '*uint8');
  1369. if checkCRC
  1370. fseek(fid, startPos, 'bof');
  1371. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1372. fread(fid,1,'uint8');
  1373. if (crc_calc ~= crc_read)
  1374. disp('CRC Error')
  1375. accelsIdx = accelsIdx - 1;
  1376. end
  1377. end
  1378.  
  1379.  
  1380. %%
  1381. % AccessoryDesired read function
  1382. function [AccessoryDesired] = ReadAccessoryDesiredObject(fid, timestamp, checkCRC, AccessoryDesired, accessorydesiredIdx)
  1383. AccessoryDesired.timestamp(accessorydesiredIdx)= timestamp;
  1384. if 0
  1385. headerSize = 8;
  1386. else
  1387. AccessoryDesired.instanceID(accessorydesiredIdx) = (fread(fid, 1, 'uint16'));
  1388. headerSize = 10;
  1389. end
  1390.  
  1391. startPos = ftell(fid) - headerSize;
  1392. AccessoryDesired.AccessoryVal(accessorydesiredIdx) = double(fread(fid, 1, 'float32'));
  1393. objLen = ftell(fid) - startPos;
  1394. % read CRC
  1395. crc_read = fread(fid, 1, '*uint8');
  1396. if checkCRC
  1397. fseek(fid, startPos, 'bof');
  1398. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1399. fread(fid,1,'uint8');
  1400. if (crc_calc ~= crc_read)
  1401. disp('CRC Error')
  1402. accessorydesiredIdx = accessorydesiredIdx - 1;
  1403. end
  1404. end
  1405.  
  1406.  
  1407. %%
  1408. % ActuatorCommand read function
  1409. function [ActuatorCommand] = ReadActuatorCommandObject(fid, timestamp, checkCRC, ActuatorCommand, actuatorcommandIdx)
  1410. ActuatorCommand.timestamp(actuatorcommandIdx)= timestamp;
  1411. if 1
  1412. headerSize = 8;
  1413. else
  1414. ActuatorCommand.instanceID(actuatorcommandIdx) = (fread(fid, 1, 'uint16'));
  1415. headerSize = 10;
  1416. end
  1417.  
  1418. startPos = ftell(fid) - headerSize;
  1419. ActuatorCommand.Channel(:,actuatorcommandIdx) = double(fread(fid, 10, 'int16'));
  1420. ActuatorCommand.MaxUpdateTime(actuatorcommandIdx) = double(fread(fid, 1, 'uint16'));
  1421. ActuatorCommand.UpdateTime(actuatorcommandIdx) = double(fread(fid, 1, 'uint8'));
  1422. ActuatorCommand.NumFailedUpdates(actuatorcommandIdx) = double(fread(fid, 1, 'uint8'));
  1423. objLen = ftell(fid) - startPos;
  1424. % read CRC
  1425. crc_read = fread(fid, 1, '*uint8');
  1426. if checkCRC
  1427. fseek(fid, startPos, 'bof');
  1428. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1429. fread(fid,1,'uint8');
  1430. if (crc_calc ~= crc_read)
  1431. disp('CRC Error')
  1432. actuatorcommandIdx = actuatorcommandIdx - 1;
  1433. end
  1434. end
  1435.  
  1436.  
  1437. %%
  1438. % ActuatorDesired read function
  1439. function [ActuatorDesired] = ReadActuatorDesiredObject(fid, timestamp, checkCRC, ActuatorDesired, actuatordesiredIdx)
  1440. ActuatorDesired.timestamp(actuatordesiredIdx)= timestamp;
  1441. if 1
  1442. headerSize = 8;
  1443. else
  1444. ActuatorDesired.instanceID(actuatordesiredIdx) = (fread(fid, 1, 'uint16'));
  1445. headerSize = 10;
  1446. end
  1447.  
  1448. startPos = ftell(fid) - headerSize;
  1449. ActuatorDesired.Roll(actuatordesiredIdx) = double(fread(fid, 1, 'float32'));
  1450. ActuatorDesired.Pitch(actuatordesiredIdx) = double(fread(fid, 1, 'float32'));
  1451. ActuatorDesired.Yaw(actuatordesiredIdx) = double(fread(fid, 1, 'float32'));
  1452. ActuatorDesired.Throttle(actuatordesiredIdx) = double(fread(fid, 1, 'float32'));
  1453. ActuatorDesired.UpdateTime(actuatordesiredIdx) = double(fread(fid, 1, 'float32'));
  1454. ActuatorDesired.NumLongUpdates(actuatordesiredIdx) = double(fread(fid, 1, 'float32'));
  1455. objLen = ftell(fid) - startPos;
  1456. % read CRC
  1457. crc_read = fread(fid, 1, '*uint8');
  1458. if checkCRC
  1459. fseek(fid, startPos, 'bof');
  1460. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1461. fread(fid,1,'uint8');
  1462. if (crc_calc ~= crc_read)
  1463. disp('CRC Error')
  1464. actuatordesiredIdx = actuatordesiredIdx - 1;
  1465. end
  1466. end
  1467.  
  1468.  
  1469. %%
  1470. % ActuatorSettings read function
  1471. function [ActuatorSettings] = ReadActuatorSettingsObject(fid, timestamp, checkCRC, ActuatorSettings, actuatorsettingsIdx)
  1472. ActuatorSettings.timestamp(actuatorsettingsIdx)= timestamp;
  1473. if 1
  1474. headerSize = 8;
  1475. else
  1476. ActuatorSettings.instanceID(actuatorsettingsIdx) = (fread(fid, 1, 'uint16'));
  1477. headerSize = 10;
  1478. end
  1479.  
  1480. startPos = ftell(fid) - headerSize;
  1481. ActuatorSettings.ChannelUpdateFreq(:,actuatorsettingsIdx) = double(fread(fid, 4, 'uint16'));
  1482. ActuatorSettings.ChannelMax(:,actuatorsettingsIdx) = double(fread(fid, 10, 'int16'));
  1483. ActuatorSettings.ChannelNeutral(:,actuatorsettingsIdx) = double(fread(fid, 10, 'int16'));
  1484. ActuatorSettings.ChannelMin(:,actuatorsettingsIdx) = double(fread(fid, 10, 'int16'));
  1485. ActuatorSettings.FixedWingRoll1(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1486. ActuatorSettings.FixedWingRoll2(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1487. ActuatorSettings.FixedWingPitch1(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1488. ActuatorSettings.FixedWingPitch2(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1489. ActuatorSettings.FixedWingYaw1(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1490. ActuatorSettings.FixedWingYaw2(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1491. ActuatorSettings.FixedWingThrottle(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1492. ActuatorSettings.VTOLMotorN(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1493. ActuatorSettings.VTOLMotorNE(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1494. ActuatorSettings.VTOLMotorE(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1495. ActuatorSettings.VTOLMotorSE(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1496. ActuatorSettings.VTOLMotorS(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1497. ActuatorSettings.VTOLMotorSW(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1498. ActuatorSettings.VTOLMotorW(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1499. ActuatorSettings.VTOLMotorNW(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1500. ActuatorSettings.ChannelType(:,actuatorsettingsIdx) = double(fread(fid, 10, 'uint8'));
  1501. ActuatorSettings.ChannelAddr(:,actuatorsettingsIdx) = double(fread(fid, 10, 'uint8'));
  1502. ActuatorSettings.MotorsSpinWhileArmed(actuatorsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1503. objLen = ftell(fid) - startPos;
  1504. % read CRC
  1505. crc_read = fread(fid, 1, '*uint8');
  1506. if checkCRC
  1507. fseek(fid, startPos, 'bof');
  1508. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1509. fread(fid,1,'uint8');
  1510. if (crc_calc ~= crc_read)
  1511. disp('CRC Error')
  1512. actuatorsettingsIdx = actuatorsettingsIdx - 1;
  1513. end
  1514. end
  1515.  
  1516.  
  1517. %%
  1518. % AltHoldSmoothed read function
  1519. function [AltHoldSmoothed] = ReadAltHoldSmoothedObject(fid, timestamp, checkCRC, AltHoldSmoothed, altholdsmoothedIdx)
  1520. AltHoldSmoothed.timestamp(altholdsmoothedIdx)= timestamp;
  1521. if 1
  1522. headerSize = 8;
  1523. else
  1524. AltHoldSmoothed.instanceID(altholdsmoothedIdx) = (fread(fid, 1, 'uint16'));
  1525. headerSize = 10;
  1526. end
  1527.  
  1528. startPos = ftell(fid) - headerSize;
  1529. AltHoldSmoothed.Altitude(altholdsmoothedIdx) = double(fread(fid, 1, 'float32'));
  1530. AltHoldSmoothed.Velocity(altholdsmoothedIdx) = double(fread(fid, 1, 'float32'));
  1531. AltHoldSmoothed.Accel(altholdsmoothedIdx) = double(fread(fid, 1, 'float32'));
  1532. objLen = ftell(fid) - startPos;
  1533. % read CRC
  1534. crc_read = fread(fid, 1, '*uint8');
  1535. if checkCRC
  1536. fseek(fid, startPos, 'bof');
  1537. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1538. fread(fid,1,'uint8');
  1539. if (crc_calc ~= crc_read)
  1540. disp('CRC Error')
  1541. altholdsmoothedIdx = altholdsmoothedIdx - 1;
  1542. end
  1543. end
  1544.  
  1545.  
  1546. %%
  1547. % AltitudeHoldDesired read function
  1548. function [AltitudeHoldDesired] = ReadAltitudeHoldDesiredObject(fid, timestamp, checkCRC, AltitudeHoldDesired, altitudeholddesiredIdx)
  1549. AltitudeHoldDesired.timestamp(altitudeholddesiredIdx)= timestamp;
  1550. if 1
  1551. headerSize = 8;
  1552. else
  1553. AltitudeHoldDesired.instanceID(altitudeholddesiredIdx) = (fread(fid, 1, 'uint16'));
  1554. headerSize = 10;
  1555. end
  1556.  
  1557. startPos = ftell(fid) - headerSize;
  1558. AltitudeHoldDesired.Altitude(altitudeholddesiredIdx) = double(fread(fid, 1, 'float32'));
  1559. AltitudeHoldDesired.Roll(altitudeholddesiredIdx) = double(fread(fid, 1, 'float32'));
  1560. AltitudeHoldDesired.Pitch(altitudeholddesiredIdx) = double(fread(fid, 1, 'float32'));
  1561. AltitudeHoldDesired.Yaw(altitudeholddesiredIdx) = double(fread(fid, 1, 'float32'));
  1562. objLen = ftell(fid) - startPos;
  1563. % read CRC
  1564. crc_read = fread(fid, 1, '*uint8');
  1565. if checkCRC
  1566. fseek(fid, startPos, 'bof');
  1567. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1568. fread(fid,1,'uint8');
  1569. if (crc_calc ~= crc_read)
  1570. disp('CRC Error')
  1571. altitudeholddesiredIdx = altitudeholddesiredIdx - 1;
  1572. end
  1573. end
  1574.  
  1575.  
  1576. %%
  1577. % AltitudeHoldSettings read function
  1578. function [AltitudeHoldSettings] = ReadAltitudeHoldSettingsObject(fid, timestamp, checkCRC, AltitudeHoldSettings, altitudeholdsettingsIdx)
  1579. AltitudeHoldSettings.timestamp(altitudeholdsettingsIdx)= timestamp;
  1580. if 1
  1581. headerSize = 8;
  1582. else
  1583. AltitudeHoldSettings.instanceID(altitudeholdsettingsIdx) = (fread(fid, 1, 'uint16'));
  1584. headerSize = 10;
  1585. end
  1586.  
  1587. startPos = ftell(fid) - headerSize;
  1588. AltitudeHoldSettings.Kp(altitudeholdsettingsIdx) = double(fread(fid, 1, 'float32'));
  1589. AltitudeHoldSettings.Ki(altitudeholdsettingsIdx) = double(fread(fid, 1, 'float32'));
  1590. AltitudeHoldSettings.Kd(altitudeholdsettingsIdx) = double(fread(fid, 1, 'float32'));
  1591. AltitudeHoldSettings.Ka(altitudeholdsettingsIdx) = double(fread(fid, 1, 'float32'));
  1592. AltitudeHoldSettings.PressureNoise(altitudeholdsettingsIdx) = double(fread(fid, 1, 'float32'));
  1593. AltitudeHoldSettings.AccelNoise(altitudeholdsettingsIdx) = double(fread(fid, 1, 'float32'));
  1594. AltitudeHoldSettings.AccelDrift(altitudeholdsettingsIdx) = double(fread(fid, 1, 'float32'));
  1595. objLen = ftell(fid) - startPos;
  1596. % read CRC
  1597. crc_read = fread(fid, 1, '*uint8');
  1598. if checkCRC
  1599. fseek(fid, startPos, 'bof');
  1600. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1601. fread(fid,1,'uint8');
  1602. if (crc_calc ~= crc_read)
  1603. disp('CRC Error')
  1604. altitudeholdsettingsIdx = altitudeholdsettingsIdx - 1;
  1605. end
  1606. end
  1607.  
  1608.  
  1609. %%
  1610. % AttitudeActual read function
  1611. function [AttitudeActual] = ReadAttitudeActualObject(fid, timestamp, checkCRC, AttitudeActual, attitudeactualIdx)
  1612. AttitudeActual.timestamp(attitudeactualIdx)= timestamp;
  1613. if 1
  1614. headerSize = 8;
  1615. else
  1616. AttitudeActual.instanceID(attitudeactualIdx) = (fread(fid, 1, 'uint16'));
  1617. headerSize = 10;
  1618. end
  1619.  
  1620. startPos = ftell(fid) - headerSize;
  1621. AttitudeActual.q1(attitudeactualIdx) = double(fread(fid, 1, 'float32'));
  1622. AttitudeActual.q2(attitudeactualIdx) = double(fread(fid, 1, 'float32'));
  1623. AttitudeActual.q3(attitudeactualIdx) = double(fread(fid, 1, 'float32'));
  1624. AttitudeActual.q4(attitudeactualIdx) = double(fread(fid, 1, 'float32'));
  1625. AttitudeActual.Roll(attitudeactualIdx) = double(fread(fid, 1, 'float32'));
  1626. AttitudeActual.Pitch(attitudeactualIdx) = double(fread(fid, 1, 'float32'));
  1627. AttitudeActual.Yaw(attitudeactualIdx) = double(fread(fid, 1, 'float32'));
  1628. objLen = ftell(fid) - startPos;
  1629. % read CRC
  1630. crc_read = fread(fid, 1, '*uint8');
  1631. if checkCRC
  1632. fseek(fid, startPos, 'bof');
  1633. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1634. fread(fid,1,'uint8');
  1635. if (crc_calc ~= crc_read)
  1636. disp('CRC Error')
  1637. attitudeactualIdx = attitudeactualIdx - 1;
  1638. end
  1639. end
  1640.  
  1641.  
  1642. %%
  1643. % AttitudeSettings read function
  1644. function [AttitudeSettings] = ReadAttitudeSettingsObject(fid, timestamp, checkCRC, AttitudeSettings, attitudesettingsIdx)
  1645. AttitudeSettings.timestamp(attitudesettingsIdx)= timestamp;
  1646. if 1
  1647. headerSize = 8;
  1648. else
  1649. AttitudeSettings.instanceID(attitudesettingsIdx) = (fread(fid, 1, 'uint16'));
  1650. headerSize = 10;
  1651. end
  1652.  
  1653. startPos = ftell(fid) - headerSize;
  1654. AttitudeSettings.GyroGain(attitudesettingsIdx) = double(fread(fid, 1, 'float32'));
  1655. AttitudeSettings.AccelKp(attitudesettingsIdx) = double(fread(fid, 1, 'float32'));
  1656. AttitudeSettings.AccelKi(attitudesettingsIdx) = double(fread(fid, 1, 'float32'));
  1657. AttitudeSettings.YawBiasRate(attitudesettingsIdx) = double(fread(fid, 1, 'float32'));
  1658. AttitudeSettings.AccelBias(:,attitudesettingsIdx) = double(fread(fid, 3, 'int16'));
  1659. AttitudeSettings.GyroBias(:,attitudesettingsIdx) = double(fread(fid, 3, 'int16'));
  1660. AttitudeSettings.BoardRotation(:,attitudesettingsIdx) = double(fread(fid, 3, 'int16'));
  1661. AttitudeSettings.ZeroDuringArming(attitudesettingsIdx) = double(fread(fid, 1, 'uint8'));
  1662. AttitudeSettings.BiasCorrectGyro(attitudesettingsIdx) = double(fread(fid, 1, 'uint8'));
  1663. AttitudeSettings.TrimFlight(attitudesettingsIdx) = double(fread(fid, 1, 'uint8'));
  1664. objLen = ftell(fid) - startPos;
  1665. % read CRC
  1666. crc_read = fread(fid, 1, '*uint8');
  1667. if checkCRC
  1668. fseek(fid, startPos, 'bof');
  1669. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1670. fread(fid,1,'uint8');
  1671. if (crc_calc ~= crc_read)
  1672. disp('CRC Error')
  1673. attitudesettingsIdx = attitudesettingsIdx - 1;
  1674. end
  1675. end
  1676.  
  1677.  
  1678. %%
  1679. % BaroAltitude read function
  1680. function [BaroAltitude] = ReadBaroAltitudeObject(fid, timestamp, checkCRC, BaroAltitude, baroaltitudeIdx)
  1681. BaroAltitude.timestamp(baroaltitudeIdx)= timestamp;
  1682. if 1
  1683. headerSize = 8;
  1684. else
  1685. BaroAltitude.instanceID(baroaltitudeIdx) = (fread(fid, 1, 'uint16'));
  1686. headerSize = 10;
  1687. end
  1688.  
  1689. startPos = ftell(fid) - headerSize;
  1690. BaroAltitude.Altitude(baroaltitudeIdx) = double(fread(fid, 1, 'float32'));
  1691. BaroAltitude.Temperature(baroaltitudeIdx) = double(fread(fid, 1, 'float32'));
  1692. BaroAltitude.Pressure(baroaltitudeIdx) = double(fread(fid, 1, 'float32'));
  1693. objLen = ftell(fid) - startPos;
  1694. % read CRC
  1695. crc_read = fread(fid, 1, '*uint8');
  1696. if checkCRC
  1697. fseek(fid, startPos, 'bof');
  1698. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1699. fread(fid,1,'uint8');
  1700. if (crc_calc ~= crc_read)
  1701. disp('CRC Error')
  1702. baroaltitudeIdx = baroaltitudeIdx - 1;
  1703. end
  1704. end
  1705.  
  1706.  
  1707. %%
  1708. % CameraDesired read function
  1709. function [CameraDesired] = ReadCameraDesiredObject(fid, timestamp, checkCRC, CameraDesired, cameradesiredIdx)
  1710. CameraDesired.timestamp(cameradesiredIdx)= timestamp;
  1711. if 1
  1712. headerSize = 8;
  1713. else
  1714. CameraDesired.instanceID(cameradesiredIdx) = (fread(fid, 1, 'uint16'));
  1715. headerSize = 10;
  1716. end
  1717.  
  1718. startPos = ftell(fid) - headerSize;
  1719. CameraDesired.Roll(cameradesiredIdx) = double(fread(fid, 1, 'float32'));
  1720. CameraDesired.Pitch(cameradesiredIdx) = double(fread(fid, 1, 'float32'));
  1721. CameraDesired.Yaw(cameradesiredIdx) = double(fread(fid, 1, 'float32'));
  1722. objLen = ftell(fid) - startPos;
  1723. % read CRC
  1724. crc_read = fread(fid, 1, '*uint8');
  1725. if checkCRC
  1726. fseek(fid, startPos, 'bof');
  1727. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1728. fread(fid,1,'uint8');
  1729. if (crc_calc ~= crc_read)
  1730. disp('CRC Error')
  1731. cameradesiredIdx = cameradesiredIdx - 1;
  1732. end
  1733. end
  1734.  
  1735.  
  1736. %%
  1737. % CameraStabSettings read function
  1738. function [CameraStabSettings] = ReadCameraStabSettingsObject(fid, timestamp, checkCRC, CameraStabSettings, camerastabsettingsIdx)
  1739. CameraStabSettings.timestamp(camerastabsettingsIdx)= timestamp;
  1740. if 1
  1741. headerSize = 8;
  1742. else
  1743. CameraStabSettings.instanceID(camerastabsettingsIdx) = (fread(fid, 1, 'uint16'));
  1744. headerSize = 10;
  1745. end
  1746.  
  1747. startPos = ftell(fid) - headerSize;
  1748. CameraStabSettings.MaxAxisLockRate(camerastabsettingsIdx) = double(fread(fid, 1, 'float32'));
  1749. CameraStabSettings.ResponseTime(:,camerastabsettingsIdx) = double(fread(fid, 3, 'uint16'));
  1750. CameraStabSettings.Input(:,camerastabsettingsIdx) = double(fread(fid, 3, 'uint8'));
  1751. CameraStabSettings.InputRange(:,camerastabsettingsIdx) = double(fread(fid, 3, 'uint8'));
  1752. CameraStabSettings.InputRate(:,camerastabsettingsIdx) = double(fread(fid, 3, 'uint8'));
  1753. CameraStabSettings.StabilizationMode(:,camerastabsettingsIdx) = double(fread(fid, 3, 'uint8'));
  1754. CameraStabSettings.OutputRange(:,camerastabsettingsIdx) = double(fread(fid, 3, 'uint8'));
  1755. objLen = ftell(fid) - startPos;
  1756. % read CRC
  1757. crc_read = fread(fid, 1, '*uint8');
  1758. if checkCRC
  1759. fseek(fid, startPos, 'bof');
  1760. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1761. fread(fid,1,'uint8');
  1762. if (crc_calc ~= crc_read)
  1763. disp('CRC Error')
  1764. camerastabsettingsIdx = camerastabsettingsIdx - 1;
  1765. end
  1766. end
  1767.  
  1768.  
  1769. %%
  1770. % FaultSettings read function
  1771. function [FaultSettings] = ReadFaultSettingsObject(fid, timestamp, checkCRC, FaultSettings, faultsettingsIdx)
  1772. FaultSettings.timestamp(faultsettingsIdx)= timestamp;
  1773. if 1
  1774. headerSize = 8;
  1775. else
  1776. FaultSettings.instanceID(faultsettingsIdx) = (fread(fid, 1, 'uint16'));
  1777. headerSize = 10;
  1778. end
  1779.  
  1780. startPos = ftell(fid) - headerSize;
  1781. FaultSettings.ActivateFault(faultsettingsIdx) = double(fread(fid, 1, 'uint8'));
  1782. objLen = ftell(fid) - startPos;
  1783. % read CRC
  1784. crc_read = fread(fid, 1, '*uint8');
  1785. if checkCRC
  1786. fseek(fid, startPos, 'bof');
  1787. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1788. fread(fid,1,'uint8');
  1789. if (crc_calc ~= crc_read)
  1790. disp('CRC Error')
  1791. faultsettingsIdx = faultsettingsIdx - 1;
  1792. end
  1793. end
  1794.  
  1795.  
  1796. %%
  1797. % FirmwareIAPObj read function
  1798. function [FirmwareIAPObj] = ReadFirmwareIAPObjObject(fid, timestamp, checkCRC, FirmwareIAPObj, firmwareiapobjIdx)
  1799. FirmwareIAPObj.timestamp(firmwareiapobjIdx)= timestamp;
  1800. if 1
  1801. headerSize = 8;
  1802. else
  1803. FirmwareIAPObj.instanceID(firmwareiapobjIdx) = (fread(fid, 1, 'uint16'));
  1804. headerSize = 10;
  1805. end
  1806.  
  1807. startPos = ftell(fid) - headerSize;
  1808. FirmwareIAPObj.crc(firmwareiapobjIdx) = double(fread(fid, 1, 'uint32'));
  1809. FirmwareIAPObj.Command(firmwareiapobjIdx) = double(fread(fid, 1, 'uint16'));
  1810. FirmwareIAPObj.BoardRevision(firmwareiapobjIdx) = double(fread(fid, 1, 'uint16'));
  1811. FirmwareIAPObj.Description(:,firmwareiapobjIdx) = double(fread(fid, 40, 'uint8'));
  1812. FirmwareIAPObj.CPUSerial(:,firmwareiapobjIdx) = double(fread(fid, 12, 'uint8'));
  1813. FirmwareIAPObj.BoardType(firmwareiapobjIdx) = double(fread(fid, 1, 'uint8'));
  1814. FirmwareIAPObj.ArmReset(firmwareiapobjIdx) = double(fread(fid, 1, 'uint8'));
  1815. objLen = ftell(fid) - startPos;
  1816. % read CRC
  1817. crc_read = fread(fid, 1, '*uint8');
  1818. if checkCRC
  1819. fseek(fid, startPos, 'bof');
  1820. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1821. fread(fid,1,'uint8');
  1822. if (crc_calc ~= crc_read)
  1823. disp('CRC Error')
  1824. firmwareiapobjIdx = firmwareiapobjIdx - 1;
  1825. end
  1826. end
  1827.  
  1828.  
  1829. %%
  1830. % FlightBatterySettings read function
  1831. function [FlightBatterySettings] = ReadFlightBatterySettingsObject(fid, timestamp, checkCRC, FlightBatterySettings, flightbatterysettingsIdx)
  1832. FlightBatterySettings.timestamp(flightbatterysettingsIdx)= timestamp;
  1833. if 1
  1834. headerSize = 8;
  1835. else
  1836. FlightBatterySettings.instanceID(flightbatterysettingsIdx) = (fread(fid, 1, 'uint16'));
  1837. headerSize = 10;
  1838. end
  1839.  
  1840. startPos = ftell(fid) - headerSize;
  1841. FlightBatterySettings.Capacity(flightbatterysettingsIdx) = double(fread(fid, 1, 'uint32'));
  1842. FlightBatterySettings.VoltageThresholds(:,flightbatterysettingsIdx) = double(fread(fid, 2, 'float32'));
  1843. FlightBatterySettings.SensorCalibrations(:,flightbatterysettingsIdx) = double(fread(fid, 2, 'float32'));
  1844. FlightBatterySettings.Type(flightbatterysettingsIdx) = double(fread(fid, 1, 'uint8'));
  1845. FlightBatterySettings.NbCells(flightbatterysettingsIdx) = double(fread(fid, 1, 'uint8'));
  1846. FlightBatterySettings.SensorType(flightbatterysettingsIdx) = double(fread(fid, 1, 'uint8'));
  1847. objLen = ftell(fid) - startPos;
  1848. % read CRC
  1849. crc_read = fread(fid, 1, '*uint8');
  1850. if checkCRC
  1851. fseek(fid, startPos, 'bof');
  1852. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1853. fread(fid,1,'uint8');
  1854. if (crc_calc ~= crc_read)
  1855. disp('CRC Error')
  1856. flightbatterysettingsIdx = flightbatterysettingsIdx - 1;
  1857. end
  1858. end
  1859.  
  1860.  
  1861. %%
  1862. % FlightBatteryState read function
  1863. function [FlightBatteryState] = ReadFlightBatteryStateObject(fid, timestamp, checkCRC, FlightBatteryState, flightbatterystateIdx)
  1864. FlightBatteryState.timestamp(flightbatterystateIdx)= timestamp;
  1865. if 1
  1866. headerSize = 8;
  1867. else
  1868. FlightBatteryState.instanceID(flightbatterystateIdx) = (fread(fid, 1, 'uint16'));
  1869. headerSize = 10;
  1870. end
  1871.  
  1872. startPos = ftell(fid) - headerSize;
  1873. FlightBatteryState.Voltage(flightbatterystateIdx) = double(fread(fid, 1, 'float32'));
  1874. FlightBatteryState.Current(flightbatterystateIdx) = double(fread(fid, 1, 'float32'));
  1875. FlightBatteryState.PeakCurrent(flightbatterystateIdx) = double(fread(fid, 1, 'float32'));
  1876. FlightBatteryState.AvgCurrent(flightbatterystateIdx) = double(fread(fid, 1, 'float32'));
  1877. FlightBatteryState.ConsumedEnergy(flightbatterystateIdx) = double(fread(fid, 1, 'float32'));
  1878. FlightBatteryState.EstimatedFlightTime(flightbatterystateIdx) = double(fread(fid, 1, 'float32'));
  1879. objLen = ftell(fid) - startPos;
  1880. % read CRC
  1881. crc_read = fread(fid, 1, '*uint8');
  1882. if checkCRC
  1883. fseek(fid, startPos, 'bof');
  1884. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1885. fread(fid,1,'uint8');
  1886. if (crc_calc ~= crc_read)
  1887. disp('CRC Error')
  1888. flightbatterystateIdx = flightbatterystateIdx - 1;
  1889. end
  1890. end
  1891.  
  1892.  
  1893. %%
  1894. % FlightPlanControl read function
  1895. function [FlightPlanControl] = ReadFlightPlanControlObject(fid, timestamp, checkCRC, FlightPlanControl, flightplancontrolIdx)
  1896. FlightPlanControl.timestamp(flightplancontrolIdx)= timestamp;
  1897. if 1
  1898. headerSize = 8;
  1899. else
  1900. FlightPlanControl.instanceID(flightplancontrolIdx) = (fread(fid, 1, 'uint16'));
  1901. headerSize = 10;
  1902. end
  1903.  
  1904. startPos = ftell(fid) - headerSize;
  1905. FlightPlanControl.Command(flightplancontrolIdx) = double(fread(fid, 1, 'uint8'));
  1906. objLen = ftell(fid) - startPos;
  1907. % read CRC
  1908. crc_read = fread(fid, 1, '*uint8');
  1909. if checkCRC
  1910. fseek(fid, startPos, 'bof');
  1911. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1912. fread(fid,1,'uint8');
  1913. if (crc_calc ~= crc_read)
  1914. disp('CRC Error')
  1915. flightplancontrolIdx = flightplancontrolIdx - 1;
  1916. end
  1917. end
  1918.  
  1919.  
  1920. %%
  1921. % FlightPlanSettings read function
  1922. function [FlightPlanSettings] = ReadFlightPlanSettingsObject(fid, timestamp, checkCRC, FlightPlanSettings, flightplansettingsIdx)
  1923. FlightPlanSettings.timestamp(flightplansettingsIdx)= timestamp;
  1924. if 1
  1925. headerSize = 8;
  1926. else
  1927. FlightPlanSettings.instanceID(flightplansettingsIdx) = (fread(fid, 1, 'uint16'));
  1928. headerSize = 10;
  1929. end
  1930.  
  1931. startPos = ftell(fid) - headerSize;
  1932. FlightPlanSettings.Test(flightplansettingsIdx) = double(fread(fid, 1, 'float32'));
  1933. objLen = ftell(fid) - startPos;
  1934. % read CRC
  1935. crc_read = fread(fid, 1, '*uint8');
  1936. if checkCRC
  1937. fseek(fid, startPos, 'bof');
  1938. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1939. fread(fid,1,'uint8');
  1940. if (crc_calc ~= crc_read)
  1941. disp('CRC Error')
  1942. flightplansettingsIdx = flightplansettingsIdx - 1;
  1943. end
  1944. end
  1945.  
  1946.  
  1947. %%
  1948. % FlightPlanStatus read function
  1949. function [FlightPlanStatus] = ReadFlightPlanStatusObject(fid, timestamp, checkCRC, FlightPlanStatus, flightplanstatusIdx)
  1950. FlightPlanStatus.timestamp(flightplanstatusIdx)= timestamp;
  1951. if 1
  1952. headerSize = 8;
  1953. else
  1954. FlightPlanStatus.instanceID(flightplanstatusIdx) = (fread(fid, 1, 'uint16'));
  1955. headerSize = 10;
  1956. end
  1957.  
  1958. startPos = ftell(fid) - headerSize;
  1959. FlightPlanStatus.ErrorFileID(flightplanstatusIdx) = double(fread(fid, 1, 'uint32'));
  1960. FlightPlanStatus.ErrorLineNum(flightplanstatusIdx) = double(fread(fid, 1, 'uint32'));
  1961. FlightPlanStatus.Debug(:,flightplanstatusIdx) = double(fread(fid, 2, 'float32'));
  1962. FlightPlanStatus.Status(flightplanstatusIdx) = double(fread(fid, 1, 'uint8'));
  1963. FlightPlanStatus.ErrorType(flightplanstatusIdx) = double(fread(fid, 1, 'uint8'));
  1964. objLen = ftell(fid) - startPos;
  1965. % read CRC
  1966. crc_read = fread(fid, 1, '*uint8');
  1967. if checkCRC
  1968. fseek(fid, startPos, 'bof');
  1969. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1970. fread(fid,1,'uint8');
  1971. if (crc_calc ~= crc_read)
  1972. disp('CRC Error')
  1973. flightplanstatusIdx = flightplanstatusIdx - 1;
  1974. end
  1975. end
  1976.  
  1977.  
  1978. %%
  1979. % FlightStatus read function
  1980. function [FlightStatus] = ReadFlightStatusObject(fid, timestamp, checkCRC, FlightStatus, flightstatusIdx)
  1981. FlightStatus.timestamp(flightstatusIdx)= timestamp;
  1982. if 1
  1983. headerSize = 8;
  1984. else
  1985. FlightStatus.instanceID(flightstatusIdx) = (fread(fid, 1, 'uint16'));
  1986. headerSize = 10;
  1987. end
  1988.  
  1989. startPos = ftell(fid) - headerSize;
  1990. FlightStatus.Armed(flightstatusIdx) = double(fread(fid, 1, 'uint8'));
  1991. FlightStatus.FlightMode(flightstatusIdx) = double(fread(fid, 1, 'uint8'));
  1992. objLen = ftell(fid) - startPos;
  1993. % read CRC
  1994. crc_read = fread(fid, 1, '*uint8');
  1995. if checkCRC
  1996. fseek(fid, startPos, 'bof');
  1997. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  1998. fread(fid,1,'uint8');
  1999. if (crc_calc ~= crc_read)
  2000. disp('CRC Error')
  2001. flightstatusIdx = flightstatusIdx - 1;
  2002. end
  2003. end
  2004.  
  2005.  
  2006. %%
  2007. % FlightTelemetryStats read function
  2008. function [FlightTelemetryStats] = ReadFlightTelemetryStatsObject(fid, timestamp, checkCRC, FlightTelemetryStats, flighttelemetrystatsIdx)
  2009. FlightTelemetryStats.timestamp(flighttelemetrystatsIdx)= timestamp;
  2010. if 1
  2011. headerSize = 8;
  2012. else
  2013. FlightTelemetryStats.instanceID(flighttelemetrystatsIdx) = (fread(fid, 1, 'uint16'));
  2014. headerSize = 10;
  2015. end
  2016.  
  2017. startPos = ftell(fid) - headerSize;
  2018. FlightTelemetryStats.TxDataRate(flighttelemetrystatsIdx) = double(fread(fid, 1, 'float32'));
  2019. FlightTelemetryStats.RxDataRate(flighttelemetrystatsIdx) = double(fread(fid, 1, 'float32'));
  2020. FlightTelemetryStats.TxFailures(flighttelemetrystatsIdx) = double(fread(fid, 1, 'uint32'));
  2021. FlightTelemetryStats.RxFailures(flighttelemetrystatsIdx) = double(fread(fid, 1, 'uint32'));
  2022. FlightTelemetryStats.TxRetries(flighttelemetrystatsIdx) = double(fread(fid, 1, 'uint32'));
  2023. FlightTelemetryStats.Status(flighttelemetrystatsIdx) = double(fread(fid, 1, 'uint8'));
  2024. objLen = ftell(fid) - startPos;
  2025. % read CRC
  2026. crc_read = fread(fid, 1, '*uint8');
  2027. if checkCRC
  2028. fseek(fid, startPos, 'bof');
  2029. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2030. fread(fid,1,'uint8');
  2031. if (crc_calc ~= crc_read)
  2032. disp('CRC Error')
  2033. flighttelemetrystatsIdx = flighttelemetrystatsIdx - 1;
  2034. end
  2035. end
  2036.  
  2037.  
  2038. %%
  2039. % GCSReceiver read function
  2040. function [GCSReceiver] = ReadGCSReceiverObject(fid, timestamp, checkCRC, GCSReceiver, gcsreceiverIdx)
  2041. GCSReceiver.timestamp(gcsreceiverIdx)= timestamp;
  2042. if 1
  2043. headerSize = 8;
  2044. else
  2045. GCSReceiver.instanceID(gcsreceiverIdx) = (fread(fid, 1, 'uint16'));
  2046. headerSize = 10;
  2047. end
  2048.  
  2049. startPos = ftell(fid) - headerSize;
  2050. GCSReceiver.Channel(:,gcsreceiverIdx) = double(fread(fid, 6, 'uint16'));
  2051. objLen = ftell(fid) - startPos;
  2052. % read CRC
  2053. crc_read = fread(fid, 1, '*uint8');
  2054. if checkCRC
  2055. fseek(fid, startPos, 'bof');
  2056. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2057. fread(fid,1,'uint8');
  2058. if (crc_calc ~= crc_read)
  2059. disp('CRC Error')
  2060. gcsreceiverIdx = gcsreceiverIdx - 1;
  2061. end
  2062. end
  2063.  
  2064.  
  2065. %%
  2066. % GCSTelemetryStats read function
  2067. function [GCSTelemetryStats] = ReadGCSTelemetryStatsObject(fid, timestamp, checkCRC, GCSTelemetryStats, gcstelemetrystatsIdx)
  2068. GCSTelemetryStats.timestamp(gcstelemetrystatsIdx)= timestamp;
  2069. if 1
  2070. headerSize = 8;
  2071. else
  2072. GCSTelemetryStats.instanceID(gcstelemetrystatsIdx) = (fread(fid, 1, 'uint16'));
  2073. headerSize = 10;
  2074. end
  2075.  
  2076. startPos = ftell(fid) - headerSize;
  2077. GCSTelemetryStats.TxDataRate(gcstelemetrystatsIdx) = double(fread(fid, 1, 'float32'));
  2078. GCSTelemetryStats.RxDataRate(gcstelemetrystatsIdx) = double(fread(fid, 1, 'float32'));
  2079. GCSTelemetryStats.TxFailures(gcstelemetrystatsIdx) = double(fread(fid, 1, 'uint32'));
  2080. GCSTelemetryStats.RxFailures(gcstelemetrystatsIdx) = double(fread(fid, 1, 'uint32'));
  2081. GCSTelemetryStats.TxRetries(gcstelemetrystatsIdx) = double(fread(fid, 1, 'uint32'));
  2082. GCSTelemetryStats.Status(gcstelemetrystatsIdx) = double(fread(fid, 1, 'uint8'));
  2083. objLen = ftell(fid) - startPos;
  2084. % read CRC
  2085. crc_read = fread(fid, 1, '*uint8');
  2086. if checkCRC
  2087. fseek(fid, startPos, 'bof');
  2088. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2089. fread(fid,1,'uint8');
  2090. if (crc_calc ~= crc_read)
  2091. disp('CRC Error')
  2092. gcstelemetrystatsIdx = gcstelemetrystatsIdx - 1;
  2093. end
  2094. end
  2095.  
  2096.  
  2097. %%
  2098. % GPSPosition read function
  2099. function [GPSPosition] = ReadGPSPositionObject(fid, timestamp, checkCRC, GPSPosition, gpspositionIdx)
  2100. GPSPosition.timestamp(gpspositionIdx)= timestamp;
  2101. if 1
  2102. headerSize = 8;
  2103. else
  2104. GPSPosition.instanceID(gpspositionIdx) = (fread(fid, 1, 'uint16'));
  2105. headerSize = 10;
  2106. end
  2107.  
  2108. startPos = ftell(fid) - headerSize;
  2109. GPSPosition.Latitude(gpspositionIdx) = double(fread(fid, 1, 'int32'));
  2110. GPSPosition.Longitude(gpspositionIdx) = double(fread(fid, 1, 'int32'));
  2111. GPSPosition.Altitude(gpspositionIdx) = double(fread(fid, 1, 'float32'));
  2112. GPSPosition.GeoidSeparation(gpspositionIdx) = double(fread(fid, 1, 'float32'));
  2113. GPSPosition.Heading(gpspositionIdx) = double(fread(fid, 1, 'float32'));
  2114. GPSPosition.Groundspeed(gpspositionIdx) = double(fread(fid, 1, 'float32'));
  2115. GPSPosition.PDOP(gpspositionIdx) = double(fread(fid, 1, 'float32'));
  2116. GPSPosition.HDOP(gpspositionIdx) = double(fread(fid, 1, 'float32'));
  2117. GPSPosition.VDOP(gpspositionIdx) = double(fread(fid, 1, 'float32'));
  2118. GPSPosition.Status(gpspositionIdx) = double(fread(fid, 1, 'uint8'));
  2119. GPSPosition.Satellites(gpspositionIdx) = double(fread(fid, 1, 'int8'));
  2120. objLen = ftell(fid) - startPos;
  2121. % read CRC
  2122. crc_read = fread(fid, 1, '*uint8');
  2123. if checkCRC
  2124. fseek(fid, startPos, 'bof');
  2125. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2126. fread(fid,1,'uint8');
  2127. if (crc_calc ~= crc_read)
  2128. disp('CRC Error')
  2129. gpspositionIdx = gpspositionIdx - 1;
  2130. end
  2131. end
  2132.  
  2133.  
  2134. %%
  2135. % GPSSatellites read function
  2136. function [GPSSatellites] = ReadGPSSatellitesObject(fid, timestamp, checkCRC, GPSSatellites, gpssatellitesIdx)
  2137. GPSSatellites.timestamp(gpssatellitesIdx)= timestamp;
  2138. if 1
  2139. headerSize = 8;
  2140. else
  2141. GPSSatellites.instanceID(gpssatellitesIdx) = (fread(fid, 1, 'uint16'));
  2142. headerSize = 10;
  2143. end
  2144.  
  2145. startPos = ftell(fid) - headerSize;
  2146. GPSSatellites.Elevation(:,gpssatellitesIdx) = double(fread(fid, 16, 'float32'));
  2147. GPSSatellites.Azimuth(:,gpssatellitesIdx) = double(fread(fid, 16, 'float32'));
  2148. GPSSatellites.SatsInView(gpssatellitesIdx) = double(fread(fid, 1, 'int8'));
  2149. GPSSatellites.PRN(:,gpssatellitesIdx) = double(fread(fid, 16, 'int8'));
  2150. GPSSatellites.SNR(:,gpssatellitesIdx) = double(fread(fid, 16, 'int8'));
  2151. objLen = ftell(fid) - startPos;
  2152. % read CRC
  2153. crc_read = fread(fid, 1, '*uint8');
  2154. if checkCRC
  2155. fseek(fid, startPos, 'bof');
  2156. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2157. fread(fid,1,'uint8');
  2158. if (crc_calc ~= crc_read)
  2159. disp('CRC Error')
  2160. gpssatellitesIdx = gpssatellitesIdx - 1;
  2161. end
  2162. end
  2163.  
  2164.  
  2165. %%
  2166. % GPSTime read function
  2167. function [GPSTime] = ReadGPSTimeObject(fid, timestamp, checkCRC, GPSTime, gpstimeIdx)
  2168. GPSTime.timestamp(gpstimeIdx)= timestamp;
  2169. if 1
  2170. headerSize = 8;
  2171. else
  2172. GPSTime.instanceID(gpstimeIdx) = (fread(fid, 1, 'uint16'));
  2173. headerSize = 10;
  2174. end
  2175.  
  2176. startPos = ftell(fid) - headerSize;
  2177. GPSTime.Year(gpstimeIdx) = double(fread(fid, 1, 'int16'));
  2178. GPSTime.Month(gpstimeIdx) = double(fread(fid, 1, 'int8'));
  2179. GPSTime.Day(gpstimeIdx) = double(fread(fid, 1, 'int8'));
  2180. GPSTime.Hour(gpstimeIdx) = double(fread(fid, 1, 'int8'));
  2181. GPSTime.Minute(gpstimeIdx) = double(fread(fid, 1, 'int8'));
  2182. GPSTime.Second(gpstimeIdx) = double(fread(fid, 1, 'int8'));
  2183. objLen = ftell(fid) - startPos;
  2184. % read CRC
  2185. crc_read = fread(fid, 1, '*uint8');
  2186. if checkCRC
  2187. fseek(fid, startPos, 'bof');
  2188. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2189. fread(fid,1,'uint8');
  2190. if (crc_calc ~= crc_read)
  2191. disp('CRC Error')
  2192. gpstimeIdx = gpstimeIdx - 1;
  2193. end
  2194. end
  2195.  
  2196.  
  2197. %%
  2198. % GuidanceSettings read function
  2199. function [GuidanceSettings] = ReadGuidanceSettingsObject(fid, timestamp, checkCRC, GuidanceSettings, guidancesettingsIdx)
  2200. GuidanceSettings.timestamp(guidancesettingsIdx)= timestamp;
  2201. if 1
  2202. headerSize = 8;
  2203. else
  2204. GuidanceSettings.instanceID(guidancesettingsIdx) = (fread(fid, 1, 'uint16'));
  2205. headerSize = 10;
  2206. end
  2207.  
  2208. startPos = ftell(fid) - headerSize;
  2209. GuidanceSettings.HorizontalPosPI(:,guidancesettingsIdx) = double(fread(fid, 3, 'float32'));
  2210. GuidanceSettings.HorizontalVelPID(:,guidancesettingsIdx) = double(fread(fid, 4, 'float32'));
  2211. GuidanceSettings.VerticalPosPI(:,guidancesettingsIdx) = double(fread(fid, 3, 'float32'));
  2212. GuidanceSettings.VerticalVelPID(:,guidancesettingsIdx) = double(fread(fid, 4, 'float32'));
  2213. GuidanceSettings.MaxRollPitch(guidancesettingsIdx) = double(fread(fid, 1, 'float32'));
  2214. GuidanceSettings.UpdatePeriod(guidancesettingsIdx) = double(fread(fid, 1, 'int32'));
  2215. GuidanceSettings.HorizontalVelMax(guidancesettingsIdx) = double(fread(fid, 1, 'uint16'));
  2216. GuidanceSettings.VerticalVelMax(guidancesettingsIdx) = double(fread(fid, 1, 'uint16'));
  2217. GuidanceSettings.GuidanceMode(guidancesettingsIdx) = double(fread(fid, 1, 'uint8'));
  2218. GuidanceSettings.ThrottleControl(guidancesettingsIdx) = double(fread(fid, 1, 'uint8'));
  2219. objLen = ftell(fid) - startPos;
  2220. % read CRC
  2221. crc_read = fread(fid, 1, '*uint8');
  2222. if checkCRC
  2223. fseek(fid, startPos, 'bof');
  2224. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2225. fread(fid,1,'uint8');
  2226. if (crc_calc ~= crc_read)
  2227. disp('CRC Error')
  2228. guidancesettingsIdx = guidancesettingsIdx - 1;
  2229. end
  2230. end
  2231.  
  2232.  
  2233. %%
  2234. % Gyros read function
  2235. function [Gyros] = ReadGyrosObject(fid, timestamp, checkCRC, Gyros, gyrosIdx)
  2236. Gyros.timestamp(gyrosIdx)= timestamp;
  2237. if 1
  2238. headerSize = 8;
  2239. else
  2240. Gyros.instanceID(gyrosIdx) = (fread(fid, 1, 'uint16'));
  2241. headerSize = 10;
  2242. end
  2243.  
  2244. startPos = ftell(fid) - headerSize;
  2245. Gyros.x(gyrosIdx) = double(fread(fid, 1, 'float32'));
  2246. Gyros.y(gyrosIdx) = double(fread(fid, 1, 'float32'));
  2247. Gyros.z(gyrosIdx) = double(fread(fid, 1, 'float32'));
  2248. Gyros.temperature(gyrosIdx) = double(fread(fid, 1, 'float32'));
  2249. objLen = ftell(fid) - startPos;
  2250. % read CRC
  2251. crc_read = fread(fid, 1, '*uint8');
  2252. if checkCRC
  2253. fseek(fid, startPos, 'bof');
  2254. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2255. fread(fid,1,'uint8');
  2256. if (crc_calc ~= crc_read)
  2257. disp('CRC Error')
  2258. gyrosIdx = gyrosIdx - 1;
  2259. end
  2260. end
  2261.  
  2262.  
  2263. %%
  2264. % GyrosBias read function
  2265. function [GyrosBias] = ReadGyrosBiasObject(fid, timestamp, checkCRC, GyrosBias, gyrosbiasIdx)
  2266. GyrosBias.timestamp(gyrosbiasIdx)= timestamp;
  2267. if 1
  2268. headerSize = 8;
  2269. else
  2270. GyrosBias.instanceID(gyrosbiasIdx) = (fread(fid, 1, 'uint16'));
  2271. headerSize = 10;
  2272. end
  2273.  
  2274. startPos = ftell(fid) - headerSize;
  2275. GyrosBias.x(gyrosbiasIdx) = double(fread(fid, 1, 'float32'));
  2276. GyrosBias.y(gyrosbiasIdx) = double(fread(fid, 1, 'float32'));
  2277. GyrosBias.z(gyrosbiasIdx) = double(fread(fid, 1, 'float32'));
  2278. objLen = ftell(fid) - startPos;
  2279. % read CRC
  2280. crc_read = fread(fid, 1, '*uint8');
  2281. if checkCRC
  2282. fseek(fid, startPos, 'bof');
  2283. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2284. fread(fid,1,'uint8');
  2285. if (crc_calc ~= crc_read)
  2286. disp('CRC Error')
  2287. gyrosbiasIdx = gyrosbiasIdx - 1;
  2288. end
  2289. end
  2290.  
  2291.  
  2292. %%
  2293. % HomeLocation read function
  2294. function [HomeLocation] = ReadHomeLocationObject(fid, timestamp, checkCRC, HomeLocation, homelocationIdx)
  2295. HomeLocation.timestamp(homelocationIdx)= timestamp;
  2296. if 1
  2297. headerSize = 8;
  2298. else
  2299. HomeLocation.instanceID(homelocationIdx) = (fread(fid, 1, 'uint16'));
  2300. headerSize = 10;
  2301. end
  2302.  
  2303. startPos = ftell(fid) - headerSize;
  2304. HomeLocation.Latitude(homelocationIdx) = double(fread(fid, 1, 'int32'));
  2305. HomeLocation.Longitude(homelocationIdx) = double(fread(fid, 1, 'int32'));
  2306. HomeLocation.Altitude(homelocationIdx) = double(fread(fid, 1, 'float32'));
  2307. HomeLocation.ECEF(:,homelocationIdx) = double(fread(fid, 3, 'int32'));
  2308. HomeLocation.RNE(:,homelocationIdx) = double(fread(fid, 9, 'float32'));
  2309. HomeLocation.Be(:,homelocationIdx) = double(fread(fid, 3, 'float32'));
  2310. HomeLocation.g_e(homelocationIdx) = double(fread(fid, 1, 'float32'));
  2311. HomeLocation.Set(homelocationIdx) = double(fread(fid, 1, 'uint8'));
  2312. objLen = ftell(fid) - startPos;
  2313. % read CRC
  2314. crc_read = fread(fid, 1, '*uint8');
  2315. if checkCRC
  2316. fseek(fid, startPos, 'bof');
  2317. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2318. fread(fid,1,'uint8');
  2319. if (crc_calc ~= crc_read)
  2320. disp('CRC Error')
  2321. homelocationIdx = homelocationIdx - 1;
  2322. end
  2323. end
  2324.  
  2325.  
  2326. %%
  2327. % HwSettings read function
  2328. function [HwSettings] = ReadHwSettingsObject(fid, timestamp, checkCRC, HwSettings, hwsettingsIdx)
  2329. HwSettings.timestamp(hwsettingsIdx)= timestamp;
  2330. if 1
  2331. headerSize = 8;
  2332. else
  2333. HwSettings.instanceID(hwsettingsIdx) = (fread(fid, 1, 'uint16'));
  2334. headerSize = 10;
  2335. end
  2336.  
  2337. startPos = ftell(fid) - headerSize;
  2338. HwSettings.CC_RcvrPort(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2339. HwSettings.CC_MainPort(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2340. HwSettings.CC_FlexiPort(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2341. HwSettings.OP_RcvrPort(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2342. HwSettings.OP_MainPort(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2343. HwSettings.OP_FlexiPort(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2344. HwSettings.TelemetrySpeed(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2345. HwSettings.GPSSpeed(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2346. HwSettings.ComUsbBridgeSpeed(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2347. HwSettings.USB_DeviceType(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2348. HwSettings.USB_HIDPort(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2349. HwSettings.USB_VCPPort(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2350. HwSettings.OptionalModules(:,hwsettingsIdx) = double(fread(fid, 5, 'uint8'));
  2351. HwSettings.DSMxBind(hwsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2352. objLen = ftell(fid) - startPos;
  2353. % read CRC
  2354. crc_read = fread(fid, 1, '*uint8');
  2355. if checkCRC
  2356. fseek(fid, startPos, 'bof');
  2357. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2358. fread(fid,1,'uint8');
  2359. if (crc_calc ~= crc_read)
  2360. disp('CRC Error')
  2361. hwsettingsIdx = hwsettingsIdx - 1;
  2362. end
  2363. end
  2364.  
  2365.  
  2366. %%
  2367. % I2CStats read function
  2368. function [I2CStats] = ReadI2CStatsObject(fid, timestamp, checkCRC, I2CStats, i2cstatsIdx)
  2369. I2CStats.timestamp(i2cstatsIdx)= timestamp;
  2370. if 1
  2371. headerSize = 8;
  2372. else
  2373. I2CStats.instanceID(i2cstatsIdx) = (fread(fid, 1, 'uint16'));
  2374. headerSize = 10;
  2375. end
  2376.  
  2377. startPos = ftell(fid) - headerSize;
  2378. I2CStats.evirq_log(:,i2cstatsIdx) = double(fread(fid, 5, 'uint32'));
  2379. I2CStats.erirq_log(:,i2cstatsIdx) = double(fread(fid, 5, 'uint32'));
  2380. I2CStats.event_errors(i2cstatsIdx) = double(fread(fid, 1, 'uint8'));
  2381. I2CStats.fsm_errors(i2cstatsIdx) = double(fread(fid, 1, 'uint8'));
  2382. I2CStats.irq_errors(i2cstatsIdx) = double(fread(fid, 1, 'uint8'));
  2383. I2CStats.nacks(i2cstatsIdx) = double(fread(fid, 1, 'uint8'));
  2384. I2CStats.timeouts(i2cstatsIdx) = double(fread(fid, 1, 'uint8'));
  2385. I2CStats.last_error_type(i2cstatsIdx) = double(fread(fid, 1, 'uint8'));
  2386. I2CStats.event_log(:,i2cstatsIdx) = double(fread(fid, 5, 'uint8'));
  2387. I2CStats.state_log(:,i2cstatsIdx) = double(fread(fid, 5, 'uint8'));
  2388. objLen = ftell(fid) - startPos;
  2389. % read CRC
  2390. crc_read = fread(fid, 1, '*uint8');
  2391. if checkCRC
  2392. fseek(fid, startPos, 'bof');
  2393. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2394. fread(fid,1,'uint8');
  2395. if (crc_calc ~= crc_read)
  2396. disp('CRC Error')
  2397. i2cstatsIdx = i2cstatsIdx - 1;
  2398. end
  2399. end
  2400.  
  2401.  
  2402. %%
  2403. % Magnetometer read function
  2404. function [Magnetometer] = ReadMagnetometerObject(fid, timestamp, checkCRC, Magnetometer, magnetometerIdx)
  2405. Magnetometer.timestamp(magnetometerIdx)= timestamp;
  2406. if 1
  2407. headerSize = 8;
  2408. else
  2409. Magnetometer.instanceID(magnetometerIdx) = (fread(fid, 1, 'uint16'));
  2410. headerSize = 10;
  2411. end
  2412.  
  2413. startPos = ftell(fid) - headerSize;
  2414. Magnetometer.x(magnetometerIdx) = double(fread(fid, 1, 'float32'));
  2415. Magnetometer.y(magnetometerIdx) = double(fread(fid, 1, 'float32'));
  2416. Magnetometer.z(magnetometerIdx) = double(fread(fid, 1, 'float32'));
  2417. objLen = ftell(fid) - startPos;
  2418. % read CRC
  2419. crc_read = fread(fid, 1, '*uint8');
  2420. if checkCRC
  2421. fseek(fid, startPos, 'bof');
  2422. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2423. fread(fid,1,'uint8');
  2424. if (crc_calc ~= crc_read)
  2425. disp('CRC Error')
  2426. magnetometerIdx = magnetometerIdx - 1;
  2427. end
  2428. end
  2429.  
  2430.  
  2431. %%
  2432. % ManualControlCommand read function
  2433. function [ManualControlCommand] = ReadManualControlCommandObject(fid, timestamp, checkCRC, ManualControlCommand, manualcontrolcommandIdx)
  2434. ManualControlCommand.timestamp(manualcontrolcommandIdx)= timestamp;
  2435. if 1
  2436. headerSize = 8;
  2437. else
  2438. ManualControlCommand.instanceID(manualcontrolcommandIdx) = (fread(fid, 1, 'uint16'));
  2439. headerSize = 10;
  2440. end
  2441.  
  2442. startPos = ftell(fid) - headerSize;
  2443. ManualControlCommand.Throttle(manualcontrolcommandIdx) = double(fread(fid, 1, 'float32'));
  2444. ManualControlCommand.Roll(manualcontrolcommandIdx) = double(fread(fid, 1, 'float32'));
  2445. ManualControlCommand.Pitch(manualcontrolcommandIdx) = double(fread(fid, 1, 'float32'));
  2446. ManualControlCommand.Yaw(manualcontrolcommandIdx) = double(fread(fid, 1, 'float32'));
  2447. ManualControlCommand.Collective(manualcontrolcommandIdx) = double(fread(fid, 1, 'float32'));
  2448. ManualControlCommand.Channel(:,manualcontrolcommandIdx) = double(fread(fid, 9, 'uint16'));
  2449. ManualControlCommand.Connected(manualcontrolcommandIdx) = double(fread(fid, 1, 'uint8'));
  2450. objLen = ftell(fid) - startPos;
  2451. % read CRC
  2452. crc_read = fread(fid, 1, '*uint8');
  2453. if checkCRC
  2454. fseek(fid, startPos, 'bof');
  2455. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2456. fread(fid,1,'uint8');
  2457. if (crc_calc ~= crc_read)
  2458. disp('CRC Error')
  2459. manualcontrolcommandIdx = manualcontrolcommandIdx - 1;
  2460. end
  2461. end
  2462.  
  2463.  
  2464. %%
  2465. % ManualControlSettings read function
  2466. function [ManualControlSettings] = ReadManualControlSettingsObject(fid, timestamp, checkCRC, ManualControlSettings, manualcontrolsettingsIdx)
  2467. ManualControlSettings.timestamp(manualcontrolsettingsIdx)= timestamp;
  2468. if 1
  2469. headerSize = 8;
  2470. else
  2471. ManualControlSettings.instanceID(manualcontrolsettingsIdx) = (fread(fid, 1, 'uint16'));
  2472. headerSize = 10;
  2473. end
  2474.  
  2475. startPos = ftell(fid) - headerSize;
  2476. ManualControlSettings.ChannelMin(:,manualcontrolsettingsIdx) = double(fread(fid, 9, 'int16'));
  2477. ManualControlSettings.ChannelNeutral(:,manualcontrolsettingsIdx) = double(fread(fid, 9, 'int16'));
  2478. ManualControlSettings.ChannelMax(:,manualcontrolsettingsIdx) = double(fread(fid, 9, 'int16'));
  2479. ManualControlSettings.ArmedTimeout(manualcontrolsettingsIdx) = double(fread(fid, 1, 'uint16'));
  2480. ManualControlSettings.ChannelGroups(:,manualcontrolsettingsIdx) = double(fread(fid, 9, 'uint8'));
  2481. ManualControlSettings.ChannelNumber(:,manualcontrolsettingsIdx) = double(fread(fid, 9, 'uint8'));
  2482. ManualControlSettings.Arming(manualcontrolsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2483. ManualControlSettings.Stabilization1Settings(:,manualcontrolsettingsIdx) = double(fread(fid, 3, 'uint8'));
  2484. ManualControlSettings.Stabilization2Settings(:,manualcontrolsettingsIdx) = double(fread(fid, 3, 'uint8'));
  2485. ManualControlSettings.Stabilization3Settings(:,manualcontrolsettingsIdx) = double(fread(fid, 3, 'uint8'));
  2486. ManualControlSettings.FlightModePosition(:,manualcontrolsettingsIdx) = double(fread(fid, 3, 'uint8'));
  2487. objLen = ftell(fid) - startPos;
  2488. % read CRC
  2489. crc_read = fread(fid, 1, '*uint8');
  2490. if checkCRC
  2491. fseek(fid, startPos, 'bof');
  2492. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2493. fread(fid,1,'uint8');
  2494. if (crc_calc ~= crc_read)
  2495. disp('CRC Error')
  2496. manualcontrolsettingsIdx = manualcontrolsettingsIdx - 1;
  2497. end
  2498. end
  2499.  
  2500.  
  2501. %%
  2502. % MixerSettings read function
  2503. function [MixerSettings] = ReadMixerSettingsObject(fid, timestamp, checkCRC, MixerSettings, mixersettingsIdx)
  2504. MixerSettings.timestamp(mixersettingsIdx)= timestamp;
  2505. if 1
  2506. headerSize = 8;
  2507. else
  2508. MixerSettings.instanceID(mixersettingsIdx) = (fread(fid, 1, 'uint16'));
  2509. headerSize = 10;
  2510. end
  2511.  
  2512. startPos = ftell(fid) - headerSize;
  2513. MixerSettings.MaxAccel(mixersettingsIdx) = double(fread(fid, 1, 'float32'));
  2514. MixerSettings.FeedForward(mixersettingsIdx) = double(fread(fid, 1, 'float32'));
  2515. MixerSettings.AccelTime(mixersettingsIdx) = double(fread(fid, 1, 'float32'));
  2516. MixerSettings.DecelTime(mixersettingsIdx) = double(fread(fid, 1, 'float32'));
  2517. MixerSettings.ThrottleCurve1(:,mixersettingsIdx) = double(fread(fid, 5, 'float32'));
  2518. MixerSettings.ThrottleCurve2(:,mixersettingsIdx) = double(fread(fid, 5, 'float32'));
  2519. MixerSettings.Curve2Source(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2520. MixerSettings.Mixer1Type(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2521. MixerSettings.Mixer1Vector(:,mixersettingsIdx) = double(fread(fid, 5, 'int8'));
  2522. MixerSettings.Mixer2Type(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2523. MixerSettings.Mixer2Vector(:,mixersettingsIdx) = double(fread(fid, 5, 'int8'));
  2524. MixerSettings.Mixer3Type(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2525. MixerSettings.Mixer3Vector(:,mixersettingsIdx) = double(fread(fid, 5, 'int8'));
  2526. MixerSettings.Mixer4Type(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2527. MixerSettings.Mixer4Vector(:,mixersettingsIdx) = double(fread(fid, 5, 'int8'));
  2528. MixerSettings.Mixer5Type(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2529. MixerSettings.Mixer5Vector(:,mixersettingsIdx) = double(fread(fid, 5, 'int8'));
  2530. MixerSettings.Mixer6Type(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2531. MixerSettings.Mixer6Vector(:,mixersettingsIdx) = double(fread(fid, 5, 'int8'));
  2532. MixerSettings.Mixer7Type(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2533. MixerSettings.Mixer7Vector(:,mixersettingsIdx) = double(fread(fid, 5, 'int8'));
  2534. MixerSettings.Mixer8Type(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2535. MixerSettings.Mixer8Vector(:,mixersettingsIdx) = double(fread(fid, 5, 'int8'));
  2536. MixerSettings.Mixer9Type(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2537. MixerSettings.Mixer9Vector(:,mixersettingsIdx) = double(fread(fid, 5, 'int8'));
  2538. MixerSettings.Mixer10Type(mixersettingsIdx) = double(fread(fid, 1, 'uint8'));
  2539. MixerSettings.Mixer10Vector(:,mixersettingsIdx) = double(fread(fid, 5, 'int8'));
  2540. objLen = ftell(fid) - startPos;
  2541. % read CRC
  2542. crc_read = fread(fid, 1, '*uint8');
  2543. if checkCRC
  2544. fseek(fid, startPos, 'bof');
  2545. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2546. fread(fid,1,'uint8');
  2547. if (crc_calc ~= crc_read)
  2548. disp('CRC Error')
  2549. mixersettingsIdx = mixersettingsIdx - 1;
  2550. end
  2551. end
  2552.  
  2553.  
  2554. %%
  2555. % MixerStatus read function
  2556. function [MixerStatus] = ReadMixerStatusObject(fid, timestamp, checkCRC, MixerStatus, mixerstatusIdx)
  2557. MixerStatus.timestamp(mixerstatusIdx)= timestamp;
  2558. if 1
  2559. headerSize = 8;
  2560. else
  2561. MixerStatus.instanceID(mixerstatusIdx) = (fread(fid, 1, 'uint16'));
  2562. headerSize = 10;
  2563. end
  2564.  
  2565. startPos = ftell(fid) - headerSize;
  2566. MixerStatus.Mixer1(mixerstatusIdx) = double(fread(fid, 1, 'float32'));
  2567. MixerStatus.Mixer2(mixerstatusIdx) = double(fread(fid, 1, 'float32'));
  2568. MixerStatus.Mixer3(mixerstatusIdx) = double(fread(fid, 1, 'float32'));
  2569. MixerStatus.Mixer4(mixerstatusIdx) = double(fread(fid, 1, 'float32'));
  2570. MixerStatus.Mixer5(mixerstatusIdx) = double(fread(fid, 1, 'float32'));
  2571. MixerStatus.Mixer6(mixerstatusIdx) = double(fread(fid, 1, 'float32'));
  2572. MixerStatus.Mixer7(mixerstatusIdx) = double(fread(fid, 1, 'float32'));
  2573. MixerStatus.Mixer8(mixerstatusIdx) = double(fread(fid, 1, 'float32'));
  2574. objLen = ftell(fid) - startPos;
  2575. % read CRC
  2576. crc_read = fread(fid, 1, '*uint8');
  2577. if checkCRC
  2578. fseek(fid, startPos, 'bof');
  2579. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2580. fread(fid,1,'uint8');
  2581. if (crc_calc ~= crc_read)
  2582. disp('CRC Error')
  2583. mixerstatusIdx = mixerstatusIdx - 1;
  2584. end
  2585. end
  2586.  
  2587.  
  2588. %%
  2589. % NedAccel read function
  2590. function [NedAccel] = ReadNedAccelObject(fid, timestamp, checkCRC, NedAccel, nedaccelIdx)
  2591. NedAccel.timestamp(nedaccelIdx)= timestamp;
  2592. if 1
  2593. headerSize = 8;
  2594. else
  2595. NedAccel.instanceID(nedaccelIdx) = (fread(fid, 1, 'uint16'));
  2596. headerSize = 10;
  2597. end
  2598.  
  2599. startPos = ftell(fid) - headerSize;
  2600. NedAccel.North(nedaccelIdx) = double(fread(fid, 1, 'float32'));
  2601. NedAccel.East(nedaccelIdx) = double(fread(fid, 1, 'float32'));
  2602. NedAccel.Down(nedaccelIdx) = double(fread(fid, 1, 'float32'));
  2603. objLen = ftell(fid) - startPos;
  2604. % read CRC
  2605. crc_read = fread(fid, 1, '*uint8');
  2606. if checkCRC
  2607. fseek(fid, startPos, 'bof');
  2608. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2609. fread(fid,1,'uint8');
  2610. if (crc_calc ~= crc_read)
  2611. disp('CRC Error')
  2612. nedaccelIdx = nedaccelIdx - 1;
  2613. end
  2614. end
  2615.  
  2616.  
  2617. %%
  2618. % ObjectPersistence read function
  2619. function [ObjectPersistence] = ReadObjectPersistenceObject(fid, timestamp, checkCRC, ObjectPersistence, objectpersistenceIdx)
  2620. ObjectPersistence.timestamp(objectpersistenceIdx)= timestamp;
  2621. if 1
  2622. headerSize = 8;
  2623. else
  2624. ObjectPersistence.instanceID(objectpersistenceIdx) = (fread(fid, 1, 'uint16'));
  2625. headerSize = 10;
  2626. end
  2627.  
  2628. startPos = ftell(fid) - headerSize;
  2629. ObjectPersistence.ObjectID(objectpersistenceIdx) = double(fread(fid, 1, 'uint32'));
  2630. ObjectPersistence.InstanceID(objectpersistenceIdx) = double(fread(fid, 1, 'uint32'));
  2631. ObjectPersistence.Operation(objectpersistenceIdx) = double(fread(fid, 1, 'uint8'));
  2632. ObjectPersistence.Selection(objectpersistenceIdx) = double(fread(fid, 1, 'uint8'));
  2633. objLen = ftell(fid) - startPos;
  2634. % read CRC
  2635. crc_read = fread(fid, 1, '*uint8');
  2636. if checkCRC
  2637. fseek(fid, startPos, 'bof');
  2638. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2639. fread(fid,1,'uint8');
  2640. if (crc_calc ~= crc_read)
  2641. disp('CRC Error')
  2642. objectpersistenceIdx = objectpersistenceIdx - 1;
  2643. end
  2644. end
  2645.  
  2646.  
  2647. %%
  2648. % OveroSyncStats read function
  2649. function [OveroSyncStats] = ReadOveroSyncStatsObject(fid, timestamp, checkCRC, OveroSyncStats, overosyncstatsIdx)
  2650. OveroSyncStats.timestamp(overosyncstatsIdx)= timestamp;
  2651. if 1
  2652. headerSize = 8;
  2653. else
  2654. OveroSyncStats.instanceID(overosyncstatsIdx) = (fread(fid, 1, 'uint16'));
  2655. headerSize = 10;
  2656. end
  2657.  
  2658. startPos = ftell(fid) - headerSize;
  2659. OveroSyncStats.Send(overosyncstatsIdx) = double(fread(fid, 1, 'uint32'));
  2660. OveroSyncStats.Received(overosyncstatsIdx) = double(fread(fid, 1, 'uint32'));
  2661. OveroSyncStats.DroppedUpdates(overosyncstatsIdx) = double(fread(fid, 1, 'uint32'));
  2662. OveroSyncStats.Connected(overosyncstatsIdx) = double(fread(fid, 1, 'uint8'));
  2663. objLen = ftell(fid) - startPos;
  2664. % read CRC
  2665. crc_read = fread(fid, 1, '*uint8');
  2666. if checkCRC
  2667. fseek(fid, startPos, 'bof');
  2668. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2669. fread(fid,1,'uint8');
  2670. if (crc_calc ~= crc_read)
  2671. disp('CRC Error')
  2672. overosyncstatsIdx = overosyncstatsIdx - 1;
  2673. end
  2674. end
  2675.  
  2676.  
  2677. %%
  2678. % PositionActual read function
  2679. function [PositionActual] = ReadPositionActualObject(fid, timestamp, checkCRC, PositionActual, positionactualIdx)
  2680. PositionActual.timestamp(positionactualIdx)= timestamp;
  2681. if 1
  2682. headerSize = 8;
  2683. else
  2684. PositionActual.instanceID(positionactualIdx) = (fread(fid, 1, 'uint16'));
  2685. headerSize = 10;
  2686. end
  2687.  
  2688. startPos = ftell(fid) - headerSize;
  2689. PositionActual.North(positionactualIdx) = double(fread(fid, 1, 'float32'));
  2690. PositionActual.East(positionactualIdx) = double(fread(fid, 1, 'float32'));
  2691. PositionActual.Down(positionactualIdx) = double(fread(fid, 1, 'float32'));
  2692. objLen = ftell(fid) - startPos;
  2693. % read CRC
  2694. crc_read = fread(fid, 1, '*uint8');
  2695. if checkCRC
  2696. fseek(fid, startPos, 'bof');
  2697. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2698. fread(fid,1,'uint8');
  2699. if (crc_calc ~= crc_read)
  2700. disp('CRC Error')
  2701. positionactualIdx = positionactualIdx - 1;
  2702. end
  2703. end
  2704.  
  2705.  
  2706. %%
  2707. % PositionDesired read function
  2708. function [PositionDesired] = ReadPositionDesiredObject(fid, timestamp, checkCRC, PositionDesired, positiondesiredIdx)
  2709. PositionDesired.timestamp(positiondesiredIdx)= timestamp;
  2710. if 1
  2711. headerSize = 8;
  2712. else
  2713. PositionDesired.instanceID(positiondesiredIdx) = (fread(fid, 1, 'uint16'));
  2714. headerSize = 10;
  2715. end
  2716.  
  2717. startPos = ftell(fid) - headerSize;
  2718. PositionDesired.North(positiondesiredIdx) = double(fread(fid, 1, 'float32'));
  2719. PositionDesired.East(positiondesiredIdx) = double(fread(fid, 1, 'float32'));
  2720. PositionDesired.Down(positiondesiredIdx) = double(fread(fid, 1, 'float32'));
  2721. objLen = ftell(fid) - startPos;
  2722. % read CRC
  2723. crc_read = fread(fid, 1, '*uint8');
  2724. if checkCRC
  2725. fseek(fid, startPos, 'bof');
  2726. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2727. fread(fid,1,'uint8');
  2728. if (crc_calc ~= crc_read)
  2729. disp('CRC Error')
  2730. positiondesiredIdx = positiondesiredIdx - 1;
  2731. end
  2732. end
  2733.  
  2734.  
  2735. %%
  2736. % RateDesired read function
  2737. function [RateDesired] = ReadRateDesiredObject(fid, timestamp, checkCRC, RateDesired, ratedesiredIdx)
  2738. RateDesired.timestamp(ratedesiredIdx)= timestamp;
  2739. if 1
  2740. headerSize = 8;
  2741. else
  2742. RateDesired.instanceID(ratedesiredIdx) = (fread(fid, 1, 'uint16'));
  2743. headerSize = 10;
  2744. end
  2745.  
  2746. startPos = ftell(fid) - headerSize;
  2747. RateDesired.Roll(ratedesiredIdx) = double(fread(fid, 1, 'float32'));
  2748. RateDesired.Pitch(ratedesiredIdx) = double(fread(fid, 1, 'float32'));
  2749. RateDesired.Yaw(ratedesiredIdx) = double(fread(fid, 1, 'float32'));
  2750. objLen = ftell(fid) - startPos;
  2751. % read CRC
  2752. crc_read = fread(fid, 1, '*uint8');
  2753. if checkCRC
  2754. fseek(fid, startPos, 'bof');
  2755. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2756. fread(fid,1,'uint8');
  2757. if (crc_calc ~= crc_read)
  2758. disp('CRC Error')
  2759. ratedesiredIdx = ratedesiredIdx - 1;
  2760. end
  2761. end
  2762.  
  2763.  
  2764. %%
  2765. % ReceiverActivity read function
  2766. function [ReceiverActivity] = ReadReceiverActivityObject(fid, timestamp, checkCRC, ReceiverActivity, receiveractivityIdx)
  2767. ReceiverActivity.timestamp(receiveractivityIdx)= timestamp;
  2768. if 1
  2769. headerSize = 8;
  2770. else
  2771. ReceiverActivity.instanceID(receiveractivityIdx) = (fread(fid, 1, 'uint16'));
  2772. headerSize = 10;
  2773. end
  2774.  
  2775. startPos = ftell(fid) - headerSize;
  2776. ReceiverActivity.ActiveGroup(receiveractivityIdx) = double(fread(fid, 1, 'uint8'));
  2777. ReceiverActivity.ActiveChannel(receiveractivityIdx) = double(fread(fid, 1, 'uint8'));
  2778. objLen = ftell(fid) - startPos;
  2779. % read CRC
  2780. crc_read = fread(fid, 1, '*uint8');
  2781. if checkCRC
  2782. fseek(fid, startPos, 'bof');
  2783. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2784. fread(fid,1,'uint8');
  2785. if (crc_calc ~= crc_read)
  2786. disp('CRC Error')
  2787. receiveractivityIdx = receiveractivityIdx - 1;
  2788. end
  2789. end
  2790.  
  2791.  
  2792. %%
  2793. % RevoCalibration read function
  2794. function [RevoCalibration] = ReadRevoCalibrationObject(fid, timestamp, checkCRC, RevoCalibration, revocalibrationIdx)
  2795. RevoCalibration.timestamp(revocalibrationIdx)= timestamp;
  2796. if 1
  2797. headerSize = 8;
  2798. else
  2799. RevoCalibration.instanceID(revocalibrationIdx) = (fread(fid, 1, 'uint16'));
  2800. headerSize = 10;
  2801. end
  2802.  
  2803. startPos = ftell(fid) - headerSize;
  2804. RevoCalibration.accel_bias(:,revocalibrationIdx) = double(fread(fid, 3, 'float32'));
  2805. RevoCalibration.accel_scale(:,revocalibrationIdx) = double(fread(fid, 3, 'float32'));
  2806. RevoCalibration.accel_var(:,revocalibrationIdx) = double(fread(fid, 3, 'float32'));
  2807. RevoCalibration.gyro_bias(:,revocalibrationIdx) = double(fread(fid, 3, 'float32'));
  2808. RevoCalibration.gyro_scale(:,revocalibrationIdx) = double(fread(fid, 3, 'float32'));
  2809. RevoCalibration.gyro_var(:,revocalibrationIdx) = double(fread(fid, 3, 'float32'));
  2810. RevoCalibration.gyro_tempcoeff(:,revocalibrationIdx) = double(fread(fid, 3, 'float32'));
  2811. RevoCalibration.mag_bias(:,revocalibrationIdx) = double(fread(fid, 3, 'float32'));
  2812. RevoCalibration.mag_scale(:,revocalibrationIdx) = double(fread(fid, 3, 'float32'));
  2813. RevoCalibration.mag_var(:,revocalibrationIdx) = double(fread(fid, 3, 'float32'));
  2814. RevoCalibration.BiasCorrectedRaw(revocalibrationIdx) = double(fread(fid, 1, 'uint8'));
  2815. objLen = ftell(fid) - startPos;
  2816. % read CRC
  2817. crc_read = fread(fid, 1, '*uint8');
  2818. if checkCRC
  2819. fseek(fid, startPos, 'bof');
  2820. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2821. fread(fid,1,'uint8');
  2822. if (crc_calc ~= crc_read)
  2823. disp('CRC Error')
  2824. revocalibrationIdx = revocalibrationIdx - 1;
  2825. end
  2826. end
  2827.  
  2828.  
  2829. %%
  2830. % SonarAltitude read function
  2831. function [SonarAltitude] = ReadSonarAltitudeObject(fid, timestamp, checkCRC, SonarAltitude, sonaraltitudeIdx)
  2832. SonarAltitude.timestamp(sonaraltitudeIdx)= timestamp;
  2833. if 1
  2834. headerSize = 8;
  2835. else
  2836. SonarAltitude.instanceID(sonaraltitudeIdx) = (fread(fid, 1, 'uint16'));
  2837. headerSize = 10;
  2838. end
  2839.  
  2840. startPos = ftell(fid) - headerSize;
  2841. SonarAltitude.Altitude(sonaraltitudeIdx) = double(fread(fid, 1, 'float32'));
  2842. objLen = ftell(fid) - startPos;
  2843. % read CRC
  2844. crc_read = fread(fid, 1, '*uint8');
  2845. if checkCRC
  2846. fseek(fid, startPos, 'bof');
  2847. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2848. fread(fid,1,'uint8');
  2849. if (crc_calc ~= crc_read)
  2850. disp('CRC Error')
  2851. sonaraltitudeIdx = sonaraltitudeIdx - 1;
  2852. end
  2853. end
  2854.  
  2855.  
  2856. %%
  2857. % StabilizationDesired read function
  2858. function [StabilizationDesired] = ReadStabilizationDesiredObject(fid, timestamp, checkCRC, StabilizationDesired, stabilizationdesiredIdx)
  2859. StabilizationDesired.timestamp(stabilizationdesiredIdx)= timestamp;
  2860. if 1
  2861. headerSize = 8;
  2862. else
  2863. StabilizationDesired.instanceID(stabilizationdesiredIdx) = (fread(fid, 1, 'uint16'));
  2864. headerSize = 10;
  2865. end
  2866.  
  2867. startPos = ftell(fid) - headerSize;
  2868. StabilizationDesired.Roll(stabilizationdesiredIdx) = double(fread(fid, 1, 'float32'));
  2869. StabilizationDesired.Pitch(stabilizationdesiredIdx) = double(fread(fid, 1, 'float32'));
  2870. StabilizationDesired.Yaw(stabilizationdesiredIdx) = double(fread(fid, 1, 'float32'));
  2871. StabilizationDesired.Throttle(stabilizationdesiredIdx) = double(fread(fid, 1, 'float32'));
  2872. StabilizationDesired.StabilizationMode(:,stabilizationdesiredIdx) = double(fread(fid, 3, 'uint8'));
  2873. objLen = ftell(fid) - startPos;
  2874. % read CRC
  2875. crc_read = fread(fid, 1, '*uint8');
  2876. if checkCRC
  2877. fseek(fid, startPos, 'bof');
  2878. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2879. fread(fid,1,'uint8');
  2880. if (crc_calc ~= crc_read)
  2881. disp('CRC Error')
  2882. stabilizationdesiredIdx = stabilizationdesiredIdx - 1;
  2883. end
  2884. end
  2885.  
  2886.  
  2887. %%
  2888. % StabilizationSettings read function
  2889. function [StabilizationSettings] = ReadStabilizationSettingsObject(fid, timestamp, checkCRC, StabilizationSettings, stabilizationsettingsIdx)
  2890. StabilizationSettings.timestamp(stabilizationsettingsIdx)= timestamp;
  2891. if 1
  2892. headerSize = 8;
  2893. else
  2894. StabilizationSettings.instanceID(stabilizationsettingsIdx) = (fread(fid, 1, 'uint16'));
  2895. headerSize = 10;
  2896. end
  2897.  
  2898. startPos = ftell(fid) - headerSize;
  2899. StabilizationSettings.ManualRate(:,stabilizationsettingsIdx) = double(fread(fid, 3, 'float32'));
  2900. StabilizationSettings.MaximumRate(:,stabilizationsettingsIdx) = double(fread(fid, 3, 'float32'));
  2901. StabilizationSettings.RollRatePID(:,stabilizationsettingsIdx) = double(fread(fid, 4, 'float32'));
  2902. StabilizationSettings.PitchRatePID(:,stabilizationsettingsIdx) = double(fread(fid, 4, 'float32'));
  2903. StabilizationSettings.YawRatePID(:,stabilizationsettingsIdx) = double(fread(fid, 4, 'float32'));
  2904. StabilizationSettings.RollPI(:,stabilizationsettingsIdx) = double(fread(fid, 3, 'float32'));
  2905. StabilizationSettings.PitchPI(:,stabilizationsettingsIdx) = double(fread(fid, 3, 'float32'));
  2906. StabilizationSettings.YawPI(:,stabilizationsettingsIdx) = double(fread(fid, 3, 'float32'));
  2907. StabilizationSettings.GyroTau(stabilizationsettingsIdx) = double(fread(fid, 1, 'float32'));
  2908. StabilizationSettings.WeakLevelingKp(stabilizationsettingsIdx) = double(fread(fid, 1, 'float32'));
  2909. StabilizationSettings.RollMax(stabilizationsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2910. StabilizationSettings.PitchMax(stabilizationsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2911. StabilizationSettings.YawMax(stabilizationsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2912. StabilizationSettings.MaxAxisLock(stabilizationsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2913. StabilizationSettings.MaxAxisLockRate(stabilizationsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2914. StabilizationSettings.MaxWeakLevelingRate(stabilizationsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2915. StabilizationSettings.LowThrottleZeroIntegral(stabilizationsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2916. objLen = ftell(fid) - startPos;
  2917. % read CRC
  2918. crc_read = fread(fid, 1, '*uint8');
  2919. if checkCRC
  2920. fseek(fid, startPos, 'bof');
  2921. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2922. fread(fid,1,'uint8');
  2923. if (crc_calc ~= crc_read)
  2924. disp('CRC Error')
  2925. stabilizationsettingsIdx = stabilizationsettingsIdx - 1;
  2926. end
  2927. end
  2928.  
  2929.  
  2930. %%
  2931. % SystemAlarms read function
  2932. function [SystemAlarms] = ReadSystemAlarmsObject(fid, timestamp, checkCRC, SystemAlarms, systemalarmsIdx)
  2933. SystemAlarms.timestamp(systemalarmsIdx)= timestamp;
  2934. if 1
  2935. headerSize = 8;
  2936. else
  2937. SystemAlarms.instanceID(systemalarmsIdx) = (fread(fid, 1, 'uint16'));
  2938. headerSize = 10;
  2939. end
  2940.  
  2941. startPos = ftell(fid) - headerSize;
  2942. SystemAlarms.Alarm(:,systemalarmsIdx) = double(fread(fid, 18, 'uint8'));
  2943. objLen = ftell(fid) - startPos;
  2944. % read CRC
  2945. crc_read = fread(fid, 1, '*uint8');
  2946. if checkCRC
  2947. fseek(fid, startPos, 'bof');
  2948. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2949. fread(fid,1,'uint8');
  2950. if (crc_calc ~= crc_read)
  2951. disp('CRC Error')
  2952. systemalarmsIdx = systemalarmsIdx - 1;
  2953. end
  2954. end
  2955.  
  2956.  
  2957. %%
  2958. % SystemSettings read function
  2959. function [SystemSettings] = ReadSystemSettingsObject(fid, timestamp, checkCRC, SystemSettings, systemsettingsIdx)
  2960. SystemSettings.timestamp(systemsettingsIdx)= timestamp;
  2961. if 1
  2962. headerSize = 8;
  2963. else
  2964. SystemSettings.instanceID(systemsettingsIdx) = (fread(fid, 1, 'uint16'));
  2965. headerSize = 10;
  2966. end
  2967.  
  2968. startPos = ftell(fid) - headerSize;
  2969. SystemSettings.GUIConfigData(:,systemsettingsIdx) = double(fread(fid, 2, 'uint32'));
  2970. SystemSettings.AirframeType(systemsettingsIdx) = double(fread(fid, 1, 'uint8'));
  2971. objLen = ftell(fid) - startPos;
  2972. % read CRC
  2973. crc_read = fread(fid, 1, '*uint8');
  2974. if checkCRC
  2975. fseek(fid, startPos, 'bof');
  2976. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  2977. fread(fid,1,'uint8');
  2978. if (crc_calc ~= crc_read)
  2979. disp('CRC Error')
  2980. systemsettingsIdx = systemsettingsIdx - 1;
  2981. end
  2982. end
  2983.  
  2984.  
  2985. %%
  2986. % SystemStats read function
  2987. function [SystemStats] = ReadSystemStatsObject(fid, timestamp, checkCRC, SystemStats, systemstatsIdx)
  2988. SystemStats.timestamp(systemstatsIdx)= timestamp;
  2989. if 1
  2990. headerSize = 8;
  2991. else
  2992. SystemStats.instanceID(systemstatsIdx) = (fread(fid, 1, 'uint16'));
  2993. headerSize = 10;
  2994. end
  2995.  
  2996. startPos = ftell(fid) - headerSize;
  2997. SystemStats.FlightTime(systemstatsIdx) = double(fread(fid, 1, 'uint32'));
  2998. SystemStats.HeapRemaining(systemstatsIdx) = double(fread(fid, 1, 'uint16'));
  2999. SystemStats.IRQStackRemaining(systemstatsIdx) = double(fread(fid, 1, 'uint16'));
  3000. SystemStats.CPULoad(systemstatsIdx) = double(fread(fid, 1, 'uint8'));
  3001. SystemStats.CPUTemp(systemstatsIdx) = double(fread(fid, 1, 'int8'));
  3002. objLen = ftell(fid) - startPos;
  3003. % read CRC
  3004. crc_read = fread(fid, 1, '*uint8');
  3005. if checkCRC
  3006. fseek(fid, startPos, 'bof');
  3007. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  3008. fread(fid,1,'uint8');
  3009. if (crc_calc ~= crc_read)
  3010. disp('CRC Error')
  3011. systemstatsIdx = systemstatsIdx - 1;
  3012. end
  3013. end
  3014.  
  3015.  
  3016. %%
  3017. % TaskInfo read function
  3018. function [TaskInfo] = ReadTaskInfoObject(fid, timestamp, checkCRC, TaskInfo, taskinfoIdx)
  3019. TaskInfo.timestamp(taskinfoIdx)= timestamp;
  3020. if 1
  3021. headerSize = 8;
  3022. else
  3023. TaskInfo.instanceID(taskinfoIdx) = (fread(fid, 1, 'uint16'));
  3024. headerSize = 10;
  3025. end
  3026.  
  3027. startPos = ftell(fid) - headerSize;
  3028. TaskInfo.StackRemaining(:,taskinfoIdx) = double(fread(fid, 17, 'uint16'));
  3029. TaskInfo.Running(:,taskinfoIdx) = double(fread(fid, 17, 'uint8'));
  3030. TaskInfo.RunningTime(:,taskinfoIdx) = double(fread(fid, 17, 'uint8'));
  3031. objLen = ftell(fid) - startPos;
  3032. % read CRC
  3033. crc_read = fread(fid, 1, '*uint8');
  3034. if checkCRC
  3035. fseek(fid, startPos, 'bof');
  3036. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  3037. fread(fid,1,'uint8');
  3038. if (crc_calc ~= crc_read)
  3039. disp('CRC Error')
  3040. taskinfoIdx = taskinfoIdx - 1;
  3041. end
  3042. end
  3043.  
  3044.  
  3045. %%
  3046. % VelocityActual read function
  3047. function [VelocityActual] = ReadVelocityActualObject(fid, timestamp, checkCRC, VelocityActual, velocityactualIdx)
  3048. VelocityActual.timestamp(velocityactualIdx)= timestamp;
  3049. if 1
  3050. headerSize = 8;
  3051. else
  3052. VelocityActual.instanceID(velocityactualIdx) = (fread(fid, 1, 'uint16'));
  3053. headerSize = 10;
  3054. end
  3055.  
  3056. startPos = ftell(fid) - headerSize;
  3057. VelocityActual.North(velocityactualIdx) = double(fread(fid, 1, 'float32'));
  3058. VelocityActual.East(velocityactualIdx) = double(fread(fid, 1, 'float32'));
  3059. VelocityActual.Down(velocityactualIdx) = double(fread(fid, 1, 'float32'));
  3060. objLen = ftell(fid) - startPos;
  3061. % read CRC
  3062. crc_read = fread(fid, 1, '*uint8');
  3063. if checkCRC
  3064. fseek(fid, startPos, 'bof');
  3065. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  3066. fread(fid,1,'uint8');
  3067. if (crc_calc ~= crc_read)
  3068. disp('CRC Error')
  3069. velocityactualIdx = velocityactualIdx - 1;
  3070. end
  3071. end
  3072.  
  3073.  
  3074. %%
  3075. % VelocityDesired read function
  3076. function [VelocityDesired] = ReadVelocityDesiredObject(fid, timestamp, checkCRC, VelocityDesired, velocitydesiredIdx)
  3077. VelocityDesired.timestamp(velocitydesiredIdx)= timestamp;
  3078. if 1
  3079. headerSize = 8;
  3080. else
  3081. VelocityDesired.instanceID(velocitydesiredIdx) = (fread(fid, 1, 'uint16'));
  3082. headerSize = 10;
  3083. end
  3084.  
  3085. startPos = ftell(fid) - headerSize;
  3086. VelocityDesired.North(velocitydesiredIdx) = double(fread(fid, 1, 'float32'));
  3087. VelocityDesired.East(velocitydesiredIdx) = double(fread(fid, 1, 'float32'));
  3088. VelocityDesired.Down(velocitydesiredIdx) = double(fread(fid, 1, 'float32'));
  3089. objLen = ftell(fid) - startPos;
  3090. % read CRC
  3091. crc_read = fread(fid, 1, '*uint8');
  3092. if checkCRC
  3093. fseek(fid, startPos, 'bof');
  3094. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  3095. fread(fid,1,'uint8');
  3096. if (crc_calc ~= crc_read)
  3097. disp('CRC Error')
  3098. velocitydesiredIdx = velocitydesiredIdx - 1;
  3099. end
  3100. end
  3101.  
  3102.  
  3103. %%
  3104. % WatchdogStatus read function
  3105. function [WatchdogStatus] = ReadWatchdogStatusObject(fid, timestamp, checkCRC, WatchdogStatus, watchdogstatusIdx)
  3106. WatchdogStatus.timestamp(watchdogstatusIdx)= timestamp;
  3107. if 1
  3108. headerSize = 8;
  3109. else
  3110. WatchdogStatus.instanceID(watchdogstatusIdx) = (fread(fid, 1, 'uint16'));
  3111. headerSize = 10;
  3112. end
  3113.  
  3114. startPos = ftell(fid) - headerSize;
  3115. WatchdogStatus.BootupFlags(watchdogstatusIdx) = double(fread(fid, 1, 'uint16'));
  3116. WatchdogStatus.ActiveFlags(watchdogstatusIdx) = double(fread(fid, 1, 'uint16'));
  3117. objLen = ftell(fid) - startPos;
  3118. % read CRC
  3119. crc_read = fread(fid, 1, '*uint8');
  3120. if checkCRC
  3121. fseek(fid, startPos, 'bof');
  3122. crc_calc = compute_crc(uint8(fread(fid,objLen,'uint8')));
  3123. fread(fid,1,'uint8');
  3124. if (crc_calc ~= crc_read)
  3125. disp('CRC Error')
  3126. watchdogstatusIdx = watchdogstatusIdx - 1;
  3127. end
  3128. end
  3129.  
  3130.  
  3131.  
  3132.  
  3133. % This function prunes the excess pre-allocated space
  3134. function [structOut]=PruneStructOfArrays(structIn, lastIndex)
  3135.  
  3136. fieldNames = fieldnames(structIn);
  3137. for i=1:length(fieldNames)
  3138. structOut.(fieldNames{i})=structIn.(fieldNames{i})(1:lastIndex);
  3139. end
  3140.  
  3141.  
  3142. function OPLog2csv(structIn, structName, logfile)
  3143. %Get each field name from the structure
  3144. fieldNames = fieldnames(structIn);
  3145.  
  3146. %Create a text string with the field names
  3147. headerOut=sprintf('%s,',fieldNames{:});
  3148. headerOut=headerOut(1:end-1); %Trim off last `,` and `\t`
  3149.  
  3150. %Assign the structure arrays to a matrix.
  3151. matOut=zeros(max(size(structIn.(fieldNames{1}))), length(fieldNames));
  3152.  
  3153. if isempty(structIn.(fieldNames{1}));
  3154. matOut=[];
  3155. else
  3156. for i=1:length(fieldNames)
  3157. matOut(:,i)=structIn.(fieldNames{i});
  3158. end
  3159. end
  3160. % Create filename by replacing opl by csv
  3161. [path, name] = fileparts(logfile);
  3162. csvDirName=[name '_csv'];
  3163. [dummyA, dummyB]=mkdir(fullfile(path, csvDirName)); %Dummy outputs so the program doens't throw warnings about "Directory already exists"
  3164. csvfile=fullfile(path, csvDirName , [name '.csv']);
  3165.  
  3166. %Write to csv.
  3167. dlmwrite(csvfile, headerOut, '');
  3168. dlmwrite(csvfile, matOut, '-append');
  3169.  
  3170. function crc = compute_crc(data)
  3171. global crc_table;
  3172. crc = 0;
  3173. for i = 1:length(data)
  3174. crc = crc_table(1+bitxor(data(i),crc));
  3175. end
Add Comment
Please, Sign In to add comment