#include "stdio.h"
#include "signal.h"
static void check(
const char *name,
canStatus status);
static void intHandler(int unused);
static void usage();
static int interrupt = 0;
int main(int argc, char *argv[])
{
int channel = -1;
for (int i=1; i<argc; i++) {
if (sscanf(argv[i], "-ch=%d", &channel) == 1);
else {
usage();
exit(1);
}
}
if (channel == -1) {
usage();
exit(1);
}
check("kvDiagAttachAnalyzer", stat);
check("kvDiagSetProgram", stat);
check("kvDiagStart", stat);
signal(SIGINT, intHandler);
while (1) {
Sleep(100);
printf("Estimated CAN bitrate to %.0f KBit/s with quality %d %%.\n",
}
check("kvDiagResetBitrateCalculation", stat);
if (interrupt) {
break;
}
}
check("kvDiagStop", stat);
check("kvDiagDetachAnalyzer", stat);
check("canClose", stat);
return 0;
}
static void check(
const char *name,
canStatus status)
{
printf("%s returned %d\n", name, status);
exit(1);
}
}
static void intHandler(int unused)
{
interrupt = 1;
}
static void usage()
{
printf(
"Usage: 'autobaud_example -ch=n', "
"where 'n' is a CANlib channel with analyzer capability.\n\n"
"Note: This program requires a working CAN bus with traffic to function properly.\n");
}