Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL2

Dependencies:   mbed

Committer:
Slord2142
Date:
Tue Nov 19 22:59:56 2019 +0000
Revision:
56:6ee4c05ccec8
Parent:
55:0f5457bc4094
Child:
57:5afd7c1b9acf
First take at fixing the negative/positive complication

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