Skip to content

Commit

Permalink
Update testing programs
Browse files Browse the repository at this point in the history
  • Loading branch information
SRGDamia1 committed Aug 2, 2024
1 parent f128f88 commit 31358ee
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 93 deletions.
103 changes: 57 additions & 46 deletions tools/TestCommands/TestCommands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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') */
Expand All @@ -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;

Expand Down Expand Up @@ -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<CR><LF>
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;
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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<CR><LF>
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)
Expand Down
75 changes: 66 additions & 9 deletions tools/TestSensorTiming/TestSensorTiming.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,35 @@ 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. */
/** NOTE: set the power off time to be something similar to what you will be using the
* 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;
Expand Down Expand Up @@ -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));
}
}
}

Expand Down Expand Up @@ -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<CR><LF>
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)
Expand Down
88 changes: 50 additions & 38 deletions tools/TestWarmUp/TestWarmUp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -131,6 +142,7 @@ void loop() {
pinMode(powerPin, OUTPUT);
digitalWrite(powerPin, HIGH);
delay(power_delay);
mySDI12.clearBuffer();
}

if (checkActive(sensorAddress, 1, true)) {
Expand Down

0 comments on commit 31358ee

Please sign in to comment.