-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2347b0
commit f1ec669
Showing
15 changed files
with
1,819 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Object files | ||
*.o | ||
*.ko | ||
*.obj | ||
*.elf | ||
|
||
# Linker output | ||
*.ilk | ||
*.map | ||
*.exp | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
*.a | ||
*.la | ||
*.lo | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
# Debug files | ||
*.dSYM/ | ||
*.su | ||
*.idb | ||
*.pdb | ||
|
||
# Kernel Module Compile Results | ||
*.mod* | ||
*.cmd | ||
.tmp_versions/ | ||
modules.order | ||
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
|
||
# Extras | ||
FS-AI_API_Console/fs-ai_api_console | ||
FS-AI_API_Tester/fs-ai_api_tester |
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// https://en.wikipedia.org/wiki/SocketCAN | ||
// https://lnguin.wordpress.com/tag/socketcan-example/ | ||
// https://stackoverflow.com/questions/21135392/socketcan-continuous-reading-and-writing | ||
|
||
#include <stdio.h> | ||
//#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
|
||
#include <net/if.h> | ||
//#include <sys/types.h> | ||
//#include <sys/socket.h> | ||
#include <sys/ioctl.h> | ||
//#include <fcntl.h> | ||
|
||
#include <linux/can.h> | ||
//#include <linux/can/raw.h> | ||
|
||
static int soc; | ||
|
||
int can_init(const char *port) { | ||
static struct sockaddr_can addr; | ||
static struct ifreq ifr; | ||
|
||
if((soc = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) { | ||
perror("Error while opening socket"); | ||
return(-1); | ||
} | ||
|
||
strcpy(ifr.ifr_name, port); | ||
|
||
if(ioctl(soc, SIOCGIFINDEX, &ifr) < 0) { | ||
perror("Error in ioctl()"); | ||
return(-1); | ||
} else { | ||
//printf("%s at index %d\n", port, ifr.ifr_ifindex); | ||
} | ||
|
||
addr.can_family = AF_CAN; | ||
addr.can_ifindex = ifr.ifr_ifindex; | ||
|
||
if(bind(soc, (struct sockaddr *)&addr, sizeof(addr)) < 0) { | ||
perror("Error in socket bind"); | ||
return(-1); | ||
} | ||
|
||
//printf("Opened: %s\r\n", port); | ||
|
||
return 0; | ||
} | ||
|
||
int can_send(struct can_frame *frame) { | ||
int retval; | ||
retval = write(soc, frame, sizeof(struct can_frame)); | ||
if (retval != sizeof(struct can_frame)) | ||
{ | ||
return(-1); | ||
} | ||
else | ||
{ | ||
return(0); | ||
} | ||
} | ||
|
||
int can_read(struct can_frame *frame) { | ||
int retval; | ||
retval = read(soc, frame, sizeof(struct can_frame)); | ||
if (retval != sizeof(struct can_frame)) | ||
{ | ||
return(-1); | ||
} | ||
else | ||
{ | ||
return(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
/* | ||
* File: can.h | ||
* Author: ian | ||
* | ||
* Created on 25 April 2018, 22:13 | ||
*/ | ||
|
||
#ifndef CAN_H | ||
#define CAN_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <linux/can.h> | ||
|
||
int can_init(const char *port); | ||
int can_send(struct can_frame *frame); | ||
int can_read(struct can_frame *frame); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* CAN_H */ | ||
|
Oops, something went wrong.