Documentation: reviewed and updated
[apps/low-level-can-service.git] / docs / 2-Installation.md
1 # Prerequisites
2
3 * An AGL system installed with latest Chinook version \(>3.0.2\).
4
5 * Make sure you built the AGL generator else you will not be able to generate custom low-level CAN binding. Generator can be found [here](http://github.com/iotbzh/can-config-generator) with the attached instruction to install and run it.
6
7 It will produce a _configuration-generated.cpp_ file to paste in the source, _src/_, directory.
8
9 * Make sure you already set up the AGL SDK using the following [guide](http://docs.iot.bzh/docs/getting_started/en/dev/reference/setup-sdk-environment.html).
10
11 To get the correct SDK version installed, you **must** prepare your environment with the **chinook-next** version. To do so, run the following command in your docker image:
12
13 ```bash
14 $ prepare_meta -f chinook-next -o /xdt -l /home/devel/mirror -p /home/devel/share/proprietary-renesas-rcar/ -t porter -e wipeconfig -e rm_work
15 ```
16
17 * Check that you updated git submodules, executing the following commands from this repository:
18
19 ```bash
20 $ git submodule init
21 $ git submodule update
22 ```
23
24 * An [USB CAN adapter](http://shop.8devices.com/usb2can) connected to OBD2 connector through the [right cable](http://www.mouser.fr/ProductDetail/EasySync/OBD-M-DB9-F-ES/)\).
25
26 # Getting started
27
28 ## Use of CAN config generator
29
30 ### Build requirements
31
32 * CMake version 3.0 or later
33 * G++, Clang++ or any C++11 complient compiler.
34 * Boost
35   * filesystem
36   * program\_options
37   * system
38
39 You can install any of these using your package manager. For instance, inside the iotbzh's docker image, you must enter this command :
40
41 ```bash
42 $ sudo apt-get install cmake libboost-system-dev libboost-filesystem-dev libboost-program-options-dev
43 ```
44
45 You may want to install `libboost-all-dev` to get all boost components even if it's not required.
46
47 ### Compile
48
49 ```bash
50 $ git clone https://github.com/iotbzh/can-config-generator.git
51 Cloning into 'can-config-generator'...
52 remote: Counting objects: 74, done.
53 remote: Compressing objects: 100% (42/42), done.
54 remote: Total 74 (delta 30), reused 67 (delta 27), pack-reused 0
55 Unpacking objects: 100% (74/74), done.
56 Checking connectivity... done.
57
58 <b>devel@bsp-devkit:~/projects/$</b> cd can-config-generator
59 <b>devel@bsp-devkit:~/projects/can-config-generator/(master)$</b> mkdir build
60 <b>devel@bsp-devkit:~/projects/can-config-generator/build(master)$</b> cmake -G "Unix Makefiles" ..
61 -- The C compiler identification is GNU 4.9.2
62 -- The CXX compiler identification is GNU 4.9.2
63 -- Check for working C compiler: /usr/bin/cc
64 -- Check for working C compiler: /usr/bin/cc -- works
65 -- Detecting C compiler ABI info
66 -- Detecting C compiler ABI info - done
67 -- Check for working CXX compiler: /usr/bin/c++
68 -- Check for working CXX compiler: /usr/bin/c++ -- works
69 -- Detecting CXX compiler ABI info
70 -- Detecting CXX compiler ABI info - done
71 -- Boost version: 1.55.0
72 -- Found the following Boost libraries:
73 --   program_options
74 --   filesystem
75 --   system
76 -- Configuring done
77 -- Generating done
78 -- Build files have been written to: /home/devel/projects/can-config-generator/build
79 <b>devel@bsp-devkit:~/projects/can-config-generator/build(master)$</b> make
80 Scanning dependencies of target can-config-generator
81 [ 12%] Building CXX object CMakeFiles/can-config-generator.dir/src/main.cpp.o
82 [ 25%] Building CXX object CMakeFiles/can-config-generator.dir/src/openxc/message_set.cpp.o
83 [ 37%] Building CXX object CMakeFiles/can-config-generator.dir/src/openxc/can_bus.cpp.o
84 [ 50%] Building CXX object CMakeFiles/can-config-generator.dir/src/openxc/can_message.cpp.o
85 [ 62%] Building CXX object CMakeFiles/can-config-generator.dir/src/openxc/command.cpp.o
86 [ 75%] Building CXX object CMakeFiles/can-config-generator.dir/src/openxc/diagnostic_message.cpp.o
87 [ 87%] Building CXX object CMakeFiles/can-config-generator.dir/src/openxc/mapping.cpp.o
88 [100%] Building CXX object CMakeFiles/can-config-generator.dir/src/openxc/signal.cpp.o
89 Linking CXX executable can-config-generator
90 [100%] Built target can-config-generator
91 ```
92
93 ### Generate your config file
94
95 To generate your config file you just have to run the generator using the `-m` option to specify your JSON file.
96
97 ```bash
98 $ can-config-generator -m ../tests/basic.json -o configuration-generated.cpp
99 ```
100
101 If you omit the `-o` option, then code is generated on the stdout.  
102 You also can specify a header and a footer file.  
103 These files must be valid C++ fragment as long as they will be inserted as is.  
104 Use the `-h` option to display help.
105
106 > **CAUTION:** Each `diagnostic_message` must define the same `bus` as the binding will use only one bus.
107
108 ### Supported OpenXC items
109
110 About now, compliance with OpenXC reference is in progress, can-config-generator and CAN\_signaling will implement them soon.  
111 `initializers`, `loopers`, `commands` and `handlers` nodes are ignored for now.
112
113 This generator will follow OpenXC support status of the low level CAN signaling binding.
114
115 > **NOTE**: The `buses` item will not be supported by this generator because the binding use another way to declare and configure buses. Please refer to the binding's documentation.
116
117 ## Compile and install the binding
118
119 With an AGL SDK environment correctly configured, I suggest you to set the TARGET variable in the root CMakeLists.txt file, if you have an AGL target already running in your network.
120
121 Then you can directly build and install the binding and source directory on your target system.
122
123 Execute these commands to get your binding compile :
124
125 ```bash
126 $ mkdir build
127 $ cd build
128 $ cmake ..
129 $ make
130 ```
131
132 And if you have set TARGET variable, you can install it on your AGL system :
133
134 ```bash
135 $ make install
136 [ 16%] Built target bitfield
137 [ 27%] Built target isotp
138 [ 40%] Built target openxc
139 [ 48%] Built target uds
140 [ 97%] Built target low-can-binding
141 [100%] Built target widget
142 Install the project...
143 -- Install configuration: ""
144 true
145 { "added": "low-can-binding@0.1" }
146 ```
147
148 It's possible that you'll see the following message :
149
150 ```bash
151 Error org.freedesktop.DBus.Error.Failed: "system error"
152 ```
153
154 It's because installation remove the binding before installing it.
155
156 If it is the first time that you make the installation then you'll have this message in place of _**true**_.
157
158 To install it manually, you need to copy the _low-can-binding.wgt_ file on your target, then from it execute the following commands :
159
160 On your host, to copy over the network :
161
162 ```bash
163 $ scp low-can-binding.wgt root@<target_IP>:~
164 ```
165
166 On the target, assuming _**wgt**_ file is in the root home directory :
167
168 ```bash
169 ~# afm-util install low-can-binding.wgt
170 { "added": "low-can-binding@0.1" }
171 ```
172
173
174