Go to the documentation of this file.00001
00002
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <unistd.h>
00006 #include <signal.h>
00007 #include <string.h>
00008 #include <stdlib.h>
00009 #include "common.h"
00010
00011
00012
00013
00014
00015
00016
00017 void signal_handler(int signal)
00018 {
00025 HANDLE h;
00026 do_exit(0, h);
00027 }
00028
00029 void do_exit(int error, HANDLE h)
00030 {
00037 if (h)
00038 {
00039 print_diag("pcan_topics", h);
00040 CAN_Close(h);
00041 }
00042 printf("pcan_topics: finished (%d).\n\n", error);
00043 exit(error);
00044 }
00045
00046
00047
00048 char const * getNameOfInterface(int nType)
00049 {
00056 switch (nType)
00057 {
00058 case HW_PCI: return "pci";
00059 case HW_ISA_SJA: return "isa";
00060 case HW_DONGLE_SJA: return "sp";
00061 case HW_DONGLE_SJA_EPP: return "epp";
00062 case HW_USB: return "usb";
00063 case HW_USB_PRO: return "usbpro";
00064 case HW_PCCARD: return "pccard";
00065 default: return "unknown";
00066 }
00067 }
00068
00069
00070 void print_diag(const char *prgName, HANDLE h)
00071 {
00078 int err;
00079 TPDIAG diag;
00080 err = LINUX_CAN_Statistics(h, &diag);
00081 if (err)
00082 printf("%s: can't read diagnostics, error %d!\n", prgName, err);
00083 else
00084 {
00085 printf("%s: type = %s\n", prgName, getNameOfInterface(diag.wType));
00086 if ((diag.wType == HW_USB) || (diag.wType == HW_USB_PRO))
00087 {
00088 printf(" Serial Number = 0x%08x\n", diag.dwBase);
00089 printf(" Device Number = %d\n", diag.wIrqLevel);
00090 }
00091 else
00092 {
00093 printf(" io = 0x%08x\n", diag.dwBase);
00094 printf(" irq = %d\n", diag.wIrqLevel);
00095 }
00096 printf(" count of reads = %d\n", diag.dwReadCounter);
00097 printf(" count of writes = %d\n", diag.dwWriteCounter);
00098 printf(" count of errors = %d\n", diag.dwErrorCounter);
00099 printf(" count of irqs = %d\n", diag.dwIRQcounter);
00100 printf(" last CAN status = 0x%04x\n", diag.wErrorFlag);
00101 printf(" last error = %d\n", diag.nLastError);
00102 printf(" open paths = %d\n", diag.nOpenPaths);
00103 printf(" driver version = %s\n", diag.szVersionString);
00104 }
00105 }
00106