mirror of https://github.com/rusefi/bldc.git
Added stat-extensions
This commit is contained in:
parent
40e9e29075
commit
50ec161b0a
|
@ -323,6 +323,36 @@ Read system info parameter param. Example:
|
|||
(sysinfo 'compiler) ; GCC version, e.g. 7.3.1
|
||||
```
|
||||
|
||||
#### stats
|
||||
|
||||
```clj
|
||||
(stats param)
|
||||
```
|
||||
|
||||
Get statistics about the selected motor since boot (or since stats-reset). The following example shows which stats are available:
|
||||
|
||||
```clj
|
||||
(stats 'stat-speed-avg) ; Average speed in m/s
|
||||
(stats 'stat-speed-max) ; Maximum speed in m/s
|
||||
(stats 'stat-power-avg) ; Average power in W
|
||||
(stats 'stat-power-max) ; Maximum power in W
|
||||
(stats 'stat-current-avg) ; Average current in A
|
||||
(stats 'stat-current-max) ; Maximum current in A
|
||||
(stats 'stat-temp-mosfet-avg) ; Average MOSFET temp in degC
|
||||
(stats 'stat-temp-mosfet-max) ; Maximum MOSFET temp in degC
|
||||
(stats 'stat-temp-motor-avg) ; Average motor temp in degC
|
||||
(stats 'stat-temp-motor-max) ; Maximum motor temp in degC
|
||||
(stats 'stat-count-time) ; Time since start of stat collection in seconds
|
||||
```
|
||||
|
||||
#### stats-reset
|
||||
|
||||
```clj
|
||||
(stats-reset)
|
||||
```
|
||||
|
||||
Reset stat counters to 0.
|
||||
|
||||
### App Override Commands
|
||||
|
||||
Several app-inputs can be detached from the external interfaces and overridden from lisp. This is useful to take advantage of existing throttle curves and control modes from the apps while providing a custom input source.
|
||||
|
|
|
@ -150,6 +150,19 @@ typedef struct {
|
|||
lbm_uint git_hash;
|
||||
lbm_uint compiler;
|
||||
|
||||
// Statistics
|
||||
lbm_uint stat_speed_avg;
|
||||
lbm_uint stat_speed_max;
|
||||
lbm_uint stat_power_avg;
|
||||
lbm_uint stat_power_max;
|
||||
lbm_uint stat_current_avg;
|
||||
lbm_uint stat_current_max;
|
||||
lbm_uint stat_temp_mosfet_avg;
|
||||
lbm_uint stat_temp_mosfet_max;
|
||||
lbm_uint stat_temp_motor_avg;
|
||||
lbm_uint stat_temp_motor_max;
|
||||
lbm_uint stat_count_time;
|
||||
|
||||
// Rates
|
||||
lbm_uint rate_100k;
|
||||
lbm_uint rate_200k;
|
||||
|
@ -362,6 +375,30 @@ static bool compare_symbol(lbm_uint sym, lbm_uint *comp) {
|
|||
get_add_symbol("compiler", comp);
|
||||
}
|
||||
|
||||
else if (comp == &syms_vesc.stat_speed_avg) {
|
||||
get_add_symbol("stat-speed-avg", comp);
|
||||
} else if (comp == &syms_vesc.stat_speed_max) {
|
||||
get_add_symbol("stat-speed-max", comp);
|
||||
} else if (comp == &syms_vesc.stat_power_avg) {
|
||||
get_add_symbol("stat-power-avg", comp);
|
||||
} else if (comp == &syms_vesc.stat_power_max) {
|
||||
get_add_symbol("stat-power-max", comp);
|
||||
} else if (comp == &syms_vesc.stat_current_avg) {
|
||||
get_add_symbol("stat-current-avg", comp);
|
||||
} else if (comp == &syms_vesc.stat_current_max) {
|
||||
get_add_symbol("stat-current-max", comp);
|
||||
} else if (comp == &syms_vesc.stat_temp_mosfet_avg) {
|
||||
get_add_symbol("stat-temp-mosfet-avg", comp);
|
||||
} else if (comp == &syms_vesc.stat_temp_mosfet_max) {
|
||||
get_add_symbol("stat-temp-mosfet-max", comp);
|
||||
} else if (comp == &syms_vesc.stat_temp_motor_avg) {
|
||||
get_add_symbol("stat-temp-motor-avg", comp);
|
||||
} else if (comp == &syms_vesc.stat_temp_motor_max) {
|
||||
get_add_symbol("stat-temp-motor-max", comp);
|
||||
} else if (comp == &syms_vesc.stat_count_time) {
|
||||
get_add_symbol("stat-count-time", comp);
|
||||
}
|
||||
|
||||
else if (comp == &syms_vesc.rate_100k) {
|
||||
get_add_symbol("rate-100k", comp);
|
||||
} else if (comp == &syms_vesc.rate_200k) {
|
||||
|
@ -1033,6 +1070,52 @@ static lbm_value ext_sysinfo(lbm_value *args, lbm_uint argn) {
|
|||
return res;
|
||||
}
|
||||
|
||||
static lbm_value ext_stats(lbm_value *args, lbm_uint argn) {
|
||||
lbm_value res = ENC_SYM_EERROR;
|
||||
|
||||
if (argn != 1) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (lbm_type_of(args[0]) != LBM_TYPE_SYMBOL) {
|
||||
return res;
|
||||
}
|
||||
|
||||
lbm_uint name = lbm_dec_sym(args[0]);
|
||||
|
||||
if (compare_symbol(name, &syms_vesc.stat_speed_avg)) {
|
||||
res = lbm_enc_float(mc_interface_stat_speed_avg());
|
||||
} else if (compare_symbol(name, &syms_vesc.stat_speed_max)) {
|
||||
res = lbm_enc_float(mc_interface_stat_speed_max());
|
||||
} else if (compare_symbol(name, &syms_vesc.stat_power_avg)) {
|
||||
res = lbm_enc_float(mc_interface_stat_power_avg());
|
||||
} else if (compare_symbol(name, &syms_vesc.stat_power_max)) {
|
||||
res = lbm_enc_float(mc_interface_stat_power_max());
|
||||
} else if (compare_symbol(name, &syms_vesc.stat_current_avg)) {
|
||||
res = lbm_enc_float(mc_interface_stat_current_avg());
|
||||
} else if (compare_symbol(name, &syms_vesc.stat_current_max)) {
|
||||
res = lbm_enc_float(mc_interface_stat_current_max());
|
||||
} else if (compare_symbol(name, &syms_vesc.stat_temp_mosfet_avg)) {
|
||||
res = lbm_enc_float(mc_interface_stat_temp_mosfet_avg());
|
||||
} else if (compare_symbol(name, &syms_vesc.stat_temp_mosfet_max)) {
|
||||
res = lbm_enc_float(mc_interface_stat_temp_mosfet_max());
|
||||
} else if (compare_symbol(name, &syms_vesc.stat_temp_motor_avg)) {
|
||||
res = lbm_enc_float(mc_interface_stat_temp_motor_avg());
|
||||
} else if (compare_symbol(name, &syms_vesc.stat_temp_motor_max)) {
|
||||
res = lbm_enc_float(mc_interface_stat_temp_motor_max());
|
||||
} else if (compare_symbol(name, &syms_vesc.stat_count_time)) {
|
||||
res = lbm_enc_float(mc_interface_stat_count_time());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static lbm_value ext_stats_reset(lbm_value *args, lbm_uint argn) {
|
||||
(void)args;(void)argn;
|
||||
mc_interface_stat_reset();
|
||||
return ENC_SYM_TRUE;
|
||||
}
|
||||
|
||||
// App set commands
|
||||
static lbm_value ext_app_adc_detach(lbm_value *args, lbm_uint argn) {
|
||||
if (argn == 1){
|
||||
|
@ -4293,6 +4376,8 @@ void lispif_load_vesc_extensions(void) {
|
|||
lbm_add_extension("eeprom-store-i", ext_eeprom_store_i);
|
||||
lbm_add_extension("eeprom-read-i", ext_eeprom_read_i);
|
||||
lbm_add_extension("sysinfo", ext_sysinfo);
|
||||
lbm_add_extension("stats", ext_stats);
|
||||
lbm_add_extension("stats-reset", ext_stats_reset);
|
||||
lbm_add_extension("import", ext_empty);
|
||||
|
||||
// APP commands
|
||||
|
|
Loading…
Reference in New Issue