\documentclass[11pt]{beamer}

%\usepackage{ngerman}
\usepackage{times}
\usepackage{graphicx}
\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps}
\usepackage{amsmath,amssymb}
\usepackage[utf8]{inputenc}
\usepackage{listings,color}
\definecolor{lbcolor}{RGB}{255,210,150}
\lstset{
	language=C,
	numbers=left,
	stepnumber=1,
	numbersep=5pt,
	numberstyle=\tiny,
	breaklines=true,
	breakautoindent=true,
	postbreak=\space,
	tabsize=2,
	basicstyle=\ttfamily\fontsize{7}{9}\selectfont,
	showspaces=false,
	showstringspaces=false,
	extendedchars=true,
	backgroundcolor=\color{lbcolor},
	keywordstyle=\bf ,
	commentstyle=\color{green},
	stringstyle=\color{red}
}

\mode<presentation>
{
	\usetheme{linutronix}
}

% on the following slides, include icon in the left sidebar
\def\lximg{/usr/share/lx/icons/fueller.png}

\title{Can unter Linux: SocketCAN}
\institute{Linutronix GmbH}

\begin{document}

\frame{ \titlepage }

% stop displaying 'fueller.png' on the following slides
\def\lximg{none}

%\AtBeginSection[]
%{
%	\begin{frame}<beamer>
%		\tableofcontents[currentsection,currentsubsection]
%	\end{frame}
%}
\begin{frame}
\frametitle{Übersicht}
\begin{itemize}
\item Als neues Netzwerkprotokoll integriert
\item PF\_CAN
\item CAN Kommunikation über Sockets
\item Konfiguration und Debugging über Netzwerktools
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitle{Virtual CAN interface}
\begin{verbatim}
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{ifconfig}
\tiny
\begin{verbatim}
$ ifconfig
...
vcan0  Link encap:UNSPEC  Hardware Adresse 00-00-00-00-00
       UP RUNNING NOARP  MTU:16  Metrik:1
       RX packets:1 errors:0 dropped:0 overruns:0 frame:0
       TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
       Kollisionen:0 Sendewarteschlangenlänge:0 
       RX bytes:4 (4.0 B)  TX bytes:4 (4.0 B)
...
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{cansend / candump}
cansend:
\begin{verbatim}
cansend vcan0 123#11223344
\end{verbatim}
candump:
\begin{verbatim}
$ candump vcan0
  vcan0  123  [4] 11 22 33 44
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{cangen}
\begin{verbatim}
$ cangen vcan0 -I 123 -L 1 -D i
\end{verbatim}
\begin{verbatim}
$ candump vcan0
  vcan0  123  [1] 39
  vcan0  123  [1] 3A
  vcan0  123  [1] 3B
  vcan0  123  [1] 3C
  vcan0  123  [1] 3D
  vcan0  123  [1] 3E
  vcan0  123  [1] 3F
  vcan0  123  [1] 40
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{cansniffer}
cangen:
\begin{verbatim}
$ cangen vcan0 -I 123 -L 1 -D i
\end{verbatim}
cansniffer vcan0:
\begin{verbatim}
-  time    ID  data ...  < cansniffer vcan0 #
0.200107  123  01000000
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Programmierbeispiel: can example}
\begin{lstlisting}
int skt = socket(PF_CAN, SOCK_RAW, CAN_RAW);
int bytes_sent, bytes_read, i;
struct ifreq ifr;
struct sockaddr_can addr;
struct can_frame frame;

strcpy(ifr.ifr_name, "vcan0");
ioctl(skt, SIOCGIFINDEX, &ifr);

addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
bind(skt, (struct sockaddr*)&addr, sizeof(addr));

frame.can_id = 0x123;
strcpy(frame.data, "tst");
frame.can_dlc = strlen(frame.data);
bytes_sent = write(skt, &frame, sizeof(frame));

bytes_read = read(skt, &frame, sizeof(frame));
for(i = 0; i < 4; i++)
   printf("Recveived -> %X\n", frame.data[i]);

\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{Programmierbeispiel: can example}
1)
\begin{verbatim}
$ ./can_example 
\end{verbatim}
2)
\begin{verbatim}
$ candump vcan0
  vcan0  123  [3] 66 6F 6F
\end{verbatim}
3)
\begin{verbatim}
$ cansend vcan0 123#11223344
\end{verbatim}
4) can\_example:
\begin{verbatim}
Received -> 11
Received -> 22
...
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{canlogserver}
\begin{verbatim}
$ canlogserver vcan0 &
\end{verbatim}
\begin{verbatim}
$ cangen vcan0 -Di  -I 42A -L1 &
\end{verbatim}
\begin{verbatim}
$ telnet localhost 28700
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
(1289664132.891896) vcan0 42A#00
(1289664133.092037) vcan0 42A#01
(1289664133.292138) vcan0 42A#02
(1289664133.492246) vcan0 42A#03
(1289664133.692351) vcan0 42A#04
\end{verbatim}
\end{frame}
\end{document}
