LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
Macros | Functions | Variables
usartcmd.c File Reference

Handles commands from the Host Interface. More...

Include dependency graph for usartcmd.c:

Macros

#define MAXPARAMS   5
 

Functions

static int8_t CmdAnalog (void)
 Set the analog instrument to a certain position. More...
 
static int8_t CmdCalibrate (void)
 Calibrates the Voltage Sensors. More...
 
static int8_t CmdClearErrors (void)
 Clears Error Flags and Counters. More...
 
static int8_t CmdDebug (void)
 Sets Debug Options. More...
 
static int8_t CmdDistance (void)
 Continuously prints the Sensor Distance Value. More...
 
static int8_t CmdDumpConf (void)
 Prints the Configuration Memory in a human readable form. More...
 
static int8_t CmdFTest (void)
 Performs a Factory Test. More...
 
static int8_t CmdGetSensorValues (void)
 Retrieves the Sensor Values. More...
 
static int8_t CmdHelp (void)
 Lists a Description of all Commands. More...
 
static int8_t CmdReset (void)
 Causes a Watchdog Reset. Useful for Debugging. More...
 
static int8_t CmdSetBright (void)
 Sets the Brightness of the LCD Backlight. More...
 
static int8_t CmdSetCistern (void)
 Sets the Cistern Metrics. More...
 
static int8_t CmdSetContrast (void)
 Sets the Contrast of the LCD Backlight. More...
 
static int8_t CmdSetDCFInv (void)
 Sets the DCF-Pin logic. More...
 
static int8_t CmdSetDisplay (void)
 Sets the Display type. More...
 
static int8_t CmdSetOcr (void)
 Sets the OCR1CL to an absolute Value. More...
 
static int8_t CmdSetPTime (void)
 Sets the Delay for automatic Display stepping. More...
 
static int8_t CmdSetPTimeK (void)
 Sets the Delay for switchback from manual to automatic Display stepping. More...
 
static int8_t CmdSetSignal (void)
 Sets the Thresholds for a Signaling Output. More...
 
static int8_t CmdSetSounds (void)
 Sets the Sounds-OK-Time and Soundmask. More...
 
static int8_t CmdSetSpontaneous (void)
 Sets Spontaneous Volume Reporting. More...
 
static int8_t CmdSetTime (void)
 Sets the Time. More...
 
static int8_t CmdStat (void)
 Prints Values of System Sensors... More...
 
static int8_t CmdUpdateSensorFirmware (void)
 Updates the Sensor Firmware. More...
 
static int8_t CmdUseRts (void)
 Sets if to use RTS/CTS-Handshake. More...
 
static int8_t CmdVerifySensorFirmware (void)
 Verifies the Sensor Firmware against an Intel-HEX-File. More...
 
static int8_t CmdWrite (void)
 Writes the Configuration to the EEPROM. More...
 
static double EnterDouble (void)
 Receives a Double from the Host. More...
 
uint8_t ExecCommand (char *str)
 Executes one command line. More...
 
static void ExtraIgnored (uint8_t n)
 Prints error message about superfluous parameters. More...
 
static void MissingArg (void)
 Prints error message about missing arguments. More...
 

Variables

static char * cmd
 
static const commandTable_t commandTable []
 
static const char helpCalibrate []
 
static const char helpClearErrors [] = "Clear error flags and counters"
 
static const char helpDCFinv [] = "Sets DCF77-pin polarity"
 
static const char helpDebug [] = "Change debug settings"
 
static const char helpDistance [] = "Continuously prints sensor distance value until you press a key"
 
static const char helpDumpConf [] = "Prints a human readable list of configuration data"
 
static const char helpFTest [] = "Executes the factory test"
 
static const char helpGetSensorValues [] = "Gets sensor measurement values"
 
static const char helpHelp [] = "This list of commands"
 
static const char helpReset [] = "Restarts the device"
 
static const char helpSetBright [] = "Sets backlight brightness, absolute or relative (e.g. 50, +10 -10)"
 
static const char helpSetCistern [] = "Sets the cistern metrics"
 
static const char helpSetContr [] = "Sets LCD contrast, absolute or relative (e.g. 25, +5 -5)"
 
static const char helpSetDisplay [] = "Sets the display type (4x20, 2x16 or analog)"
 
