Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
src/command.cpp@43:291bbdba48f3, 2019-03-09 (annotated)
- Committer:
- mfwic
- Date:
- Sat Mar 09 21:16:38 2019 +0000
- Revision:
- 43:291bbdba48f3
- Parent:
- 42:3ae73b61f657
Added boards, lut, and command.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfwic | 42:3ae73b61f657 | 1 | //------------------------------------------------------------------------------- |
mfwic | 42:3ae73b61f657 | 2 | // |
mfwic | 42:3ae73b61f657 | 3 | // Treehouse Inc. |
mfwic | 42:3ae73b61f657 | 4 | // Colorado Springs, Colorado |
mfwic | 42:3ae73b61f657 | 5 | // |
mfwic | 42:3ae73b61f657 | 6 | // Copyright (c) 2016 by Treehouse Designs Inc. |
mfwic | 42:3ae73b61f657 | 7 | // |
mfwic | 42:3ae73b61f657 | 8 | // This code is the property of Treehouse, Inc. (Treehouse) |
mfwic | 42:3ae73b61f657 | 9 | // and may not be redistributed in any form without prior written |
mfwic | 42:3ae73b61f657 | 10 | // permission of the copyright holder, Treehouse. |
mfwic | 42:3ae73b61f657 | 11 | // |
mfwic | 42:3ae73b61f657 | 12 | // The above copyright notice and this permission notice shall be included in |
mfwic | 42:3ae73b61f657 | 13 | // all copies or substantial portions of the Software. |
mfwic | 42:3ae73b61f657 | 14 | // |
mfwic | 42:3ae73b61f657 | 15 | // |
mfwic | 42:3ae73b61f657 | 16 | //------------------------------------------------------------------------------- |
mfwic | 42:3ae73b61f657 | 17 | // |
mfwic | 42:3ae73b61f657 | 18 | // REVISION HISTORY: |
mfwic | 42:3ae73b61f657 | 19 | // |
mfwic | 42:3ae73b61f657 | 20 | // $Author: $ |
mfwic | 42:3ae73b61f657 | 21 | // $Rev: $ |
mfwic | 42:3ae73b61f657 | 22 | // $Date: $ |
mfwic | 42:3ae73b61f657 | 23 | // $URL: $ |
mfwic | 42:3ae73b61f657 | 24 | // |
mfwic | 42:3ae73b61f657 | 25 | //------------------------------------------------------------------------------- |
mfwic | 42:3ae73b61f657 | 26 | |
mfwic | 42:3ae73b61f657 | 27 | #include "mbed.h" |
mfwic | 42:3ae73b61f657 | 28 | #include "string.h" |
mfwic | 42:3ae73b61f657 | 29 | #include "stdio.h" |
mfwic | 42:3ae73b61f657 | 30 | #include "stdlib.h" |
mfwic | 42:3ae73b61f657 | 31 | #include "ctype.h" |
mfwic | 42:3ae73b61f657 | 32 | #include "serial.h" |
mfwic | 42:3ae73b61f657 | 33 | #include "globals.h" |
mfwic | 42:3ae73b61f657 | 34 | #include "math.h" |
mfwic | 42:3ae73b61f657 | 35 | #include "parameters.h" |
mfwic | 42:3ae73b61f657 | 36 | #include "all_io.h" |
mfwic | 42:3ae73b61f657 | 37 | #include "boards.h" |
mfwic | 42:3ae73b61f657 | 38 | #include "menu.h" |
mfwic | 42:3ae73b61f657 | 39 | #include "command.h" |
mfwic | 42:3ae73b61f657 | 40 | |
mfwic | 42:3ae73b61f657 | 41 | unsigned int boardsActive = ALLON; |
mfwic | 42:3ae73b61f657 | 42 | unsigned int boardMults = 32; |
mfwic | 42:3ae73b61f657 | 43 | unsigned int commandData; |
mfwic | 42:3ae73b61f657 | 44 | extern unsigned short my12; |
mfwic | 42:3ae73b61f657 | 45 | |
mfwic | 42:3ae73b61f657 | 46 | /************* FILE SCOPE VARIABLES ************************/ |
mfwic | 42:3ae73b61f657 | 47 | char setvalue = FALSE; |
mfwic | 42:3ae73b61f657 | 48 | int endOfCommand = 0; |
mfwic | 42:3ae73b61f657 | 49 | int commandError = 0; |
mfwic | 42:3ae73b61f657 | 50 | int menuLevel = LEVEL_MAIN; |
mfwic | 42:3ae73b61f657 | 51 | int readback = 0; |
mfwic | 42:3ae73b61f657 | 52 | |
mfwic | 42:3ae73b61f657 | 53 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 54 | * Routine: getDelimiter |
mfwic | 42:3ae73b61f657 | 55 | * Input: none |
mfwic | 42:3ae73b61f657 | 56 | * Output: none |
mfwic | 42:3ae73b61f657 | 57 | * Description: |
mfwic | 42:3ae73b61f657 | 58 | * searches for a delimiter and moves the buffer location |
mfwic | 42:3ae73b61f657 | 59 | * to be just past it |
mfwic | 42:3ae73b61f657 | 60 | * |
mfwic | 42:3ae73b61f657 | 61 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 62 | void getDelimiter(void) |
mfwic | 42:3ae73b61f657 | 63 | { |
mfwic | 42:3ae73b61f657 | 64 | ++bufloc; |
mfwic | 42:3ae73b61f657 | 65 | |
mfwic | 42:3ae73b61f657 | 66 | while ((rxbuf[bufloc] != ' ') && |
mfwic | 42:3ae73b61f657 | 67 | (rxbuf[bufloc] != ',') && |
mfwic | 42:3ae73b61f657 | 68 | (rxbuf[bufloc] != '=') && |
mfwic | 42:3ae73b61f657 | 69 | (rxbuf[bufloc] != 0 )) |
mfwic | 42:3ae73b61f657 | 70 | { |
mfwic | 42:3ae73b61f657 | 71 | bufloc++; |
mfwic | 42:3ae73b61f657 | 72 | } |
mfwic | 42:3ae73b61f657 | 73 | } |
mfwic | 42:3ae73b61f657 | 74 | |
mfwic | 42:3ae73b61f657 | 75 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 76 | * Routine: gethex |
mfwic | 42:3ae73b61f657 | 77 | * Input: hex character |
mfwic | 42:3ae73b61f657 | 78 | * Returns: hex integer |
mfwic | 42:3ae73b61f657 | 79 | * Description: |
mfwic | 42:3ae73b61f657 | 80 | * Converts a hex character to a value |
mfwic | 42:3ae73b61f657 | 81 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 82 | char gethex(char val) |
mfwic | 42:3ae73b61f657 | 83 | { |
mfwic | 42:3ae73b61f657 | 84 | int retval; |
mfwic | 42:3ae73b61f657 | 85 | switch(val) |
mfwic | 42:3ae73b61f657 | 86 | { |
mfwic | 42:3ae73b61f657 | 87 | case '0': |
mfwic | 42:3ae73b61f657 | 88 | retval = 0; |
mfwic | 42:3ae73b61f657 | 89 | break; |
mfwic | 42:3ae73b61f657 | 90 | case '1': |
mfwic | 42:3ae73b61f657 | 91 | retval = 1; |
mfwic | 42:3ae73b61f657 | 92 | break; |
mfwic | 42:3ae73b61f657 | 93 | case '2': |
mfwic | 42:3ae73b61f657 | 94 | retval = 2; |
mfwic | 42:3ae73b61f657 | 95 | break; |
mfwic | 42:3ae73b61f657 | 96 | case '3': |
mfwic | 42:3ae73b61f657 | 97 | retval = 3; |
mfwic | 42:3ae73b61f657 | 98 | break; |
mfwic | 42:3ae73b61f657 | 99 | case '4': |
mfwic | 42:3ae73b61f657 | 100 | retval = 4; |
mfwic | 42:3ae73b61f657 | 101 | break; |
mfwic | 42:3ae73b61f657 | 102 | case '5': |
mfwic | 42:3ae73b61f657 | 103 | retval = 5; |
mfwic | 42:3ae73b61f657 | 104 | break; |
mfwic | 42:3ae73b61f657 | 105 | case '6': |
mfwic | 42:3ae73b61f657 | 106 | retval = 6; |
mfwic | 42:3ae73b61f657 | 107 | break; |
mfwic | 42:3ae73b61f657 | 108 | case '7': |
mfwic | 42:3ae73b61f657 | 109 | retval = 7; |
mfwic | 42:3ae73b61f657 | 110 | break; |
mfwic | 42:3ae73b61f657 | 111 | case '8': |
mfwic | 42:3ae73b61f657 | 112 | retval = 8; |
mfwic | 42:3ae73b61f657 | 113 | break; |
mfwic | 42:3ae73b61f657 | 114 | case '9': |
mfwic | 42:3ae73b61f657 | 115 | retval = 9; |
mfwic | 42:3ae73b61f657 | 116 | break; |
mfwic | 42:3ae73b61f657 | 117 | case 'A': |
mfwic | 42:3ae73b61f657 | 118 | retval = 10; |
mfwic | 42:3ae73b61f657 | 119 | break; |
mfwic | 42:3ae73b61f657 | 120 | case 'B': |
mfwic | 42:3ae73b61f657 | 121 | retval = 11; |
mfwic | 42:3ae73b61f657 | 122 | break; |
mfwic | 42:3ae73b61f657 | 123 | case 'C': |
mfwic | 42:3ae73b61f657 | 124 | retval = 12; |
mfwic | 42:3ae73b61f657 | 125 | break; |
mfwic | 42:3ae73b61f657 | 126 | case 'D': |
mfwic | 42:3ae73b61f657 | 127 | retval = 13; |
mfwic | 42:3ae73b61f657 | 128 | break; |
mfwic | 42:3ae73b61f657 | 129 | case 'E': |
mfwic | 42:3ae73b61f657 | 130 | retval = 14; |
mfwic | 42:3ae73b61f657 | 131 | break; |
mfwic | 42:3ae73b61f657 | 132 | case 'F': |
mfwic | 42:3ae73b61f657 | 133 | retval = 15; |
mfwic | 42:3ae73b61f657 | 134 | break; |
mfwic | 42:3ae73b61f657 | 135 | default: |
mfwic | 42:3ae73b61f657 | 136 | retval = 0; |
mfwic | 42:3ae73b61f657 | 137 | break; |
mfwic | 42:3ae73b61f657 | 138 | |
mfwic | 42:3ae73b61f657 | 139 | } |
mfwic | 42:3ae73b61f657 | 140 | return retval; |
mfwic | 42:3ae73b61f657 | 141 | } |
mfwic | 42:3ae73b61f657 | 142 | |
mfwic | 42:3ae73b61f657 | 143 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 144 | * Routine: showfval |
mfwic | 42:3ae73b61f657 | 145 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 146 | * value (float value to display) |
mfwic | 42:3ae73b61f657 | 147 | * Output: none |
mfwic | 42:3ae73b61f657 | 148 | * Description: |
mfwic | 42:3ae73b61f657 | 149 | * Sends a floating point number (value) over the serial port |
mfwic | 42:3ae73b61f657 | 150 | * if it is being retrieved (GET) |
mfwic | 42:3ae73b61f657 | 151 | * |
mfwic | 42:3ae73b61f657 | 152 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 153 | void showfval(char setval,float value) |
mfwic | 42:3ae73b61f657 | 154 | { |
mfwic | 42:3ae73b61f657 | 155 | if(!setval) |
mfwic | 42:3ae73b61f657 | 156 | { |
mfwic | 42:3ae73b61f657 | 157 | sprintf(strbuf," %4.9f",value); |
mfwic | 42:3ae73b61f657 | 158 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 159 | } |
mfwic | 42:3ae73b61f657 | 160 | } |
mfwic | 42:3ae73b61f657 | 161 | |
mfwic | 42:3ae73b61f657 | 162 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 163 | * Routine: showival |
mfwic | 42:3ae73b61f657 | 164 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 165 | * value (integer value to display) |
mfwic | 42:3ae73b61f657 | 166 | * Output: none |
mfwic | 42:3ae73b61f657 | 167 | * Description: |
mfwic | 42:3ae73b61f657 | 168 | * Sends an integer (value) over the serial port |
mfwic | 42:3ae73b61f657 | 169 | * if it is being retrieved (GET) |
mfwic | 42:3ae73b61f657 | 170 | * |
mfwic | 42:3ae73b61f657 | 171 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 172 | void showival(char setval, int value) |
mfwic | 42:3ae73b61f657 | 173 | { |
mfwic | 42:3ae73b61f657 | 174 | if(!setval) |
mfwic | 42:3ae73b61f657 | 175 | { |
mfwic | 42:3ae73b61f657 | 176 | sprintf(strbuf," %i",value); |
mfwic | 42:3ae73b61f657 | 177 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 178 | } |
mfwic | 42:3ae73b61f657 | 179 | } |
mfwic | 42:3ae73b61f657 | 180 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 181 | * Routine: showcval |
mfwic | 42:3ae73b61f657 | 182 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 183 | * value (character to display) |
mfwic | 42:3ae73b61f657 | 184 | * Output: none |
mfwic | 42:3ae73b61f657 | 185 | * Description: |
mfwic | 42:3ae73b61f657 | 186 | * Sends a character over the serial port |
mfwic | 42:3ae73b61f657 | 187 | * if it is being retrieved (GET) |
mfwic | 42:3ae73b61f657 | 188 | * |
mfwic | 42:3ae73b61f657 | 189 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 190 | void showcval(char setval, int value) |
mfwic | 42:3ae73b61f657 | 191 | { |
mfwic | 42:3ae73b61f657 | 192 | if(!setval) |
mfwic | 42:3ae73b61f657 | 193 | { |
mfwic | 42:3ae73b61f657 | 194 | sprintf(strbuf," %c",(char)value); |
mfwic | 42:3ae73b61f657 | 195 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 196 | } |
mfwic | 42:3ae73b61f657 | 197 | } |
mfwic | 42:3ae73b61f657 | 198 | |
mfwic | 42:3ae73b61f657 | 199 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 200 | * Routine: showlval |
mfwic | 42:3ae73b61f657 | 201 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 202 | * value (integer value to display) |
mfwic | 42:3ae73b61f657 | 203 | * Output: none |
mfwic | 42:3ae73b61f657 | 204 | * Description: |
mfwic | 42:3ae73b61f657 | 205 | * Sends an long (value) over the serial port |
mfwic | 42:3ae73b61f657 | 206 | * if it is being retrieved (GET) |
mfwic | 42:3ae73b61f657 | 207 | * |
mfwic | 42:3ae73b61f657 | 208 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 209 | void showlval(char setval, long value) |
mfwic | 42:3ae73b61f657 | 210 | { |
mfwic | 42:3ae73b61f657 | 211 | if(!setval) |
mfwic | 42:3ae73b61f657 | 212 | { |
mfwic | 42:3ae73b61f657 | 213 | sprintf(strbuf," %ld",value); |
mfwic | 42:3ae73b61f657 | 214 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 215 | } |
mfwic | 42:3ae73b61f657 | 216 | } |
mfwic | 42:3ae73b61f657 | 217 | |
mfwic | 42:3ae73b61f657 | 218 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 219 | * Routine: showuival |
mfwic | 42:3ae73b61f657 | 220 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 221 | * value (integer value to display) |
mfwic | 42:3ae73b61f657 | 222 | * Output: none |
mfwic | 42:3ae73b61f657 | 223 | * Description: |
mfwic | 42:3ae73b61f657 | 224 | * Sends an unsigned int (value) over the serial port |
mfwic | 42:3ae73b61f657 | 225 | * if it is being retrieved (GET) |
mfwic | 42:3ae73b61f657 | 226 | * |
mfwic | 42:3ae73b61f657 | 227 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 228 | void showuival(char setval, unsigned int value) |
mfwic | 42:3ae73b61f657 | 229 | { |
mfwic | 42:3ae73b61f657 | 230 | if(!setval) |
mfwic | 42:3ae73b61f657 | 231 | { |
mfwic | 42:3ae73b61f657 | 232 | sprintf(strbuf," %u",value); |
mfwic | 42:3ae73b61f657 | 233 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 234 | } |
mfwic | 42:3ae73b61f657 | 235 | } |
mfwic | 42:3ae73b61f657 | 236 | |
mfwic | 42:3ae73b61f657 | 237 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 238 | * Routine: showhval |
mfwic | 42:3ae73b61f657 | 239 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 240 | * value (hex integeger value to display) |
mfwic | 42:3ae73b61f657 | 241 | * Output: none |
mfwic | 42:3ae73b61f657 | 242 | * Description: |
mfwic | 42:3ae73b61f657 | 243 | * Sends an integer (value) in hex over the serial port |
mfwic | 42:3ae73b61f657 | 244 | * if it is being retrieved (GET) |
mfwic | 42:3ae73b61f657 | 245 | * |
mfwic | 42:3ae73b61f657 | 246 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 247 | void showhval(char setval, int value) |
mfwic | 42:3ae73b61f657 | 248 | { |
mfwic | 42:3ae73b61f657 | 249 | if(!setval) |
mfwic | 42:3ae73b61f657 | 250 | { |
mfwic | 42:3ae73b61f657 | 251 | if(serialStatus.computer) |
mfwic | 42:3ae73b61f657 | 252 | sprintf(strbuf," %u",(unsigned int)value); |
mfwic | 42:3ae73b61f657 | 253 | else |
mfwic | 42:3ae73b61f657 | 254 | sprintf(strbuf," 0x%04x",value); |
mfwic | 42:3ae73b61f657 | 255 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 256 | } |
mfwic | 42:3ae73b61f657 | 257 | } |
mfwic | 42:3ae73b61f657 | 258 | |
mfwic | 42:3ae73b61f657 | 259 | |
mfwic | 42:3ae73b61f657 | 260 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 261 | * Routine: getival |
mfwic | 42:3ae73b61f657 | 262 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 263 | * Returns: the value if it is being SET or 0 if it is a GET |
mfwic | 42:3ae73b61f657 | 264 | * Description: |
mfwic | 42:3ae73b61f657 | 265 | * Gets an integer from the serial port connection. |
mfwic | 42:3ae73b61f657 | 266 | * |
mfwic | 42:3ae73b61f657 | 267 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 268 | int getival(char setval) |
mfwic | 42:3ae73b61f657 | 269 | { |
mfwic | 42:3ae73b61f657 | 270 | if (setval) |
mfwic | 42:3ae73b61f657 | 271 | { |
mfwic | 42:3ae73b61f657 | 272 | return atoi(&rxbuf[++bufloc]); |
mfwic | 42:3ae73b61f657 | 273 | } |
mfwic | 42:3ae73b61f657 | 274 | |
mfwic | 42:3ae73b61f657 | 275 | return 0; |
mfwic | 42:3ae73b61f657 | 276 | } |
mfwic | 42:3ae73b61f657 | 277 | |
mfwic | 42:3ae73b61f657 | 278 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 279 | * Routine: getcval |
mfwic | 42:3ae73b61f657 | 280 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 281 | * Returns: the value if it is being SET or 0 if it is a GET |
mfwic | 42:3ae73b61f657 | 282 | * Description: |
mfwic | 42:3ae73b61f657 | 283 | * Gets an character from the serial port connection. |
mfwic | 42:3ae73b61f657 | 284 | * |
mfwic | 42:3ae73b61f657 | 285 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 286 | int getcval(char setval) |
mfwic | 42:3ae73b61f657 | 287 | { |
mfwic | 42:3ae73b61f657 | 288 | if(setval) |
mfwic | 42:3ae73b61f657 | 289 | { |
mfwic | 42:3ae73b61f657 | 290 | // skip one space |
mfwic | 42:3ae73b61f657 | 291 | ++bufloc; |
mfwic | 42:3ae73b61f657 | 292 | // skip spaces and the equals sign |
mfwic | 42:3ae73b61f657 | 293 | while((rxbuf[bufloc] == ' ') || (rxbuf[bufloc] == '=')) |
mfwic | 42:3ae73b61f657 | 294 | bufloc++; |
mfwic | 42:3ae73b61f657 | 295 | return rxbuf[bufloc++]; |
mfwic | 42:3ae73b61f657 | 296 | } |
mfwic | 42:3ae73b61f657 | 297 | else |
mfwic | 42:3ae73b61f657 | 298 | return 0; |
mfwic | 42:3ae73b61f657 | 299 | |
mfwic | 42:3ae73b61f657 | 300 | } |
mfwic | 42:3ae73b61f657 | 301 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 302 | * Routine: getlval |
mfwic | 42:3ae73b61f657 | 303 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 304 | * Returns: the value if it is being SET or 0 if it is a GET |
mfwic | 42:3ae73b61f657 | 305 | * Description: |
mfwic | 42:3ae73b61f657 | 306 | * Gets an long from the serial port connection. |
mfwic | 42:3ae73b61f657 | 307 | * |
mfwic | 42:3ae73b61f657 | 308 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 309 | long getlval(char setval) |
mfwic | 42:3ae73b61f657 | 310 | { |
mfwic | 42:3ae73b61f657 | 311 | if(setval) |
mfwic | 42:3ae73b61f657 | 312 | return atol(&rxbuf[++bufloc]); |
mfwic | 42:3ae73b61f657 | 313 | else |
mfwic | 42:3ae73b61f657 | 314 | return 0; |
mfwic | 42:3ae73b61f657 | 315 | |
mfwic | 42:3ae73b61f657 | 316 | } |
mfwic | 42:3ae73b61f657 | 317 | |
mfwic | 42:3ae73b61f657 | 318 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 319 | * Routine: getfval |
mfwic | 42:3ae73b61f657 | 320 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 321 | * Returns: the value if it is being SET or 0 if it is a GET |
mfwic | 42:3ae73b61f657 | 322 | * Description: |
mfwic | 42:3ae73b61f657 | 323 | * Gets an float from the serial port connection. |
mfwic | 42:3ae73b61f657 | 324 | * |
mfwic | 42:3ae73b61f657 | 325 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 326 | float getfval(char setval) |
mfwic | 42:3ae73b61f657 | 327 | { |
mfwic | 42:3ae73b61f657 | 328 | if(setval) |
mfwic | 42:3ae73b61f657 | 329 | return atof(&rxbuf[++bufloc]); |
mfwic | 42:3ae73b61f657 | 330 | else |
mfwic | 42:3ae73b61f657 | 331 | return 0; |
mfwic | 42:3ae73b61f657 | 332 | } |
mfwic | 42:3ae73b61f657 | 333 | |
mfwic | 42:3ae73b61f657 | 334 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 335 | * Routine: validateEntry |
mfwic | 42:3ae73b61f657 | 336 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 337 | * limlo -- low limit |
mfwic | 42:3ae73b61f657 | 338 | * limhi -- high limit |
mfwic | 42:3ae73b61f657 | 339 | * address -- address in eeprom to use |
mfwic | 42:3ae73b61f657 | 340 | * Returns: 0 if entry validates and is written |
mfwic | 42:3ae73b61f657 | 341 | * 1 if entry fails |
mfwic | 42:3ae73b61f657 | 342 | * Description: |
mfwic | 42:3ae73b61f657 | 343 | * Gets or sets a value in eeprom at the address but only |
mfwic | 42:3ae73b61f657 | 344 | * if it is between the limits will it write the value to |
mfwic | 42:3ae73b61f657 | 345 | * eeprom |
mfwic | 42:3ae73b61f657 | 346 | * |
mfwic | 42:3ae73b61f657 | 347 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 348 | int validateEntry(char setvalue, float limlo, float limhi, float *address) |
mfwic | 42:3ae73b61f657 | 349 | { |
mfwic | 42:3ae73b61f657 | 350 | float val; |
mfwic | 42:3ae73b61f657 | 351 | |
mfwic | 42:3ae73b61f657 | 352 | if (setvalue) |
mfwic | 42:3ae73b61f657 | 353 | { |
mfwic | 42:3ae73b61f657 | 354 | val = getfval(SET); |
mfwic | 42:3ae73b61f657 | 355 | |
mfwic | 42:3ae73b61f657 | 356 | if ((val >= limlo) && (val <= limhi)) |
mfwic | 42:3ae73b61f657 | 357 | { |
mfwic | 42:3ae73b61f657 | 358 | *address = val; |
mfwic | 42:3ae73b61f657 | 359 | } |
mfwic | 42:3ae73b61f657 | 360 | else |
mfwic | 42:3ae73b61f657 | 361 | { |
mfwic | 42:3ae73b61f657 | 362 | showRangeError(0, 0, val); |
mfwic | 42:3ae73b61f657 | 363 | return 0; |
mfwic | 42:3ae73b61f657 | 364 | } |
mfwic | 42:3ae73b61f657 | 365 | } |
mfwic | 42:3ae73b61f657 | 366 | else |
mfwic | 42:3ae73b61f657 | 367 | { |
mfwic | 42:3ae73b61f657 | 368 | val = *address; |
mfwic | 42:3ae73b61f657 | 369 | sprintf(strbuf, " %4.3f", val); |
mfwic | 42:3ae73b61f657 | 370 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 371 | } |
mfwic | 42:3ae73b61f657 | 372 | |
mfwic | 42:3ae73b61f657 | 373 | return 1; |
mfwic | 42:3ae73b61f657 | 374 | } |
mfwic | 42:3ae73b61f657 | 375 | |
mfwic | 42:3ae73b61f657 | 376 | |
mfwic | 42:3ae73b61f657 | 377 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 378 | * Routine: validateEntry |
mfwic | 42:3ae73b61f657 | 379 | * Input: setval (GET or SET) |
mfwic | 42:3ae73b61f657 | 380 | * limlo -- low limit |
mfwic | 42:3ae73b61f657 | 381 | * limhi -- high limit |
mfwic | 42:3ae73b61f657 | 382 | * address -- address in eeprom to use |
mfwic | 42:3ae73b61f657 | 383 | * |
mfwic | 42:3ae73b61f657 | 384 | * Returns: FALSE if entry fails |
mfwic | 42:3ae73b61f657 | 385 | * TRUE if entry validates and is written |
mfwic | 42:3ae73b61f657 | 386 | * |
mfwic | 42:3ae73b61f657 | 387 | * Description: |
mfwic | 42:3ae73b61f657 | 388 | * Gets or sets a value in eeprom at the address but only |
mfwic | 42:3ae73b61f657 | 389 | * if it is between the limits will it write the value to |
mfwic | 42:3ae73b61f657 | 390 | * eeprom |
mfwic | 42:3ae73b61f657 | 391 | * |
mfwic | 42:3ae73b61f657 | 392 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 393 | int validateInt(char setvalue, int limlo, int limhi, int *address) |
mfwic | 42:3ae73b61f657 | 394 | { |
mfwic | 42:3ae73b61f657 | 395 | float val; |
mfwic | 42:3ae73b61f657 | 396 | |
mfwic | 42:3ae73b61f657 | 397 | if (setvalue) |
mfwic | 42:3ae73b61f657 | 398 | { |
mfwic | 42:3ae73b61f657 | 399 | val = getfval(SET); |
mfwic | 42:3ae73b61f657 | 400 | |
mfwic | 42:3ae73b61f657 | 401 | if ((val >= limlo) && (val <= limhi)) |
mfwic | 42:3ae73b61f657 | 402 | { |
mfwic | 42:3ae73b61f657 | 403 | *address = val; |
mfwic | 42:3ae73b61f657 | 404 | } |
mfwic | 42:3ae73b61f657 | 405 | else |
mfwic | 42:3ae73b61f657 | 406 | { |
mfwic | 42:3ae73b61f657 | 407 | showRangeError(1, val, 0); |
mfwic | 42:3ae73b61f657 | 408 | return FALSE; |
mfwic | 42:3ae73b61f657 | 409 | } |
mfwic | 42:3ae73b61f657 | 410 | } |
mfwic | 42:3ae73b61f657 | 411 | else |
mfwic | 42:3ae73b61f657 | 412 | { |
mfwic | 42:3ae73b61f657 | 413 | val = *address; |
mfwic | 42:3ae73b61f657 | 414 | sprintf(strbuf, " %4.0f", val); |
mfwic | 42:3ae73b61f657 | 415 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 416 | } |
mfwic | 42:3ae73b61f657 | 417 | |
mfwic | 42:3ae73b61f657 | 418 | return TRUE; |
mfwic | 42:3ae73b61f657 | 419 | } |
mfwic | 42:3ae73b61f657 | 420 | |
mfwic | 42:3ae73b61f657 | 421 | |
mfwic | 42:3ae73b61f657 | 422 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 423 | * Routine: parseCommand |
mfwic | 42:3ae73b61f657 | 424 | * Input: setvalue (GET or SET), command buffer |
mfwic | 42:3ae73b61f657 | 425 | * Returns: none |
mfwic | 42:3ae73b61f657 | 426 | * Description: |
mfwic | 42:3ae73b61f657 | 427 | * parses a command and gets the commandstring |
mfwic | 42:3ae73b61f657 | 428 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 429 | void parseCommand(char setvalue, char *commandString) |
mfwic | 42:3ae73b61f657 | 430 | { |
mfwic | 42:3ae73b61f657 | 431 | int i, endofc; |
mfwic | 42:3ae73b61f657 | 432 | char store; |
mfwic | 42:3ae73b61f657 | 433 | |
mfwic | 42:3ae73b61f657 | 434 | // Ignore any white space and the optional ';' character before the start of |
mfwic | 42:3ae73b61f657 | 435 | // the command string (any ']' character is from the last command so skip that, |
mfwic | 42:3ae73b61f657 | 436 | // too) |
mfwic | 42:3ae73b61f657 | 437 | while ((isspace(rxbuf[bufloc])) || (rxbuf[bufloc] == ';') || (rxbuf[bufloc] == ']')) |
mfwic | 42:3ae73b61f657 | 438 | { |
mfwic | 42:3ae73b61f657 | 439 | bufloc++; |
mfwic | 42:3ae73b61f657 | 440 | if ((rxbuf[bufloc] == 0x0D) || (rxbuf[bufloc] == 0)) break; |
mfwic | 42:3ae73b61f657 | 441 | } |
mfwic | 42:3ae73b61f657 | 442 | |
mfwic | 42:3ae73b61f657 | 443 | if (setvalue) |
mfwic | 42:3ae73b61f657 | 444 | { |
mfwic | 42:3ae73b61f657 | 445 | // We need a value for SET so hitting the end is a problem |
mfwic | 42:3ae73b61f657 | 446 | if ((rxbuf[bufloc] == 0) || (rxbuf[bufloc] == 0x0D)) |
mfwic | 42:3ae73b61f657 | 447 | { |
mfwic | 42:3ae73b61f657 | 448 | commandError = 1; |
mfwic | 42:3ae73b61f657 | 449 | return; |
mfwic | 42:3ae73b61f657 | 450 | } |
mfwic | 42:3ae73b61f657 | 451 | } |
mfwic | 42:3ae73b61f657 | 452 | |
mfwic | 42:3ae73b61f657 | 453 | // Find the end of the command string |
mfwic | 42:3ae73b61f657 | 454 | endofc = bufloc + 1; |
mfwic | 42:3ae73b61f657 | 455 | |
mfwic | 42:3ae73b61f657 | 456 | // White space, '[' and '?' all terminate the command string |
mfwic | 42:3ae73b61f657 | 457 | while ((!isspace(rxbuf[endofc])) && (rxbuf[endofc] != '[') && (rxbuf[endofc] != '?')) |
mfwic | 42:3ae73b61f657 | 458 | { |
mfwic | 42:3ae73b61f657 | 459 | endofc++; |
mfwic | 42:3ae73b61f657 | 460 | // (As does hitting the end of rxbuf!) |
mfwic | 42:3ae73b61f657 | 461 | if ((rxbuf[endofc] == 0x0D) || (rxbuf[endofc] == 0)) break; |
mfwic | 42:3ae73b61f657 | 462 | } |
mfwic | 42:3ae73b61f657 | 463 | |
mfwic | 42:3ae73b61f657 | 464 | // Save the character that marks the end of the command string |
mfwic | 42:3ae73b61f657 | 465 | store = rxbuf[endofc]; |
mfwic | 42:3ae73b61f657 | 466 | |
mfwic | 42:3ae73b61f657 | 467 | // sprintf(strbuf, "store == %c\r\n", store); |
mfwic | 42:3ae73b61f657 | 468 | // sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 469 | |
mfwic | 42:3ae73b61f657 | 470 | // Command strings ending in '?' are readbacks |
mfwic | 42:3ae73b61f657 | 471 | readback = ((store == '?') ? 1 : 0); |
mfwic | 42:3ae73b61f657 | 472 | |
mfwic | 42:3ae73b61f657 | 473 | // Set end to null character so string can now be copied |
mfwic | 42:3ae73b61f657 | 474 | rxbuf[endofc] = 0; |
mfwic | 42:3ae73b61f657 | 475 | |
mfwic | 42:3ae73b61f657 | 476 | // Copy the command string into commandString |
mfwic | 42:3ae73b61f657 | 477 | char commandStringBuf[80]; |
mfwic | 42:3ae73b61f657 | 478 | char *tok; |
mfwic | 42:3ae73b61f657 | 479 | strcpy(commandStringBuf, &rxbuf[bufloc]); |
mfwic | 42:3ae73b61f657 | 480 | if(strstr(commandStringBuf, "=")){ |
mfwic | 42:3ae73b61f657 | 481 | tok = strtok(commandStringBuf, "="); |
mfwic | 42:3ae73b61f657 | 482 | strcpy(commandString, tok); |
mfwic | 42:3ae73b61f657 | 483 | tok = strtok(NULL, "="); |
mfwic | 42:3ae73b61f657 | 484 | commandData = atoi(tok); |
mfwic | 42:3ae73b61f657 | 485 | } |
mfwic | 42:3ae73b61f657 | 486 | else{ |
mfwic | 42:3ae73b61f657 | 487 | strcpy(commandString, commandStringBuf); |
mfwic | 42:3ae73b61f657 | 488 | } |
mfwic | 42:3ae73b61f657 | 489 | |
mfwic | 42:3ae73b61f657 | 490 | // Convert the command string to all uppercase characters |
mfwic | 42:3ae73b61f657 | 491 | for (i = 0; i < strlen(commandString); i++) |
mfwic | 42:3ae73b61f657 | 492 | { |
mfwic | 42:3ae73b61f657 | 493 | commandString[i] = toupper(commandString[i]); |
mfwic | 42:3ae73b61f657 | 494 | } |
mfwic | 42:3ae73b61f657 | 495 | |
mfwic | 42:3ae73b61f657 | 496 | // Replace the character we clobbered in rxbuf |
mfwic | 42:3ae73b61f657 | 497 | rxbuf[endofc] = store; |
mfwic | 42:3ae73b61f657 | 498 | |
mfwic | 42:3ae73b61f657 | 499 | // Update bufloc to the end of the command string |
mfwic | 42:3ae73b61f657 | 500 | bufloc = endofc; |
mfwic | 42:3ae73b61f657 | 501 | } |
mfwic | 42:3ae73b61f657 | 502 | |
mfwic | 42:3ae73b61f657 | 503 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 504 | * Routine: doCommand |
mfwic | 42:3ae73b61f657 | 505 | * Input: none |
mfwic | 42:3ae73b61f657 | 506 | * Returns: none |
mfwic | 42:3ae73b61f657 | 507 | * Description: |
mfwic | 42:3ae73b61f657 | 508 | * This is the start of the command string. |
mfwic | 42:3ae73b61f657 | 509 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 510 | void doCommand(void) |
mfwic | 42:3ae73b61f657 | 511 | { |
mfwic | 42:3ae73b61f657 | 512 | int ival; |
mfwic | 42:3ae73b61f657 | 513 | unsigned int boardEnables; |
mfwic | 42:3ae73b61f657 | 514 | |
mfwic | 42:3ae73b61f657 | 515 | char commandString[80] = { 0 }; |
mfwic | 42:3ae73b61f657 | 516 | |
mfwic | 42:3ae73b61f657 | 517 | bufloc = 0; |
mfwic | 42:3ae73b61f657 | 518 | commandError = 0; |
mfwic | 42:3ae73b61f657 | 519 | |
mfwic | 42:3ae73b61f657 | 520 | parseCommand(GET, commandString); |
mfwic | 42:3ae73b61f657 | 521 | |
mfwic | 42:3ae73b61f657 | 522 | if (!strcmp(commandString, "MENU")) |
mfwic | 42:3ae73b61f657 | 523 | { |
mfwic | 42:3ae73b61f657 | 524 | menuRedraw(NO_PROMPT); |
mfwic | 42:3ae73b61f657 | 525 | } |
mfwic | 42:3ae73b61f657 | 526 | else if (!strcmp(commandString, "HELP")) |
mfwic | 42:3ae73b61f657 | 527 | { |
mfwic | 42:3ae73b61f657 | 528 | menuRedraw(NO_PROMPT); |
mfwic | 42:3ae73b61f657 | 529 | } |
mfwic | 42:3ae73b61f657 | 530 | else if (!strcmp(commandString, "MAXB")) |
mfwic | 42:3ae73b61f657 | 531 | // MAXB is used to get/set the max_boards value. |
mfwic | 42:3ae73b61f657 | 532 | // The integer value of max_boards is used to select the appropriate lookup table. |
mfwic | 42:3ae73b61f657 | 533 | { |
mfwic | 42:3ae73b61f657 | 534 | if (readback) |
mfwic | 42:3ae73b61f657 | 535 | { |
mfwic | 43:291bbdba48f3 | 536 | sprintf(strbuf, " %d", 3); |
mfwic | 42:3ae73b61f657 | 537 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 538 | } |
mfwic | 42:3ae73b61f657 | 539 | else if (running == 1) |
mfwic | 42:3ae73b61f657 | 540 | { |
mfwic | 42:3ae73b61f657 | 541 | sprintf(strbuf, " Parameters may not be updated while running!"); |
mfwic | 42:3ae73b61f657 | 542 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 543 | } |
mfwic | 42:3ae73b61f657 | 544 | else |
mfwic | 42:3ae73b61f657 | 545 | { |
mfwic | 43:291bbdba48f3 | 546 | //max_boards = commandData; |
mfwic | 42:3ae73b61f657 | 547 | } |
mfwic | 42:3ae73b61f657 | 548 | } |
mfwic | 42:3ae73b61f657 | 549 | else if (!strcmp(commandString, "BRDS")) |
mfwic | 42:3ae73b61f657 | 550 | // BRDS is used to get/set the wr_out value. |
mfwic | 42:3ae73b61f657 | 551 | // The integer value of boardsActive is used to change wr_out via setBoardEnables(boardsActive). |
mfwic | 42:3ae73b61f657 | 552 | // Slots 12 to 0 are activated with the wr_out signals |
mfwic | 42:3ae73b61f657 | 553 | // wr_out[13] = slots[12:0] |
mfwic | 42:3ae73b61f657 | 554 | { |
mfwic | 42:3ae73b61f657 | 555 | if (readback) |
mfwic | 42:3ae73b61f657 | 556 | { |
mfwic | 42:3ae73b61f657 | 557 | sprintf(strbuf, " %d", boardsActive); |
mfwic | 42:3ae73b61f657 | 558 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 559 | } |
mfwic | 42:3ae73b61f657 | 560 | else if (running == 1) |
mfwic | 42:3ae73b61f657 | 561 | { |
mfwic | 42:3ae73b61f657 | 562 | sprintf(strbuf, " Parameters may not be updated while running!"); |
mfwic | 42:3ae73b61f657 | 563 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 564 | } |
mfwic | 42:3ae73b61f657 | 565 | else |
mfwic | 42:3ae73b61f657 | 566 | { |
mfwic | 42:3ae73b61f657 | 567 | boardsActive = commandData; |
mfwic | 42:3ae73b61f657 | 568 | if(checkRange(boardsActive, 0, 8191) == 1){ |
mfwic | 43:291bbdba48f3 | 569 | //wr_out_code = setBoardEnables(boardsActive); |
mfwic | 42:3ae73b61f657 | 570 | testing = TRUE; |
mfwic | 42:3ae73b61f657 | 571 | }else{ |
mfwic | 42:3ae73b61f657 | 572 | showRangeError(1, boardsActive, 0.0); |
mfwic | 42:3ae73b61f657 | 573 | } |
mfwic | 42:3ae73b61f657 | 574 | } |
mfwic | 42:3ae73b61f657 | 575 | } |
mfwic | 42:3ae73b61f657 | 576 | else if (!strcmp(commandString, "MULT")) |
mfwic | 42:3ae73b61f657 | 577 | // MULT is used to get/set the en_out value. |
mfwic | 42:3ae73b61f657 | 578 | // The integer value of boardMults is used to change en_out via setBoardWeights(boardMults). |
mfwic | 42:3ae73b61f657 | 579 | // en_out are binary weighted signals that activate groups of DC-DC converters on the slot cards. |
mfwic | 42:3ae73b61f657 | 580 | // en_out[6] = {en32, en16, en8, en4, en2, en1} |
mfwic | 42:3ae73b61f657 | 581 | { |
mfwic | 42:3ae73b61f657 | 582 | if (readback) |
mfwic | 42:3ae73b61f657 | 583 | { |
mfwic | 42:3ae73b61f657 | 584 | sprintf(strbuf, " %d", boardMults); |
mfwic | 42:3ae73b61f657 | 585 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 586 | } |
mfwic | 42:3ae73b61f657 | 587 | else if (running == 1) |
mfwic | 42:3ae73b61f657 | 588 | { |
mfwic | 42:3ae73b61f657 | 589 | sprintf(strbuf, " Parameters may not be updated while running!"); |
mfwic | 42:3ae73b61f657 | 590 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 591 | } |
mfwic | 42:3ae73b61f657 | 592 | else |
mfwic | 42:3ae73b61f657 | 593 | { |
mfwic | 42:3ae73b61f657 | 594 | boardMults = commandData; |
mfwic | 42:3ae73b61f657 | 595 | if(checkRange(boardMults, 0, 63) == 1){ |
mfwic | 43:291bbdba48f3 | 596 | //en_out_code = setBoardWeights(boardMults); |
mfwic | 42:3ae73b61f657 | 597 | testing = TRUE; |
mfwic | 42:3ae73b61f657 | 598 | }else{ |
mfwic | 42:3ae73b61f657 | 599 | showRangeError(1, boardMults, 0.0); |
mfwic | 42:3ae73b61f657 | 600 | } |
mfwic | 42:3ae73b61f657 | 601 | } |
mfwic | 42:3ae73b61f657 | 602 | } |
mfwic | 42:3ae73b61f657 | 603 | else if (!strcmp(commandString, "MY12")) |
mfwic | 42:3ae73b61f657 | 604 | // MULT is used to get/set the en_out value. |
mfwic | 42:3ae73b61f657 | 605 | // The integer value of boardMults is used to change en_out via setBoardWeights(boardMults). |
mfwic | 42:3ae73b61f657 | 606 | // en_out are binary weighted signals that activate groups of DC-DC converters on the slot cards. |
mfwic | 42:3ae73b61f657 | 607 | // en_out[6] = {en32, en16, en8, en4, en2, en1} |
mfwic | 42:3ae73b61f657 | 608 | { |
mfwic | 42:3ae73b61f657 | 609 | |
mfwic | 42:3ae73b61f657 | 610 | if (readback) |
mfwic | 42:3ae73b61f657 | 611 | { |
mfwic | 42:3ae73b61f657 | 612 | sprintf(strbuf, " %d", my12); |
mfwic | 42:3ae73b61f657 | 613 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 614 | }else{ |
mfwic | 42:3ae73b61f657 | 615 | my12 = commandData; |
mfwic | 42:3ae73b61f657 | 616 | testing = FALSE; |
mfwic | 42:3ae73b61f657 | 617 | } |
mfwic | 42:3ae73b61f657 | 618 | } |
mfwic | 42:3ae73b61f657 | 619 | else if (!strcmp(commandString, "ALLOFF")) |
mfwic | 42:3ae73b61f657 | 620 | { |
mfwic | 42:3ae73b61f657 | 621 | my12 = 0; |
mfwic | 42:3ae73b61f657 | 622 | running = FALSE; |
mfwic | 42:3ae73b61f657 | 623 | testing = FALSE; |
mfwic | 43:291bbdba48f3 | 624 | |
mfwic | 42:3ae73b61f657 | 625 | } |
mfwic | 42:3ae73b61f657 | 626 | else if (!strcmp(commandString, "ALLON")) |
mfwic | 42:3ae73b61f657 | 627 | { |
mfwic | 43:291bbdba48f3 | 628 | //wr_out_code = setBoardEnables((unsigned int)ALLON); |
mfwic | 42:3ae73b61f657 | 629 | testing = TRUE; |
mfwic | 42:3ae73b61f657 | 630 | } |
mfwic | 42:3ae73b61f657 | 631 | else if (!strcmp(commandString, "RUN")) |
mfwic | 42:3ae73b61f657 | 632 | { |
mfwic | 42:3ae73b61f657 | 633 | // Skip over any white space and the optional '[' character |
mfwic | 42:3ae73b61f657 | 634 | while ((isspace(rxbuf[bufloc])) || (rxbuf[bufloc] == '[')) bufloc++; |
mfwic | 42:3ae73b61f657 | 635 | |
mfwic | 42:3ae73b61f657 | 636 | if(rxbuf[bufloc] == NULL){ |
mfwic | 42:3ae73b61f657 | 637 | boardsActive = ALLON; |
mfwic | 42:3ae73b61f657 | 638 | startConverter(boardsActive); |
mfwic | 42:3ae73b61f657 | 639 | testing = FALSE; |
mfwic | 42:3ae73b61f657 | 640 | } |
mfwic | 42:3ae73b61f657 | 641 | else if (rxbuf[bufloc] == '0') |
mfwic | 42:3ae73b61f657 | 642 | { |
mfwic | 42:3ae73b61f657 | 643 | stopConverter(); |
mfwic | 42:3ae73b61f657 | 644 | testing = FALSE; |
mfwic | 42:3ae73b61f657 | 645 | } |
mfwic | 43:291bbdba48f3 | 646 | else if ((rxbuf[bufloc] > '0') && (rxbuf[bufloc] < '0' + 3)) |
mfwic | 42:3ae73b61f657 | 647 | { |
mfwic | 42:3ae73b61f657 | 648 | ival = atoi(&rxbuf[bufloc]); |
mfwic | 42:3ae73b61f657 | 649 | //ival--; |
mfwic | 42:3ae73b61f657 | 650 | |
mfwic | 42:3ae73b61f657 | 651 | if (running == 0) |
mfwic | 42:3ae73b61f657 | 652 | { |
mfwic | 42:3ae73b61f657 | 653 | boardsActive = ival; |
mfwic | 42:3ae73b61f657 | 654 | startConverter(boardsActive); |
mfwic | 42:3ae73b61f657 | 655 | testing = FALSE; |
mfwic | 42:3ae73b61f657 | 656 | } |
mfwic | 42:3ae73b61f657 | 657 | else |
mfwic | 42:3ae73b61f657 | 658 | { |
mfwic | 42:3ae73b61f657 | 659 | // Compare the board enable flags between registers |
mfwic | 42:3ae73b61f657 | 660 | //boardEnables = checkRegisterCompatibility(ival); |
mfwic | 42:3ae73b61f657 | 661 | |
mfwic | 42:3ae73b61f657 | 662 | // If board enable flags match, change the register set |
mfwic | 42:3ae73b61f657 | 663 | if (boardEnables == 0) |
mfwic | 42:3ae73b61f657 | 664 | { |
mfwic | 42:3ae73b61f657 | 665 | boardsActive = ival; |
mfwic | 42:3ae73b61f657 | 666 | } |
mfwic | 42:3ae73b61f657 | 667 | else |
mfwic | 42:3ae73b61f657 | 668 | { |
mfwic | 42:3ae73b61f657 | 669 | sprintf(strbuf, " Board enable flags do not match (0x%08x)", boardEnables); |
mfwic | 42:3ae73b61f657 | 670 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 671 | } |
mfwic | 42:3ae73b61f657 | 672 | } |
mfwic | 42:3ae73b61f657 | 673 | } |
mfwic | 42:3ae73b61f657 | 674 | else |
mfwic | 42:3ae73b61f657 | 675 | { |
mfwic | 42:3ae73b61f657 | 676 | sprintf(strbuf, " Invalid number of boards (1 - %d)", MAX_BOARDS); |
mfwic | 42:3ae73b61f657 | 677 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 678 | commandError = 1; |
mfwic | 42:3ae73b61f657 | 679 | } |
mfwic | 42:3ae73b61f657 | 680 | } |
mfwic | 42:3ae73b61f657 | 681 | else if (!strcmp(commandString, "STOP")) |
mfwic | 42:3ae73b61f657 | 682 | { |
mfwic | 42:3ae73b61f657 | 683 | stopConverter(); |
mfwic | 42:3ae73b61f657 | 684 | testing = FALSE; |
mfwic | 42:3ae73b61f657 | 685 | my12 = 0; |
mfwic | 42:3ae73b61f657 | 686 | } |
mfwic | 42:3ae73b61f657 | 687 | else if(!strcmp(commandString, "CAL")) |
mfwic | 42:3ae73b61f657 | 688 | { |
mfwic | 42:3ae73b61f657 | 689 | if (running == 1) |
mfwic | 42:3ae73b61f657 | 690 | { |
mfwic | 42:3ae73b61f657 | 691 | sprintf(strbuf, " Parameters may not be updated while running!"); |
mfwic | 42:3ae73b61f657 | 692 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 693 | commandError = 1; |
mfwic | 42:3ae73b61f657 | 694 | } |
mfwic | 42:3ae73b61f657 | 695 | |
mfwic | 42:3ae73b61f657 | 696 | if (!commandError){ |
mfwic | 42:3ae73b61f657 | 697 | raw = TRUE; |
mfwic | 42:3ae73b61f657 | 698 | menuRedraw(NO_PROMPT); |
mfwic | 42:3ae73b61f657 | 699 | } |
mfwic | 42:3ae73b61f657 | 700 | } |
mfwic | 42:3ae73b61f657 | 701 | else if(!strcmp(commandString, "UNCAL")) |
mfwic | 42:3ae73b61f657 | 702 | { |
mfwic | 42:3ae73b61f657 | 703 | if (running == 1) |
mfwic | 42:3ae73b61f657 | 704 | { |
mfwic | 42:3ae73b61f657 | 705 | sprintf(strbuf, " Parameters may not be updated while running!"); |
mfwic | 42:3ae73b61f657 | 706 | sendSerial(strbuf); |
mfwic | 42:3ae73b61f657 | 707 | commandError = 1; |
mfwic | 42:3ae73b61f657 | 708 | } |
mfwic | 42:3ae73b61f657 | 709 | |
mfwic | 42:3ae73b61f657 | 710 | if (!commandError){ |
mfwic | 42:3ae73b61f657 | 711 | raw = FALSE; |
mfwic | 42:3ae73b61f657 | 712 | menuRedraw(NO_PROMPT); |
mfwic | 42:3ae73b61f657 | 713 | } |
mfwic | 42:3ae73b61f657 | 714 | } |
mfwic | 42:3ae73b61f657 | 715 | else |
mfwic | 42:3ae73b61f657 | 716 | { |
mfwic | 42:3ae73b61f657 | 717 | if (strcmp(commandString, "")) |
mfwic | 42:3ae73b61f657 | 718 | { |
mfwic | 42:3ae73b61f657 | 719 | commandError = 1; |
mfwic | 42:3ae73b61f657 | 720 | } |
mfwic | 42:3ae73b61f657 | 721 | } |
mfwic | 42:3ae73b61f657 | 722 | |
mfwic | 42:3ae73b61f657 | 723 | if (commandError) |
mfwic | 42:3ae73b61f657 | 724 | { |
mfwic | 42:3ae73b61f657 | 725 | sendSerial(" !"); |
mfwic | 42:3ae73b61f657 | 726 | } |
mfwic | 42:3ae73b61f657 | 727 | |
mfwic | 42:3ae73b61f657 | 728 | menuPrompt(MENU_DCM1); |
mfwic | 42:3ae73b61f657 | 729 | } |
mfwic | 42:3ae73b61f657 | 730 | |
mfwic | 42:3ae73b61f657 | 731 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 732 | * Routine: processCommand |
mfwic | 42:3ae73b61f657 | 733 | * Input: none |
mfwic | 42:3ae73b61f657 | 734 | * Returns: none |
mfwic | 42:3ae73b61f657 | 735 | * Description: |
mfwic | 42:3ae73b61f657 | 736 | * This is the main serial communications routine. Everything |
mfwic | 42:3ae73b61f657 | 737 | * starts here as soon as a command is avaiable for processing. |
mfwic | 42:3ae73b61f657 | 738 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 739 | void processCommand(void) |
mfwic | 42:3ae73b61f657 | 740 | { |
mfwic | 42:3ae73b61f657 | 741 | if (!serialStatus.command && !serialStatus.repeat) |
mfwic | 42:3ae73b61f657 | 742 | { |
mfwic | 42:3ae73b61f657 | 743 | return; |
mfwic | 42:3ae73b61f657 | 744 | } |
mfwic | 42:3ae73b61f657 | 745 | |
mfwic | 42:3ae73b61f657 | 746 | doCommand(); // if not computer (i.e. terminal) you can do the command as well |
mfwic | 42:3ae73b61f657 | 747 | |
mfwic | 42:3ae73b61f657 | 748 | bufloc = 0; |
mfwic | 42:3ae73b61f657 | 749 | rxbuf[bufloc] = 0; |
mfwic | 42:3ae73b61f657 | 750 | |
mfwic | 42:3ae73b61f657 | 751 | serialStatus.computer = FALSE; |
mfwic | 42:3ae73b61f657 | 752 | serialStatus.command = FALSE; |
mfwic | 42:3ae73b61f657 | 753 | } |
mfwic | 42:3ae73b61f657 | 754 | |
mfwic | 42:3ae73b61f657 | 755 | /************************************************************ |
mfwic | 42:3ae73b61f657 | 756 | * Routine: waitCommand |
mfwic | 42:3ae73b61f657 | 757 | * Input: none |
mfwic | 42:3ae73b61f657 | 758 | * Returns: none |
mfwic | 42:3ae73b61f657 | 759 | * Description: |
mfwic | 42:3ae73b61f657 | 760 | **************************************************************/ |
mfwic | 42:3ae73b61f657 | 761 | bool waitCommand(void) |
mfwic | 42:3ae73b61f657 | 762 | { |
mfwic | 42:3ae73b61f657 | 763 | if (!serialStatus.command && !serialStatus.repeat) |
mfwic | 42:3ae73b61f657 | 764 | { |
mfwic | 42:3ae73b61f657 | 765 | return TRUE; |
mfwic | 42:3ae73b61f657 | 766 | } |
mfwic | 42:3ae73b61f657 | 767 | |
mfwic | 42:3ae73b61f657 | 768 | serialStatus.computer = FALSE; |
mfwic | 42:3ae73b61f657 | 769 | serialStatus.command = FALSE; |
mfwic | 42:3ae73b61f657 | 770 | |
mfwic | 42:3ae73b61f657 | 771 | return FALSE; |
mfwic | 42:3ae73b61f657 | 772 | } |
mfwic | 42:3ae73b61f657 | 773 | |
mfwic | 42:3ae73b61f657 | 774 | // Verify that the same boards are enabled in both the current register and |
mfwic | 42:3ae73b61f657 | 775 | // the specified register |
mfwic | 42:3ae73b61f657 | 776 | |
mfwic | 42:3ae73b61f657 | 777 |