2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
// FILE: unit_test_001.cpp
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2020-12-03
|
|
|
|
// PURPOSE: unit tests for the Cozir CO2 library
|
2021-03-01 04:11:54 -05:00
|
|
|
// https://github.com/RobTillaart/Cozir
|
2021-01-29 06:31:58 -05:00
|
|
|
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
|
|
|
//
|
|
|
|
|
|
|
|
// supported assertions
|
|
|
|
// https://github.com/Arduino-CI/arduino_ci/blob/master/cpp/unittest/Assertion.h#L33-L42
|
|
|
|
// ----------------------------
|
2021-03-01 04:11:54 -05:00
|
|
|
// assertEqual(expected, actual); // a == b
|
|
|
|
// assertNotEqual(unwanted, actual); // a != b
|
|
|
|
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
|
|
|
|
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
|
|
|
|
// assertLess(upperBound, actual); // a < b
|
|
|
|
// assertMore(lowerBound, actual); // a > b
|
|
|
|
// assertLessOrEqual(upperBound, actual); // a <= b
|
|
|
|
// assertMoreOrEqual(lowerBound, actual); // a >= b
|
|
|
|
// assertTrue(actual);
|
|
|
|
// assertFalse(actual);
|
|
|
|
// assertNull(actual);
|
|
|
|
|
|
|
|
// // special cases for floats
|
|
|
|
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
|
|
|
|
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
|
|
|
|
// assertInfinity(actual); // isinf(a)
|
|
|
|
// assertNotInfinity(actual); // !isinf(a)
|
|
|
|
// assertNAN(arg); // isnan(a)
|
|
|
|
// assertNotNAN(arg); // !isnan(a)
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
#include <ArduinoUnitTests.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "cozir.h"
|
|
|
|
#include "SoftwareSerial.h"
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: normally the COZIR lib is tested with software serial, at least in sketches
|
|
|
|
// to get the unit test up and running I (tried to) use Serial here.
|
|
|
|
|
|
|
|
// aspects of software serial
|
|
|
|
bool bigEndian = false;
|
|
|
|
|
2021-12-14 13:05:30 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_setup()
|
|
|
|
{
|
2021-12-14 13:05:30 -05:00
|
|
|
fprintf(stderr, "COZIR_LIB_VERSION: %s\n", (char *) COZIR_LIB_VERSION);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
2021-12-14 13:05:30 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-14 13:05:30 -05:00
|
|
|
unittest(test_constants)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\noutput fields\n");
|
|
|
|
assertEqual(0x2000, CZR_LIGHT );
|
|
|
|
assertEqual(0x1000, CZR_HUMIDITY );
|
|
|
|
assertEqual(0x0800, CZR_FILTLED );
|
|
|
|
assertEqual(0x0400, CZR_RAWLED );
|
|
|
|
assertEqual(0x0200, CZR_MAXLED );
|
|
|
|
|
|
|
|
assertEqual(0x0100, CZR_ZEROPOINT );
|
|
|
|
assertEqual(0x0080, CZR_RAWTEMP );
|
|
|
|
assertEqual(0x0040, CZR_FILTTEMP );
|
|
|
|
assertEqual(0x0020, CZR_FILTLEDSIGNAL);
|
|
|
|
assertEqual(0x0010, CZR_RAWLEDSIGNAL );
|
|
|
|
|
|
|
|
assertEqual(0x0008, CZR_SENSTEMP );
|
|
|
|
assertEqual(0x0004, CZR_FILTCO2 );
|
|
|
|
assertEqual(0x0002, CZR_RAWCO2 );
|
|
|
|
assertEqual(0x0001, CZR_NONE );
|
|
|
|
assertEqual(0x1082, CZR_HTC );
|
|
|
|
|
|
|
|
assertEqual(0x3FFE, CZR_ALL );
|
|
|
|
|
|
|
|
fprintf(stderr, "\nmodi operandi\n");
|
|
|
|
assertEqual(0x00, CZR_COMMAND);
|
|
|
|
assertEqual(0x01, CZR_STREAMING);
|
|
|
|
assertEqual(0x02, CZR_POLLING);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest(test_software_serial)
|
|
|
|
{
|
|
|
|
int receivePin = 4;
|
|
|
|
int transmitPin = 5;
|
|
|
|
|
|
|
|
GodmodeState* state = GODMODE();
|
|
|
|
|
|
|
|
SoftwareSerial sws(receivePin, transmitPin);
|
|
|
|
COZIR co(&sws);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.init()\n");
|
|
|
|
co.init();
|
|
|
|
assertEqual("K 2\r\n", state->digitalPin[transmitPin].toAscii(1, bigEndian));
|
2021-08-15 13:38:45 -04:00
|
|
|
delay(1300);
|
|
|
|
assertTrue(co.isInitialized());
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
2021-03-01 04:11:54 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest(test_constructor)
|
|
|
|
{
|
|
|
|
GodmodeState* state = GODMODE();
|
|
|
|
|
|
|
|
state->serialPort[0].dataIn = ""; // the queue of data waiting to be read
|
|
|
|
state->serialPort[0].dataOut = ""; // the history of data written
|
|
|
|
|
|
|
|
fprintf(stderr, "default there is no data on the Serial bus\n");
|
|
|
|
assertEqual(-1, Serial.peek());
|
|
|
|
assertEqual("", state->serialPort[0].dataIn);
|
|
|
|
assertEqual("", state->serialPort[0].dataOut);
|
|
|
|
|
|
|
|
COZIR co(&Serial);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.init()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.init();
|
|
|
|
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.getVersionSerial()\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.getVersionSerial();
|
2021-02-03 11:20:20 -05:00
|
|
|
assertEqual("K 0\r\nY\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.getConfiguration()\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.getConfiguration();
|
2021-02-03 11:20:20 -05:00
|
|
|
assertEqual("K 0\r\n*\r\n", state->serialPort[0].dataOut);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_setOperatingMode)
|
|
|
|
{
|
|
|
|
GodmodeState* state = GODMODE();
|
|
|
|
|
|
|
|
COZIR co(&Serial);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.init()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.init();
|
2021-08-15 13:38:45 -04:00
|
|
|
// init() sets CZR_POLLING
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(co.getOperatingMode(), CZR_POLLING);
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
fprintf(stderr, "COZIR.SetOperatingMode(CZR_COMMAND)\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.setOperatingMode(CZR_COMMAND);
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("K 0\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(co.getOperatingMode(), CZR_COMMAND);
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
fprintf(stderr, "COZIR.SetOperatingMode(CZR_STREAMING)\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.setOperatingMode(CZR_STREAMING);
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("K 1\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(co.getOperatingMode(), CZR_STREAMING);
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
fprintf(stderr, "COZIR.SetOperatingMode(CZR_POLLING)\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.setOperatingMode(CZR_POLLING);
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(co.getOperatingMode(), CZR_POLLING);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_read_sensor)
|
|
|
|
{
|
|
|
|
GodmodeState* state = GODMODE();
|
|
|
|
|
|
|
|
COZIR co(&Serial);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.init()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.init();
|
|
|
|
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
fprintf(stderr, "COZIR.Celsius()\n");
|
|
|
|
state->serialPort[0].dataIn = "T 750\r\n"; // 1000 = 0°C
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
float celsius = co.celsius();
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("T\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqualFloat(-25.0, celsius, 0.0001);
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "T 1257\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
celsius = co.celsius();
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("T\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqualFloat(25.7, celsius, 0.0001);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.humidity()\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "H 627\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
float humidity = co.humidity();
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("H\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqualFloat(62.7, humidity, 0.0001);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
fprintf(stderr, "COZIR.light()\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "L 189\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
float light = co.light();
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("L\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(189, light);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.CO2()\n");
|
|
|
|
state->serialPort[0].dataIn = "Z 432\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
float CO2 = co.CO2();
|
|
|
|
assertEqual("Z\r\n", state->serialPort[0].dataOut);
|
|
|
|
assertEqual(432, CO2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_calibrate)
|
|
|
|
{
|
|
|
|
GodmodeState* state = GODMODE();
|
|
|
|
|
|
|
|
COZIR co(&Serial);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.init()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.init();
|
|
|
|
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.fineTuneZeroPoint(400, 382)\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "F 32950\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
uint16_t fineTuneZeroPoint = co.fineTuneZeroPoint(400, 382);
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("F 400 382\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(32950, fineTuneZeroPoint);
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.calibrateFreshAir()\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "G 32950\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
uint16_t calibrateFreshAir = co.calibrateFreshAir();
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("G\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(32950, calibrateFreshAir);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
fprintf(stderr, "COZIR.calibrateNitrogen()\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "U 32590\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
uint16_t calibrateNitrogen = co.calibrateNitrogen();
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("U\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(32590, calibrateNitrogen);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
fprintf(stderr, "COZIR.calibrateKnownGas(100)\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "X 33012\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
uint16_t calibrateKnownGas = co.calibrateKnownGas(100);
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("X 100\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(33012, calibrateKnownGas);
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_digi_filter)
|
|
|
|
{
|
|
|
|
GodmodeState* state = GODMODE();
|
|
|
|
|
|
|
|
COZIR co(&Serial);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.init()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.init();
|
|
|
|
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.setDigiFilter(42)\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.setDigiFilter(42);
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("A 42\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.getDigiFilter()\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "a 42\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
uint8_t digifilter = co.getDigiFilter();
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("a\r\n", state->serialPort[0].dataOut);
|
|
|
|
assertEqual(42, digifilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_streaming_mode)
|
|
|
|
{
|
|
|
|
GodmodeState* state = GODMODE();
|
|
|
|
|
|
|
|
COZIR co(&Serial);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.init()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.init();
|
|
|
|
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(co.getOutputFields(), CZR_NONE);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
fprintf(stderr, "COZIR.setOperatingMode(CZR_STREAMING)\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.setOperatingMode(CZR_STREAMING);
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("K 1\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
fprintf(stderr, "COZIR.setOutputFields(CZR_HUMIDITY | CZR_RAWTEMP | CZR_RAWCO2)\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.setOutputFields(CZR_HUMIDITY | CZR_RAWTEMP | CZR_RAWCO2);
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("M 4226\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(co.getOutputFields(), CZR_HTC);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.inOutputFields()\n");
|
|
|
|
assertTrue(co.inOutputFields(CZR_HUMIDITY));
|
|
|
|
assertTrue(co.inOutputFields(CZR_RAWTEMP));
|
|
|
|
assertTrue(co.inOutputFields(CZR_RAWCO2));
|
|
|
|
assertFalse(co.inOutputFields(CZR_LIGHT));
|
|
|
|
assertFalse(co.inOutputFields(~CZR_HTC));
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
fprintf(stderr, "COZIR.getRecentFields()\n");
|
2021-03-01 04:11:54 -05:00
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.getRecentFields();
|
2021-03-01 04:11:54 -05:00
|
|
|
assertEqual("Q\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.clearOutputFields()\n");
|
2021-03-01 04:11:54 -05:00
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.clearOutputFields();
|
2021-03-01 04:11:54 -05:00
|
|
|
assertEqual("M 1\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
fprintf(stderr, "COZIR.inOutputFields()\n");
|
|
|
|
assertTrue(co.inOutputFields(CZR_NONE));
|
|
|
|
assertFalse(co.inOutputFields(~CZR_NONE));
|
2021-03-01 04:11:54 -05:00
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
fprintf(stderr, "COZIR.getRecentFields()\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co.getRecentFields();
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("Q\r\n", state->serialPort[0].dataOut);
|
|
|
|
// USER MUST READ RETURNED DATA AS IT CAN BE QUITE A LOT.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
unittest(test_eeprom_I)
|
2021-01-29 06:31:58 -05:00
|
|
|
{
|
|
|
|
GodmodeState* state = GODMODE();
|
|
|
|
|
|
|
|
COZIR co(&Serial);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.init()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.init();
|
|
|
|
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
// needs redo
|
|
|
|
fprintf(stderr, "COZIR._setEEPROM(10, 42)\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
co._setEEPROM(10, 42);
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("P 10 42\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
fprintf(stderr, "COZIR._getEEPROM(100)\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
state->serialPort[0].dataIn = "p 42\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
uint8_t getEEPROM = co._getEEPROM(100);
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual("p 100\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(42, getEEPROM);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
unittest(test_eeprom_II)
|
|
|
|
{
|
|
|
|
GodmodeState* state = GODMODE();
|
|
|
|
|
|
|
|
COZIR co(&Serial);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.init()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.init();
|
|
|
|
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.setAutoCalibrationPreload()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.setAutoCalibrationPreload(123);
|
|
|
|
assertEqual("P 3 0\r\nP 4 123\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.getAutoCalibrationPreload()\n");
|
|
|
|
state->serialPort[0].dataIn = "p 01\r\np 42\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
uint16_t ACP = co.getAutoCalibrationPreload();
|
|
|
|
assertEqual("p 3\r\np 4\r\n", state->serialPort[0].dataOut);
|
|
|
|
assertEqual(298, ACP);
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.setAutoCalibrationInterval()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.setAutoCalibrationInterval(123);
|
|
|
|
assertEqual("P 5 0\r\nP 6 123\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.getAutoCalibrationInterval()\n");
|
|
|
|
state->serialPort[0].dataIn = "p 04\r\np 01\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
uint16_t interval = co.getAutoCalibrationInterval();
|
|
|
|
assertEqual("p 5\r\np 6\r\n", state->serialPort[0].dataOut);
|
|
|
|
assertEqual(1025, interval);
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.setAutoCalibrationOn()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.setAutoCalibrationOn();
|
|
|
|
assertEqual("P 7 1\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.setAutoCalibrationOff()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.setAutoCalibrationOff();
|
|
|
|
assertEqual("P 7 0\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.getAutoCalibration()\n");
|
|
|
|
state->serialPort[0].dataIn = "p 01\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
uint8_t AC = co.getAutoCalibration();
|
|
|
|
assertEqual("p 7\r\n", state->serialPort[0].dataOut);
|
|
|
|
assertEqual(1, AC);
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.setAutoCalibrationBackgroundConcentration()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.setAutoCalibrationBackgroundConcentration(524);
|
|
|
|
assertEqual("P 8 2\r\nP 9 12\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.getAutoCalibrationBackgroundConcentration()\n");
|
|
|
|
state->serialPort[0].dataIn = "p 03\r\np 10\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
uint16_t ACBC = co.getAutoCalibrationBackgroundConcentration();
|
|
|
|
assertEqual("p 8\r\np 9\r\n", state->serialPort[0].dataOut);
|
|
|
|
assertEqual(778, ACBC);
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.setAmbientConcentration()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.setAmbientConcentration(1083);
|
|
|
|
assertEqual("P 10 4\r\nP 11 59\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.getAmbientConcentration()\n");
|
|
|
|
state->serialPort[0].dataIn = "p 05\r\np 00\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
uint16_t AMC = co.getAmbientConcentration();
|
|
|
|
assertEqual("p 10\r\np 11\r\n", state->serialPort[0].dataOut);
|
|
|
|
assertEqual(1280, AMC);
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.setBufferClearTime()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.setBufferClearTime(83);
|
|
|
|
assertEqual("P 12 0\r\nP 13 83\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.getBufferClearTime()\n");
|
|
|
|
state->serialPort[0].dataIn = "p 06\r\np 01\r\n";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
uint16_t BCT = co.getBufferClearTime();
|
|
|
|
assertEqual("p 12\r\np 13\r\n", state->serialPort[0].dataOut);
|
|
|
|
assertEqual(1537, BCT);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-03-01 04:11:54 -05:00
|
|
|
unittest(test_PPM)
|
|
|
|
{
|
|
|
|
GodmodeState* state = GODMODE();
|
|
|
|
|
|
|
|
COZIR co(&Serial);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.init()\n");
|
|
|
|
state->serialPort[0].dataIn = "";
|
|
|
|
state->serialPort[0].dataOut = "";
|
|
|
|
co.init();
|
|
|
|
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
|
|
|
|
|
|
|
|
fprintf(stderr, "COZIR.getPPMFactor()\n");
|
2021-08-15 13:38:45 -04:00
|
|
|
state->serialPort[0].dataIn = "p 01\r\n";
|
2021-03-01 04:11:54 -05:00
|
|
|
state->serialPort[0].dataOut = "";
|
2021-08-15 13:38:45 -04:00
|
|
|
uint16_t ppm = co.getPPMFactor();
|
2021-03-01 04:11:54 -05:00
|
|
|
assertEqual(".\r\n", state->serialPort[0].dataOut);
|
2021-08-15 13:38:45 -04:00
|
|
|
assertEqual(1, ppm);
|
2021-03-01 04:11:54 -05:00
|
|
|
|
2021-08-15 13:38:45 -04:00
|
|
|
fprintf(stderr, "\n===========================================\n\n");
|
|
|
|
}
|
2021-03-01 04:11:54 -05:00
|
|
|
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_main()
|
|
|
|
|
|
|
|
// --------
|