Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL2

Dependencies:   mbed

Committer:
Slord2142
Date:
Wed Nov 06 20:21:37 2019 +0000
Revision:
37:1cbd51e24610
Parent:
36:849c22bd60b0
Child:
54:660af33fa930
LUTA/LUTB interfacing with RCRD/RTRV

Who changed what in which revision?

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