// print out device and channel diagnostics void print_diag(const char *prgName) { int err; TPDIAG diag; err = LINUX_CAN_Statistics(h, &diag); if (err) printf("%s: can't read diagnostics, error %d!\n", prgName, err); else { printf("%s: type = %s\n", prgName, getNameOfInterface(diag.wType)); if ((diag.wType == HW_USB) || (diag.wType == HW_USB_PRO)) { printf(" Serial Number = 0x%08x\n", diag.dwBase); printf(" Device Number = %d\n", diag.wIrqLevel); } else { printf(" io = 0x%08x\n", diag.dwBase); printf(" irq = %d\n", diag.wIrqLevel); } printf(" count of reads = %d\n", diag.dwReadCounter); printf(" count of writes = %d\n", diag.dwWriteCounter); printf(" count of errors = %d\n", diag.dwErrorCounter); printf(" count of irqs = %d\n", diag.dwIRQcounter); printf(" last CAN status = 0x%04x\n", diag.wErrorFlag); printf(" last error = %d\n", diag.nLastError); printf(" open paths = %d\n", diag.nOpenPaths); printf(" driver version = %s\n", diag.szVersionString); } }
// print out device and channel diagnostics void print_diag(const char *prgName, HANDLE h) { /*! *\brief The function is copied from the common.cpp file used by both the transmi- and receivetest * * * * */ int err; TPDIAG diag; err = LINUX_CAN_Statistics(h, &diag); if (err) printf("%s: can't read diagnostics, error %d!\n", prgName, err); else { printf("%s: type = %s\n", prgName, getNameOfInterface(diag.wType)); if ((diag.wType == HW_USB) || (diag.wType == HW_USB_PRO)) { printf(" Serial Number = 0x%08x\n", diag.dwBase); printf(" Device Number = %d\n", diag.wIrqLevel); } else { printf(" io = 0x%08x\n", diag.dwBase); printf(" irq = %d\n", diag.wIrqLevel); } printf(" count of reads = %d\n", diag.dwReadCounter); printf(" count of writes = %d\n", diag.dwWriteCounter); printf(" count of errors = %d\n", diag.dwErrorCounter); printf(" count of irqs = %d\n", diag.dwIRQcounter); printf(" last CAN status = 0x%04x\n", diag.wErrorFlag); printf(" last error = %d\n", diag.nLastError); printf(" open paths = %d\n", diag.nOpenPaths); printf(" driver version = %s\n", diag.szVersionString); } }
void pcan_transmit::init(int argc, char **argv) { /*! *\brief The init() function is based on the middle part of the main() function of the transmitest program. * * Compared to the transmitest program a lot of cases have been removed. * Therefore, only the PCAN-USB adapter is, and standard messages are, supported. * * */ int nExtended = CAN_INIT_TYPE_ST; int nType; __u32 dwPort; __u16 wIrq; char *ptr; __u16 wBTR0BTR1 = 0x011C; // parameter wBTR0BTR1 // bitrate codes of BTR0/BTR1 registers //#define CAN_BAUD_1M 0x0014 // 1 MBit/s //#define CAN_BAUD_500K 0x001C // 500 kBit/s //#define CAN_BAUD_250K 0x011C // 250 kBit/s //#define CAN_BAUD_125K 0x031C // 125 kBit/s //#define CAN_BAUD_100K 0x432F // 100 kBit/s //#define CAN_BAUD_50K 0x472F // 50 kBit/s //#define CAN_BAUD_20K 0x532F // 20 kBit/s //#define CAN_BAUD_10K 0x672F // 10 kBit/s //#define CAN_BAUD_5K 0x7F7F // 5 kBit/s const char *szDevNode = DEFAULT_NODE; bool bDevNodeGiven = false; bool bTypeGiven = false; char txt[VERSIONSTRING_LEN]; /* QApplication a(argc, argv); QWidget *mainWindow=new QWidget; mainWindow->setWindowTitle("Change the Data Value"); QSlider *slider= new QSlider(Qt::Horizontal); QSpinBox *spinner= new QSpinBox; slider->setRange(0,100); spinner->setRange(0,100); connect(ui->slider, SIGNAL(valueChanged(double)), SLOT(onSliderValueChanged(double))); double slidValue= ui->Slider->value(); //string msg[]= "ID, LEN, ss";*/ // decode command line arguments for (int i = 1; i < argc; i++) { char c; ptr = argv[i]; while (*ptr == '-') ptr++; c = *ptr; ptr++; if (*ptr == '=') ptr++; switch(tolower(c)) { case '?': case 'h': hlpMsg(); do_exit(errno, h); break; case 'f': szDevNode = ptr; bDevNodeGiven = true; break; case 'b': wBTR0BTR1 = (__u16)strtoul(ptr, NULL, 16); break; default: errno = EINVAL; do_exit(errno, h);; break; } } /* open CAN port */ if ((bDevNodeGiven) || (!bDevNodeGiven && !bTypeGiven)) { h = LINUX_CAN_Open(szDevNode, O_RDWR); if (!h) { printf("pcan_transmit: can't open %s\n", szDevNode); do_exit(errno, h);; } } else { // please use what is appropriate // HW_DONGLE_SJA // HW_DONGLE_SJA_EPP // HW_ISA_SJA // HW_PCI h = CAN_Open(nType, dwPort, wIrq); if (!h) { printf("pcan_transmit: can't open %s device.\n", getNameOfInterface(nType)); do_exit(errno, h);; } } /* clear status */ CAN_Status(h); // get version info errno = CAN_VersionInfo(h, txt); if (!errno) printf("pcan_transmit: driver version = %s\n", txt); else { perror("pcan_transmit: CAN_VersionInfo()"); do_exit(errno, h);; } // init to a user defined bit rate if (wBTR0BTR1) { errno = CAN_Init(h, wBTR0BTR1, nExtended); if (errno) { perror("pcan_transmit: CAN_Init()"); do_exit(errno, h);; } } }
// here all is done int main(int argc, char *argv[]) { char *ptr; int i; int nType = HW_PCI; __u32 dwPort = 0; __u16 wIrq = 0; __u16 wBTR0BTR1 = 0; int nExtended = CAN_INIT_TYPE_ST; const char *szDevNode = DEFAULT_NODE; bool bDevNodeGiven = false; bool bTypeGiven = false; bool bDisplayOn = true; char txt[VERSIONSTRING_LEN]; errno = 0; current_release = CURRENT_RELEASE; disclaimer("receivetest"); init(); // decode command line arguments for (i = 1; i < argc; i++) { char c; ptr = argv[i]; while (*ptr == '-') ptr++; c = *ptr; ptr++; if (*ptr == '=') ptr++; switch(tolower(c)) { case 'f': szDevNode = ptr; bDevNodeGiven = true; break; case 'd': if (strcmp(ptr, "no") == 0) bDisplayOn = false; break; case 't': nType = getTypeOfInterface(ptr); if (!nType) { errno = EINVAL; printf("receivetest: unknown type of interface!\n"); goto error; } bTypeGiven = true; break; case 'p': dwPort = strtoul(ptr, NULL, 16); break; case 'i': wIrq = (__u16)strtoul(ptr, NULL, 10); break; case 'e': nExtended = CAN_INIT_TYPE_EX; break; case '?': case 'h': hlpMsg(); goto error; break; case 'b': wBTR0BTR1 = (__u16)strtoul(ptr, NULL, 16); break; default: errno = EINVAL; perror("receivetest: unknown command line argument!\n"); goto error; break; } } // simple command input check if (bDevNodeGiven && bTypeGiven) { errno = EINVAL; perror("receivetest: device node and type together is useless"); goto error; } // give some information back if (!bTypeGiven) { printf("receivetest: device node=\"%s\"\n", szDevNode); } else { printf("receivetest: type=%s", getNameOfInterface(nType)); switch (nType) { case HW_USB: case HW_USB_PRO: case HW_USB_FD: case HW_USB_PRO_FD: if (dwPort) printf(", %d. device\n", dwPort); else printf(", standard device\n"); break; default: if (dwPort) { if (nType == HW_PCI) printf(", %d. PCI device", dwPort); else printf(", port=0x%08x", dwPort); } else printf(", port=default"); if ((wIrq) && !(nType == HW_PCI)) printf(" irq=0x%04x\n", wIrq); else printf(", irq=default\n"); break; } } if (nExtended == CAN_INIT_TYPE_EX) printf(" Extended frames are accepted"); else printf(" Only standard frames are accepted"); if (wBTR0BTR1) printf(", init with BTR0BTR1=0x%04x\n", wBTR0BTR1); else printf(", init with 500 kbit/sec.\n"); /* open CAN port */ if ((bDevNodeGiven) || (!bDevNodeGiven && !bTypeGiven)) { h = LINUX_CAN_Open(szDevNode, O_RDWR); if (!h) { printf("receivetest: can't open %s\n", szDevNode); goto error; } } else { // please use what is appropriate // HW_DONGLE_SJA // HW_DONGLE_SJA_EPP // HW_ISA_SJA // HW_PCI h = CAN_Open(nType, dwPort, wIrq); if (!h) { printf("receivetest: can't open %s device.\n", getNameOfInterface(nType)); goto error; } } /* clear status */ // CAN_Status(h); // get version info errno = CAN_VersionInfo(h, txt); if (!errno) printf("receivetest: driver version = %s\n", txt); else { perror("receivetest: CAN_VersionInfo()"); goto error; } // init to a user defined bit rate if (wBTR0BTR1) { errno = CAN_Init(h, wBTR0BTR1, nExtended); if (errno) { perror("receivetest: CAN_Init()"); goto error; } } errno = read_loop(bDisplayOn); if (!errno) return 0; error: do_exit(errno); return errno; }
int main(int argc, char *argv[]) { char *ptr; int i; int nType = HW_PCI; __u32 dwPort = 0; __u16 wIrq = 0; __u16 wBTR0BTR1 = 0; __u32 dwMaxTimeInterval = 0, dwMaxLoop = 0; char *filename = NULL; const char *szDevNode = DEFAULT_NODE; bool bDevNodeGiven = false; bool bTypeGiven = false; parser MyParser; char txt[VERSIONSTRING_LEN]; errno = 0; current_release = CURRENT_RELEASE; disclaimer("transmitest"); init(); // decode command line arguments for (i = 1; i < argc; i++) { char c; ptr = argv[i]; if (*ptr == '-') { while (*ptr == '-') ptr++; c = *ptr; ptr++; if (*ptr == '=') ptr++; switch(tolower(c)) { case 'f': szDevNode = ptr; bDevNodeGiven = true; break; case 't': nType = getTypeOfInterface(ptr); if (!nType) { errno = EINVAL; printf("transmitest: unknown type of interface\n"); goto error; } bTypeGiven = true; break; case 'p': dwPort = strtoul(ptr, NULL, 16); break; case 'i': wIrq = (__u16)strtoul(ptr, NULL, 10); break; case 'e': nExtended = CAN_INIT_TYPE_EX; break; case '?': case 'h': hlpMsg(); goto error; break; case 'b': wBTR0BTR1 = (__u16)strtoul(ptr, NULL, 16); break; case 'r': dwMaxTimeInterval = strtoul(ptr, NULL, 10); break; case 'n': dwMaxLoop = strtoul(ptr, NULL, 10); break; default: errno = EINVAL; printf("transmitest: unknown command line argument\n"); goto error; break; } } else filename = ptr; } // test for filename if (filename == NULL) { errno = EINVAL; perror("transmitest: no filename given"); goto error; } // test device node and type if (bDevNodeGiven && bTypeGiven) { errno = EINVAL; perror("transmitest: device node and type together is useless"); goto error; } // give the filename to my parser MyParser.setFileName(filename); // tell some information to the user if (!bTypeGiven) { printf("transmitest: device node=\"%s\"\n", szDevNode); } else { printf("transmitest: type=%s", getNameOfInterface(nType)); if (nType == HW_USB) printf(", Serial Number=default, Device Number=%d\n", dwPort); else { if (dwPort) { if (nType == HW_PCI) printf(", %d. PCI device", dwPort); else printf(", port=0x%08x", dwPort); } else printf(", port=default"); if ((wIrq) && !(nType == HW_PCI)) printf(" irq=0x%04x\n", wIrq); else printf(", irq=default\n"); } } if (nExtended == CAN_INIT_TYPE_EX) printf(" Extended frames are sent"); else printf(" Only standard frames are sent"); if (wBTR0BTR1) printf(", init with BTR0BTR1=0x%04x\n", wBTR0BTR1); else printf(", init with 500 kbit/sec.\n"); printf(" Data will be read from \"%s\".\n", filename); if (dwMaxTimeInterval) printf(" Messages are send in random time intervalls with a max. gap time of %d msec.\n", dwMaxTimeInterval); /* get the list of data from parser */ List = MyParser.Messages(); if (!List) { errno = MyParser.nGetLastError(); perror("transmitest: error at file read"); goto error; } /* open CAN port */ if ((bDevNodeGiven) || (!bDevNodeGiven && !bTypeGiven)) { h = LINUX_CAN_Open(szDevNode, O_RDWR); if (!h) { printf("transmitest: can't open %s\n", szDevNode); goto error; } } else { // please use what is appropriate // HW_DONGLE_SJA // HW_DONGLE_SJA_EPP // HW_ISA_SJA // HW_PCI h = CAN_Open(nType, dwPort, wIrq); if (!h) { printf("transmitest: can't open %s device.\n", getNameOfInterface(nType)); goto error; } } /* clear status */ CAN_Status(h); // get version info errno = CAN_VersionInfo(h, txt); if (!errno) printf("transmitest: driver version = %s\n", txt); else { perror("transmitest: CAN_VersionInfo()"); goto error; } // init to a user defined bit rate if (wBTR0BTR1) { errno = CAN_Init(h, wBTR0BTR1, nExtended); if (errno) { perror("transmitest: CAN_Init()"); goto error; } } // enter in the write loop errno = write_loop(dwMaxTimeInterval, dwMaxLoop); if (!errno) return 0; error: do_exit(errno); return errno; }