flash based config testing

Dependencies:   mbed

Committer:
bwang
Date:
Tue Mar 07 08:06:39 2017 +0000
Revision:
3:82c00c8e2cb4
lot's more commands

Who changed what in which revision?

UserRevisionLine numberNew 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 int tokenize(char *buf, char **out, int max) {
bwang 3:82c00c8e2cb4 16 char* tok;
bwang 3:82c00c8e2cb4 17 int k = 0;
bwang 3:82c00c8e2cb4 18
bwang 3:82c00c8e2cb4 19 tok = strtok(buf, " ");
bwang 3:82c00c8e2cb4 20
bwang 3:82c00c8e2cb4 21 while(tok != NULL && k < max) {
bwang 3:82c00c8e2cb4 22 out[k] = tok;
bwang 3:82c00c8e2cb4 23 k++;
bwang 3:82c00c8e2cb4 24 tok = strtok(NULL, " ");
bwang 3:82c00c8e2cb4 25 }
bwang 3:82c00c8e2cb4 26 return k;
bwang 3:82c00c8e2cb4 27 }
bwang 3:82c00c8e2cb4 28
bwang 3:82c00c8e2cb4 29 #define __check(x) if(strcmp(s, #x) == 0) return &_##x
bwang 3:82c00c8e2cb4 30 #define __check2(x) if (strcmp(s, #x) == 0) return &x
bwang 3:82c00c8e2cb4 31
bwang 3:82c00c8e2cb4 32 float* checkf(char *s) {
bwang 3:82c00c8e2cb4 33 __check(MAX_TQPCT_PLUS);
bwang 3:82c00c8e2cb4 34 __check(MAX_TQPCT_MINUS);
bwang 3:82c00c8e2cb4 35 __check(TORQUE_MAX);
bwang 3:82c00c8e2cb4 36 __check(W_MAX);
bwang 3:82c00c8e2cb4 37 __check(BUS_VOLTAGE);
bwang 3:82c00c8e2cb4 38 __check(F_SW);
bwang 3:82c00c8e2cb4 39 __check(K_LOOP_D);
bwang 3:82c00c8e2cb4 40 __check(KI_BASE_D);
bwang 3:82c00c8e2cb4 41 __check(K_LOOP_Q);
bwang 3:82c00c8e2cb4 42 __check(KI_BASE_Q);
bwang 3:82c00c8e2cb4 43 __check(F_SLOW_LOOP);
bwang 3:82c00c8e2cb4 44 __check(INTEGRAL_MAX);
bwang 3:82c00c8e2cb4 45 __check(W_FILTER_STRENGTH);
bwang 3:82c00c8e2cb4 46 __check(DQ_FILTER_STRENGTH);
bwang 3:82c00c8e2cb4 47 __check(THROTTLE_FILTER_STRENGTH);
bwang 3:82c00c8e2cb4 48 __check(KP_D);
bwang 3:82c00c8e2cb4 49 __check(KI_D);
bwang 3:82c00c8e2cb4 50 __check(KP_Q);
bwang 3:82c00c8e2cb4 51 __check(KI_Q);
bwang 3:82c00c8e2cb4 52 __check(POLE_PAIRS);
bwang 3:82c00c8e2cb4 53 __check(POS_OFFSET);
bwang 3:82c00c8e2cb4 54 __check(RESOLVER_LOBES);
bwang 3:82c00c8e2cb4 55 __check(Ld);
bwang 3:82c00c8e2cb4 56 __check(Lq);
bwang 3:82c00c8e2cb4 57 __check(FLUX_LINKAGE);
bwang 3:82c00c8e2cb4 58 __check(Rs);
bwang 3:82c00c8e2cb4 59 __check(KT);
bwang 3:82c00c8e2cb4 60 __check(W_SAFE);
bwang 3:82c00c8e2cb4 61 __check(W_CRAZY);
bwang 3:82c00c8e2cb4 62 __check(W_STEP);
bwang 3:82c00c8e2cb4 63 return NULL;
bwang 3:82c00c8e2cb4 64 }
bwang 3:82c00c8e2cb4 65
bwang 3:82c00c8e2cb4 66 int* checkn(char *s) {
bwang 3:82c00c8e2cb4 67 __check(TORQUE_MODE);
bwang 3:82c00c8e2cb4 68 __check(CPR);
bwang 3:82c00c8e2cb4 69 __check(TH_LIMIT_LOW);
bwang 3:82c00c8e2cb4 70 __check(TH_LIMIT_HIGH);
bwang 3:82c00c8e2cb4 71 __check(TH_LIMIT_CRAZY);
bwang 3:82c00c8e2cb4 72 __check(ROWS);
bwang 3:82c00c8e2cb4 73 __check(COLUMNS);
bwang 3:82c00c8e2cb4 74 __check2(BREMS_mode);
bwang 3:82c00c8e2cb4 75 __check2(BREMS_src);
bwang 3:82c00c8e2cb4 76 __check2(BREMS_op);
bwang 3:82c00c8e2cb4 77 return NULL;
bwang 3:82c00c8e2cb4 78 }
bwang 3:82c00c8e2cb4 79
bwang 3:82c00c8e2cb4 80 #define __strcase(in, out) case in:strcpy(result, out);break
bwang 3:82c00c8e2cb4 81 #define __intcase(in, out) if (strcmp(buf, in) == 0) return out
bwang 3:82c00c8e2cb4 82
bwang 3:82c00c8e2cb4 83 char* mode_to_str(int n) {
bwang 3:82c00c8e2cb4 84 static char result[12];
bwang 3:82c00c8e2cb4 85 switch (n) {
bwang 3:82c00c8e2cb4 86 __strcase(MODE_RUN, "Run");
bwang 3:82c00c8e2cb4 87 __strcase(MODE_CFG, "Config");
bwang 3:82c00c8e2cb4 88 __strcase(MODE_ZERO, "Zero");
bwang 3:82c00c8e2cb4 89 __strcase(MODE_CHR, "Wizard");
bwang 3:82c00c8e2cb4 90 default:
bwang 3:82c00c8e2cb4 91 strcpy(result, "Invalid");
bwang 3:82c00c8e2cb4 92 break;
bwang 3:82c00c8e2cb4 93 }
bwang 3:82c00c8e2cb4 94 return result;
bwang 3:82c00c8e2cb4 95 }
bwang 3:82c00c8e2cb4 96
bwang 3:82c00c8e2cb4 97 int str_to_mode(char *buf) {
bwang 3:82c00c8e2cb4 98 __intcase("run", MODE_RUN);
bwang 3:82c00c8e2cb4 99 __intcase("cfg", MODE_CFG);
bwang 3:82c00c8e2cb4 100 __intcase("zero", MODE_ZERO);
bwang 3:82c00c8e2cb4 101 __intcase("char", MODE_CHR);
bwang 3:82c00c8e2cb4 102 __intcase("wizard", MODE_CHR);
bwang 3:82c00c8e2cb4 103 return -1;
bwang 3:82c00c8e2cb4 104 }
bwang 3:82c00c8e2cb4 105
bwang 3:82c00c8e2cb4 106 char* src_to_str(int n) {
bwang 3:82c00c8e2cb4 107 static char result[12];
bwang 3:82c00c8e2cb4 108 switch (n) {
bwang 3:82c00c8e2cb4 109 __strcase(CMD_SRC_RC, "RC");
bwang 3:82c00c8e2cb4 110 __strcase(CMD_SRC_ANALOG, "Analog");
bwang 3:82c00c8e2cb4 111 __strcase(CMD_SRC_TERMINAL, "Terminal");
bwang 3:82c00c8e2cb4 112 __strcase(CMD_SRC_SERIAL, "Serial");
bwang 3:82c00c8e2cb4 113 __strcase(CMD_SRC_CAN, "CAN");
bwang 3:82c00c8e2cb4 114 __strcase(CMD_SRC_INTERNAL, "Internal");
bwang 3:82c00c8e2cb4 115 default:
bwang 3:82c00c8e2cb4 116 strcpy(result, "Invalid");
bwang 3:82c00c8e2cb4 117 break;
bwang 3:82c00c8e2cb4 118 }
bwang 3:82c00c8e2cb4 119 return result;
bwang 3:82c00c8e2cb4 120 }
bwang 3:82c00c8e2cb4 121
bwang 3:82c00c8e2cb4 122 int str_to_src(char *buf) {
bwang 3:82c00c8e2cb4 123 __intcase("rc", CMD_SRC_RC);
bwang 3:82c00c8e2cb4 124 __intcase("analog", CMD_SRC_ANALOG);
bwang 3:82c00c8e2cb4 125 __intcase("terminal", CMD_SRC_TERMINAL);
bwang 3:82c00c8e2cb4 126 __intcase("serial", CMD_SRC_SERIAL);
bwang 3:82c00c8e2cb4 127 __intcase("can", CMD_SRC_CAN);
bwang 3:82c00c8e2cb4 128 __intcase("internal", CMD_SRC_INTERNAL);
bwang 3:82c00c8e2cb4 129 return -1;
bwang 3:82c00c8e2cb4 130 }
bwang 3:82c00c8e2cb4 131
bwang 3:82c00c8e2cb4 132 char* op_to_str(int n) {
bwang 3:82c00c8e2cb4 133 static char result[24];
bwang 3:82c00c8e2cb4 134 switch(n) {
bwang 3:82c00c8e2cb4 135 __strcase(OP_TORQUE, "Torque loop");
bwang 3:82c00c8e2cb4 136 __strcase(OP_DRIVING, "Driving map");
bwang 3:82c00c8e2cb4 137 __strcase(OP_SPEED, "Speed loop");
bwang 3:82c00c8e2cb4 138 __strcase(OP_POSITION, "Position loop");
bwang 3:82c00c8e2cb4 139 default:
bwang 3:82c00c8e2cb4 140 strcpy(result, "Invalid");
bwang 3:82c00c8e2cb4 141 break;
bwang 3:82c00c8e2cb4 142 }
bwang 3:82c00c8e2cb4 143 return result;
bwang 3:82c00c8e2cb4 144 }
bwang 3:82c00c8e2cb4 145
bwang 3:82c00c8e2cb4 146 int str_to_op(char *buf) {
bwang 3:82c00c8e2cb4 147 __intcase("torque", OP_TORQUE);
bwang 3:82c00c8e2cb4 148 __intcase("driving", OP_DRIVING);
bwang 3:82c00c8e2cb4 149 __intcase("speed", OP_SPEED);
bwang 3:82c00c8e2cb4 150 __intcase("pos", OP_POSITION);
bwang 3:82c00c8e2cb4 151 __intcase("position", OP_POSITION);
bwang 3:82c00c8e2cb4 152 return -1;
bwang 3:82c00c8e2cb4 153 }
bwang 3:82c00c8e2cb4 154