static const char helpSetPTime [] = "Sets the delay for automatic display stepping (0 means no automatic stepping)"
 
static const char helpSetPTimeK [] = "Sets the delay for switchback from manual to automatic stepping"
 
static const char helpSetSignal [] = "Sets the thresholds for signaling outputs"
 
static const char helpSetSounds [] = "Sets the Sounds-OK-Time and Soundmask. E.g. SetSounds 9 18 0"
 
static const char helpSetSpontaneous [] = "Sets Volume difference for spontaneous reporting (0=Off)"
 
static const char helpSetTime [] = "Sets the time. E.g. SetTime 18:35"
 
static const char helpStatus [] = "Prints current status"
 
static const char helpUpdate [] = "Updates sensor firmware"
 
static const char helpUseRts [] = "Use RTS/CTS-handshake for serial communication"
 
static const char helpVerify [] = "Verifies sensor firmware"
 
static const char helpWrite [] = "Writes configuration to non-volatile memory.\n\n*** Execute Write after any changes in configuration\n or your changes will get lost at next reset! ***\n\n"
 
static uint8_t nParams
 
static char * params [MAXPARAMS]
 
static const char helpCalibrate [] PROGMEM = "Calibrates the voltage sensors"
 

Detailed Description

Handles commands from the Host Interface.

Handles commands from the serial interface

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Macro Definition Documentation

◆ MAXPARAMS

#define MAXPARAMS   5

Function Documentation

◆ CmdAnalog()

static int8_t CmdAnalog ( void  )
static

Set the analog instrument to a certain position.

This command is only useful for debugging if no other part of the software is setting the value!

References ExtraIgnored(), hprintf_P(), MissingArg(), nParams, params, and SetAnalogPerCent().

Here is the call graph for this function:

◆ CmdCalibrate()

static int8_t CmdCalibrate ( void  )
static

Calibrates the Voltage Sensors.

Normal operation is halted during the calibration so the RTC will be late afterwards.
The user is prompted to enter the voltages from which the real Volts per LSB for each channel is calculated.

Note
The JTAGEN-fuse has to be disabled for an accurate Value of P3 and no JTAG debugger must be connected else you would end up in heavy miscalibration of the P3-value!
Returns
0 on success, -1 on error.

References ADCData_t::ADC_P3, ADCData_t::ADC_P5, ADCData_t::ADC_SWUnreg, ADCData_t::ADC_Unreg, ADCDataAvg, AssertRTS(), byteFromHost, CFLAG_BYTERECEIVED, cFlags, config, configDirty, delay10ms(), EnterDouble(), hprintf_P(), InitADC(), confStruct_t::instCal, LCDClear(), LCDSetBrightness(), ADCData_t::named, confStruct_t::P3VoltsPerLSB, confStruct_t::P5VoltsPerLSB, SensorPowerOff(), SensorPowerOn(), SetAnalogPerCent(), confStruct_t::SWUnregVoltsPerLSB, confStruct_t::UnregVoltsPerLSB, and usart1FlushRx().

Here is the call graph for this function:

◆ CmdClearErrors()

static int8_t CmdClearErrors ( void  )
static

Clears Error Flags and Counters.

Resets watchdog and brownout reset counters and the error flags in the display.

Returns
always 0

References boCnt, ExtraIgnored(), hprintf_P(), nParams, ResetDisplayFlags(), and wdrCnt.

Here is the call graph for this function:

◆ CmdDebug()

static int8_t CmdDebug ( void  )
static

Sets Debug Options.

Possible parameters are dcf and sensor. Adding a parameter switches debug output on, omitting it off. So debug without parameters completely disables debugging output.

Note
Be careful using debug output especially for DCF77. This includes calling interrupt serviced routines (UART) from an interrupt and may lock up if the transmit buffer is filled (e.g. by auxiliary communication) since in ATMega-architecture interrupts and non-interruptible!
Returns
0

References DFLAG_ADC, DFLAG_DCF77, DFLAG_SENSOR, dFlags, hprintf_P(), nParams, and params.

Here is the call graph for this function:

◆ CmdDistance()

static int8_t CmdDistance ( void  )
static

Continuously prints the Sensor Distance Value.

This command terminates if you press any key on the console. Mostly used for debugging and sensor installation.

Note
Normal operation is suspended while this command is running.
Returns
Always 0

