forked from Delsian/CanSerial
-
Notifications
You must be signed in to change notification settings - Fork 1
/
canserial.c
executable file
·56 lines (44 loc) · 927 Bytes
/
canserial.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Main starting point for CanSerial - virtual serial ports for CAN devices
*
* Copyright (C) 2019 Eug Krashtan <[email protected]>
* This file may be distributed under the terms of the GNU GPLv3 license.
*
*/
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <signal.h>
#include "cansock.h"
#include "portnumber.h"
static int running;
static void cleanup_handler(int signo)
{
if (signo == SIGINT) {
printf("Received SIGINT\n");
running = 0;
CanSockClose();
}
}
int main(int argc, char **argv)
{
int retval;
int i;
if(signal(SIGINT, cleanup_handler) == SIG_ERR) {
fprintf(stderr, "Can't catch SIGINT\n");
} else {
running = 1;
}
PnInit();
if ( (retval = CanSockInit()) != 0) {
fprintf(stderr, "Socket init error: %d\n", retval);
return 1;
}
/* send frame */
while(running)
{
CanPing();
usleep(3000000); /* Delay 3s before next loop */
}
return 0;
}