From fcde099aa977b3d6a7419bc95662d3c66df89fdd Mon Sep 17 00:00:00 2001 From: Matthew Clark Date: Thu, 9 Nov 2023 13:42:04 -0600 Subject: [PATCH] Major improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Serial communications are now MUCH faster! - The original method induced a 1-second delay after every command; now, after a command is sent, it awaits a response of either “Done” or “Error” so that it can return instantly. - Now that sending commands involves checking for a “Done” or “Error” response, all configuration methods now return boolean to indicate whether the change was successful. - Reading presence status via serial is now almost as fast as `digitalRead()` New methods: - `configBegin()` and `configEnd()` allow you to make multiple configuration changes with only a single call to `stop()`, `saveConfig()` and `start()` - `setTriggerLatency()` allows you to configure delays on confirmation (amount of time that continuous presence activity must be detected before asserting a presence state) and disappearance (amount of time that must not contain any presence activity before deasserting a presence state). - `begin()` doesn’t currently do anything, but reserved for future use. Removed methods related to auto-start since there’s not a straightforward way to determine whether the sensor is running. Factory default is for the sensor to automatically start on power-up, so it’s safer to operate around that assumption. I may restore these methods at a later date, especially if I decide on what `begin()` will do. --- .../Basic-DigitalTrigger.ino | 3 +- .../Basic-SoftwareSerial.ino | 5 +- examples/Basic/Basic.ino | 5 +- src/DFR_Radar.cpp | 345 +++++++++++++----- src/DFR_Radar.h | 176 +++++---- 5 files changed, 365 insertions(+), 169 deletions(-) diff --git a/examples/Basic-DigitalTrigger/Basic-DigitalTrigger.ino b/examples/Basic-DigitalTrigger/Basic-DigitalTrigger.ino index 89130f6..97c0d71 100644 --- a/examples/Basic-DigitalTrigger/Basic-DigitalTrigger.ino +++ b/examples/Basic-DigitalTrigger/Basic-DigitalTrigger.ino @@ -4,7 +4,8 @@ * This is a basic example of how to instantiate a DFR_Radar object using * the second UART available on most Arduino boards. This example is almost * identical to the Basic.ino, except this one uses a digital input to check - * for presence triggering instead of querying over serial -- much faster! + * for presence triggering instead of querying over serial, which could be + * somewhat faster. * * The detection area and sensitivity are set quite low to make it easier * to test the unit right in front of you (too high and it'll just stay diff --git a/examples/Basic-SoftwareSerial/Basic-SoftwareSerial.ino b/examples/Basic-SoftwareSerial/Basic-SoftwareSerial.ino index e2f3fe8..83de4fd 100644 --- a/examples/Basic-SoftwareSerial/Basic-SoftwareSerial.ino +++ b/examples/Basic-SoftwareSerial/Basic-SoftwareSerial.ino @@ -73,10 +73,7 @@ void loop() * be missed. */ - // Query the presence detection status -- this is - // kind of slow since it communicates via serial. - // This can slow your loop down up to 100ms per - // iteration or more. + // Query the presence detection status bool presence = sensor.checkPresence(); // If presence == true, turn on the built-in LED. diff --git a/examples/Basic/Basic.ino b/examples/Basic/Basic.ino index 1d9b646..660fbc5 100644 --- a/examples/Basic/Basic.ino +++ b/examples/Basic/Basic.ino @@ -57,10 +57,7 @@ void loop() * be missed. */ - // Query the presence detection status -- this is - // kind of slow since it communicates via serial. - // This can slow your loop down up to 100ms per - // iteration or more. + // Query the presence detection status bool presence = sensor.checkPresence(); // If presence == true, turn on the built-in LED. diff --git a/src/DFR_Radar.cpp b/src/DFR_Radar.cpp index e53fa22..6ef324b 100644 --- a/src/DFR_Radar.cpp +++ b/src/DFR_Radar.cpp @@ -17,57 +17,136 @@ DFR_Radar::DFR_Radar( Stream *s ) { sensorUART = s; + // isConfigured = false; + stopped = false; + multiConfig = false; } -size_t DFR_Radar::readBytes( char *buffer, size_t length ) +bool DFR_Radar::begin() { - size_t offset = 0, remaining = length; - unsigned long startTime = millis(); + /* Not sure if I want to impliment this, keeping it for future consideration... + + unsigned long startTime = millis() + startupDelay; + + // Give the sensor time to start up just in case this method is called too soon. + // + // There's probably a smarter way to do this. Factory default configuration will + // have the sensor dumping out $JYBSS messages once per second, so that could be + // an easy way to tell that it's "ready". But if the sensor is configured to send + // these only when queried, or when an presence event occurs, or if the interval + // is set too long, then this won't really work. + // + // Another way might be to send a `sensorStart` and see if 1) it complains about + // not being ready, or 2) it responds with "sensor started already" and "Error", + // or 3) actually starts? + + while( millis() < startTime ) + yield(); + + if( !stop() ) + return false; - while( remaining ) - { - if( sensorUART->available() ) - { - buffer[offset] = sensorUART->read(); - offset++; - remaining--; - } - - if( millis() - startTime > readBytesTimeout ) - break; - } + // Disable command echoing (less response data that we have to parse through) + sendCommand( comSetEcho ); + + // Disable periodic $JYBSS messages (we will query for them) + sendCommand( comSetUartOutput ); + + if( !saveConfig() ) + return false; + + if( !start() ) + return false; + + isConfigured = true; + + */ - return offset; + return true; } -bool DFR_Radar::readPacket( char *buffer ) +size_t DFR_Radar::readLines( char *buffer, size_t lineCount ) { - unsigned long startTime = millis(); - bool result = false; + unsigned long timeLimit = millis() + readPacketTimeout; + size_t offset = 0, linesLeft = lineCount; - while( !result ) + while( linesLeft && millis() < timeLimit ) { - if( millis() - startTime > readPacketTimeout ) - break; + if( sensorUART->available() <= 0 ) + continue; - if( readBytes( buffer, packetLength ) == packetLength ) - if( strncmp( packetStart, buffer, strlen( packetStart ) ) == 0 ) - result = true; - } + char c = sensorUART->read(); - buffer[packetLength] = '\0'; + if( c == '\r' ) + continue; + + buffer[offset++] = c; + + if( c == '\n' ) + linesLeft--; + } - return result; + return strlen( buffer ); } bool DFR_Radar::checkPresence() { - char data[packetLength] = {0}; + char packet[packetLength] = {0}; + + // Factory default settings have $JYBSS messages sent once per second, + // but we won't want to wait; this will prompt for status immediately + sensorUART->write( comGetOutput ); + + /** + * Get the response immediately after sending the command. + * + * If command echoing is enabled, there should be three lines: + * 1. the "getOutput 1" echoed back + * 2. a "Done" status + * 3. the "leapMMW:/>" response followed by the $JYBSS data we want + * + * If command echoing is disabled, there should be two lines: + * 1. a "Done" status + * 2. the $JYBSS data we want + * + * Factory default is command echoing on (might change this in `begin()`) + */ + size_t length = readLines( packet, 3 ); + + if( !length ) + return false; + + const size_t expectedLength = 16; + char data[expectedLength] = {0}; + uint8_t offset = 0; + bool startCharacterFound = false, endCharacterFound = false; + + /** + * Parse through the packet until we find a "$", and + * then start capturing characters until we find a "*" + * + * We're expecting to get something like: $JYBSS,1, , , * + */ + for( uint8_t i = 0; i < length; i++ ) + { + char c = packet[i]; + + if( c == '$' ) + startCharacterFound = true; + + if( !startCharacterFound ) + continue; + + if( c == '*' ) + endCharacterFound = true; - // Should contain something like this: $JYBSS,1, , , * - // ...with parameter 1 (character 7) being either 0 or 1. + data[offset++] = c; - if( !readPacket( data ) ) + if( endCharacterFound || offset == expectedLength ) + break; + } + + if( !startCharacterFound || !endCharacterFound ) return false; return ( data[7] == '1' ); @@ -81,9 +160,7 @@ bool DFR_Radar::setLockout( float time ) char _comSetInhibit[15] = {0}; sprintf( _comSetInhibit, comSetInhibit, time ); - setConfig( _comSetInhibit ); - - return true; + return setConfig( _comSetInhibit ); } bool DFR_Radar::setTriggerLevel( PinStatus triggerLevel ) @@ -94,9 +171,7 @@ bool DFR_Radar::setTriggerLevel( PinStatus triggerLevel ) char _comSetGpioMode[16] = {0}; sprintf( _comSetGpioMode, comSetGpioMode, triggerLevel ); - setConfig( _comSetGpioMode ); - - return true; + return setConfig( _comSetGpioMode ); } bool DFR_Radar::setDetectionArea( float rangeStart, float rangeEnd ) @@ -104,6 +179,7 @@ bool DFR_Radar::setDetectionArea( float rangeStart, float rangeEnd ) if( rangeStart < 0 || rangeEnd < 0 || rangeEnd < rangeStart ) return false; + // Convert meters into 15cm units uint8_t _rangeStart = rangeStart / 0.15; uint8_t _rangeEnd = rangeEnd / 0.15; @@ -113,9 +189,7 @@ bool DFR_Radar::setDetectionArea( float rangeStart, float rangeEnd ) char _comDetRangeCfg[23] = {0}; sprintf( _comDetRangeCfg, comDetRangeCfg1, _rangeStart, _rangeEnd ); - setConfig( _comDetRangeCfg ); - - return true; + return setConfig( _comDetRangeCfg ); } bool DFR_Radar::setDetectionArea( float rangeA_Start, float rangeA_End, float rangeB_Start, float rangeB_End ) @@ -129,6 +203,7 @@ bool DFR_Radar::setDetectionArea( float rangeA_Start, float rangeA_End, float ra if( rangeB_Start < rangeA_End ) return false; + // Convert meters into 15cm units uint8_t _rangeA_Start = rangeA_Start / 0.15; uint8_t _rangeA_End = rangeA_End / 0.15; uint8_t _rangeB_Start = rangeB_Start / 0.15; @@ -140,9 +215,7 @@ bool DFR_Radar::setDetectionArea( float rangeA_Start, float rangeA_End, float ra char _comDetRangeCfg[31] = {0}; sprintf( _comDetRangeCfg, comDetRangeCfg2, _rangeA_Start, _rangeA_End, _rangeB_Start, _rangeB_End ); - setConfig( _comDetRangeCfg ); - - return true; + return setConfig( _comDetRangeCfg ); } bool DFR_Radar::setDetectionArea( float rangeA_Start, float rangeA_End, float rangeB_Start, float rangeB_End, float rangeC_Start, float rangeC_End ) @@ -159,6 +232,7 @@ bool DFR_Radar::setDetectionArea( float rangeA_Start, float rangeA_End, float ra if( rangeB_Start < rangeA_End || rangeC_Start < rangeB_End ) return false; + // Convert meters into 15cm units uint8_t _rangeA_Start = rangeA_Start / 0.15; uint8_t _rangeA_End = rangeA_End / 0.15; uint8_t _rangeB_Start = rangeB_Start / 0.15; @@ -172,9 +246,7 @@ bool DFR_Radar::setDetectionArea( float rangeA_Start, float rangeA_End, float ra char _comDetRangeCfg[39] = {0}; sprintf( _comDetRangeCfg, comDetRangeCfg3, _rangeA_Start, _rangeA_End, _rangeB_Start, _rangeB_End, _rangeC_Start, _rangeC_End ); - setConfig( _comDetRangeCfg ); - - return true; + return setConfig( _comDetRangeCfg ); } bool DFR_Radar::setDetectionArea( float rangeA_Start, float rangeA_End, float rangeB_Start, float rangeB_End, float rangeC_Start, float rangeC_End, float rangeD_Start, float rangeD_End ) @@ -194,6 +266,7 @@ bool DFR_Radar::setDetectionArea( float rangeA_Start, float rangeA_End, float ra if( rangeB_Start < rangeA_End || rangeC_Start < rangeB_End || rangeD_Start < rangeC_End ) return false; + // Convert meters into 15cm units uint8_t _rangeA_Start = rangeA_Start / 0.15; uint8_t _rangeA_End = rangeA_End / 0.15; uint8_t _rangeB_Start = rangeB_Start / 0.15; @@ -209,9 +282,22 @@ bool DFR_Radar::setDetectionArea( float rangeA_Start, float rangeA_End, float ra char _comDetRangeCfg[47] = {0}; sprintf( _comDetRangeCfg, comDetRangeCfg4, _rangeA_Start, _rangeA_End, _rangeB_Start, _rangeB_End, _rangeC_Start, _rangeC_End, _rangeD_Start, _rangeD_End ); - setConfig( _comDetRangeCfg ); + return setConfig( _comDetRangeCfg ); +} - return true; + +bool DFR_Radar::setTriggerLatency( float confirmationDelay, float disappearanceDelay ) +{ + if( confirmationDelay < 0 || confirmationDelay > 100 ) + return false; + + if( disappearanceDelay < 0 || disappearanceDelay > 1500 ) + return false; + + char _comSetLatency[20] = {0}; + sprintf( _comSetLatency, comSetLatency, confirmationDelay , disappearanceDelay ); + + return setConfig( _comSetLatency ); } @@ -220,6 +306,7 @@ bool DFR_Radar::setOutputLatency( float triggerDelay, float resetDelay ) if( triggerDelay < 0 || resetDelay < 0 ) return false; + // Convert seconds into 25ms units uint16_t _triggerDelay = triggerDelay * 1000 / 25; uint16_t _resetDelay = resetDelay * 1000 / 25; @@ -229,9 +316,7 @@ bool DFR_Radar::setOutputLatency( float triggerDelay, float resetDelay ) char _comOutputLatency[29] = {0}; sprintf( _comOutputLatency, comOutputLatency, _triggerDelay , _resetDelay ); - setConfig( _comOutputLatency ); - - return true; + return setConfig( _comOutputLatency ); } bool DFR_Radar::setSensitivity( uint8_t level ) @@ -242,68 +327,114 @@ bool DFR_Radar::setSensitivity( uint8_t level ) char _comSetSensitivity[17] = {0}; sprintf( _comSetSensitivity, comSetSensitivity, level ); - setConfig( _comSetSensitivity ); - - return true; + return setConfig( _comSetSensitivity ); } -void DFR_Radar::disableLED() +bool DFR_Radar::disableLED() { - configureLED( true ); + return configureLED( true ); } -void DFR_Radar::enableLED() +bool DFR_Radar::enableLED() { - configureLED( false ); + return configureLED( false ); } -void DFR_Radar::configureLED( bool disabled ) +bool DFR_Radar::configureLED( bool disabled ) { char _comSetLedMode[15] = {0}; sprintf( _comSetLedMode, comSetLedMode, disabled ); - setConfig( _comSetLedMode ); + return setConfig( _comSetLedMode ); } -void DFR_Radar::enableAutoStart() +bool DFR_Radar::factoryReset() { - configureAutoStart( true ); + if( !stop() ) + return false; + + return sendCommand( comFactoryReset ); } -void DFR_Radar::disableAutoStart() +bool DFR_Radar::configBegin() { - configureAutoStart( false ); + if( multiConfig ) + return true; + + if( !stop() ) + return false; + + multiConfig = true; + + return true; } -void DFR_Radar::configureAutoStart( bool autoStart ) +bool DFR_Radar::configEnd() { - char _comSensorCfgStart[17] = {0}; - sprintf( _comSensorCfgStart, comSensorCfgStart, autoStart ); + if( !multiConfig ) + return false; + + multiConfig = false; + + if( !saveConfig() ) + return false; + + if( !start() ) + return false; - setConfig( _comSensorCfgStart ); + return true; } -void DFR_Radar::factoryReset() +bool DFR_Radar::setConfig( const char *command ) { - setConfig( comFactoryReset ); + if( multiConfig ) + { + return sendCommand( command ); + } + else + { + if( !stop() ) + return false; + + if( !sendCommand( command ) ) + return false; + + bool saved = saveConfig(); + + if( !start() ) + return false; + + return saved; + } } -void DFR_Radar::setConfig( const char *command ) +bool DFR_Radar::saveConfig() { - stop(); - sendCommand( command ); - saveConfig(); - start(); + return sendCommand( comSaveCfg ); } -void DFR_Radar::start() +bool DFR_Radar::start() { - sendCommand( comStart ); + if( !stopped ) + return true; + + if( !sendCommand( comStart ) ) + return false; + + stopped = false; + return true; } -void DFR_Radar::stop() +bool DFR_Radar::stop() { - sendCommand( comStop ); + if( stopped ) + return true; + + if( !sendCommand( comStop ) ) + return false; + + stopped = true; + return true; } void DFR_Radar::reboot() @@ -311,13 +442,55 @@ void DFR_Radar::reboot() sendCommand( comResetSystem ); } -void DFR_Radar::sendCommand( const char *command ) +bool DFR_Radar::sendCommand( const char *command ) { + char responseBuffer[32] = {0}; + unsigned long timeout = millis() + comTimeout; + + static const size_t successLength = strlen( comResponseSuccess ); + static const size_t failLength = strlen( comResponseFail ); + static const size_t minResponseLength = min( successLength, failLength ); + + const size_t commandLength = strlen( command ); + const size_t minLength = min( commandLength, minResponseLength ); + + // Make sure we have exactly enough time + sensorUART->setTimeout( comTimeout ); + + // Send the command... sensorUART->write( command ); - delay( comDelay ); -} -void DFR_Radar::saveConfig() -{ - sendCommand( comSaveCfg ); + // ...then wait for a response + while( millis() < timeout ) + { + if( sensorUART->available() <= 0 ) + continue; + + // Start with an empty buffer + responseBuffer[0] = '\0'; + + // Read a whole line + size_t responseLength = sensorUART->readBytesUntil( '\n', responseBuffer, sizeof( responseBuffer ) ); + + // We got something shorter than anything we're expecting, so try again + if( responseLength < minLength ) + continue; + + // Check if that line is an echo of the original command + if( strncmp( command, responseBuffer, commandLength ) == 0 ) + continue; + + // ...or if that line says "Done" + if( strncmp( comResponseSuccess, responseBuffer, successLength ) == 0 ) + return true; + + // ...or if that line says "Error" + if( strncmp( comResponseFail, responseBuffer, failLength ) == 0 ) + return false; + + // ...we got nothing we expected, so try again + } + + // We've timed out + return false; } diff --git a/src/DFR_Radar.h b/src/DFR_Radar.h index bc8ecd7..41982a9 100644 --- a/src/DFR_Radar.h +++ b/src/DFR_Radar.h @@ -17,6 +17,9 @@ #include +#ifdef ESP32 + #define PinStatus uint8_t +#endif class DFR_Radar { @@ -28,6 +31,13 @@ class DFR_Radar */ DFR_Radar( Stream *s ); + /** + * @brief Not currently implemented + * + * @return true + */ + bool begin( void ); + /** * @brief Configure sensor detection for a single range * @@ -118,6 +128,18 @@ class DFR_Radar */ bool setSensitivity( uint8_t level ); + /** + * @brief Configure delays that translate actual presence activity to sensor assertion of presence + * + * @note A longer confirmation delay can reduce false positives. A longer disappearance delay can bridge gaps between presence events. + * + * @param confirmationDelay Time in seconds of continuous presence activity before the sensor actually asserts presence; factory default is 0.025s + * @param disappearanceDelay Time in seconds without any presence activity before desserting presence; factory default is 5s + * + * @return false if either delay value is invalid (no changes made), true otherwise + */ + bool setTriggerLatency( float confirmationDelay, float disappearanceDelay ); + /** * @brief Configure delays between state changes on output (IO2) * @@ -131,15 +153,15 @@ class DFR_Radar /** * @brief Check if the sensor is detecting presence * - * @return true if presence is currently being detected - * @return false if no presence or reading sensor failed + * @return true if presence is currently being detected; + * false if no presence or reading sensor failed */ bool checkPresence( void ); /** * @brief Sets a delay between when the presence detection resets and when it can trigger again. * - * @note Used to prevent short-cycling (re-triggering immediately after a rest). + * @note Used to prevent short-cycling (re-triggering immediately after a reset). * * @param time Time in seconds after the presence detection has reset before it can be triggered again. * Range is 0.1 - 255; factory default is 1 @@ -159,16 +181,20 @@ class DFR_Radar bool setTriggerLevel( PinStatus triggerLevel ); /** - * @brief Start the sensor. + * @brief Start the sensor * + * @return true if sensor started (or was already started); + * false if sensor failed to start */ - void start( void ); + bool start( void ); /** * @brief Stop the sensor * + * @return true if sensor stopped (or was already stopped); + * false if sensor failed to stop */ - void stop( void ); + bool stop( void ); /** * @brief Restart the sensor's internal software (safe; configuration is not lost or changed). @@ -179,14 +205,16 @@ class DFR_Radar /** * @brief Disable the LED * + * @return true if command was successful */ - void disableLED( void ); + bool disableLED( void ); /** * @brief Enable the LED * + * @return true if command was successful */ - void enableLED( void ); + bool enableLED( void ); /** * @brief Set whether LED is enabled. @@ -194,89 +222,81 @@ class DFR_Radar * @note Called by `disableLED()` and `enableLED()` * * @param disabled true if LED should be disabled, false for enabled - */ - void configureLED( bool disabled ); - - /** - * @brief Enable automatic start on power-up. * + * @return true if command was successful */ - void enableAutoStart(); + bool configureLED( bool disabled ); /** - * @brief Disable automatic start on power-up. - * - * @note Will need to call `start()` at runtime. + * @brief Allows setting multiple configuration options without + * stopping/saving/re-starting with each one. Make sure + * to call `configEnd()` after making changes. * + * @return false if the sensor failed to stop (multi-config mode will be disabled), true otherwise */ - void disableAutoStart(); + bool configBegin( void ); /** - * @brief Set whether sensor will start automatically on power-up. - * - * @note Called by `disableAutoStart()` and `enableAutoStart()` - * - * @param autoStart true if sensor should start immediately after power-up, - * false if not (will need to call `start()` at runtime) - */ - void configureAutoStart( bool autoStart ); - - /** - * @brief Commits configuration data to flash + * @brief Allows setting multiple configuration options without + * stopping/saving/re-starting with each one. Must call + * `configBegin()` first. * + * @return false if multi-config mode isn't enabled (forgot to call `configBegin()` first or it failed), + * or if saving or re-starting failed; true otherwise */ - void saveConfig(); + bool configEnd( void ); /** * @brief Restore the sensor configuration to factory default settings. * + * @return true if command was successful; + * false if the sensor failed to stop or if the ecommand failed */ - void factoryReset( void ); + bool factoryReset( void ); private: /** - * @brief Read data from the serial port + * @brief Read a line (or more) from the UART port * * @param buffer Store the read data - * @param length The number of bytes to read * - * @return the actual length of bytes read + * @return length of characters captured */ - size_t readBytes( char *buffer, size_t length ); + size_t readLines( char *buffer, size_t lineCount = 1 ); /** - * @brief Read complete data packet + * @brief Executes a command string after first stopping the sensor, then afterwards + * saves the configuration and re-starts the sensor. * - * @note The packet should be 15 bytes long and look like this: - * `$JYBSS,1, , , *` - * The first field is presence detection (0 or 1), and the - * remaining three fields are reserved (always be spaces). + * @details If multi-config mode is enabled (`configBegin()` was called earlier), + * this this method only executes the command string, and `configEnd()` + * must be called to save the configuration and re-start the sensor. * - * @param buffer Store the read data + * @param command A command string generated by one of the configuration methods * - * @return true if successful, false otherwise + * @return true if command was successful; + * false if sensor failed to stop or re-start, command failed, or save failed */ - bool readPacket( char *buffer ); + bool setConfig( const char *command ); /** - * @brief Executes a command string after first stopping the sensor, then - * afterwards saves the configuration and re-starts the sensor - * - * @note Each of the methods called by this one also call `sendCommand()`, which - * will delay for `comDelay` -- thus, this method will delay for `4 x comDelay` + * @brief Commits configuration data to flash * - * @param command A command string generated by one of the configuration methods + * @return true if command was successful */ - void setConfig( const char *command ); + bool saveConfig( void ); /** - * @brief Writes a command string to the sensor UART port, then delays for `comDelay` + * @brief Writes a command string to the sensor UART port and waits for response * * @param command A command string generated by one of the other config/command methods + * + * @return true if response was "Done"; + * false if "Error" or timeout */ - void sendCommand( const char *command ); + bool sendCommand( const char *command ); /** * @brief The serial port (hardware or software) to use for communicating with the sensor @@ -284,28 +304,36 @@ class DFR_Radar */ Stream *sensorUART; - - static const uint16_t readBytesTimeout = 100; - static const uint16_t readPacketTimeout = 1000; - static const size_t packetLength = 16; - static constexpr const char *packetStart = "$JYBSS"; - - static const unsigned long comDelay = 1000; - static constexpr const char *comStop = "sensorStop"; - static constexpr const char *comStart = "sensorStart"; - static constexpr const char *comResetSystem = "resetSystem 0"; - static constexpr const char *comDetRangeCfg1 = "detRangeCfg -1 %u %u"; - static constexpr const char *comDetRangeCfg2 = "detRangeCfg -1 %u %u %u %u"; - static constexpr const char *comDetRangeCfg3 = "detRangeCfg -1 %u %u %u %u %u %u"; - static constexpr const char *comDetRangeCfg4 = "detRangeCfg -1 %u %u %u %u %u %u %u %u"; - static constexpr const char *comSetSensitivity = "setSensitivity %u"; - static constexpr const char *comOutputLatency = "outputLatency -1 %u %u"; - static constexpr const char *comSetGpioMode = "setGpioMode 1 %u"; - static constexpr const char *comSetInhibit = "setInhibit %u"; - static constexpr const char *comSetLedMode = "setLedMode 1 %u"; - static constexpr const char *comSensorCfgStart = "sensorCfgStart %u"; - static constexpr const char *comSaveCfg = "saveConfig"; // "saveCfg 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"; - static constexpr const char *comFactoryReset = "resetCfg"; // "factoryReset 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"; + // bool isConfigured; + bool stopped; + bool multiConfig; + + static const uint16_t readPacketTimeout = 100; + static const size_t packetLength = 64; + + static const unsigned long startupDelay = 2000; + + static const unsigned long comTimeout = 1000; + static constexpr const char *comStop = "sensorStop"; + static constexpr const char *comStart = "sensorStart"; + static constexpr const char *comResetSystem = "resetSystem 0"; + static constexpr const char *comDetRangeCfg1 = "detRangeCfg -1 %u %u"; + static constexpr const char *comDetRangeCfg2 = "detRangeCfg -1 %u %u %u %u"; + static constexpr const char *comDetRangeCfg3 = "detRangeCfg -1 %u %u %u %u %u %u"; + static constexpr const char *comDetRangeCfg4 = "detRangeCfg -1 %u %u %u %u %u %u %u %u"; + static constexpr const char *comSetSensitivity = "setSensitivity %u"; + static constexpr const char *comOutputLatency = "outputLatency -1 %u %u"; + static constexpr const char *comSetLatency = "setLatency %u %u"; + static constexpr const char *comSetGpioMode = "setGpioMode 1 %u"; + static constexpr const char *comGetOutput = "getOutput 1"; + static constexpr const char *comSetInhibit = "setInhibit %u"; + static constexpr const char *comSetLedMode = "setLedMode 1 %u"; + // static constexpr const char *comSetUartOutput = "setUartOutput 1 1 0 1501"; + static constexpr const char *comSetEcho = "setEcho 0"; + static constexpr const char *comResponseSuccess = "Done"; + static constexpr const char *comResponseFail = "Error"; + static constexpr const char *comSaveCfg = "saveConfig"; // "saveCfg 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"; + static constexpr const char *comFactoryReset = "resetCfg"; // "factoryReset 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"; }; #endif