References AssertRTS(), CFLAG_BYTERECEIVED, CFLAG_TIMERECEIVED, cFlags, displayValues, distance, hprintf_P(), hrCnt, LitersFromDist(), displayValues_t::literUnitChar, minCnt, pulseTime, pulseTimeInt, pulseTimeMult, secCnt, SensorPowerOff(), SensorPowerOn(), and speedOfSound.

Here is the call graph for this function:

◆ CmdDumpConf()

static int8_t CmdDumpConf ( void  )
static

Prints the Configuration Memory in a human readable form.

Returns
always 0

References DumpConfig(), ExtraIgnored(), hprintf_P(), and nParams.

Here is the call graph for this function:

◆ CmdFTest()

static int8_t CmdFTest ( void  )
static

Performs a Factory Test.

Returns
This function does not return. It ends with a device reset.

References CmdReset(), FTest(), and hprintf_P().

Here is the call graph for this function:

◆ CmdGetSensorValues()

static int8_t CmdGetSensorValues ( void  )
static

Retrieves the Sensor Values.

Measured volume and temperature inside the cistern.

Returns
always 0

References displayValues, ExtraIgnored(), hprintf_P(), displayValues_t::liters, displayValues_t::literUnitChar, nParams, and displayValues_t::tempSemi.

Here is the call graph for this function:

◆ CmdHelp()

static int8_t CmdHelp ( void  )
static

Lists a Description of all Commands.

References cmd, commandTable, ExtraIgnored(), hprintf_P(), and nParams.

Here is the call graph for this function:

◆ CmdReset()

static int8_t CmdReset ( void  )
static

Causes a Watchdog Reset. Useful for Debugging.

Note
The Display will show watchdog resets after this command. Use a clean power up or a "ClearErrors" to get rid of these.
Returns
This function does not return.

References hprintf_P().

Referenced by CmdFTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CmdSetBright()

static int8_t CmdSetBright ( void  )
static

Sets the Brightness of the LCD Backlight.

If the brightness is a pure number, it is treated as an absolute value, a preceding '+' or '-' increases or decreases the brightness for the specified value.

Returns
0 on success, -1 on error.

References config, configDirty, ExtraIgnored(), hprintf_P(), confStruct_t::LCDBright, LCDGetBrightness(), LCDSetBrightness(), MissingArg(), nParams, and params.

Here is the call graph for this function:

◆ CmdSetCistern()

static int8_t CmdSetCistern ( void  )
static

◆ CmdSetContrast()

static int8_t CmdSetContrast ( void  )
static

Sets the Contrast of the LCD Backlight.

If the contrast is a pure number, it is treated as an absolute value, a preceding '+' or '-' increases or decreases the contrast for the specified value.

Returns
0 on success, -1 on error.

References config, configDirty, ExtraIgnored(), hprintf_P(), confStruct_t::LCDBright, LCDGetContrast(), LCDSetContrast(), MissingArg(), nParams, and params.

Here is the call graph for this function:

◆ CmdSetDCFInv()

static int8_t CmdSetDCFInv ( void  )
static

Sets the DCF-Pin logic.

Returns
0 on success, -1 on error.

References config, configDirty, DCF77_PINMASK, hprintf_P(), confStruct_t::invDCF77, MissingArg(), nParams, and params.

Here is the call graph for this function:

◆ CmdSetDisplay()

static int8_t CmdSetDisplay ( void  )
static

Sets the Display type.

Returns
0 on success, -1 on error.

References config, configDirty, DISPLAY_2x16, DISPLAY_4x20, DISPLAY_ANALOG, confStruct_t::displayType, ExtraIgnored(), hprintf_P(), LCDClear(), MissingArg(), nParams, and params.

Here is the call graph for this function:

◆ CmdSetOcr()

static int8_t CmdSetOcr ( void  )
static

Sets the OCR1CL to an absolute Value.

This command is only useful for debugging if no other part of the software is setting the value!

Returns
Always 0

References ExtraIgnored(), hprintf_P(), MissingArg(), nParams, and params.

Here is the call graph for this function:

◆ CmdSetPTime()

static int8_t CmdSetPTime ( void  )
static

Sets the Delay for automatic Display stepping.

Returns
0 on success, -1 on error.

