This package contains a simple test of tests for various elements of the SmartBoard hardware, which is a simple baseboard designed for easy embedding. It is able to run both a semi-automatic test suite as well as allow interactive testing.

Dependencies:   EthernetNetIf NTPClient_NetServices mbed

This program is most of what you need to test your SmartBoard baseboard hardware. It provides a means to test the following:

  • Two channels of CAN (with a loopback cable)
  • RS-232 Ports
  • Analog inputs
  • PWM outputs
  • Ethernet port
  • Real time clock
  • micro SD
  • USB Host port
Committer:
WiredHome
Date:
Sun Jan 16 18:30:14 2011 +0000
Revision:
0:5db287f0060b
Child:
1:586392c0e935
First release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:5db287f0060b 1 /// @file SmartBoard_Tester.cpp is the simple test framework
WiredHome 0:5db287f0060b 2 ///
WiredHome 0:5db287f0060b 3 /// This file contains the startup, interactive, and test code
WiredHome 0:5db287f0060b 4 /// to evaluate the SmartBoard baseboard.
WiredHome 0:5db287f0060b 5 ///
WiredHome 0:5db287f0060b 6 /// @note Copyright © 2011 by Smartware Computing, all rights reserved.
WiredHome 0:5db287f0060b 7 /// @author David Smart
WiredHome 0:5db287f0060b 8 ///
WiredHome 0:5db287f0060b 9 #include "mbed.h"
WiredHome 0:5db287f0060b 10 #include "SmartBoard.h"
WiredHome 0:5db287f0060b 11 #include "ShowTime.h"
WiredHome 0:5db287f0060b 12 #include "EthernetNetIf.h"
WiredHome 0:5db287f0060b 13 #include "NTPClient.h"
WiredHome 0:5db287f0060b 14 #include "SDFileSystem.h"
WiredHome 0:5db287f0060b 15 #include "MSCFileSystem.h"
WiredHome 0:5db287f0060b 16
WiredHome 0:5db287f0060b 17 Serial pc(USBTX, USBRX); ///< Used as the console for interactively reporting progress
WiredHome 0:5db287f0060b 18
WiredHome 0:5db287f0060b 19 const char * TicTocServer = "ntp.okstate.edu"; ///< time server since it is closer than "0.uk.pool.ntp.org"
WiredHome 0:5db287f0060b 20 const int tzOffsetHr = -6; ///< time zone offset hours to print time in local time
WiredHome 0:5db287f0060b 21 const int tzOffsetMin = 0; ///< time zone offset minutes to print time in local time
WiredHome 0:5db287f0060b 22
WiredHome 0:5db287f0060b 23 void LED_Tests(void);
WiredHome 0:5db287f0060b 24 void PWM_Tests(void);
WiredHome 0:5db287f0060b 25 void AnalogIn_Tests(void);
WiredHome 0:5db287f0060b 26 void RTC_Tests(void);
WiredHome 0:5db287f0060b 27 void MicroSD_Tests(void);
WiredHome 0:5db287f0060b 28 void RS_232_Tests(void);
WiredHome 0:5db287f0060b 29 void CAN_Tests(void);
WiredHome 0:5db287f0060b 30 void Ethernet_Tests(void);
WiredHome 0:5db287f0060b 31 void USBHost_Tests(void);
WiredHome 0:5db287f0060b 32
WiredHome 0:5db287f0060b 33 /// TestVector will execute a given test, based on the parameter
WiredHome 0:5db287f0060b 34 ///
WiredHome 0:5db287f0060b 35 /// It can show the list of available commands, as for an interactive
WiredHome 0:5db287f0060b 36 /// test session, or it can simply execute the chosen test. This is
WiredHome 0:5db287f0060b 37 /// used for both the automated testing and the interactive testing,
WiredHome 0:5db287f0060b 38 /// so a couple of the commands for interactive would not be used
WiredHome 0:5db287f0060b 39 /// for the automated testing.
WiredHome 0:5db287f0060b 40 /// '?' causes it to display the available commands.
WiredHome 0:5db287f0060b 41 ///
WiredHome 0:5db287f0060b 42 /// @param i contains the single character value indicating the operation
WiredHome 0:5db287f0060b 43 /// to perform.
WiredHome 0:5db287f0060b 44 /// @returns false if the input paramter was 'X'.
WiredHome 0:5db287f0060b 45 /// @returns true if the input parameters was not 'X'.
WiredHome 0:5db287f0060b 46 ///
WiredHome 0:5db287f0060b 47 bool TestVector(int i) {
WiredHome 0:5db287f0060b 48 bool r = true; ///< expect to return true
WiredHome 0:5db287f0060b 49
WiredHome 0:5db287f0060b 50 switch (i) {
WiredHome 0:5db287f0060b 51 default:
WiredHome 0:5db287f0060b 52 case '?':
WiredHome 0:5db287f0060b 53 pc.printf("Commands:\r\nx"
WiredHome 0:5db287f0060b 54 " L LED_Tests();\r\n"
WiredHome 0:5db287f0060b 55 " P PWM_Tests(); // note interaction between LEDs and PWMs\r\n"
WiredHome 0:5db287f0060b 56 " A AnalogIn_Tests();\r\n"
WiredHome 0:5db287f0060b 57 " R RTC_Tests();\r\n"
WiredHome 0:5db287f0060b 58 " M MicroSD_Tests();\r\n"
WiredHome 0:5db287f0060b 59 " S RS_232_Tests();\r\n"
WiredHome 0:5db287f0060b 60 " C CAN_Tests();\r\n"
WiredHome 0:5db287f0060b 61 " E Ethernet_Tests();\r\n"
WiredHome 0:5db287f0060b 62 " U USBHost_Tests();\r\n"
WiredHome 0:5db287f0060b 63 " X eXit to automatic testing\r\n");
WiredHome 0:5db287f0060b 64 break;
WiredHome 0:5db287f0060b 65 case 'X':
WiredHome 0:5db287f0060b 66 r = false;
WiredHome 0:5db287f0060b 67 break;
WiredHome 0:5db287f0060b 68 case 'L':
WiredHome 0:5db287f0060b 69 LED_Tests();
WiredHome 0:5db287f0060b 70 break;
WiredHome 0:5db287f0060b 71 case 'P':
WiredHome 0:5db287f0060b 72 PWM_Tests();
WiredHome 0:5db287f0060b 73 break;
WiredHome 0:5db287f0060b 74 case 'A':
WiredHome 0:5db287f0060b 75 AnalogIn_Tests();
WiredHome 0:5db287f0060b 76 break;
WiredHome 0:5db287f0060b 77 case 'R':
WiredHome 0:5db287f0060b 78 RTC_Tests();
WiredHome 0:5db287f0060b 79 break;
WiredHome 0:5db287f0060b 80 case 'M':
WiredHome 0:5db287f0060b 81 MicroSD_Tests();
WiredHome 0:5db287f0060b 82 break;
WiredHome 0:5db287f0060b 83 case 'S':
WiredHome 0:5db287f0060b 84 RS_232_Tests();
WiredHome 0:5db287f0060b 85 break;
WiredHome 0:5db287f0060b 86 case 'C':
WiredHome 0:5db287f0060b 87 CAN_Tests();
WiredHome 0:5db287f0060b 88 break;
WiredHome 0:5db287f0060b 89 case 'E':
WiredHome 0:5db287f0060b 90 Ethernet_Tests();
WiredHome 0:5db287f0060b 91 break;
WiredHome 0:5db287f0060b 92 case 'U':
WiredHome 0:5db287f0060b 93 USBHost_Tests();
WiredHome 0:5db287f0060b 94 break;
WiredHome 0:5db287f0060b 95 }
WiredHome 0:5db287f0060b 96 return r;
WiredHome 0:5db287f0060b 97 }
WiredHome 0:5db287f0060b 98
WiredHome 0:5db287f0060b 99 /// main is the main startup code.
WiredHome 0:5db287f0060b 100 ///
WiredHome 0:5db287f0060b 101 /// This initializes the test environment, shows a banner,
WiredHome 0:5db287f0060b 102 /// and starts the automated testing.
WiredHome 0:5db287f0060b 103 /// It also detects if the user is attempting to interact, and
WiredHome 0:5db287f0060b 104 /// between each test category there is the possibility to transfer
WiredHome 0:5db287f0060b 105 /// to the interactive test mode.
WiredHome 0:5db287f0060b 106 /// When in interactive test mode, the user determines which test
WiredHome 0:5db287f0060b 107 /// to run. The user can also exit interactive mode back to the
WiredHome 0:5db287f0060b 108 /// automated test mode.
WiredHome 0:5db287f0060b 109 ///
WiredHome 0:5db287f0060b 110 /// @returns never
WiredHome 0:5db287f0060b 111 ///
WiredHome 0:5db287f0060b 112 int main() {
WiredHome 0:5db287f0060b 113 bool init = true; ///< init is slightly different
WiredHome 0:5db287f0060b 114 bool interactive = false; ///< track when in interactive mode
WiredHome 0:5db287f0060b 115 int test = 0; ///< which test to run
WiredHome 0:5db287f0060b 116 char TestList[] = "XLPARMSCEU"; ///< list of valid test commands
WiredHome 0:5db287f0060b 117
WiredHome 0:5db287f0060b 118 while (1) {
WiredHome 0:5db287f0060b 119 if (pc.readable() || init) {
WiredHome 0:5db287f0060b 120 pc.printf("\r\n\r\n");
WiredHome 0:5db287f0060b 121 pc.printf("SmartBoard Hardware Tester\r\n");
WiredHome 0:5db287f0060b 122 pc.printf(" SmartBoard Hardware v0.05\r\n");
WiredHome 0:5db287f0060b 123 pc.printf(" SmartBoard Software v0.07\r\n");
WiredHome 0:5db287f0060b 124 pc.printf("\r\n");
WiredHome 0:5db287f0060b 125 pc.printf(" [USB] [Eth/USB] \r\n");
WiredHome 0:5db287f0060b 126 pc.printf(" +---------------+------------+---+-------+---+\r\n");
WiredHome 0:5db287f0060b 127 pc.printf(" |O [RS232 1-2] | | | | | | O|\r\n");
WiredHome 0:5db287f0060b 128 pc.printf(" | | |microSD| | | | |\r\n");
WiredHome 0:5db287f0060b 129 pc.printf(" |S | | | | | | C|\r\n");
WiredHome 0:5db287f0060b 130 pc.printf(" |P | +-------+ | | | A|\r\n");
WiredHome 0:5db287f0060b 131 pc.printf(" |I | | |Yl Gr| N|\r\n");
WiredHome 0:5db287f0060b 132 pc.printf(" |1 | | +-------+ 1|\r\n");
WiredHome 0:5db287f0060b 133 pc.printf(" |- | | -|\r\n");
WiredHome 0:5db287f0060b 134 pc.printf(" |2 | RTC | 2|\r\n");
WiredHome 0:5db287f0060b 135 pc.printf(" | | (Battery) | |\r\n");
WiredHome 0:5db287f0060b 136 pc.printf(" | | | |\r\n");
WiredHome 0:5db287f0060b 137 pc.printf(" | | 1 2 3 4 | |\r\n");
WiredHome 0:5db287f0060b 138 pc.printf(" | +------------+ |\r\n");
WiredHome 0:5db287f0060b 139 pc.printf(" |O[Analog In ] O [PWM Out] O|\r\n");
WiredHome 0:5db287f0060b 140 pc.printf(" +--------------------------------------------+\r\n");
WiredHome 0:5db287f0060b 141 pc.printf("\r\n");
WiredHome 0:5db287f0060b 142 init = false;
WiredHome 0:5db287f0060b 143 }
WiredHome 0:5db287f0060b 144 if (pc.readable()) {
WiredHome 0:5db287f0060b 145 interactive = true;
WiredHome 0:5db287f0060b 146 while (pc.readable())
WiredHome 0:5db287f0060b 147 (void)pc.getc();
WiredHome 0:5db287f0060b 148
WiredHome 0:5db287f0060b 149 while (interactive) {
WiredHome 0:5db287f0060b 150 pc.printf("> ");
WiredHome 0:5db287f0060b 151 int i = pc.getc();
WiredHome 0:5db287f0060b 152 pc.putc(i);
WiredHome 0:5db287f0060b 153 pc.putc('\r');
WiredHome 0:5db287f0060b 154 pc.putc('\n');
WiredHome 0:5db287f0060b 155 interactive = TestVector(i);
WiredHome 0:5db287f0060b 156 }
WiredHome 0:5db287f0060b 157 } else {
WiredHome 0:5db287f0060b 158 if (test == 0)
WiredHome 0:5db287f0060b 159 pc.printf("\x07"); // Bell character indicating start of tests
WiredHome 0:5db287f0060b 160 TestVector(TestList[test++]);
WiredHome 0:5db287f0060b 161 if (TestList[test] == '\0')
WiredHome 0:5db287f0060b 162 test = 0;
WiredHome 0:5db287f0060b 163 wait(5.0); // Extra pause
WiredHome 0:5db287f0060b 164 }
WiredHome 0:5db287f0060b 165 }
WiredHome 0:5db287f0060b 166 }
WiredHome 0:5db287f0060b 167
WiredHome 0:5db287f0060b 168 /// LED_Tests performs some simple digital output to the
WiredHome 0:5db287f0060b 169 /// LEDs.
WiredHome 0:5db287f0060b 170 ///
WiredHome 0:5db287f0060b 171 /// It will attempt to exercise the LEDs on the Ethernet ports
WiredHome 0:5db287f0060b 172 /// as well, but by jumper configuration these may not be available.
WiredHome 0:5db287f0060b 173 ///
WiredHome 0:5db287f0060b 174 void LED_Tests(void) {
WiredHome 0:5db287f0060b 175 int l;
WiredHome 0:5db287f0060b 176 int i;
WiredHome 0:5db287f0060b 177 struct {
WiredHome 0:5db287f0060b 178 const char * name;
WiredHome 0:5db287f0060b 179 DigitalOut led;
WiredHome 0:5db287f0060b 180 } Leds[] = {
WiredHome 0:5db287f0060b 181 {"Ethernet Green", ETHERGREEN},
WiredHome 0:5db287f0060b 182 {"Ethernet Yellow", ETHERYELLOW},
WiredHome 0:5db287f0060b 183 {"Led 1", LED1},
WiredHome 0:5db287f0060b 184 {"Led 2", LED2},
WiredHome 0:5db287f0060b 185 {"Led 3", LED3},
WiredHome 0:5db287f0060b 186 {"Led 4", LED4}
WiredHome 0:5db287f0060b 187 };
WiredHome 0:5db287f0060b 188 const int numLeds = sizeof(Leds) / sizeof(Leds[0]);
WiredHome 0:5db287f0060b 189
WiredHome 0:5db287f0060b 190 printf("LED Test:\r\n");
WiredHome 0:5db287f0060b 191 for (l=0; l<numLeds; l++) {
WiredHome 0:5db287f0060b 192 printf(" Blink %s LED 3 times\r\n", Leds[l].name);
WiredHome 0:5db287f0060b 193 for (i=0; i<3; i++) {
WiredHome 0:5db287f0060b 194 Leds[l].led = true;
WiredHome 0:5db287f0060b 195 wait(0.4);
WiredHome 0:5db287f0060b 196 Leds[l].led = false;
WiredHome 0:5db287f0060b 197 wait(0.4);
WiredHome 0:5db287f0060b 198 }
WiredHome 0:5db287f0060b 199 }
WiredHome 0:5db287f0060b 200 }
WiredHome 0:5db287f0060b 201
WiredHome 0:5db287f0060b 202 /// PWM_Tests performs some simple pwm output to the
WiredHome 0:5db287f0060b 203 /// PWM channels and the LEDs.
WiredHome 0:5db287f0060b 204 ///
WiredHome 0:5db287f0060b 205 /// It will attempt to exercise the outputs with a simple ramping
WiredHome 0:5db287f0060b 206 /// signal, but by jumper configuration these may not be available.
WiredHome 0:5db287f0060b 207 ///
WiredHome 0:5db287f0060b 208 void PWM_Tests(void) {
WiredHome 0:5db287f0060b 209 int l;
WiredHome 0:5db287f0060b 210 int i;
WiredHome 0:5db287f0060b 211 float f;
WiredHome 0:5db287f0060b 212 struct {
WiredHome 0:5db287f0060b 213 const char * name;
WiredHome 0:5db287f0060b 214 PwmOut pwm;
WiredHome 0:5db287f0060b 215 } Pwms[] = {
WiredHome 0:5db287f0060b 216 {"PWM 1", p21},
WiredHome 0:5db287f0060b 217 {"PWM 2", p22},
WiredHome 0:5db287f0060b 218 {"PWM 3", p23},
WiredHome 0:5db287f0060b 219 {"PWM 4", p24},
WiredHome 0:5db287f0060b 220 {"PWM 5", p25},
WiredHome 0:5db287f0060b 221 {"PWM 6", p26},
WiredHome 0:5db287f0060b 222 {"Led 1", LED1},
WiredHome 0:5db287f0060b 223 {"Led 2", LED2},
WiredHome 0:5db287f0060b 224 {"Led 3", LED3},
WiredHome 0:5db287f0060b 225 {"Led 4", LED4}
WiredHome 0:5db287f0060b 226 };
WiredHome 0:5db287f0060b 227 const int numPwms = sizeof(Pwms) / sizeof(Pwms[0]);
WiredHome 0:5db287f0060b 228
WiredHome 0:5db287f0060b 229 printf("PWM Test:\r\n");
WiredHome 0:5db287f0060b 230 for (l=0; l<numPwms; l++) {
WiredHome 0:5db287f0060b 231 printf(" Ramp %s PWM 3 times\r\n", Pwms[l].name);
WiredHome 0:5db287f0060b 232 for (i=0; i<3; i++) {
WiredHome 0:5db287f0060b 233 for (f=0.0; f<=1.0; f+= 0.1) {
WiredHome 0:5db287f0060b 234 Pwms[l].pwm = f;
WiredHome 0:5db287f0060b 235 wait(0.1);
WiredHome 0:5db287f0060b 236 }
WiredHome 0:5db287f0060b 237 }
WiredHome 0:5db287f0060b 238 Pwms[l].pwm = 0; // off when done
WiredHome 0:5db287f0060b 239 }
WiredHome 0:5db287f0060b 240 }
WiredHome 0:5db287f0060b 241
WiredHome 0:5db287f0060b 242 /// AnalogIn_Tests takes a few sample measurements on each channel
WiredHome 0:5db287f0060b 243 ///
WiredHome 0:5db287f0060b 244 /// It samples each channel a number of times and presents the
WiredHome 0:5db287f0060b 245 /// converted results on the console.
WiredHome 0:5db287f0060b 246 ///
WiredHome 0:5db287f0060b 247 void AnalogIn_Tests(void) {
WiredHome 0:5db287f0060b 248 int l;
WiredHome 0:5db287f0060b 249 int i;
WiredHome 0:5db287f0060b 250 const int samples = 20;
WiredHome 0:5db287f0060b 251 struct {
WiredHome 0:5db287f0060b 252 const char * name;
WiredHome 0:5db287f0060b 253 AnalogIn in;
WiredHome 0:5db287f0060b 254 } Analogs[] = {
WiredHome 0:5db287f0060b 255 {"Ain 1", p15},
WiredHome 0:5db287f0060b 256 {"Ain 2", p16},
WiredHome 0:5db287f0060b 257 {"Ain 3", p17},
WiredHome 0:5db287f0060b 258 {"Ain 4", p18},
WiredHome 0:5db287f0060b 259 {"Ain 5", p19},
WiredHome 0:5db287f0060b 260 {"Ain 6", p20}
WiredHome 0:5db287f0060b 261 };
WiredHome 0:5db287f0060b 262 const int numAnalogs = sizeof(Analogs) / sizeof(Analogs[0]);
WiredHome 0:5db287f0060b 263
WiredHome 0:5db287f0060b 264 printf("Analog Test:\r\n");
WiredHome 0:5db287f0060b 265 for (l=0; l<numAnalogs; l++) {
WiredHome 0:5db287f0060b 266 for (i=0; i<samples; i++) {
WiredHome 0:5db287f0060b 267 uint16_t raw = Analogs[l].in.read_u16();
WiredHome 0:5db287f0060b 268 float flt = Analogs[l].in.read();
WiredHome 0:5db287f0060b 269 printf(" Analog %i is %04X, %3.2f, %3.2fv\r", l, raw, flt, flt*3.3);
WiredHome 0:5db287f0060b 270 wait(0.1);
WiredHome 0:5db287f0060b 271 }
WiredHome 0:5db287f0060b 272 printf("\n");
WiredHome 0:5db287f0060b 273 }
WiredHome 0:5db287f0060b 274 }
WiredHome 0:5db287f0060b 275
WiredHome 0:5db287f0060b 276 /// RTC_Tests will perform simple tests on the Real Time Clock
WiredHome 0:5db287f0060b 277 ///
WiredHome 0:5db287f0060b 278 /// It will first sample the time from the RTC and later restore
WiredHome 0:5db287f0060b 279 /// it as best it can.
WiredHome 0:5db287f0060b 280 /// In the middle of that it will set the clock, then simply show
WiredHome 0:5db287f0060b 281 /// the time once per second for 5 seconds. After this it
WiredHome 0:5db287f0060b 282 /// will restore the clock at best it can.
WiredHome 0:5db287f0060b 283 ///
WiredHome 0:5db287f0060b 284 void RTC_Tests(void) {
WiredHome 0:5db287f0060b 285 time_t x;
WiredHome 0:5db287f0060b 286 int i;
WiredHome 0:5db287f0060b 287 const int oldTime = 1256729737;
WiredHome 0:5db287f0060b 288
WiredHome 0:5db287f0060b 289 printf("RTC Test:\r\n");
WiredHome 0:5db287f0060b 290 ShowTime(0, -6, 0);
WiredHome 0:5db287f0060b 291 x = time(NULL); // Save the time before the test
WiredHome 0:5db287f0060b 292 printf(" Saving current time(%d)\r\n", x);
WiredHome 0:5db287f0060b 293
WiredHome 0:5db287f0060b 294 set_time(oldTime); // Set RTC time to Wed, 28 Oct 2009 11:35:37
WiredHome 0:5db287f0060b 295 printf(" Set time to Wed, 28 Oct 2009 11:35:37\r\n");
WiredHome 0:5db287f0060b 296
WiredHome 0:5db287f0060b 297 for (i=0; i<5; i++) {
WiredHome 0:5db287f0060b 298 ShowTime();
WiredHome 0:5db287f0060b 299 wait(1.0);
WiredHome 0:5db287f0060b 300 }
WiredHome 0:5db287f0060b 301 set_time(x + time(NULL) - 1256729737); // Approximately restored
WiredHome 0:5db287f0060b 302 ShowTime(0, -6, 0);
WiredHome 0:5db287f0060b 303 wait(1.0);
WiredHome 0:5db287f0060b 304 ShowTime(0, -6, 0);
WiredHome 0:5db287f0060b 305 }
WiredHome 0:5db287f0060b 306
WiredHome 0:5db287f0060b 307 /// Ethernet_Tests will attempt to test the Ethernet interface
WiredHome 0:5db287f0060b 308 ///
WiredHome 0:5db287f0060b 309 /// It will connect to the network - if possible, then it will
WiredHome 0:5db287f0060b 310 /// try to connect to a network time server and set the clock,
WiredHome 0:5db287f0060b 311 /// using hard coded time server and time zone offset values.
WiredHome 0:5db287f0060b 312 ///
WiredHome 0:5db287f0060b 313 /// It appears that the Ethernet interface cannot be instantiated,
WiredHome 0:5db287f0060b 314 /// destroyed, and later instantiated again (it would reliably "hang").
WiredHome 0:5db287f0060b 315 /// So, this test is "runonce" protected.
WiredHome 0:5db287f0060b 316 ///
WiredHome 0:5db287f0060b 317 void Ethernet_Tests(void) {
WiredHome 0:5db287f0060b 318 EthernetNetIf eth;
WiredHome 0:5db287f0060b 319 NTPClient ntp;
WiredHome 0:5db287f0060b 320 static bool runonce = true;
WiredHome 0:5db287f0060b 321
WiredHome 0:5db287f0060b 322 printf("Ethernet Test:\r\n");
WiredHome 0:5db287f0060b 323 if (runonce) {
WiredHome 0:5db287f0060b 324 EthernetErr ethErr = eth.setup();
WiredHome 0:5db287f0060b 325 if (ethErr) {
WiredHome 0:5db287f0060b 326 printf("Error %d in setup.\r\n", ethErr);
WiredHome 0:5db287f0060b 327 return;
WiredHome 0:5db287f0060b 328 }
WiredHome 0:5db287f0060b 329 printf(" Ethernet Setup OK\r\n");
WiredHome 0:5db287f0060b 330 ShowTime(0, tzOffsetHr, tzOffsetMin);
WiredHome 0:5db287f0060b 331 printf(" Setting clock to %s\r\n", TicTocServer);
WiredHome 0:5db287f0060b 332 Host server(IpAddr(), 123, TicTocServer);
WiredHome 0:5db287f0060b 333 ntp.setTime(server);
WiredHome 0:5db287f0060b 334 printf(" Clock was set.\r\n");
WiredHome 0:5db287f0060b 335 wait(1.0);
WiredHome 0:5db287f0060b 336 ShowTime(0, tzOffsetHr, tzOffsetMin);
WiredHome 0:5db287f0060b 337 runonce = false;
WiredHome 0:5db287f0060b 338 } else {
WiredHome 0:5db287f0060b 339 printf(" only runs once per cold-boot.\r\n");
WiredHome 0:5db287f0060b 340 }
WiredHome 0:5db287f0060b 341 }
WiredHome 0:5db287f0060b 342
WiredHome 0:5db287f0060b 343 /// MicroSD_Tests attempts to access and write a file on the micro SD card
WiredHome 0:5db287f0060b 344 ///
WiredHome 0:5db287f0060b 345 /// It will mount the file system, then attempt to write a simple
WiredHome 0:5db287f0060b 346 /// file on the micro SD card.
WiredHome 0:5db287f0060b 347 ///
WiredHome 0:5db287f0060b 348 void MicroSD_Tests(void) {
WiredHome 0:5db287f0060b 349 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
WiredHome 0:5db287f0060b 350 FILE *fp;
WiredHome 0:5db287f0060b 351 char buffer[50];
WiredHome 0:5db287f0060b 352
WiredHome 0:5db287f0060b 353 printf("SD File System Tests:\r\n");
WiredHome 0:5db287f0060b 354 mkdir("/sd/mydir", 0777);
WiredHome 0:5db287f0060b 355 fp = fopen("/sd/mydir/sdtest.txt", "w");
WiredHome 0:5db287f0060b 356 if (fp == NULL) {
WiredHome 0:5db287f0060b 357 printf(" Could not open file for write\r\n");
WiredHome 0:5db287f0060b 358 } else {
WiredHome 0:5db287f0060b 359 fprintf(fp, "Write a message to the micro SD card!");
WiredHome 0:5db287f0060b 360 fclose(fp);
WiredHome 0:5db287f0060b 361 printf(" Closed file.\r\n");
WiredHome 0:5db287f0060b 362 fp = fopen("/sd/mydir/sdtest.txt", "r");
WiredHome 0:5db287f0060b 363 if (fp) {
WiredHome 0:5db287f0060b 364 printf(" Reading file back.\r\n");
WiredHome 0:5db287f0060b 365 if (fgets(buffer, sizeof(buffer), fp)) {
WiredHome 0:5db287f0060b 366 if (strlen(buffer) > 2)
WiredHome 0:5db287f0060b 367 buffer[strlen(buffer)-2] = '\0'; // chomp the <LF>
WiredHome 0:5db287f0060b 368 printf(" Read: {%s}\r\n", buffer);
WiredHome 0:5db287f0060b 369 }
WiredHome 0:5db287f0060b 370 fclose(fp);
WiredHome 0:5db287f0060b 371 }
WiredHome 0:5db287f0060b 372 }
WiredHome 0:5db287f0060b 373 printf(" test complete!\r\n");
WiredHome 0:5db287f0060b 374 }
WiredHome 0:5db287f0060b 375
WiredHome 0:5db287f0060b 376
WiredHome 0:5db287f0060b 377 /// USBHost_Tests attempts to access and write a file on USB stick
WiredHome 0:5db287f0060b 378 ///
WiredHome 0:5db287f0060b 379 /// It will mount the file system, then attempt to write a simple
WiredHome 0:5db287f0060b 380 /// file on the USB interface.
WiredHome 0:5db287f0060b 381 ///
WiredHome 0:5db287f0060b 382 void USBHost_Tests(void) {
WiredHome 0:5db287f0060b 383 MSCFileSystem fs ("fs");
WiredHome 0:5db287f0060b 384 FILE *fp;
WiredHome 0:5db287f0060b 385 char buffer[50];
WiredHome 0:5db287f0060b 386
WiredHome 0:5db287f0060b 387 printf("USB Host Tests: [installed memory stick required]\r\n");
WiredHome 0:5db287f0060b 388 fp = fopen("/fs/hello.txt","w");
WiredHome 0:5db287f0060b 389 if (fp) {
WiredHome 0:5db287f0060b 390 printf(" Writing to hello.txt file\r\n");
WiredHome 0:5db287f0060b 391 fprintf(fp,"Hello world!\r\n");
WiredHome 0:5db287f0060b 392 fclose (fp);
WiredHome 0:5db287f0060b 393 printf(" Closed file.\r\n");
WiredHome 0:5db287f0060b 394 fp = fopen("/fs/hello.txt", "r");
WiredHome 0:5db287f0060b 395 if (fp) {
WiredHome 0:5db287f0060b 396 printf(" Reading file back.\r\n");
WiredHome 0:5db287f0060b 397 if (fgets(buffer, sizeof(buffer), fp)) {
WiredHome 0:5db287f0060b 398 if (strlen(buffer) > 2)
WiredHome 0:5db287f0060b 399 buffer[strlen(buffer)-2] = '\0'; // chomp the <LF>
WiredHome 0:5db287f0060b 400 printf(" Read: {%s}\r\n", buffer);
WiredHome 0:5db287f0060b 401 }
WiredHome 0:5db287f0060b 402 fclose(fp);
WiredHome 0:5db287f0060b 403 }
WiredHome 0:5db287f0060b 404 }
WiredHome 0:5db287f0060b 405 }
WiredHome 0:5db287f0060b 406
WiredHome 0:5db287f0060b 407 /// CAN_Tests will send some packets on one CAN port and expect them on the other
WiredHome 0:5db287f0060b 408 ///
WiredHome 0:5db287f0060b 409 /// It will attempt to send 10 messages on one port and expect that
WiredHome 0:5db287f0060b 410 /// all 10 messages were received on the other port. The two ports should
WiredHome 0:5db287f0060b 411 /// be wired from one to the other with a loop-back cable and a termination
WiredHome 0:5db287f0060b 412 /// resistor.
WiredHome 0:5db287f0060b 413 ///
WiredHome 0:5db287f0060b 414 void CAN_Tests(void) {
WiredHome 0:5db287f0060b 415 CAN can1(p9, p10);
WiredHome 0:5db287f0060b 416 CAN can2(p30, p29);
WiredHome 0:5db287f0060b 417 char Txcounter = 0;
WiredHome 0:5db287f0060b 418 char Rxcounter = 0;
WiredHome 0:5db287f0060b 419 CANMessage msg;
WiredHome 0:5db287f0060b 420 int i;
WiredHome 0:5db287f0060b 421
WiredHome 0:5db287f0060b 422 printf("CAN Tests:\r\n");
WiredHome 0:5db287f0060b 423 for (i=0; i<10; i++) {
WiredHome 0:5db287f0060b 424 if (can1.write(CANMessage(1337, &Txcounter, 1))) {
WiredHome 0:5db287f0060b 425 Txcounter++;
WiredHome 0:5db287f0060b 426 printf(" Message sent: %d\r\n", Txcounter);
WiredHome 0:5db287f0060b 427 wait(0.05);
WiredHome 0:5db287f0060b 428 }
WiredHome 0:5db287f0060b 429 if (can2.read(msg)) {
WiredHome 0:5db287f0060b 430 printf(" Message received: %d\r\n", msg.data[0]);
WiredHome 0:5db287f0060b 431 Rxcounter++;
WiredHome 0:5db287f0060b 432 }
WiredHome 0:5db287f0060b 433 wait(0.2);
WiredHome 0:5db287f0060b 434 }
WiredHome 0:5db287f0060b 435 if (Txcounter == Rxcounter)
WiredHome 0:5db287f0060b 436 printf(" passed.\r\n");
WiredHome 0:5db287f0060b 437 else
WiredHome 0:5db287f0060b 438 printf(" **** Txcounter (%d) != Rxcounter (%d) ****\r\n", Txcounter, Rxcounter);
WiredHome 0:5db287f0060b 439 }
WiredHome 0:5db287f0060b 440
WiredHome 0:5db287f0060b 441 /// RS_232_Tests will say hello on each of the RS-232 channels
WiredHome 0:5db287f0060b 442 ///
WiredHome 0:5db287f0060b 443 /// It will print a hello text string out each of the ports.
WiredHome 0:5db287f0060b 444 ///
WiredHome 0:5db287f0060b 445 void RS_232_Tests(void) {
WiredHome 0:5db287f0060b 446 Serial s1(p13, p14);
WiredHome 0:5db287f0060b 447 Serial s2(p28, p27);
WiredHome 0:5db287f0060b 448
WiredHome 0:5db287f0060b 449 pc.printf("RS-232 Tests:\r\n");
WiredHome 0:5db287f0060b 450 s1.printf(" Hello going out S1\r\n");
WiredHome 0:5db287f0060b 451 s2.printf(" Hello going out S2\r\n");
WiredHome 0:5db287f0060b 452 pc.printf(" end tests.\r\n");
WiredHome 0:5db287f0060b 453 }