most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown

Dependencies:   mbed MODSERIAL FATFileSystem

Committer:
joel_ssc
Date:
Mon Feb 25 21:26:34 2019 +0000
Revision:
85:dd8176285b6e
Parent:
82:0981b9ada820
Child:
86:ba3a118b0080
tests imu.roll

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:");
tnhnrl 17:7c16b5671d0e 10
tnhnrl 17:7c16b5671d0e 11 ConfigFile read_sequence_cfg;
tnhnrl 17:7c16b5671d0e 12 char value[256];
tnhnrl 17:7c16b5671d0e 13
tnhnrl 17:7c16b5671d0e 14 //read configuration file stored on MBED
tnhnrl 45:16b8162188ca 15 if (!read_sequence_cfg.read("/local/sequence.txt")) {
tnhnrl 74:d281aaef9766 16 xbee().printf("\n\rERROR:Failure to read sequence.txt file.");
tnhnrl 17:7c16b5671d0e 17 }
tnhnrl 45:16b8162188ca 18 else {
tnhnrl 17:7c16b5671d0e 19 /* Read values from the file until you reach an "exit" character" */
tnhnrl 45:16b8162188ca 20 //up to 256 items in the sequence
tnhnrl 45:16b8162188ca 21 for (int i = 0; i < 256; i++) { //works
tnhnrl 17:7c16b5671d0e 22 /* convert INT to string */
tnhnrl 17:7c16b5671d0e 23 char buf[256];
tnhnrl 17:7c16b5671d0e 24 sprintf(buf, "%d", i); //searching for 0,1,2,3...
tnhnrl 17:7c16b5671d0e 25 /* convert INT to string */
tnhnrl 17:7c16b5671d0e 26
tnhnrl 17:7c16b5671d0e 27 if (read_sequence_cfg.getValue(buf, &value[0], sizeof(value))) {
tnhnrl 74:d281aaef9766 28 xbee().printf("\n\rsequence %d = %s",i,value);
tnhnrl 17:7c16b5671d0e 29
tnhnrl 17:7c16b5671d0e 30 sequenceStructLoaded[i] = process(value); //create the structs using process(string randomstring)
tnhnrl 17:7c16b5671d0e 31 }
tnhnrl 17:7c16b5671d0e 32
tnhnrl 17:7c16b5671d0e 33 if (sequenceStructLoaded[i].title == "exit") {
tnhnrl 17:7c16b5671d0e 34 _number_of_sequences = i; //before the exit
tnhnrl 17:7c16b5671d0e 35 break;
tnhnrl 17:7c16b5671d0e 36 }
tnhnrl 17:7c16b5671d0e 37 }
tnhnrl 17:7c16b5671d0e 38 } //end of successful read
tnhnrl 17:7c16b5671d0e 39 }
tnhnrl 17:7c16b5671d0e 40
tnhnrl 17:7c16b5671d0e 41 sequenceStruct SequenceController::process(string randomstring) {
tnhnrl 17:7c16b5671d0e 42 //this is the struct that is loaded from the config variables
tnhnrl 17:7c16b5671d0e 43
tnhnrl 21:38c8544db6f4 44 sequenceStruct loadStruct; //local struct
tnhnrl 17:7c16b5671d0e 45
tnhnrl 17:7c16b5671d0e 46 /* CONVERT STRING TO CHAR ARRAY */
tnhnrl 17:7c16b5671d0e 47 const char *cstr = randomstring.c_str();
tnhnrl 17:7c16b5671d0e 48 /* CONVERT STRING TO CHAR ARRAY */
tnhnrl 17:7c16b5671d0e 49
tnhnrl 17:7c16b5671d0e 50 /* DIVE */
tnhnrl 45:16b8162188ca 51 //this can only be in the first position
tnhnrl 45:16b8162188ca 52 if ((signed int) randomstring.find("dive") != -1) {
tnhnrl 17:7c16b5671d0e 53 loadStruct.title = "dive";
tnhnrl 17:7c16b5671d0e 54 loadStruct.state = MULTI_DIVE; //NEW: separate state handles multiple dives
tnhnrl 17:7c16b5671d0e 55 }
tnhnrl 17:7c16b5671d0e 56 /* DIVE */
tnhnrl 17:7c16b5671d0e 57
tnhnrl 17:7c16b5671d0e 58 /* PITCH */
tnhnrl 45:16b8162188ca 59 if ((signed int) randomstring.find("neutral") != -1) {
tnhnrl 17:7c16b5671d0e 60 loadStruct.title = "neutral";
tnhnrl 74:d281aaef9766 61 xbee().printf("\n\rLOAD neutral. %d", randomstring.find("neutral"));
tnhnrl 17:7c16b5671d0e 62 loadStruct.state = FIND_NEUTRAL;
tnhnrl 17:7c16b5671d0e 63 }
tnhnrl 17:7c16b5671d0e 64 /* PITCH */
tnhnrl 17:7c16b5671d0e 65
tnhnrl 17:7c16b5671d0e 66 /* EXIT */
tnhnrl 45:16b8162188ca 67 if ((signed int) randomstring.find("exit") != -1) {
tnhnrl 17:7c16b5671d0e 68 loadStruct.title = "exit";
tnhnrl 74:d281aaef9766 69 xbee().printf("\n\rReminder. Exit command is state FLOAT_BROADCAST\n\r");
tnhnrl 30:2964617e7676 70 loadStruct.state = FLOAT_BROADCAST; //this is the new exit condition of the dive-rise sequence (11/4/17)
tnhnrl 17:7c16b5671d0e 71 }
tnhnrl 17:7c16b5671d0e 72 /* EXIT */
tnhnrl 17:7c16b5671d0e 73
tnhnrl 17:7c16b5671d0e 74 /* DEPTH TO FLOAT */
tnhnrl 45:16b8162188ca 75 if ((signed int) randomstring.find("depth") != -1) {
tnhnrl 17:7c16b5671d0e 76 if (randomstring.find("neutral") || randomstring.find("dive")) {
tnhnrl 17:7c16b5671d0e 77 int depth_pos = randomstring.find("depth") + 6; //11 in example literally "depth="
tnhnrl 17:7c16b5671d0e 78 char depth_array[256] = {0}; //clear memory
tnhnrl 17:7c16b5671d0e 79 int depth_counter = 0;
tnhnrl 17:7c16b5671d0e 80 for (int i = depth_pos; i < randomstring.length(); i++) {
tnhnrl 17:7c16b5671d0e 81 if (cstr[i] == ',')
tnhnrl 17:7c16b5671d0e 82 break;
tnhnrl 17:7c16b5671d0e 83 else if (cstr[i] == ';')
tnhnrl 17:7c16b5671d0e 84 break;
tnhnrl 17:7c16b5671d0e 85 else {
tnhnrl 17:7c16b5671d0e 86 depth_array[depth_counter] = cstr[i];
tnhnrl 17:7c16b5671d0e 87 depth_counter++;
tnhnrl 17:7c16b5671d0e 88 }
tnhnrl 17:7c16b5671d0e 89 }
tnhnrl 17:7c16b5671d0e 90 loadStruct.depth = atof(depth_array);
tnhnrl 17:7c16b5671d0e 91 }
tnhnrl 17:7c16b5671d0e 92 }
tnhnrl 17:7c16b5671d0e 93 /* DEPTH TO FLOAT */
tnhnrl 17:7c16b5671d0e 94
tnhnrl 17:7c16b5671d0e 95 /* PITCH TO FLOAT */
tnhnrl 45:16b8162188ca 96 if ((signed int) randomstring.find("pitch") != -1) {
tnhnrl 17:7c16b5671d0e 97 if (randomstring.find("neutral") || randomstring.find("dive")) {
tnhnrl 17:7c16b5671d0e 98 int pitch_pos = randomstring.find("pitch") + 6; //11 in example
tnhnrl 17:7c16b5671d0e 99 char pitch_array[256] = {0}; //clear memory
tnhnrl 17:7c16b5671d0e 100 int pitch_counter = 0;
tnhnrl 17:7c16b5671d0e 101 for (int i = pitch_pos; i < randomstring.length(); i++) {
tnhnrl 17:7c16b5671d0e 102 if (cstr[i] == ',')
tnhnrl 17:7c16b5671d0e 103 break;
tnhnrl 17:7c16b5671d0e 104 else if (cstr[i] == ';')
tnhnrl 17:7c16b5671d0e 105 break;
tnhnrl 17:7c16b5671d0e 106 else {
tnhnrl 17:7c16b5671d0e 107 pitch_array[pitch_counter] = cstr[i];
tnhnrl 17:7c16b5671d0e 108 pitch_counter++;
tnhnrl 17:7c16b5671d0e 109 }
tnhnrl 17:7c16b5671d0e 110 }
tnhnrl 17:7c16b5671d0e 111 loadStruct.pitch = atof(pitch_array);
tnhnrl 17:7c16b5671d0e 112 }
tnhnrl 17:7c16b5671d0e 113 }
tnhnrl 17:7c16b5671d0e 114 /* PITCH TO FLOAT */
tnhnrl 17:7c16b5671d0e 115
tnhnrl 17:7c16b5671d0e 116 /* PAUSE */
tnhnrl 45:16b8162188ca 117 if ((signed int) randomstring.find("pause") != -1) {
tnhnrl 17:7c16b5671d0e 118 loadStruct.title = "pause";
tnhnrl 17:7c16b5671d0e 119 }
tnhnrl 17:7c16b5671d0e 120 /* PAUSE */
tnhnrl 17:7c16b5671d0e 121
tnhnrl 17:7c16b5671d0e 122 /* TIME TO FLOAT */
tnhnrl 45:16b8162188ca 123 if ((signed int) randomstring.find("timeout") != -1) {
tnhnrl 45:16b8162188ca 124
tnhnrl 17:7c16b5671d0e 125 int time_pos = randomstring.find("timeout") + 8; //position of timeout + "timeout=" so 8
tnhnrl 17:7c16b5671d0e 126 char time_array[256] = {0};
tnhnrl 17:7c16b5671d0e 127 int time_counter = 0;
tnhnrl 17:7c16b5671d0e 128 for (int i = time_pos; i < randomstring.length(); i++) {
tnhnrl 74:d281aaef9766 129 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
tnhnrl 17:7c16b5671d0e 130
tnhnrl 17:7c16b5671d0e 131 if (cstr[i] == ',')
tnhnrl 17:7c16b5671d0e 132 break;
tnhnrl 17:7c16b5671d0e 133 else if (cstr[i] == ';')
tnhnrl 17:7c16b5671d0e 134 break;
tnhnrl 17:7c16b5671d0e 135 else {
tnhnrl 74:d281aaef9766 136 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
tnhnrl 17:7c16b5671d0e 137 time_array[time_counter] = cstr[i];
tnhnrl 17:7c16b5671d0e 138 time_counter++;
tnhnrl 17:7c16b5671d0e 139 }
tnhnrl 17:7c16b5671d0e 140 }
tnhnrl 17:7c16b5671d0e 141 loadStruct.timeout = atof(time_array);
tnhnrl 17:7c16b5671d0e 142 }
tnhnrl 17:7c16b5671d0e 143 /* TIME TO FLOAT */
tnhnrl 17:7c16b5671d0e 144
tnhnrl 45:16b8162188ca 145 // /* EXIT */
tnhnrl 45:16b8162188ca 146 // if (randomstring.find("exit") != 0) {
tnhnrl 45:16b8162188ca 147 // loadStruct.title = "exit";
tnhnrl 74:d281aaef9766 148 // xbee().printf("\n\rEXIT.");
tnhnrl 45:16b8162188ca 149 // }
tnhnrl 45:16b8162188ca 150 // /* EXIT */
tnhnrl 17:7c16b5671d0e 151
joel_ssc 82:0981b9ada820 152 return loadStruct; //each iteration of this returns a completed struct
tnhnrl 17:7c16b5671d0e 153 }
tnhnrl 17:7c16b5671d0e 154
tnhnrl 17:7c16b5671d0e 155 void SequenceController::sequenceFunction() {
tnhnrl 74:d281aaef9766 156 //xbee().printf("sequenceFunction\n\r"); //debug (verified it is working correctly)
tnhnrl 17:7c16b5671d0e 157
tnhnrl 17:7c16b5671d0e 158 int check_current_state = stateMachine().getState();
tnhnrl 74:d281aaef9766 159 xbee().printf("State Machine State: %d\n\r", check_current_state);
tnhnrl 17:7c16b5671d0e 160
tnhnrl 17:7c16b5671d0e 161 if (stateMachine().getState() == SIT_IDLE) {
tnhnrl 17:7c16b5671d0e 162 //system starts idle
tnhnrl 17:7c16b5671d0e 163 //set the state machine to the current sequence in the array
tnhnrl 17:7c16b5671d0e 164 //example, set to "dive" and set pitch and depth and timeout
tnhnrl 17:7c16b5671d0e 165
tnhnrl 17:7c16b5671d0e 166 _current_state = sequenceStructLoaded[_sequence_counter].state;
tnhnrl 74:d281aaef9766 167 xbee().printf("_current_state: %d\n\r", _current_state);
tnhnrl 74:d281aaef9766 168 xbee().printf("_sequence_counter: %d\n\r", _sequence_counter);
tnhnrl 74:d281aaef9766 169 xbee().printf("_number_of_sequences: %d\n\r", _number_of_sequences);
tnhnrl 17:7c16b5671d0e 170
tnhnrl 17:7c16b5671d0e 171 stateMachine().setState(_current_state);
tnhnrl 17:7c16b5671d0e 172 stateMachine().setDepthCommand(sequenceStructLoaded[_sequence_counter].depth);
tnhnrl 17:7c16b5671d0e 173 stateMachine().setPitchCommand(sequenceStructLoaded[_sequence_counter].pitch);
tnhnrl 17:7c16b5671d0e 174 stateMachine().setTimeout(sequenceStructLoaded[_sequence_counter].timeout);
tnhnrl 17:7c16b5671d0e 175
tnhnrl 17:7c16b5671d0e 176 if (_sequence_counter == _number_of_sequences-1) //end when you finish all of the sequences
tnhnrl 17:7c16b5671d0e 177 sequenceTicker.detach();
tnhnrl 17:7c16b5671d0e 178
tnhnrl 17:7c16b5671d0e 179 _sequence_counter++; //exit ticker when counter complete
tnhnrl 17:7c16b5671d0e 180 }
tnhnrl 17:7c16b5671d0e 181 }
tnhnrl 17:7c16b5671d0e 182
joel_ssc 82:0981b9ada820 183 int LegController::getLegState() {
tnhnrl 17:7c16b5671d0e 184 return _current_state;
joel_ssc 82:0981b9ada820 185 }
joel_ssc 82:0981b9ada820 186 LegController::LegController() {
joel_ssc 82:0981b9ada820 187 _leg_counter = 0;
joel_ssc 82:0981b9ada820 188 }
joel_ssc 82:0981b9ada820 189
joel_ssc 82:0981b9ada820 190 int LegController::loadLeg() {
joel_ssc 82:0981b9ada820 191 xbee().printf("\n\rLoading Leg commands Dive File:");
joel_ssc 82:0981b9ada820 192
joel_ssc 82:0981b9ada820 193 ConfigFile read_leg_cfg;
joel_ssc 82:0981b9ada820 194 char value[256];
joel_ssc 82:0981b9ada820 195 // char buf[256];
joel_ssc 82:0981b9ada820 196 char bux2[256];
joel_ssc 82:0981b9ada820 197 static int default_legstruct_loaded = 0;
joel_ssc 82:0981b9ada820 198 sprintf(bux2,"\n\rin loadleg(): Loading Leg commands Dive File:");
joel_ssc 82:0981b9ada820 199 mbedLogger().appendDiagFile(bux2,0);
joel_ssc 82:0981b9ada820 200
joel_ssc 82:0981b9ada820 201 if(default_legstruct_loaded == 0 ) {
joel_ssc 82:0981b9ada820 202 legStructLoaded[0] = load_def_leg(); // is this right call pointer vs item?
joel_ssc 82:0981b9ada820 203 legStructLoaded[1].title = "exit";
joel_ssc 82:0981b9ada820 204 default_legstruct_loaded = 1;
joel_ssc 82:0981b9ada820 205 }
joel_ssc 82:0981b9ada820 206 //read configuration file stored on MBED
joel_ssc 82:0981b9ada820 207 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 208 xbee().printf("\n\rERROR:Failure to read legfile.txt file.");
joel_ssc 82:0981b9ada820 209 sprintf(bux2,"\n\rERROR:Failure to read legfile.txt file.");
joel_ssc 82:0981b9ada820 210 //mbedLogger().appendDiagFile(bux2,0);
joel_ssc 82:0981b9ada820 211
joel_ssc 82:0981b9ada820 212 }
joel_ssc 82:0981b9ada820 213 else {
joel_ssc 82:0981b9ada820 214 /* Read values from the file until you reach an "exit" character" */
joel_ssc 82:0981b9ada820 215 //up to 256 items in the sequence
joel_ssc 82:0981b9ada820 216 for (int i = 0; i < 256; i++) { //works
joel_ssc 82:0981b9ada820 217 /* convert INT to string */
joel_ssc 82:0981b9ada820 218 char buf[256];
joel_ssc 82:0981b9ada820 219 sprintf(buf, "%d", i); //searching for 0,1,2,3...
joel_ssc 82:0981b9ada820 220 /* convert INT to string */
joel_ssc 82:0981b9ada820 221
joel_ssc 82:0981b9ada820 222 if (read_leg_cfg.getValue(buf, &value[0], sizeof(value))) {
joel_ssc 82:0981b9ada820 223 xbee().printf("\n\rsequence %d = %s",i,value);
joel_ssc 82:0981b9ada820 224 sprintf(bux2, "\n\r leg values sequence %d = %s",i,value);
joel_ssc 82:0981b9ada820 225 mbedLogger().appendDiagFile(bux2,0);
joel_ssc 82:0981b9ada820 226
joel_ssc 82:0981b9ada820 227 legStructLoaded[i] = process(value); //create the structs using process(string randomstring)
joel_ssc 82:0981b9ada820 228 }
joel_ssc 82:0981b9ada820 229
joel_ssc 82:0981b9ada820 230 if (legStructLoaded[i].title == "exit") {
joel_ssc 82:0981b9ada820 231 _number_of_legs = i; //before the exit
joel_ssc 82:0981b9ada820 232 break;
joel_ssc 82:0981b9ada820 233 }
joel_ssc 82:0981b9ada820 234 }
joel_ssc 82:0981b9ada820 235 } //end of successful read
joel_ssc 82:0981b9ada820 236 if (_number_of_legs > 0 ) {return 1; }
joel_ssc 82:0981b9ada820 237 else {return 0; }
joel_ssc 82:0981b9ada820 238 }
joel_ssc 82:0981b9ada820 239
joel_ssc 85:dd8176285b6e 240 legStruct LegController::load_def_leg() { // default leg structure and if used, will NOT start leg mode
joel_ssc 82:0981b9ada820 241 legStruct loadStruct;
joel_ssc 82:0981b9ada820 242
joel_ssc 85:dd8176285b6e 243 loadStruct.title = "sit_idle";
joel_ssc 85:dd8176285b6e 244 loadStruct.state = SIT_IDLE ; // LEG_POSITION_DIVE;
joel_ssc 82:0981b9ada820 245 loadStruct.max_depth = 15;
joel_ssc 82:0981b9ada820 246 loadStruct.min_depth = 5;
joel_ssc 85:dd8176285b6e 247 loadStruct.yo_time = 100;
joel_ssc 85:dd8176285b6e 248 loadStruct.timeout = 600;
joel_ssc 82:0981b9ada820 249 loadStruct.heading = 90;
joel_ssc 82:0981b9ada820 250 return loadStruct;
joel_ssc 82:0981b9ada820 251 }
joel_ssc 82:0981b9ada820 252
joel_ssc 82:0981b9ada820 253 legStruct LegController::process(string randomstring) {
joel_ssc 82:0981b9ada820 254 //this is the struct that is loaded from the config variables
joel_ssc 82:0981b9ada820 255
joel_ssc 82:0981b9ada820 256 legStruct loadStruct; //local struct
joel_ssc 82:0981b9ada820 257
joel_ssc 82:0981b9ada820 258 /* CONVERT STRING TO CHAR ARRAY */
joel_ssc 82:0981b9ada820 259 const char *cstr = randomstring.c_str();
joel_ssc 82:0981b9ada820 260 char bux2[256];
joel_ssc 82:0981b9ada820 261 /* CONVERT STRING TO CHAR ARRAY */
joel_ssc 82:0981b9ada820 262
joel_ssc 85:dd8176285b6e 263 /* leg position DIVing */
joel_ssc 82:0981b9ada820 264 //this can only be in the first position
joel_ssc 82:0981b9ada820 265 if ((signed int) randomstring.find("leg") != -1) {
joel_ssc 82:0981b9ada820 266 loadStruct.title = "leg";
joel_ssc 82:0981b9ada820 267 loadStruct.state = LEG_POSITION_DIVE; //NEW: separate state handles multiple dives
joel_ssc 82:0981b9ada820 268 sprintf(bux2, "\n\r process leg file: found leg label, setting state to LEG_POSITION_DIVE");
joel_ssc 82:0981b9ada820 269 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 270 }
joel_ssc 85:dd8176285b6e 271 /* LPD */
joel_ssc 82:0981b9ada820 272
joel_ssc 85:dd8176285b6e 273 /* neutral */
joel_ssc 82:0981b9ada820 274 if ((signed int) randomstring.find("neutral") != -1) {
joel_ssc 82:0981b9ada820 275 loadStruct.title = "neutral";
joel_ssc 82:0981b9ada820 276 xbee().printf("\n\rLOAD neutral. %d", randomstring.find("neutral"));
joel_ssc 82:0981b9ada820 277 loadStruct.state = FIND_NEUTRAL;
joel_ssc 82:0981b9ada820 278 }
joel_ssc 85:dd8176285b6e 279 /* neutral */
joel_ssc 82:0981b9ada820 280
joel_ssc 82:0981b9ada820 281 /* EXIT */
joel_ssc 82:0981b9ada820 282 if ((signed int) randomstring.find("exit") != -1) {
joel_ssc 82:0981b9ada820 283 loadStruct.title = "exit";
joel_ssc 82:0981b9ada820 284 xbee().printf("\n\rReminder. Exit command is state FLOAT_BROADCAST\n\r");
joel_ssc 82:0981b9ada820 285 loadStruct.state = FLOAT_BROADCAST; //this is the new exit condition of the dive-rise sequence (11/4/17)
joel_ssc 82:0981b9ada820 286 sprintf(bux2, "\n\r process legfile: found exit key \n");
joel_ssc 82:0981b9ada820 287 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 288 }
joel_ssc 82:0981b9ada820 289 /* EXIT */
joel_ssc 82:0981b9ada820 290
joel_ssc 82:0981b9ada820 291 /* max DEPTH TO cycle to */
joel_ssc 82:0981b9ada820 292
joel_ssc 82:0981b9ada820 293 if ((signed int) randomstring.find("max_depth") != -1) {
joel_ssc 82:0981b9ada820 294 if (randomstring.find("neutral") || randomstring.find("leg")) {
joel_ssc 82:0981b9ada820 295 int depth_pos = randomstring.find("max_depth") + 10; //11 in example literally "depth="
joel_ssc 82:0981b9ada820 296 char depth_array[256] = {0}; //clear memory
joel_ssc 82:0981b9ada820 297 int depth_counter = 0;
joel_ssc 82:0981b9ada820 298 for (int i = depth_pos; i < randomstring.length(); i++) {
joel_ssc 82:0981b9ada820 299 if (cstr[i] == ',')
joel_ssc 82:0981b9ada820 300 break;
joel_ssc 82:0981b9ada820 301 else if (cstr[i] == ';')
joel_ssc 82:0981b9ada820 302 break;
joel_ssc 82:0981b9ada820 303 else {
joel_ssc 82:0981b9ada820 304 depth_array[depth_counter] = cstr[i];
joel_ssc 82:0981b9ada820 305 depth_counter++;
joel_ssc 82:0981b9ada820 306 }
joel_ssc 82:0981b9ada820 307 }
joel_ssc 82:0981b9ada820 308 loadStruct.max_depth = atof(depth_array);
joel_ssc 82:0981b9ada820 309 sprintf(bux2, "\n\r process legfile: key=max_depth val=%g \n", atof(depth_array));
joel_ssc 82:0981b9ada820 310 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 311 }
joel_ssc 82:0981b9ada820 312 }
joel_ssc 82:0981b9ada820 313
joel_ssc 82:0981b9ada820 314
joel_ssc 82:0981b9ada820 315 if ((signed int) randomstring.find("min_depth") != -1) {
joel_ssc 82:0981b9ada820 316 if (randomstring.find("neutral") || randomstring.find("leg")) {
joel_ssc 82:0981b9ada820 317 int depth_pos = randomstring.find("min_depth") + 10; //11 in example literally "depth="
joel_ssc 82:0981b9ada820 318 char depth_array[256] = {0}; //clear memory
joel_ssc 82:0981b9ada820 319 int depth_counter = 0;
joel_ssc 82:0981b9ada820 320 for (int i = depth_pos; i < randomstring.length(); i++) {
joel_ssc 82:0981b9ada820 321 if (cstr[i] == ',')
joel_ssc 82:0981b9ada820 322 break;
joel_ssc 82:0981b9ada820 323 else if (cstr[i] == ';')
joel_ssc 82:0981b9ada820 324 break;
joel_ssc 82:0981b9ada820 325 else {
joel_ssc 82:0981b9ada820 326 depth_array[depth_counter] = cstr[i];
joel_ssc 82:0981b9ada820 327 depth_counter++;
joel_ssc 82:0981b9ada820 328 }
joel_ssc 82:0981b9ada820 329 }
joel_ssc 82:0981b9ada820 330 loadStruct.min_depth = atof(depth_array);
joel_ssc 82:0981b9ada820 331 sprintf(bux2, "\n\r process legfile: key=min_depth val=%g \n", atof(depth_array));
joel_ssc 82:0981b9ada820 332 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 333 }
joel_ssc 82:0981b9ada820 334 }
joel_ssc 82:0981b9ada820 335 if ((signed int) randomstring.find("heading") != -1) {
joel_ssc 82:0981b9ada820 336 if (randomstring.find("neutral") || randomstring.find("leg")) {
joel_ssc 82:0981b9ada820 337 int depth_pos = randomstring.find("heading") + 8; //11 in example literally "depth="
joel_ssc 82:0981b9ada820 338 char depth_array[256] = {0}; //clear memory
joel_ssc 82:0981b9ada820 339 int depth_counter = 0;
joel_ssc 82:0981b9ada820 340 for (int i = depth_pos; i < randomstring.length(); i++) {
joel_ssc 82:0981b9ada820 341 if (cstr[i] == ',')
joel_ssc 82:0981b9ada820 342 break;
joel_ssc 82:0981b9ada820 343 else if (cstr[i] == ';')
joel_ssc 82:0981b9ada820 344 break;
joel_ssc 82:0981b9ada820 345 else {
joel_ssc 82:0981b9ada820 346 depth_array[depth_counter] = cstr[i];
joel_ssc 82:0981b9ada820 347 depth_counter++;
joel_ssc 82:0981b9ada820 348 }
joel_ssc 82:0981b9ada820 349 }
joel_ssc 82:0981b9ada820 350 loadStruct.heading = atof(depth_array);
joel_ssc 82:0981b9ada820 351 sprintf(bux2, "\n\r process legfile: key=heading val=%g \n", atof(depth_array));
joel_ssc 82:0981b9ada820 352 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 353 }
joel_ssc 82:0981b9ada820 354 }
joel_ssc 82:0981b9ada820 355 /* DEPTH TO FLOAT */
joel_ssc 82:0981b9ada820 356
joel_ssc 82:0981b9ada820 357
joel_ssc 82:0981b9ada820 358
joel_ssc 82:0981b9ada820 359 /* PAUSE */
joel_ssc 82:0981b9ada820 360 if ((signed int) randomstring.find("pause") != -1) {
joel_ssc 82:0981b9ada820 361 loadStruct.title = "pause";
joel_ssc 82:0981b9ada820 362 }
joel_ssc 82:0981b9ada820 363 /* PAUSE */
joel_ssc 82:0981b9ada820 364
joel_ssc 85:dd8176285b6e 365 /* TIME TO maintain leg yo-yo operations */
joel_ssc 82:0981b9ada820 366 if ((signed int) randomstring.find("timeout") != -1) {
joel_ssc 82:0981b9ada820 367
joel_ssc 82:0981b9ada820 368 int time_pos = randomstring.find("timeout") + 8; //position of timeout + "timeout=" so 8
joel_ssc 82:0981b9ada820 369 char time_array[256] = {0};
joel_ssc 82:0981b9ada820 370 int time_counter = 0;
joel_ssc 82:0981b9ada820 371 for (int i = time_pos; i < randomstring.length(); i++) {
joel_ssc 82:0981b9ada820 372 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
joel_ssc 82:0981b9ada820 373
joel_ssc 82:0981b9ada820 374 if (cstr[i] == ',')
joel_ssc 82:0981b9ada820 375 break;
joel_ssc 82:0981b9ada820 376 else if (cstr[i] == ';')
joel_ssc 82:0981b9ada820 377 break;
joel_ssc 82:0981b9ada820 378 else {
joel_ssc 82:0981b9ada820 379 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
joel_ssc 82:0981b9ada820 380 time_array[time_counter] = cstr[i];
joel_ssc 82:0981b9ada820 381 time_counter++;
joel_ssc 82:0981b9ada820 382 }
joel_ssc 82:0981b9ada820 383 }
joel_ssc 82:0981b9ada820 384 loadStruct.timeout = atof(time_array);
joel_ssc 82:0981b9ada820 385 sprintf(bux2, "\n\r process legfile: key=timeout val=%g \n", atof(time_array));
joel_ssc 82:0981b9ada820 386 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 387 }
joel_ssc 82:0981b9ada820 388 // yo_time is to avoid a single down/or up segment going on too long - maybe 10 minutes?
joel_ssc 82:0981b9ada820 389 if ((signed int) randomstring.find("yo_time") != -1) {
joel_ssc 82:0981b9ada820 390
joel_ssc 82:0981b9ada820 391 int time_pos = randomstring.find("yo_time") + 8; //position of timeout + "timeout=" so 8
joel_ssc 82:0981b9ada820 392 char time_array[256] = {0};
joel_ssc 82:0981b9ada820 393 int time_counter = 0;
joel_ssc 82:0981b9ada820 394 for (int i = time_pos; i < randomstring.length(); i++) {
joel_ssc 82:0981b9ada820 395 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
joel_ssc 82:0981b9ada820 396
joel_ssc 82:0981b9ada820 397 if (cstr[i] == ',')
joel_ssc 82:0981b9ada820 398 break;
joel_ssc 82:0981b9ada820 399 else if (cstr[i] == ';')
joel_ssc 82:0981b9ada820 400 break;
joel_ssc 82:0981b9ada820 401 else {
joel_ssc 82:0981b9ada820 402 //xbee().printf("time string cstr[i] = %c\n\r", cstr[i]); //debug
joel_ssc 82:0981b9ada820 403 time_array[time_counter] = cstr[i];
joel_ssc 82:0981b9ada820 404 time_counter++;
joel_ssc 82:0981b9ada820 405 }
joel_ssc 82:0981b9ada820 406 }
joel_ssc 82:0981b9ada820 407 loadStruct.yo_time = atof(time_array);
joel_ssc 82:0981b9ada820 408 sprintf(bux2, "\n\r process legfile: key=yo_time val=%g \n", atof(time_array));
joel_ssc 82:0981b9ada820 409 mbedLogger().appendDiagFile(bux2,3);
joel_ssc 82:0981b9ada820 410 }
joel_ssc 82:0981b9ada820 411 /* TIME TO FLOAT */
joel_ssc 82:0981b9ada820 412
joel_ssc 82:0981b9ada820 413 // /* EXIT */
joel_ssc 82:0981b9ada820 414 // if (randomstring.find("exit") != 0) {
joel_ssc 82:0981b9ada820 415 // loadStruct.title = "exit";
joel_ssc 82:0981b9ada820 416 // xbee().printf("\n\rEXIT.");
joel_ssc 82:0981b9ada820 417 // }
joel_ssc 82:0981b9ada820 418 // /* EXIT */
joel_ssc 82:0981b9ada820 419
joel_ssc 82:0981b9ada820 420 return loadStruct; //each iteration this returns a completed struct
joel_ssc 82:0981b9ada820 421 }