1 # Install AFB Websocket CLI client to test the binding.
3 You can test it using afb-client-demo CLI tool provided by the RPM package *libafbwsc-dev*.
5 You can find this package in your build environment, using docker SDK recommended setup the file is `/xdt/build/tmp/deploy/rpm/<your-target-arch>/`.
7 After a successful bitbake build and using Renesas RCar Gen2, Porter, you have to copy the file if your board is connected to your network and you know its IP address:
10 $ scp /xdt/build/tmp/deploy/rpm/cortex15hf_neon/libafbwsc-dev-1.0-r0.cortexa15hf_neon.rpm root@<target_IP>:~
13 Else, you have to copy into the SDcard with the AGL image installed on it.
15 From the docker image copy RPM to the shared directory between docker image and your host:
18 $ cp /xdt/build/tmp/deploy/rpm/cortex15hf_neon/libafbwsc-dev-1.0-r0.cortexa15hf_neon.rpm ~/share
21 Then plugin you SDcard in your Linux host (Windows can't read ext4 filesystem AGL runs on) and copy RPM file on it.
23 From your host, identify SDcard block device node here it is **sdc** with the correct capacity automounted by the desktop manager:
28 └─docker-253:0-3146365-pool 253:3 0 100G 0 dm
29 └─docker-253:0-3146365-e9f80849a2681e18549d3a4238cbf031e44052e36cd88a0abf041804b799b61c
30 253:4 0 10G 0 dm /var/lib/docker/devicemapper/mnt/e9f80849a2681e18549d3a4238cbf031e44052e36cd88a0abf041804b799b61c
31 sdb 8:16 0 238.5G 0 disk
32 ├─sdb2 8:18 0 238G 0 part
33 │ └─Shamash-agl 253:1 0 238G 0 lvm /home/claneys/Workspace/agl-docker
34 └─sdb1 8:17 0 500M 0 part /boot
35 sr0 11:0 1 1024M 0 rom
36 loop0 7:0 0 100G 0 loop
37 └─docker-253:0-3146365-pool 253:3 0 100G 0 dm
38 └─docker-253:0-3146365-e9f80849a2681e18549d3a4238cbf031e44052e36cd88a0abf041804b799b61c
39 253:4 0 10G 0 dm /var/lib/docker/devicemapper/mnt/e9f80849a2681e18549d3a4238cbf031e44052e36cd88a0abf041804b799b61c
40 sdc 8:32 1 14.9G 0 disk
41 └─sdc1 8:33 1 2G 0 part /run/media/claneys/97f418a5-612f-44e9-b968-a19505695151
42 sda 8:0 0 931.5G 0 disk
43 ├─sda2 8:2 0 500G 0 part
44 │ ├─Shamash-home 253:2 0 150G 0 lvm /home
45 │ └─Shamash-root 253:0 0 50G 0 lvm /
46 └─sda1 8:1 0 16G 0 part [SWAP]
49 Copy, still from your host:
51 > **CAUTION** Make sure to sync IO with sync command before unplug your SDcard. It could be corrupted if removed before all pending IO aren't done.
54 $ sudo cp ~/devel/docker/share/libafbwsc-dev-1.0-r0.cortexa15hf_neon.rpm /run/media/claneys/97f418a5-612f-44e9-b968-a19505695151/home/root
58 Insert the modified SDcard in your Porter board and boot from it. You are ready to go.
60 ## Configure the AGL system
62 ### Virtual CAN device
64 Connected to the target, here is how to load the virtual CAN device driver and set up a new vcan device :
68 # ip link add vcan0 type vcan
69 # ip link set vcan0 up
72 ### CAN device using the USB CAN adapter
74 Using real connection to CAN bus of your car using the USB CAN adapter connected to the OBD2 connector.
76 Once connected, launch ```dmesg``` command and search which device to use :
81 [ 131.871441] usb 1-3: new full-speed USB device number 4 using ohci-pci
82 [ 161.860504] can: controller area network core (rev 20120528 abi 9)
83 [ 161.860522] NET: Registered protocol family 29
84 [ 177.561620] usb 1-3: USB disconnect, device number 4
85 [ 191.061423] usb 1-2: USB disconnect, device number 3
86 [ 196.095325] usb 1-2: new full-speed USB device number 5 using ohci-pci
87 [ 327.568882] usb 1-2: USB disconnect, device number 5
88 [ 428.594177] CAN device driver interface
89 [ 1872.551543] usb 1-2: new full-speed USB device number 6 using ohci-pci
90 [ 1872.809302] usb_8dev 1-2:1.0 can0: firmware: 1.7, hardware: 1.0
91 [ 1872.809356] usbcore: registered new interface driver usb_8dev
94 Here device is named **can0**.
96 This instruction assuming a speed of 500000kbps for your CAN bus, you can try others supported bitrate like 125000, 250000 if 500000 doesn't work:
99 # ip link set can0 type can bitrate 500000
100 # ip link set can0 up
102 can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
104 can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
105 bitrate 500000 sample-point 0.875
106 tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
107 sja1000: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
111 ## Configure the binding
113 Configure the binding specifying in the JSON configuration file the CAN device(s) that it will to connect to. Edit file */var/lib/afm/applications/low-can-binding/0.1/can_buses.json* and change the CAN device name to the one you have :
121 If you have several specify CAN bus devices use an array:
125 "canbus": [ "vcan0", "can0" ]
129 > **WARNING** Make sure the CAN bus(es) you specify in your configuration file match those specified in your generated source file with the [can-config-generator](http://github.com/iotbzh/can-config-generator).
131 ## Run it, test it, use it !
133 You can run the binding using **afm-util** tool, here is the classic way to go :
136 # afm-util run low-can-binding@0.1
140 You can find instructions to use afm-util tool [here](http://docs.iot.bzh/docs/apis_services/en/dev/reference/af-main/afm-daemons.html#using-afm-util), as well as documentation about Application Framework.
142 But you can't control nor interact with it because you don't know security token that **Application Framework** gaves it at launch.
144 So, to test it, it is better to launch the binding manually. In the following example, we will use port **1234** and left empty security token for testing purpose:
147 # afb-daemon --ldpaths=/usr/lib/afb:/var/lib/afm/applications/low-can-binding/0.1/libs/ --rootdir=/var/lib/afm/applications/low-can-binding/0.1/ --port=1234 --token=
148 NOTICE: binding [/usr/lib/afb/afb-dbus-binding.so] calling registering function afbBindingV1Register
149 NOTICE: binding /usr/lib/afb/afb-dbus-binding.so loaded with API prefix dbus
150 NOTICE: binding [/usr/lib/afb/authLogin.so] calling registering function afbBindingV1Register
151 NOTICE: binding /usr/lib/afb/authLogin.so loaded with API prefix auth
152 NOTICE: binding [/var/lib/afm/applications/low-can-binding/0.1/libs//low-can-binding.so] calling registering function afbBindingV1Register
153 NOTICE: binding /var/lib/afm/applications/low-can-binding/0.1/libs//low-can-binding.so loaded with API prefix low-can
154 NOTICE: Waiting port=1234 rootdir=/var/lib/afm/applications/low-can-binding/0.1/
155 NOTICE: Browser URL= http:/*localhost:1234
156 NOTICE: vcan0 device opened and reading {binding low-can}
157 NOTICE: Initialized 1/1 can bus device(s) {binding low-can}
160 Then connect to the binding using previously installed ***AFB Websocket CLI*** tool :
163 # afb-client-demo ws://localhost:1234/api?token=
166 You will be on an interactive session where you can communicate directly with the binding API.
168 The binding provides at this moment 2 verbs, *subscribe* and *unsubscribe*, which can take argument by a JSON **event** object.
170 The argument value is the CAN message **generic_name** as described in the JSON file used to generate cpp file for the binding.
172 To use the ***AFB Websocket CLI*** tool, a command line will be like the following :
175 <api> <verb> <arguments>
180 - API : ***low-can***.
181 - Verb : ***subscribe*** or ***unsubscribe***
182 - Arguments : ***{ "event": "driver.doors.open" }***
184 ### Subscription and unsubscription
186 You can ask to subscribe to chosen CAN event with a call to *subscribe* API verb with the CAN messages name as JSON argument.
188 > **Note** If no argument is provided, then you'll subscribe to all signals at once.
190 For example from a websocket session:
193 low-can subscribe { "event": "doors.driver.open" }
194 ON-REPLY 1:low-can/subscribe: {"jtype":"afb-reply","request":{"status":"success","uuid":"a18fd375-b6fa-4c0e-a1d4-9d3955975ae8"}}
197 Subscription and unsubscription can take wildcard in their *event* value.
199 To reveive all doors events :
202 low-can subscribe { "event" : "doors*" }
203 ON-REPLY 1:low-can/subscribe: {"jtype":"afb-reply","request":{"status":"success","uuid":"511c872e-d7f3-4f3b-89c2-aa9a3e9fbbdb"}}
206 Then you will receive an event each time a CAN message is decoded for the event named *doors.driver.open*
209 ON-EVENT low-can/messages.doors.driver.open({"event":"low-can\/messages.doors.driver.open","data":{"name":"messages.doors.driver.open","value":true},"jtype":"afb-event"})
212 Notice that event shows you that the CAN event is named *messages.doors.driver.open* but you ask for event about *doors.driver.open*.
214 This is because all CAN messages or diagnostic messages are prefixed by the JSON parent node name, **messages** for CAN messages and **diagnostic_messages** for diagnostic messages like OBD2.
216 This will let you subscribe or unsubcribe to all signals at once, not recommended, and better make filter on subscribe operation based upon their type. Examples:
219 low-can subscribe { "event" : "*speed*" } --> will subscribe to all messages with speed in their name. Search will be make without prefix for it.
220 low-can subscribe { "event" : "speed*" } --> will subscribe to all messages begin by speed in their name. Search will be make without prefix for it.
221 low-can subscribe { "event" : "messages*speed*" } --> will subscribe to all CAN messages with speed in their name. Search will be on prefixed messages here.
222 low-can subscribe { "event" : "messages*speed" } --> will subscribe to all CAN messages ending with speed in their name. Search will be on prefixed messages here.
223 low-can subscribe { "event" : "diagnostic*speed*" } --> will subscribe to all diagnostic messages with speed in their name. Search will be on prefixed messages here.
224 low-can subscribe { "event" : "diagnostic*speed" } --> will subscribe to all diagnostic messages ending with speed in their name. Search will be on prefixed messages here.
227 You can stop receiving event from it by unsubscribe the signal the same way you did for subscribe
230 low-can unsubscribe { "event": "doors.driver.open" }
231 ON-REPLY 2:low-can/unsubscribe: {"jtype":"afb-reply","request":{"status":"success"}}
232 low-can unsubscribe { "event" : "doors*" }
233 ON-REPLY 3:low-can/unsubscribe: {"jtype":"afb-reply","request":{"status":"success"}}