58 #include "rnr/rnrconfig.h" 78 static const char *SubSysName =
"WatchDog";
84 printSubHdr(
"Initialize WatchDog");
92 printTestResult(PassTag,
"Communication interface %s is open.",
98 printTestResult(FatalTag,
99 "Communication interface not open - cannot continue.");
112 printSubHdr(
"Read WatchDog Info");
117 printTestResult(FailTag,
"%s: Failed to read firmware version number.",
123 printTestResult(PassTag,
"%s: Read firmware version number.", SubSysName);
128 printf(
" Name: %s\n", SubSysName);
129 printf(
" Desc: Arduino compatible Atmega328 sub-processor\n");
130 printf(
" FW Version: %u\n", uVerNum);
137 static uint_t alarms[] =
144 LaeWdArgAlarmBatt | LaeWdArgAlarmBattCrit,
145 LaeWdArgAlarmTemp | LaeWdArgAlarmCrit,
149 static const char *names[] =
151 "no",
"general",
"battery",
"temperature",
"estop",
152 "battery critical",
"temperature critical",
158 printSubHdr(
"Test WatchDog Alarm Control");
160 for(
size_t i = 0; i < arraysize(names); ++i)
163 printf(
"%s Set %s alarms = (0x%04x)\r", WaitTag, names[i], alarms[i]);
167 printf(
"%s\n", FailTag);
172 printf(
"%s\n", PassTag);
182 static uint_t charge[] =
184 100, 90, 75, 60, 50, 40, 25, 10, 0, 100
189 printSubHdr(
"Test Battery Charge LED Control");
191 for(
size_t i = 0; i < arraysize(charge); ++i)
194 printf(
"%s Set battery charge to %u%%\r", WaitTag, charge[i]);
198 printf(
"%s\n", FailTag);
203 printf(
"%s\n", PassTag);
213 static byte_t rgb[][3] =
215 {255, 0, 0}, {255, 255, 0}, {0, 255, 0},
216 {0, 255, 255}, {0, 0, 255}, {255, 0, 255}
219 static const char *colors[] =
221 "red",
"yellow",
"green",
"cyan",
"blue",
"magenta" 226 printSubHdr(
"Test USER LED Control");
228 for(
size_t i = 0; i < arraysize(colors); ++i)
231 printf(
"%s Set RGB LED to %s = (%u, %u, %u)\r",
232 WaitTag, colors[i], rgb[i][0], rgb[i][1], rgb[i][2]);
234 if( WatchDog.
cmdSetRgbLed(rgb[i][0], rgb[i][1], rgb[i][2]) < 0 )
236 printf(
"%s\n", FailTag);
241 printf(
"%s\n", PassTag);
249 printTestResult(FailTag,
"Failed to reset RGB LED to state defaults.");
253 printTestResult(PassTag,
"Reset RGB LED to state defaults.");
267 printSubHdr(
"Test Digital I/O Control");
269 for(pin = LaeWdArgDPinNumMin; pin <= LaeWdArgDPinNumMax; ++pin)
271 printf(
"%s * Pin %u\n", WaitTag, pin);
277 if( WatchDog.
cmdConfigDPin(pin, LaeWdArgDPinDirOut) == LAE_OK )
286 printTestResult(sTag,
"Configure digital pin %u to output.", pin);
292 value = LaeWdArgDPinValHigh;
302 printTestResult(sTag,
"Write digital pin %u value to high=%u.", pin, value);
312 printTestResult(sTag,
"Read digital pin %u value=%u.", pin, value);
317 printTestResult(sTag,
"Read digital pin %u.", pin);
324 value = LaeWdArgDPinValLow;
334 printTestResult(sTag,
"Write digital pin %u value to low=%u.", pin, value);
347 printSubHdr(
"Test Analog Output");
349 for(pin = LaeWdArgAOutPinNumMin; pin <= LaeWdArgAOutPinNumMax; ++pin)
351 printf(
"%s * Pin %u\n", WaitTag, pin);
357 value = LaeWdArgAOutPinValMax;
367 printTestResult(sTag,
"Write pin %u analog value=%u.", pin, value);
373 value = LaeWdArgDPinValLow;
383 printTestResult(sTag,
"Write pin %u digital value to low=%u.", pin, value);
397 printSubHdr(
"Test Analog Input");
399 for(pin = LaeWdArgAInPinNumMin; pin <= LaeWdArgAInPinNumMax; ++pin)
401 printf(
"%s * Pin %u\n", WaitTag, pin);
411 printTestResult(sTag,
"Read analog pin %u value=%u.", pin, value);
416 printTestResult(sTag,
"Read analog pin %u.", pin);
428 printHdr(
"WatchDog Diagnostics");
433 statsTest = initWatchDog();
434 printSubTotals(statsTest);
435 statsTotal += statsTest;
440 if( !statsTotal.fatal )
442 statsTest = readInfo();
443 printSubTotals(statsTest);
444 statsTotal += statsTest;
450 if( !statsTotal.fatal )
452 statsTest = testAlarms();
453 printSubTotals(statsTest);
454 statsTotal += statsTest;
460 if( !statsTotal.fatal )
462 statsTest = testBatteryCharge();
463 printSubTotals(statsTest);
464 statsTotal += statsTest;
470 if( !statsTotal.fatal )
472 statsTest = testLeds();
473 printSubTotals(statsTest);
474 statsTotal += statsTest;
480 if( !statsTotal.fatal )
482 statsTest = testDigitalIO();
483 printSubTotals(statsTest);
484 statsTotal += statsTest;
490 if( !statsTotal.fatal )
492 statsTest = testAnalogOutput();
493 printSubTotals(statsTest);
494 statsTotal += statsTest;
500 if( !statsTotal.fatal )
502 statsTest = testAnalogInput();
503 printSubTotals(statsTest);
504 statsTotal += statsTest;
510 printTotals(statsTotal);
virtual int cmdReadDPin(uint_t pin, uint_t &val)
Read the value of a digital pin command.
std::string getDevName()
Get associated I2C device name.
virtual int cmdWriteDPin(uint_t pin, uint_t val)
Write a value to a digital pin command.
Laelaps WatchDog software class interface.
Laelaps I2C class interface.
virtual int cmdResetRgbLed()
Reset the LED RGB color to state defaults.
virtual int cmdSetBatterySoC(uint_t uBatterySoC)
Set battery's state of charge state command.
virtual int cmdSetRgbLed(uint_t red, uint_t green, uint_t blue)
Set the LED RGB color command.
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Simple diagnostics statistics class.
Laelaps common utilities.
bool isOpen()
Check if device is open.
virtual int cmdReadAPin(uint_t pin, uint_t &val)
Read the value of an analog pin command.
Laelaps built-in Arduino sub-processor.
virtual int cmdGetFwVersion(uint_t &uVerNum)
Get the firmware version command.
virtual int cmdConfigDPin(uint_t pin, uint_t dir)
Configure a digital pin command.
virtual int cmdWriteAPin(uint_t pin, uint_t val)
Write the value to an analog pin command.
Top-level package include file.
virtual int cmdSetAlarms(uint_t uAlarms)
Set (clear) alarms command.