Bayley Wang
/
flash_configuration
flash based config testing
CommandProcessor/cmd_set_get.cpp@3:82c00c8e2cb4, 2017-03-07 (annotated)
- Committer:
- bwang
- Date:
- Tue Mar 07 08:06:39 2017 +0000
- Revision:
- 3:82c00c8e2cb4
lot's more commands
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bwang | 3:82c00c8e2cb4 | 1 | #include "mbed.h" |
bwang | 3:82c00c8e2cb4 | 2 | #include "CommandProcessor.h" |
bwang | 3:82c00c8e2cb4 | 3 | #include "PreferenceWriter.h" |
bwang | 3:82c00c8e2cb4 | 4 | #include "globals.h" |
bwang | 3:82c00c8e2cb4 | 5 | |
bwang | 3:82c00c8e2cb4 | 6 | #include "config.h" |
bwang | 3:82c00c8e2cb4 | 7 | #include "config_driving.h" |
bwang | 3:82c00c8e2cb4 | 8 | #include "config_inverter.h" |
bwang | 3:82c00c8e2cb4 | 9 | #include "config_logging.h" |
bwang | 3:82c00c8e2cb4 | 10 | #include "config_loop.h" |
bwang | 3:82c00c8e2cb4 | 11 | #include "config_motor.h" |
bwang | 3:82c00c8e2cb4 | 12 | #include "config_pins.h" |
bwang | 3:82c00c8e2cb4 | 13 | #include "config_table.h" |
bwang | 3:82c00c8e2cb4 | 14 | |
bwang | 3:82c00c8e2cb4 | 15 | void cmd_ls(Serial *pc) { |
bwang | 3:82c00c8e2cb4 | 16 | DPRINT(TORQUE_MODE); |
bwang | 3:82c00c8e2cb4 | 17 | FPRINT(MAX_TQPCT_PLUS); |
bwang | 3:82c00c8e2cb4 | 18 | FPRINT(MAX_TQPCT_MINUS); |
bwang | 3:82c00c8e2cb4 | 19 | FPRINT(TORQUE_MAX); |
bwang | 3:82c00c8e2cb4 | 20 | FPRINT(W_MAX); |
bwang | 3:82c00c8e2cb4 | 21 | FPRINT(BUS_VOLTAGE); |
bwang | 3:82c00c8e2cb4 | 22 | FPRINT(F_SW); |
bwang | 3:82c00c8e2cb4 | 23 | FPRINT(K_LOOP_D); |
bwang | 3:82c00c8e2cb4 | 24 | FPRINT(KI_BASE_D); |
bwang | 3:82c00c8e2cb4 | 25 | FPRINT(K_LOOP_Q); |
bwang | 3:82c00c8e2cb4 | 26 | FPRINT(KI_BASE_Q); |
bwang | 3:82c00c8e2cb4 | 27 | FPRINT(F_SLOW_LOOP); |
bwang | 3:82c00c8e2cb4 | 28 | FPRINT(INTEGRAL_MAX); |
bwang | 3:82c00c8e2cb4 | 29 | FPRINT(W_FILTER_STRENGTH); |
bwang | 3:82c00c8e2cb4 | 30 | FPRINT(DQ_FILTER_STRENGTH); |
bwang | 3:82c00c8e2cb4 | 31 | FPRINT(THROTTLE_FILTER_STRENGTH); |
bwang | 3:82c00c8e2cb4 | 32 | FPRINT(KP_D); |
bwang | 3:82c00c8e2cb4 | 33 | FPRINT(KI_D); |
bwang | 3:82c00c8e2cb4 | 34 | FPRINT(KP_Q); |
bwang | 3:82c00c8e2cb4 | 35 | FPRINT(KI_Q); |
bwang | 3:82c00c8e2cb4 | 36 | FPRINT(SLOW_LOOP_COUNTER); |
bwang | 3:82c00c8e2cb4 | 37 | FPRINT(POLE_PAIRS); |
bwang | 3:82c00c8e2cb4 | 38 | FPRINT(POS_OFFSET); |
bwang | 3:82c00c8e2cb4 | 39 | FPRINT(RESOLVER_LOBES); |
bwang | 3:82c00c8e2cb4 | 40 | DPRINT(CPR); |
bwang | 3:82c00c8e2cb4 | 41 | FPRINT(Ld); |
bwang | 3:82c00c8e2cb4 | 42 | FPRINT(Lq); |
bwang | 3:82c00c8e2cb4 | 43 | FPRINT(FLUX_LINKAGE); |
bwang | 3:82c00c8e2cb4 | 44 | FPRINT(Rs); |
bwang | 3:82c00c8e2cb4 | 45 | FPRINT(KT); |
bwang | 3:82c00c8e2cb4 | 46 | FPRINT(W_SAFE); |
bwang | 3:82c00c8e2cb4 | 47 | FPRINT(W_CRAZY); |
bwang | 3:82c00c8e2cb4 | 48 | DPRINT(TH_LIMIT_LOW); |
bwang | 3:82c00c8e2cb4 | 49 | DPRINT(TH_LIMIT_HIGH); |
bwang | 3:82c00c8e2cb4 | 50 | DPRINT(TH_LIMIT_CRAZY); |
bwang | 3:82c00c8e2cb4 | 51 | DPRINT(ROWS); |
bwang | 3:82c00c8e2cb4 | 52 | DPRINT(COLUMNS); |
bwang | 3:82c00c8e2cb4 | 53 | FPRINT(W_STEP); |
bwang | 3:82c00c8e2cb4 | 54 | } |
bwang | 3:82c00c8e2cb4 | 55 | |
bwang | 3:82c00c8e2cb4 | 56 | void cmd_ls2(Serial *pc, char *buf) { |
bwang | 3:82c00c8e2cb4 | 57 | if (strcmp(buf, "mode") == 0) { |
bwang | 3:82c00c8e2cb4 | 58 | pc->printf("%s\n", mode_to_str(BREMS_mode)); |
bwang | 3:82c00c8e2cb4 | 59 | return; |
bwang | 3:82c00c8e2cb4 | 60 | } |
bwang | 3:82c00c8e2cb4 | 61 | if (strcmp(buf, "src") == 0) { |
bwang | 3:82c00c8e2cb4 | 62 | pc->printf("%s\n", src_to_str(BREMS_src)); |
bwang | 3:82c00c8e2cb4 | 63 | return; |
bwang | 3:82c00c8e2cb4 | 64 | } |
bwang | 3:82c00c8e2cb4 | 65 | if (strcmp(buf, "op") == 0) { |
bwang | 3:82c00c8e2cb4 | 66 | pc->printf("%s\n", op_to_str(BREMS_op)); |
bwang | 3:82c00c8e2cb4 | 67 | return; |
bwang | 3:82c00c8e2cb4 | 68 | } |
bwang | 3:82c00c8e2cb4 | 69 | |
bwang | 3:82c00c8e2cb4 | 70 | float *fptr = checkf(buf); |
bwang | 3:82c00c8e2cb4 | 71 | if (fptr != NULL) pc->printf("%s: %f\n", buf, *fptr); |
bwang | 3:82c00c8e2cb4 | 72 | int *nptr = NULL; |
bwang | 3:82c00c8e2cb4 | 73 | if (fptr == NULL) nptr = checkn(buf); |
bwang | 3:82c00c8e2cb4 | 74 | if (nptr != NULL) pc->printf("%s: %d\n", buf, *nptr); |
bwang | 3:82c00c8e2cb4 | 75 | if (nptr == NULL && fptr == NULL) pc->printf("%s\n", "No Such Parameter"); |
bwang | 3:82c00c8e2cb4 | 76 | } |
bwang | 3:82c00c8e2cb4 | 77 | |
bwang | 3:82c00c8e2cb4 | 78 | void cmd_defaults(Serial *pc) { |
bwang | 3:82c00c8e2cb4 | 79 | DEFAULT(TORQUE_MODE); |
bwang | 3:82c00c8e2cb4 | 80 | DEFAULT(MAX_TQPCT_PLUS); |
bwang | 3:82c00c8e2cb4 | 81 | DEFAULT(MAX_TQPCT_MINUS); |
bwang | 3:82c00c8e2cb4 | 82 | DEFAULT(TORQUE_MAX); |
bwang | 3:82c00c8e2cb4 | 83 | DEFAULT(W_MAX); |
bwang | 3:82c00c8e2cb4 | 84 | DEFAULT(BUS_VOLTAGE); |
bwang | 3:82c00c8e2cb4 | 85 | DEFAULT(F_SW); |
bwang | 3:82c00c8e2cb4 | 86 | DEFAULT(K_LOOP_D); |
bwang | 3:82c00c8e2cb4 | 87 | DEFAULT(KI_BASE_D); |
bwang | 3:82c00c8e2cb4 | 88 | DEFAULT(K_LOOP_Q); |
bwang | 3:82c00c8e2cb4 | 89 | DEFAULT(KI_BASE_Q); |
bwang | 3:82c00c8e2cb4 | 90 | DEFAULT(F_SLOW_LOOP); |
bwang | 3:82c00c8e2cb4 | 91 | DEFAULT(INTEGRAL_MAX); |
bwang | 3:82c00c8e2cb4 | 92 | DEFAULT(W_FILTER_STRENGTH); |
bwang | 3:82c00c8e2cb4 | 93 | DEFAULT(DQ_FILTER_STRENGTH); |
bwang | 3:82c00c8e2cb4 | 94 | DEFAULT(THROTTLE_FILTER_STRENGTH); |
bwang | 3:82c00c8e2cb4 | 95 | DEFAULT(KP_D); |
bwang | 3:82c00c8e2cb4 | 96 | DEFAULT(KI_D); |
bwang | 3:82c00c8e2cb4 | 97 | DEFAULT(KP_Q); |
bwang | 3:82c00c8e2cb4 | 98 | DEFAULT(KI_Q); |
bwang | 3:82c00c8e2cb4 | 99 | DEFAULT(SLOW_LOOP_COUNTER); |
bwang | 3:82c00c8e2cb4 | 100 | DEFAULT(POLE_PAIRS); |
bwang | 3:82c00c8e2cb4 | 101 | DEFAULT(POS_OFFSET); |
bwang | 3:82c00c8e2cb4 | 102 | DEFAULT(RESOLVER_LOBES); |
bwang | 3:82c00c8e2cb4 | 103 | DEFAULT(CPR); |
bwang | 3:82c00c8e2cb4 | 104 | DEFAULT(Ld); |
bwang | 3:82c00c8e2cb4 | 105 | DEFAULT(Lq); |
bwang | 3:82c00c8e2cb4 | 106 | DEFAULT(FLUX_LINKAGE); |
bwang | 3:82c00c8e2cb4 | 107 | DEFAULT(Rs); |
bwang | 3:82c00c8e2cb4 | 108 | DEFAULT(KT); |
bwang | 3:82c00c8e2cb4 | 109 | DEFAULT(W_SAFE); |
bwang | 3:82c00c8e2cb4 | 110 | DEFAULT(W_CRAZY); |
bwang | 3:82c00c8e2cb4 | 111 | DEFAULT(TH_LIMIT_LOW); |
bwang | 3:82c00c8e2cb4 | 112 | DEFAULT(TH_LIMIT_HIGH); |
bwang | 3:82c00c8e2cb4 | 113 | DEFAULT(TH_LIMIT_CRAZY); |
bwang | 3:82c00c8e2cb4 | 114 | DEFAULT(ROWS); |
bwang | 3:82c00c8e2cb4 | 115 | DEFAULT(COLUMNS); |
bwang | 3:82c00c8e2cb4 | 116 | DEFAULT(W_STEP); |
bwang | 3:82c00c8e2cb4 | 117 | pc->printf("Defaults Loaded\n"); |
bwang | 3:82c00c8e2cb4 | 118 | } |
bwang | 3:82c00c8e2cb4 | 119 | |
bwang | 3:82c00c8e2cb4 | 120 | void cmd_reload(Serial *pc, PreferenceWriter *pref) { |
bwang | 3:82c00c8e2cb4 | 121 | pref->load(); |
bwang | 3:82c00c8e2cb4 | 122 | pc->printf("Flash Values Loaded\n"); |
bwang | 3:82c00c8e2cb4 | 123 | } |
bwang | 3:82c00c8e2cb4 | 124 | |
bwang | 3:82c00c8e2cb4 | 125 | void cmd_set(Serial *pc, char *buf, char *val) { |
bwang | 3:82c00c8e2cb4 | 126 | float *fptr = checkf(buf); |
bwang | 3:82c00c8e2cb4 | 127 | if (fptr != NULL) *fptr = (float) (atof(val)); |
bwang | 3:82c00c8e2cb4 | 128 | int *nptr = NULL; |
bwang | 3:82c00c8e2cb4 | 129 | if (fptr == NULL) nptr = checkn(buf); |
bwang | 3:82c00c8e2cb4 | 130 | if (nptr != NULL) *nptr = (int) (atoi(val)); |
bwang | 3:82c00c8e2cb4 | 131 | cmd_ls2(pc, buf); |
bwang | 3:82c00c8e2cb4 | 132 | if (nptr == NULL && fptr == NULL) pc->printf("%s\n", "No Such Parameter"); |
bwang | 3:82c00c8e2cb4 | 133 | } |
bwang | 3:82c00c8e2cb4 | 134 | |
bwang | 3:82c00c8e2cb4 | 135 | void cmd_flush(Serial *pc, PreferenceWriter *pref) { |
bwang | 3:82c00c8e2cb4 | 136 | if (!pref->ready()) pref->open(); |
bwang | 3:82c00c8e2cb4 | 137 | pref->flush(); |
bwang | 3:82c00c8e2cb4 | 138 | } |