Skip to content

Commit

Permalink
2019 library source code added.
Browse files Browse the repository at this point in the history
  • Loading branch information
IanMurphy-Rockfort committed Apr 21, 2021
1 parent a2347b0 commit f1ec669
Show file tree
Hide file tree
Showing 15 changed files with 1,819 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .gitignore
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.
389 changes: 389 additions & 0 deletions Docs/adsdv_2019_vcu_ai_interface_v2.dbc

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions FS-AI_API/can.c
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);
}
}
32 changes: 32 additions & 0 deletions FS-AI_API/can.h
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 */

Loading

0 comments on commit f1ec669

Please sign in to comment.