From 31358eeeeac7660a9ee44b89d1ceb771b008cce0 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 2 Aug 2024 14:45:19 -0400 Subject: [PATCH] Update testing programs --- tools/TestCommands/TestCommands.ino | 103 +++++++++++--------- tools/TestSensorTiming/TestSensorTiming.ino | 75 ++++++++++++-- tools/TestWarmUp/TestWarmUp.ino | 88 +++++++++-------- 3 files changed, 173 insertions(+), 93 deletions(-) diff --git a/tools/TestCommands/TestCommands.ino b/tools/TestCommands/TestCommands.ino index d6cf424..55d757a 100644 --- a/tools/TestCommands/TestCommands.ino +++ b/tools/TestCommands/TestCommands.ino @@ -9,7 +9,7 @@ /* connection information */ uint32_t serialBaud = 115200; /*!< The baud rate for the output serial port */ -uint8_t dataPin = 7; /*!< The pin of the SDI-12 data bus */ +int8_t dataPin = 7; /*!< The pin of the SDI-12 data bus */ int8_t powerPin = 22; /*!< The sensor power pin (or -1 if not switching power) */ uint32_t wake_delay = 0; /*!< Extra time needed for the sensor to wake (0-100ms) */ int8_t firstAddress = 0; /* The first address in the address space to check (0='0') */ @@ -20,6 +20,10 @@ int8_t commandsToTest = /** Define the SDI-12 bus */ SDI12 mySDI12(dataPin); +/** Error codes, if returned */ +int8_t error_result_number = 7; +float no_error_value = 0; + /// variable that alternates output type back and forth between parsed and raw boolean flip = 0; @@ -79,45 +83,6 @@ char decToChar(byte i) { return i; } -/** - * @brief gets identification information from a sensor, and prints it to the serial - * port - * - * @param i a character between '0'-'9', 'a'-'z', or 'A'-'Z'. - */ -void printInfo(char i, bool printCommands = true) { - String command = ""; - command += (char)i; - command += "I!"; - mySDI12.sendCommand(command, wake_delay); - if (printCommands) { - Serial.print(">>>"); - Serial.println(command); - } - - String sdiResponse = mySDI12.readStringUntil('\n'); - sdiResponse.trim(); - // allccccccccmmmmmmvvvxxx...xx - if (printCommands) { - Serial.print("<<<"); - Serial.println(sdiResponse); - } - - Serial.print("Address: "); - Serial.print(sdiResponse.substring(0, 1)); // address - Serial.print(", SDI-12 Version: "); - Serial.print(sdiResponse.substring(1, 3).toFloat() / 10); // SDI-12 version number - Serial.print(", Vendor ID: "); - Serial.print(sdiResponse.substring(3, 11)); // vendor id - Serial.print(", Sensor Model: "); - Serial.print(sdiResponse.substring(11, 17)); // sensor model - Serial.print(", Sensor Version: "); - Serial.print(sdiResponse.substring(17, 20)); // sensor version - Serial.print(", Sensor ID: "); - Serial.print(sdiResponse.substring(20)); // sensor id - Serial.println(); -} - bool getResults(char address, int resultsExpected, bool verify_crc = false, bool printCommands = true) { uint8_t resultsReceived = 0; @@ -258,12 +223,15 @@ bool getResults(char address, int resultsExpected, bool verify_crc = false, resultsReceived++; } // check for a failure error code at the end - if (resultsReceived == 5 && result != 0.0) { - gotResults = false; - resultsReceived = 0; - if (printCommands) { - Serial.print("Got a failure code of "); - Serial.println(String(result, strnlen(dec_pl, max_sdi_digits) - 1)); + if (error_result_number >= 1) { + if (resultsReceived == error_result_number && result != no_error_value) { + gotResults = false; + resultsReceived = 0; + if (printCommands) { + Serial.print("Got a failure code of "); + Serial.println(String(result, strnlen(dec_pl, max_sdi_digits) - 1)); + } + return false; } } @@ -510,6 +478,49 @@ bool checkActive(char address, int8_t numPings = 3, bool printCommands = true) { return false; } +/** + * @brief gets identification information from a sensor, and prints it to the serial + * port + * + * @param i a character between '0'-'9', 'a'-'z', or 'A'-'Z'. + */ +bool printInfo(char i, bool printCommands = true) { + String command = ""; + command += (char)i; + command += "I!"; + mySDI12.sendCommand(command, wake_delay); + if (printCommands) { + Serial.print(">>>"); + Serial.println(command); + } + delay(100); + + String sdiResponse = mySDI12.readStringUntil('\n'); + sdiResponse.trim(); + // allccccccccmmmmmmvvvxxx...xx + if (printCommands) { + Serial.print("<<<"); + Serial.println(sdiResponse); + } + + Serial.print("Address: "); + Serial.print(sdiResponse.substring(0, 1)); // address + Serial.print(", SDI-12 Version: "); + Serial.print(sdiResponse.substring(1, 3).toFloat() / 10); // SDI-12 version number + Serial.print(", Vendor ID: "); + Serial.print(sdiResponse.substring(3, 11)); // vendor id + Serial.print(", Sensor Model: "); + Serial.print(sdiResponse.substring(11, 17)); // sensor model + Serial.print(", Sensor Version: "); + Serial.print(sdiResponse.substring(17, 20)); // sensor version + Serial.print(", Sensor ID: "); + Serial.print(sdiResponse.substring(20)); // sensor id + Serial.println(); + + if (sdiResponse.length() < 3) { return false; }; + return true; +} + void setup() { Serial.begin(serialBaud); while (!Serial) diff --git a/tools/TestSensorTiming/TestSensorTiming.ino b/tools/TestSensorTiming/TestSensorTiming.ino index c15803f..c515773 100644 --- a/tools/TestSensorTiming/TestSensorTiming.ino +++ b/tools/TestSensorTiming/TestSensorTiming.ino @@ -13,14 +13,19 @@ uint32_t serialBaud = 115200; /*!< The baud rate for the output serial port * int8_t dataPin = 7; /*!< The pin of the SDI-12 data bus */ char sensorAddress = '0'; /*!< The address of the SDI-12 sensor */ int8_t powerPin = 22; /*!< The sensor power pin (or -1 if not switching power) */ -uint32_t wake_delay = 100; /*!< Extra time needed for the sensor to wake (0-100ms) */ /** Define the SDI-12 bus */ SDI12 mySDI12(dataPin); /** Define some testing specs */ -bool testPowerOff = true; -int32_t min_power_delay = 4900L; /*!< The min time to test wake after power on. */ + +/** Error codes, if returned */ +int8_t error_result_number = 7; +float no_error_value = 0; + +/** Testing turning off power */ +bool testPowerOff = false; +int32_t min_power_delay = 100L; /*!< The min time to test wake after power on. */ int32_t max_power_delay = 180000L; /*!< The max time to test wake after power on. */ int32_t increment_power_delay = 100L; /*!< The time to lengthen waits between reps. */ int32_t power_off_time = 60000L; /*!< The time to power off between tests. */ @@ -28,8 +33,15 @@ int32_t power_off_time = 60000L; /*!< The time to power off between tests * the real world! Some sensors take longer to warm up if they've been off for a while. */ +/** Testing the length of the break */ +bool testBreak = true; +int32_t min_wake_delay = 0; /*!< The min time to test wake after a line break. */ +int32_t max_wake_delay = 100; /*!< The max time to test wake (should be <=100). */ +int32_t increment_wake = 5; /*!< The time to lengthen waits between reps. */ + /** set some initial values */ int32_t power_delay = min_power_delay; +int32_t wake_delay = min_wake_delay; int32_t total_meas_time = 0; int32_t total_meas_made = 0; @@ -178,12 +190,14 @@ bool getResults(char address, int resultsExpected, bool verify_crc = false, resultsReceived++; } // check for a failure error code at the end - if (resultsReceived == 5 && result != 0.0) { - gotResults = false; - resultsReceived = 0; - if (printCommands) { - Serial.print("Got a failure code of "); - Serial.println(String(result, strnlen(dec_pl, max_sdi_digits) - 1)); + if (error_result_number >= 1) { + if (resultsReceived == error_result_number && result != no_error_value) { + gotResults = false; + resultsReceived = 0; + if (printCommands) { + Serial.print("Got a failure code of "); + Serial.println(String(result, strnlen(dec_pl, max_sdi_digits) - 1)); + } } } @@ -359,6 +373,49 @@ bool checkActive(char address, int8_t numPings = 3, bool printCommands = true) { return false; } +/** + * @brief gets identification information from a sensor, and prints it to the serial + * port + * + * @param i a character between '0'-'9', 'a'-'z', or 'A'-'Z'. + */ +bool printInfo(char i, bool printCommands = true) { + String command = ""; + command += (char)i; + command += "I!"; + mySDI12.sendCommand(command, wake_delay); + if (printCommands) { + Serial.print(">>>"); + Serial.println(command); + } + delay(100); + + String sdiResponse = mySDI12.readStringUntil('\n'); + sdiResponse.trim(); + // allccccccccmmmmmmvvvxxx...xx + if (printCommands) { + Serial.print("<<<"); + Serial.println(sdiResponse); + } + + Serial.print("Address: "); + Serial.print(sdiResponse.substring(0, 1)); // address + Serial.print(", SDI-12 Version: "); + Serial.print(sdiResponse.substring(1, 3).toFloat() / 10); // SDI-12 version number + Serial.print(", Vendor ID: "); + Serial.print(sdiResponse.substring(3, 11)); // vendor id + Serial.print(", Sensor Model: "); + Serial.print(sdiResponse.substring(11, 17)); // sensor model + Serial.print(", Sensor Version: "); + Serial.print(sdiResponse.substring(17, 20)); // sensor version + Serial.print(", Sensor ID: "); + Serial.print(sdiResponse.substring(20)); // sensor id + Serial.println(); + + if (sdiResponse.length() < 3) { return false; }; + return true; +} + void setup() { Serial.begin(serialBaud); while (!Serial) diff --git a/tools/TestWarmUp/TestWarmUp.ino b/tools/TestWarmUp/TestWarmUp.ino index b31314d..b58616d 100644 --- a/tools/TestWarmUp/TestWarmUp.ino +++ b/tools/TestWarmUp/TestWarmUp.ino @@ -15,17 +15,61 @@ char sensorAddress = '0'; /*!< The address of the SDI-12 sensor */ int8_t powerPin = 22; /*!< The sensor power pin (or -1 if not switching power) */ /** Define the SDI-12 bus */ -SDI12 mySDI12(dataPin); -int32_t min_wake_delay = 0; /*!< The min time to test wake after a line break. */ -int32_t increment_wake = 5; /*!< The time to lengthen waits between reps. */ -int32_t max_wake_delay = 100; /*!< The max time to test wake (should be <=100). */ +SDI12 mySDI12(dataPin); + +/** Define some testing specs */ + +/** Error codes, if returned */ +int8_t error_result_number = 7; +float no_error_value = 0; + +/** Testing turning off power */ int32_t min_power_delay = 100L; /*!< The min time to test wake after power on. */ -int32_t increment_power = 100; /*!< The time to lengthen waits between reps. */ int32_t max_power_delay = 10000L; /*!< The max time to test wake after power on. */ +int32_t increment_power = 100; /*!< The time to lengthen waits between reps. */ +/** Testing the length of the break */ +int32_t min_wake_delay = 0; /*!< The min time to test wake after a line break. */ +int32_t max_wake_delay = 100; /*!< The max time to test wake (should be <=100). */ +int32_t increment_wake = 5; /*!< The time to lengthen waits between reps. */ + +/** set some initial values */ int32_t power_delay = min_power_delay; int32_t wake_delay = min_wake_delay; +// this checks for activity at a particular address +// expects a char, '0'-'9', 'a'-'z', or 'A'-'Z' +bool checkActive(char address, int8_t numPings = 3, bool printCommands = false) { + String command = ""; + command += (char)address; // sends basic 'acknowledge' command [address][!] + command += "!"; + + for (int j = 0; j < numPings; j++) { // goes through three rapid contact attempts + if (printCommands) { + Serial.print(">>>"); + Serial.println(command); + } + mySDI12.sendCommand(command, wake_delay); + + // the sensor should just return its address + String sdiResponse = mySDI12.readStringUntil('\n'); + sdiResponse.trim(); + if (printCommands) { + Serial.print("<<<"); + Serial.println(sdiResponse); + } + mySDI12.clearBuffer(); + + // check the address, return false if it's incorrect + String returned_address = sdiResponse.substring(0, 1); + char ret_addr_array[2]; + returned_address.toCharArray(ret_addr_array, sizeof(ret_addr_array)); + if (returned_address == String(address)) { return true; } + } + mySDI12.clearBuffer(); + return false; +} + /** * @brief gets identification information from a sensor, and prints it to the serial * port @@ -69,39 +113,6 @@ bool printInfo(char i, bool printCommands = true) { return true; } -// this checks for activity at a particular address -// expects a char, '0'-'9', 'a'-'z', or 'A'-'Z' -bool checkActive(char address, int8_t numPings = 3, bool printCommands = false) { - String command = ""; - command += (char)address; // sends basic 'acknowledge' command [address][!] - command += "!"; - - for (int j = 0; j < numPings; j++) { // goes through three rapid contact attempts - if (printCommands) { - Serial.print(">>>"); - Serial.println(command); - } - mySDI12.sendCommand(command, wake_delay); - - // the sensor should just return its address - String sdiResponse = mySDI12.readStringUntil('\n'); - sdiResponse.trim(); - if (printCommands) { - Serial.print("<<<"); - Serial.println(sdiResponse); - } - mySDI12.clearBuffer(); - - // check the address, return false if it's incorrect - String returned_address = sdiResponse.substring(0, 1); - char ret_addr_array[2]; - returned_address.toCharArray(ret_addr_array, sizeof(ret_addr_array)); - if (returned_address == String(address)) { return true; } - } - mySDI12.clearBuffer(); - return false; -} - void setup() { Serial.begin(serialBaud); while (!Serial) @@ -131,6 +142,7 @@ void loop() { pinMode(powerPin, OUTPUT); digitalWrite(powerPin, HIGH); delay(power_delay); + mySDI12.clearBuffer(); } if (checkActive(sensorAddress, 1, true)) {