Skip to content

Commit f1ec669

Browse files
2019 library source code added.
1 parent a2347b0 commit f1ec669

15 files changed

+1819
-0
lines changed

.gitignore

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Object files
5+
*.o
6+
*.ko
7+
*.obj
8+
*.elf
9+
10+
# Linker output
11+
*.ilk
12+
*.map
13+
*.exp
14+
15+
# Precompiled Headers
16+
*.gch
17+
*.pch
18+
19+
# Libraries
20+
*.lib
21+
*.a
22+
*.la
23+
*.lo
24+
25+
# Shared objects (inc. Windows DLLs)
26+
*.dll
27+
*.so
28+
*.so.*
29+
*.dylib
30+
31+
# Executables
32+
*.exe
33+
*.out
34+
*.app
35+
*.i*86
36+
*.x86_64
37+
*.hex
38+
39+
# Debug files
40+
*.dSYM/
41+
*.su
42+
*.idb
43+
*.pdb
44+
45+
# Kernel Module Compile Results
46+
*.mod*
47+
*.cmd
48+
.tmp_versions/
49+
modules.order
50+
Module.symvers
51+
Mkfile.old
52+
dkms.conf
53+
54+
# Extras
55+
FS-AI_API_Console/fs-ai_api_console
56+
FS-AI_API_Tester/fs-ai_api_tester
Binary file not shown.

Docs/adsdv_2019_vcu_ai_interface_v2.dbc

+389
Large diffs are not rendered by default.

FS-AI_API/can.c

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// https://en.wikipedia.org/wiki/SocketCAN
2+
// https://lnguin.wordpress.com/tag/socketcan-example/
3+
// https://stackoverflow.com/questions/21135392/socketcan-continuous-reading-and-writing
4+
5+
#include <stdio.h>
6+
//#include <stdlib.h>
7+
#include <unistd.h>
8+
#include <string.h>
9+
10+
#include <net/if.h>
11+
//#include <sys/types.h>
12+
//#include <sys/socket.h>
13+
#include <sys/ioctl.h>
14+
//#include <fcntl.h>
15+
16+
#include <linux/can.h>
17+
//#include <linux/can/raw.h>
18+
19+
static int soc;
20+
21+
int can_init(const char *port) {
22+
static struct sockaddr_can addr;
23+
static struct ifreq ifr;
24+
25+
if((soc = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
26+
perror("Error while opening socket");
27+
return(-1);
28+
}
29+
30+
strcpy(ifr.ifr_name, port);
31+
32+
if(ioctl(soc, SIOCGIFINDEX, &ifr) < 0) {
33+
perror("Error in ioctl()");
34+
return(-1);
35+
} else {
36+
//printf("%s at index %d\n", port, ifr.ifr_ifindex);
37+
}
38+
39+
addr.can_family = AF_CAN;
40+
addr.can_ifindex = ifr.ifr_ifindex;
41+
42+
if(bind(soc, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
43+
perror("Error in socket bind");
44+
return(-1);
45+
}
46+
47+
//printf("Opened: %s\r\n", port);
48+
49+
return 0;
50+
}
51+
52+
int can_send(struct can_frame *frame) {
53+
int retval;
54+
retval = write(soc, frame, sizeof(struct can_frame));
55+
if (retval != sizeof(struct can_frame))
56+
{
57+
return(-1);
58+
}
59+
else
60+
{
61+
return(0);
62+
}
63+
}
64+
65+
int can_read(struct can_frame *frame) {
66+
int retval;
67+
retval = read(soc, frame, sizeof(struct can_frame));
68+
if (retval != sizeof(struct can_frame))
69+
{
70+
return(-1);
71+
}
72+
else
73+
{
74+
return(0);
75+
}
76+
}

FS-AI_API/can.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
/*
8+
* File: can.h
9+
* Author: ian
10+
*
11+
* Created on 25 April 2018, 22:13
12+
*/
13+
14+
#ifndef CAN_H
15+
#define CAN_H
16+
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
#include <linux/can.h>
22+
23+
int can_init(const char *port);
24+
int can_send(struct can_frame *frame);
25+
int can_read(struct can_frame *frame);
26+
27+
#ifdef __cplusplus
28+
}
29+
#endif
30+
31+
#endif /* CAN_H */
32+

0 commit comments

Comments
 (0)