common.cpp
Go to the documentation of this file.
1 //****************************************************************************
2 // INCLUDES
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h> // exit
6 #include <signal.h>
7 #include <string.h>
8 #include <stdlib.h> // strtoul
9 #include "common.h"
10 
11 
12 //****************************************************************************
13 // CODE
14 
15 
16 
17 void signal_handler(int signal)
18 {
25  HANDLE h;
26  do_exit(0, h);
27 }
28 
29 void do_exit(int error, HANDLE h)
30 {
37  if (h)
38  {
39  print_diag("pcan_topics", h);
40  CAN_Close(h);
41 
42  }
43  printf("pcan_topics: finished (%d).\n\n", error);
44  exit(error);
45 }
46 
47 
48 // the opposite: lookup for device string out of HW_.. constant
49 char const * getNameOfInterface(int nType)
50 {
57  switch (nType)
58  {
59  case HW_PCI: return "pci";
60  case HW_ISA_SJA: return "isa";
61  case HW_DONGLE_SJA: return "sp";
62  case HW_DONGLE_SJA_EPP: return "epp";
63  case HW_USB: return "usb";
64  case HW_USB_PRO: return "usbpro";
65  case HW_PCCARD: return "pccard";
66 
67  default: return "unknown";
68  }
69 }
70 
71 // print out device and channel diagnostics
72 void print_diag(const char *prgName, HANDLE h)
73 {
80  int err;
81  TPDIAG diag;
82 
83  err = LINUX_CAN_Statistics(h, &diag);
84  if (err)
85  printf("%s: can't read diagnostics, error %d!\n", prgName, err);
86  else
87  {
88  printf("%s: type = %s\n", prgName, getNameOfInterface(diag.wType));
89  if ((diag.wType == HW_USB) || (diag.wType == HW_USB_PRO))
90  {
91  printf(" Serial Number = 0x%08x\n", diag.dwBase);
92  printf(" Device Number = %d\n", diag.wIrqLevel);
93  }
94  else
95  {
96  printf(" io = 0x%08x\n", diag.dwBase);
97  printf(" irq = %d\n", diag.wIrqLevel);
98  }
99  printf(" count of reads = %d\n", diag.dwReadCounter);
100  printf(" count of writes = %d\n", diag.dwWriteCounter);
101  printf(" count of errors = %d\n", diag.dwErrorCounter);
102  printf(" count of irqs = %d\n", diag.dwIRQcounter);
103  printf(" last CAN status = 0x%04x\n", diag.wErrorFlag);
104  printf(" last error = %d\n", diag.nLastError);
105  printf(" open paths = %d\n", diag.nOpenPaths);
106  printf(" driver version = %s\n", diag.szVersionString);
107  }
108 }
109 
void print_diag(const char *prgName, HANDLE h)
Definition: common.cpp:72
void do_exit(int error, HANDLE h)
Definition: common.cpp:29
char const * getNameOfInterface(int nType)
Definition: common.cpp:49
void signal_handler(int signal)
Definition: common.cpp:17


pcan_topics
Author(s):
autogenerated on Sun Dec 14 2014 19:01:10