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:
- 11:01dcfb29fbc4
- Parent:
- 10:6c3233b03658
- Child:
- 12:fd1fd1857628
--- a/src/command.cpp Fri Dec 07 17:39:01 2018 +0000 +++ b/src/command.cpp Fri Dec 07 20:42:41 2018 +0000 @@ -32,7 +32,6 @@ #include "serial.h" #include "globals.h" #include "math.h" -#include "RTC.h" #include "parameters.h" #include "all_io.h" //#include "calibrate.h" @@ -40,11 +39,9 @@ #include "menu.h" #include "command.h" -extern unsigned int boardsActive; -extern unsigned int boardMults; -extern unsigned int binCode[WEIGHT_BIN_WIDTH+1]; -extern unsigned int thermCode[BOARDS_THERMCODE_WIDTH+1]; -extern unsigned int commandData; +unsigned int boardsActive; +unsigned int boardMults; +unsigned int commandData; extern unsigned short my12; /************* FILE SCOPE VARIABLES ************************/ @@ -546,407 +543,6 @@ } } - -/************************************************************ -* Routine: chlprMenu -* Input: none -* Returns: none -* Description: -* Channel Pair Menu -**************************************************************/ -/*void chlprMenu(void) -{ - int ival; - - char commandString[80] = { 0 }; - - commandError = 0; - parseCommand(GET, commandString); - - if (!strcmp(commandString, "AMPL")) - { - if (!readback) - { - setPairVariable(&ch[chpair][registerno].a_dwell1_volts, &ch[chpair][registerno].b_dwell1_volts, MIN_VOLTAGE, MAX_VOLTAGE); - - 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(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d, %d] peak voltage = %0.3f V", chpair, registerno, ch[chpair][registerno].a_dwell1_volts); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "DWLPHS")) - { - if (!readback) - { - // 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(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d] in-phase dwell time = %0.3f ms", registerno, dwells[registerno].a_dwell1_time); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString,"DWLPHS_OV")) - { - if (!readback) - { - setPairVariable(&ch[chpair][registerno].a_dwell1_ov, &ch[chpair][registerno].b_dwell1_ov, MIN_VOLTAGE, MAX_VOLTAGE); - - 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(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d, %d] in-phase overvoltage = %0.3f V", chpair, registerno, ch[chpair][registerno].a_dwell1_ov); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString,"DWLPHS_OV_TIME")) - { - if (!readback) - { - // Set overvoltage times using the specified value - setPairVariable(&dwells[registerno].a_dwell1_ov_time, &dwells[registerno].b_dwell1_ov_time, MIN_DWELL_TIME_MS, MAX_DWELL_TIME_MS); - 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(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d] in-phase overvoltage time = %0.3f ms", registerno, dwells[registerno].a_dwell1_ov_time); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString,"DWLDIFFL")) - { - if (!readback) - { - // 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(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d] differential dwell time = %0.3f ms", registerno, dwells[registerno].a_dwell2_time); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "ENABLE")) - { - ival = getival(SET); - if ((ival != 0) && (ival != 1)) ival = 0; - - if (!readback) - { - ch[chpair][registerno].enabled = ival; - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "DISABLE")) - { - if (!readback) - { - ch[chpair][registerno].enabled = 0; - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "DIFF")) - { - ival = getival(SET); - if ((ival != 0) && (ival != 1)) ival = 0; - - if (!readback) - { - ch[chpair][registerno].differential_dwell = ival; - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d, %d] differential_dwell = %d", chpair, registerno, ch[chpair][registerno].differential_dwell); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "INVERT")) - { - ival = getival(SET); - if ((ival != 0) && (ival != 1)) ival = 0; - - if (!readback) - { - ch[chpair][registerno].inverted = ival; - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d, %d] inverted = %d", chpair, registerno, ch[chpair][registerno].inverted); - sendSerial(strbuf); - return; - } - - if (strcmp(commandString, "")) - { - commandError = 1; - } -}*/ - - -/************************************************************ -* Routine: setSingleVariable -* Input: *avariable,*bvariable -* Returns: none -* Description: -* sets a single channel variable -**************************************************************/ -/*void setSingleVariable(float* avariable, float* bvariable, float limitlo, float limithi) -{ - float* variable; - - if ((chsgl == 'A') || (chsgl == 'a')) - { - variable = avariable; - } - else - { - variable = bvariable; - } - - if (!readback) - { - validateEntry(SET, limitlo, limithi, variable); - } -}*/ - - -/************************************************************ -* Routine: chlsglMenu -* Input: none -* Returns: none -* Description: -* Channel Single Menu -**************************************************************/ -/*void chlsglMenu(void) -{ - int channelSide; - float value; - - char commandString[80] = { 0 }; - - commandError = 0; - parseCommand(GET, commandString); - - channelSide = (((chsgl == 'A') || (chsgl == 'a')) ? 1 : 2); - - if (!strcmp(commandString, "DWL1AMPL")) - { - if (!readback) - { - setSingleVariable(&ch[chpair][registerno].a_dwell1_volts, &ch[chpair][registerno].b_dwell1_volts, MIN_VOLTAGE, MAX_VOLTAGE); - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - value = ((channelSide == 1) ? ch[chpair][registerno].a_dwell1_volts : ch[chpair][registerno].b_dwell1_volts); - - sprintf(strbuf, " [%d%c, %d] dwell 1 peak amplitude = %0.3f V", chpair, chsgl, registerno, value); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "DWL1")) - { - if (!readback) - { - // 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(strbuf, " Setting"); - sendSerial(strbuf); - } - - value = ((channelSide == 1) ? dwells[registerno].a_dwell1_time : dwells[registerno].b_dwell1_time); - - sprintf(strbuf, " [%d] dwell 1 time = %0.3f ms", registerno, value); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "DWL1_OV")) - { - if (!readback) - { - setSingleVariable(&ch[chpair][registerno].a_dwell1_ov, &ch[chpair][registerno].b_dwell1_ov, MIN_VOLTAGE, MAX_VOLTAGE); - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - value = ((channelSide == 1) ? ch[chpair][registerno].a_dwell1_ov : ch[chpair][registerno].b_dwell1_ov); - - sprintf(strbuf, " [%d%c, %d] dwell 1 overvoltage = %0.3f V", chpair, chsgl, registerno, value); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "DWL1_OV_TIME")) - { - if (!readback) - { - // 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(strbuf, " Setting"); - sendSerial(strbuf); - } - - value = ((channelSide == 1) ? dwells[registerno].a_dwell1_ov_time : dwells[registerno].b_dwell1_ov_time); - - sprintf(strbuf, " [%d] dwell 1 overvoltage time = %0.3f ms", registerno, value); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "DWL2AMPL")) - { - if (!readback) - { - setSingleVariable(&ch[chpair][registerno].a_dwell2_volts, &ch[chpair][registerno].b_dwell2_volts, MIN_VOLTAGE, MAX_VOLTAGE); - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - value = ((channelSide == 1) ? ch[chpair][registerno].a_dwell2_volts : ch[chpair][registerno].b_dwell2_volts); - - sprintf(strbuf, " [%d%c, %d] dwell 2 peak amplitude = %0.3f V", chpair, chsgl, registerno, value); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString,"DWL2")) - { - if (!readback) - { - // Set dwell 2 time - setSingleVariable(&dwells[registerno].a_dwell2_time, &dwells[registerno].b_dwell2_time, MIN_DWELL_TIME_MS, MAX_DWELL_TIME_MS); - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - value = ((channelSide == 1) ? dwells[registerno].a_dwell2_time : dwells[registerno].b_dwell2_time); - - sprintf(strbuf, " [%d] dwell 2 time = %0.3f ms", registerno, value); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "DWL2_OV")) - { - if (!readback) - { - setSingleVariable(&ch[chpair][registerno].a_dwell2_ov, &ch[chpair][registerno].b_dwell2_ov, MIN_VOLTAGE, MAX_VOLTAGE); - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - value = ((channelSide == 1) ? ch[chpair][registerno].a_dwell2_ov : ch[chpair][registerno].b_dwell2_ov); - - sprintf(strbuf, " [%d%c, %d] dwell 2 overvoltage = %0.3f V", chpair, chsgl, registerno, value); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "DWL2_OV_TIME")) - { - if (!readback) - { - // 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(strbuf, " Setting"); - sendSerial(strbuf); - } - - value = ((channelSide == 1) ? dwells[registerno].a_dwell2_ov_time : dwells[registerno].b_dwell2_ov_time); - - sprintf(strbuf, " [%d] dwell 2 overvoltage time = %0.3f ms", registerno, value); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "ENABLE")) - { - if (!readback) - { - ch[chpair][registerno].enabled = 1; - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString,"DISABLE")) - { - if (!readback) - { - ch[chpair][registerno].enabled = 0; - - sprintf(strbuf, " Setting"); - sendSerial(strbuf); - } - - sprintf(strbuf, " [%d, %d] enable = %d", chpair, registerno, ch[chpair][registerno].enabled); - sendSerial(strbuf); - return; - } - - if (strcmp(commandString, "")) - { - commandError = 1; - } -}*/ - - /************************************************************ * Routine: testMenu * Input: none @@ -1041,263 +637,33 @@ sendSerial(strbuf); return; } -/* - if (!strcmp(commandString, "VOLTS")) - { - ch = getival(SET); - getDelimiter(); - dac = getival(SET); - getDelimiter(); - fval = getfval(SET); - validateChannel(ch); - if (commandError) return; - ch--; - - if (dac == 1) - { - data = (unsigned int)(cal[ch].a_scale * fval + cal[ch].a_offset); - dac = ADC_CH1; - } - else - { - data = (unsigned int)(cal[ch].b_scale * fval + cal[ch].b_offset); - dac = ADC_CH2; - } - - 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, "BENB")) // board enable bits - { - ival = getival(SET); - setBoardEnables((unsigned int)ival); - sprintf(strbuf, " Board Enable Bits = 0x%04x\r\n", ival); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "BEN")) // board enable - { - ch = getival(SET); - getDelimiter(); - ival = getival(SET); - - validateChannel(ch); - if (commandError) return; - ch--; - - setBoardEnable(ch, (unsigned int)ival); - sprintf(strbuf, " Board Enable %d = %d\r\n", ch + 1, ival); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "LD")) - { - ival = getival(SET); - - if (ival) - { - tst_ld = 1; - } - else - { - tst_ld = 0; - } - - Delay(100); - ival = dtst_out; - sprintf(strbuf, " DTST_OUT = %d\r\n", ival); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "SCK")) - { - ival = getival(SET); - - if (ival) - { - sclk = 1; - } - else - { - sclk = 0; - } - - ival = dtst_out; - sprintf(strbuf, " DTST_OUT = %d\r\n", ival); - sendSerial(strbuf); - return; - } - - if (!strcmp(commandString, "FLASHDEMO")) // flash test - { - flashdemo(); - return; - } - - if (!strcmp(commandString, "HVGOOD")) - { - sprintf(strbuf, " HVCMP1: %i HVCMP2: %i", (int)hv_cmptr1, (int)hv_cmptr2); - sendSerial(strbuf); - return; - } -*/ if (strcmp(commandString, "")) { commandError = 1; } -} - -/************************************************************ -* Routine: setDwellTime -* Input: dwellType (enum) -* Returns: none -* Description: -* 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 }; - -void setDwellTime(int dwellType) -{ - char channelSideChar, setSingleChannel; - float fValue; - - if (readback) - { - if (dwellType == DWELL_1_OV_TIME) - { - 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 (running == 1) - { - sprintf(strbuf, " Parameters may not be updated while running!"); - sendSerial(strbuf); - } - else - { - // Find the next command string character - while (rxbuf[bufloc] == ' ' || rxbuf[bufloc] == '[' && rxbuf[bufloc] != 0x0D ){ bufloc++; } - - // Is the user setting a single channel or a channel pair? - channelSideChar = toupper(rxbuf[bufloc]); - setSingleChannel = ((channelSideChar == 'A') || (channelSideChar == 'B')); - - if (setSingleChannel) - { - chsgl = channelSideChar; - - // Skip over the channel side character - bufloc++; - - // Find the next command string character - while (rxbuf[bufloc] == ' ' || rxbuf[bufloc] == ',' && rxbuf[bufloc] != 0x0D ){ bufloc++; } - } - - // Back up because the current character should be the start of the register - // number but validateInt() is going to advance one character before calling - // atof() - bufloc--; +}//end void testMenu - if (!validateInt(SET, 1, MAX_REGISTERS, ®isterno)) - { - sprintf(strbuf, " Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(strbuf); - commandError = 1; - } - - if (!commandError) - { - // Adjust user values (1 - MAX) to 0 offset values (0 - (MAX - 1)) - registerno--; - - // Skip over the register number - while (isdigit(rxbuf[bufloc]) && rxbuf[bufloc] != 0x0D ){ bufloc++; } - - // Skip over white space and delimiters - while (rxbuf[bufloc] == ' ' || rxbuf[bufloc] == ',' && rxbuf[bufloc] != 0x0D ){ bufloc++; } - - // Back up because the current character should be the start of the value - // but validateEntry() is going to advance one character before calling - // atof() - bufloc--; - - // Read and validate the dwell time value - if (!validateEntry(SET, MIN_DWELL_TIME_MS, MAX_DWELL_TIME_MS, &fValue)) - { - sprintf(strbuf, " Invalid dwell time"); - sendSerial(strbuf); - commandError = 1; - } - } - - if (!commandError) - { - if (dwellType == DWELL_1_OV_TIME) - { - if ((!setSingleChannel) || (channelSideChar == 'A')) - { - dwells[registerno].a_dwell1_ov_time = fValue; - 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(strbuf, "\r\n Channel B Dwell 1 OV Time [%i] = %0.3f", registerno + 1, dwells[registerno].b_dwell1_ov_time); - sendSerial(strbuf); - } - } - - } - } -}*/ - - -// Clear the specified register -/* -void clearRegister(unsigned int reg) +unsigned int checkRegisterCompatibility(unsigned int reg) { int i; - - dwells[reg].a_dwell1_time = 0; - dwells[reg].a_dwell2_time = 0; - dwells[reg].a_dwell1_ov_time = 0; - dwells[reg].a_dwell2_ov_time = 0; - dwells[reg].b_dwell1_time = 0; - dwells[reg].b_dwell2_time = 0; - dwells[reg].b_dwell1_ov_time = 0; - dwells[reg].b_dwell2_ov_time = 0; + + unsigned int boardsEnabled = 0; for (i = 0; i < MAX_BOARDS; i++) { - ch[i][reg].enabled = 0; - ch[i][reg].installed = 0; - ch[i][reg].inverted = 0; - ch[i][reg].differential_dwell = 1; + //if (ch[i][reg].enabled == 1) + //{ + // Set the corresponding bit + boardsEnabled |= (1 << i); + //} + } + + // Invert the bits because 0 == enabled on the SPI write + boardsEnabled = ~boardsEnabled; - ch[i][reg].a_dwell1_volts = 0; - ch[i][reg].a_dwell2_volts = 0; - ch[i][reg].a_dwell1_ov = 0; - ch[i][reg].a_dwell2_ov = 0; - ch[i][reg].b_dwell1_volts = 0; - ch[i][reg].b_dwell2_volts = 0; - ch[i][reg].b_dwell1_ov = 0; - ch[i][reg].b_dwell2_ov = 0; - } -}*/ - + return (boardsEnabled ^ boardEnableBits) & 0x000003FF; +} /************************************************************ * Routine: doCommand @@ -1308,9 +674,7 @@ **************************************************************/ void doCommand(void) { - //int channelNum, channelSide, numPoints, i; int ival; - //char channelSideChar; unsigned int boardEnables; char commandString[80] = { 0 }; @@ -1404,12 +768,8 @@ } else if (!strcmp(commandString, "ALLOFF")) { - - //hv_en = 1; - //wr_out_code = setBoardEnables((unsigned int)ALLOFF); my12 = 0; running = FALSE; - //setBoardEnables((unsigned int *)alloff); if(DEBUG){ sprintf(strbuf, "wr_out_code=%d\r\n", wr_out_code); sendSerial(strbuf); @@ -1417,18 +777,8 @@ } else if (!strcmp(commandString, "ALLON")) { - //hv_en = 0; - //setBoardEnables((unsigned int *)allon); wr_out_code = setBoardEnables((unsigned int)ALLON); } - else if (!strcmp(commandString, "DWL1_OV_TIME")) - { - //setDwellTime(DWELL_1_OV_TIME); - } - else if (!strcmp(commandString, "DWL1_TIME")) - { - //setDwellTime(DWELL_1_TIME); - } else if (!strcmp(commandString, "RUN")) { // Skip over any white space and the optional '[' character @@ -1451,9 +801,6 @@ if (running == 0) { - //setDacsToZeroVolts(); - //Delay(1000); - //wait(0.5); boardsActive = ival; startConverter(boardsActive); } @@ -1486,49 +833,6 @@ stopConverter(); //hv_en = OFF; } -/* else if (!strcmp(commandString, "CLEAR")) - { - if (running == 1) - { - sprintf(strbuf, " Parameters may not be updated while running!"); - sendSerial(strbuf); - commandError = 1; - } - else if (!validateInt(SET, 0, MAX_REGISTERS, ®isterno)) - { - sprintf(strbuf, " Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(strbuf); - commandError = 1; - } - - if (!commandError) - { - if (registerno == 0) - { - frequency = 1000; - - clearRegister(0); - clearRegister(1); - clearRegister(2); - clearRegister(3); - - initCalParameters(); - - sprintf(strbuf, " All parameters reset to default values"); - sendSerial(strbuf); - } - else - { - // Adjust user values (1 - MAX) to 0 offset values (0 - (MAX - 1)) - registerno--; - - clearRegister(registerno); - - sprintf(strbuf, " [x, %d] voltages are 0", registerno); - sendSerial(strbuf); - } - } - }*/ else if(!strcmp(commandString, "TEST")) { if (running == 1) @@ -1541,43 +845,6 @@ testMenu(); } } -/* else if(!strcmp(commandString, "READ")) - { - if (!validateInt(SET, 1, MAX_REGISTERS, ®isterno)) - { - sprintf(strbuf, " Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(strbuf); - commandError = 1; - } - - if (!commandError) - { - // Adjust user values (1 - MAX) to 0 offset values (0 - (MAX - 1)) - registerno--; - - 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(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")) { if (running == 1) @@ -1586,12 +853,7 @@ sendSerial(strbuf); commandError = 1; } - /*else if (!validateInt(SET, 1, MAX_BOARDS, &channelNum)) - { - sprintf(strbuf, " Invalid board number (1 - %d)", MAX_BOARDS); - sendSerial(strbuf); - commandError = 1; - }*/ + if (!commandError){ raw = TRUE; menuRedraw(NO_PROMPT); @@ -1605,243 +867,12 @@ sendSerial(strbuf); commandError = 1; } - /*else if (!validateInt(SET, 1, MAX_BOARDS, &channelNum)) - { - sprintf(strbuf, " Invalid board number (1 - %d)", MAX_BOARDS); - sendSerial(strbuf); - commandError = 1; - }*/ + if (!commandError){ raw = FALSE; menuRedraw(NO_PROMPT); } } - /* - if (!commandError) - { - // Adjust user values (1 - MAX) to 0 offset values (0 - (MAX - 1)) - channelNum--; - - // Skip over digits parsed as part of the atoi() call - while (isdigit(rxbuf[bufloc])) bufloc++; - - // Does the user simply want to read the current cal parameters? - if (rxbuf[bufloc] == '?') - { - 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; - } - - // First character after digits must be either 'A' or 'B' - channelSideChar = toupper(rxbuf[bufloc]); - - if ((channelSideChar != 'A') && (channelSideChar != 'B')) - { - sprintf(strbuf, " Invalid channel (A/B)"); - sendSerial(strbuf); - commandError = 1; - } - } - - if (!commandError) - { - // Translate 'A' to CHAN1 and 'B' to CHAN2 - channelSide = (channelSideChar == 'A' ? 1 : 2); - - // Move past the channel side character - bufloc++; - - // Does the user simply want to read the current cal parameters? - if (rxbuf[bufloc] == '?') - { - if (channelSide == 1) - { - sprintf(strbuf, "\r\nChannel %dA Scale = %0.4f Offset = %0.4f", channelNum, cal[channelNum].a_scale, cal[channelNum].a_offset); - sendSerial(strbuf); - } - else - { - sprintf(strbuf, "\r\nChannel %dB Scale = %0.4f Offset = %0.4f", channelNum, cal[channelNum].b_scale, cal[channelNum].b_offset); - sendSerial(strbuf); - } - - sendCRLF(); - return; - } - - // If no point value specified, silently default to 3-point cal - if (!strcmp(&rxbuf[bufloc], "")) - { - numPoints = 3; - } - else if (!validateInt(SET, 3, 11, &numPoints)) - { - sprintf(strbuf, " Invalid number of cal points (3 - 11)"); - sendSerial(strbuf); - commandError = 1; - } - } - - if (!commandError) - { - 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; - rxbuf[bufloc] = 0; - - calibrate(channelNum, channelSide, numPoints); - } - } - else if (!strcmp(commandString, "COMMIT")) - { - commitParametersToFlash(); - } - else if (!strcmp(commandString, "CHLPR")) - { - if (readback) - { - sprintf(strbuf, " [%i, %i]", chpair, registerno); - sendSerial(strbuf); - } - else if (running == 1) - { - sprintf(strbuf, " Parameters may not be updated while running!"); - sendSerial(strbuf); - } - else - { - if (!validateInt(SET, 1, MAX_BOARDS, &chpair)) - { - sprintf(strbuf, "Invalid board number (1 - %d)", MAX_BOARDS); - sendSerial(strbuf); - commandError = 1; - } - - if (!commandError) - { - getDelimiter(); - - if (!validateInt(SET, 1, MAX_REGISTERS, ®isterno)) - { - sprintf(strbuf, "Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(strbuf); - commandError = 1; - } - } - - if (!commandError) - { - // Adjust user values (1 - MAX) to 0 offset values (0 - (MAX - 1)) - chpair--; - registerno--; - - // ignore spaces - while ((rxbuf[bufloc++] == ' ') && (rxbuf[bufloc] != 0x0D) && (rxbuf[bufloc] != 0) && (rxbuf[bufloc] != ';')); - - if (rxbuf[bufloc] == 0 || rxbuf[bufloc] == 0x0D) - { - commandError = 1; - } - else - { - while((rxbuf[bufloc++] != ' ') && (rxbuf[bufloc] != 0x0D) && (rxbuf[bufloc] != 0) && (rxbuf[bufloc] == ';') ); - - if (rxbuf[bufloc] == 0 || rxbuf[bufloc] == 0x0D) - { - commandError = 1; - } - else - { - chlprMenu(); - } - } - } - } - } - else if (!strcmp(commandString, "CHLSGL")) - { - if (readback) - { - sprintf(strbuf, " [%i%c, %i]", chpair, chsgl, registerno); - sendSerial(strbuf); - } - else if (running == 1) - { - sprintf(strbuf, " Parameters may not be updated while running!"); - sendSerial(strbuf); - } - else - { - if (!validateInt(SET, 1, MAX_BOARDS, &chpair)) - { - sprintf(strbuf, "Invalid board number (1 - %d)", MAX_BOARDS); - sendSerial(strbuf); - commandError = 1; - } - - if (!commandError) - { - while(rxbuf[bufloc] == ' ' || rxbuf[bufloc] == '[' || isdigit(rxbuf[bufloc]) && rxbuf[bufloc] != 0x0D ){ bufloc++; } - - channelSideChar = toupper(rxbuf[bufloc]); - - if ((channelSideChar != 'A') && (channelSideChar != 'B')) - { - sprintf(strbuf, "Invalid channel (A/B)"); - sendSerial(strbuf); - commandError = 1; - } - - if (!commandError) - { - chsgl = channelSideChar; - getDelimiter(); - - if (!validateInt(SET, 1, MAX_REGISTERS, ®isterno)) - { - sprintf(strbuf, "Invalid register number (1 - %d)", MAX_REGISTERS); - sendSerial(strbuf); - commandError = 1; - } - } - - if (!commandError) - { - // Adjust user values (1 - MAX) to 0 offset values (0 - (MAX - 1)) - chpair--; - registerno--; - - // ignore spaces - while ((rxbuf[bufloc++] == ' ') && (rxbuf[bufloc] != 0x0D) && (rxbuf[bufloc] != 0) && (rxbuf[bufloc] == ';')); - - if (rxbuf[bufloc] == 0 || rxbuf[bufloc] == 0x0D) - { - commandError = 1; - } - } - - if (!commandError) - { - while ((rxbuf[bufloc++] != ' ') && (rxbuf[bufloc] != 0x0D) && (rxbuf[bufloc] != 0) && (rxbuf[bufloc] == ';')); - - if (rxbuf[bufloc] == 0 || rxbuf[bufloc] == 0x0D) - { - commandError = 1; - } - else - { - chlsglMenu(); - } - } - } - } - }*/ else { if (strcmp(commandString, "")) @@ -1903,3 +934,8 @@ return FALSE; } + +// Verify that the same boards are enabled in both the current register and +// the specified register + +