home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / wincam.zip / winc_src.zip / diags.c < prev    next >
C/C++ Source or Header  |  1997-02-28  |  3KB  |  97 lines

  1. /*
  2.  *
  3.  * run wincam diagnostics
  4.  *
  5.  * Copyright (C) 1996, Paul G. Fox
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify it
  8.  * under the terms of the GNU General Public License as published by the
  9.  * Free Software Foundation; either version 2 of the License, or (at your
  10.  * option) any later version.
  11.  * 
  12.  * This program is distributed in the hope that it will be useful, but
  13.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU General Public License along
  18.  * with this program; if not, write to the Free Software Foundation, Inc.,
  19.  * 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  * This software was created with the help of proprietary information
  22.  * belonging to StarDot Technologies.
  23.  *
  24.  * $Header: E:/winc/RCS/diags.c 1.1 1997/03/01 03:44:14 Derek Exp Derek $
  25.  */
  26. #define NDEBUG 1
  27.  
  28. #include <stdlib.h>
  29. #include <unistd.h>
  30. #include <errno.h>
  31. #include <termios.h>
  32. #include <assert.h>
  33. #include <string.h>
  34. #include "private.h"
  35. #include "trace.h"
  36.  
  37. #define SENDBYTES 0x55, 0xaa, 0x80, 0x01, 0xff, 0x00 
  38.  
  39. result
  40. winc_diagnose( cam_t cam )
  41. {
  42.     int i;
  43.     byte retbytes[256];
  44.     byte sendbytes[6] = { SENDBYTES };
  45.  
  46.     assert(cam);
  47.  
  48.     TRACE("da", "Running camera diagnostics...\n");
  49.     TRACE("dA", __FILE__ ": running receive test\n");
  50.     if (winc_send_cmd(cam, Cmd_rx_test, SENDBYTES, -1 ) != OK)
  51.     return NotOK;
  52.  
  53.     if (winc_get_resp(cam, 6, retbytes, 0) != OK)
  54.     return NotOK;
  55.  
  56.     if (memcmp(retbytes, sendbytes, 6) != 0) {
  57.     errormsg(__FILE__ ": receive test failed\n");
  58.     return NotOK;
  59.     }
  60.     TRACE("dA", __FILE__ ": receive test passed\n");
  61.  
  62.     TRACE("dA", __FILE__ ": running transmit test\n");
  63.     if (winc_send_cmd(cam, Cmd_tx_test, -1) != OK)
  64.     return NotOK;
  65.  
  66.     memset(retbytes, 0, 256);
  67.     if (winc_get_resp(cam, 256, retbytes, 0) != OK)
  68.     return NotOK;
  69.  
  70.     for (i = 0; i < 256; i++) {
  71.     if (retbytes[i] != i) {
  72.         errormsg(__FILE__ ": receive test failed\n");
  73.         return NotOK;
  74.     }
  75.     }
  76.     TRACE("dA", __FILE__ ": transmit test passed\n");
  77.  
  78.     TRACE("dA", __FILE__ ": running dram test\n");
  79.     if (winc_send_cmd(cam, Cmd_test_dram, -1) != OK)
  80.     return NotOK;
  81.  
  82.     if (winc_get_resp_wait(cam, 1, retbytes, 10000, 0) != OK)
  83.     return NotOK;
  84.  
  85.     if (retbytes[0] == '*') {
  86.     TRACE("dA", __FILE__ ": dram test passed\n");
  87.     } else if (retbytes[0] == '-') {
  88.     errormsg(__FILE__ ": dram test failed\n");
  89.     } else {
  90.     errormsg(__FILE__ ": dram test -- unexpected result\n");
  91.     }
  92.  
  93.     TRACE("da", " ...diagnostics passed\n");
  94.     return OK;
  95. }
  96.  
  97.