1 fn = '~/Documents/Programming/serial_logger/bma180_l3gd20_desk_20120228.dat';
2 fn = '~/Documents/Programming/serial_logger/mpu6000_desk_20120228.dat';
3 fn = '~/Documents/Programming/serial_logger/mpu6000_desk2_20110228.dat';
4 fn = '~/Documents/Programming/serial_logger/output.dat';
6 dat = uint8(fread(fid,'uint8'));
18 latitude = zeros(4096,1);
19 longitude = zeros(4096,1);
20 altitude = zeros(4096,1);
21 heading = zeros(4096,1);
22 groundspeed = zeros(4096,1);
23 gps_satellites = zeros(4096,1);
24 gps_time = zeros(4096,1);
36 while head < (length(dat) - 200)
42 disp(sprintf('Processed: %0.3g%% Bad: %0.3g%%',(head/total) * 100,bad_samples * 100 / (bad_samples + good_samples)));
45 idx = find(dat(head+1:head+100)==255,1,'first');
54 time = double(dat(head+1))* 256 + double(dat(head+2));%typecast(flipud(dat(head+(1:2))),'uint16');
55 if min([(time - last_time) (last_time - time)]) > 2
56 disp(['Err' num2str(time-last_time)]);
58 bad_samples = bad_samples + (head - last_head);
66 accel_idx = accel_idx + 1;
67 if accel_idx > size(accel,1)
68 accel(accel_idx * 2,:) = 0;
70 accel(accel_idx,1:3) = typecast(dat(head+(1:12)),'single');
72 accel(accel_idx,4) = time;
75 gyro_idx = gyro_idx + 1;
76 if gyro_idx > size(gyro,1);
77 gyro(gyro_idx * 2,:) = 0;
79 gyro(gyro_idx,1:4) = typecast(dat(head+(1:16)),'single');
81 gyro(gyro_idx,5) = time;
83 if dat(head+1) == 1 % Process the mag data
85 mag_idx = mag_idx + 1;
86 if mag_idx > size(mag,1)
87 mag(mag_idx * 2, :) = 0;
89 mag(mag_idx,1:3) = typecast(dat(head + (1:12)),'single');
91 mag(mag_idx,4) = time;
94 if dat(head+1) == 2 % Process the GPS data
99 % float GeoidSeparation;
107 % } __attribute__((packed)) GPSPositionData;
111 gps_idx = gps_idx + 1;
112 if gps_idx > length(latitude)
113 latitude(gps_idx * 2) = 0;
114 longitude(gps_idx * 2) = 0;
115 altitude(gps_idx * 2) = 0;
116 heading(gps_idx * 2) = 0;
117 groundspeed(gps_idx * 2) = 0;
118 gps_satellites(gps_idx * 2) = 0;
119 gps_time(gps_idx * 2) = 0;
122 latitude(gps_idx) = double(typecast(dat(head+(1:4)),'int32')) / 1e7;
123 longitude(gps_idx) = double(typecast(dat(head+(5:8)),'int32')) / 1e7;
124 altitude(gps_idx) = typecast(dat(head+(9:12)),'single');
125 heading(gps_idx) = typecast(dat(head+(17:20)),'single');
126 groundspeed(gps_idx) = typecast(dat(head+(21:24)),'single');
127 gps_satelites(gps_idx) = dat(head+38);
128 gps_time(gps_idx) = time;
129 head = head + 9 * 4 + 2;
132 if dat(head+1) == 3 % Process the baro data
134 baro_idx = baro_idx + 1;
135 if baro_idx > size(baro,1)
136 baro(baro_idx * 2,:) = 0;
138 baro(baro_idx,1) = typecast(dat(head+(1:4)),'single');
139 baro(baro_idx,2) = time;
142 good_samples = good_samples + (head - last_head);
145 accel(accel_idx+1:end,:) = [];
146 gyro(gyro_idx+1:end,:) = [];
147 mag(mag_idx+1:end) = [];
148 latitude(gps_idx+1:end) = [];
149 longitude(gps_idx+1:end) = [];
150 altitude(gps_idx+1:end) = [];
151 groundspeed(gps_idx+1:end) = [];
152 gps_satellites(gps_idx+1:end) = [];
153 gps_time(gps_idx+1:end) = [];
154 baro(baro_idx+1:end,:) = [];