Skip to content

Commit

Permalink
Merge pull request #54 from Legrandgroup/release
Browse files Browse the repository at this point in the history
* Major re-architecture done by Marc and new features addition to the library.
* Switching to cmake, moving source codes, creating an AES SPI and a facade pattern to hide libezsp internal structure.
* Adding firmware upgrade mode feature as well as offline commissionning.
* Full GP support is operational, including MIC validation.
* Also adding CI using travils+sonarcloud and coverage checking using gcov.
* Changing the compilation process to generate a shared library and publish header files.
* Added many command-line options to sample mainEzspTest
* Supports custom baudrates on adapter (including 115200 which is now the default)
  • Loading branch information
lionelains authored Apr 14, 2020
2 parents af7407a + 58adab7 commit 7b8275e
Show file tree
Hide file tree
Showing 171 changed files with 13,166 additions and 8,113 deletions.
18 changes: 17 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
*.o
/.Build.stamp
/.project
/.cproject
CMakeFiles/
/CMakeCache.txt
cmake_install.cmake
/include/ezsp/config.h
/src/ezsp/Makefile
/src/spi/Makefile
/tests/Makefile
/example/Makefile
/src/spi/libezspspi.so
/src/ezsp/libezsp.so
/example/mainEzspTest
/tests/gptest
/version.h
*.o
*.a
/doc
15 changes: 15 additions & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Path to sources
#sonar.sources=.
#sonar.exclusions=
#sonar.inclusions=

# Path to tests
#sonar.tests=
#sonar.test.exclusions=
#sonar.test.inclusions=

# Source encoding
#sonar.sourceEncoding=UTF-8

# Exclusions for copy-paste detection
#sonar.cpd.exclusions=
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: cpp
compiler: gcc
dist: trusty

addons:
sonarcloud:
organization: "legrandgroup"

script:
- mkdir -p build
- cd build
- cmake ${CMAKE_OPTIONS} -DUSE_CPPTHREADS=ON -DUSE_AESCUSTOM=ON -DUSE_GCOV=y -DUSE_MOCKSERIAL=ON ..
- build-wrapper-linux-x86-64 --out-dir bw-output/ make
- ./tests/gptest
- ../gcov.sh
- cd ..
- sonar-scanner
51 changes: 50 additions & 1 deletion Build
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,54 @@

source ../Config.sh

pp_do "$@"
pp_clean_local () {
pp_clean_default
}

pp_build_local () {

mkdir -p "build-for-target"
cd "build-for-target"

CFLAGS=${FW_CFLAGS_3RDPARTY} \
CXXFLAGS=${FW_CXXFLAGS_3RDPARTY} \
LDFLAGS=${FW_LDFLAGS_3RDPARTY} \
cmake \
-DCMAKE_C_COMPILER="$(type -P "$CC")" \
-DCMAKE_CXX_COMPILER="$(type -P "$CXX")" \
-DCMAKE_AR="$(type -P "$AR")" \
-DCMAKE_C_COMPILER_AR="$(type -P "$AR")" \
-DCMAKE_CXX_COMPILER_AR="$(type -P "$AR")" \
-DCMAKE_RANLIB="$(type -P "$RANLIB")" \
-DCMAKE_C_COMPILER_RANLIB="$(type -P "$RANLIB")" \
-DCMAKE_CXX_COMPILER_RANLIB="$(type -P "$RANLIB")" \
-DCMAKE_LINKER="$(type -P "${CROSS}ld")" \
-DCMAKE_NM="$(type -P "${CROSS}nm")" \
-DCMAKE_OBJDUMP="$(type -P "${CROSS}objdump")" \
-DCMAKE_OBJCOPY="$(type -P "${CROSS}objcopy")" \
-DCMAKE_STRIP="$(type -P "${CROSS}strip")" \
-DCMAKE_INSTALL_OLDINCLUDEDIR="/include" \
-DCMAKE_PREFIX_PATH="$DESTDIR" \
-DCMAKE_INSTALL_PREFIX=/ \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_C_FLAGS="${FW_CFLAGS_3RDPARTY}" \
-DCMAKE_CXX_FLAGS="${FW_CXXFLAGS_3RDPARTY}" \
-DCMAKE_LD_FLAGS="${FW_LDFLAGS_3RDPARTY}" \
-DUSE_RARITAN=ON \
-DUSE_AESCUSTOM=ON \
..
make
make install

cd "$OLDPWD"
}

pp_moddeps_local () {
echo "${LIBC_COMPONENT}"
}

pp_test_local () {
:
}

pp_do "$@"
28 changes: 28 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.8)

# set the project name and version
project(ezsp VERSION 1.0)

configure_file(version.h.in version.h)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)

add_definitions("-fvisibility=hidden")
add_definitions("-fvisibility-inlines-hidden")

option(USE_GCOV "Use GCOV coverage profiler" OFF)
if(USE_GCOV)
add_definitions(-g -O0 --coverage -fprofile-arcs -ftest-coverage)
link_libraries(--coverage -lgcov -fprofile-arcs)
endif()

#add_subdirectory(src)
add_subdirectory(src/ezsp)
add_subdirectory(src/spi)
add_subdirectory(example)
add_subdirectory(tests)
7 changes: 0 additions & 7 deletions Makefile

