ibError.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /***************************************************************************
  2. lib/ibError.c
  3. -------------------
  4. copyright : (C) 2001,2002,2003 by Frank Mori Hess
  5. email : fmhess@users.sourceforge.net
  6. ***************************************************************************/
  7. /***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #include "ib_internal.h"
  16. #include <time.h>
  17. #include <stdio.h>
  18. #include <stdarg.h>
  19. #include <string.h>
  20. char *routptr[]= {
  21. "ibrd",
  22. "ibwrt",
  23. "ibcmd",
  24. "ibwait",
  25. "ibrpp",
  26. "ibonl",
  27. "ibsic",
  28. "ibsre",
  29. "ibgts",
  30. "ibcac",
  31. "ibpoke",
  32. "iblines",
  33. "ibpad",
  34. "ibsad",
  35. "ibtmo",
  36. "ibeot",
  37. "ibeos",
  38. "ibrsv", /*17*/
  39. "dvtrg",
  40. "dvclr",
  41. "dvrsp",
  42. "dvrd",
  43. "dvwrt", /*22*/
  44. "cfcbase",
  45. "cfcirq",
  46. "cfcdma", /*25*/
  47. "unknown"
  48. };
  49. char *ibVerbCode(int code)
  50. {
  51. if( code >=0 && code <=17 ) return routptr[code];
  52. else if( code >=100 && code <=104 ) return routptr[18+(code-100)];
  53. else if( code >=200 && code <=202 ) return routptr[23+(code-200)];
  54. else return routptr[26];
  55. }
  56. void ibPutMsg (char *format,...)
  57. {
  58. va_list ap;
  59. time_t tm;
  60. char strtime[60];
  61. va_start(ap,format);
  62. time(&tm);
  63. strftime(strtime,59,"%c",gmtime(&tm));
  64. fprintf(stderr,"\n gpib-message :[%s] ",strtime);
  65. vfprintf(stderr, format, ap);
  66. va_end(ap);
  67. }
  68. void ibPutErrlog(int ud,char *routine)
  69. {
  70. time_t tm;
  71. char strtime[60];
  72. if( ibsta & ERR ) {
  73. time(&tm);
  74. strftime(strtime,59,"%c",gmtime(&tm));
  75. if(ud>=0) fprintf(stderr, "\n %-15s:[%s](%s)< ",routine,strtime, ibConfigs[ud]->name);
  76. else fprintf(stderr, "\n %-15s:[%s](-)< " ,routine,strtime);
  77. if ( ibsta & ERR ) fprintf(stderr," ERR");
  78. if ( ibsta & TIMO ) fprintf(stderr," TIMO");
  79. if ( ibsta & END ) fprintf(stderr," END");
  80. if ( ibsta & SRQI ) fprintf(stderr," SRQI");
  81. /*if ( ibsta & RQS ) fprintf(stderr," RQS");*/
  82. if ( ibsta & CMPL ) fprintf(stderr," CMPL");
  83. /*if ( ibsta & LOK ) fprintf(stderr," LOK");*/
  84. /*if ( ibsta & REM ) fprintf(stderr," REM");*/
  85. if ( ibsta & CIC ) fprintf(stderr," CIC");
  86. if ( ibsta & ATN ) fprintf(stderr," ATM");
  87. if ( ibsta & TACS ) fprintf(stderr," TACS");
  88. if ( ibsta & LACS ) fprintf(stderr," LACS");
  89. /*if ( ibsta & DTAS ) fprintf(stderr," DATS");*/
  90. /*if ( ibsta & DCAS ) fprintf(stderr," DCTS");*/
  91. fprintf(stderr,"> ");
  92. if ( iberr == EDVR) fprintf(stderr," EDVR <OS Error>\n");
  93. if ( iberr == ECIC) fprintf(stderr," ECIC <Not CIC>\n");
  94. if ( iberr == ENOL) fprintf(stderr," ENOL <No Listener>\n");
  95. if ( iberr == EADR) fprintf(stderr," EADR <Adress Error>\n");
  96. if ( iberr == EARG) fprintf(stderr," ECIC <Invalid Argument>\n");
  97. if ( iberr == ESAC) fprintf(stderr," ESAC <No Sys Ctrlr>\n");
  98. if ( iberr == EABO) fprintf(stderr," EABO <Operation Aborted>\n");
  99. if ( iberr == ENEB) fprintf(stderr," ENEB <No Gpib Board>\n");
  100. if ( iberr == EOIP) fprintf(stderr," EOIP <Async I/O in prg>\n");
  101. if ( iberr == ECAP) fprintf(stderr," ECAP <No Capability>\n");
  102. if ( iberr == EFSO) fprintf(stderr," EFSO <File sys. error>\n");
  103. if ( iberr == EBUS) fprintf(stderr," EBUS <Command error>\n");
  104. if ( iberr == ESTB) fprintf(stderr," ESTB <Status byte lost>\n");
  105. if ( iberr == ESRQ) fprintf(stderr," ESRQ <SRQ stuck on>\n");
  106. if ( iberr == ETAB) fprintf(stderr," ETAB <Table Overflow>\n");
  107. if ( iberr == ETAB) fprintf(stderr," ETAB <Device Table Overflow>\n");
  108. if ( iberr == EDVR && ibcnt != 0) {
  109. fprintf(stderr," -- errno=%d (%s)\n",ibcnt,strerror(ibcnt));
  110. }
  111. }
  112. }