References config, configDirty, ExtraIgnored(), hprintf_P(), MissingArg(), nParams, confStruct_t::pageTime, and params.

Here is the call graph for this function:

◆ CmdSetPTimeK()

static int8_t CmdSetPTimeK ( void  )
static

Sets the Delay for switchback from manual to automatic Display stepping.

Returns
0 on success, -1 on error.

References config, configDirty, ExtraIgnored(), hprintf_P(), MissingArg(), nParams, confStruct_t::pageTime, confStruct_t::pageTimeK, and params.

Here is the call graph for this function:

◆ CmdSetSignal()

static int8_t CmdSetSignal ( void  )
static

Sets the Thresholds for a Signaling Output.

Returns
0 on success, -1 on error.

References signalOutput_t::activeAbove, signalOutput_t::activeBelow, config, configDirty, DumpConfigSignal(), ExtraIgnored(), hprintf_P(), MissingArg(), nParams, params, and confStruct_t::signalOutputs.

Here is the call graph for this function:

◆ CmdSetSounds()

static int8_t CmdSetSounds ( void  )
static

Sets the Sounds-OK-Time and Soundmask.

Returns
0 on success, -1 on error.

References config, configDirty, ExtraIgnored(), hprintf_P(), MissingArg(), nParams, params, and confStruct_t::sndMask.

Here is the call graph for this function:

◆ CmdSetSpontaneous()

static int8_t CmdSetSpontaneous ( void  )
static

Sets Spontaneous Volume Reporting.

Returns
0 on success, -1 on error.

References config, configDirty, ExtraIgnored(), hprintf_P(), MissingArg(), nParams, params, and confStruct_t::spontaneousReportVolume.

Here is the call graph for this function:

◆ CmdSetTime()

static int8_t CmdSetTime ( void  )
static

Sets the Time.

Returns
0 on success, -1 on error.

References DCFInSync, ExtraIgnored(), hprintf_P(), hrCnt, min, minCnt, MissingArg(), nParams, params, and secCnt.

Here is the call graph for this function:

◆ CmdStat()

static int8_t CmdStat ( void  )
static

◆ CmdUpdateSensorFirmware()

static int8_t CmdUpdateSensorFirmware ( void  )
static

Updates the Sensor Firmware.

The User is asked to send the Intel HEX file which is then sent to the sensor.

Returns
0

References ExtraIgnored(), nParams, and UpdateSensorFirmware().

Here is the call graph for this function:

◆ CmdUseRts()

static int8_t CmdUseRts ( void  )
static

Sets if to use RTS/CTS-Handshake.

Returns
0 if OK, -1 on error

References config, configDirty, hprintf_P(), MissingArg(), nParams, params, and confStruct_t::useRts.

Here is the call graph for this function:

◆ CmdVerifySensorFirmware()

static int8_t CmdVerifySensorFirmware ( void  )
static

Verifies the Sensor Firmware against an Intel-HEX-File.

The User is asked to send the Intel HEX file which is then verified against the sensor firmware.

Returns
0

References ExtraIgnored(), nParams, and VerifySensorFirmware().

Here is the call graph for this function:

◆ CmdWrite()

static int8_t CmdWrite ( void  )
static

Writes the Configuration to the EEPROM.

Returns
0 on success, -1 on error.

References configDirty, ExtraIgnored(), hprintf_P(), nParams, and WriteConfig().

Here is the call graph for this function:

◆ EnterDouble()

static double EnterDouble ( void  )
static

Receives a Double from the Host.

Returns
The Value

References ADCData_t::ADC_P3, ADCData_t::ADC_P5, ADCData_t::ADC_SWUnreg, ADCData_t::ADC_Unreg, ADCDataAvg, ADCFLAG_NEWAVERAGES, adcFlags, AssertRTS(), CFLAG_CMDRECEIVED, cFlags, cmdline, config, DISPLAY_4x20, confStruct_t::displayType, LCDGoTo(), ADCData_t::named, P3FromADC(), P5FromADC(), SWUnregFromADC(), and UnregFromADC().

Referenced by CmdCalibrate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExecCommand()

uint8_t ExecCommand ( char *  str)

Executes one command line.

Parameters
strA pointer to the line
Returns
0 on success, 1 on error

References commandTable_t::adr, cmd, commandTable, configDirty, hprintf_P(), nParams, and params.

