correcting MSP implementation, optimizations

pull/3/head
cTn 11 years ago
parent e01160dae7
commit 74e9256e75

@ -2,35 +2,35 @@ function configuration_backup() {
// request configuration data (one by one)
function get_ident_data() {
send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT, false, get_status_data);
send_message(MSP_codes.MSP_IDENT, false, false, get_status_data);
}
function get_status_data() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS, false, get_pid_data);
send_message(MSP_codes.MSP_STATUS, false, false, get_pid_data);
}
function get_pid_data() {
send_message(MSP_codes.MSP_PID, MSP_codes.MSP_PID, false, get_rc_tuning_data);
send_message(MSP_codes.MSP_PID, false, false, get_rc_tuning_data);
}
function get_rc_tuning_data() {
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING, false, get_box_names_data);
send_message(MSP_codes.MSP_RC_TUNING, false, false, get_box_names_data);
}
function get_box_names_data() {
send_message(MSP_codes.MSP_BOXNAMES, MSP_codes.MSP_BOXNAMES, false, get_box_data);
send_message(MSP_codes.MSP_BOXNAMES, false, false, get_box_data);
}
function get_box_data() {
send_message(MSP_codes.MSP_BOX, MSP_codes.MSP_BOX, false, get_acc_trim_data);
send_message(MSP_codes.MSP_BOX, false, false, get_acc_trim_data);
}
function get_acc_trim_data() {
send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM, false, get_misc_data);
send_message(MSP_codes.MSP_ACC_TRIM, false, false, get_misc_data);
}
function get_misc_data() {
send_message(MSP_codes.MSP_MISC, MSP_codes.MSP_MISC, false, backup);
send_message(MSP_codes.MSP_MISC, false, false, backup);
}
function backup() {
@ -222,9 +222,7 @@ function configuration_upload() {
}
// Send over the PID changes
send_message(MSP_codes.MSP_SET_PID, PID_buffer_out, false, function() {
rc_tuning();
});
send_message(MSP_codes.MSP_SET_PID, PID_buffer_out, false, rc_tuning);
function rc_tuning() {
// RC Tuning section
@ -238,9 +236,7 @@ function configuration_upload() {
RC_tuning_buffer_out[6] = parseInt(RC_tuning.throttle_EXPO * 100);
// Send over the RC_tuning changes
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out, false, function() {
aux();
});
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out, false, aux);
}
function aux() {
@ -254,9 +250,7 @@ function configuration_upload() {
}
// Send over the AUX changes
send_message(MSP_codes.MSP_SET_BOX, AUX_val_buffer_out, false, function() {
trim();
});
send_message(MSP_codes.MSP_SET_BOX, AUX_val_buffer_out, false, trim);
}
// Trim section
@ -268,9 +262,7 @@ function configuration_upload() {
buffer_out[3] = highByte(CONFIG.accelerometerTrims[1]);
// Send over the new trims
send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out, false, function() {
misc();
});
send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out, false, misc);
}
function misc() {
@ -303,7 +295,7 @@ function configuration_upload() {
// Send ove the new MISC
send_message(MSP_codes.MSP_SET_MISC, buffer_out, false, function() {
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function() {
GUI.log('EEPROM <span style="color: green">saved</span>');
});
});

@ -379,16 +379,16 @@ MSP.process_data = function(code, message_buffer, message_length) {
// With new flight software settings in place, we have to re-pull
// latest values
send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT);
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_PID, MSP_codes.MSP_PID);
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING);
send_message(MSP_codes.MSP_BOXNAMES, MSP_codes.MSP_BOXNAMES);
send_message(MSP_codes.MSP_BOX, MSP_codes.MSP_BOX);
send_message(MSP_codes.MSP_IDENT);
send_message(MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_PID);
send_message(MSP_codes.MSP_RC_TUNING);
send_message(MSP_codes.MSP_BOXNAMES);
send_message(MSP_codes.MSP_BOX);
// baseflight specific
send_message(MSP_codes.MSP_UID, MSP_codes.MSP_UID);
send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM);
send_message(MSP_codes.MSP_UID);
send_message(MSP_codes.MSP_ACC_TRIM);
break;
case MSP_codes.MSP_SELECT_SETTING:
console.log('Profile selected');
@ -464,7 +464,7 @@ function send_message(code, data, callback_sent, callback_msp) {
var bufView;
// always reserve 6 bytes for protocol overhead !
if (typeof data === 'object') {
if (data) {
var size = data.length + 6;
var checksum = 0;
@ -487,7 +487,7 @@ function send_message(code, data, callback_sent, callback_msp) {
bufView[5 + data.length] = checksum;
} else {
bufferOut = new ArrayBuffer(7);
bufferOut = new ArrayBuffer(6);
bufView = new Uint8Array(bufferOut);
bufView[0] = 36; // $
@ -495,8 +495,7 @@ function send_message(code, data, callback_sent, callback_msp) {
bufView[2] = 60; // <
bufView[3] = 0; // data length
bufView[4] = code; // code
bufView[5] = data; // data
bufView[6] = bufView[3] ^ bufView[4] ^ bufView[5]; // checksum
bufView[5] = bufView[3] ^ bufView[4]; // checksum
}
// utilizing callback/timeout system for all commands

@ -155,9 +155,9 @@ function onOpen(openInfo) {
}, 10000);
// request configuration data
send_message(MSP_codes.MSP_UID, MSP_codes.MSP_UID, false, function() {
send_message(MSP_codes.MSP_UID, false, false, function() {
GUI.log('Unique device ID <span style="color: green">received</span> - <strong>0x' + CONFIG.uid[0].toString(16) + CONFIG.uid[1].toString(16) + CONFIG.uid[2].toString(16) + '</strong>');
send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT, false, function() {
send_message(MSP_codes.MSP_IDENT, false, false, function() {
GUI.timeout_remove('connecting'); // kill connecting timer
GUI.log(chrome.i18n.getMessage('firmware_version', [CONFIG.version]));

@ -2,10 +2,10 @@ function tab_initialize_auxiliary_configuration() {
ga_tracker.sendAppView('Auxiliary Configuration');
GUI.active_tab = 'auxiliary_configuration';
send_message(MSP_codes.MSP_BOXNAMES, MSP_codes.MSP_BOXNAMES, false, get_box_data);
send_message(MSP_codes.MSP_BOXNAMES, false, false, get_box_data);
function get_box_data() {
send_message(MSP_codes.MSP_BOX, MSP_codes.MSP_BOX, false, load_html);
send_message(MSP_codes.MSP_BOX, false, false, load_html);
}
function load_html() {
@ -94,7 +94,7 @@ function tab_initialize_auxiliary_configuration() {
send_message(MSP_codes.MSP_SET_BOX, AUX_val_buffer_out, false, save_to_eeprom);
function save_to_eeprom() {
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function() {
GUI.log('EEPROM <span style="color: green">saved</span>');
var element = $('a.update');
@ -109,7 +109,7 @@ function tab_initialize_auxiliary_configuration() {
// data pulling functions used inside interval timer
function get_rc_data() {
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC, false, update_ui);
send_message(MSP_codes.MSP_RC, false, false, update_ui);
}
function update_ui() {
@ -136,7 +136,7 @@ function tab_initialize_auxiliary_configuration() {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_STATUS);
}, 250, true);
}
}

@ -2,7 +2,7 @@ function tab_initialize_gps () {
ga_tracker.sendAppView('GPS Page');
GUI.active_tab = 'gps';
send_message(MSP_codes.MSP_RAW_GPS, MSP_codes.MSP_RAW_GPS, false, load_html);
send_message(MSP_codes.MSP_RAW_GPS, false, false, load_html);
function load_html() {
$('#content').load("./tabs/gps.html", process_html);
@ -10,11 +10,11 @@ function tab_initialize_gps () {
function process_html() {
function get_raw_gps_data() {
send_message(MSP_codes.MSP_RAW_GPS, MSP_codes.MSP_RAW_GPS, false, get_gpsvinfo_data);
send_message(MSP_codes.MSP_RAW_GPS, false, false, get_gpsvinfo_data);
}
function get_gpsvinfo_data() {
send_message(MSP_codes.MSP_GPSSVINFO, MSP_codes.MSP_GPSSVINFO, false, update_ui);
send_message(MSP_codes.MSP_GPSSVINFO, false, false, update_ui);
}
function update_ui() {
@ -42,7 +42,7 @@ function tab_initialize_gps () {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_STATUS);
}, 250, true);
}
}

@ -2,10 +2,10 @@ function tab_initialize_initial_setup() {
ga_tracker.sendAppView('Initial Setup');
GUI.active_tab = 'initial_setup';
send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM, false, load_misc_data);
send_message(MSP_codes.MSP_ACC_TRIM, false, false, load_misc_data);
function load_misc_data() {
send_message(MSP_codes.MSP_MISC, MSP_codes.MSP_MISC, false, load_html);
send_message(MSP_codes.MSP_MISC, false, false, load_html);
}
function load_html() {
@ -107,7 +107,7 @@ function tab_initialize_initial_setup() {
// During this period MCU won't be able to process any serial commands because its locked in a for/while loop
// until this operation finishes, sending more commands through data_poll() will result in serial buffer overflow
GUI.interval_pause('initial_setup_data_pull');
send_message(MSP_codes.MSP_ACC_CALIBRATION, MSP_codes.MSP_ACC_CALIBRATION, false, function() {
send_message(MSP_codes.MSP_ACC_CALIBRATION, false, false, function() {
GUI.log('Accelerometer calibration started');
});
@ -127,7 +127,7 @@ function tab_initialize_initial_setup() {
if (!self.hasClass('calibrating')) {
self.addClass('calibrating');
send_message(MSP_codes.MSP_MAG_CALIBRATION, MSP_codes.MSP_MAG_CALIBRATION, false, function() {
send_message(MSP_codes.MSP_MAG_CALIBRATION, false, false, function() {
GUI.log('Magnetometer calibration started');
});
@ -139,7 +139,7 @@ function tab_initialize_initial_setup() {
});
$('a.resetSettings').click(function() {
send_message(MSP_codes.MSP_RESET_CONF, MSP_codes.MSP_RESET_CONF, false, function() {
send_message(MSP_codes.MSP_RESET_CONF, false, false, function() {
GUI.log('Settings restored to <strong>default</strong>');
GUI.tab_switch_cleanup(function() {
@ -202,7 +202,7 @@ function tab_initialize_initial_setup() {
send_message(MSP_codes.MSP_SET_MISC, buffer_out, false, save_to_eeprom);
function save_to_eeprom() {
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function() {
GUI.log('EEPROM <span style="color: green">saved</span>');
var element = $('a.update');
@ -227,11 +227,11 @@ function tab_initialize_initial_setup() {
// data pulling functions used inside interval timer
function get_analog_data() {
send_message(MSP_codes.MSP_ANALOG, MSP_codes.MSP_ANALOG, false, get_attitude_data);
send_message(MSP_codes.MSP_ANALOG, false, false, get_attitude_data);
}
function get_attitude_data() {
send_message(MSP_codes.MSP_ATTITUDE, MSP_codes.MSP_ATTITUDE, false, update_ui);
send_message(MSP_codes.MSP_ATTITUDE, false, false, update_ui);
}
function update_ui() {
@ -257,7 +257,7 @@ function tab_initialize_initial_setup() {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_STATUS);
}, 250, true);
}
}

@ -2,10 +2,10 @@ function tab_initialize_motor_outputs() {
ga_tracker.sendAppView('Motor Outputs Page');
GUI.active_tab = 'motor_outputs';
send_message(MSP_codes.MSP_MISC, MSP_codes.MSP_MISC, false, get_motor_data);
send_message(MSP_codes.MSP_MISC, false, false, get_motor_data);
function get_motor_data() {
send_message(MSP_codes.MSP_MOTOR, MSP_codes.MSP_MOTOR, false, load_html);
send_message(MSP_codes.MSP_MOTOR, false, false, load_html);
}
function load_html() {
@ -77,11 +77,11 @@ function tab_initialize_motor_outputs() {
// data pulling functions used inside interval timer
function get_motor_data() {
send_message(MSP_codes.MSP_MOTOR, MSP_codes.MSP_MOTOR, false, get_servo_data);
send_message(MSP_codes.MSP_MOTOR, false, false, get_servo_data);
}
function get_servo_data() {
send_message(MSP_codes.MSP_SERVO, MSP_codes.MSP_SERVO, false, update_ui);
send_message(MSP_codes.MSP_SERVO, false, false, update_ui);
}
function update_ui() {
@ -111,7 +111,7 @@ function tab_initialize_motor_outputs() {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_STATUS);
}, 250, true);
}
}

@ -3,14 +3,14 @@ function tab_initialize_pid_tuning() {
GUI.active_tab = 'pid_tuning';
// requesting MSP_STATUS manually because it contains CONFIG.profile
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS, false, get_pid_data);
send_message(MSP_codes.MSP_STATUS, false, false, get_pid_data);
function get_pid_data() {
send_message(MSP_codes.MSP_PID, MSP_codes.MSP_PID, false, get_rc_tuning_data);
send_message(MSP_codes.MSP_PID, false, false, get_rc_tuning_data);
}
function get_rc_tuning_data() {
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING, false, load_html);
send_message(MSP_codes.MSP_RC_TUNING, false, false, load_html);
}
function load_html() {
@ -278,7 +278,7 @@ function tab_initialize_pid_tuning() {
}
function save_to_eeprom() {
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function() {
GUI.log('EEPROM <span style="color: green">saved</span>');
var element = $('a.update');
@ -293,7 +293,7 @@ function tab_initialize_pid_tuning() {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_STATUS);
}, 250, true);
}
}

@ -2,10 +2,10 @@ function tab_initialize_receiver() {
ga_tracker.sendAppView('Receiver Page');
GUI.active_tab = 'receiver';
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING, false, get_rc_data);
send_message(MSP_codes.MSP_RC_TUNING, false, false, get_rc_data);
function get_rc_data() {
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC, false, load_html);
send_message(MSP_codes.MSP_RC, false, false, load_html);
}
function load_html() {
@ -79,7 +79,7 @@ function tab_initialize_receiver() {
}).change();
$('a.refresh').click(function() {
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING, false, function() {
send_message(MSP_codes.MSP_RC_TUNING, false, false, function() {
GUI.log('RC Tuning data <strong>refreshed</strong>');
// fill in data from RC_tuning
@ -116,7 +116,7 @@ function tab_initialize_receiver() {
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out, false, save_to_eeprom);
function save_to_eeprom() {
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function() {
GUI.log('EEPROM <span style="color: green">saved</span>');
var element = $('a.update');
@ -137,7 +137,7 @@ function tab_initialize_receiver() {
chrome.storage.local.set({'rx_refresh_rate': plot_update_rate});
function get_rc_data() {
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC, false, update_ui);
send_message(MSP_codes.MSP_RC, false, false, update_ui);
}
var meter_array = [];
@ -347,7 +347,7 @@ function tab_initialize_receiver() {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_STATUS);
}, 250, true);
}
}

@ -222,19 +222,19 @@ function tab_initialize_sensors() {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_STATUS);
}, 250, true);
GUI.interval_add('IMU_pull', function imu_data_pull() {
send_message(MSP_codes.MSP_RAW_IMU, MSP_codes.MSP_RAW_IMU, false, update_imu_graphs);
send_message(MSP_codes.MSP_RAW_IMU, false, false, update_imu_graphs);
}, fastest, true);
GUI.interval_add('altitude_pull', function altitude_data_pull() {
send_message(MSP_codes.MSP_ALTITUDE, MSP_codes.MSP_ALTITUDE, false, update_altitude_graph);
send_message(MSP_codes.MSP_ALTITUDE, false, false, update_altitude_graph);
}, rates.baro, true);
GUI.interval_add('debug_pull', function debug_data_pull() {
send_message(MSP_codes.MSP_DEBUG, MSP_codes.MSP_DEBUG, false, update_debug_graphs);
send_message(MSP_codes.MSP_DEBUG, false, false, update_debug_graphs);
}, rates.debug, true);
function update_imu_graphs() {

@ -9,14 +9,14 @@ function tab_initialize_servos() {
ga_tracker.sendAppView('Servos');
GUI.active_tab = 'servos';
send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT, false, get_servo_conf_data);
send_message(MSP_codes.MSP_IDENT, false, false, get_servo_conf_data);
function get_servo_conf_data() {
send_message(MSP_codes.MSP_SERVO_CONF, MSP_codes.MSP_SERVO_CONF, false, get_boxnames_data);
send_message(MSP_codes.MSP_SERVO_CONF, false, false, get_boxnames_data);
}
function get_boxnames_data() {
send_message(MSP_codes.MSP_BOXNAMES, MSP_codes.MSP_BOXNAMES, false, load_html);
send_message(MSP_codes.MSP_BOXNAMES, false, false, load_html);
}
function load_html() {
@ -176,7 +176,7 @@ function tab_initialize_servos() {
if (save_to_eeprom) {
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function() {
GUI.log('EEPROM <span style="color: green">saved</span>');
var element = $('a.update');
@ -297,7 +297,7 @@ function tab_initialize_servos() {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_STATUS);
}, 250, true);
}
}
Loading…
Cancel
Save