Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL2

Dependencies:   mbed

Committer:
Slord2142
Date:
Tue Oct 22 20:59:27 2019 +0000
Revision:
35:ec224d706f7c
Parent:
34:419242dc004d
Child:
36:849c22bd60b0
Comprehensive update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfwic 0:44a3005d4f20 1 //-------------------------------------------------------------------------------
mfwic 0:44a3005d4f20 2 //
mfwic 0:44a3005d4f20 3 // Treehouse Inc.
mfwic 0:44a3005d4f20 4 // Colorado Springs, Colorado
mfwic 0:44a3005d4f20 5 //
mfwic 0:44a3005d4f20 6 // Copyright (c) 2016 by Treehouse Designs Inc.
mfwic 0:44a3005d4f20 7 //
mfwic 0:44a3005d4f20 8 // This code is the property of Treehouse, Inc. (Treehouse)
mfwic 0:44a3005d4f20 9 // and may not be redistributed in any form without prior written
mfwic 0:44a3005d4f20 10 // permission of the copyright holder, Treehouse.
mfwic 0:44a3005d4f20 11 //
mfwic 0:44a3005d4f20 12 // The above copyright notice and this permission notice shall be included in
mfwic 0:44a3005d4f20 13 // all copies or substantial portions of the Software.
mfwic 0:44a3005d4f20 14 //
mfwic 0:44a3005d4f20 15 //
mfwic 0:44a3005d4f20 16 //-------------------------------------------------------------------------------
mfwic 0:44a3005d4f20 17 //
mfwic 0:44a3005d4f20 18 // REVISION HISTORY:
mfwic 0:44a3005d4f20 19 //
mfwic 0:44a3005d4f20 20 // $Author: $
mfwic 0:44a3005d4f20 21 // $Rev: $
mfwic 0:44a3005d4f20 22 // $Date: $
mfwic 0:44a3005d4f20 23 // $URL: $
mfwic 0:44a3005d4f20 24 //
mfwic 0:44a3005d4f20 25 //-------------------------------------------------------------------------------
mfwic 0:44a3005d4f20 26
mfwic 0:44a3005d4f20 27 #include "mbed.h"
mfwic 0:44a3005d4f20 28 #include "string.h"
mfwic 0:44a3005d4f20 29 #include "stdio.h"
mfwic 0:44a3005d4f20 30 #include "stdlib.h"
mfwic 0:44a3005d4f20 31 #include "ctype.h"
mfwic 0:44a3005d4f20 32 #include "serial.h"
mfwic 0:44a3005d4f20 33 #include "globals.h"
mfwic 0:44a3005d4f20 34 #include "math.h"
mfwic 0:44a3005d4f20 35 #include "parameters.h"
mfwic 1:9f8583ba2431 36 #include "all_io.h"
mfwic 1:9f8583ba2431 37 #include "boards.h"
mfwic 1:9f8583ba2431 38 #include "menu.h"
mfwic 8:d3d7dca419b3 39 #include "command.h"
Slord2142 33:6c7364ea360f 40 #include "SOFBlock.h"
Slord2142 33:6c7364ea360f 41 #include "adc.h"
Slord2142 35:ec224d706f7c 42 #include "adc_defs.h"
mfwic 0:44a3005d4f20 43
Slord2142 33:6c7364ea360f 44 uint8_t *storo;
Slord2142 35:ec224d706f7c 45 char storoBuild[200], storoFrag[10], storoLUT[100];
Slord2142 33:6c7364ea360f 46 char storoSpace[2] = ":";
mfwic 21:fe0ea1860c9f 47 unsigned int boardsActive = ALLON;
mfwic 21:fe0ea1860c9f 48 unsigned int boardMults = 32;
Slord2142 33:6c7364ea360f 49 double commandData;
Slord2142 33:6c7364ea360f 50 unsigned int section;
Slord2142 33:6c7364ea360f 51 unsigned int fort;
Slord2142 33:6c7364ea360f 52 unsigned int select;
Slord2142 33:6c7364ea360f 53 double VOLTAGE_48_ACTUAL_VALUE = 1.51;
Slord2142 33:6c7364ea360f 54 double VOLTAGE_24_ACTUAL_VALUE = 1.55;
Slord2142 33:6c7364ea360f 55 double VOLTAGE_12_ACTUAL_VALUE = 1.65;
Slord2142 33:6c7364ea360f 56 double VOLTAGE_48_OFFSET = 0;
Slord2142 33:6c7364ea360f 57 double VOLTAGE_24_OFFSET = 0;
Slord2142 33:6c7364ea360f 58 double VOLTAGE_12_OFFSET = 0;
Slord2142 33:6c7364ea360f 59 int Vloc = 0;
Slord2142 33:6c7364ea360f 60 int Aloc = 0;
Slord2142 33:6c7364ea360f 61 double VOLTAGE_CAL_1;
Slord2142 33:6c7364ea360f 62 double VOLTAGE_CAL_2;
Slord2142 33:6c7364ea360f 63 double VOLTAGE_CAL_3;
Slord2142 33:6c7364ea360f 64 double VSTORE_1;
Slord2142 33:6c7364ea360f 65 double VSTORE_2;
Slord2142 33:6c7364ea360f 66 double VSTORE_3;
Slord2142 35:ec224d706f7c 67
Slord2142 35:ec224d706f7c 68 bool LUTA = false;
Slord2142 35:ec224d706f7c 69 bool LUTB = false;
Slord2142 35:ec224d706f7c 70 unsigned int luta = 0;
Slord2142 35:ec224d706f7c 71 unsigned int lutb = 0;
Slord2142 35:ec224d706f7c 72
Slord2142 33:6c7364ea360f 73 struct adcValues adcVals;
Slord2142 33:6c7364ea360f 74 struct displayValues dvals;
Slord2142 35:ec224d706f7c 75
Slord2142 33:6c7364ea360f 76 signed int CURRENT_48_DIV_FACTOR5 = -370;
Slord2142 33:6c7364ea360f 77 signed int CURRENT_48_DIV_FACTOR4 = -570;
Slord2142 33:6c7364ea360f 78 signed int CURRENT_48_DIV_FACTOR3 = -740;
Slord2142 33:6c7364ea360f 79 signed int CURRENT_48_DIV_FACTOR2 = -948;
Slord2142 33:6c7364ea360f 80 signed int CURRENT_48_DIV_FACTOR1 = -1541;
Slord2142 33:6c7364ea360f 81 signed int CURRENT_48_DIV_FACTOR0 = -1610;
Slord2142 33:6c7364ea360f 82
Slord2142 33:6c7364ea360f 83 unsigned int CURRENT_48_DIV_THRESH5 = 3000;
Slord2142 33:6c7364ea360f 84 unsigned int CURRENT_48_DIV_THRESH4 = 2500;
Slord2142 33:6c7364ea360f 85 unsigned int CURRENT_48_DIV_THRESH3 = 2000;
Slord2142 33:6c7364ea360f 86 unsigned int CURRENT_48_DIV_THRESH2 = 1500;
Slord2142 33:6c7364ea360f 87 unsigned int CURRENT_48_DIV_THRESH1 = 500;
Slord2142 33:6c7364ea360f 88
Slord2142 33:6c7364ea360f 89 signed int CURRENT_24_DIV_FACTOR = -376;
Slord2142 33:6c7364ea360f 90
Slord2142 33:6c7364ea360f 91 signed int CURRENT_12_DIV_FACTOR5 = -188;
Slord2142 33:6c7364ea360f 92 signed int CURRENT_12_DIV_FACTOR4 = -186;
Slord2142 33:6c7364ea360f 93 signed int CURRENT_12_DIV_FACTOR3 = -182;
Slord2142 33:6c7364ea360f 94 signed int CURRENT_12_DIV_FACTOR2 = -177;
Slord2142 33:6c7364ea360f 95 signed int CURRENT_12_DIV_FACTOR1 = -179;
Slord2142 33:6c7364ea360f 96 signed int CURRENT_12_DIV_FACTOR0 = -175;
Slord2142 33:6c7364ea360f 97
Slord2142 33:6c7364ea360f 98 unsigned int CURRENT_12_DIV_THRESH5 = 1600;
Slord2142 33:6c7364ea360f 99 unsigned int CURRENT_12_DIV_THRESH4 = 800;
Slord2142 33:6c7364ea360f 100 unsigned int CURRENT_12_DIV_THRESH3 = 600;
Slord2142 33:6c7364ea360f 101 unsigned int CURRENT_12_DIV_THRESH2 = 400;
Slord2142 33:6c7364ea360f 102 unsigned int CURRENT_12_DIV_THRESH1 = 200;
Slord2142 33:6c7364ea360f 103
Slord2142 33:6c7364ea360f 104 unsigned int CURRENT_REF_1;
Slord2142 33:6c7364ea360f 105 unsigned int CURRENT_REF_2;
Slord2142 33:6c7364ea360f 106 unsigned int CURRENT_REF_3;
Slord2142 33:6c7364ea360f 107 unsigned int CURRENT_REF_4;
Slord2142 33:6c7364ea360f 108 unsigned int CURRENT_REF_5;
Slord2142 33:6c7364ea360f 109 unsigned int CURRENT_REF_6;
Slord2142 33:6c7364ea360f 110 double CURRENT_IN_1;
Slord2142 33:6c7364ea360f 111 double CURRENT_IN_2;
Slord2142 33:6c7364ea360f 112 double CURRENT_IN_3;
Slord2142 33:6c7364ea360f 113 double CURRENT_IN_4;
Slord2142 33:6c7364ea360f 114 double CURRENT_IN_5;
Slord2142 33:6c7364ea360f 115 double CURRENT_IN_6;
Slord2142 33:6c7364ea360f 116
Slord2142 33:6c7364ea360f 117 double CURRENT_12_CORRECTION0;
Slord2142 33:6c7364ea360f 118 double CURRENT_12_CORRECTION1;
Slord2142 33:6c7364ea360f 119 double CURRENT_12_CORRECTION2;
Slord2142 33:6c7364ea360f 120 double CURRENT_12_CORRECTION3;
Slord2142 33:6c7364ea360f 121 double CURRENT_12_CORRECTION4;
Slord2142 33:6c7364ea360f 122 double CURRENT_12_CORRECTION5;
mfwic 6:39442d493098 123 extern unsigned short my12;
Slord2142 33:6c7364ea360f 124 char storage[50];
Slord2142 33:6c7364ea360f 125
Slord2142 33:6c7364ea360f 126 /************* TEMPORARY WRITING BLOCK *********************/
Slord2142 33:6c7364ea360f 127
Slord2142 33:6c7364ea360f 128 SOFWriter writer;
Slord2142 33:6c7364ea360f 129 SOFReader reader;
mfwic 0:44a3005d4f20 130
mfwic 0:44a3005d4f20 131 /************* FILE SCOPE VARIABLES ************************/
mfwic 0:44a3005d4f20 132 char setvalue = FALSE;
mfwic 0:44a3005d4f20 133 int endOfCommand = 0;
mfwic 0:44a3005d4f20 134 int commandError = 0;
mfwic 0:44a3005d4f20 135 int menuLevel = LEVEL_MAIN;
mfwic 0:44a3005d4f20 136 int readback = 0;
mfwic 0:44a3005d4f20 137
mfwic 0:44a3005d4f20 138 /************************************************************
mfwic 0:44a3005d4f20 139 * Routine: getDelimiter
mfwic 0:44a3005d4f20 140 * Input: none
mfwic 0:44a3005d4f20 141 * Output: none
mfwic 0:44a3005d4f20 142 * Description:
mfwic 0:44a3005d4f20 143 * searches for a delimiter and moves the buffer location
mfwic 0:44a3005d4f20 144 * to be just past it
mfwic 0:44a3005d4f20 145 *
mfwic 0:44a3005d4f20 146 **************************************************************/
mfwic 0:44a3005d4f20 147 void getDelimiter(void)
mfwic 0:44a3005d4f20 148 {
mfwic 0:44a3005d4f20 149 ++bufloc;
mfwic 0:44a3005d4f20 150
mfwic 0:44a3005d4f20 151 while ((rxbuf[bufloc] != ' ') &&
mfwic 0:44a3005d4f20 152 (rxbuf[bufloc] != ',') &&
mfwic 0:44a3005d4f20 153 (rxbuf[bufloc] != '=') &&
mfwic 0:44a3005d4f20 154 (rxbuf[bufloc] != 0 ))
mfwic 0:44a3005d4f20 155 {
mfwic 0:44a3005d4f20 156 bufloc++;
mfwic 0:44a3005d4f20 157 }
mfwic 0:44a3005d4f20 158 }
mfwic 0:44a3005d4f20 159
mfwic 0:44a3005d4f20 160 /************************************************************
mfwic 0:44a3005d4f20 161 * Routine: gethex
mfwic 0:44a3005d4f20 162 * Input: hex character
mfwic 0:44a3005d4f20 163 * Returns: hex integer
mfwic 0:44a3005d4f20 164 * Description:
mfwic 0:44a3005d4f20 165 * Converts a hex character to a value
mfwic 0:44a3005d4f20 166 **************************************************************/
mfwic 0:44a3005d4f20 167 char gethex(char val)
mfwic 0:44a3005d4f20 168 {
mfwic 0:44a3005d4f20 169 int retval;
mfwic 0:44a3005d4f20 170 switch(val)
mfwic 0:44a3005d4f20 171 {
mfwic 0:44a3005d4f20 172 case '0':
mfwic 0:44a3005d4f20 173 retval = 0;
mfwic 0:44a3005d4f20 174 break;
mfwic 0:44a3005d4f20 175 case '1':
mfwic 0:44a3005d4f20 176 retval = 1;
mfwic 0:44a3005d4f20 177 break;
mfwic 0:44a3005d4f20 178 case '2':
mfwic 0:44a3005d4f20 179 retval = 2;
mfwic 0:44a3005d4f20 180 break;
mfwic 0:44a3005d4f20 181 case '3':
mfwic 0:44a3005d4f20 182 retval = 3;
mfwic 0:44a3005d4f20 183 break;
mfwic 0:44a3005d4f20 184 case '4':
mfwic 0:44a3005d4f20 185 retval = 4;
mfwic 0:44a3005d4f20 186 break;
mfwic 0:44a3005d4f20 187 case '5':
mfwic 0:44a3005d4f20 188 retval = 5;
mfwic 0:44a3005d4f20 189 break;
mfwic 0:44a3005d4f20 190 case '6':
mfwic 0:44a3005d4f20 191 retval = 6;
mfwic 0:44a3005d4f20 192 break;
mfwic 0:44a3005d4f20 193 case '7':
mfwic 0:44a3005d4f20 194 retval = 7;
mfwic 0:44a3005d4f20 195 break;
mfwic 0:44a3005d4f20 196 case '8':
mfwic 0:44a3005d4f20 197 retval = 8;
mfwic 0:44a3005d4f20 198 break;
mfwic 0:44a3005d4f20 199 case '9':
mfwic 0:44a3005d4f20 200 retval = 9;
mfwic 0:44a3005d4f20 201 break;
mfwic 0:44a3005d4f20 202 case 'A':
mfwic 0:44a3005d4f20 203 retval = 10;
mfwic 0:44a3005d4f20 204 break;
mfwic 0:44a3005d4f20 205 case 'B':
mfwic 0:44a3005d4f20 206 retval = 11;
mfwic 0:44a3005d4f20 207 break;
mfwic 0:44a3005d4f20 208 case 'C':
mfwic 0:44a3005d4f20 209 retval = 12;
mfwic 0:44a3005d4f20 210 break;
mfwic 0:44a3005d4f20 211 case 'D':
mfwic 0:44a3005d4f20 212 retval = 13;
mfwic 0:44a3005d4f20 213 break;
mfwic 0:44a3005d4f20 214 case 'E':
mfwic 0:44a3005d4f20 215 retval = 14;
mfwic 0:44a3005d4f20 216 break;
mfwic 0:44a3005d4f20 217 case 'F':
mfwic 0:44a3005d4f20 218 retval = 15;
mfwic 0:44a3005d4f20 219 break;
mfwic 0:44a3005d4f20 220 default:
mfwic 0:44a3005d4f20 221 retval = 0;
mfwic 0:44a3005d4f20 222 break;
mfwic 0:44a3005d4f20 223
mfwic 0:44a3005d4f20 224 }
mfwic 0:44a3005d4f20 225 return retval;
mfwic 0:44a3005d4f20 226 }
mfwic 0:44a3005d4f20 227
mfwic 0:44a3005d4f20 228 /************************************************************
mfwic 0:44a3005d4f20 229 * Routine: showfval
mfwic 0:44a3005d4f20 230 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 231 * value (float value to display)
mfwic 0:44a3005d4f20 232 * Output: none
mfwic 0:44a3005d4f20 233 * Description:
mfwic 0:44a3005d4f20 234 * Sends a floating point number (value) over the serial port
mfwic 0:44a3005d4f20 235 * if it is being retrieved (GET)
mfwic 0:44a3005d4f20 236 *
mfwic 0:44a3005d4f20 237 **************************************************************/
mfwic 0:44a3005d4f20 238 void showfval(char setval,float value)
mfwic 0:44a3005d4f20 239 {
mfwic 0:44a3005d4f20 240 if(!setval)
mfwic 0:44a3005d4f20 241 {
mfwic 1:9f8583ba2431 242 sprintf(strbuf," %4.9f",value);
mfwic 1:9f8583ba2431 243 sendSerial(strbuf);
mfwic 0:44a3005d4f20 244 }
mfwic 0:44a3005d4f20 245 }
mfwic 0:44a3005d4f20 246
mfwic 0:44a3005d4f20 247 /************************************************************
mfwic 0:44a3005d4f20 248 * Routine: showival
mfwic 0:44a3005d4f20 249 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 250 * value (integer value to display)
mfwic 0:44a3005d4f20 251 * Output: none
mfwic 0:44a3005d4f20 252 * Description:
mfwic 0:44a3005d4f20 253 * Sends an integer (value) over the serial port
mfwic 0:44a3005d4f20 254 * if it is being retrieved (GET)
mfwic 0:44a3005d4f20 255 *
mfwic 0:44a3005d4f20 256 **************************************************************/
mfwic 0:44a3005d4f20 257 void showival(char setval, int value)
mfwic 0:44a3005d4f20 258 {
mfwic 0:44a3005d4f20 259 if(!setval)
mfwic 0:44a3005d4f20 260 {
mfwic 1:9f8583ba2431 261 sprintf(strbuf," %i",value);
mfwic 1:9f8583ba2431 262 sendSerial(strbuf);
mfwic 0:44a3005d4f20 263 }
mfwic 0:44a3005d4f20 264 }
mfwic 0:44a3005d4f20 265 /************************************************************
mfwic 0:44a3005d4f20 266 * Routine: showcval
mfwic 0:44a3005d4f20 267 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 268 * value (character to display)
mfwic 0:44a3005d4f20 269 * Output: none
mfwic 0:44a3005d4f20 270 * Description:
mfwic 0:44a3005d4f20 271 * Sends a character over the serial port
mfwic 0:44a3005d4f20 272 * if it is being retrieved (GET)
mfwic 0:44a3005d4f20 273 *
mfwic 0:44a3005d4f20 274 **************************************************************/
mfwic 0:44a3005d4f20 275 void showcval(char setval, int value)
mfwic 0:44a3005d4f20 276 {
mfwic 0:44a3005d4f20 277 if(!setval)
mfwic 0:44a3005d4f20 278 {
mfwic 1:9f8583ba2431 279 sprintf(strbuf," %c",(char)value);
mfwic 1:9f8583ba2431 280 sendSerial(strbuf);
mfwic 0:44a3005d4f20 281 }
mfwic 0:44a3005d4f20 282 }
mfwic 0:44a3005d4f20 283
mfwic 0:44a3005d4f20 284 /************************************************************
mfwic 0:44a3005d4f20 285 * Routine: showlval
mfwic 0:44a3005d4f20 286 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 287 * value (integer value to display)
mfwic 0:44a3005d4f20 288 * Output: none
mfwic 0:44a3005d4f20 289 * Description:
mfwic 0:44a3005d4f20 290 * Sends an long (value) over the serial port
mfwic 0:44a3005d4f20 291 * if it is being retrieved (GET)
mfwic 0:44a3005d4f20 292 *
mfwic 0:44a3005d4f20 293 **************************************************************/
mfwic 0:44a3005d4f20 294 void showlval(char setval, long value)
mfwic 0:44a3005d4f20 295 {
mfwic 0:44a3005d4f20 296 if(!setval)
mfwic 0:44a3005d4f20 297 {
mfwic 1:9f8583ba2431 298 sprintf(strbuf," %ld",value);
mfwic 1:9f8583ba2431 299 sendSerial(strbuf);
mfwic 0:44a3005d4f20 300 }
mfwic 0:44a3005d4f20 301 }
mfwic 0:44a3005d4f20 302
mfwic 0:44a3005d4f20 303 /************************************************************
mfwic 0:44a3005d4f20 304 * Routine: showuival
mfwic 0:44a3005d4f20 305 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 306 * value (integer value to display)
mfwic 0:44a3005d4f20 307 * Output: none
mfwic 0:44a3005d4f20 308 * Description:
mfwic 0:44a3005d4f20 309 * Sends an unsigned int (value) over the serial port
mfwic 0:44a3005d4f20 310 * if it is being retrieved (GET)
mfwic 0:44a3005d4f20 311 *
mfwic 0:44a3005d4f20 312 **************************************************************/
mfwic 0:44a3005d4f20 313 void showuival(char setval, unsigned int value)
mfwic 0:44a3005d4f20 314 {
mfwic 0:44a3005d4f20 315 if(!setval)
mfwic 0:44a3005d4f20 316 {
mfwic 1:9f8583ba2431 317 sprintf(strbuf," %u",value);
mfwic 1:9f8583ba2431 318 sendSerial(strbuf);
mfwic 0:44a3005d4f20 319 }
mfwic 0:44a3005d4f20 320 }
mfwic 0:44a3005d4f20 321
mfwic 0:44a3005d4f20 322 /************************************************************
mfwic 0:44a3005d4f20 323 * Routine: showhval
mfwic 0:44a3005d4f20 324 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 325 * value (hex integeger value to display)
mfwic 0:44a3005d4f20 326 * Output: none
mfwic 0:44a3005d4f20 327 * Description:
mfwic 0:44a3005d4f20 328 * Sends an integer (value) in hex over the serial port
mfwic 0:44a3005d4f20 329 * if it is being retrieved (GET)
mfwic 0:44a3005d4f20 330 *
mfwic 0:44a3005d4f20 331 **************************************************************/
mfwic 0:44a3005d4f20 332 void showhval(char setval, int value)
mfwic 0:44a3005d4f20 333 {
mfwic 0:44a3005d4f20 334 if(!setval)
mfwic 0:44a3005d4f20 335 {
mfwic 0:44a3005d4f20 336 if(serialStatus.computer)
mfwic 1:9f8583ba2431 337 sprintf(strbuf," %u",(unsigned int)value);
mfwic 0:44a3005d4f20 338 else
mfwic 1:9f8583ba2431 339 sprintf(strbuf," 0x%04x",value);
mfwic 1:9f8583ba2431 340 sendSerial(strbuf);
mfwic 0:44a3005d4f20 341 }
mfwic 0:44a3005d4f20 342 }
mfwic 0:44a3005d4f20 343
mfwic 0:44a3005d4f20 344
mfwic 0:44a3005d4f20 345 /************************************************************
mfwic 0:44a3005d4f20 346 * Routine: getival
mfwic 0:44a3005d4f20 347 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 348 * Returns: the value if it is being SET or 0 if it is a GET
mfwic 0:44a3005d4f20 349 * Description:
mfwic 0:44a3005d4f20 350 * Gets an integer from the serial port connection.
mfwic 0:44a3005d4f20 351 *
mfwic 0:44a3005d4f20 352 **************************************************************/
mfwic 0:44a3005d4f20 353 int getival(char setval)
mfwic 0:44a3005d4f20 354 {
mfwic 0:44a3005d4f20 355 if (setval)
mfwic 0:44a3005d4f20 356 {
mfwic 0:44a3005d4f20 357 return atoi(&rxbuf[++bufloc]);
mfwic 0:44a3005d4f20 358 }
mfwic 0:44a3005d4f20 359
mfwic 0:44a3005d4f20 360 return 0;
mfwic 0:44a3005d4f20 361 }
mfwic 0:44a3005d4f20 362
mfwic 0:44a3005d4f20 363 /************************************************************
mfwic 0:44a3005d4f20 364 * Routine: getcval
mfwic 0:44a3005d4f20 365 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 366 * Returns: the value if it is being SET or 0 if it is a GET
mfwic 0:44a3005d4f20 367 * Description:
mfwic 0:44a3005d4f20 368 * Gets an character from the serial port connection.
mfwic 0:44a3005d4f20 369 *
mfwic 0:44a3005d4f20 370 **************************************************************/
mfwic 0:44a3005d4f20 371 int getcval(char setval)
mfwic 0:44a3005d4f20 372 {
mfwic 0:44a3005d4f20 373 if(setval)
mfwic 0:44a3005d4f20 374 {
mfwic 0:44a3005d4f20 375 // skip one space
mfwic 0:44a3005d4f20 376 ++bufloc;
mfwic 0:44a3005d4f20 377 // skip spaces and the equals sign
mfwic 0:44a3005d4f20 378 while((rxbuf[bufloc] == ' ') || (rxbuf[bufloc] == '='))
mfwic 0:44a3005d4f20 379 bufloc++;
mfwic 0:44a3005d4f20 380 return rxbuf[bufloc++];
mfwic 0:44a3005d4f20 381 }
mfwic 0:44a3005d4f20 382 else
mfwic 0:44a3005d4f20 383 return 0;
mfwic 0:44a3005d4f20 384
mfwic 0:44a3005d4f20 385 }
mfwic 0:44a3005d4f20 386 /************************************************************
mfwic 0:44a3005d4f20 387 * Routine: getlval
mfwic 0:44a3005d4f20 388 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 389 * Returns: the value if it is being SET or 0 if it is a GET
mfwic 0:44a3005d4f20 390 * Description:
mfwic 0:44a3005d4f20 391 * Gets an long from the serial port connection.
mfwic 0:44a3005d4f20 392 *
mfwic 0:44a3005d4f20 393 **************************************************************/
mfwic 0:44a3005d4f20 394 long getlval(char setval)
mfwic 0:44a3005d4f20 395 {
mfwic 0:44a3005d4f20 396 if(setval)
mfwic 0:44a3005d4f20 397 return atol(&rxbuf[++bufloc]);
mfwic 0:44a3005d4f20 398 else
mfwic 0:44a3005d4f20 399 return 0;
mfwic 0:44a3005d4f20 400
mfwic 0:44a3005d4f20 401 }
mfwic 0:44a3005d4f20 402
mfwic 0:44a3005d4f20 403 /************************************************************
mfwic 0:44a3005d4f20 404 * Routine: getfval
mfwic 0:44a3005d4f20 405 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 406 * Returns: the value if it is being SET or 0 if it is a GET
mfwic 0:44a3005d4f20 407 * Description:
mfwic 0:44a3005d4f20 408 * Gets an float from the serial port connection.
mfwic 0:44a3005d4f20 409 *
mfwic 0:44a3005d4f20 410 **************************************************************/
mfwic 0:44a3005d4f20 411 float getfval(char setval)
mfwic 0:44a3005d4f20 412 {
mfwic 0:44a3005d4f20 413 if(setval)
mfwic 0:44a3005d4f20 414 return atof(&rxbuf[++bufloc]);
mfwic 0:44a3005d4f20 415 else
mfwic 0:44a3005d4f20 416 return 0;
mfwic 0:44a3005d4f20 417 }
mfwic 0:44a3005d4f20 418
mfwic 0:44a3005d4f20 419 /************************************************************
mfwic 0:44a3005d4f20 420 * Routine: validateEntry
mfwic 0:44a3005d4f20 421 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 422 * limlo -- low limit
mfwic 0:44a3005d4f20 423 * limhi -- high limit
mfwic 0:44a3005d4f20 424 * address -- address in eeprom to use
mfwic 0:44a3005d4f20 425 * Returns: 0 if entry validates and is written
mfwic 0:44a3005d4f20 426 * 1 if entry fails
mfwic 0:44a3005d4f20 427 * Description:
mfwic 0:44a3005d4f20 428 * Gets or sets a value in eeprom at the address but only
mfwic 0:44a3005d4f20 429 * if it is between the limits will it write the value to
mfwic 0:44a3005d4f20 430 * eeprom
mfwic 0:44a3005d4f20 431 *
mfwic 0:44a3005d4f20 432 **************************************************************/
mfwic 0:44a3005d4f20 433 int validateEntry(char setvalue, float limlo, float limhi, float *address)
mfwic 0:44a3005d4f20 434 {
mfwic 0:44a3005d4f20 435 float val;
mfwic 0:44a3005d4f20 436
mfwic 0:44a3005d4f20 437 if (setvalue)
mfwic 0:44a3005d4f20 438 {
mfwic 0:44a3005d4f20 439 val = getfval(SET);
mfwic 0:44a3005d4f20 440
mfwic 0:44a3005d4f20 441 if ((val >= limlo) && (val <= limhi))
mfwic 0:44a3005d4f20 442 {
mfwic 0:44a3005d4f20 443 *address = val;
mfwic 0:44a3005d4f20 444 }
mfwic 0:44a3005d4f20 445 else
mfwic 0:44a3005d4f20 446 {
mfwic 0:44a3005d4f20 447 showRangeError(0, 0, val);
mfwic 0:44a3005d4f20 448 return 0;
mfwic 0:44a3005d4f20 449 }
mfwic 0:44a3005d4f20 450 }
mfwic 0:44a3005d4f20 451 else
mfwic 0:44a3005d4f20 452 {
mfwic 0:44a3005d4f20 453 val = *address;
mfwic 1:9f8583ba2431 454 sprintf(strbuf, " %4.3f", val);
mfwic 1:9f8583ba2431 455 sendSerial(strbuf);
mfwic 0:44a3005d4f20 456 }
mfwic 0:44a3005d4f20 457
mfwic 0:44a3005d4f20 458 return 1;
mfwic 0:44a3005d4f20 459 }
mfwic 0:44a3005d4f20 460
mfwic 0:44a3005d4f20 461
mfwic 0:44a3005d4f20 462 /************************************************************
mfwic 0:44a3005d4f20 463 * Routine: validateEntry
mfwic 0:44a3005d4f20 464 * Input: setval (GET or SET)
mfwic 0:44a3005d4f20 465 * limlo -- low limit
mfwic 0:44a3005d4f20 466 * limhi -- high limit
mfwic 0:44a3005d4f20 467 * address -- address in eeprom to use
mfwic 0:44a3005d4f20 468 *
mfwic 0:44a3005d4f20 469 * Returns: FALSE if entry fails
mfwic 0:44a3005d4f20 470 * TRUE if entry validates and is written
mfwic 0:44a3005d4f20 471 *
mfwic 0:44a3005d4f20 472 * Description:
mfwic 0:44a3005d4f20 473 * Gets or sets a value in eeprom at the address but only
mfwic 0:44a3005d4f20 474 * if it is between the limits will it write the value to
mfwic 0:44a3005d4f20 475 * eeprom
mfwic 0:44a3005d4f20 476 *
mfwic 0:44a3005d4f20 477 **************************************************************/
mfwic 0:44a3005d4f20 478 int validateInt(char setvalue, int limlo, int limhi, int *address)
mfwic 0:44a3005d4f20 479 {
mfwic 0:44a3005d4f20 480 float val;
mfwic 0:44a3005d4f20 481
mfwic 0:44a3005d4f20 482 if (setvalue)
mfwic 0:44a3005d4f20 483 {
mfwic 0:44a3005d4f20 484 val = getfval(SET);
mfwic 0:44a3005d4f20 485
mfwic 0:44a3005d4f20 486 if ((val >= limlo) && (val <= limhi))
mfwic 0:44a3005d4f20 487 {
mfwic 0:44a3005d4f20 488 *address = val;
mfwic 0:44a3005d4f20 489 }
mfwic 0:44a3005d4f20 490 else
mfwic 0:44a3005d4f20 491 {
mfwic 0:44a3005d4f20 492 showRangeError(1, val, 0);
mfwic 0:44a3005d4f20 493 return FALSE;
mfwic 0:44a3005d4f20 494 }
mfwic 0:44a3005d4f20 495 }
mfwic 0:44a3005d4f20 496 else
mfwic 0:44a3005d4f20 497 {
mfwic 0:44a3005d4f20 498 val = *address;
mfwic 1:9f8583ba2431 499 sprintf(strbuf, " %4.0f", val);
mfwic 1:9f8583ba2431 500 sendSerial(strbuf);
mfwic 0:44a3005d4f20 501 }
mfwic 0:44a3005d4f20 502
mfwic 0:44a3005d4f20 503 return TRUE;
mfwic 0:44a3005d4f20 504 }
mfwic 0:44a3005d4f20 505
mfwic 0:44a3005d4f20 506
mfwic 0:44a3005d4f20 507 /************************************************************
mfwic 0:44a3005d4f20 508 * Routine: parseCommand
mfwic 0:44a3005d4f20 509 * Input: setvalue (GET or SET), command buffer
mfwic 0:44a3005d4f20 510 * Returns: none
mfwic 0:44a3005d4f20 511 * Description:
mfwic 0:44a3005d4f20 512 * parses a command and gets the commandstring
mfwic 0:44a3005d4f20 513 **************************************************************/
mfwic 0:44a3005d4f20 514 void parseCommand(char setvalue, char *commandString)
mfwic 0:44a3005d4f20 515 {
mfwic 0:44a3005d4f20 516 int i, endofc;
mfwic 0:44a3005d4f20 517 char store;
mfwic 0:44a3005d4f20 518
mfwic 0:44a3005d4f20 519 // Ignore any white space and the optional ';' character before the start of
mfwic 0:44a3005d4f20 520 // the command string (any ']' character is from the last command so skip that,
mfwic 0:44a3005d4f20 521 // too)
mfwic 0:44a3005d4f20 522 while ((isspace(rxbuf[bufloc])) || (rxbuf[bufloc] == ';') || (rxbuf[bufloc] == ']'))
mfwic 0:44a3005d4f20 523 {
mfwic 0:44a3005d4f20 524 bufloc++;
mfwic 0:44a3005d4f20 525 if ((rxbuf[bufloc] == 0x0D) || (rxbuf[bufloc] == 0)) break;
mfwic 0:44a3005d4f20 526 }
mfwic 0:44a3005d4f20 527
mfwic 0:44a3005d4f20 528 if (setvalue)
mfwic 0:44a3005d4f20 529 {
mfwic 0:44a3005d4f20 530 // We need a value for SET so hitting the end is a problem
mfwic 0:44a3005d4f20 531 if ((rxbuf[bufloc] == 0) || (rxbuf[bufloc] == 0x0D))
mfwic 0:44a3005d4f20 532 {
mfwic 0:44a3005d4f20 533 commandError = 1;
mfwic 0:44a3005d4f20 534 return;
mfwic 0:44a3005d4f20 535 }
mfwic 0:44a3005d4f20 536 }
mfwic 0:44a3005d4f20 537
mfwic 0:44a3005d4f20 538 // Find the end of the command string
mfwic 0:44a3005d4f20 539 endofc = bufloc + 1;
mfwic 0:44a3005d4f20 540
mfwic 0:44a3005d4f20 541 // White space, '[' and '?' all terminate the command string
mfwic 0:44a3005d4f20 542 while ((!isspace(rxbuf[endofc])) && (rxbuf[endofc] != '[') && (rxbuf[endofc] != '?'))
mfwic 0:44a3005d4f20 543 {
mfwic 0:44a3005d4f20 544 endofc++;
mfwic 0:44a3005d4f20 545 // (As does hitting the end of rxbuf!)
mfwic 0:44a3005d4f20 546 if ((rxbuf[endofc] == 0x0D) || (rxbuf[endofc] == 0)) break;
mfwic 0:44a3005d4f20 547 }
mfwic 0:44a3005d4f20 548
mfwic 0:44a3005d4f20 549 // Save the character that marks the end of the command string
mfwic 0:44a3005d4f20 550 store = rxbuf[endofc];
mfwic 0:44a3005d4f20 551
mfwic 1:9f8583ba2431 552 // sprintf(strbuf, "store == %c\r\n", store);
mfwic 1:9f8583ba2431 553 // sendSerial(strbuf);
mfwic 0:44a3005d4f20 554
mfwic 0:44a3005d4f20 555 // Command strings ending in '?' are readbacks
mfwic 0:44a3005d4f20 556 readback = ((store == '?') ? 1 : 0);
mfwic 0:44a3005d4f20 557
mfwic 0:44a3005d4f20 558 // Set end to null character so string can now be copied
mfwic 0:44a3005d4f20 559 rxbuf[endofc] = 0;
mfwic 0:44a3005d4f20 560
mfwic 0:44a3005d4f20 561 // Copy the command string into commandString
mfwic 5:09be5bbb5020 562 char commandStringBuf[80];
mfwic 5:09be5bbb5020 563 char *tok;
mfwic 5:09be5bbb5020 564 strcpy(commandStringBuf, &rxbuf[bufloc]);
mfwic 5:09be5bbb5020 565 if(strstr(commandStringBuf, "=")){
mfwic 5:09be5bbb5020 566 tok = strtok(commandStringBuf, "=");
mfwic 5:09be5bbb5020 567 strcpy(commandString, tok);
mfwic 5:09be5bbb5020 568 tok = strtok(NULL, "=");
Slord2142 33:6c7364ea360f 569 commandData = atof(tok);
mfwic 5:09be5bbb5020 570 }
mfwic 5:09be5bbb5020 571 else{
mfwic 5:09be5bbb5020 572 strcpy(commandString, commandStringBuf);
mfwic 5:09be5bbb5020 573 }
mfwic 0:44a3005d4f20 574
mfwic 0:44a3005d4f20 575 // Convert the command string to all uppercase characters
mfwic 0:44a3005d4f20 576 for (i = 0; i < strlen(commandString); i++)
mfwic 0:44a3005d4f20 577 {
mfwic 0:44a3005d4f20 578 commandString[i] = toupper(commandString[i]);
mfwic 0:44a3005d4f20 579 }
mfwic 0:44a3005d4f20 580
mfwic 0:44a3005d4f20 581 // Replace the character we clobbered in rxbuf
mfwic 0:44a3005d4f20 582 rxbuf[endofc] = store;
mfwic 0:44a3005d4f20 583
mfwic 0:44a3005d4f20 584 // Update bufloc to the end of the command string
mfwic 0:44a3005d4f20 585 bufloc = endofc;
mfwic 11:01dcfb29fbc4 586 }
mfwic 0:44a3005d4f20 587
mfwic 0:44a3005d4f20 588 /************************************************************
mfwic 0:44a3005d4f20 589 * Routine: doCommand
mfwic 0:44a3005d4f20 590 * Input: none
mfwic 0:44a3005d4f20 591 * Returns: none
mfwic 0:44a3005d4f20 592 * Description:
mfwic 0:44a3005d4f20 593 * This is the start of the command string.
mfwic 0:44a3005d4f20 594 **************************************************************/
mfwic 0:44a3005d4f20 595 void doCommand(void)
mfwic 0:44a3005d4f20 596 {
mfwic 6:39442d493098 597 int ival;
mfwic 0:44a3005d4f20 598 unsigned int boardEnables;
mfwic 0:44a3005d4f20 599
mfwic 0:44a3005d4f20 600 char commandString[80] = { 0 };
mfwic 0:44a3005d4f20 601
mfwic 0:44a3005d4f20 602 bufloc = 0;
mfwic 0:44a3005d4f20 603 commandError = 0;
mfwic 0:44a3005d4f20 604
mfwic 0:44a3005d4f20 605 parseCommand(GET, commandString);
mfwic 0:44a3005d4f20 606
mfwic 1:9f8583ba2431 607 if (!strcmp(commandString, "MENU"))
mfwic 1:9f8583ba2431 608 {
mfwic 8:d3d7dca419b3 609 menuRedraw(NO_PROMPT);
mfwic 1:9f8583ba2431 610 }
mfwic 3:d8948c5b2951 611 else if (!strcmp(commandString, "HELP"))
mfwic 3:d8948c5b2951 612 {
mfwic 8:d3d7dca419b3 613 menuRedraw(NO_PROMPT);
mfwic 3:d8948c5b2951 614 }
mfwic 25:8bcc8bea0e31 615 else if (!strcmp(commandString, "MAXB"))
mfwic 25:8bcc8bea0e31 616 // MAXB is used to get/set the max_boards value.
mfwic 25:8bcc8bea0e31 617 // The integer value of max_boards is used to select the appropriate lookup table.
mfwic 25:8bcc8bea0e31 618 {
mfwic 25:8bcc8bea0e31 619 if (readback)
mfwic 25:8bcc8bea0e31 620 {
mfwic 25:8bcc8bea0e31 621 sprintf(strbuf, " %d", max_boards);
mfwic 25:8bcc8bea0e31 622 sendSerial(strbuf);
mfwic 25:8bcc8bea0e31 623 }
mfwic 25:8bcc8bea0e31 624 else if (running == 1)
mfwic 25:8bcc8bea0e31 625 {
mfwic 25:8bcc8bea0e31 626 sprintf(strbuf, " Parameters may not be updated while running!");
mfwic 25:8bcc8bea0e31 627 sendSerial(strbuf);
mfwic 25:8bcc8bea0e31 628 }
mfwic 25:8bcc8bea0e31 629 else
mfwic 25:8bcc8bea0e31 630 {
mfwic 25:8bcc8bea0e31 631 max_boards = commandData;
mfwic 25:8bcc8bea0e31 632 }
mfwic 25:8bcc8bea0e31 633 }
mfwic 1:9f8583ba2431 634 else if (!strcmp(commandString, "BRDS"))
mfwic 1:9f8583ba2431 635 // BRDS is used to get/set the wr_out value.
mfwic 5:09be5bbb5020 636 // The integer value of boardsActive is used to change wr_out via setBoardEnables(boardsActive).
mfwic 1:9f8583ba2431 637 // Slots 12 to 0 are activated with the wr_out signals
mfwic 1:9f8583ba2431 638 // wr_out[13] = slots[12:0]
mfwic 0:44a3005d4f20 639 {
mfwic 0:44a3005d4f20 640 if (readback)
mfwic 0:44a3005d4f20 641 {
mfwic 5:09be5bbb5020 642 sprintf(strbuf, " %d", boardsActive);
mfwic 1:9f8583ba2431 643 sendSerial(strbuf);
mfwic 0:44a3005d4f20 644 }
mfwic 12:fd1fd1857628 645 else if (running == 1)
mfwic 12:fd1fd1857628 646 {
mfwic 12:fd1fd1857628 647 sprintf(strbuf, " Parameters may not be updated while running!");
mfwic 12:fd1fd1857628 648 sendSerial(strbuf);
mfwic 12:fd1fd1857628 649 }
mfwic 0:44a3005d4f20 650 else
mfwic 0:44a3005d4f20 651 {
mfwic 12:fd1fd1857628 652 boardsActive = commandData;
mfwic 12:fd1fd1857628 653 if(checkRange(boardsActive, 0, 8191) == 1){
mfwic 12:fd1fd1857628 654 wr_out_code = setBoardEnables(boardsActive);
mfwic 12:fd1fd1857628 655 testing = TRUE;
mfwic 1:9f8583ba2431 656 }else{
mfwic 5:09be5bbb5020 657 showRangeError(1, boardsActive, 0.0);
mfwic 1:9f8583ba2431 658 }
mfwic 1:9f8583ba2431 659 }
mfwic 1:9f8583ba2431 660 }
mfwic 1:9f8583ba2431 661 else if (!strcmp(commandString, "MULT"))
mfwic 1:9f8583ba2431 662 // MULT is used to get/set the en_out value.
mfwic 5:09be5bbb5020 663 // The integer value of boardMults is used to change en_out via setBoardWeights(boardMults).
mfwic 1:9f8583ba2431 664 // en_out are binary weighted signals that activate groups of DC-DC converters on the slot cards.
mfwic 1:9f8583ba2431 665 // en_out[6] = {en32, en16, en8, en4, en2, en1}
mfwic 1:9f8583ba2431 666 {
mfwic 1:9f8583ba2431 667 if (readback)
mfwic 1:9f8583ba2431 668 {
mfwic 5:09be5bbb5020 669 sprintf(strbuf, " %d", boardMults);
mfwic 1:9f8583ba2431 670 sendSerial(strbuf);
Slord2142 33:6c7364ea360f 671
mfwic 1:9f8583ba2431 672 }
mfwic 12:fd1fd1857628 673 else if (running == 1)
mfwic 12:fd1fd1857628 674 {
mfwic 12:fd1fd1857628 675 sprintf(strbuf, " Parameters may not be updated while running!");
mfwic 12:fd1fd1857628 676 sendSerial(strbuf);
mfwic 12:fd1fd1857628 677 }
mfwic 1:9f8583ba2431 678 else
mfwic 1:9f8583ba2431 679 {
mfwic 12:fd1fd1857628 680 boardMults = commandData;
mfwic 5:09be5bbb5020 681 if(checkRange(boardMults, 0, 63) == 1){
mfwic 6:39442d493098 682 en_out_code = setBoardWeights(boardMults);
mfwic 12:fd1fd1857628 683 testing = TRUE;
mfwic 1:9f8583ba2431 684 }else{
mfwic 5:09be5bbb5020 685 showRangeError(1, boardMults, 0.0);
mfwic 1:9f8583ba2431 686 }
mfwic 0:44a3005d4f20 687 }
Slord2142 33:6c7364ea360f 688 }/*
Slord2142 33:6c7364ea360f 689 else if (!strcmp(commandString, "PERM"))
Slord2142 33:6c7364ea360f 690 {
Slord2142 33:6c7364ea360f 691 if (readback)
Slord2142 33:6c7364ea360f 692 {
Slord2142 33:6c7364ea360f 693 reader.open(sector_index);
Slord2142 33:6c7364ea360f 694 //printf("data %d bytes at %p :\r\n", reader.get_data_size(), reader.get_physical_data_addr());
Slord2142 33:6c7364ea360f 695 //printf("%.*s\r\n", reader.get_data_size(), reader.get_physical_data_addr());
Slord2142 33:6c7364ea360f 696 storo = reader.get_physical_data_addr();
Slord2142 33:6c7364ea360f 697 reader.close();
Slord2142 33:6c7364ea360f 698 printf("%s\r\n", storo);
Slord2142 33:6c7364ea360f 699 sprintf(storage, "%s", storo);
Slord2142 33:6c7364ea360f 700 int storage_size = strlen(storage);
Slord2142 33:6c7364ea360f 701 char delim[] = ":";
Slord2142 33:6c7364ea360f 702 char *ptr = strtok(storage, delim);
Slord2142 33:6c7364ea360f 703 if (ptr != NULL)
Slord2142 33:6c7364ea360f 704 {
Slord2142 33:6c7364ea360f 705 CURRENT_48_DIV_FACTOR0 = atoi(ptr);
Slord2142 33:6c7364ea360f 706 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 707 if (ptr != NULL)
Slord2142 33:6c7364ea360f 708 {
Slord2142 33:6c7364ea360f 709 CURRENT_48_DIV_FACTOR1 = atoi(ptr);
Slord2142 33:6c7364ea360f 710 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 711 if (ptr != NULL)
Slord2142 33:6c7364ea360f 712 {
Slord2142 33:6c7364ea360f 713 CURRENT_48_DIV_FACTOR2 = atoi(ptr);
Slord2142 33:6c7364ea360f 714 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 715 if (ptr != NULL)
Slord2142 33:6c7364ea360f 716 {
Slord2142 33:6c7364ea360f 717 CURRENT_48_DIV_FACTOR3 = atoi(ptr);
Slord2142 33:6c7364ea360f 718 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 719 if (ptr != NULL)
Slord2142 33:6c7364ea360f 720 {
Slord2142 33:6c7364ea360f 721 CURRENT_48_DIV_FACTOR4 = atoi(ptr);
Slord2142 33:6c7364ea360f 722 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 723 if (ptr != NULL)
Slord2142 33:6c7364ea360f 724 {
Slord2142 33:6c7364ea360f 725 CURRENT_48_DIV_FACTOR5 = atoi(ptr);
Slord2142 33:6c7364ea360f 726 printf("%d\r\n", CURRENT_48_DIV_FACTOR0);
Slord2142 33:6c7364ea360f 727 printf("%d\r\n", CURRENT_48_DIV_FACTOR1);
Slord2142 33:6c7364ea360f 728 printf("%d\r\n", CURRENT_48_DIV_FACTOR2);
Slord2142 33:6c7364ea360f 729 printf("%d\r\n", CURRENT_48_DIV_FACTOR3);
Slord2142 33:6c7364ea360f 730 printf("%d\r\n", CURRENT_48_DIV_FACTOR4);
Slord2142 33:6c7364ea360f 731 printf("%d\r\n", CURRENT_48_DIV_FACTOR5);
Slord2142 33:6c7364ea360f 732 } else {
Slord2142 33:6c7364ea360f 733 printf("Insufficient variables found.");
Slord2142 33:6c7364ea360f 734 }
Slord2142 33:6c7364ea360f 735 } else {
Slord2142 33:6c7364ea360f 736 printf("Infussicient variables found.");
Slord2142 33:6c7364ea360f 737 }
Slord2142 33:6c7364ea360f 738 } else {
Slord2142 33:6c7364ea360f 739 printf("Insufficient variables found.");
Slord2142 33:6c7364ea360f 740 }
Slord2142 33:6c7364ea360f 741 } else {
Slord2142 33:6c7364ea360f 742 printf("Insufficient variables found.");
Slord2142 33:6c7364ea360f 743 }
Slord2142 33:6c7364ea360f 744 } else {
Slord2142 33:6c7364ea360f 745 printf("Insufficient variables found.");
Slord2142 33:6c7364ea360f 746 }
Slord2142 33:6c7364ea360f 747 } else {
Slord2142 33:6c7364ea360f 748 printf("Infufficient variables found.");
Slord2142 33:6c7364ea360f 749 }
Slord2142 33:6c7364ea360f 750 sendSerial(strbuf);
Slord2142 33:6c7364ea360f 751
Slord2142 33:6c7364ea360f 752 }
Slord2142 33:6c7364ea360f 753 else if (running == 1)
Slord2142 33:6c7364ea360f 754 {
Slord2142 33:6c7364ea360f 755 sprintf(strbuf, " Parameters may not be updated while running!");
Slord2142 33:6c7364ea360f 756 sendSerial(strbuf);
Slord2142 33:6c7364ea360f 757 }
Slord2142 33:6c7364ea360f 758 else
Slord2142 33:6c7364ea360f 759 {
Slord2142 33:6c7364ea360f 760 if(checkRange(boardMults, 0, 63) == 1){
Slord2142 33:6c7364ea360f 761 writer.open(sector_index) ;
Slord2142 33:6c7364ea360f 762 writer.write_data((uint8_t*) storoBuild, sizeof storoBuild);
Slord2142 33:6c7364ea360f 763 writer.close();
Slord2142 33:6c7364ea360f 764 testing = TRUE;
Slord2142 33:6c7364ea360f 765 }else{
Slord2142 33:6c7364ea360f 766 showRangeError(1, boardMults, 0.0);
Slord2142 33:6c7364ea360f 767 }
Slord2142 33:6c7364ea360f 768 }
mfwic 0:44a3005d4f20 769 }
Slord2142 33:6c7364ea360f 770 else if (!strcmp(commandString, "PREP"))
Slord2142 33:6c7364ea360f 771 {
Slord2142 33:6c7364ea360f 772 if (readback)
Slord2142 33:6c7364ea360f 773 {
Slord2142 33:6c7364ea360f 774 printf("%s\r\n", storo);
Slord2142 33:6c7364ea360f 775 sendSerial(strbuf);
Slord2142 33:6c7364ea360f 776 }
Slord2142 33:6c7364ea360f 777 else
Slord2142 33:6c7364ea360f 778 {
Slord2142 33:6c7364ea360f 779 if (commandData == 0)
Slord2142 33:6c7364ea360f 780 {
Slord2142 33:6c7364ea360f 781 memset(storoBuild, 0, sizeof storoBuild);
Slord2142 33:6c7364ea360f 782 }
Slord2142 33:6c7364ea360f 783 else
Slord2142 33:6c7364ea360f 784 {
Slord2142 33:6c7364ea360f 785 sprintf(storoFrag, "%d", commandData);
Slord2142 33:6c7364ea360f 786 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 787 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 788 if(checkRange(boardMults, 0, 63) == 1){
Slord2142 33:6c7364ea360f 789 printf("%s\r\n", storoBuild);
Slord2142 33:6c7364ea360f 790 testing = TRUE;
Slord2142 33:6c7364ea360f 791 }else{
Slord2142 33:6c7364ea360f 792 showRangeError(1, boardMults, 0.0);
Slord2142 33:6c7364ea360f 793 }
Slord2142 33:6c7364ea360f 794 }
Slord2142 33:6c7364ea360f 795 }
Slord2142 33:6c7364ea360f 796 }*/
Slord2142 33:6c7364ea360f 797 else if (!strcmp(commandString, "SECT"))
Slord2142 33:6c7364ea360f 798 {
Slord2142 33:6c7364ea360f 799 if (commandData == 48)
Slord2142 33:6c7364ea360f 800 {
Slord2142 33:6c7364ea360f 801 section = 48;
Slord2142 33:6c7364ea360f 802 }
Slord2142 33:6c7364ea360f 803 else if (commandData == 24)
Slord2142 33:6c7364ea360f 804 {
Slord2142 33:6c7364ea360f 805 section = 24;
Slord2142 33:6c7364ea360f 806 fort = 0;
Slord2142 33:6c7364ea360f 807 }
Slord2142 33:6c7364ea360f 808 else if (commandData == 12)
Slord2142 33:6c7364ea360f 809 {
Slord2142 33:6c7364ea360f 810 section = 12;
Slord2142 33:6c7364ea360f 811 }
Slord2142 33:6c7364ea360f 812 else {
Slord2142 33:6c7364ea360f 813 printf("Input not accepted.");
Slord2142 33:6c7364ea360f 814 }
Slord2142 33:6c7364ea360f 815 }/*
Slord2142 33:6c7364ea360f 816 else if (!strcmp(commandString, "FORT"))
Slord2142 33:6c7364ea360f 817 {
Slord2142 33:6c7364ea360f 818 if (readback)
Slord2142 33:6c7364ea360f 819 {
Slord2142 33:6c7364ea360f 820 if (fort == 0)
Slord2142 33:6c7364ea360f 821 {
Slord2142 33:6c7364ea360f 822 printf("Currently accessing: Div Factors \r\n");
Slord2142 33:6c7364ea360f 823 }
Slord2142 33:6c7364ea360f 824 else if (fort == 1)
Slord2142 33:6c7364ea360f 825 {
Slord2142 33:6c7364ea360f 826 printf("Currently accessing: Div Thresholds \r\n");
Slord2142 33:6c7364ea360f 827 } else {
Slord2142 33:6c7364ea360f 828 printf("Currently accessing: Nothing \r\n");
Slord2142 33:6c7364ea360f 829 }
Slord2142 33:6c7364ea360f 830 }else if (section != 24){
Slord2142 33:6c7364ea360f 831 if (commandData == 0)
Slord2142 33:6c7364ea360f 832 {
Slord2142 33:6c7364ea360f 833 fort = 0;
Slord2142 33:6c7364ea360f 834 printf("Now accessing: Div Factors \r\n");
Slord2142 33:6c7364ea360f 835 }
Slord2142 33:6c7364ea360f 836 else if (commandData == 1)
Slord2142 33:6c7364ea360f 837 {
Slord2142 33:6c7364ea360f 838 fort = 1;
Slord2142 33:6c7364ea360f 839 printf("Now accessing: Div Thresholds \r\n");
Slord2142 33:6c7364ea360f 840 }
Slord2142 33:6c7364ea360f 841 }
Slord2142 33:6c7364ea360f 842 }*/
Slord2142 33:6c7364ea360f 843 else if (!strcmp(commandString, "DIAL"))
Slord2142 33:6c7364ea360f 844 {
Slord2142 33:6c7364ea360f 845 if (Vloc == 0)
Slord2142 33:6c7364ea360f 846 {
Slord2142 33:6c7364ea360f 847 if (section == 48)
Slord2142 33:6c7364ea360f 848 {
Slord2142 33:6c7364ea360f 849 printf("Begin Voltage 48 calibration? (Enter Dial=1 to continue)");
Slord2142 33:6c7364ea360f 850 Vloc = -1;
Slord2142 33:6c7364ea360f 851 }
Slord2142 33:6c7364ea360f 852 else if (section == 24)
Slord2142 33:6c7364ea360f 853 {
Slord2142 33:6c7364ea360f 854 printf("Begin Voltage 24 calibration? (Enter Dial=1 to continue)");
Slord2142 33:6c7364ea360f 855 Vloc = 7;
Slord2142 33:6c7364ea360f 856 }
Slord2142 33:6c7364ea360f 857 else if (section == 12)
Slord2142 33:6c7364ea360f 858 {
Slord2142 33:6c7364ea360f 859 printf("Begin Voltage 12 calibration? (Enter Dial=1 to continue)");
Slord2142 33:6c7364ea360f 860 Vloc = 1;
Slord2142 33:6c7364ea360f 861 }
Slord2142 33:6c7364ea360f 862 }
Slord2142 33:6c7364ea360f 863 else if (Vloc == 1)
Slord2142 33:6c7364ea360f 864 {
Slord2142 33:6c7364ea360f 865 if (commandData == 1)
Slord2142 33:6c7364ea360f 866 {
Slord2142 33:6c7364ea360f 867 printf("Enter actual output at 12V load. (ex. Dial=1.52)");
Slord2142 33:6c7364ea360f 868 Vloc = 2;
Slord2142 33:6c7364ea360f 869 } else{
Slord2142 33:6c7364ea360f 870 printf("Calibration cancelled.");
Slord2142 33:6c7364ea360f 871 Vloc = 0;
Slord2142 33:6c7364ea360f 872 }
Slord2142 33:6c7364ea360f 873 }
Slord2142 33:6c7364ea360f 874 else if (Vloc == 2)
Slord2142 33:6c7364ea360f 875 {
Slord2142 33:6c7364ea360f 876 VOLTAGE_CAL_1 = commandData;
Slord2142 33:6c7364ea360f 877 printf("Enter actual output at 10V load. (ex. Dial=1.08)");
Slord2142 33:6c7364ea360f 878 Vloc = 3;
Slord2142 33:6c7364ea360f 879 }
Slord2142 33:6c7364ea360f 880 else if (Vloc == 3)
Slord2142 33:6c7364ea360f 881 {
Slord2142 33:6c7364ea360f 882 VOLTAGE_CAL_2 = commandData;
Slord2142 33:6c7364ea360f 883 printf("Enter actual output at 8V load. (ex. Dial=0.58)");
Slord2142 33:6c7364ea360f 884 Vloc = 4;
Slord2142 33:6c7364ea360f 885 }
Slord2142 33:6c7364ea360f 886 else if (Vloc == 4)
Slord2142 33:6c7364ea360f 887 {
Slord2142 33:6c7364ea360f 888 VOLTAGE_CAL_3 = commandData;
Slord2142 33:6c7364ea360f 889 Vloc = 0;
Slord2142 33:6c7364ea360f 890 VOLTAGE_12_ACTUAL_VALUE = (VOLTAGE_CAL_1-VOLTAGE_CAL_3)*0.4125;
Slord2142 33:6c7364ea360f 891 printf("\r\n%4.2f, %4.2f", VOLTAGE_CAL_1, VOLTAGE_CAL_3);
Slord2142 33:6c7364ea360f 892 VOLTAGE_12_OFFSET = VOLTAGE_CAL_1-(VOLTAGE_12_ACTUAL_VALUE*12/1.65)+((VOLTAGE_CAL_2-(VOLTAGE_12_ACTUAL_VALUE*10/1.65))*0.5);
Slord2142 33:6c7364ea360f 893 printf("\r\n12V calibration completed.\r\n");
Slord2142 33:6c7364ea360f 894 printf("%4.2f, %4.2f\r\n", VOLTAGE_12_ACTUAL_VALUE, VOLTAGE_12_OFFSET);
Slord2142 33:6c7364ea360f 895 }
Slord2142 33:6c7364ea360f 896 else if (Vloc == -1)
Slord2142 33:6c7364ea360f 897 {
Slord2142 33:6c7364ea360f 898 if (commandData == 1)
Slord2142 33:6c7364ea360f 899 {
Slord2142 33:6c7364ea360f 900 printf("\r\n Enter actual output at 48V load. (ex. Dial=1.52) \r\n");
Slord2142 33:6c7364ea360f 901 Vloc = -2;
Slord2142 33:6c7364ea360f 902 } else{
Slord2142 33:6c7364ea360f 903 printf("Calibration cancelled.");
Slord2142 33:6c7364ea360f 904 Vloc = 0;
Slord2142 33:6c7364ea360f 905 }
Slord2142 33:6c7364ea360f 906 }
Slord2142 33:6c7364ea360f 907 else if (Vloc == -2)
Slord2142 33:6c7364ea360f 908 {
Slord2142 33:6c7364ea360f 909 VOLTAGE_CAL_1 = commandData;
Slord2142 33:6c7364ea360f 910 printf("\r\n Enter actual output at 44V load. (ex. Dial=1.08) \r\n");
Slord2142 33:6c7364ea360f 911 Vloc = -3;
Slord2142 33:6c7364ea360f 912 }
Slord2142 33:6c7364ea360f 913 else if (Vloc == -3)
Slord2142 33:6c7364ea360f 914 {
Slord2142 33:6c7364ea360f 915 VOLTAGE_CAL_2 = commandData;
Slord2142 33:6c7364ea360f 916 printf("\r\n Enter actual output at 40V load. (ex. Dial=0.58) \r\n");
Slord2142 33:6c7364ea360f 917 Vloc = -4;
Slord2142 33:6c7364ea360f 918 }
Slord2142 33:6c7364ea360f 919 else if (Vloc == -4)
Slord2142 33:6c7364ea360f 920 {
Slord2142 33:6c7364ea360f 921 VOLTAGE_CAL_3 = commandData;
Slord2142 33:6c7364ea360f 922 Vloc = 0;
Slord2142 33:6c7364ea360f 923 VOLTAGE_48_ACTUAL_VALUE = (VOLTAGE_CAL_1-VOLTAGE_CAL_3)*0.20625;
Slord2142 33:6c7364ea360f 924 printf("\r\n%4.2f, %4.2f", VOLTAGE_CAL_1, VOLTAGE_CAL_3);
Slord2142 33:6c7364ea360f 925 VOLTAGE_48_OFFSET = VOLTAGE_CAL_1-(VOLTAGE_12_ACTUAL_VALUE*48/1.65)+((VOLTAGE_CAL_2-(VOLTAGE_12_ACTUAL_VALUE*44/1.65))*0.5);
Slord2142 33:6c7364ea360f 926 printf("\r\n48V calibration completed.\r\n");
Slord2142 33:6c7364ea360f 927 printf("%4.2f, %4.2f\r\n", VOLTAGE_12_ACTUAL_VALUE, VOLTAGE_12_OFFSET);
Slord2142 33:6c7364ea360f 928 }
Slord2142 33:6c7364ea360f 929 else if (Vloc == 7)
Slord2142 33:6c7364ea360f 930 {
Slord2142 33:6c7364ea360f 931 if (commandData == 1)
Slord2142 33:6c7364ea360f 932 {
Slord2142 33:6c7364ea360f 933 printf("\r\n Enter actual output at 24V load. (ex. Dial=1.52) \r\n");
Slord2142 33:6c7364ea360f 934 Vloc = 13;
Slord2142 33:6c7364ea360f 935 } else{
Slord2142 33:6c7364ea360f 936 printf("Calibration cancelled.");
Slord2142 33:6c7364ea360f 937 Vloc = 0;
Slord2142 33:6c7364ea360f 938 }
Slord2142 33:6c7364ea360f 939 }
Slord2142 33:6c7364ea360f 940 else if (Vloc == 13)
Slord2142 33:6c7364ea360f 941 {
Slord2142 33:6c7364ea360f 942 VOLTAGE_CAL_1 = commandData;
Slord2142 33:6c7364ea360f 943 printf("\r\n Enter actual output at 21V load. (ex. Dial=1.08) \r\n");
Slord2142 33:6c7364ea360f 944 Vloc = 21;
Slord2142 33:6c7364ea360f 945 }
Slord2142 33:6c7364ea360f 946 else if (Vloc == 21)
Slord2142 33:6c7364ea360f 947 {
Slord2142 33:6c7364ea360f 948 VOLTAGE_CAL_2 = commandData;
Slord2142 33:6c7364ea360f 949 printf("\r\n Enter actual output at 18V load. (ex. Dial=0.58) \r\n");
Slord2142 33:6c7364ea360f 950 Vloc = 42;
Slord2142 33:6c7364ea360f 951 }
Slord2142 33:6c7364ea360f 952 else if (Vloc == 42)
Slord2142 33:6c7364ea360f 953 {
Slord2142 33:6c7364ea360f 954 VOLTAGE_CAL_3 = commandData;
Slord2142 33:6c7364ea360f 955 Vloc = 0;
Slord2142 33:6c7364ea360f 956 VOLTAGE_24_ACTUAL_VALUE = (VOLTAGE_CAL_1-VOLTAGE_CAL_3)*0.275;
Slord2142 33:6c7364ea360f 957 printf("\r\n%4.2f, %4.2f", VOLTAGE_CAL_1, VOLTAGE_CAL_3);
Slord2142 33:6c7364ea360f 958 VOLTAGE_24_OFFSET = VOLTAGE_CAL_1-(VOLTAGE_12_ACTUAL_VALUE*24/1.65)+((VOLTAGE_CAL_2-(VOLTAGE_12_ACTUAL_VALUE*21/1.65))*0.5);
Slord2142 33:6c7364ea360f 959 printf("\r\n24V calibration completed.\r\n");
Slord2142 33:6c7364ea360f 960 printf("%4.2f, %4.2f\r\n", VOLTAGE_12_ACTUAL_VALUE, VOLTAGE_12_OFFSET);
Slord2142 33:6c7364ea360f 961 }
Slord2142 33:6c7364ea360f 962 }
Slord2142 33:6c7364ea360f 963 else if (!strcmp(commandString, "SCL"))
Slord2142 33:6c7364ea360f 964 {
Slord2142 33:6c7364ea360f 965 if (section == 48)
Slord2142 33:6c7364ea360f 966 {
Slord2142 33:6c7364ea360f 967 printf("Not yet implimented.");
Slord2142 33:6c7364ea360f 968 }
Slord2142 33:6c7364ea360f 969 else if (section == 24)
Slord2142 33:6c7364ea360f 970 {
Slord2142 33:6c7364ea360f 971 printf("Not yet implimented.");
Slord2142 33:6c7364ea360f 972 }
Slord2142 33:6c7364ea360f 973 else if (section == 12)
Slord2142 33:6c7364ea360f 974 {
Slord2142 33:6c7364ea360f 975 if (Aloc == 0)
Slord2142 33:6c7364ea360f 976 {
Slord2142 33:6c7364ea360f 977 printf("Begin Voltage 12 current calibration? (Enter Scl=1 to continue)");
Slord2142 33:6c7364ea360f 978 Aloc = -1;
Slord2142 33:6c7364ea360f 979 }
Slord2142 33:6c7364ea360f 980 else if (Aloc == -1)
Slord2142 33:6c7364ea360f 981 {
Slord2142 33:6c7364ea360f 982 if (commandData == 1)
Slord2142 33:6c7364ea360f 983 {
Slord2142 33:6c7364ea360f 984 printf("Set current to smallest reference point(1/6). Enter actual current amount. (Ex. Scl=1.25)");
Slord2142 33:6c7364ea360f 985 Aloc = -2;
Slord2142 33:6c7364ea360f 986 } else{
Slord2142 33:6c7364ea360f 987 printf("Calibration cancelled.");
Slord2142 33:6c7364ea360f 988 Aloc = 0;
Slord2142 33:6c7364ea360f 989 }
Slord2142 33:6c7364ea360f 990 }
Slord2142 33:6c7364ea360f 991 else if (Aloc == -2)
Slord2142 33:6c7364ea360f 992 {
Slord2142 33:6c7364ea360f 993 CURRENT_IN_1 = commandData;
Slord2142 33:6c7364ea360f 994 adcValues adcVals = getADCresults();
Slord2142 33:6c7364ea360f 995 CURRENT_REF_1 = adcVals.i12;
Slord2142 33:6c7364ea360f 996 printf("Increase input current. Enter new actual input current(2/6).");
Slord2142 33:6c7364ea360f 997 Aloc = -3;
Slord2142 33:6c7364ea360f 998 }
Slord2142 33:6c7364ea360f 999 else if (Aloc == -3)
Slord2142 33:6c7364ea360f 1000 {
Slord2142 33:6c7364ea360f 1001 CURRENT_IN_2 = commandData;
Slord2142 33:6c7364ea360f 1002 adcValues adcVals = getADCresults();
Slord2142 33:6c7364ea360f 1003 CURRENT_REF_2 = adcVals.i12;
Slord2142 33:6c7364ea360f 1004 printf("Increase input current. Enter new actual input current(3/6).");
Slord2142 33:6c7364ea360f 1005 Aloc = -4;
Slord2142 33:6c7364ea360f 1006 }
Slord2142 33:6c7364ea360f 1007 else if (Aloc == -4)
Slord2142 33:6c7364ea360f 1008 {
Slord2142 33:6c7364ea360f 1009 CURRENT_IN_3 = commandData;
Slord2142 33:6c7364ea360f 1010 adcValues adcVals = getADCresults();
Slord2142 33:6c7364ea360f 1011 CURRENT_REF_3 = adcVals.i12;
Slord2142 33:6c7364ea360f 1012 printf("Increase input current. Enter new actual input current(4/6).");
Slord2142 33:6c7364ea360f 1013 Aloc = -5;
Slord2142 33:6c7364ea360f 1014 }
Slord2142 33:6c7364ea360f 1015 else if (Aloc == -5)
Slord2142 33:6c7364ea360f 1016 {
Slord2142 33:6c7364ea360f 1017 CURRENT_IN_4 = commandData;
Slord2142 33:6c7364ea360f 1018 adcValues adcVals = getADCresults();
Slord2142 33:6c7364ea360f 1019 CURRENT_REF_4 = adcVals.i12;
Slord2142 33:6c7364ea360f 1020 printf("Increase input current. Enter new actual input current(5/6).");
Slord2142 33:6c7364ea360f 1021 Aloc = -6;
Slord2142 33:6c7364ea360f 1022 }
Slord2142 33:6c7364ea360f 1023 else if (Aloc == -6)
Slord2142 33:6c7364ea360f 1024 {
Slord2142 33:6c7364ea360f 1025 CURRENT_IN_5 = commandData;
Slord2142 33:6c7364ea360f 1026 adcValues adcVals = getADCresults();
Slord2142 33:6c7364ea360f 1027 CURRENT_REF_5 = adcVals.i12;
Slord2142 33:6c7364ea360f 1028 printf("Increase input current. Enter new actual input current(6/6).");
Slord2142 33:6c7364ea360f 1029 Aloc = -7;
Slord2142 33:6c7364ea360f 1030 }
Slord2142 33:6c7364ea360f 1031 else if (Aloc == -7)
Slord2142 33:6c7364ea360f 1032 {
Slord2142 33:6c7364ea360f 1033 CURRENT_IN_6 = commandData;
Slord2142 33:6c7364ea360f 1034 adcValues adcVals = getADCresults();
Slord2142 33:6c7364ea360f 1035 CURRENT_REF_6 = adcVals.i12;
Slord2142 33:6c7364ea360f 1036 Aloc = 0;
Slord2142 35:ec224d706f7c 1037 sprintf(strbuf, " %f;%d;%d", CURRENT_12_OFFSET,CURRENT_12_DIV_THRESH5,CURRENT_12_DIV_THRESH1);
Slord2142 35:ec224d706f7c 1038 sendSerial(strbuf);
Slord2142 33:6c7364ea360f 1039 if ((CURRENT_REF_6 - CURRENT_12_OFFSET < 0 && CURRENT_REF_1 - CURRENT_12_OFFSET < 0 && CURRENT_REF_6 > CURRENT_REF_1)
Slord2142 33:6c7364ea360f 1040 || (CURRENT_REF_6 - CURRENT_12_OFFSET > 0 && CURRENT_REF_1 - CURRENT_12_OFFSET > 0 && CURRENT_REF_6 < CURRENT_REF_1))
Slord2142 33:6c7364ea360f 1041 {
Slord2142 33:6c7364ea360f 1042 CURRENT_12_DIV_THRESH5 = CURRENT_REF_1-CURRENT_12_OFFSET;
Slord2142 33:6c7364ea360f 1043 CURRENT_12_DIV_THRESH4 = CURRENT_REF_2-CURRENT_12_OFFSET;
Slord2142 33:6c7364ea360f 1044 CURRENT_12_DIV_THRESH3 = CURRENT_REF_3-CURRENT_12_OFFSET;
Slord2142 33:6c7364ea360f 1045 CURRENT_12_DIV_THRESH2 = CURRENT_REF_4-CURRENT_12_OFFSET;
Slord2142 33:6c7364ea360f 1046 CURRENT_12_DIV_THRESH1 = CURRENT_REF_5-CURRENT_12_OFFSET;
Slord2142 33:6c7364ea360f 1047 CURRENT_12_DIV_FACTOR5 = (CURRENT_REF_1-CURRENT_12_OFFSET)/CURRENT_IN_1;
Slord2142 33:6c7364ea360f 1048 CURRENT_12_CORRECTION4 = ((CURRENT_REF_1-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR5)-CURRENT_IN_1;
Slord2142 33:6c7364ea360f 1049 CURRENT_12_DIV_FACTOR4 = (CURRENT_REF_2-CURRENT_REF_1)/(CURRENT_IN_2-CURRENT_IN_1);
Slord2142 33:6c7364ea360f 1050 CURRENT_12_CORRECTION4 = ((CURRENT_REF_2-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR4)-CURRENT_IN_2;
Slord2142 33:6c7364ea360f 1051 CURRENT_12_DIV_FACTOR3 = (CURRENT_REF_3-CURRENT_REF_2)/(CURRENT_IN_3-CURRENT_IN_2);
Slord2142 33:6c7364ea360f 1052 CURRENT_12_CORRECTION3 = ((CURRENT_REF_3-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR3)-CURRENT_IN_3;
Slord2142 33:6c7364ea360f 1053 CURRENT_12_DIV_FACTOR2 = (CURRENT_REF_4-CURRENT_REF_3)/(CURRENT_IN_4-CURRENT_IN_3);
Slord2142 33:6c7364ea360f 1054 CURRENT_12_CORRECTION2 = ((CURRENT_REF_4-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR2)-CURRENT_IN_4;
Slord2142 33:6c7364ea360f 1055 CURRENT_12_DIV_FACTOR1 = (CURRENT_REF_5-CURRENT_REF_4)/(CURRENT_IN_5-CURRENT_IN_4);
Slord2142 33:6c7364ea360f 1056 CURRENT_12_CORRECTION1 = ((CURRENT_REF_5-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR1)-CURRENT_IN_5;
Slord2142 33:6c7364ea360f 1057 CURRENT_12_DIV_FACTOR0 = (CURRENT_REF_6-CURRENT_REF_5)/(CURRENT_IN_6-CURRENT_IN_5);
Slord2142 33:6c7364ea360f 1058 CURRENT_12_CORRECTION0 = ((CURRENT_REF_6-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR0)-CURRENT_IN_6;
Slord2142 33:6c7364ea360f 1059 }
Slord2142 33:6c7364ea360f 1060 else if ((CURRENT_REF_6 - CURRENT_12_OFFSET < 0 && CURRENT_REF_1 - CURRENT_12_OFFSET < 0 && CURRENT_REF_6 < CURRENT_REF_1)
Slord2142 33:6c7364ea360f 1061 || (CURRENT_REF_6 - CURRENT_12_OFFSET > 0 && CURRENT_REF_1 - CURRENT_12_OFFSET > 0 && CURRENT_REF_6 > CURRENT_REF_1))
Slord2142 33:6c7364ea360f 1062 {
Slord2142 33:6c7364ea360f 1063 CURRENT_12_DIV_THRESH5 = CURRENT_REF_5-CURRENT_12_OFFSET;
Slord2142 33:6c7364ea360f 1064 CURRENT_12_DIV_THRESH4 = CURRENT_REF_4-CURRENT_12_OFFSET;
Slord2142 33:6c7364ea360f 1065 CURRENT_12_DIV_THRESH3 = CURRENT_REF_3-CURRENT_12_OFFSET;
Slord2142 33:6c7364ea360f 1066 CURRENT_12_DIV_THRESH2 = CURRENT_REF_2-CURRENT_12_OFFSET;
Slord2142 33:6c7364ea360f 1067 CURRENT_12_DIV_THRESH1 = CURRENT_REF_1-CURRENT_12_OFFSET;
Slord2142 33:6c7364ea360f 1068 CURRENT_12_DIV_FACTOR0 = (CURRENT_REF_1-CURRENT_12_OFFSET)/CURRENT_IN_1;
Slord2142 33:6c7364ea360f 1069 CURRENT_12_CORRECTION0 = 0;
Slord2142 33:6c7364ea360f 1070 CURRENT_12_DIV_FACTOR1 = (CURRENT_REF_2-CURRENT_REF_1)/(CURRENT_IN_2-CURRENT_IN_1);
Slord2142 33:6c7364ea360f 1071 CURRENT_12_CORRECTION1 = ((CURRENT_REF_2-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR1)-CURRENT_IN_2;
Slord2142 33:6c7364ea360f 1072 CURRENT_12_DIV_FACTOR2 = (CURRENT_REF_3-CURRENT_REF_2)/(CURRENT_IN_3-CURRENT_IN_2);
Slord2142 33:6c7364ea360f 1073 CURRENT_12_CORRECTION2 = ((CURRENT_REF_3-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR2)-CURRENT_IN_3;
Slord2142 33:6c7364ea360f 1074 CURRENT_12_DIV_FACTOR3 = (CURRENT_REF_4-CURRENT_REF_3)/(CURRENT_IN_4-CURRENT_IN_3);
Slord2142 33:6c7364ea360f 1075 CURRENT_12_CORRECTION3 = ((CURRENT_REF_4-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR3)-CURRENT_IN_4;
Slord2142 33:6c7364ea360f 1076 CURRENT_12_DIV_FACTOR4 = (CURRENT_REF_5-CURRENT_REF_4)/(CURRENT_IN_5-CURRENT_IN_4);
Slord2142 33:6c7364ea360f 1077 CURRENT_12_CORRECTION4 = ((CURRENT_REF_5-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR4)-CURRENT_IN_5;
Slord2142 33:6c7364ea360f 1078 CURRENT_12_DIV_FACTOR5 = (CURRENT_REF_6-CURRENT_REF_5)/(CURRENT_IN_6-CURRENT_IN_5);
Slord2142 33:6c7364ea360f 1079 CURRENT_12_CORRECTION5 = ((CURRENT_REF_6-CURRENT_12_OFFSET)/CURRENT_12_DIV_FACTOR5)-CURRENT_IN_6;
Slord2142 33:6c7364ea360f 1080 }
Slord2142 35:ec224d706f7c 1081 sprintf(strbuf, " %f;%d;%d", CURRENT_12_OFFSET,CURRENT_12_DIV_THRESH5,CURRENT_12_DIV_THRESH1);
Slord2142 35:ec224d706f7c 1082 sendSerial(strbuf);
Slord2142 33:6c7364ea360f 1083 printf("\r\n12V current calibration completed.\r\n");
Slord2142 33:6c7364ea360f 1084 //printf("%4.2f, %4.2f\r\n", VOLTAGE_12_ACTUAL_VALUE, VOLTAGE_12_OFFSET);
Slord2142 33:6c7364ea360f 1085 }
Slord2142 33:6c7364ea360f 1086 }
Slord2142 33:6c7364ea360f 1087 }
Slord2142 35:ec224d706f7c 1088 else if (!strcmp(commandString, "LUT"))
Slord2142 35:ec224d706f7c 1089 {
Slord2142 35:ec224d706f7c 1090 if (readback)
Slord2142 35:ec224d706f7c 1091 {
Slord2142 35:ec224d706f7c 1092 int lut = 0;
Slord2142 35:ec224d706f7c 1093 int una = 0;
Slord2142 35:ec224d706f7c 1094 int due = 0;
Slord2142 35:ec224d706f7c 1095 while(lut < 1023)
Slord2142 35:ec224d706f7c 1096 {
Slord2142 35:ec224d706f7c 1097 lut += 1;
Slord2142 35:ec224d706f7c 1098 una = binC_12[lut];
Slord2142 35:ec224d706f7c 1099 due = binC_12[lut-1];
Slord2142 35:ec224d706f7c 1100 if (una != due)
Slord2142 35:ec224d706f7c 1101 {
Slord2142 35:ec224d706f7c 1102 sprintf(strbuf, " %d", lut);
Slord2142 35:ec224d706f7c 1103 sendSerial(strbuf);
Slord2142 35:ec224d706f7c 1104 }
Slord2142 35:ec224d706f7c 1105 }
Slord2142 35:ec224d706f7c 1106 }
Slord2142 35:ec224d706f7c 1107 }
Slord2142 35:ec224d706f7c 1108 else if (!strcmp(commandString, "LUTA"))
Slord2142 35:ec224d706f7c 1109 {
Slord2142 35:ec224d706f7c 1110 if (readback)
Slord2142 35:ec224d706f7c 1111 {
Slord2142 35:ec224d706f7c 1112 sprintf(strbuf, " %d", luta);
Slord2142 35:ec224d706f7c 1113 sendSerial(strbuf);
Slord2142 35:ec224d706f7c 1114 }
Slord2142 35:ec224d706f7c 1115 if (LUTB == false)
Slord2142 35:ec224d706f7c 1116 {
Slord2142 35:ec224d706f7c 1117 luta = commandData/ROW_CORRECTION_FACTOR;
Slord2142 35:ec224d706f7c 1118 LUTA = true;
Slord2142 35:ec224d706f7c 1119 }
Slord2142 35:ec224d706f7c 1120 else if (LUTB == true)
Slord2142 35:ec224d706f7c 1121 {
Slord2142 35:ec224d706f7c 1122 luta = commandData/ROW_CORRECTION_FACTOR;
Slord2142 35:ec224d706f7c 1123 int lut = 1;
Slord2142 35:ec224d706f7c 1124 int luts = 0;
Slord2142 35:ec224d706f7c 1125 int LUTS = 0;
Slord2142 35:ec224d706f7c 1126 while (lut < 32 && luts < 1024)
Slord2142 35:ec224d706f7c 1127 {
Slord2142 35:ec224d706f7c 1128 if (luts >= luta)
Slord2142 35:ec224d706f7c 1129 {
Slord2142 35:ec224d706f7c 1130 LUTS += 1;
Slord2142 35:ec224d706f7c 1131 if (LUTS == 1)
Slord2142 35:ec224d706f7c 1132 {
Slord2142 35:ec224d706f7c 1133 lut += 1;
Slord2142 35:ec224d706f7c 1134 sprintf(storoFrag, "%d", luts);
Slord2142 35:ec224d706f7c 1135 strcat(storoLUT, storoFrag);
Slord2142 35:ec224d706f7c 1136 strcat(storoLUT, storoSpace);
Slord2142 35:ec224d706f7c 1137 } else if (LUTS == lutb)
Slord2142 35:ec224d706f7c 1138 {
Slord2142 35:ec224d706f7c 1139 LUTS = 0;
Slord2142 35:ec224d706f7c 1140 }
Slord2142 35:ec224d706f7c 1141 }
Slord2142 35:ec224d706f7c 1142 binC_12[luts] = lut;
Slord2142 35:ec224d706f7c 1143 binC_13[luts] = lut;
Slord2142 35:ec224d706f7c 1144 luts += 1;
Slord2142 35:ec224d706f7c 1145 }
Slord2142 35:ec224d706f7c 1146 while (luts < 1024)
Slord2142 35:ec224d706f7c 1147 {
Slord2142 35:ec224d706f7c 1148 binC_12[luts] = lut;
Slord2142 35:ec224d706f7c 1149 binC_13[luts] = lut;
Slord2142 35:ec224d706f7c 1150 luts += 1;
Slord2142 35:ec224d706f7c 1151 }
Slord2142 35:ec224d706f7c 1152 printf("LUT updated.");
Slord2142 35:ec224d706f7c 1153 }
Slord2142 35:ec224d706f7c 1154 }
Slord2142 35:ec224d706f7c 1155 else if (!strcmp(commandString, "LUTB"))
Slord2142 35:ec224d706f7c 1156 {
Slord2142 35:ec224d706f7c 1157 if (readback)
Slord2142 35:ec224d706f7c 1158 {
Slord2142 35:ec224d706f7c 1159 sprintf(strbuf, " %d", lutb);
Slord2142 35:ec224d706f7c 1160 sendSerial(strbuf);
Slord2142 35:ec224d706f7c 1161 }
Slord2142 35:ec224d706f7c 1162 if (LUTA == false)
Slord2142 35:ec224d706f7c 1163 {
Slord2142 35:ec224d706f7c 1164 lutb = commandData/ROW_CORRECTION_FACTOR;
Slord2142 35:ec224d706f7c 1165 LUTB = true;
Slord2142 35:ec224d706f7c 1166 }
Slord2142 35:ec224d706f7c 1167 else if (LUTA == true)
Slord2142 35:ec224d706f7c 1168 {
Slord2142 35:ec224d706f7c 1169 lutb = commandData/ROW_CORRECTION_FACTOR;
Slord2142 35:ec224d706f7c 1170 int lut = 1;
Slord2142 35:ec224d706f7c 1171 int luts = 0;
Slord2142 35:ec224d706f7c 1172 int LUTS = 0;
Slord2142 35:ec224d706f7c 1173 while (lut < 32 && luts < 1024)
Slord2142 35:ec224d706f7c 1174 {
Slord2142 35:ec224d706f7c 1175 if (luts >= luta)
Slord2142 35:ec224d706f7c 1176 {
Slord2142 35:ec224d706f7c 1177 LUTS += 1;
Slord2142 35:ec224d706f7c 1178 if (LUTS == 1)
Slord2142 35:ec224d706f7c 1179 {
Slord2142 35:ec224d706f7c 1180 lut += 1;
Slord2142 35:ec224d706f7c 1181 sprintf(storoFrag, "%d", luts);
Slord2142 35:ec224d706f7c 1182 strcat(storoLUT, storoFrag);
Slord2142 35:ec224d706f7c 1183 strcat(storoLUT, storoSpace);
Slord2142 35:ec224d706f7c 1184 } else if (LUTS == lutb)
Slord2142 35:ec224d706f7c 1185 {
Slord2142 35:ec224d706f7c 1186 LUTS = 0;
Slord2142 35:ec224d706f7c 1187 }
Slord2142 35:ec224d706f7c 1188 }
Slord2142 35:ec224d706f7c 1189 binC_12[luts] = lut;
Slord2142 35:ec224d706f7c 1190 binC_13[luts] = lut;
Slord2142 35:ec224d706f7c 1191 luts += 1;
Slord2142 35:ec224d706f7c 1192 }
Slord2142 35:ec224d706f7c 1193 while (luts < 1024)
Slord2142 35:ec224d706f7c 1194 {
Slord2142 35:ec224d706f7c 1195 binC_12[luts] = lut;
Slord2142 35:ec224d706f7c 1196 binC_13[luts] = lut;
Slord2142 35:ec224d706f7c 1197 luts += 1;
Slord2142 35:ec224d706f7c 1198 }
Slord2142 35:ec224d706f7c 1199 printf("LUT updated.");
Slord2142 35:ec224d706f7c 1200 }
Slord2142 35:ec224d706f7c 1201 }
Slord2142 33:6c7364ea360f 1202 else if (!strcmp(commandString, "RCRD"))
Slord2142 33:6c7364ea360f 1203 {
Slord2142 33:6c7364ea360f 1204 if(checkRange(boardMults, 0, 63) == 1){
Slord2142 33:6c7364ea360f 1205 sprintf(storoFrag, "%4.2f", VOLTAGE_48_ACTUAL_VALUE);
Slord2142 33:6c7364ea360f 1206 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1207 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1208 sprintf(storoFrag, "%4.2f", VOLTAGE_48_OFFSET);
Slord2142 33:6c7364ea360f 1209 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1210 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1211 sprintf(storoFrag, "%4.2f", VOLTAGE_24_ACTUAL_VALUE);
Slord2142 33:6c7364ea360f 1212 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1213 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1214 sprintf(storoFrag, "%4.2f", VOLTAGE_24_OFFSET);
Slord2142 33:6c7364ea360f 1215 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1216 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1217 sprintf(storoFrag, "%4.2f", VOLTAGE_12_ACTUAL_VALUE);
Slord2142 33:6c7364ea360f 1218 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1219 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1220 sprintf(storoFrag, "%4.2f", VOLTAGE_12_OFFSET);
Slord2142 33:6c7364ea360f 1221 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1222 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1223 sprintf(storoFrag, "%d", CURRENT_12_DIV_THRESH1);
Slord2142 33:6c7364ea360f 1224 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1225 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1226 sprintf(storoFrag, "%d", CURRENT_12_DIV_THRESH2);
Slord2142 33:6c7364ea360f 1227 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1228 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1229 sprintf(storoFrag, "%d", CURRENT_12_DIV_THRESH3);
Slord2142 33:6c7364ea360f 1230 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1231 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1232 sprintf(storoFrag, "%d", CURRENT_12_DIV_THRESH4);
Slord2142 33:6c7364ea360f 1233 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1234 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1235 sprintf(storoFrag, "%d", CURRENT_12_DIV_THRESH5);
Slord2142 33:6c7364ea360f 1236 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1237 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1238 sprintf(storoFrag, "%d", CURRENT_12_DIV_FACTOR0);
Slord2142 33:6c7364ea360f 1239 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1240 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1241 sprintf(storoFrag, "%4.2f", CURRENT_12_CORRECTION0);
Slord2142 33:6c7364ea360f 1242 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1243 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1244 sprintf(storoFrag, "%d", CURRENT_12_DIV_FACTOR1);
Slord2142 33:6c7364ea360f 1245 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1246 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1247 sprintf(storoFrag, "%4.2f", CURRENT_12_CORRECTION1);
Slord2142 33:6c7364ea360f 1248 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1249 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1250 sprintf(storoFrag, "%d", CURRENT_12_DIV_FACTOR2);
Slord2142 33:6c7364ea360f 1251 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1252 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1253 sprintf(storoFrag, "%4.2f", CURRENT_12_CORRECTION2);
Slord2142 33:6c7364ea360f 1254 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1255 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1256 sprintf(storoFrag, "%d", CURRENT_12_DIV_FACTOR3);
Slord2142 33:6c7364ea360f 1257 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1258 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1259 sprintf(storoFrag, "%4.2f", CURRENT_12_CORRECTION3);
Slord2142 33:6c7364ea360f 1260 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1261 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1262 sprintf(storoFrag, "%d", CURRENT_12_DIV_FACTOR4);
Slord2142 33:6c7364ea360f 1263 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1264 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1265 sprintf(storoFrag, "%4.2f", CURRENT_12_CORRECTION4);
Slord2142 33:6c7364ea360f 1266 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1267 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1268 sprintf(storoFrag, "%d", CURRENT_12_DIV_FACTOR5);
Slord2142 33:6c7364ea360f 1269 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1270 strcat(storoBuild, storoSpace);
Slord2142 33:6c7364ea360f 1271 sprintf(storoFrag, "%4.2f", CURRENT_12_CORRECTION5);
Slord2142 33:6c7364ea360f 1272 strcat(storoBuild, storoFrag);
Slord2142 33:6c7364ea360f 1273 strcat(storoBuild, storoSpace);
Slord2142 34:419242dc004d 1274 //SOFBlock::format(sector_index);
Slord2142 33:6c7364ea360f 1275 writer.open(sector_index) ;
Slord2142 33:6c7364ea360f 1276 writer.write_data((uint8_t*) storoBuild, sizeof storoBuild);
Slord2142 33:6c7364ea360f 1277 writer.close();
Slord2142 33:6c7364ea360f 1278 testing = TRUE;
Slord2142 33:6c7364ea360f 1279 }else{
Slord2142 33:6c7364ea360f 1280 showRangeError(1, boardMults, 0.0);
Slord2142 33:6c7364ea360f 1281 }
Slord2142 33:6c7364ea360f 1282 }
Slord2142 33:6c7364ea360f 1283 else if (!strcmp(commandString, "RTRV"))
Slord2142 33:6c7364ea360f 1284 {
Slord2142 33:6c7364ea360f 1285 reader.open(sector_index);
Slord2142 33:6c7364ea360f 1286 storo = reader.get_physical_data_addr();
Slord2142 33:6c7364ea360f 1287 reader.close();
Slord2142 33:6c7364ea360f 1288 sprintf(storage, "%s", storo);
Slord2142 33:6c7364ea360f 1289 int storage_size = strlen(storage);
Slord2142 33:6c7364ea360f 1290 char delim[] = ":";
Slord2142 33:6c7364ea360f 1291 char *ptr = strtok(storage, delim);
Slord2142 33:6c7364ea360f 1292 VOLTAGE_48_ACTUAL_VALUE = atof(ptr);
Slord2142 33:6c7364ea360f 1293 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1294 VOLTAGE_48_OFFSET = atof(ptr);
Slord2142 33:6c7364ea360f 1295 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1296 VOLTAGE_24_ACTUAL_VALUE = atof(ptr);
Slord2142 33:6c7364ea360f 1297 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1298 VOLTAGE_24_OFFSET = atof(ptr);
Slord2142 33:6c7364ea360f 1299 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1300 VOLTAGE_12_ACTUAL_VALUE = atof(ptr);
Slord2142 33:6c7364ea360f 1301 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1302 VOLTAGE_12_OFFSET = atof(ptr);
Slord2142 33:6c7364ea360f 1303 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1304 CURRENT_12_DIV_THRESH1 = atoi(ptr);
Slord2142 33:6c7364ea360f 1305 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1306 CURRENT_12_DIV_THRESH2 = atoi(ptr);
Slord2142 33:6c7364ea360f 1307 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1308 CURRENT_12_DIV_THRESH3 = atoi(ptr);
Slord2142 33:6c7364ea360f 1309 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1310 CURRENT_12_DIV_THRESH4 = atoi(ptr);
Slord2142 33:6c7364ea360f 1311 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1312 CURRENT_12_DIV_THRESH5 = atoi(ptr);
Slord2142 33:6c7364ea360f 1313 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1314 CURRENT_12_DIV_FACTOR0 = atoi(ptr);
Slord2142 33:6c7364ea360f 1315 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1316 CURRENT_12_CORRECTION0 = atof(ptr);
Slord2142 33:6c7364ea360f 1317 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1318 CURRENT_12_DIV_FACTOR1 = atoi(ptr);
Slord2142 33:6c7364ea360f 1319 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1320 CURRENT_12_CORRECTION1 = atof(ptr);
Slord2142 33:6c7364ea360f 1321 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1322 CURRENT_12_DIV_FACTOR2 = atoi(ptr);
Slord2142 33:6c7364ea360f 1323 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1324 CURRENT_12_CORRECTION2 = atof(ptr);
Slord2142 33:6c7364ea360f 1325 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1326 CURRENT_12_DIV_FACTOR3 = atoi(ptr);
Slord2142 33:6c7364ea360f 1327 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1328 CURRENT_12_CORRECTION3 = atof(ptr);
Slord2142 33:6c7364ea360f 1329 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1330 CURRENT_12_DIV_FACTOR4 = atoi(ptr);
Slord2142 33:6c7364ea360f 1331 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1332 CURRENT_12_CORRECTION4 = atof(ptr);
Slord2142 33:6c7364ea360f 1333 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1334 CURRENT_12_DIV_FACTOR5 = atoi(ptr);
Slord2142 33:6c7364ea360f 1335 ptr = strtok(NULL, delim);
Slord2142 33:6c7364ea360f 1336 CURRENT_12_CORRECTION5 = atof(ptr);
Slord2142 33:6c7364ea360f 1337 printf("Values retreived. \r\n");
Slord2142 33:6c7364ea360f 1338 }
mfwic 6:39442d493098 1339 else if (!strcmp(commandString, "MY12"))
mfwic 6:39442d493098 1340 // MULT is used to get/set the en_out value.
mfwic 6:39442d493098 1341 // The integer value of boardMults is used to change en_out via setBoardWeights(boardMults).
mfwic 6:39442d493098 1342 // en_out are binary weighted signals that activate groups of DC-DC converters on the slot cards.
mfwic 6:39442d493098 1343 // en_out[6] = {en32, en16, en8, en4, en2, en1}
Slord2142 31:be17caf56d22 1344 {
mfwic 6:39442d493098 1345
mfwic 6:39442d493098 1346 if (readback)
mfwic 6:39442d493098 1347 {
mfwic 6:39442d493098 1348 sprintf(strbuf, " %d", my12);
mfwic 6:39442d493098 1349 sendSerial(strbuf);
mfwic 12:fd1fd1857628 1350 }else{
mfwic 12:fd1fd1857628 1351 my12 = commandData;
mfwic 12:fd1fd1857628 1352 testing = FALSE;
mfwic 6:39442d493098 1353 }
mfwic 6:39442d493098 1354 }
mfwic 0:44a3005d4f20 1355 else if (!strcmp(commandString, "ALLOFF"))
mfwic 0:44a3005d4f20 1356 {
mfwic 7:860b3a8275cb 1357 my12 = 0;
mfwic 7:860b3a8275cb 1358 running = FALSE;
mfwic 12:fd1fd1857628 1359 testing = FALSE;
mfwic 7:860b3a8275cb 1360 if(DEBUG){
mfwic 7:860b3a8275cb 1361 sprintf(strbuf, "wr_out_code=%d\r\n", wr_out_code);
mfwic 7:860b3a8275cb 1362 sendSerial(strbuf);
mfwic 7:860b3a8275cb 1363 }
mfwic 0:44a3005d4f20 1364 }
mfwic 0:44a3005d4f20 1365 else if (!strcmp(commandString, "ALLON"))
mfwic 0:44a3005d4f20 1366 {
mfwic 7:860b3a8275cb 1367 wr_out_code = setBoardEnables((unsigned int)ALLON);
mfwic 12:fd1fd1857628 1368 testing = TRUE;
mfwic 0:44a3005d4f20 1369 }
mfwic 0:44a3005d4f20 1370 else if (!strcmp(commandString, "RUN"))
mfwic 0:44a3005d4f20 1371 {
mfwic 0:44a3005d4f20 1372 // Skip over any white space and the optional '[' character
mfwic 0:44a3005d4f20 1373 while ((isspace(rxbuf[bufloc])) || (rxbuf[bufloc] == '[')) bufloc++;
mfwic 0:44a3005d4f20 1374
mfwic 9:816b9a4e4f21 1375 if(rxbuf[bufloc] == NULL){
mfwic 21:fe0ea1860c9f 1376 boardsActive = ALLON;
mfwic 9:816b9a4e4f21 1377 startConverter(boardsActive);
mfwic 12:fd1fd1857628 1378 testing = FALSE;
mfwic 9:816b9a4e4f21 1379 }
mfwic 9:816b9a4e4f21 1380 else if (rxbuf[bufloc] == '0')
mfwic 0:44a3005d4f20 1381 {
mfwic 1:9f8583ba2431 1382 stopConverter();
mfwic 12:fd1fd1857628 1383 testing = FALSE;
mfwic 0:44a3005d4f20 1384 }
mfwic 25:8bcc8bea0e31 1385 else if ((rxbuf[bufloc] > '0') && (rxbuf[bufloc] < '0' + max_boards))
mfwic 0:44a3005d4f20 1386 {
mfwic 0:44a3005d4f20 1387 ival = atoi(&rxbuf[bufloc]);
mfwic 9:816b9a4e4f21 1388 //ival--;
mfwic 0:44a3005d4f20 1389
mfwic 0:44a3005d4f20 1390 if (running == 0)
mfwic 0:44a3005d4f20 1391 {
mfwic 1:9f8583ba2431 1392 boardsActive = ival;
mfwic 1:9f8583ba2431 1393 startConverter(boardsActive);
mfwic 12:fd1fd1857628 1394 testing = FALSE;
mfwic 0:44a3005d4f20 1395 }
mfwic 0:44a3005d4f20 1396 else
mfwic 0:44a3005d4f20 1397 {
mfwic 0:44a3005d4f20 1398 // Compare the board enable flags between registers
mfwic 25:8bcc8bea0e31 1399 //boardEnables = checkRegisterCompatibility(ival);
mfwic 0:44a3005d4f20 1400
mfwic 0:44a3005d4f20 1401 // If board enable flags match, change the register set
mfwic 0:44a3005d4f20 1402 if (boardEnables == 0)
mfwic 0:44a3005d4f20 1403 {
mfwic 1:9f8583ba2431 1404 boardsActive = ival;
mfwic 0:44a3005d4f20 1405 }
mfwic 0:44a3005d4f20 1406 else
mfwic 0:44a3005d4f20 1407 {
mfwic 1:9f8583ba2431 1408 sprintf(strbuf, " Board enable flags do not match (0x%08x)", boardEnables);
mfwic 1:9f8583ba2431 1409 sendSerial(strbuf);
mfwic 0:44a3005d4f20 1410 }
mfwic 0:44a3005d4f20 1411 }
mfwic 0:44a3005d4f20 1412 }
mfwic 0:44a3005d4f20 1413 else
mfwic 0:44a3005d4f20 1414 {
mfwic 9:816b9a4e4f21 1415 sprintf(strbuf, " Invalid number of boards (1 - %d)", MAX_BOARDS);
mfwic 1:9f8583ba2431 1416 sendSerial(strbuf);
mfwic 0:44a3005d4f20 1417 commandError = 1;
mfwic 0:44a3005d4f20 1418 }
mfwic 0:44a3005d4f20 1419 }
mfwic 0:44a3005d4f20 1420 else if (!strcmp(commandString, "STOP"))
mfwic 0:44a3005d4f20 1421 {
mfwic 1:9f8583ba2431 1422 stopConverter();
mfwic 12:fd1fd1857628 1423 testing = FALSE;
mfwic 12:fd1fd1857628 1424 my12 = 0;
mfwic 0:44a3005d4f20 1425 }
Slord2142 33:6c7364ea360f 1426 else if(!strcmp(commandString, "RAW"))
mfwic 0:44a3005d4f20 1427 {
mfwic 0:44a3005d4f20 1428 if (running == 1)
mfwic 0:44a3005d4f20 1429 {
mfwic 1:9f8583ba2431 1430 sprintf(strbuf, " Parameters may not be updated while running!");
mfwic 1:9f8583ba2431 1431 sendSerial(strbuf);
mfwic 0:44a3005d4f20 1432 commandError = 1;
mfwic 0:44a3005d4f20 1433 }
mfwic 11:01dcfb29fbc4 1434
mfwic 8:d3d7dca419b3 1435 if (!commandError){
mfwic 8:d3d7dca419b3 1436 raw = TRUE;
mfwic 8:d3d7dca419b3 1437 menuRedraw(NO_PROMPT);
mfwic 0:44a3005d4f20 1438 }
mfwic 8:d3d7dca419b3 1439 }
Slord2142 33:6c7364ea360f 1440 else if(!strcmp(commandString, "COOK"))
mfwic 8:d3d7dca419b3 1441 {
mfwic 8:d3d7dca419b3 1442 if (running == 1)
mfwic 8:d3d7dca419b3 1443 {
mfwic 8:d3d7dca419b3 1444 sprintf(strbuf, " Parameters may not be updated while running!");
mfwic 8:d3d7dca419b3 1445 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 1446 commandError = 1;
mfwic 8:d3d7dca419b3 1447 }
mfwic 11:01dcfb29fbc4 1448
mfwic 8:d3d7dca419b3 1449 if (!commandError){
mfwic 8:d3d7dca419b3 1450 raw = FALSE;
mfwic 8:d3d7dca419b3 1451 menuRedraw(NO_PROMPT);
mfwic 8:d3d7dca419b3 1452 }
mfwic 8:d3d7dca419b3 1453 }
mfwic 0:44a3005d4f20 1454 else
mfwic 0:44a3005d4f20 1455 {
mfwic 0:44a3005d4f20 1456 if (strcmp(commandString, ""))
mfwic 0:44a3005d4f20 1457 {
mfwic 0:44a3005d4f20 1458 commandError = 1;
mfwic 0:44a3005d4f20 1459 }
mfwic 0:44a3005d4f20 1460 }
mfwic 0:44a3005d4f20 1461
mfwic 0:44a3005d4f20 1462 if (commandError)
mfwic 0:44a3005d4f20 1463 {
mfwic 6:39442d493098 1464 sendSerial(" !");
mfwic 0:44a3005d4f20 1465 }
mfwic 0:44a3005d4f20 1466
mfwic 3:d8948c5b2951 1467 menuPrompt(MENU_DCM1);
mfwic 0:44a3005d4f20 1468 }
mfwic 0:44a3005d4f20 1469
mfwic 0:44a3005d4f20 1470 /************************************************************
mfwic 0:44a3005d4f20 1471 * Routine: processCommand
mfwic 0:44a3005d4f20 1472 * Input: none
mfwic 0:44a3005d4f20 1473 * Returns: none
mfwic 0:44a3005d4f20 1474 * Description:
mfwic 0:44a3005d4f20 1475 * This is the main serial communications routine. Everything
mfwic 0:44a3005d4f20 1476 * starts here as soon as a command is avaiable for processing.
mfwic 0:44a3005d4f20 1477 **************************************************************/
mfwic 0:44a3005d4f20 1478 void processCommand(void)
mfwic 0:44a3005d4f20 1479 {
mfwic 0:44a3005d4f20 1480 if (!serialStatus.command && !serialStatus.repeat)
mfwic 0:44a3005d4f20 1481 {
mfwic 0:44a3005d4f20 1482 return;
mfwic 0:44a3005d4f20 1483 }
mfwic 0:44a3005d4f20 1484
mfwic 0:44a3005d4f20 1485 doCommand(); // if not computer (i.e. terminal) you can do the command as well
mfwic 0:44a3005d4f20 1486
mfwic 0:44a3005d4f20 1487 bufloc = 0;
mfwic 0:44a3005d4f20 1488 rxbuf[bufloc] = 0;
mfwic 0:44a3005d4f20 1489
mfwic 0:44a3005d4f20 1490 serialStatus.computer = FALSE;
mfwic 0:44a3005d4f20 1491 serialStatus.command = FALSE;
mfwic 0:44a3005d4f20 1492 }
mfwic 8:d3d7dca419b3 1493
mfwic 8:d3d7dca419b3 1494 /************************************************************
mfwic 8:d3d7dca419b3 1495 * Routine: waitCommand
mfwic 8:d3d7dca419b3 1496 * Input: none
mfwic 8:d3d7dca419b3 1497 * Returns: none
mfwic 8:d3d7dca419b3 1498 * Description:
mfwic 8:d3d7dca419b3 1499 **************************************************************/
mfwic 8:d3d7dca419b3 1500 bool waitCommand(void)
mfwic 8:d3d7dca419b3 1501 {
mfwic 8:d3d7dca419b3 1502 if (!serialStatus.command && !serialStatus.repeat)
mfwic 8:d3d7dca419b3 1503 {
mfwic 8:d3d7dca419b3 1504 return TRUE;
mfwic 8:d3d7dca419b3 1505 }
mfwic 8:d3d7dca419b3 1506
mfwic 8:d3d7dca419b3 1507 serialStatus.computer = FALSE;
mfwic 8:d3d7dca419b3 1508 serialStatus.command = FALSE;
mfwic 8:d3d7dca419b3 1509
mfwic 8:d3d7dca419b3 1510 return FALSE;
mfwic 8:d3d7dca419b3 1511 }
mfwic 11:01dcfb29fbc4 1512
mfwic 11:01dcfb29fbc4 1513 // Verify that the same boards are enabled in both the current register and
mfwic 11:01dcfb29fbc4 1514 // the specified register
mfwic 11:01dcfb29fbc4 1515
mfwic 11:01dcfb29fbc4 1516