source: examples-v2/micromonitor/diagnostics/main.c @ c304643

4.11
Last change on this file since c304643 was 9a0cbfd, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 6, 2009 at 11:23:20 PM

2009-08-06 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?, README, diagnostics/README, diagnostics/cfg.h, diagnostics/cli.h, diagnostics/cstart.c, diagnostics/main.c, diagnostics/makefile, diagnostics/monlib.c, diagnostics/monlib.h, diagnostics/tfs.h, umon/Makefile, umon/README, umon/test.c: New files.
  • Property mode set to 100755
File size: 1.2 KB
Line 
1/*
2 * This file is a simple example of a "diagnostic" program that
3 * could be run before a real application.
4 *
5 * main():
6 * The main() function demonstrates a simple way to communicate the diagnostics
7 * result back to the MicroMonitor script.
8 */
9
10#include "monlib.h"
11
12int getakey(void)
13{
14  while(!mon_gotachar());
15  return mon_getchar();
16}
17
18int
19main(int argc,char *argv[])
20{
21  char *result = (char *)0;
22
23  mon_printf(
24    "\n\nDiagnotics Program\n"
25    "Should the diagnostics return p (pass), u (unknown), f (fail)? >"
26  );
27
28  /*
29   *  Run the diagnostics.  OK in this case, we are just asking the
30   *  user to decide if they passed or failed.
31   */
32  while (1) {
33     int c = getakey();
34     mon_printf( "%c\n", c);
35     if ( c == 'p' ) {
36       result = "PASS";
37       break;
38     }
39     if ( c == 'f' ) {
40       result = "FAIL";
41       break;
42     }
43     if ( c == 'u' ) {
44       result = "UNKNOWN";
45       break;
46     }
47     mon_printf( "Unknown response %c -- try again\n", c );
48  }
49
50  /*
51   * We broke out of the loop so must have a result.
52   */
53  mon_setenv( "DIAGNOSTICS_RESULT", result );
54
55  mon_printf(
56    "Set DIAGNOSTICS_RESULT to %s\n"
57    "At the MicroMonitor prompt: echo $DIAGNOSTICS_RESULT\n",
58    mon_getenv("DIAGNOSTICS_RESULT")
59  );
60 
61  return 0;
62}
Note: See TracBrowser for help on using the repository browser.