Flying Sea Glider / Mbed 2 deprecated 2019_13sep_jcw_nosd

Dependencies:   mbed MODSERIAL FATFileSystem

Committer:
CodyMarquardt
Date:
Fri Jun 28 13:59:11 2019 +0000
Revision:
99:9d0849f5fcd7
Parent:
87:6d95f853dab3
Child:
100:a21bb2e4493d
Program has bugs. Committing in order to access in MBED studio to debug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tnhnrl 17:7c16b5671d0e 1 #include "SequenceController.hpp"
tnhnrl 17:7c16b5671d0e 2 #include "StaticDefs.hpp"
tnhnrl 17:7c16b5671d0e 3
tnhnrl 17:7c16b5671d0e 4 SequenceController::SequenceController() {
tnhnrl 17:7c16b5671d0e 5 _sequence_counter = 0;
tnhnrl 17:7c16b5671d0e 6 }
tnhnrl 17:7c16b5671d0e 7
tnhnrl 17:7c16b5671d0e 8 void SequenceController::loadSequence() {
tnhnrl 74:d281aaef9766 9 xbee().printf("\n\rLoading Dive Sequence File:");
CodyMarquardt 99:9d0849f5fcd7 10 wait(2);
tnhnrl 17:7c16b5671d0e 11 ConfigFile read_sequence_cfg;
joel_ssc 86:ba3a118b0080 12 char value[256];
joel_ssc 86:ba3a118b0080 13 char bux2[256];
tnhnrl 17:7c16b5671d0e 14
tnhnrl 17:7c16b5671d0e 15 //read configuration file stored on MBED
tnhnrl 45:16b8162188ca 16 if (!read_sequence_cfg.read("/local/sequence.txt")) {
tnhnrl 74:d281aaef9766 17 xbee().printf("\n\rERROR:Failure to read sequence.txt file.");
tnhnrl 17:7c16b5671d0e 18 }
tnhnrl 45:16b8162188ca 19 else {
tnhnrl 17:7c16b5671d0e 20 /* Read values from the file until you reach an "exit" character" */
tnhnrl 45:16b8162188ca 21 //up to 256 items in the sequence
tnhnrl 45:16b8162188ca 22 for (int i = 0; i < 256; i++) { //works
tnhnrl 17:7c16b5671d0e 23 /* convert INT to string */
tnhnrl 17:7c16b5671d0e 24 char buf[256];
tnhnrl 17:7c16b5671d0e 25 sprintf(buf, "%d", i); //searching for 0,1,2,3...
tnhnrl 17:7c16b5671d0e 26 /* convert INT to string */
tnhnrl 17:7c16b5671d0e 27
tnhnrl 17:7c16b5671d0e 28 if (read_sequence_cfg.getValue(buf, &value[0], sizeof(value))) {
tnhnrl 74:d281aaef9766 29 xbee().printf("\n\rsequence %d = %s",i,value);
CodyMarquardt 99:9d0849f5fcd7 30 xbee().printf("stuff");
tnhnrl 17:7c16b5671d0e 31 sequenceStructLoaded[i] = process(value); //create the structs using process(string randomstring)
tnhnrl 17:7c16b5671d0e 32 }
tnhnrl 17:7c16b5671d0e 33
tnhnrl 17:7c16b5671d0e 34 if (sequenceStructLoaded[i].title == "exit") {
tnhnrl 17:7c16b5671d0e 35 _number_of_sequences = i; //before the exit
joel_ssc 86:ba3a118b0080 36 sprintf(bux2,"\n\rin loadsequence(): found final exit line num-sequences=%d\n", i);
joel_ssc 86:ba3a118b0080 37 mbedLogger().appendDiagFile(bux2,0);
tnhnrl 17:7c16b5671d0e 38 break;
tnhnrl 17:7c16b5671d0e 39 }
tnhnrl 17:7c16b5671d0e 40 }
tnhnrl 17:7c16b5671d0e 41 } //end of successful read
tnhnrl 17:7c16b5671d0e 42 }
tnhnrl 17:7c16b5671d0e 43
tnhnrl 17:7c16b5671d0e 44 sequenceStruct SequenceController::process(string randomstring) {
tnhnrl 17:7c16b5671d0e 45 //this is the struct that is loaded from the config variables
joel_ssc 86:ba3a118b0080 46 char bux2[256];
tnhnrl 21:38c8544db6f4 47 sequenceStruct loadStruct; //local struct
tnhnrl 17:7c16b5671d0e 48
tnhnrl 17:7c16b5671d0e 49 /* CONVERT STRING TO CHAR ARRAY */
tnhnrl 17:7c16b5671d0e 50 const char *cstr = randomstring.c_str();
tnhnrl 17:7c16b5671d0e 51 /* CONVERT STRING TO CHAR ARRAY */
tnhnrl 17:7c16b5671d0e 52
tnhnrl 17:7c16b5671d0e 53 /* DIVE */
tnhnrl 45:16b8162188ca 54 //this can only be in the first position
tnhnrl 45:16b8162188ca 55 if ((signed int) randomstring.find("dive") != -1) {
tnhnrl 17:7c16b5671d0e 56 loadStruct.title = "dive";
tnhnrl 17:7c16b5671d0e 57 loadStruct.state = MULTI_DIVE; //NEW: separate state handles multiple dives
tnhnrl 17:7c16b5671d0e 58 }
tnhnrl 17:7c16b5671d0e 59 /* DIVE */
tnhnrl 17:7c16b5671d0e 60
tnhnrl 17:7c16b5671d0e 61 /* PITCH */
tnhnrl 45:16b8162188ca 62 if ((signed int) randomstring.find("neutral") != -1) {
tnhnrl 17:7c16b5671d0e 63 loadStruct.title = "neutral";
tnhnrl 74:d281aaef9766 64 xbee().printf("\n\rLOAD neutral. %d", randomstring.find("neutral"));
tnhnrl 17:7c16b5671d0e 65 loadStruct.state = FIND_NEUTRAL;
joel_ssc 86:ba3a118b0080 66 sprintf(bux2,"\n\rin sequence().process(string): FOUND NEUTRAL in randomstring.find \n");
joel_ssc 86:ba3a118b0080 67 mbedLogger().appendDiagFile(bux2,3);
tnhnrl 17:7c16b5671d0e 68 }
tnhnrl 17:7c16b5671d0e 69 /* PITCH */
tnhnrl 17:7c16b5671d0e 70
tnhnrl 17:7c16b5671d0e 71 /* EXIT */
tnhnrl 45:16b8162188ca 72 if ((signed int) randomstring.find("exit") != -1) {
tnhnrl 17:7c16b5671d0e 73 loadStruct.title = "exit";
tnhnrl 74:d281aaef9766 74 xbee().printf("\n\rReminder. Exit command is state FLOAT_BROADCAST\n\r");
joel_ssc 86:ba3a118b0080 75 sprintf(bux2,"\n\rin sequence().process(string): FOUND EXIT in randomstring.find \n");
joel_ssc 86:ba3a118b0080 76 mbedLogger().appendDiagFile(bux2,0);
tnhnrl 30:2964617e7676 77 loadStruct.state = FLOAT_BROADCAST; //this is the new exit condition of the dive-rise sequence (11/4/17)
tnhnrl 17:7c16b5671d0e 78 }
tnhnrl 17:7c16b5671d0e 79 /* EXIT */
tnhnrl 17:7c16b5671d0e 80
tnhnrl 17:7c16b5671d0e 81 /* DEPTH TO FLOAT */
tnhnrl 45:16b8162188ca 82 if ((signed int) randomstring.find("depth") != -1) {
tnhnrl 17:7c16b5671d0e 83 if (randomstring.find("neutral") || randomstring.find("dive")) {
tnhnrl 17:7c16b5671d0e 84 int depth_pos = randomstring.find("depth") + 6; //11 in example literally "depth="
tnhnrl 17:7c16b5671d0e 85 char depth_array[256] = {0}; //clear memory
tnhnrl 17:7c16b5671d0e 86 int depth_counter = 0;
tnhnrl 17:7c16b5671d0e 87 for (int i = depth_pos; i < randomstring.length(); i++) {
joel_ssc 86:ba3a118b0080 88 if (cstr[i] == ',')
tnhnrl 17:7c16b5671d0e 89 break;
joel_ssc 86:ba3a118b0080 90 else if (cstr[i] == ';')
tnhnrl 17:7c16b5671d0e 91 break;
tnhnrl 17:7c16b5671d0e 92 else {
joel_ssc 86:ba3a118b0080 93 depth_array[depth_counter] = cstr[i];
tnhnrl 17:7c16b5671d0e 94 depth_counter++;
tnhnrl 17:7c16b5671d0e 95 }
tnhnrl 17:7c16b5671d0e 96 }
tnhnrl 17:7c16b5671d0e 97 loadStruct.depth = atof(depth_array);
tnhnrl 17:7c16b5671d0e 98 }
tnhnrl 17:7c16b5671d0e 99 }
tnhnrl 17:7c16b5671d0e 100 /* DEPTH TO FLOAT */
tnhnrl 17:7c16b5671d0e 101
CodyMarquardt 99:9d0849f5fcd7 102
tnhnrl 17:7c16b5671d0e 103 /* PITCH TO FLOAT */
tnhnrl 45:16b8162188ca 104 if ((signed int) randomstring.find("pitch") != -1) {
tnhnrl 17:7c16b5671d0e 105 if (randomstring.find("neutral") || randomstring.find("dive")) {
tnhnrl 17:7c16b5671d0e 106 int pitch_pos = randomstring.find("pitch") + 6; //11 in example
tnhnrl 17:7c16b5671d0e 107 char pitch_array[256] = {0}; //clear memory
tnhnrl 17:7c16b5671d0e 108 int pitch_counter = 0;
tnhnrl 17:7c16b5671d0e 109 for (int i = pitch_pos; i < randomstring.length(); i++) {
tnhnrl 17:7c16b5671d0e 110 if (cstr[i] == ',')
tnhnrl 17:7c16b5671d0e 111 break;
tnhnrl 17:7c16b5671d0e 112 else if (cstr[i] == ';')
tnhnrl 17:7c16b5671d0e 113 break;
tnhnrl 17:7c16b5671d0e 114 else {
tnhnrl 17:7c16b5671d0e 115 pitch_array[pitch_counter] = cstr[i];
tnhnrl 17:7c16b5671d0e 116 pitch_counter++;
tnhnrl 17:7c16b5671d0e 117 }
tnhnrl 17:7c16b5671d0e 118 }
tnhnrl 17:7c16b5671d0e 119 loadStruct.pitch = atof(pitch_array);
tnhnrl 17:7c16b5671d0e 120 }
tnhnrl 17:7c16b5671d0e 121 }
tnhnrl 17:7c16b5671d0e 122 /* PITCH TO FLOAT */
tnhnrl 17:7c16b5671d0e 123
tnhnrl 17:7c16b5671d0e 124 /* PAUSE */
tnhnrl 45:16b8162188ca 125 if ((signed int) randomstring.find("pause") != -1) {
tnhnrl 17:7c16b5671d0e 126 loadStruct.title = "pause";
tnhnrl 17:7c16b5671d0e 127 }
tnhnrl 17:7c16b5671d0e 128 /* PAUSE */
tnhnrl 17:7c16b5671d0e 129
tnhnrl 17:7c16b5671d0e 130 /* TIME TO FLOAT */
tnhnrl 45:16b8162188ca 131 if ((signed int) randomstring.find("timeout") != -1) {
tnhnrl 45:16b8162188ca 132
tnhnrl 17:7c16b5671d0e 133 int time_pos = randomstring.find("timeout") + 8; //position of timeout + "timeout=" so 8
tnhnrl 17:7c16b5671d0e 134 char time_array[256] = {0};
tnhnrl 17:7c16b5671d0e 135 int time_counter = 0;
tnhnrl 17:7c16b5671d0e 136 for (int i = time_pos; i < randomstring.length(); i++) {
tnhnrl 74:d281aaef9766 137 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
tnhnrl 17:7c16b5671d0e 138
tnhnrl 17:7c16b5671d0e 139 if (cstr[i] == ',')
tnhnrl 17:7c16b5671d0e 140 break;
tnhnrl 17:7c16b5671d0e 141 else if (cstr[i] == ';')
tnhnrl 17:7c16b5671d0e 142 break;
tnhnrl 17:7c16b5671d0e 143 else {
tnhnrl 74:d281aaef9766 144 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
tnhnrl 17:7c16b5671d0e 145 time_array[time_counter] = cstr[i];
tnhnrl 17:7c16b5671d0e 146 time_counter++;
tnhnrl 17:7c16b5671d0e 147 }
tnhnrl 17:7c16b5671d0e 148 }
tnhnrl 17:7c16b5671d0e 149 loadStruct.timeout = atof(time_array);
tnhnrl 17:7c16b5671d0e 150 }
tnhnrl 17:7c16b5671d0e 151 /* TIME TO FLOAT */
tnhnrl 17:7c16b5671d0e 152
tnhnrl 45:16b8162188ca 153 // /* EXIT */
tnhnrl 45:16b8162188ca 154 // if (randomstring.find("exit") != 0) {
tnhnrl 45:16b8162188ca 155 // loadStruct.title = "exit";
tnhnrl 74:d281aaef9766 156 // xbee().printf("\n\rEXIT.");
tnhnrl 45:16b8162188ca 157 // }
tnhnrl 45:16b8162188ca 158 // /* EXIT */
tnhnrl 17:7c16b5671d0e 159
joel_ssc 82:0981b9ada820 160 return loadStruct; //each iteration of this returns a completed struct
tnhnrl 17:7c16b5671d0e 161 }
tnhnrl 17:7c16b5671d0e 162
tnhnrl 17:7c16b5671d0e 163 void SequenceController::sequenceFunction() {
tnhnrl 74:d281aaef9766 164 //xbee().printf("sequenceFunction\n\r"); //debug (verified it is working correctly)
tnhnrl 17:7c16b5671d0e 165
tnhnrl 17:7c16b5671d0e 166 int check_current_state = stateMachine().getState();
tnhnrl 74:d281aaef9766 167 xbee().printf("State Machine State: %d\n\r", check_current_state);
tnhnrl 17:7c16b5671d0e 168
tnhnrl 17:7c16b5671d0e 169 if (stateMachine().getState() == SIT_IDLE) {
tnhnrl 17:7c16b5671d0e 170 //system starts idle
tnhnrl 17:7c16b5671d0e 171 //set the state machine to the current sequence in the array
tnhnrl 17:7c16b5671d0e 172 //example, set to "dive" and set pitch and depth and timeout
tnhnrl 17:7c16b5671d0e 173
tnhnrl 17:7c16b5671d0e 174 _current_state = sequenceStructLoaded[_sequence_counter].state;
tnhnrl 74:d281aaef9766 175 xbee().printf("_current_state: %d\n\r", _current_state);
tnhnrl 74:d281aaef9766 176 xbee().printf("_sequence_counter: %d\n\r", _sequence_counter);
tnhnrl 74:d281aaef9766 177 xbee().printf("_number_of_sequences: %d\n\r", _number_of_sequences);
tnhnrl 17:7c16b5671d0e 178
tnhnrl 17:7c16b5671d0e 179 stateMachine().setState(_current_state);
tnhnrl 17:7c16b5671d0e 180 stateMachine().setDepthCommand(sequenceStructLoaded[_sequence_counter].depth);
tnhnrl 17:7c16b5671d0e 181 stateMachine().setPitchCommand(sequenceStructLoaded[_sequence_counter].pitch);
tnhnrl 17:7c16b5671d0e 182 stateMachine().setTimeout(sequenceStructLoaded[_sequence_counter].timeout);
tnhnrl 17:7c16b5671d0e 183
tnhnrl 17:7c16b5671d0e 184 if (_sequence_counter == _number_of_sequences-1) //end when you finish all of the sequences
tnhnrl 17:7c16b5671d0e 185 sequenceTicker.detach();
tnhnrl 17:7c16b5671d0e 186
tnhnrl 17:7c16b5671d0e 187 _sequence_counter++; //exit ticker when counter complete
tnhnrl 17:7c16b5671d0e 188 }
tnhnrl 17:7c16b5671d0e 189 }
tnhnrl 17:7c16b5671d0e 190
joel_ssc 82:0981b9ada820 191 int LegController::getLegState() {
tnhnrl 17:7c16b5671d0e 192 return _current_state;
joel_ssc 82:0981b9ada820 193 }
joel_ssc 82:0981b9ada820 194 LegController::LegController() {
joel_ssc 82:0981b9ada820 195 _leg_counter = 0;
joel_ssc 82:0981b9ada820 196 }
joel_ssc 82:0981b9ada820 197
joel_ssc 82:0981b9ada820 198 int LegController::loadLeg() {
joel_ssc 82:0981b9ada820 199 xbee().printf("\n\rLoading Leg commands Dive File:");
joel_ssc 82:0981b9ada820 200
joel_ssc 82:0981b9ada820 201 ConfigFile read_leg_cfg;
joel_ssc 82:0981b9ada820 202 char value[256];
joel_ssc 82:0981b9ada820 203 // char buf[256];
joel_ssc 82:0981b9ada820 204 char bux2[256];
joel_ssc 82:0981b9ada820 205 static int default_legstruct_loaded = 0;
joel_ssc 82:0981b9ada820 206 sprintf(bux2,"\n\rin loadleg(): Loading Leg commands Dive File:");
joel_ssc 82:0981b9ada820 207 mbedLogger().appendDiagFile(bux2,0);
joel_ssc 82:0981b9ada820 208
joel_ssc 82:0981b9ada820 209 if(default_legstruct_loaded == 0 ) {
joel_ssc 82:0981b9ada820 210 legStructLoaded[0] = load_def_leg(); // is this right call pointer vs item?
joel_ssc 82:0981b9ada820 211 legStructLoaded[1].title = "exit";
joel_ssc 82:0981b9ada820 212 default_legstruct_loaded = 1;
joel_ssc 82:0981b9ada820 213 }
joel_ssc 82:0981b9ada820 214 //read configuration file stored on MBED
joel_ssc 82:0981b9ada820 215 if (!read_leg_cfg.read("/local/legfile.txt")) { //legfile.txt has exact same format as sequence.txt file,with starting 0=leg,.... and ending 1=exit line
joel_ssc 82:0981b9ada820 216 xbee().printf("\n\rERROR:Failure to read legfile.txt file.");
joel_ssc 82:0981b9ada820 217 sprintf(bux2,"\n\rERROR:Failure to read legfile.txt file.");
joel_ssc 86:ba3a118b0080 218 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 219
joel_ssc 82:0981b9ada820 220 }
joel_ssc 82:0981b9ada820 221 else {
joel_ssc 82:0981b9ada820 222 /* Read values from the file until you reach an "exit" character" */
joel_ssc 82:0981b9ada820 223 //up to 256 items in the sequence
joel_ssc 82:0981b9ada820 224 for (int i = 0; i < 256; i++) { //works
joel_ssc 82:0981b9ada820 225 /* convert INT to string */
joel_ssc 82:0981b9ada820 226 char buf[256];
joel_ssc 82:0981b9ada820 227 sprintf(buf, "%d", i); //searching for 0,1,2,3...
joel_ssc 82:0981b9ada820 228 /* convert INT to string */
joel_ssc 82:0981b9ada820 229
joel_ssc 82:0981b9ada820 230 if (read_leg_cfg.getValue(buf, &value[0], sizeof(value))) {
joel_ssc 82:0981b9ada820 231 xbee().printf("\n\rsequence %d = %s",i,value);
joel_ssc 87:6d95f853dab3 232 sprintf(bux2, "\n\r leg values sequence %d = %s\n",i,value);
joel_ssc 82:0981b9ada820 233 mbedLogger().appendDiagFile(bux2,0);
joel_ssc 82:0981b9ada820 234
joel_ssc 82:0981b9ada820 235 legStructLoaded[i] = process(value); //create the structs using process(string randomstring)
joel_ssc 82:0981b9ada820 236 }
joel_ssc 82:0981b9ada820 237
joel_ssc 82:0981b9ada820 238 if (legStructLoaded[i].title == "exit") {
joel_ssc 82:0981b9ada820 239 _number_of_legs = i; //before the exit
joel_ssc 82:0981b9ada820 240 break;
joel_ssc 82:0981b9ada820 241 }
joel_ssc 82:0981b9ada820 242 }
joel_ssc 82:0981b9ada820 243 } //end of successful read
joel_ssc 82:0981b9ada820 244 if (_number_of_legs > 0 ) {return 1; }
joel_ssc 82:0981b9ada820 245 else {return 0; }
joel_ssc 82:0981b9ada820 246 }
joel_ssc 82:0981b9ada820 247
joel_ssc 85:dd8176285b6e 248 legStruct LegController::load_def_leg() { // default leg structure and if used, will NOT start leg mode
joel_ssc 82:0981b9ada820 249 legStruct loadStruct;
joel_ssc 82:0981b9ada820 250
joel_ssc 85:dd8176285b6e 251 loadStruct.title = "sit_idle";
joel_ssc 85:dd8176285b6e 252 loadStruct.state = SIT_IDLE ; // LEG_POSITION_DIVE;
joel_ssc 82:0981b9ada820 253 loadStruct.max_depth = 15;
joel_ssc 82:0981b9ada820 254 loadStruct.min_depth = 5;
joel_ssc 85:dd8176285b6e 255 loadStruct.yo_time = 100;
joel_ssc 85:dd8176285b6e 256 loadStruct.timeout = 600;
joel_ssc 82:0981b9ada820 257 loadStruct.heading = 90;
joel_ssc 82:0981b9ada820 258 return loadStruct;
joel_ssc 82:0981b9ada820 259 }
joel_ssc 82:0981b9ada820 260
joel_ssc 82:0981b9ada820 261 legStruct LegController::process(string randomstring) {
joel_ssc 82:0981b9ada820 262 //this is the struct that is loaded from the config variables
joel_ssc 82:0981b9ada820 263
joel_ssc 82:0981b9ada820 264 legStruct loadStruct; //local struct
joel_ssc 86:ba3a118b0080 265 static int callcount=0;
joel_ssc 82:0981b9ada820 266 /* CONVERT STRING TO CHAR ARRAY */
joel_ssc 82:0981b9ada820 267 const char *cstr = randomstring.c_str();
joel_ssc 82:0981b9ada820 268 char bux2[256];
joel_ssc 82:0981b9ada820 269 /* CONVERT STRING TO CHAR ARRAY */
joel_ssc 82:0981b9ada820 270
joel_ssc 85:dd8176285b6e 271 /* leg position DIVing */
joel_ssc 82:0981b9ada820 272 //this can only be in the first position
joel_ssc 86:ba3a118b0080 273
joel_ssc 86:ba3a118b0080 274 callcount++;
joel_ssc 82:0981b9ada820 275 if ((signed int) randomstring.find("leg") != -1) {
joel_ssc 82:0981b9ada820 276 loadStruct.title = "leg";
joel_ssc 82:0981b9ada820 277 loadStruct.state = LEG_POSITION_DIVE; //NEW: separate state handles multiple dives
joel_ssc 82:0981b9ada820 278 sprintf(bux2, "\n\r process leg file: found leg label, setting state to LEG_POSITION_DIVE");
joel_ssc 82:0981b9ada820 279 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 280 }
joel_ssc 85:dd8176285b6e 281 /* LPD */
joel_ssc 82:0981b9ada820 282
joel_ssc 87:6d95f853dab3 283 /* start-swim */
joel_ssc 87:6d95f853dab3 284 if ((signed int) randomstring.find("start_swim") != -1) {
joel_ssc 87:6d95f853dab3 285 loadStruct.title = "start_swim";
joel_ssc 87:6d95f853dab3 286 xbee().printf("\n\rLOAD start-swim %d", randomstring.find("start_swim"));
joel_ssc 87:6d95f853dab3 287 loadStruct.state = START_SWIM;
joel_ssc 87:6d95f853dab3 288 sprintf(bux2, "\n\r process leg file: found START-SWIM label, setting state to same\n");
joel_ssc 87:6d95f853dab3 289 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 290 }
joel_ssc 87:6d95f853dab3 291 /* start-swim */
joel_ssc 87:6d95f853dab3 292 /* flying_idle */
joel_ssc 87:6d95f853dab3 293 if ((signed int) randomstring.find("flying_idle") != -1) {
joel_ssc 87:6d95f853dab3 294 loadStruct.title = "flying_idle";
joel_ssc 87:6d95f853dab3 295 xbee().printf("\n\rLOAD flying-idle found at %d", randomstring.find("flying_idle"));
joel_ssc 87:6d95f853dab3 296 loadStruct.state = FLYING_IDLE;
joel_ssc 87:6d95f853dab3 297 sprintf(bux2, "\n\r process leg file: found FLYING_IDLE label, setting state to FLYING_IDLE \n");
joel_ssc 87:6d95f853dab3 298 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 87:6d95f853dab3 299 }
joel_ssc 87:6d95f853dab3 300 /* flying_idle */
joel_ssc 82:0981b9ada820 301 /* EXIT */
joel_ssc 82:0981b9ada820 302 if ((signed int) randomstring.find("exit") != -1) {
joel_ssc 82:0981b9ada820 303 loadStruct.title = "exit";
joel_ssc 82:0981b9ada820 304 xbee().printf("\n\rReminder. Exit command is state FLOAT_BROADCAST\n\r");
joel_ssc 82:0981b9ada820 305 loadStruct.state = FLOAT_BROADCAST; //this is the new exit condition of the dive-rise sequence (11/4/17)
joel_ssc 87:6d95f853dab3 306 sprintf(bux2, "\n\r process(valuestring) legfile: found exit key. Callcount=%d\n", callcount);
joel_ssc 82:0981b9ada820 307 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 308 }
joel_ssc 82:0981b9ada820 309 /* EXIT */
joel_ssc 82:0981b9ada820 310
joel_ssc 82:0981b9ada820 311 /* max DEPTH TO cycle to */
joel_ssc 82:0981b9ada820 312
CodyMarquardt 99:9d0849f5fcd7 313 if ((signed int) randomstring.find("max_d") != -1) {
joel_ssc 87:6d95f853dab3 314
CodyMarquardt 99:9d0849f5fcd7 315 int depth_pos = randomstring.find("max_d") + 6; //11 in example literally "depth="
joel_ssc 87:6d95f853dab3 316 char depth_array[256] = {0}; //clear memory
joel_ssc 87:6d95f853dab3 317 int depth_counter = 0;
joel_ssc 87:6d95f853dab3 318 for (int i = depth_pos; i < randomstring.length(); i++) {
joel_ssc 87:6d95f853dab3 319 if (cstr[i] == ',')
joel_ssc 87:6d95f853dab3 320 break;
joel_ssc 87:6d95f853dab3 321 else if (cstr[i] == ';')
joel_ssc 87:6d95f853dab3 322 break;
joel_ssc 87:6d95f853dab3 323 else {
joel_ssc 87:6d95f853dab3 324 depth_array[depth_counter] = cstr[i];
joel_ssc 87:6d95f853dab3 325 depth_counter++;
joel_ssc 82:0981b9ada820 326 }
joel_ssc 82:0981b9ada820 327 }
joel_ssc 87:6d95f853dab3 328 loadStruct.max_depth = atof(depth_array);
CodyMarquardt 99:9d0849f5fcd7 329 sprintf(bux2, "\n\r process legfile: key=max_d val=%g process(legstring)count=%d \n", atof(depth_array), callcount);
joel_ssc 87:6d95f853dab3 330 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 87:6d95f853dab3 331
joel_ssc 87:6d95f853dab3 332 }
joel_ssc 82:0981b9ada820 333
joel_ssc 82:0981b9ada820 334
CodyMarquardt 99:9d0849f5fcd7 335 if ((signed int) randomstring.find("min_d") != -1) {
joel_ssc 87:6d95f853dab3 336
CodyMarquardt 99:9d0849f5fcd7 337 int depth_pos = randomstring.find("min_d") + 6; //11 in example literally "depth="
joel_ssc 87:6d95f853dab3 338 char depth_array[256] = {0}; //clear memory
joel_ssc 87:6d95f853dab3 339 int depth_counter = 0;
joel_ssc 87:6d95f853dab3 340 for (int i = depth_pos; i < randomstring.length(); i++) {
joel_ssc 87:6d95f853dab3 341 if (cstr[i] == ',')
joel_ssc 87:6d95f853dab3 342 break;
joel_ssc 87:6d95f853dab3 343 else if (cstr[i] == ';')
joel_ssc 87:6d95f853dab3 344 break;
joel_ssc 87:6d95f853dab3 345 else {
joel_ssc 87:6d95f853dab3 346 depth_array[depth_counter] = cstr[i];
joel_ssc 87:6d95f853dab3 347 depth_counter++;
joel_ssc 82:0981b9ada820 348 }
joel_ssc 87:6d95f853dab3 349 }
joel_ssc 87:6d95f853dab3 350 loadStruct.min_depth = atof(depth_array);
CodyMarquardt 99:9d0849f5fcd7 351 sprintf(bux2, "\n\r process legfile: key=min_d val=%g \n", atof(depth_array));
joel_ssc 87:6d95f853dab3 352 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 87:6d95f853dab3 353
joel_ssc 87:6d95f853dab3 354 }
CodyMarquardt 99:9d0849f5fcd7 355
CodyMarquardt 99:9d0849f5fcd7 356 /* Buoyancy Engine Offset on Dive */
CodyMarquardt 99:9d0849f5fcd7 357 if ((signed int) randomstring.find("BCE_dive") != -1) {
CodyMarquardt 99:9d0849f5fcd7 358
CodyMarquardt 99:9d0849f5fcd7 359 int BCE_dive_offset_pos = randomstring.find("BCE_dive") + 9 ; //11 in example literally "BCE_dive_offset="
CodyMarquardt 99:9d0849f5fcd7 360 char BCE_dive_offset_array[256] = {0}; //clear memory
CodyMarquardt 99:9d0849f5fcd7 361 int BCE_dive_offset_counter = 0;
CodyMarquardt 99:9d0849f5fcd7 362 for (int i = BCE_dive_offset_pos; i < randomstring.length(); i++) {
CodyMarquardt 99:9d0849f5fcd7 363 if (cstr[i] == ',')
CodyMarquardt 99:9d0849f5fcd7 364 break;
CodyMarquardt 99:9d0849f5fcd7 365 else if (cstr[i] == ';')
CodyMarquardt 99:9d0849f5fcd7 366 break;
CodyMarquardt 99:9d0849f5fcd7 367 else {
CodyMarquardt 99:9d0849f5fcd7 368 BCE_dive_offset_array[BCE_dive_offset_counter] = cstr[i];
CodyMarquardt 99:9d0849f5fcd7 369 BCE_dive_offset_counter++;
CodyMarquardt 99:9d0849f5fcd7 370 }
CodyMarquardt 99:9d0849f5fcd7 371 }
CodyMarquardt 99:9d0849f5fcd7 372 loadStruct.BCE_dive_offset = atof(BCE_dive_offset_array);
CodyMarquardt 99:9d0849f5fcd7 373 sprintf(bux2, "\n\r process legfile: key=BCE_dive val=%g \n", atof(BCE_dive_offset_array));
CodyMarquardt 99:9d0849f5fcd7 374 mbedLogger().appendDiagFile(bux2,3);
CodyMarquardt 99:9d0849f5fcd7 375 }
CodyMarquardt 99:9d0849f5fcd7 376
CodyMarquardt 99:9d0849f5fcd7 377 /* Buoyancy Engine Offset on Dive */
CodyMarquardt 99:9d0849f5fcd7 378
CodyMarquardt 99:9d0849f5fcd7 379 /* Battery Mass Mover Offset on Dive */
CodyMarquardt 99:9d0849f5fcd7 380 if ((signed int) randomstring.find("BMM_dive") != -1) {
CodyMarquardt 99:9d0849f5fcd7 381
CodyMarquardt 99:9d0849f5fcd7 382 int BMM_dive_offset_pos = randomstring.find("BMM_dive") + 9 ; //11 in example literally "BMM_dive_offset="
CodyMarquardt 99:9d0849f5fcd7 383 char BMM_dive_offset_array[256] = {0}; //clear memory
CodyMarquardt 99:9d0849f5fcd7 384 int BMM_dive_offset_counter = 0;
CodyMarquardt 99:9d0849f5fcd7 385 for (int i = BMM_dive_offset_pos; i < randomstring.length(); i++) {
CodyMarquardt 99:9d0849f5fcd7 386 if (cstr[i] == ',')
CodyMarquardt 99:9d0849f5fcd7 387 break;
CodyMarquardt 99:9d0849f5fcd7 388 else if (cstr[i] == ';')
CodyMarquardt 99:9d0849f5fcd7 389 break;
CodyMarquardt 99:9d0849f5fcd7 390 else {
CodyMarquardt 99:9d0849f5fcd7 391 BMM_dive_offset_array[BMM_dive_offset_counter] = cstr[i];
CodyMarquardt 99:9d0849f5fcd7 392 BMM_dive_offset_counter++;
CodyMarquardt 99:9d0849f5fcd7 393 }
CodyMarquardt 99:9d0849f5fcd7 394 }
CodyMarquardt 99:9d0849f5fcd7 395 loadStruct.BMM_dive_offset = atof(BMM_dive_offset_array);
CodyMarquardt 99:9d0849f5fcd7 396 sprintf(bux2, "\n\r process legfile: key=BMM_dive val=%g \n", atof(BMM_dive_offset_array));
CodyMarquardt 99:9d0849f5fcd7 397 mbedLogger().appendDiagFile(bux2,3);
CodyMarquardt 99:9d0849f5fcd7 398 }
joel_ssc 87:6d95f853dab3 399
CodyMarquardt 99:9d0849f5fcd7 400 /* Battery Mass Mover Offset on Dive */
CodyMarquardt 99:9d0849f5fcd7 401
CodyMarquardt 99:9d0849f5fcd7 402 /* Buoyancy Engine Offset on Rise */
CodyMarquardt 99:9d0849f5fcd7 403 if ((signed int) randomstring.find("BCE_rise") != -1) {
CodyMarquardt 99:9d0849f5fcd7 404
CodyMarquardt 99:9d0849f5fcd7 405 int BCE_rise_offset_pos = randomstring.find("BCE_rise") + 9 ; //11 in example literally "BCE_rise_offset="
CodyMarquardt 99:9d0849f5fcd7 406 char BCE_rise_offset_array[256] = {0}; //clear memory
CodyMarquardt 99:9d0849f5fcd7 407 int BCE_rise_offset_counter = 0;
CodyMarquardt 99:9d0849f5fcd7 408 for (int i = BCE_rise_offset_pos; i < randomstring.length(); i++) {
CodyMarquardt 99:9d0849f5fcd7 409 if (cstr[i] == ',')
CodyMarquardt 99:9d0849f5fcd7 410 break;
CodyMarquardt 99:9d0849f5fcd7 411 else if (cstr[i] == ';')
CodyMarquardt 99:9d0849f5fcd7 412 break;
CodyMarquardt 99:9d0849f5fcd7 413 else {
CodyMarquardt 99:9d0849f5fcd7 414 BCE_rise_offset_array[BCE_rise_offset_counter] = cstr[i];
CodyMarquardt 99:9d0849f5fcd7 415 BCE_rise_offset_counter++;
CodyMarquardt 99:9d0849f5fcd7 416 }
CodyMarquardt 99:9d0849f5fcd7 417 }
CodyMarquardt 99:9d0849f5fcd7 418 loadStruct.BCE_rise_offset = atof(BCE_rise_offset_array);
CodyMarquardt 99:9d0849f5fcd7 419 sprintf(bux2, "\n\r process legfile: key=BCE_rise val=%g \n", atof(BCE_rise_offset_array));
CodyMarquardt 99:9d0849f5fcd7 420 mbedLogger().appendDiagFile(bux2,3);
CodyMarquardt 99:9d0849f5fcd7 421 }
CodyMarquardt 99:9d0849f5fcd7 422
CodyMarquardt 99:9d0849f5fcd7 423 /* Buoyancy Engine Offset on Rise */
CodyMarquardt 99:9d0849f5fcd7 424
CodyMarquardt 99:9d0849f5fcd7 425 /* Battery Mass Mover Offset on Rise */
CodyMarquardt 99:9d0849f5fcd7 426 if ((signed int) randomstring.find("BMM_rise") != -1) {
CodyMarquardt 99:9d0849f5fcd7 427
CodyMarquardt 99:9d0849f5fcd7 428 int BMM_rise_offset_pos = randomstring.find("BMM_rise") + 9 ; //11 in example literally "BMM_rise_offset="
CodyMarquardt 99:9d0849f5fcd7 429 char BMM_rise_offset_array[256] = {0}; //clear memory
CodyMarquardt 99:9d0849f5fcd7 430 int BMM_rise_offset_counter = 0;
CodyMarquardt 99:9d0849f5fcd7 431 for (int i = BMM_rise_offset_pos; i < randomstring.length(); i++) {
CodyMarquardt 99:9d0849f5fcd7 432 if (cstr[i] == ',')
CodyMarquardt 99:9d0849f5fcd7 433 break;
CodyMarquardt 99:9d0849f5fcd7 434 else if (cstr[i] == ';')
CodyMarquardt 99:9d0849f5fcd7 435 break;
CodyMarquardt 99:9d0849f5fcd7 436 else {
CodyMarquardt 99:9d0849f5fcd7 437 BMM_rise_offset_array[BMM_rise_offset_counter] = cstr[i];
CodyMarquardt 99:9d0849f5fcd7 438 BMM_rise_offset_counter++;
CodyMarquardt 99:9d0849f5fcd7 439 }
CodyMarquardt 99:9d0849f5fcd7 440 }
CodyMarquardt 99:9d0849f5fcd7 441 loadStruct.BMM_rise_offset = atof(BMM_rise_offset_array);
CodyMarquardt 99:9d0849f5fcd7 442 sprintf(bux2, "\n\r process legfile: key=BMM_rise val=%g \n", atof(BMM_rise_offset_array));
CodyMarquardt 99:9d0849f5fcd7 443 mbedLogger().appendDiagFile(bux2,3);
CodyMarquardt 99:9d0849f5fcd7 444 }
CodyMarquardt 99:9d0849f5fcd7 445
CodyMarquardt 99:9d0849f5fcd7 446 /* Battery Mass Mover Offset on Rise */
CodyMarquardt 99:9d0849f5fcd7 447
CodyMarquardt 99:9d0849f5fcd7 448
CodyMarquardt 99:9d0849f5fcd7 449 if ((signed int) randomstring.find("head") != -1) {
CodyMarquardt 99:9d0849f5fcd7 450
CodyMarquardt 99:9d0849f5fcd7 451 int heading_pos = randomstring.find("head") + 5; //11 in example literally "depth="
CodyMarquardt 99:9d0849f5fcd7 452 char heading_array[256] = {0}; //clear memory
CodyMarquardt 99:9d0849f5fcd7 453 int heading_counter = 0;
CodyMarquardt 99:9d0849f5fcd7 454 for (int i = heading_pos; i < randomstring.length(); i++) {
joel_ssc 87:6d95f853dab3 455 if (cstr[i] == ',')
joel_ssc 82:0981b9ada820 456 break;
joel_ssc 87:6d95f853dab3 457 else if (cstr[i] == ';')
joel_ssc 82:0981b9ada820 458 break;
joel_ssc 82:0981b9ada820 459 else {
CodyMarquardt 99:9d0849f5fcd7 460 heading_array[heading_counter] = cstr[i];
CodyMarquardt 99:9d0849f5fcd7 461 heading_counter++;
joel_ssc 87:6d95f853dab3 462 }
joel_ssc 82:0981b9ada820 463 }
CodyMarquardt 99:9d0849f5fcd7 464 loadStruct.heading = atof(heading_array);
CodyMarquardt 99:9d0849f5fcd7 465 sprintf(bux2, "\n\r process legfile: key=head val=%g \n", atof(heading_array));
joel_ssc 87:6d95f853dab3 466 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 87:6d95f853dab3 467
joel_ssc 87:6d95f853dab3 468 }
joel_ssc 82:0981b9ada820 469 /* DEPTH TO FLOAT */
joel_ssc 82:0981b9ada820 470
joel_ssc 82:0981b9ada820 471
joel_ssc 82:0981b9ada820 472
joel_ssc 82:0981b9ada820 473 /* PAUSE */
joel_ssc 82:0981b9ada820 474 if ((signed int) randomstring.find("pause") != -1) {
joel_ssc 82:0981b9ada820 475 loadStruct.title = "pause";
joel_ssc 82:0981b9ada820 476 }
joel_ssc 82:0981b9ada820 477 /* PAUSE */
joel_ssc 82:0981b9ada820 478
joel_ssc 85:dd8176285b6e 479 /* TIME TO maintain leg yo-yo operations */
joel_ssc 82:0981b9ada820 480 if ((signed int) randomstring.find("timeout") != -1) {
joel_ssc 82:0981b9ada820 481
joel_ssc 82:0981b9ada820 482 int time_pos = randomstring.find("timeout") + 8; //position of timeout + "timeout=" so 8
joel_ssc 82:0981b9ada820 483 char time_array[256] = {0};
joel_ssc 82:0981b9ada820 484 int time_counter = 0;
joel_ssc 82:0981b9ada820 485 for (int i = time_pos; i < randomstring.length(); i++) {
joel_ssc 82:0981b9ada820 486 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
joel_ssc 82:0981b9ada820 487
joel_ssc 82:0981b9ada820 488 if (cstr[i] == ',')
joel_ssc 82:0981b9ada820 489 break;
joel_ssc 82:0981b9ada820 490 else if (cstr[i] == ';')
joel_ssc 82:0981b9ada820 491 break;
joel_ssc 82:0981b9ada820 492 else {
joel_ssc 82:0981b9ada820 493 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
joel_ssc 82:0981b9ada820 494 time_array[time_counter] = cstr[i];
joel_ssc 82:0981b9ada820 495 time_counter++;
joel_ssc 82:0981b9ada820 496 }
joel_ssc 82:0981b9ada820 497 }
joel_ssc 82:0981b9ada820 498 loadStruct.timeout = atof(time_array);
joel_ssc 82:0981b9ada820 499 sprintf(bux2, "\n\r process legfile: key=timeout val=%g \n", atof(time_array));
joel_ssc 82:0981b9ada820 500 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 501 }
joel_ssc 82:0981b9ada820 502 // yo_time is to avoid a single down/or up segment going on too long - maybe 10 minutes?
joel_ssc 82:0981b9ada820 503 if ((signed int) randomstring.find("yo_time") != -1) {
joel_ssc 82:0981b9ada820 504
joel_ssc 82:0981b9ada820 505 int time_pos = randomstring.find("yo_time") + 8; //position of timeout + "timeout=" so 8
joel_ssc 82:0981b9ada820 506 char time_array[256] = {0};
joel_ssc 82:0981b9ada820 507 int time_counter = 0;
joel_ssc 82:0981b9ada820 508 for (int i = time_pos; i < randomstring.length(); i++) {
joel_ssc 82:0981b9ada820 509 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
joel_ssc 82:0981b9ada820 510
joel_ssc 82:0981b9ada820 511 if (cstr[i] == ',')
joel_ssc 82:0981b9ada820 512 break;
joel_ssc 82:0981b9ada820 513 else if (cstr[i] == ';')
joel_ssc 82:0981b9ada820 514 break;
joel_ssc 82:0981b9ada820 515 else {
joel_ssc 82:0981b9ada820 516 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
joel_ssc 82:0981b9ada820 517 time_array[time_counter] = cstr[i];
joel_ssc 82:0981b9ada820 518 time_counter++;
joel_ssc 82:0981b9ada820 519 }
joel_ssc 82:0981b9ada820 520 }
joel_ssc 82:0981b9ada820 521 loadStruct.yo_time = atof(time_array);
joel_ssc 82:0981b9ada820 522 sprintf(bux2, "\n\r process legfile: key=yo_time val=%g \n", atof(time_array));
joel_ssc 82:0981b9ada820 523 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 524 }
joel_ssc 82:0981b9ada820 525 /* TIME TO FLOAT */
joel_ssc 82:0981b9ada820 526
joel_ssc 82:0981b9ada820 527 // /* EXIT */
joel_ssc 82:0981b9ada820 528 // if (randomstring.find("exit") != 0) {
joel_ssc 82:0981b9ada820 529 // loadStruct.title = "exit";
joel_ssc 82:0981b9ada820 530 // xbee().printf("\n\rEXIT.");
joel_ssc 82:0981b9ada820 531 // }
joel_ssc 82:0981b9ada820 532 // /* EXIT */
joel_ssc 82:0981b9ada820 533
joel_ssc 82:0981b9ada820 534 return loadStruct; //each iteration this returns a completed struct
joel_ssc 82:0981b9ada820 535 }