Referenced by DoCflags().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExtraIgnored()

static void ExtraIgnored ( uint8_t  n)
static

Prints error message about superfluous parameters.

Parameters
nThe number of extra parameters

References cmd, and hprintf_P().

Referenced by CmdAnalog(), CmdClearErrors(), CmdDumpConf(), CmdGetSensorValues(), CmdHelp(), CmdSetBright(), CmdSetCistern(), CmdSetContrast(), CmdSetDisplay(), CmdSetOcr(), CmdSetPTime(), CmdSetPTimeK(), CmdSetSignal(), CmdSetSounds(), CmdSetSpontaneous(), CmdSetTime(), CmdStat(), CmdUpdateSensorFirmware(), CmdVerifySensorFirmware(), and CmdWrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MissingArg()

static void MissingArg ( void  )
static

Prints error message about missing arguments.

References cmd, and hprintf_P().

Referenced by CmdAnalog(), CmdSetBright(), CmdSetCistern(), CmdSetContrast(), CmdSetDCFInv(), CmdSetDisplay(), CmdSetOcr(), CmdSetPTime(), CmdSetPTimeK(), CmdSetSignal(), CmdSetSounds(), CmdSetSpontaneous(), CmdSetTime(), and CmdUseRts().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cmd

char* cmd
static

◆ commandTable

const commandTable_t commandTable[]
static

Referenced by CmdHelp(), and ExecCommand().

◆ helpCalibrate

const char helpCalibrate[]
static

◆ helpClearErrors

static const char helpClearErrors = "Clear error flags and counters"
static

◆ helpDCFinv

static const char helpDCFinv = "Sets DCF77-pin polarity"
static

◆ helpDebug

static const char helpDebug = "Change debug settings"
static

◆ helpDistance

static const char helpDistance = "Continuously prints sensor distance value until you press a key"
static

◆ helpDumpConf

static const char helpDumpConf = "Prints a human readable list of configuration data"
static

◆ helpFTest

static const char helpFTest = "Executes the factory test"
static

◆ helpGetSensorValues

static const char helpGetSensorValues = "Gets sensor measurement values"
static

◆ helpHelp

static const char helpHelp = "This list of commands"
static

◆ helpReset

static const char helpReset = "Restarts the device"
static

◆ helpSetBright

static const char helpSetBright = "Sets backlight brightness, absolute or relative (e.g. 50, +10 -10)"
static

◆ helpSetCistern

static const char helpSetCistern = "Sets the cistern metrics"
static

◆ helpSetContr

static const char helpSetContr = "Sets LCD contrast, absolute or relative (e.g. 25, +5 -5)"
static

◆ helpSetDisplay

static const char helpSetDisplay = "Sets the display type (4x20, 2x16 or analog)"
static

◆ helpSetPTime

static const char helpSetPTime = "Sets the delay for automatic display stepping (0 means no automatic stepping)"
static

◆ helpSetPTimeK

static const char helpSetPTimeK = "Sets the delay for switchback from manual to automatic stepping"
static

◆ helpSetSignal

static const char helpSetSignal = "Sets the thresholds for signaling outputs"
static

◆ helpSetSounds

static const char helpSetSounds = "Sets the Sounds-OK-Time and Soundmask. E.g. SetSounds 9 18 0"
static

◆ helpSetSpontaneous

static const char helpSetSpontaneous = "Sets Volume difference for spontaneous reporting (0=Off)"
static

◆ helpSetTime

static const char helpSetTime = "Sets the time. E.g. SetTime 18:35"
static

◆ helpStatus

static const char helpStatus = "Prints current status"
static

◆ helpUpdate

static const char helpUpdate = "Updates sensor firmware"
static

◆ helpUseRts

static const char helpUseRts = "Use RTS/CTS-handshake for serial communication"
static

◆ helpVerify

static const char helpVerify = "Verifies sensor firmware"
static

◆ helpWrite

static const char helpWrite = "Writes configuration to non-volatile memory.\n\n*** Execute Write after any changes in configuration\n or your changes will get lost at next reset! ***\n\n"
static

◆ nParams

uint8_t nParams
static

◆ params

char* params[MAXPARAMS]
static

◆ PROGMEM

const char helpWrite [] PROGMEM = "Calibrates the voltage sensors"
static