function DUT_callback(obj, event, DUT_port) persistent stored_data; if isempty(stored_data) stored_data = []; end if ~strcmp(DUT_port.status,'open') return; end if ~DUT_port.BytesAvailable return; end try new_data = fread(DUT_port,DUT_port.BytesAvailable); catch exception fprintf('ERROR: Failed to read from DUT port. Shutting down.\n'); cleanup(); return; end data_array = [stored_data;new_data]; packet.NewPacket = 1; while packet.NewPacket == 1 [packet,data_array] = parse_serial_data(data_array); % Report bad checksum if appropriate if packet.BadChecksum end % If packet was received, do stuff with it if packet.NewPacket == 1 % HANDLE RAW GYRO DATA PACKET if packet.Address == 86 % Extract the gyro data gyro_x = typecast( flipud(uint8(packet.data(1:2))), 'int16' ); gyro_y = typecast( flipud(uint8(packet.data(3:4))), 'int16' ); gyro_z = typecast( flipud(uint8(packet.data(5:6))), 'int16' ); got_gyro_data = 1; % fprintf('%d\t%d\t%d\n',gyro_x,gyro_y,gyro_z); end % HANDLE TEMPERATURE DATA PACKET if packet.Address == 118 temperature = typecast( flipud(uint8(packet.data(1:4))), 'single' ); got_temperature_data = 1; % fprintf('%3.2f\n',temperature); end % If we received gyro and temperature data, log it to % the workspace if logging is enabled. if got_temperature_data && got_gyro_data got_temperature_data = 0; got_gyro_data = 0; if GDATA.logging_data == 1 && GDATA.selected_DUT > 0 if GDATA.DUT_samples_collected < GDATA.MAX_SAMPLES GDATA.DUT_samples_collected = GDATA.DUT_samples_collected + 1; GDATA.DUT_data(GDATA.DUT_samples_collected,:) = [single([GDATA.selected_DUT,gyro_x,gyro_y,gyro_z]),temperature]; else fprintf('Maximum datapoints were collected. Logging disabled.\n'); GDATA.logging_data = 0; end end end end end
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)