This file was deleted.

35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# libezsp
[![Build Status](https://travis-ci.org/Legrandgroup/libezsp.svg?branch=release)](https://travis-ci.org/Legrandgroup/libezsp)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=legrandgroup_libezsp&metric=alert_status)](https://sonarcloud.io/dashboard?id=legrandgroup_libezsp)

C++ library to send/receive wireless traffic to/from a UART transceiver using the EZSP protocol from Silicon Labs.
The code for a sample demo program is located in `src/example/mainEzspTest.cpp` and `src/example/CAppDemo.cpp`, this code is designed to work seamlessly on Linux within or outside of the Raritan framework.
Expand All @@ -9,12 +11,13 @@ The code for a sample demo program is located in `src/example/mainEzspTest.cpp`

If you compile in the Raritan environment, you will just have to clone this code into a subfolder or the source code root, move into this folder, and issue the following command:
```
./Build
./Build && cp ./build-for-target/example/mainEzspTest ../install_root/bin
```

The newly generated binary will be located in `../install_root/bin/mainEzspTest` (so, on the qemu installation, it will directly be accessible in the path to be run from a terminal on the target):
By default, only the shared library is copied over to the target rootfs, this is why we also manually copy the example binary (mainEzspTest) to `../install_root/bin/mainEzspTest`
This binary will be directly be accessible on the target, and in the default search path, so that it can run from a terminal on the target, by issueing:
```
mainEzspTest
mainEzspTest --help
```

### Using libserialcpp and C++11 threads under Linux
Expand All @@ -33,32 +36,34 @@ This should result in a binary shared library built as file `~/serial/libserialc
Now, we have to compile libezsp pointing it to the libserialcpp library we have just generated (in the example below, we assume the sources for libezsp are located in directory `~/libezsp`).
Issue the following commands in order to compile libezsp:
```
cd ~/libezsp/src/example
LOCAL_LDFLAGS=-L$HOME/serial LOCAL_INC=-I$HOME/serial/include make
cd ~/libezsp
LDFLAGS=-L$HOME/serial cmake -DCMAKE_CXX_FLAGS=-isystem\ $HOME/serial/include/ -DUSE_RARITAN=OFF -DUSE_CPPTHREADS=ON -DUSE_SERIALCPP=ON -DUSE_AESCUSTOM=ON
make
```

This will tell the compiler that libserialcpp.so can be found in `$HOME/serial` and headers are in `$HOME/serial/include` (this should be the default after the libserialcpp compilation steps above).
Additional environment variables tell the compiler that libserialcpp.so can be found in `$HOME/serial` and headers are in `$HOME/serial/include` (this should be the default after the libserialcpp compilation steps above).

In order to run the sample code under Linux, issue the following command in a terminal:
```
cd ~/libezsp/src/example
LD_LIBRARY_PATH=$HOME/serial ./mainEzspTest
cd ~/libezsp
LD_LIBRARY_PATH=$HOME/serial ./example/mainEzspTest -C 11 -c 26 -r '*' -s '0x01510004/0123456789abcdef0123456789abcdef' -d
```

The example above will open Green Power commissionning mode for 11s, and use the Zigbee channel 26 (for both Zigbee and Green Power transmission and reception).

The `-r` switch will flush any pre-existing known source ID & associated keys, and `-s` will manually add decoding support for a Green Power device with source ID 0x01510004 (and provides its associated 128-bit AES key).

### Execution

Note that the UART device for communication with the transceiver (eg: `/dev/ttyUSB0`) is hardcoded inside the code (file `src/example/mainEzspTest.cpp`)

We then library is run, it will first try to communicate with the dongle over the serial link provided above.

Once this is done, and when launched for the first time, the library will instruct the dongle to first create a Zigbee network.
Each time the sample binary process is subsequently run, it will open its network for any device to join for a limited period of time. You can thus enter a sensor in the network at this moment by pressing the button on the sensor device.

Once the network is created, the sample application provided will then automatically discover sensors and bind to temperature and humidity, then it will configure reporting to be sent to the dongle by the sensor (each time this configuration will be redone).

Finally, when the sensor sends periodically updated values of temperature/humidty, the dongle will receive these, the library will handle this incoming traffic and values will displayed in real time on the output stream of the sample process.
Once this is done, and when launched for the first time, the library will instruct the dongle to first create a network on the specified channel.
Each time the sample binary process is subsequently run, it will listen to sensor reports on that channel.
When the sensor sends periodically updated values of temperature/humidty via Green Power radio frames, the dongle will receive these, the library will handle this incoming traffic and values will displayed in real time on the output stream of the sample binary.

In order to force the sensor to send a report, you can also press 4 times on the button.
In order to force the sensor to send a report, you can also press on the button.

## For developpers

Expand Down
11 changes: 11 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
option(USE_RARITAN "Use RARITAN environment" ON)
option(USE_CPPTHREADS "Use CPPTHREAD" OFF)

if(USE_CPPTHREADS)
set(USE_RARITAN OFF)
endif()

add_executable(mainEzspTest mainEzspTest.cpp)

target_include_directories(mainEzspTest PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(mainEzspTest PUBLIC ezsp ezspspi)
Loading

0 comments on commit 7b8275e

Please sign in to comment.