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
Diff: src/command.cpp
- Revision:
- 1:9f8583ba2431
- Parent:
- 0:44a3005d4f20
- Child:
- 3:d8948c5b2951
--- a/src/command.cpp Sat Nov 24 18:22:31 2018 +0000 +++ b/src/command.cpp Sun Nov 25 00:36:35 2018 +0000 @@ -34,12 +34,10 @@ #include "math.h" #include "RTC.h" #include "parameters.h" -#include "spi_bb.h" -#include "selfTest.h" -#include "dio.h" -#include "SOFBlock.h" -#include "flash.h" -#include "calibrate.h" +#include "all_io.h" +//#include "calibrate.h" +#include "boards.h" +#include "menu.h" /************* FILE SCOPE VARIABLES ************************/ @@ -49,8 +47,6 @@ int menuLevel = LEVEL_MAIN; int readback = 0; - - /************************************************************ * Routine: getDelimiter * Input: none @@ -157,8 +153,8 @@ { if(!setval) { - sprintf(stemp," %4.9f",value); - sendSerial(stemp); + sprintf(strbuf," %4.9f",value); + sendSerial(strbuf); } } @@ -176,8 +172,8 @@ { if(!setval) { - sprintf(stemp," %i",value); - sendSerial(stemp); + sprintf(strbuf," %i",value); + sendSerial(strbuf); } } /************************************************************ @@ -194,8 +190,8 @@ { if(!setval) { - sprintf(stemp," %c",(char)value); - sendSerial(stemp); + sprintf(strbuf," %c",(char)value); + sendSerial(strbuf); } } @@ -213,8 +209,8 @@ { if(!setval) { - sprintf(stemp," %ld",value); - sendSerial(stemp); + sprintf(strbuf," %ld",value); + sendSerial(strbuf); } } @@ -232,8 +228,8 @@ { if(!setval) { - sprintf(stemp," %u",value); - sendSerial(stemp); + sprintf(strbuf," %u",value); + sendSerial(strbuf); } } @@ -252,10 +248,10 @@ if(!setval) { if(serialStatus.computer) - sprintf(stemp," %u",(unsigned int)value); + sprintf(strbuf," %u",(unsigned int)value); else - sprintf(stemp," 0x%04x",value); - sendSerial(stemp); + sprintf(strbuf," 0x%04x",value); + sendSerial(strbuf); } } @@ -334,24 +330,6 @@ return 0; } - -/************************************************************ -* Routine: showRangeError -* Input: error -- 0 = in range, 1 = out of range -* Output: none -* Description: -* Sends a floating point number (value) over the serial port -* if it is being retrieved (GET) -* -**************************************************************/ -void showRangeError(int intValue, int iBadValue, float fBadValue) -{ - if (intValue) sprintf(stemp, "Out of Range: %d", iBadValue); - else sprintf(stemp, "Out of Range: %0.3f", fBadValue); - - sendSerial(stemp); -} - /************************************************************ * Routine: validateEntry * Input: setval (GET or SET) @@ -387,8 +365,8 @@ else { val = *address; - sprintf(stemp, " %4.3f", val); - sendSerial(stemp); + sprintf(strbuf, " %4.3f", val); + sendSerial(strbuf); } return 1; @@ -432,8 +410,8 @@ else { val = *address; - sprintf(stemp, " %4.0f", val); - sendSerial(stemp); + sprintf(strbuf, " %4.0f", val); + sendSerial(strbuf); } return TRUE; @@ -485,8 +463,8 @@ // Save the character that marks the end of the command string store = rxbuf[endofc]; - // sprintf(stemp, "store == %c\r\n", store); - // sendSerial(stemp); + // sprintf(strbuf, "store == %c\r\n", store); + // sendSerial(strbuf); // Command strings ending in '?' are readbacks readback = ((store == '?') ? 1 : 0); @@ -522,8 +500,8 @@ { if ((channel < 1) || (channel > MAX_BOARDS)) { - sprintf(stemp, " Invalid channel/board: %d (range is 1 - %d)", channel, MAX_BOARDS); - sendSerial(stemp); + sprintf(strbuf, " Invalid channel/board: %d (range is 1 - %d)", channel, MAX_BOARDS); + sendSerial(strbuf); commandError = 1; } } @@ -554,7 +532,7 @@ * Description: * Channel Pair Menu **************************************************************/ -void chlprMenu(void) +/*void chlprMenu(void) { int ival; @@ -571,12 +549,12 @@ ch[chpair][registerno].a_dwell2_volts = ch[chpair][registerno].a_dwell1_volts; ch[chpair][registerno].b_dwell2_volts = ch[chpair][registerno].b_dwell1_volts; - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d, %d] peak voltage = %0.3f V", chpair, registerno, ch[chpair][registerno].a_dwell1_volts); - sendSerial(stemp); + sprintf(strbuf, " [%d, %d] peak voltage = %0.3f V", chpair, registerno, ch[chpair][registerno].a_dwell1_volts); + sendSerial(strbuf); return; } @@ -587,12 +565,12 @@ // Set dwell times using the specified value setPairVariable(&dwells[registerno].a_dwell1_time, &dwells[registerno].b_dwell1_time, MIN_DWELL_TIME_MS, MAX_DWELL_TIME_MS); - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d] in-phase dwell time = %0.3f ms", registerno, dwells[registerno].a_dwell1_time); - sendSerial(stemp); + sprintf(strbuf, " [%d] in-phase dwell time = %0.3f ms", registerno, dwells[registerno].a_dwell1_time); + sendSerial(strbuf); return; } @@ -605,12 +583,12 @@ ch[chpair][registerno].a_dwell2_ov = ch[chpair][registerno].a_dwell1_ov; ch[chpair][registerno].b_dwell2_ov = ch[chpair][registerno].b_dwell1_ov; - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d, %d] in-phase overvoltage = %0.3f V", chpair, registerno, ch[chpair][registerno].a_dwell1_ov); - sendSerial(stemp); + sprintf(strbuf, " [%d, %d] in-phase overvoltage = %0.3f V", chpair, registerno, ch[chpair][registerno].a_dwell1_ov); + sendSerial(strbuf); return; } @@ -623,12 +601,12 @@ dwells[registerno].a_dwell2_ov_time = dwells[registerno].a_dwell1_ov_time; dwells[registerno].b_dwell2_ov_time = dwells[registerno].b_dwell1_ov_time; - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d] in-phase overvoltage time = %0.3f ms", registerno, dwells[registerno].a_dwell1_ov_time); - sendSerial(stemp); + sprintf(strbuf, " [%d] in-phase overvoltage time = %0.3f ms", registerno, dwells[registerno].a_dwell1_ov_time); + sendSerial(strbuf); return; } @@ -639,12 +617,12 @@ // Set dwell times using the specified value setPairVariable(&dwells[registerno].a_dwell2_time, &dwells[registerno].b_dwell2_time, MIN_DWELL_TIME_MS, MAX_DWELL_TIME_MS); - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d] differential dwell time = %0.3f ms", registerno, dwells[registerno].a_dwell2_time); - sendSerial(stemp); + sprintf(strbuf, " [%d] differential dwell time = %0.3f ms", registerno, dwells[registerno].a_dwell2_time); + sendSerial(strbuf); return; } @@ -657,12 +635,12 @@ { ch[chpair][registerno].enabled = ival; - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); - sendSerial(stemp); + sprintf(strbuf, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); + sendSerial(strbuf); return; } @@ -672,12 +650,12 @@ { ch[chpair][registerno].enabled = 0; - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); - sendSerial(stemp); + sprintf(strbuf, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); + sendSerial(strbuf); return; } @@ -690,12 +668,12 @@ { ch[chpair][registerno].differential_dwell = ival; - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d, %d] differential_dwell = %d", chpair, registerno, ch[chpair][registerno].differential_dwell); - sendSerial(stemp); + sprintf(strbuf, " [%d, %d] differential_dwell = %d", chpair, registerno, ch[chpair][registerno].differential_dwell); + sendSerial(strbuf); return; } @@ -708,12 +686,12 @@ { ch[chpair][registerno].inverted = ival; - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d, %d] inverted = %d", chpair, registerno, ch[chpair][registerno].inverted); - sendSerial(stemp); + sprintf(strbuf, " [%d, %d] inverted = %d", chpair, registerno, ch[chpair][registerno].inverted); + sendSerial(strbuf); return; } @@ -721,7 +699,7 @@ { commandError = 1; } -} +}*/ /************************************************************ @@ -731,7 +709,7 @@ * Description: * sets a single channel variable **************************************************************/ -void setSingleVariable(float* avariable, float* bvariable, float limitlo, float limithi) +/*void setSingleVariable(float* avariable, float* bvariable, float limitlo, float limithi) { float* variable; @@ -748,7 +726,7 @@ { validateEntry(SET, limitlo, limithi, variable); } -} +}*/ /************************************************************ @@ -758,7 +736,7 @@ * Description: * Channel Single Menu **************************************************************/ -void chlsglMenu(void) +/*void chlsglMenu(void) { int channelSide; float value; @@ -776,14 +754,14 @@ { setSingleVariable(&ch[chpair][registerno].a_dwell1_volts, &ch[chpair][registerno].b_dwell1_volts, MIN_VOLTAGE, MAX_VOLTAGE); - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } value = ((channelSide == 1) ? ch[chpair][registerno].a_dwell1_volts : ch[chpair][registerno].b_dwell1_volts); - sprintf(stemp, " [%d%c, %d] dwell 1 peak amplitude = %0.3f V", chpair, chsgl, registerno, value); - sendSerial(stemp); + sprintf(strbuf, " [%d%c, %d] dwell 1 peak amplitude = %0.3f V", chpair, chsgl, registerno, value); + sendSerial(strbuf); return; } @@ -794,14 +772,14 @@ // Set dwell times using the specified value setSingleVariable(&dwells[registerno].a_dwell1_time, &dwells[registerno].b_dwell1_time, MIN_DWELL_TIME_MS, MAX_DWELL_TIME_MS); - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } value = ((channelSide == 1) ? dwells[registerno].a_dwell1_time : dwells[registerno].b_dwell1_time); - sprintf(stemp, " [%d] dwell 1 time = %0.3f ms", registerno, value); - sendSerial(stemp); + sprintf(strbuf, " [%d] dwell 1 time = %0.3f ms", registerno, value); + sendSerial(strbuf); return; } @@ -811,14 +789,14 @@ { setSingleVariable(&ch[chpair][registerno].a_dwell1_ov, &ch[chpair][registerno].b_dwell1_ov, MIN_VOLTAGE, MAX_VOLTAGE); - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } value = ((channelSide == 1) ? ch[chpair][registerno].a_dwell1_ov : ch[chpair][registerno].b_dwell1_ov); - sprintf(stemp, " [%d%c, %d] dwell 1 overvoltage = %0.3f V", chpair, chsgl, registerno, value); - sendSerial(stemp); + sprintf(strbuf, " [%d%c, %d] dwell 1 overvoltage = %0.3f V", chpair, chsgl, registerno, value); + sendSerial(strbuf); return; } @@ -829,14 +807,14 @@ // Set channel 1's dwell 1 overvoltage time setSingleVariable(&dwells[registerno].a_dwell1_ov_time, &dwells[registerno].b_dwell1_ov_time, MIN_DWELL_TIME_MS, MAX_DWELL_TIME_MS); - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } value = ((channelSide == 1) ? dwells[registerno].a_dwell1_ov_time : dwells[registerno].b_dwell1_ov_time); - sprintf(stemp, " [%d] dwell 1 overvoltage time = %0.3f ms", registerno, value); - sendSerial(stemp); + sprintf(strbuf, " [%d] dwell 1 overvoltage time = %0.3f ms", registerno, value); + sendSerial(strbuf); return; } @@ -846,14 +824,14 @@ { setSingleVariable(&ch[chpair][registerno].a_dwell2_volts, &ch[chpair][registerno].b_dwell2_volts, MIN_VOLTAGE, MAX_VOLTAGE); - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } value = ((channelSide == 1) ? ch[chpair][registerno].a_dwell2_volts : ch[chpair][registerno].b_dwell2_volts); - sprintf(stemp, " [%d%c, %d] dwell 2 peak amplitude = %0.3f V", chpair, chsgl, registerno, value); - sendSerial(stemp); + sprintf(strbuf, " [%d%c, %d] dwell 2 peak amplitude = %0.3f V", chpair, chsgl, registerno, value); + sendSerial(strbuf); return; } @@ -864,14 +842,14 @@ // Set dwell 2 time setSingleVariable(&dwells[registerno].a_dwell2_time, &dwells[registerno].b_dwell2_time, MIN_DWELL_TIME_MS, MAX_DWELL_TIME_MS); - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } value = ((channelSide == 1) ? dwells[registerno].a_dwell2_time : dwells[registerno].b_dwell2_time); - sprintf(stemp, " [%d] dwell 2 time = %0.3f ms", registerno, value); - sendSerial(stemp); + sprintf(strbuf, " [%d] dwell 2 time = %0.3f ms", registerno, value); + sendSerial(strbuf); return; } @@ -881,14 +859,14 @@ { setSingleVariable(&ch[chpair][registerno].a_dwell2_ov, &ch[chpair][registerno].b_dwell2_ov, MIN_VOLTAGE, MAX_VOLTAGE); - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } value = ((channelSide == 1) ? ch[chpair][registerno].a_dwell2_ov : ch[chpair][registerno].b_dwell2_ov); - sprintf(stemp, " [%d%c, %d] dwell 2 overvoltage = %0.3f V", chpair, chsgl, registerno, value); - sendSerial(stemp); + sprintf(strbuf, " [%d%c, %d] dwell 2 overvoltage = %0.3f V", chpair, chsgl, registerno, value); + sendSerial(strbuf); return; } @@ -899,14 +877,14 @@ // Set dwell 2 overvoltage time setSingleVariable(&dwells[registerno].a_dwell2_ov_time, &dwells[registerno].b_dwell2_ov_time, MIN_DWELL_TIME_MS, MAX_DWELL_TIME_MS); - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } value = ((channelSide == 1) ? dwells[registerno].a_dwell2_ov_time : dwells[registerno].b_dwell2_ov_time); - sprintf(stemp, " [%d] dwell 2 overvoltage time = %0.3f ms", registerno, value); - sendSerial(stemp); + sprintf(strbuf, " [%d] dwell 2 overvoltage time = %0.3f ms", registerno, value); + sendSerial(strbuf); return; } @@ -916,12 +894,12 @@ { ch[chpair][registerno].enabled = 1; - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); - sendSerial(stemp); + sprintf(strbuf, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); + sendSerial(strbuf); return; } @@ -931,12 +909,12 @@ { ch[chpair][registerno].enabled = 0; - sprintf(stemp, " Setting"); - sendSerial(stemp); + sprintf(strbuf, " Setting"); + sendSerial(strbuf); } - sprintf(stemp, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); - sendSerial(stemp); + sprintf(strbuf, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); + sendSerial(strbuf); return; } @@ -944,7 +922,7 @@ { commandError = 1; } -} +}*/ /************************************************************ @@ -968,7 +946,7 @@ if (!strcmp(commandString, "LEDS")) // duh do I have to tell you? { - testLEDs(); + //testLEDs(); return; } @@ -976,7 +954,8 @@ { if ((rxbuf[bufloc] == 0x0D) || (rxbuf[bufloc] == 0)) { - ival = DEFAULT_SELFTEST_BOARDS; + //ival = DEFAULT_SELFTEST_BOARDS; + ival = 0; } else { @@ -984,21 +963,21 @@ if ((ival < 1) || (ival > MAX_BOARDS)) { - sprintf(stemp, " Invalid number of channels/boards (range is 1 - %d)", MAX_BOARDS); - sendSerial(stemp); + sprintf(strbuf, " Invalid number of channels/boards (range is 1 - %d)", MAX_BOARDS); + sendSerial(strbuf); commandError = 1; return; } } - selfTest(ival); + //selfTest(ival); return; } if (!strcmp(commandString, "HVEN")) // high voltage enable { ival = getival(SET); - hv_en = ival; + //hv_en = ival; return; } @@ -1014,32 +993,32 @@ if (commandError) return; ch--; - sendData((unsigned int)ch, (unsigned int)dac, data); - sprintf(stemp, " ch: %u dac: %u value: %u", ch + 1, dac, data); - sendSerial(stemp); + //sendData((unsigned int)ch, (unsigned int)dac, data); + sprintf(strbuf, " ch: %u dac: %u value: %u", ch + 1, dac, data); + sendSerial(strbuf); return; } if (!strcmp(commandString, "DINIT")) { - initDACs(); + //initDACs(); return; } if (!strcmp(commandString, "FINIT")) { - formatParameterSector(); + //formatParameterSector(); return; } if (!strcmp(commandString, "CINIT")) { - initCalParameters(); - sprintf(stemp, " All calibration parameters set to default values"); - sendSerial(stemp); + //initCalParameters(); + sprintf(strbuf, " All calibration parameters set to default values"); + sendSerial(strbuf); return; } - +/* if (!strcmp(commandString, "VOLTS")) { ch = getival(SET); @@ -1064,8 +1043,8 @@ } sendData((unsigned int)ch, (unsigned int)dac, data); - sprintf(stemp, " ch: %u dac: %u value: %u", ch + 1, dac, data); - sendSerial(stemp); + sprintf(strbuf, " ch: %u dac: %u value: %u", ch + 1, dac, data); + sendSerial(strbuf); return; } @@ -1073,8 +1052,8 @@ { ival = getival(SET); setBoardEnables((unsigned int)ival); - sprintf(stemp, " Board Enable Bits = 0x%04x\r\n", ival); - sendSerial(stemp); + sprintf(strbuf, " Board Enable Bits = 0x%04x\r\n", ival); + sendSerial(strbuf); return; } @@ -1089,8 +1068,8 @@ ch--; setBoardEnable(ch, (unsigned int)ival); - sprintf(stemp, " Board Enable %d = %d\r\n", ch + 1, ival); - sendSerial(stemp); + sprintf(strbuf, " Board Enable %d = %d\r\n", ch + 1, ival); + sendSerial(strbuf); return; } @@ -1109,8 +1088,8 @@ Delay(100); ival = dtst_out; - sprintf(stemp, " DTST_OUT = %d\r\n", ival); - sendSerial(stemp); + sprintf(strbuf, " DTST_OUT = %d\r\n", ival); + sendSerial(strbuf); return; } @@ -1128,8 +1107,8 @@ } ival = dtst_out; - sprintf(stemp, " DTST_OUT = %d\r\n", ival); - sendSerial(stemp); + sprintf(strbuf, " DTST_OUT = %d\r\n", ival); + sendSerial(strbuf); return; } @@ -1141,11 +1120,11 @@ if (!strcmp(commandString, "HVGOOD")) { - sprintf(stemp, " HVCMP1: %i HVCMP2: %i", (int)hv_cmptr1, (int)hv_cmptr2); - sendSerial(stemp); + sprintf(strbuf, " HVCMP1: %i HVCMP2: %i", (int)hv_cmptr1, (int)hv_cmptr2); + sendSerial(strbuf); return; } - +*/ if (strcmp(commandString, "")) { commandError = 1; @@ -1160,7 +1139,7 @@ * Set the specified dwell time in [registerno] to the indicated * number of milliseconds **************************************************************/ -enum { DWELL_1_OV_TIME, DWELL_1_TIME, DWELL_2_OV_TIME, DWELL_2_TIME }; +/*enum { DWELL_1_OV_TIME, DWELL_1_TIME, DWELL_2_OV_TIME, DWELL_2_TIME }; void setDwellTime(int dwellType) { @@ -1171,37 +1150,17 @@ { if (dwellType == DWELL_1_OV_TIME) { - sprintf(stemp, "\r\n Channel A Dwell 1 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].a_dwell1_ov_time); - sendSerial(stemp); - sprintf(stemp, "\r\n Channel B Dwell 1 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell1_ov_time); - sendSerial(stemp); - } - else if (dwellType == DWELL_1_TIME) - { - sprintf(stemp, "\r\n Channel A Dwell 1 Time [%i] = %0.3f", registerno + 1, dwells[registerno].a_dwell1_time); - sendSerial(stemp); - sprintf(stemp, "\r\n Channel B Dwell 1 Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell1_time); - sendSerial(stemp); + sprintf(strbuf, "\r\n Channel A Dwell 1 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].a_dwell1_ov_time); + sendSerial(strbuf); + sprintf(strbuf, "\r\n Channel B Dwell 1 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell1_ov_time); + sendSerial(strbuf); } - else if (dwellType == DWELL_2_OV_TIME) - { - sprintf(stemp, "\r\n Channel A Dwell 2 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].a_dwell2_ov_time); - sendSerial(stemp); - sprintf(stemp, "\r\n Channel B Dwell 2 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell2_ov_time); - sendSerial(stemp); - } - else if (dwellType == DWELL_2_TIME) - { - sprintf(stemp, "\r\n Channel A Dwell 2 Time [%i] = %0.3f", registerno + 1, dwells[registerno].a_dwell2_time); - sendSerial(stemp); - sprintf(stemp, "\r\n Channel B Dwell 2 Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell2_time); - sendSerial(stemp); - } + } else if (running == 1) { - sprintf(stemp, " Parameters may not be updated while running!"); - sendSerial(stemp); + sprintf(strbuf, " Parameters may not be updated while running!"); + sendSerial(strbuf); } else { @@ -1230,8 +1189,8 @@ if (!validateInt(SET, 1, MAX_REGISTERS, ®isterno)) { - sprintf(stemp, " Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(stemp); + sprintf(strbuf, " Invalid register number (1 - %d)", MAX_REGISTERS); + sendSerial(strbuf); commandError = 1; } @@ -1254,8 +1213,8 @@ // Read and validate the dwell time value if (!validateEntry(SET, MIN_DWELL_TIME_MS, MAX_DWELL_TIME_MS, &fValue)) { - sprintf(stemp, " Invalid dwell time"); - sendSerial(stemp); + sprintf(strbuf, " Invalid dwell time"); + sendSerial(strbuf); commandError = 1; } } @@ -1267,68 +1226,24 @@ if ((!setSingleChannel) || (channelSideChar == 'A')) { dwells[registerno].a_dwell1_ov_time = fValue; - sprintf(stemp, "\r\n Channel A Dwell 1 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].a_dwell1_ov_time); - sendSerial(stemp); + sprintf(strbuf, "\r\n Channel A Dwell 1 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].a_dwell1_ov_time); + sendSerial(strbuf); } if ((!setSingleChannel) || (channelSideChar == 'B')) { dwells[registerno].b_dwell1_ov_time = fValue; - sprintf(stemp, "\r\n Channel B Dwell 1 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell1_ov_time); - sendSerial(stemp); - } - } - else if (dwellType == DWELL_1_TIME) - { - if ((!setSingleChannel) || (channelSideChar == 'A')) - { - dwells[registerno].a_dwell1_time = fValue; - sprintf(stemp, "\r\n Channel A Dwell 1 Time [%i] = %0.3f", registerno + 1, dwells[registerno].a_dwell1_time); - sendSerial(stemp); - } - if ((!setSingleChannel) || (channelSideChar == 'B')) - { - dwells[registerno].b_dwell1_time = fValue; - sprintf(stemp, "\r\n Channel B Dwell 1 Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell1_time); - sendSerial(stemp); + sprintf(strbuf, "\r\n Channel B Dwell 1 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell1_ov_time); + sendSerial(strbuf); } } - else if (dwellType == DWELL_2_OV_TIME) - { - if ((!setSingleChannel) || (channelSideChar == 'A')) - { - dwells[registerno].a_dwell2_ov_time = fValue; - sprintf(stemp, "\r\n Channel A Dwell 2 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].a_dwell2_ov_time); - sendSerial(stemp); - } - if ((!setSingleChannel) || (channelSideChar == 'B')) - { - dwells[registerno].b_dwell2_ov_time = fValue; - sprintf(stemp, "\r\n Channel B Dwell 2 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell2_ov_time); - sendSerial(stemp); - } - } - else if (dwellType == DWELL_2_TIME) - { - if ((!setSingleChannel) || (channelSideChar == 'A')) - { - dwells[registerno].a_dwell2_time = fValue; - sprintf(stemp, "\r\n Channel A Dwell 2 Time [%i] = %0.3f", registerno + 1, dwells[registerno].a_dwell2_time); - sendSerial(stemp); - } - if ((!setSingleChannel) || (channelSideChar == 'B')) - { - dwells[registerno].b_dwell2_time = fValue; - sprintf(stemp, "\r\n Channel B Dwell 2 Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell2_time); - sendSerial(stemp); - } - } + } } -} +}*/ // Clear the specified register - +/* void clearRegister(unsigned int reg) { int i; @@ -1358,7 +1273,7 @@ ch[i][reg].b_dwell1_ov = 0; ch[i][reg].b_dwell2_ov = 0; } -} +}*/ /************************************************************ @@ -1373,6 +1288,7 @@ int channelNum, channelSide, numPoints, i, ival; char channelSideChar; unsigned int boardEnables; + unsigned int multiplier; char commandString[80] = { 0 }; @@ -1381,48 +1297,77 @@ parseCommand(GET, commandString); - if (!strcmp(commandString, "FREQ")) + if (!strcmp(commandString, "MENU")) + { + menuRedraw();//RK: menuRedraw is empty. + } + else if (!strcmp(commandString, "BRDS")) + // BRDS is used to get/set the wr_out value. + // The integer value of multiplier is used to change wr_out via setBoardEnables(multiplier). + // Slots 12 to 0 are activated with the wr_out signals + // wr_out[13] = slots[12:0] { if (readback) { - sprintf(stemp, " %f", frequency); - sendSerial(stemp); + sprintf(strbuf, " %d", multiplier); + sendSerial(strbuf); } - else if (running == 1) - { - sprintf(stemp, " Parameters may not be updated while running!"); - sendSerial(stemp); - } + //else if (running == 1) + //{ + // sprintf(strbuf, " Parameters may not be updated while running!"); + // sendSerial(strbuf); + //} else { - validateEntry(SET, 1.0, 10000.0, &frequency); + if(checkRange(0, 63, multiplier) == 1){ + setBoardEnables(multiplier); + }else{ + showRangeError(1, multiplier, 0.0); + } + } + } + else if (!strcmp(commandString, "MULT")) + // MULT is used to get/set the en_out value. + // The integer value of multiplier is used to change en_out via setBoardWeights(multiplier). + // en_out are binary weighted signals that activate groups of DC-DC converters on the slot cards. + // en_out[6] = {en32, en16, en8, en4, en2, en1} + { + if (readback) + { + sprintf(strbuf, " %d", multiplier); + sendSerial(strbuf); + } + //else if (running == 1) + //{ + // sprintf(strbuf, " Parameters may not be updated while running!"); + // sendSerial(strbuf); + //} + else + { + if(checkRange(0, 63, multiplier) == 1){ + setBoardWeights(multiplier); + }else{ + showRangeError(1, multiplier, 0.0); + } } } else if (!strcmp(commandString, "ALLOFF")) { - hv_en = 1; + //hv_en = 1; setBoardEnables(ALLOFF); } else if (!strcmp(commandString, "ALLON")) { - hv_en = 0; + //hv_en = 0; setBoardEnables(ALLON); } else if (!strcmp(commandString, "DWL1_OV_TIME")) { - setDwellTime(DWELL_1_OV_TIME); + //setDwellTime(DWELL_1_OV_TIME); } else if (!strcmp(commandString, "DWL1_TIME")) { - setDwellTime(DWELL_1_TIME); - } - else if (!strcmp(commandString, "DWL2_OV_TIME")) - { - setDwellTime(DWELL_2_OV_TIME); - } - else if (!strcmp(commandString, "DWL2_TIME")) - { - setDwellTime(DWELL_2_TIME); + //setDwellTime(DWELL_1_TIME); } else if (!strcmp(commandString, "RUN")) { @@ -1431,20 +1376,21 @@ if (rxbuf[bufloc] == '0') { - stopPulser(); - setDacsToZeroVolts(); + stopConverter(); + //setDacsToZeroVolts(); } - else if ((rxbuf[bufloc] > '0') && (rxbuf[bufloc] < '0' + MAX_REGISTERS)) + else if ((rxbuf[bufloc] > '0') && (rxbuf[bufloc] < '0' + MAX_BOARDS)) { ival = atoi(&rxbuf[bufloc]); ival--; if (running == 0) { - setDacsToZeroVolts(); - Delay(1000); - registerno = ival; - startPulser(registerno); + //setDacsToZeroVolts(); + //Delay(1000); + wait(0.5); + boardsActive = ival; + startConverter(boardsActive); } else { @@ -1454,40 +1400,40 @@ // If board enable flags match, change the register set if (boardEnables == 0) { - registerno = ival; + boardsActive = ival; } else { - sprintf(stemp, " Board enable flags do not match (0x%08x)", boardEnables); - sendSerial(stemp); + sprintf(strbuf, " Board enable flags do not match (0x%08x)", boardEnables); + sendSerial(strbuf); } } } else { - sprintf(stemp, " Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(stemp); + sprintf(strbuf, " Invalid register number (1 - %d)", MAX_BOARDS); + sendSerial(strbuf); commandError = 1; } } else if (!strcmp(commandString, "STOP")) { - stopPulser(); + stopConverter(); setBoardEnables(ALLOFF); - hv_en = OFF; + //hv_en = OFF; } - else if (!strcmp(commandString, "CLEAR")) +/* else if (!strcmp(commandString, "CLEAR")) { if (running == 1) { - sprintf(stemp, " Parameters may not be updated while running!"); - sendSerial(stemp); + sprintf(strbuf, " Parameters may not be updated while running!"); + sendSerial(strbuf); commandError = 1; } else if (!validateInt(SET, 0, MAX_REGISTERS, ®isterno)) { - sprintf(stemp, " Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(stemp); + sprintf(strbuf, " Invalid register number (1 - %d)", MAX_REGISTERS); + sendSerial(strbuf); commandError = 1; } @@ -1504,8 +1450,8 @@ initCalParameters(); - sprintf(stemp, " All parameters reset to default values"); - sendSerial(stemp); + sprintf(strbuf, " All parameters reset to default values"); + sendSerial(strbuf); } else { @@ -1514,29 +1460,29 @@ clearRegister(registerno); - sprintf(stemp, " [x, %d] voltages are 0", registerno); - sendSerial(stemp); + sprintf(strbuf, " [x, %d] voltages are 0", registerno); + sendSerial(strbuf); } } - } + }*/ else if(!strcmp(commandString, "TEST")) { if (running == 1) { - sprintf(stemp, " Parameters may not be updated while running!"); - sendSerial(stemp); + sprintf(strbuf, " Parameters may not be updated while running!"); + sendSerial(strbuf); } else { testMenu(); } } - else if(!strcmp(commandString, "READ")) +/* else if(!strcmp(commandString, "READ")) { if (!validateInt(SET, 1, MAX_REGISTERS, ®isterno)) { - sprintf(stemp, " Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(stemp); + sprintf(strbuf, " Invalid register number (1 - %d)", MAX_REGISTERS); + sendSerial(strbuf); commandError = 1; } @@ -1545,60 +1491,41 @@ // Adjust user values (1 - MAX) to 0 offset values (0 - (MAX - 1)) registerno--; - sprintf(stemp, "\r\n Register [x, %d]: ", registerno + 1); - sendSerial(stemp); - sprintf(stemp, "\r\n frequency = %0.3f Hz", frequency); - sendSerial(stemp); - sprintf(stemp, "\r\n dwell1_ov_time = %0.3f ms", dwells[registerno].a_dwell1_ov_time); - sendSerial(stemp); - sprintf(stemp, "\r\n dwell1_time = %0.3f ms", dwells[registerno].a_dwell1_time); - sendSerial(stemp); - sprintf(stemp, "\r\n dwell2_ov_time = %0.3f ms", dwells[registerno].a_dwell2_ov_time); - sendSerial(stemp); - sprintf(stemp, "\r\n dwell2_time = %0.3f ms", dwells[registerno].a_dwell2_time); - sendSerial(stemp); + sprintf(strbuf, "\r\n Register [x, %d]: ", registerno + 1); + sendSerial(strbuf); + sprintf(strbuf, "\r\n frequency = %0.3f Hz", frequency); + sendSerial(strbuf); + sprintf(strbuf, "\r\n dwell1_ov_time = %0.3f ms", dwells[registerno].a_dwell1_ov_time); + sendSerial(strbuf); + sprintf(strbuf, "\r\n dwell1_time = %0.3f ms", dwells[registerno].a_dwell1_time); + sendSerial(strbuf); for (i = 0; i < MAX_BOARDS; i++) { - sprintf(stemp, "\r\n\r\n Register [%d, %d]: ", i + 1, registerno + 1); - sendSerial(stemp); - sprintf(stemp, "\r\n enabled = %d", ch[i][registerno].enabled); - sendSerial(stemp); - sprintf(stemp, "\r\n differential = %d", ch[i][registerno].differential_dwell); - sendSerial(stemp); - sprintf(stemp, "\r\n inverted = %d", ch[i][registerno].inverted); - sendSerial(stemp); - sprintf(stemp, "\r\n a_dwell1_ov = %0.3f V", ch[i][registerno].a_dwell1_ov); - sendSerial(stemp); - sprintf(stemp, "\r\n a_dwell1_volts = %0.3f V", ch[i][registerno].a_dwell1_volts); - sendSerial(stemp); - sprintf(stemp, "\r\n a_dwell2_ov = %0.3f V", ch[i][registerno].a_dwell2_ov); - sendSerial(stemp); - sprintf(stemp, "\r\n a_dwell2_volts = %0.3f V", ch[i][registerno].a_dwell2_volts); - sendSerial(stemp); - sprintf(stemp, "\r\n b_dwell1_ov = %0.3f V", ch[i][registerno].b_dwell1_ov); - sendSerial(stemp); - sprintf(stemp, "\r\n b_dwell1_volts = %0.3f V", ch[i][registerno].b_dwell1_volts); - sendSerial(stemp); - sprintf(stemp, "\r\n b_dwell2_ov = %0.3f V", ch[i][registerno].b_dwell2_ov); - sendSerial(stemp); - sprintf(stemp, "\r\n b_dwell2_volts = %0.3f V", ch[i][registerno].b_dwell2_volts); - sendSerial(stemp); + sprintf(strbuf, "\r\n\r\n Register [%d, %d]: ", i + 1, registerno + 1); + sendSerial(strbuf); + sprintf(strbuf, "\r\n enabled = %d", ch[i][registerno].enabled); + sendSerial(strbuf); + sprintf(strbuf, "\r\n a_dwell1_ov = %0.3f V", ch[i][registerno].a_dwell1_ov); + sendSerial(strbuf); + sprintf(strbuf, "\r\n a_dwell1_volts = %0.3f V", ch[i][registerno].a_dwell1_volts); + sendSerial(strbuf); + } } - } - else if(!strcmp(commandString, "CAL")) + }*/ +/* else if(!strcmp(commandString, "CAL")) { if (running == 1) { - sprintf(stemp, " Parameters may not be updated while running!"); - sendSerial(stemp); + sprintf(strbuf, " Parameters may not be updated while running!"); + sendSerial(strbuf); commandError = 1; } else if (!validateInt(SET, 1, MAX_BOARDS, &channelNum)) { - sprintf(stemp, " Invalid board number (1 - %d)", MAX_BOARDS); - sendSerial(stemp); + sprintf(strbuf, " Invalid board number (1 - %d)", MAX_BOARDS); + sendSerial(strbuf); commandError = 1; } @@ -1613,10 +1540,10 @@ // Does the user simply want to read the current cal parameters? if (rxbuf[bufloc] == '?') { - sprintf(stemp, "\r\nChannel %dA Scale = %0.4f Offset = %0.4f", channelNum, cal[channelNum].a_scale, cal[channelNum].a_offset); - sendSerial(stemp); - sprintf(stemp, "\r\nChannel %dB Scale = %0.4f Offset = %0.4f", channelNum, cal[channelNum].b_scale, cal[channelNum].b_offset); - sendSerial(stemp); + sprintf(strbuf, "\r\nChannel %dA Scale = %0.4f Offset = %0.4f", channelNum, cal[channelNum].a_scale, cal[channelNum].a_offset); + sendSerial(strbuf); + sprintf(strbuf, "\r\nChannel %dB Scale = %0.4f Offset = %0.4f", channelNum, cal[channelNum].b_scale, cal[channelNum].b_offset); + sendSerial(strbuf); sendCRLF(); return; } @@ -1626,8 +1553,8 @@ if ((channelSideChar != 'A') && (channelSideChar != 'B')) { - sprintf(stemp, " Invalid channel (A/B)"); - sendSerial(stemp); + sprintf(strbuf, " Invalid channel (A/B)"); + sendSerial(strbuf); commandError = 1; } } @@ -1645,13 +1572,13 @@ { if (channelSide == 1) { - sprintf(stemp, "\r\nChannel %dA Scale = %0.4f Offset = %0.4f", channelNum, cal[channelNum].a_scale, cal[channelNum].a_offset); - sendSerial(stemp); + sprintf(strbuf, "\r\nChannel %dA Scale = %0.4f Offset = %0.4f", channelNum, cal[channelNum].a_scale, cal[channelNum].a_offset); + sendSerial(strbuf); } else { - sprintf(stemp, "\r\nChannel %dB Scale = %0.4f Offset = %0.4f", channelNum, cal[channelNum].b_scale, cal[channelNum].b_offset); - sendSerial(stemp); + sprintf(strbuf, "\r\nChannel %dB Scale = %0.4f Offset = %0.4f", channelNum, cal[channelNum].b_scale, cal[channelNum].b_offset); + sendSerial(strbuf); } sendCRLF(); @@ -1665,16 +1592,16 @@ } else if (!validateInt(SET, 3, 11, &numPoints)) { - sprintf(stemp, " Invalid number of cal points (3 - 11)"); - sendSerial(stemp); + sprintf(strbuf, " Invalid number of cal points (3 - 11)"); + sendSerial(strbuf); commandError = 1; } } if (!commandError) { - sprintf(stemp, " Starting %d-point Calibration on Channel %d%c", numPoints, channelNum, channelSideChar); - sendSerial(stemp); + sprintf(strbuf, " Starting %d-point Calibration on Channel %d%c", numPoints, channelNum, channelSideChar); + sendSerial(strbuf); // Reset the serial buffer for the incoming user input bufloc = 0; @@ -1691,20 +1618,20 @@ { if (readback) { - sprintf(stemp, " [%i, %i]", chpair, registerno); - sendSerial(stemp); + sprintf(strbuf, " [%i, %i]", chpair, registerno); + sendSerial(strbuf); } else if (running == 1) { - sprintf(stemp, " Parameters may not be updated while running!"); - sendSerial(stemp); + sprintf(strbuf, " Parameters may not be updated while running!"); + sendSerial(strbuf); } else { if (!validateInt(SET, 1, MAX_BOARDS, &chpair)) { - sprintf(stemp, "Invalid board number (1 - %d)", MAX_BOARDS); - sendSerial(stemp); + sprintf(strbuf, "Invalid board number (1 - %d)", MAX_BOARDS); + sendSerial(strbuf); commandError = 1; } @@ -1714,8 +1641,8 @@ if (!validateInt(SET, 1, MAX_REGISTERS, ®isterno)) { - sprintf(stemp, "Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(stemp); + sprintf(strbuf, "Invalid register number (1 - %d)", MAX_REGISTERS); + sendSerial(strbuf); commandError = 1; } } @@ -1753,20 +1680,20 @@ { if (readback) { - sprintf(stemp, " [%i%c, %i]", chpair, chsgl, registerno); - sendSerial(stemp); + sprintf(strbuf, " [%i%c, %i]", chpair, chsgl, registerno); + sendSerial(strbuf); } else if (running == 1) { - sprintf(stemp, " Parameters may not be updated while running!"); - sendSerial(stemp); + sprintf(strbuf, " Parameters may not be updated while running!"); + sendSerial(strbuf); } else { if (!validateInt(SET, 1, MAX_BOARDS, &chpair)) { - sprintf(stemp, "Invalid board number (1 - %d)", MAX_BOARDS); - sendSerial(stemp); + sprintf(strbuf, "Invalid board number (1 - %d)", MAX_BOARDS); + sendSerial(strbuf); commandError = 1; } @@ -1778,8 +1705,8 @@ if ((channelSideChar != 'A') && (channelSideChar != 'B')) { - sprintf(stemp, "Invalid channel (A/B)"); - sendSerial(stemp); + sprintf(strbuf, "Invalid channel (A/B)"); + sendSerial(strbuf); commandError = 1; } @@ -1790,8 +1717,8 @@ if (!validateInt(SET, 1, MAX_REGISTERS, ®isterno)) { - sprintf(stemp, "Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(stemp); + sprintf(strbuf, "Invalid register number (1 - %d)", MAX_REGISTERS); + sendSerial(strbuf); commandError = 1; } } @@ -1826,7 +1753,7 @@ } } } - } + }*/ else { if (strcmp(commandString, ""))