initialze muted, improved trace on i2c failure
[apps/agl-service-unicens.git] / README.md
1 ------------------------------------------------------------------------
2 AGL-UNICENS binding expose UNICENS-V2 APIs through AGL framework
3 ------------------------------------------------------------------------
4
5 Cloning Audio-Binding from Git
6 -------------------------------------------------------
7
8 ```
9 git clone --recurse-submodules https://github.com/iotbzh/unicens2-binding
10 cd  unicens2-binding
11 ```
12
13 AFB_daemon dependency on Standard Linux Distributions
14 -------------------------------------------------------
15     # handle dependencies > (OpenSuse-42.2, Fedora-25, Ubuntu 16.04.2LTS)
16     gcc > 4.8
17     systemd-devel (libsystemd-dev>=222)
18     libuuid-devel
19     file-devel(OpenSuSe) or libmagic-dev(Ubuntu)
20     libjson-c-devel
21     alsa-devel
22     ElectricFence (BUG should not be mandatory)
23     libopenssl-devel libgcrypt-devel libgnutls-devel (optional but requested by libmicrohttpd for https)
24
25     OpenSuse >=42.2
26       zypper in gcc5 gdb gcc5-c++ git cmake make ElectricFence systemd-devel libopenssl-devel  libuuid-devel alsa-devel libgcrypt-devel libgnutls-devel libjson-c-devel file-devel mxml-devel
27
28     Ubuntu >= 16.4 libuuid-devel
29       apt-get install cmake git electric-fence libsystemd-dev libssl-dev uuid-dev libasound2-dev libgcrypt20-dev libgnutls-dev libgnutls-dev libjson-c-dev libmagic-dev  libmxml-dev
30
31     libmicrohttpd>=0.9.55 (as today OpenSuse-42.2 or Ubuntu-.16.4 ship older versions)
32     afb-daemon from AGL Gerrit git clone https://gerrit.automotivelinux.org/gerrit/src/app-framework-binder
33
34 ```
35     # Might want to add following variables into ~/.bashrc
36     echo "#----------  AGL options Start ---------" >>~/.bashrc
37     echo "# Object: AGL cmake option for  binder/bindings" >>~/.bashrc
38     echo "# Date: `date`" >>~/.bashrc
39     echo 'export CC=gcc-5; export CXX=g++-5' >>~/.bashrc   # if using gcc5
40     echo 'export INSTALL_PREFIX=$HOME/opt' >>~/.bashrc
41     echo 'export LD_LIBRARY_PATH=$INSTALL_PREFIX/lib64:$INSTALL_PREFIX/lib' >>~/.bashrc
42     echo 'export LIBRARY_PATH=$INSTALL_PREFIX/lib64:$INSTALL_PREFIX/lib' >>~/.bashrc
43     echo 'export PKG_CONFIG_PATH=$INSTALL_PREFIX/lib64/pkgconfig:$INSTALL_PREFIX/lib/pkgconfig' >>~/.bashrc
44     echo 'export PATH=$INSTALL_PREFIX/bin:$PATH' >>~/.bashrc
45     echo 'export RSYNC_TARGET=MY_TARGET_HOSTNAME' >>~/.bashrc
46     echo 'export RSYNC_PREFIX=./opt' >>~/.bashrc
47
48     echo "#----------  AGL options End ---------" >>~/.bashrc
49     source ~/.bashrc
50
51     # install LibMicroHttpd
52     LIB_MH_VERSION=0.9.55
53     wget https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-${LIB_MH_VERSION}.tar.gz
54     tar -xzf libmicrohttpd-${LIB_MH_VERSION}.tar.gz
55     cd libmicrohttpd-${LIB_MH_VERSION}
56     ./configure --prefix=${INSTALL_PREFIX}
57     make
58     sudo make install-strip
59
60     # retrieve last AFB_daemon from AGL
61     git clone https://gerrit.automotivelinux.org/gerrit/src/app-framework-binder
62
63     # Warning: previous GCC options should be set before initial cmake (clean Build/*)
64     cd app-framework-binder; mkdir -p build; cd build
65     cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX ..
66     make
67     make install
68 ```
69
70
71 # Compile binding
72
73 ```
74     source ~/.bashrc  # or any other file where your have place your compilation preferences
75     mkdir -p build
76     cd build
77     cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX ..
78     make
79
80     afb-daemon --workdir=.. --ldpaths=build --port=1234  --roothttp=./htdocs --token="" --verbose
81
82     speaker-test -twav -D hw:ep01 -c 2
83     firefox http://localhost:1234
84 ```
85
86 # Archive
87
88 ```
89 VERSION=0.1
90 GIT_TAG=master
91 PKG_NAME=UNICENS-agent
92 git archive --format=tar.gz --prefix=${PKG_NAME}-${VERSION}/ ${GIT_TAG} -o ${PKG_NAME}_${VERSION}.orig.tar.gz
93 ```
94
95 # Local Source Debug with GDB
96
97 Warning: technically AGL bindings are shared libraries loaded thought 'dlopen'. GDB supports source debug of dynamically
98 loaded libraries, but user should be warn that the actual path to sharelib symbols is directly inherited from DLOPEN.
99 As a result if you change your directory after binder start with --workdir=xxx then GDB will not find symbols anymore
100
101
102 ```
103     Examples:
104
105     # WORK when running in direct
106     afb-daemon --workdir=.. --ldpaths=build --port=1234 --roothttp=./htdocs
107
108     # FAIL when using GDB with warning: Could not load shared library ....
109     gdb -args afb-daemon --workdir=.. --ldpaths=build --port=1234 --roothttp=./htdocs
110     ...
111     warning: Could not load shared library symbols for ./build/ucs2-afb/afb-ucs2.so.
112     Do you need "set solib-search-path" or "set sysroot"?
113     ...
114 ```
115
116 To debug sharelib symbol path: start your binder under GDB. Then break your session after the binder has
117 loaded its bindings. Finally use "info sharedlibrary" and check 'SymsRead'. If equal to 'No' then either you start GDB
118 from the wrong relative directory, either you have to use 'set solib-search-path' to force the path.
119
120 ```
121     gdb -args afb-daemon --workdir=.. --ldpaths=build --port=1234 --roothttp=./htdocs
122     run
123         ...
124         NOTICE: API UNICENS added
125         NOTICE: Waiting port=1234 rootdir=.
126         NOTICE: Browser URL= http://localhost:1234
127     (hit Ctrl-C to break the execution)
128     info sharedlibrary afb-*
129 ```
130
131
132 # Running an debugging on a target
133
134 ```
135 export RSYNC_TARGET=root@xx.xx.xx.xx
136 export RSYNC_PREFIX=/opt    # WARNING: installation directory should exist
137
138 mkdir $RSYNC_TARGET
139 cd    $RSYNC_TARGET
140
141 cmake -DRSYNC_TARGET=$RSYNC_TARGET -DRSYNC_PREFIX=$RSYNC_PREFIX ..
142 make remote-target-populate
143
144     ./build/target/start-${RSYNC_TARGET}.sh
145     firefox http://localhost:1234    # WARNING: do not forget firewall if any
146
147     ssh -tt ${RSYNC_TARGET} speaker-test -twav -D hw:ep01 -c 2
148 ```
149
150 Note: remote-target-populate will
151  - create a script to remotely start the binder on the target in ./build/target/start-on-target-name.sh
152  - create a gdbinit file to transparently debug remotely in source code with gdb -x ./build/target/gdb-on-target-name.ini
153  - to run and debug directly from your IDE just configure the run and debug properties with the corresponding filename
154
155 Note that Netbeans impose to set debug directory to ./build/pkgout or it won't find binding symbols for source debugging
156
157 # Default Volume of Amplifiers
158 The binding currently supports two use cases for amplifiers.
159 1. Amplifiers are initialized with a default volume. The head unit uses software volume 
160    to change the volume of streaming data.
161 2. Amplifiers are initialized muted. The head unit uses hardware volume (e.g. HAL-MOST-UNICENS)
162    to change the volume of amplifiers remotely.
163
164 Use case 2 is the default use case. If you like to use this binding without hardware volume support
165 please adopt the ```config_multichannel_audio_kit.xml``` as explained below.
166
167 ```
168 <!-- Register 7: Master Volume (Max Volume=07 00 00 and Min Volume=07 03 FF) -->
169 <!--   - together with HAL-MOST-UNICENS binding use "07 03 FF" = muted after start -->
170 <!--   - otherwise use "07 01 50" = default volume -->
171 <I2CPortWrite Address="0x2A" Payload="07 03 FF"/>
172 ```